CuPy
CuPy is a NumPy-compatible GPU array library that provides GPU acceleration for numerical operations. It’s an excellent choice when you want to use NumPy-like operations on the GPU.
Key Points:
CuPy arrays are already on GPU, no explicit device transfer needed
Use
cvcuda.as_tensor()to convert CuPy arrays to CV-CUDAUse
cupy.asarray()to convert CV-CUDA tensors back to CuPyCuPy provides the most NumPy-like interface for GPU arrays
Required Imports:
import cupy
import cvcuda
CuPy to CV-CUDA:
cupy_array = cupy.random.random((10, 10), dtype=cupy.float32)
cvcuda_tensor = cvcuda.as_tensor(cupy_array)
CuPy arrays are created directly on the GPU and can be immediately converted to CV-CUDA tensors.
CV-CUDA to CuPy:
new_cupy_array = cupy.asarray(cvcuda_tensor.cuda())
The cupy.asarray() function recognizes the CUDA Array Interface and creates a CuPy array that
views the same GPU memory as the CV-CUDA tensor.
Complete Example: See samples/interoperability/cupy_interop.py