Convert host data to a CUDA buffer Args: host_data (numpy array): Host data Returns: CudaBuffer: The converted CUDA buffer
(host_data)
| 145 | |
| 146 | |
| 147 | def 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 | |
| 173 | def to_cvcuda_tensor(data, layout): |
no test coverage detected