nabu.cuda.utils module

nabu.cuda.utils.get_cuda_context(device_id=None, cleanup_at_exit=True)[source]

Create or get a CUDA context.

nabu.cuda.utils.count_cuda_devices()[source]
nabu.cuda.utils.get_gpu_memory(device_id)[source]

Return the total memory (in GigaBytes) of a device.

nabu.cuda.utils.is_gpu_usable()[source]

Test whether at least one Nvidia GPU is available.

nabu.cuda.utils.detect_cuda_gpus()[source]

Detect the available Nvidia CUDA GPUs on the current host.

Returns:

  • gpus (dict) – Dictionary where the key is the GPU ID, and the value is a pycuda.driver.Device object.

  • error_msg (str) – In the case where there is an error, the message is returned in this item. Otherwise, it is a None object.

nabu.cuda.utils.collect_cuda_gpus()[source]

Return a dictionary of GPU ids and brief description of each CUDA-compatible GPU with a few fields.

nabu.cuda.utils.get_nvcc_version(nvcc_cmd='nvcc')[source]
nabu.cuda.utils.check_textures_availability()[source]

Check whether Cuda textures can be used. The only limitation is pycuda which does not support texture objects. Textures references were deprecated, and removed from Cuda 12.

nabu.cuda.utils.cuarray_format_to_dtype(cuarr_fmt)[source]
nabu.cuda.utils.cuarray_shape_dtype(cuarray)[source]
nabu.cuda.utils.get_shape_dtype(arr)[source]
nabu.cuda.utils.copy_array(dst, src, check=False, src_dtype=None, dst_x_in_bytes=0, dst_y=0)[source]

Copy a source array to a destination array. Source and destination can be either numpy.ndarray, pycuda.Driver.Array, or pycuda.gpuarray.GPUArray.

Parameters:
  • dst (pycuda.driver.Array or pycuda.gpuarray.GPUArray or numpy.ndarray) – Destination array. Its content will be overwritten by copy.

  • src (pycuda.driver.Array or pycuda.gpuarray.GPUArray or numpy.ndarray) – Source array.

  • check (bool, optional) – Whether to check src and dst shape and data type.

nabu.cuda.utils.copy_big_gpuarray(dst, src, itemsize=4, checks=False)[source]

Copy a big pycuda.gpuarray.GPUArray into another. Transactions of more than 2**32 -1 octets fail, so are doing several partial copies of smaller arrays.

nabu.cuda.utils.replace_array_memory(arr, new_shape)[source]

Replace the underlying buffer data of a pycuda.gpuarray.GPUArray. This function is dangerous ! It should merely be used to clear memory, the array should not be used afterwise.

nabu.cuda.utils.pycuda_to_cupy(arr_pycuda)[source]
nabu.cuda.utils.cupy_to_pycuda(arr_cupy)[source]