MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / cuda_memcpy_h2d

Function cuda_memcpy_h2d

samples/interoperability/cuda_python_common.py:80–104  ·  view source on GitHub ↗

Copy host array to device array. Args: host_array: Host array to copy. device_array: Device array to copy to, __cuda_array_interface__ or object with interface.

(
    host_array: np.ndarray,
    device_array: int | dict | object,
)

Source from the content-addressed store, hash-verified

78
79# docs_tag: being_cuda_memcpy_h2d
80def cuda_memcpy_h2d(
81 host_array: np.ndarray,
82 device_array: int | dict | object,
83) -> None:
84 """
85 Copy host array to device array.
86
87 Args:
88 host_array: Host array to copy.
89 device_array: Device array to copy to, __cuda_array_interface__ or object with interface.
90 """
91 if hasattr(device_array, "__cuda_array_interface__"):
92 device_array = device_array.__cuda_array_interface__["data"][0]
93 elif isinstance(device_array, dict) and "data" in device_array:
94 device_array = device_array["data"][0]
95 elif not isinstance(device_array, int):
96 raise ValueError("Invalid device array")
97 (err,) = cudart.cudaMemcpy(
98 device_array,
99 host_array.ctypes.data,
100 host_array.nbytes,
101 cudart.cudaMemcpyKind.cudaMemcpyHostToDevice,
102 )
103 if err != cudart.cudaError_t.cudaSuccess:
104 raise RuntimeError(f"cudaMemcpy failed: {err}")
105
106
107# docs_tag: end_cuda_memcpy_h2d

Callers 7

mainFunction · 0.90
mainFunction · 0.90
color_labels_nhwcFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected