python/1_GettingStarted/copyImageArraytoGPU/README.md
Copy image arrays between CPU and GPU memory using the modern cuda.core API with optimal performance through pinned memory and asynchronous transfers.
cuda.core API for memory managementcuda.core - Modern CUDA Python APInumpy - Array operations and DLPack supportcupy - GPU array operations and CUDA interoperabilitycuda.core:Device() - Initialize and access CUDA deviceDevice.set_current() - Set the current device for API callsDevice.create_stream() - Create CUDA stream for async operationsDevice.memory_resource - Access device memory allocatorPinnedMemoryResource() - Allocate pinned host memorybuffer.copy_to() - Copy data between memory spacesbuffer.close() - Release allocated memorynumpy:np.from_dlpack() - Create array view from DLPack capsulenp.copyto() - Copy data between arrayscupy:cp.from_dlpack() - Create GPU array view from DLPack capsulecp.cuda.Stream.from_external() - Use external CUDA streamcuda_samples_utils:verify_array_result() - Verify computation resultscuda-python package (>=13.0.0+)cuda-core package (>=1.0.0)cupy-cuda13x package (14.0.0+)Install the required packages from requirements.txt:
cd /path/to/cuda-samples/python/1_GettingStarted/copyImageArraytoGPU
pip install -r requirements.txt
The requirements.txt installs:
numpy (2.3.2+, required for DLPack)cuda-python (>=13.0.0+)cuda-core (>=1.0.0)cupy-cuda13x (14.0.0+)cd samples/python/1_GettingStarted/copyImageArraytoGPU
python copyImageArraytoGPU.py
[Image Array Copy to GPU using CUDA Core API]
Device: NVIDIA GeForce RTX 4090
[Image array copy of 256x256x3 image]
Creating sample image...
Copying image to GPU...
Creating CuPy view of GPU data...
Mean pixel value (computed on GPU): 127.50
Copying image back from GPU...
Verifying result...
Test PASSED
Done
Note: Device name will vary based on your GPU.
copyImageArraytoGPU.py - Python implementation using cuda.core APIREADME.md - This filerequirements.txt - Sample dependencies../../Utilities/cuda_samples_utils.py - Common utilities (imported by this sample)