Examples#
The canonical, runnable examples for cuda.core live under
samples/cuda_core/ in the cuda-python repository. Each sample is
a self-contained directory with its own README.md, requirements.txt,
and PEP 723 dependency block, and every sample is exercised as part of the
cuda.core test suite.
Getting started#
vectorAdd compiles and launches a templated vector-add kernel and demonstrates
Device.allocate()andname_expressions.deviceQuery enumerates every CUDA device with an
nvidia-smi-style summary and an optional--verbosemode for the long-tail property list.systemInfo reports system-wide CUDA information (driver / runtime / NVML).
Kernels and launch configuration#
launchConfigTuning explores how launch-configuration choices affect kernel performance.
threadBlockCluster demonstrates
LaunchConfig(cluster=...)on Hopper-class GPUs.tmaTensorMap uses Tensor Memory Accelerator descriptors for bulk data movement.
greenContext partitions SMs across kernels with green contexts.
kernelNsysProfile annotates kernel launches with NVTX markers for Nsight Systems.
host_launch.py orders a host function between two kernel launches on a stream and reads a pinned buffer from it.
Memory management and interop#
memoryResources covers
DeviceMemoryResource,PinnedMemoryResource,ManagedMemoryResource, andGraphMemoryResource, plus configurable resource options.copyImageArraytoGPU stages host-to-device copies through
PinnedMemoryResource.blurImageUnifiedMemory applies a stencil kernel over unified memory.
stridedMemoryViewConstructors walks through the four
StridedMemoryView.from_*constructors.stridedMemoryViewCpu dispatches to a JIT-compiled CPU function via
cffi.stridedMemoryViewGpu dispatches to an NVRTC-compiled GPU kernel through the same decorator.
ipcMemoryPool shares an IPC-enabled
DeviceMemoryResourceacross processes.buffer_deallocation_stream.py transfers a buffer between streams and safely changes the stream that orders its deallocation.
CUDA graphs and linking#
cudaGraphs captures and replays a multi-kernel graph, then reuses it via
Graph.update().jitLtoLinking links two device modules with PTX vs LTO and swaps in a runtime plug-in.
Framework interop and compute algorithms#
customPyTorchKernel launches a cuda.core kernel from a PyTorch autograd function.
customTensorFlowKernel wires a cuda.core kernel into a TensorFlow custom op.
numpyVsCupy compares NumPy and CuPy execution paths side-by-side.
fftSignalAnalysis runs a CuPy FFT-based signal analysis pipeline.
binarySearch, prefixSum, reduction, parallelReduction, reductionMultiBlockCG, parallelHistogram, blockwiseSum, matrixMulSharedMem, cudaComputeLambdas, pageRank – classic parallel-algorithm building blocks.
Multi-GPU and streams#
simpleMultiGpu runs independent kernels on two GPUs in the same process.
simpleP2P demonstrates peer-to-peer memory access between GPUs.
multiGPUGradientAverage averages gradients across GPUs with MPI.
streamingCopyComputeOverlap overlaps copies and compute across multiple streams.
simpleZeroCopy runs kernels against zero-copy mapped host memory.
processCheckpoint checkpoints and restores CUDA process state.
Graphics interop#
glInteropPlasma writes CUDA-generated pixels into an OpenGL PBO with zero CPU round-trip.
Simple utilities#
simplePrint minimal kernel that prints from the device.