mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Reducing warnings in Sycl backend.
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
#define EIGEN_TEST_NO_LONGDOUBLE
|
||||
#define EIGEN_TEST_NO_COMPLEX
|
||||
#define EIGEN_TEST_FUNC cxx11_tensor_sycl
|
||||
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int
|
||||
#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int64_t
|
||||
#define EIGEN_USE_SYCL
|
||||
|
||||
#include "main.h"
|
||||
@@ -27,24 +27,24 @@ using Eigen::SyclDevice;
|
||||
using Eigen::Tensor;
|
||||
using Eigen::TensorMap;
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
template <typename DataType, int DataLayout, typename IndexType>
|
||||
void test_sycl_mem_transfers(const Eigen::SyclDevice &sycl_device) {
|
||||
int sizeDim1 = 100;
|
||||
int sizeDim2 = 10;
|
||||
int sizeDim3 = 20;
|
||||
array<int, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
|
||||
Tensor<DataType, 3, DataLayout> in1(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout> out1(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout> out2(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout> out3(tensorRange);
|
||||
IndexType sizeDim1 = 100;
|
||||
IndexType sizeDim2 = 10;
|
||||
IndexType sizeDim3 = 20;
|
||||
array<IndexType, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
|
||||
Tensor<DataType, 3, DataLayout, IndexType> in1(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout, IndexType> out1(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout, IndexType> out2(tensorRange);
|
||||
Tensor<DataType, 3, DataLayout, IndexType> out3(tensorRange);
|
||||
|
||||
in1 = in1.random();
|
||||
|
||||
DataType* gpu_data1 = static_cast<DataType*>(sycl_device.allocate(in1.size()*sizeof(DataType)));
|
||||
DataType* gpu_data2 = static_cast<DataType*>(sycl_device.allocate(out1.size()*sizeof(DataType)));
|
||||
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu1(gpu_data1, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu2(gpu_data2, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu1(gpu_data1, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu2(gpu_data2, tensorRange);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_data1, in1.data(),(in1.size())*sizeof(DataType));
|
||||
sycl_device.memcpyHostToDevice(gpu_data2, in1.data(),(in1.size())*sizeof(DataType));
|
||||
@@ -55,7 +55,7 @@ void test_sycl_mem_transfers(const Eigen::SyclDevice &sycl_device) {
|
||||
sycl_device.memcpyDeviceToHost(out3.data(), gpu_data2,(out3.size())*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
|
||||
for (int i = 0; i < in1.size(); ++i) {
|
||||
for (IndexType i = 0; i < in1.size(); ++i) {
|
||||
VERIFY_IS_APPROX(out1(i), in1(i) * 3.14f);
|
||||
VERIFY_IS_APPROX(out2(i), in1(i) * 3.14f);
|
||||
VERIFY_IS_APPROX(out3(i), in1(i) * 2.7f);
|
||||
@@ -65,20 +65,20 @@ void test_sycl_mem_transfers(const Eigen::SyclDevice &sycl_device) {
|
||||
sycl_device.deallocate(gpu_data2);
|
||||
}
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
template <typename DataType, int DataLayout, typename IndexType>
|
||||
void test_sycl_mem_sync(const Eigen::SyclDevice &sycl_device) {
|
||||
int size = 20;
|
||||
array<int, 1> tensorRange = {{size}};
|
||||
Tensor<DataType, 1, DataLayout> in1(tensorRange);
|
||||
Tensor<DataType, 1, DataLayout> in2(tensorRange);
|
||||
Tensor<DataType, 1, DataLayout> out(tensorRange);
|
||||
IndexType size = 20;
|
||||
array<IndexType, 1> tensorRange = {{size}};
|
||||
Tensor<DataType, 1, DataLayout, IndexType> in1(tensorRange);
|
||||
Tensor<DataType, 1, DataLayout, IndexType> in2(tensorRange);
|
||||
Tensor<DataType, 1, DataLayout, IndexType> out(tensorRange);
|
||||
|
||||
in1 = in1.random();
|
||||
in2 = in1;
|
||||
|
||||
DataType* gpu_data = static_cast<DataType*>(sycl_device.allocate(in1.size()*sizeof(DataType)));
|
||||
|
||||
TensorMap<Tensor<DataType, 1, DataLayout>> gpu1(gpu_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 1, DataLayout, IndexType>> gpu1(gpu_data, tensorRange);
|
||||
sycl_device.memcpyHostToDevice(gpu_data, in1.data(),(in1.size())*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
in1.setZero();
|
||||
@@ -86,24 +86,24 @@ void test_sycl_mem_sync(const Eigen::SyclDevice &sycl_device) {
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_data, out.size()*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
|
||||
for (int i = 0; i < in1.size(); ++i) {
|
||||
for (IndexType i = 0; i < in1.size(); ++i) {
|
||||
VERIFY_IS_APPROX(out(i), in2(i));
|
||||
}
|
||||
|
||||
sycl_device.deallocate(gpu_data);
|
||||
}
|
||||
|
||||
template <typename DataType, int DataLayout>
|
||||
template <typename DataType, int DataLayout, typename IndexType>
|
||||
void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
int sizeDim1 = 100;
|
||||
int sizeDim2 = 10;
|
||||
int sizeDim3 = 20;
|
||||
array<int, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
|
||||
Tensor<DataType, 3,DataLayout> in1(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout> in2(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout> in3(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout> out(tensorRange);
|
||||
IndexType sizeDim1 = 100;
|
||||
IndexType sizeDim2 = 10;
|
||||
IndexType sizeDim3 = 20;
|
||||
array<IndexType, 3> tensorRange = {{sizeDim1, sizeDim2, sizeDim3}};
|
||||
Tensor<DataType, 3,DataLayout, IndexType> in1(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout, IndexType> in2(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout, IndexType> in3(tensorRange);
|
||||
Tensor<DataType, 3,DataLayout, IndexType> out(tensorRange);
|
||||
|
||||
in2 = in2.random();
|
||||
in3 = in3.random();
|
||||
@@ -113,19 +113,19 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
DataType * gpu_in3_data = static_cast<DataType*>(sycl_device.allocate(in3.size()*sizeof(DataType)));
|
||||
DataType * gpu_out_data = static_cast<DataType*>(sycl_device.allocate(out.size()*sizeof(DataType)));
|
||||
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu_in1(gpu_in1_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu_in2(gpu_in2_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu_in3(gpu_in3_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout>> gpu_out(gpu_out_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_in1(gpu_in1_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_in2(gpu_in2_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_in3(gpu_in3_data, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_out(gpu_out_data, tensorRange);
|
||||
|
||||
/// a=1.2f
|
||||
gpu_in1.device(sycl_device) = gpu_in1.constant(1.2f);
|
||||
sycl_device.memcpyDeviceToHost(in1.data(), gpu_in1_data ,(in1.size())*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
for (IndexType i = 0; i < sizeDim1; ++i) {
|
||||
for (IndexType j = 0; j < sizeDim2; ++j) {
|
||||
for (IndexType k = 0; k < sizeDim3; ++k) {
|
||||
VERIFY_IS_APPROX(in1(i,j,k), 1.2f);
|
||||
}
|
||||
}
|
||||
@@ -137,9 +137,9 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data ,(out.size())*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
for (IndexType i = 0; i < sizeDim1; ++i) {
|
||||
for (IndexType j = 0; j < sizeDim2; ++j) {
|
||||
for (IndexType k = 0; k < sizeDim3; ++k) {
|
||||
VERIFY_IS_APPROX(out(i,j,k),
|
||||
in1(i,j,k) * 1.2f);
|
||||
}
|
||||
@@ -153,9 +153,9 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
for (IndexType i = 0; i < sizeDim1; ++i) {
|
||||
for (IndexType j = 0; j < sizeDim2; ++j) {
|
||||
for (IndexType k = 0; k < sizeDim3; ++k) {
|
||||
VERIFY_IS_APPROX(out(i,j,k),
|
||||
in1(i,j,k) *
|
||||
in2(i,j,k));
|
||||
@@ -168,9 +168,9 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
gpu_out.device(sycl_device) = gpu_in1 + gpu_in2;
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
for (IndexType i = 0; i < sizeDim1; ++i) {
|
||||
for (IndexType j = 0; j < sizeDim2; ++j) {
|
||||
for (IndexType k = 0; k < sizeDim3; ++k) {
|
||||
VERIFY_IS_APPROX(out(i,j,k),
|
||||
in1(i,j,k) +
|
||||
in2(i,j,k));
|
||||
@@ -183,9 +183,9 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
gpu_out.device(sycl_device) = gpu_in1 * gpu_in1;
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
for (IndexType i = 0; i < sizeDim1; ++i) {
|
||||
for (IndexType j = 0; j < sizeDim2; ++j) {
|
||||
for (IndexType k = 0; k < sizeDim3; ++k) {
|
||||
VERIFY_IS_APPROX(out(i,j,k),
|
||||
in1(i,j,k) *
|
||||
in1(i,j,k));
|
||||
@@ -198,9 +198,9 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
gpu_out.device(sycl_device) = gpu_in1 * gpu_in1.constant(3.14f) + gpu_in2 * gpu_in2.constant(2.7f);
|
||||
sycl_device.memcpyDeviceToHost(out.data(),gpu_out_data,(out.size())*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
for (IndexType i = 0; i < sizeDim1; ++i) {
|
||||
for (IndexType j = 0; j < sizeDim2; ++j) {
|
||||
for (IndexType k = 0; k < sizeDim3; ++k) {
|
||||
VERIFY_IS_APPROX(out(i,j,k),
|
||||
in1(i,j,k) * 3.14f
|
||||
+ in2(i,j,k) * 2.7f);
|
||||
@@ -214,9 +214,9 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
gpu_out.device(sycl_device) =(gpu_in1 > gpu_in1.constant(0.5f)).select(gpu_in2, gpu_in3);
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.size())*sizeof(DataType));
|
||||
sycl_device.synchronize();
|
||||
for (int i = 0; i < sizeDim1; ++i) {
|
||||
for (int j = 0; j < sizeDim2; ++j) {
|
||||
for (int k = 0; k < sizeDim3; ++k) {
|
||||
for (IndexType i = 0; i < sizeDim1; ++i) {
|
||||
for (IndexType j = 0; j < sizeDim2; ++j) {
|
||||
for (IndexType k = 0; k < sizeDim3; ++k) {
|
||||
VERIFY_IS_APPROX(out(i, j, k), (in1(i, j, k) > 0.5f)
|
||||
? in2(i, j, k)
|
||||
: in3(i, j, k));
|
||||
@@ -229,26 +229,26 @@ void test_sycl_computations(const Eigen::SyclDevice &sycl_device) {
|
||||
sycl_device.deallocate(gpu_in3_data);
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
template<typename Scalar1, typename Scalar2, int DataLayout>
|
||||
template<typename Scalar1, typename Scalar2, int DataLayout, typename IndexType>
|
||||
static void test_sycl_cast(const Eigen::SyclDevice& sycl_device){
|
||||
int size = 20;
|
||||
array<int, 1> tensorRange = {{size}};
|
||||
Tensor<Scalar1, 1, DataLayout> in(tensorRange);
|
||||
Tensor<Scalar2, 1, DataLayout> out(tensorRange);
|
||||
Tensor<Scalar2, 1, DataLayout> out_host(tensorRange);
|
||||
IndexType size = 20;
|
||||
array<IndexType, 1> tensorRange = {{size}};
|
||||
Tensor<Scalar1, 1, DataLayout, IndexType> in(tensorRange);
|
||||
Tensor<Scalar2, 1, DataLayout, IndexType> out(tensorRange);
|
||||
Tensor<Scalar2, 1, DataLayout, IndexType> out_host(tensorRange);
|
||||
|
||||
in = in.random();
|
||||
|
||||
Scalar1* gpu_in_data = static_cast<Scalar1*>(sycl_device.allocate(in.size()*sizeof(Scalar1)));
|
||||
Scalar2 * gpu_out_data = static_cast<Scalar2*>(sycl_device.allocate(out.size()*sizeof(Scalar2)));
|
||||
|
||||
TensorMap<Tensor<Scalar1, 1, DataLayout>> gpu_in(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<Scalar2, 1, DataLayout>> gpu_out(gpu_out_data, tensorRange);
|
||||
TensorMap<Tensor<Scalar1, 1, DataLayout, IndexType>> gpu_in(gpu_in_data, tensorRange);
|
||||
TensorMap<Tensor<Scalar2, 1, DataLayout, IndexType>> gpu_out(gpu_out_data, tensorRange);
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, in.data(),(in.size())*sizeof(Scalar1));
|
||||
gpu_out.device(sycl_device) = gpu_in. template cast<Scalar2>();
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data, out.size()*sizeof(Scalar2));
|
||||
out_host = in. template cast<Scalar2>();
|
||||
for(int i=0; i< size; i++)
|
||||
for(IndexType i=0; i< size; i++)
|
||||
{
|
||||
VERIFY_IS_APPROX(out(i), out_host(i));
|
||||
}
|
||||
@@ -259,14 +259,14 @@ static void test_sycl_cast(const Eigen::SyclDevice& sycl_device){
|
||||
template<typename DataType, typename dev_Selector> void sycl_computing_test_per_device(dev_Selector s){
|
||||
QueueInterface queueInterface(s);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
test_sycl_mem_transfers<DataType, RowMajor>(sycl_device);
|
||||
test_sycl_computations<DataType, RowMajor>(sycl_device);
|
||||
test_sycl_mem_sync<DataType, RowMajor>(sycl_device);
|
||||
test_sycl_mem_transfers<DataType, ColMajor>(sycl_device);
|
||||
test_sycl_computations<DataType, ColMajor>(sycl_device);
|
||||
test_sycl_mem_sync<DataType, ColMajor>(sycl_device);
|
||||
test_sycl_cast<DataType, int, RowMajor>(sycl_device);
|
||||
test_sycl_cast<DataType, int, ColMajor>(sycl_device);
|
||||
test_sycl_mem_transfers<DataType, RowMajor, int64_t>(sycl_device);
|
||||
test_sycl_computations<DataType, RowMajor, int64_t>(sycl_device);
|
||||
test_sycl_mem_sync<DataType, RowMajor, int64_t>(sycl_device);
|
||||
test_sycl_mem_transfers<DataType, ColMajor, int64_t>(sycl_device);
|
||||
test_sycl_computations<DataType, ColMajor, int64_t>(sycl_device);
|
||||
test_sycl_mem_sync<DataType, ColMajor, int64_t>(sycl_device);
|
||||
test_sycl_cast<DataType, int, RowMajor, int64_t>(sycl_device);
|
||||
test_sycl_cast<DataType, int, ColMajor, int64_t>(sycl_device);
|
||||
}
|
||||
|
||||
void test_cxx11_tensor_sycl() {
|
||||
|
||||
Reference in New Issue
Block a user