14 #define EIGEN_TEST_NO_LONGDOUBLE
15 #define EIGEN_TEST_NO_COMPLEX
17 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE int64_t
18 #define EIGEN_USE_SYCL
21 #include <unsupported/Eigen/CXX11/Tensor>
26 template <
typename DataType,
typename IndexType>
30 IndexType sizeDim0 = 4;
31 IndexType sizeDim1 = 2;
32 IndexType sizeDim2 = 3;
33 IndexType sizeDim3 = 5;
34 IndexType sizeDim4 = 7;
35 array<IndexType, 5> tensorColMajorRange = {{sizeDim0, sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
36 array<IndexType, 5> tensorRowMajorRange = {{sizeDim4, sizeDim3, sizeDim2, sizeDim1, sizeDim0}};
42 DataType* gpu_data_col_major =
static_cast<DataType*
>(sycl_device.allocate(tensor_col_major.
size()*
sizeof(DataType)));
43 DataType* gpu_data_row_major =
static_cast<DataType*
>(sycl_device.allocate(tensor_row_major.
size()*
sizeof(DataType)));
47 sycl_device.memcpyHostToDevice(gpu_data_col_major, tensor_col_major.
data(),(tensor_col_major.
size())*
sizeof(DataType));
48 gpu_row_major.device(sycl_device)=gpu_col_major.swap_layout();
52 array<IndexType, 6> patchColMajorTensorRange={{sizeDim0,1, 1, 1, sizeDim1*sizeDim2*sizeDim3, sizeDim4}};
54 size_t patchTensorBuffSize =single_voxel_patch_col_major.
size()*
sizeof(DataType);
55 DataType* gpu_data_single_voxel_patch_col_major =
static_cast<DataType*
>(sycl_device.allocate(patchTensorBuffSize));
57 gpu_single_voxel_patch_col_major.device(sycl_device)=gpu_col_major.extract_volume_patches(1, 1, 1);
58 sycl_device.memcpyDeviceToHost(single_voxel_patch_col_major.
data(), gpu_data_single_voxel_patch_col_major, patchTensorBuffSize);
68 array<IndexType, 6> patchRowMajorTensorRange={{sizeDim4, sizeDim1*sizeDim2*sizeDim3, 1, 1, 1, sizeDim0}};
70 patchTensorBuffSize =single_voxel_patch_row_major.
size()*
sizeof(DataType);
71 DataType* gpu_data_single_voxel_patch_row_major =
static_cast<DataType*
>(sycl_device.allocate(patchTensorBuffSize));
73 gpu_single_voxel_patch_row_major.device(sycl_device)=gpu_row_major.extract_volume_patches(1, 1, 1);
74 sycl_device.memcpyDeviceToHost(single_voxel_patch_row_major.
data(), gpu_data_single_voxel_patch_row_major, patchTensorBuffSize);
83 sycl_device.memcpyDeviceToHost(tensor_row_major.
data(), gpu_data_row_major, (tensor_col_major.
size())*
sizeof(DataType));
84 for (IndexType
i = 0;
i < tensor_col_major.
size(); ++
i) {
91 sycl_device.deallocate(gpu_data_col_major);
92 sycl_device.deallocate(gpu_data_row_major);
93 sycl_device.deallocate(gpu_data_single_voxel_patch_col_major);
94 sycl_device.deallocate(gpu_data_single_voxel_patch_row_major);
97 template <
typename DataType,
typename IndexType>
101 const int patch_z = 2;
102 const int patch_y = 3;
103 const int patch_x = 5;
113 DataType* gpu_data_col_major =
static_cast<DataType*
>(sycl_device.allocate(tensor_col_major.
size()*
sizeof(DataType)));
114 DataType* gpu_data_row_major =
static_cast<DataType*
>(sycl_device.allocate(tensor_row_major.
size()*
sizeof(DataType)));
118 sycl_device.memcpyHostToDevice(gpu_data_col_major, tensor_col_major.
data(),(tensor_col_major.
size())*
sizeof(DataType));
119 gpu_row_major.device(sycl_device)=gpu_col_major.swap_layout();
120 sycl_device.memcpyDeviceToHost(tensor_row_major.
data(), gpu_data_row_major, (tensor_col_major.
size())*
sizeof(DataType));
126 size_t patchTensorBuffSize =entire_volume_patch_col_major.
size()*
sizeof(DataType);
127 DataType* gpu_data_entire_volume_patch_col_major =
static_cast<DataType*
>(sycl_device.allocate(patchTensorBuffSize));
129 gpu_entire_volume_patch_col_major.device(sycl_device)=gpu_col_major.extract_volume_patches(patch_z, patch_y, patch_x);
130 sycl_device.memcpyDeviceToHost(entire_volume_patch_col_major.
data(), gpu_data_entire_volume_patch_col_major, patchTensorBuffSize);
151 patchTensorBuffSize =entire_volume_patch_row_major.
size()*
sizeof(DataType);
152 DataType* gpu_data_entire_volume_patch_row_major =
static_cast<DataType*
>(sycl_device.allocate(patchTensorBuffSize));
154 gpu_entire_volume_patch_row_major.device(sycl_device)=gpu_row_major.extract_volume_patches(patch_z, patch_y, patch_x);
155 sycl_device.memcpyDeviceToHost(entire_volume_patch_row_major.
data(), gpu_data_entire_volume_patch_row_major, patchTensorBuffSize);
165 const int dz = patch_z - 1;
166 const int dy = patch_y - 1;
167 const int dx = patch_x - 1;
169 const int forward_pad_z = dz / 2;
170 const int forward_pad_y = dy / 2;
171 const int forward_pad_x = dx / 2;
173 for (
int pz = 0; pz < patch_z; pz++) {
174 for (
int py = 0;
py < patch_y;
py++) {
175 for (
int px = 0;
px < patch_x;
px++) {
176 const int patchId = pz + patch_z * (
py +
px * patch_y);
177 for (
int z = 0;
z < patch_z;
z++) {
178 for (
int y = 0;
y < patch_y;
y++) {
179 for (
int x = 0;
x < patch_x;
x++) {
183 float expected_row_major = 0.0f;
184 const int eff_z =
z - forward_pad_z + pz;
185 const int eff_y =
y - forward_pad_y +
py;
186 const int eff_x =
x - forward_pad_x +
px;
187 if (eff_z >= 0 && eff_y >= 0 && eff_x >= 0 &&
188 eff_z < patch_z && eff_y < patch_y && eff_x < patch_x) {
189 expected = tensor_col_major(
d, eff_z, eff_y, eff_x,
b);
190 expected_row_major = tensor_row_major(
b, eff_x, eff_y, eff_z,
d);
202 sycl_device.deallocate(gpu_data_col_major);
203 sycl_device.deallocate(gpu_data_row_major);
204 sycl_device.deallocate(gpu_data_entire_volume_patch_col_major);
205 sycl_device.deallocate(gpu_data_entire_volume_patch_row_major);
211 QueueInterface queueInterface(
s);
212 auto sycl_device = Eigen::SyclDevice(&queueInterface);
213 std::cout <<
"Running on " <<
s.template get_info<cl::sycl::info::device::name>() << std::endl;
214 test_single_voxel_patch_sycl<DataType, int64_t>(sycl_device);
215 test_entire_volume_patch_sycl<DataType, int64_t>(sycl_device);
219 for (
const auto& device :Eigen::get_sycl_supported_devices()) {
220 CALL_SUBTEST(sycl_tensor_volume_patch_test_per_device<float>(device));