def test_data_ptr_tensor_list_cpu(): arr = np.random.rand(3, 5, 6) tensorlist = TensorListCPU(arr, "NHWC") tensor = tensorlist.as_tensor() from_tensor_list = py_buffer_from_address(tensorlist.data_ptr(), tensor.shape(), tensor.dtype()) assert (np.array_equal(arr, from_tensor_list))
def test_data_ptr_tensor_gpu(): arr = np.random.rand(3, 5, 6) pipe = ExternalSourcePipe(arr.shape[0], arr) pipe.build() tensor = pipe.run()[0][0] from_tensor = py_buffer_from_address(tensor.data_ptr(), tensor.shape(), tensor.dtype(), gpu=True) # from_tensor is cupy array, convert arr to cupy as well assert(cp.allclose(arr[0], from_tensor))
def test_data_ptr_tensor_list_gpu(): arr = np.random.rand(3, 5, 6) pipe = ExternalSourcePipe(arr.shape[0], arr) pipe.build() tensor_list = pipe.run()[0] tensor = tensor_list.as_tensor() from_tensor = py_buffer_from_address(tensor_list.data_ptr(), tensor.shape(), types.to_numpy_type(tensor.dtype), gpu=True) # from_tensor is cupy array, convert arr to cupy as well assert cp.allclose(arr, from_tensor)
def test_data_ptr_tensor_cpu(): arr = np.random.rand(3, 5, 6) tensor = TensorCPU(arr, "NHWC") from_tensor = py_buffer_from_address(tensor.data_ptr(), tensor.shape(), tensor.dtype()) assert (np.array_equal(arr, from_tensor))