16 #define EIGEN_TEST_NO_LONGDOUBLE 17 #define EIGEN_TEST_NO_COMPLEX 18 #define EIGEN_TEST_FUNC cxx11_tensor_sycl 19 #define EIGEN_DEFAULT_DENSE_INDEX_TYPE int 20 #define EIGEN_USE_SYCL 23 #include <unsupported/Eigen/CXX11/Tensor> 26 using Eigen::SyclDevice;
44 float * gpu_in1_data =
static_cast<float*
>(sycl_device.allocate(in1.
dimensions().TotalSize()*
sizeof(float)));
45 float * gpu_in2_data =
static_cast<float*
>(sycl_device.allocate(in2.
dimensions().TotalSize()*
sizeof(float)));
46 float * gpu_in3_data =
static_cast<float*
>(sycl_device.allocate(in3.
dimensions().TotalSize()*
sizeof(float)));
47 float * gpu_out_data =
static_cast<float*
>(sycl_device.allocate(out.
dimensions().TotalSize()*
sizeof(float)));
55 gpu_in1.
device(sycl_device) = gpu_in1.constant(1.2
f);
56 sycl_device.memcpyDeviceToHost(in1.
data(), gpu_in1_data ,(in1.
dimensions().TotalSize())*
sizeof(
float));
57 for (
int i = 0; i < sizeDim1; ++i) {
58 for (
int j = 0; j < sizeDim2; ++j) {
59 for (
int k = 0; k < sizeDim3; ++k) {
60 VERIFY_IS_APPROX(in1(i,j,k), 1.2
f);
64 printf(
"a=1.2f Test passed\n");
67 gpu_out.
device(sycl_device) = gpu_in1 * 1.2f;
68 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data ,(out.
dimensions().TotalSize())*
sizeof(
float));
69 for (
int i = 0; i < sizeDim1; ++i) {
70 for (
int j = 0; j < sizeDim2; ++j) {
71 for (
int k = 0; k < sizeDim3; ++k) {
72 VERIFY_IS_APPROX(out(i,j,k),
77 printf(
"a=b*1.2f Test Passed\n");
80 sycl_device.memcpyHostToDevice(gpu_in2_data, in2.
data(),(in2.
dimensions().TotalSize())*
sizeof(
float));
81 gpu_out.
device(sycl_device) = gpu_in1 * gpu_in2;
82 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data,(out.
dimensions().TotalSize())*
sizeof(
float));
83 for (
int i = 0; i < sizeDim1; ++i) {
84 for (
int j = 0; j < sizeDim2; ++j) {
85 for (
int k = 0; k < sizeDim3; ++k) {
86 VERIFY_IS_APPROX(out(i,j,k),
92 printf(
"c=a*b Test Passed\n");
95 gpu_out.
device(sycl_device) = gpu_in1 + gpu_in2;
96 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data,(out.
dimensions().TotalSize())*
sizeof(
float));
97 for (
int i = 0; i < sizeDim1; ++i) {
98 for (
int j = 0; j < sizeDim2; ++j) {
99 for (
int k = 0; k < sizeDim3; ++k) {
100 VERIFY_IS_APPROX(out(i,j,k),
106 printf(
"c=a+b Test Passed\n");
109 gpu_out.
device(sycl_device) = gpu_in1 * gpu_in1;
110 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data,(out.
dimensions().TotalSize())*
sizeof(
float));
111 for (
int i = 0; i < sizeDim1; ++i) {
112 for (
int j = 0; j < sizeDim2; ++j) {
113 for (
int k = 0; k < sizeDim3; ++k) {
114 VERIFY_IS_APPROX(out(i,j,k),
120 printf(
"c= a*a Test Passed\n");
123 gpu_out.
device(sycl_device) = gpu_in1 * gpu_in1.constant(3.14
f) + gpu_in2 * gpu_in2.constant(2.7
f);
124 sycl_device.memcpyDeviceToHost(out.
data(),gpu_out_data,(out.
dimensions().TotalSize())*
sizeof(
float));
125 for (
int i = 0; i < sizeDim1; ++i) {
126 for (
int j = 0; j < sizeDim2; ++j) {
127 for (
int k = 0; k < sizeDim3; ++k) {
128 VERIFY_IS_APPROX(out(i,j,k),
130 + in2(i,j,k) * 2.7
f);
134 printf(
"a*3.14f + b*2.7f Test Passed\n");
137 sycl_device.memcpyHostToDevice(gpu_in3_data, in3.
data(),(in3.
dimensions().TotalSize())*
sizeof(
float));
138 gpu_out.
device(sycl_device) =(gpu_in1 > gpu_in1.constant(0.5
f)).select(gpu_in2, gpu_in3);
139 sycl_device.memcpyDeviceToHost(out.
data(), gpu_out_data,(out.
dimensions().TotalSize())*
sizeof(
float));
140 for (
int i = 0; i < sizeDim1; ++i) {
141 for (
int j = 0; j < sizeDim2; ++j) {
142 for (
int k = 0; k < sizeDim3; ++k) {
143 VERIFY_IS_APPROX(out(i, j, k), (in1(i, j, k) > 0.5
f)
149 printf(
"d= (a>0.5? b:c) Test Passed\n");
150 sycl_device.deallocate(gpu_in1_data);
151 sycl_device.deallocate(gpu_in2_data);
152 sycl_device.deallocate(gpu_in3_data);
153 sycl_device.deallocate(gpu_out_data);
156 cl::sycl::gpu_selector
s;
157 Eigen::SyclDevice sycl_device(s);
void test_sycl_cpu(const Eigen::SyclDevice &sycl_device)
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
TensorDevice< TensorMap< PlainObjectType, Options_, MakePointer_ >, DeviceType > device(const DeviceType &device)
void test_cxx11_tensor_sycl()
A tensor expression mapping an existing array of data.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Dimensions & dimensions() const