16 #define EIGEN_TEST_NO_LONGDOUBLE 17 #define EIGEN_TEST_NO_COMPLEX 19 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE int64_t 20 #define EIGEN_USE_SYCL 23 #include <unsupported/Eigen/CXX11/Tensor> 26 using Eigen::SyclDevice;
30 template <
typename DataType,
int DataLayout,
typename IndexType>
32 IndexType sizeDim1 = 5;
33 IndexType sizeDim2 = 5;
34 IndexType sizeDim3 = 1;
43 DataType* gpu_data1 =
static_cast<DataType*
>(sycl_device.allocate(in1.
size()*
sizeof(DataType)));
44 DataType* gpu_data2 =
static_cast<DataType*
>(sycl_device.allocate(out1.
size()*
sizeof(DataType)));
49 sycl_device.memcpyHostToDevice(gpu_data1, in1.
data(),(in1.
size())*
sizeof(DataType));
50 sycl_device.memcpyHostToDevice(gpu_data2, in1.
data(),(in1.
size())*
sizeof(DataType));
51 gpu1.
device(sycl_device) = gpu1 * 3.14f;
52 gpu2.
device(sycl_device) = gpu2 * 2.7f;
53 sycl_device.memcpyDeviceToHost(out1.
data(), gpu_data1,(out1.
size())*
sizeof(DataType));
54 sycl_device.memcpyDeviceToHost(out2.
data(), gpu_data1,(out2.
size())*
sizeof(DataType));
55 sycl_device.memcpyDeviceToHost(out3.
data(), gpu_data2,(out3.
size())*
sizeof(DataType));
56 sycl_device.synchronize();
58 for (IndexType
i = 0;
i < in1.
size(); ++
i) {
65 sycl_device.deallocate(gpu_data1);
66 sycl_device.deallocate(gpu_data2);
69 template <
typename DataType,
int DataLayout,
typename IndexType>
80 DataType* gpu_data =
static_cast<DataType*
>(sycl_device.allocate(in1.
size()*
sizeof(DataType)));
83 sycl_device.memcpyHostToDevice(gpu_data, in1.
data(),(in1.
size())*
sizeof(DataType));
84 sycl_device.synchronize();
87 sycl_device.memcpyDeviceToHost(out.
data(), gpu_data, out.
size()*
sizeof(DataType));
88 sycl_device.synchronize();
90 for (IndexType
i = 0;
i < in1.
size(); ++
i) {
94 sycl_device.deallocate(gpu_data);
97 template <
typename DataType,
int DataLayout,
typename IndexType>
100 IndexType full_size = 32;
101 IndexType half_size = full_size / 2;
103 tensor_type in1(tensorRange);
104 tensor_type
out(tensorRange);
106 DataType* gpu_data =
static_cast<DataType*
>(sycl_device.allocate(full_size *
sizeof(DataType)));
111 sycl_device.memcpyHostToDevice(gpu_data, in1.data(), full_size *
sizeof(DataType));
112 sycl_device.memcpyDeviceToHost(out.data(), gpu_data + half_size, half_size *
sizeof(DataType));
113 sycl_device.memcpyDeviceToHost(out.data() + half_size, gpu_data, half_size *
sizeof(DataType));
115 for (IndexType
i = 0;
i < half_size; ++
i) {
123 sycl_device.memcpyHostToDevice(gpu_data + half_size, in1.data(), half_size *
sizeof(DataType));
124 sycl_device.memcpyHostToDevice(gpu_data, in1.data() + half_size, half_size *
sizeof(DataType));
125 sycl_device.memcpyDeviceToHost(out.data(), gpu_data, full_size *
sizeof(DataType));
127 for (IndexType
i = 0;
i < half_size; ++
i) {
134 DataType* gpu_data_out =
static_cast<DataType*
>(sycl_device.allocate(full_size *
sizeof(DataType)));
137 sycl_device.memcpyHostToDevice(gpu_data, in1.data(), full_size *
sizeof(DataType));
138 sycl_device.memcpy(gpu_data_out + half_size, gpu_data, half_size *
sizeof(DataType));
139 sycl_device.memcpy(gpu_data_out, gpu_data + half_size, half_size *
sizeof(DataType));
140 sycl_device.memcpyDeviceToHost(out.data(), gpu_data_out, full_size *
sizeof(DataType));
142 for (IndexType
i = 0;
i < half_size; ++
i) {
147 sycl_device.deallocate(gpu_data_out);
148 sycl_device.deallocate(gpu_data);
151 template <
typename DataType,
int DataLayout,
typename IndexType>
154 IndexType full_size = 32;
155 IndexType half_size = full_size / 2;
157 tensor_type cpu_out(tensorRange);
158 tensor_type
out(tensorRange);
162 std::memset(cpu_out.data(), 0, half_size *
sizeof(DataType));
163 std::memset(cpu_out.data() + half_size, 1, half_size *
sizeof(DataType));
165 DataType* gpu_data =
static_cast<DataType*
>(sycl_device.allocate(full_size *
sizeof(DataType)));
168 sycl_device.memset(gpu_data, 0, half_size *
sizeof(DataType));
169 sycl_device.memset(gpu_data + half_size, 1, half_size *
sizeof(DataType));
170 sycl_device.memcpyDeviceToHost(out.data(), gpu_data, full_size *
sizeof(DataType));
172 for (IndexType
i = 0;
i < full_size; ++
i) {
176 sycl_device.deallocate(gpu_data);
179 template <
typename DataType,
int DataLayout,
typename IndexType>
182 IndexType sizeDim1 = 100;
183 IndexType sizeDim2 = 10;
184 IndexType sizeDim3 = 20;
194 DataType * gpu_in1_data =
static_cast<DataType*
>(sycl_device.allocate(in1.
size()*
sizeof(DataType)));
195 DataType * gpu_in2_data =
static_cast<DataType*
>(sycl_device.allocate(in2.
size()*
sizeof(DataType)));
196 DataType * gpu_in3_data =
static_cast<DataType*
>(sycl_device.allocate(in3.
size()*
sizeof(DataType)));
197 DataType * gpu_out_data =
static_cast<DataType*
>(sycl_device.allocate(out.
size()*
sizeof(DataType)));
205 gpu_in1.
device(sycl_device) = gpu_in1.constant(1.2
f);
206 sycl_device.memcpyDeviceToHost(in1.
data(), gpu_in1_data ,(in1.
size())*
sizeof(DataType));
207 sycl_device.synchronize();
209 for (IndexType
i = 0;
i < sizeDim1; ++
i) {
210 for (IndexType
j = 0;
j < sizeDim2; ++
j) {
211 for (IndexType k = 0; k < sizeDim3; ++k) {
216 printf(
"a=1.2f Test passed\n");
219 gpu_out.
device(sycl_device) = gpu_in1 * 1.2f;
220 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data ,(out.
size())*
sizeof(DataType));
221 sycl_device.synchronize();
223 for (IndexType
i = 0;
i < sizeDim1; ++
i) {
224 for (IndexType
j = 0;
j < sizeDim2; ++
j) {
225 for (IndexType k = 0; k < sizeDim3; ++k) {
231 printf(
"a=b*1.2f Test Passed\n");
234 sycl_device.memcpyHostToDevice(gpu_in2_data, in2.
data(),(in2.
size())*
sizeof(DataType));
235 gpu_out.
device(sycl_device) = gpu_in1 * gpu_in2;
236 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data,(out.
size())*
sizeof(DataType));
237 sycl_device.synchronize();
239 for (IndexType
i = 0;
i < sizeDim1; ++
i) {
240 for (IndexType
j = 0;
j < sizeDim2; ++
j) {
241 for (IndexType k = 0; k < sizeDim3; ++k) {
248 printf(
"c=a*b Test Passed\n");
251 gpu_out.
device(sycl_device) = gpu_in1 + gpu_in2;
252 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data,(out.
size())*
sizeof(DataType));
253 sycl_device.synchronize();
254 for (IndexType
i = 0;
i < sizeDim1; ++
i) {
255 for (IndexType
j = 0;
j < sizeDim2; ++
j) {
256 for (IndexType k = 0; k < sizeDim3; ++k) {
263 printf(
"c=a+b Test Passed\n");
266 gpu_out.
device(sycl_device) = gpu_in1 * gpu_in1;
267 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data,(out.
size())*
sizeof(DataType));
268 sycl_device.synchronize();
269 for (IndexType
i = 0;
i < sizeDim1; ++
i) {
270 for (IndexType
j = 0;
j < sizeDim2; ++
j) {
271 for (IndexType k = 0; k < sizeDim3; ++k) {
278 printf(
"c= a*a Test Passed\n");
281 gpu_out.
device(sycl_device) = gpu_in1 * gpu_in1.constant(3.14
f) + gpu_in2 * gpu_in2.constant(2.7
f);
282 sycl_device.memcpyDeviceToHost(out.
data(),gpu_out_data,(out.
size())*
sizeof(DataType));
283 sycl_device.synchronize();
284 for (IndexType
i = 0;
i < sizeDim1; ++
i) {
285 for (IndexType
j = 0;
j < sizeDim2; ++
j) {
286 for (IndexType k = 0; k < sizeDim3; ++k) {
289 + in2(
i,
j,k) * 2.7
f);
293 printf(
"a*3.14f + b*2.7f Test Passed\n");
296 sycl_device.memcpyHostToDevice(gpu_in3_data, in3.
data(),(in3.
size())*
sizeof(DataType));
297 gpu_out.
device(sycl_device) =(gpu_in1 > gpu_in1.constant(0.5
f)).select(gpu_in2, gpu_in3);
298 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data,(out.
size())*
sizeof(DataType));
299 sycl_device.synchronize();
300 for (IndexType
i = 0;
i < sizeDim1; ++
i) {
301 for (IndexType
j = 0;
j < sizeDim2; ++
j) {
302 for (IndexType k = 0; k < sizeDim3; ++k) {
309 printf(
"d= (a>0.5? b:c) Test Passed\n");
310 sycl_device.deallocate(gpu_in1_data);
311 sycl_device.deallocate(gpu_in2_data);
312 sycl_device.deallocate(gpu_in3_data);
313 sycl_device.deallocate(gpu_out_data);
315 template<
typename Scalar1,
typename Scalar2,
int DataLayout,
typename IndexType>
325 Scalar1* gpu_in_data =
static_cast<Scalar1*
>(sycl_device.allocate(in.
size()*
sizeof(Scalar1)));
326 Scalar2 * gpu_out_data =
static_cast<Scalar2*
>(sycl_device.allocate(out.
size()*
sizeof(Scalar2)));
330 sycl_device.memcpyHostToDevice(gpu_in_data, in.
data(),(in.
size())*
sizeof(Scalar1));
331 gpu_out.
device(sycl_device) = gpu_in.
template cast<Scalar2>();
332 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data, out.
size()*
sizeof(Scalar2));
333 out_host = in.
template cast<Scalar2>();
334 for(IndexType
i=0;
i<
size;
i++)
338 printf(
"cast Test Passed\n");
339 sycl_device.deallocate(gpu_in_data);
340 sycl_device.deallocate(gpu_out_data);
343 QueueInterface queueInterface(s);
344 auto sycl_device = Eigen::SyclDevice(&queueInterface);
345 test_sycl_mem_transfers<DataType, RowMajor, int64_t>(sycl_device);
346 test_sycl_computations<DataType, RowMajor, int64_t>(sycl_device);
347 test_sycl_mem_sync<DataType, RowMajor, int64_t>(sycl_device);
348 test_sycl_mem_sync_offsets<DataType, RowMajor, int64_t>(sycl_device);
349 test_sycl_memset_offsets<DataType, RowMajor, int64_t>(sycl_device);
350 test_sycl_mem_transfers<DataType, ColMajor, int64_t>(sycl_device);
351 test_sycl_computations<DataType, ColMajor, int64_t>(sycl_device);
352 test_sycl_mem_sync<DataType, ColMajor, int64_t>(sycl_device);
358 for (
const auto& device :Eigen::get_sycl_supported_devices()) {
359 CALL_SUBTEST(sycl_computing_test_per_device<float>(device));
void test_sycl_mem_sync_offsets(const Eigen::SyclDevice &sycl_device)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
std::ofstream out("Result.txt")
EIGEN_DECLARE_TEST(cxx11_tensor_sycl)
void test_sycl_computations(const Eigen::SyclDevice &sycl_device)
#define VERIFY_IS_APPROX(a, b)
A tensor expression mapping an existing array of data.
void test_sycl_mem_sync(const Eigen::SyclDevice &sycl_device)
static void test_sycl_cast(const Eigen::SyclDevice &sycl_device)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
TensorDevice< TensorMap< PlainObjectType, Options_, MakePointer_ >, DeviceType > device(const DeviceType &dev)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
#define CALL_SUBTEST(FUNC)
void test_sycl_mem_transfers(const Eigen::SyclDevice &sycl_device)
void test_sycl_memset_offsets(const Eigen::SyclDevice &sycl_device)
void sycl_computing_test_per_device(dev_Selector s)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setZero()