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

Function to_cuda_buffer

tests/cvcuda/python/cvcuda_util.py:147–170  ·  view source on GitHub ↗

Convert host data to a CUDA buffer Args: host_data (numpy array): Host data Returns: CudaBuffer: The converted CUDA buffer

(host_data)

Source from the content-addressed store, hash-verified

145
146
147def to_cuda_buffer(host_data):
148 """Convert host data to a CUDA buffer
149
150 Args:
151 host_data (numpy array): Host data
152
153 Returns:
154 CudaBuffer: The converted CUDA buffer
155 """
156 orig_dtype = copy.copy(host_data.dtype)
157
158 host_data.dtype = to_torch_dtype(host_data.dtype)
159
160 dev = torch.as_tensor(host_data, device="cuda").cuda()
161 host_data.dtype = orig_dtype # restore it
162
163 # The cuda buffer only needs the cuda array interface.
164 # We can then set its dtype to whatever we want.
165 buf = CudaBuffer()
166 buf.__cuda_array_interface__ = dev.__cuda_array_interface__
167 buf.__cuda_array_interface__["typestr"] = orig_dtype.str
168 buf.obj = dev # make sure it holds a reference to the torch buffer
169
170 return buf
171
172
173def to_cvcuda_tensor(data, layout):

Callers 2

to_cvcuda_tensorFunction · 0.85
to_cvcuda_imageFunction · 0.85

Calls 3

to_torch_dtypeFunction · 0.85
CudaBufferClass · 0.70
cudaMethod · 0.45

Tested by

no test coverage detected