aboutsummaryrefslogtreecommitdiffhomepage
path: root/unsupported/test/cxx11_tensor_contract_sycl.cpp
diff options
context:
space:
mode:
authorGravatar Mehdi Goli <mehdi.goli@codeplay.com>2017-02-01 15:29:53 +0000
committerGravatar Mehdi Goli <mehdi.goli@codeplay.com>2017-02-01 15:29:53 +0000
commitbab29936a1cf0a68ffe4ccb1fd9b4807a3ec87ae (patch)
treec750b36227a31ddb2a1e0d5fd11f0036fda775db /unsupported/test/cxx11_tensor_contract_sycl.cpp
parent48a20b7d956433713a39e04d39cba443b7a763de (diff)
Reducing warnings in Sycl backend.
Diffstat (limited to 'unsupported/test/cxx11_tensor_contract_sycl.cpp')
-rw-r--r--unsupported/test/cxx11_tensor_contract_sycl.cpp198
1 files changed, 101 insertions, 97 deletions
diff --git a/unsupported/test/cxx11_tensor_contract_sycl.cpp b/unsupported/test/cxx11_tensor_contract_sycl.cpp
index cb8fcb74c..41acd5579 100644
--- a/unsupported/test/cxx11_tensor_contract_sycl.cpp
+++ b/unsupported/test/cxx11_tensor_contract_sycl.cpp
@@ -14,7 +14,7 @@
#define EIGEN_TEST_NO_LONGDOUBLE
#define EIGEN_TEST_NO_COMPLEX
#define EIGEN_TEST_FUNC cxx11_tensor_contract_sycl
-#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int
+#define EIGEN_DEFAULT_DENSE_INDEX_TYPE int64_t
#define EIGEN_USE_SYCL
#include <iostream>
@@ -28,39 +28,39 @@ using Eigen::array;
using Eigen::SyclDevice;
using Eigen::Tensor;
using Eigen::TensorMap;
-static const float error_threshold =1e-4f;
-typedef Tensor<float, 1>::DimensionPair DimPair;
-template<int DataLayout, typename Device>
-void test_sycl_contraction(const Device& sycl_device, int m_size, int k_size, int n_size)
+template<int DataLayout, typename DataType, typename IndexType, typename Device>
+void static test_sycl_contraction(const Device& sycl_device, IndexType m_size, IndexType k_size, IndexType n_size)
{
+ typedef typename Tensor<DataType, 1, DataLayout, IndexType>::DimensionPair DimPair;
+ static const DataType error_threshold =1e-4f;
// std::cout << "Testing for (" << m_size << "," << k_size << "," << n_size << ")" << std::endl;
// with these dimensions, the output has 300 * 140 elements, which is
// more than 30 * 1024, which is the number of threads in blocks on
// a 15 SM GK110 GPU
- Tensor<float, 2, DataLayout> t_left(m_size, k_size);
- Tensor<float, 2, DataLayout> t_right(k_size, n_size);
- Tensor<float, 2, DataLayout> t_result(m_size, n_size);
- Tensor<float, 2, DataLayout> t_result_gpu(m_size, n_size);
+ Tensor<DataType, 2, DataLayout, IndexType> t_left(m_size, k_size);
+ Tensor<DataType, 2, DataLayout, IndexType> t_right(k_size, n_size);
+ Tensor<DataType, 2, DataLayout, IndexType> t_result(m_size, n_size);
+ Tensor<DataType, 2, DataLayout, IndexType> t_result_gpu(m_size, n_size);
// Eigen::array<DimPair, 1> dims(DimPair(1, 0));
Eigen::array<DimPair, 1> dims = {{DimPair(1, 0)}};
- Eigen::array<int, 2> left_dims = {{m_size, k_size}};
- Eigen::array<int, 2> right_dims = {{k_size, n_size}};
- Eigen::array<int, 2> result_dims = {{m_size, n_size}};
+ Eigen::array<IndexType, 2> left_dims = {{m_size, k_size}};
+ Eigen::array<IndexType, 2> right_dims = {{k_size, n_size}};
+ Eigen::array<IndexType, 2> result_dims = {{m_size, n_size}};
t_left.setRandom();
t_right.setRandom();
- std::size_t t_left_bytes = t_left.size() * sizeof(float);
- std::size_t t_right_bytes = t_right.size() * sizeof(float);
- std::size_t t_result_bytes = t_result.size() * sizeof(float);
+ std::size_t t_left_bytes = t_left.size() * sizeof(DataType);
+ std::size_t t_right_bytes = t_right.size() * sizeof(DataType);
+ std::size_t t_result_bytes = t_result.size() * sizeof(DataType);
- float * d_t_left = static_cast<float*>(sycl_device.allocate(t_left_bytes));
- float * d_t_right = static_cast<float*>(sycl_device.allocate(t_right_bytes));
- float * d_t_result = static_cast<float*>(sycl_device.allocate(t_result_bytes));
+ DataType * d_t_left = static_cast<DataType*>(sycl_device.allocate(t_left_bytes));
+ DataType * d_t_right = static_cast<DataType*>(sycl_device.allocate(t_right_bytes));
+ DataType * d_t_result = static_cast<DataType*>(sycl_device.allocate(t_result_bytes));
- Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout> > gpu_t_left(d_t_left, left_dims);
- Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout> > gpu_t_right(d_t_right, right_dims);
- Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout> > gpu_t_result(d_t_result, result_dims);
+ Eigen::TensorMap<Eigen::Tensor<DataType, 2, DataLayout, IndexType> > gpu_t_left(d_t_left, left_dims);
+ Eigen::TensorMap<Eigen::Tensor<DataType, 2, DataLayout, IndexType> > gpu_t_right(d_t_right, right_dims);
+ Eigen::TensorMap<Eigen::Tensor<DataType, 2, DataLayout, IndexType> > gpu_t_result(d_t_result, result_dims);
sycl_device.memcpyHostToDevice(d_t_left, t_left.data(),t_left_bytes);
sycl_device.memcpyHostToDevice(d_t_right, t_right.data(),t_right_bytes);
@@ -70,14 +70,14 @@ void test_sycl_contraction(const Device& sycl_device, int m_size, int k_size, in
t_result = t_left.contract(t_right, dims);
- for (DenseIndex i = 0; i < t_result.size(); i++) {
- if (static_cast<float>(fabs(t_result(i) - t_result_gpu(i))) < error_threshold) {
+ for (IndexType i = 0; i < t_result.size(); i++) {
+ if (static_cast<DataType>(fabs(t_result(i) - t_result_gpu(i))) < error_threshold) {
continue;
}
if (Eigen::internal::isApprox(t_result(i), t_result_gpu(i), error_threshold)) {
continue;
}
- std::cout << "mismatch detected at index " << i << ": " << t_result(i)
+ std::cout << "mismatch detected at IndexType " << i << ": " << t_result(i)
<< " vs " << t_result_gpu(i) << std::endl;
assert(false);
}
@@ -86,19 +86,21 @@ void test_sycl_contraction(const Device& sycl_device, int m_size, int k_size, in
sycl_device.deallocate(d_t_result);
}
-template<int DataLayout, typename Device>
+template<int DataLayout, typename DataType, typename IndexType, typename Device>
void test_TF(const Device& sycl_device)
{
- Eigen::array<long, 2> left_dims = {{2, 3}};
- Eigen::array<long, 2> right_dims = {{3, 1}};
- Eigen::array<long, 2> res_dims = {{2, 1}};
+ typedef typename Tensor<DataType, 1, DataLayout, IndexType>::DimensionPair DimPair;
+ static const DataType error_threshold =1e-4f;
+ Eigen::array<IndexType, 2> left_dims = {{2, 3}};
+ Eigen::array<IndexType, 2> right_dims = {{3, 1}};
+ Eigen::array<IndexType, 2> res_dims = {{2, 1}};
Eigen::array<DimPair, 1> dims = {{DimPair(1, 0)}};
- Tensor<float, 2, DataLayout, long> t_left(left_dims);
- Tensor<float, 2, DataLayout, long> t_right(right_dims);
- Tensor<float, 2, DataLayout, long> t_result_gpu(res_dims);
- Tensor<float, 2, DataLayout, long> t_result(res_dims);
+ Tensor<DataType, 2, DataLayout, IndexType> t_left(left_dims);
+ Tensor<DataType, 2, DataLayout, IndexType> t_right(right_dims);
+ Tensor<DataType, 2, DataLayout, IndexType> t_result_gpu(res_dims);
+ Tensor<DataType, 2, DataLayout, IndexType> t_result(res_dims);
t_left.data()[0] = 1.0f;
t_left.data()[1] = 2.0f;
@@ -111,18 +113,18 @@ void test_TF(const Device& sycl_device)
t_right.data()[1] = 0.5f;
t_right.data()[2] = 2.0f;
- std::size_t t_left_bytes = t_left.size() * sizeof(float);
- std::size_t t_right_bytes = t_right.size() * sizeof(float);
- std::size_t t_result_bytes = t_result.size()*sizeof(float);
+ std::size_t t_left_bytes = t_left.size() * sizeof(DataType);
+ std::size_t t_right_bytes = t_right.size() * sizeof(DataType);
+ std::size_t t_result_bytes = t_result.size()*sizeof(DataType);
- float * d_t_left = static_cast<float*>(sycl_device.allocate(t_left_bytes));
- float * d_t_right = static_cast<float*>(sycl_device.allocate(t_right_bytes));
- float * d_t_result = static_cast<float*>(sycl_device.allocate(t_result_bytes));
+ DataType * d_t_left = static_cast<DataType*>(sycl_device.allocate(t_left_bytes));
+ DataType * d_t_right = static_cast<DataType*>(sycl_device.allocate(t_right_bytes));
+ DataType * d_t_result = static_cast<DataType*>(sycl_device.allocate(t_result_bytes));
- Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout, long> > gpu_t_left(d_t_left, left_dims);
- Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout, long> > gpu_t_right(d_t_right, right_dims);
- Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout, long> > gpu_t_result(d_t_result, res_dims);
+ Eigen::TensorMap<Eigen::Tensor<DataType, 2, DataLayout, IndexType> > gpu_t_left(d_t_left, left_dims);
+ Eigen::TensorMap<Eigen::Tensor<DataType, 2, DataLayout, IndexType> > gpu_t_right(d_t_right, right_dims);
+ Eigen::TensorMap<Eigen::Tensor<DataType, 2, DataLayout, IndexType> > gpu_t_result(d_t_result, res_dims);
sycl_device.memcpyHostToDevice(d_t_left, t_left.data(),t_left_bytes);
sycl_device.memcpyHostToDevice(d_t_right, t_right.data(),t_right_bytes);
@@ -132,14 +134,14 @@ void test_TF(const Device& sycl_device)
t_result = t_left.contract(t_right, dims);
- for (DenseIndex i = 0; i < t_result.size(); i++) {
- if (static_cast<float>(fabs(t_result(i) - t_result_gpu(i))) < error_threshold) {
+ for (IndexType i = 0; i < t_result.size(); i++) {
+ if (static_cast<DataType>(fabs(t_result(i) - t_result_gpu(i))) < error_threshold) {
continue;
}
if (Eigen::internal::isApprox(t_result(i), t_result_gpu(i), error_threshold)) {
continue;
}
- std::cout << "mismatch detected at index " << i << ": " << t_result(i)
+ std::cout << "mismatch detected at IndexType " << i << ": " << t_result(i)
<< " vs " << t_result_gpu(i) << std::endl;
assert(false);
}
@@ -150,35 +152,37 @@ void test_TF(const Device& sycl_device)
}
-template<int DataLayout, typename Device>
-void test_scalar(const Device& sycl_device, int m_size, int k_size, int n_size)
+template<int DataLayout, typename DataType, typename IndexType, typename Device>
+void test_scalar(const Device& sycl_device, IndexType m_size, IndexType k_size, IndexType n_size)
{
//std::cout << "Testing for (" << m_size << "," << k_size << "," << n_size << ")" << std::endl;
// with these dimensions, the output has 300 * 140 elements, which is
// more than 30 * 1024, which is the number of threads in blocks on
// a 15 SM GK110 GPU
- Tensor<float, 2, DataLayout> t_left(m_size, k_size);
- Tensor<float, 2, DataLayout> t_right(k_size, n_size);
- Tensor<float, 0, DataLayout> t_result;
- Tensor<float, 0, DataLayout> t_result_gpu;
+ typedef typename Tensor<DataType, 1, DataLayout, IndexType>::DimensionPair DimPair;
+ static const DataType error_threshold =1e-4f;
+ Tensor<DataType, 2, DataLayout, IndexType> t_left(m_size, k_size);
+ Tensor<DataType, 2, DataLayout, IndexType> t_right(k_size, n_size);
+ Tensor<DataType, 0, DataLayout, IndexType> t_result;
+ Tensor<DataType, 0, DataLayout, IndexType> t_result_gpu;
Eigen::array<DimPair, 2> dims = {{DimPair(0, 0), DimPair(1, 1)}};
- Eigen::array<int, 2> left_dims = {{m_size, k_size}};
- Eigen::array<int, 2> right_dims = {{k_size, n_size}};
+ Eigen::array<IndexType, 2> left_dims = {{m_size, k_size}};
+ Eigen::array<IndexType, 2> right_dims = {{k_size, n_size}};
t_left.setRandom();
t_right.setRandom();
- std::size_t t_left_bytes = t_left.size() * sizeof(float);
- std::size_t t_right_bytes = t_right.size() * sizeof(float);
- std::size_t t_result_bytes = sizeof(float);
+ std::size_t t_left_bytes = t_left.size() * sizeof(DataType);
+ std::size_t t_right_bytes = t_right.size() * sizeof(DataType);
+ std::size_t t_result_bytes = sizeof(DataType);
- float * d_t_left = static_cast<float*>(sycl_device.allocate(t_left_bytes));
- float * d_t_right = static_cast<float*>(sycl_device.allocate(t_right_bytes));
- float * d_t_result = static_cast<float*>(sycl_device.allocate(t_result_bytes));
+ DataType * d_t_left = static_cast<DataType*>(sycl_device.allocate(t_left_bytes));
+ DataType * d_t_right = static_cast<DataType*>(sycl_device.allocate(t_right_bytes));
+ DataType * d_t_result = static_cast<DataType*>(sycl_device.allocate(t_result_bytes));
- Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout> > gpu_t_left(d_t_left, left_dims);
- Eigen::TensorMap<Eigen::Tensor<float, 2, DataLayout> > gpu_t_right(d_t_right, right_dims);
- Eigen::TensorMap<Eigen::Tensor<float, 0, DataLayout> > gpu_t_result(d_t_result);
+ Eigen::TensorMap<Eigen::Tensor<DataType, 2, DataLayout, IndexType> > gpu_t_left(d_t_left, left_dims);
+ Eigen::TensorMap<Eigen::Tensor<DataType, 2, DataLayout, IndexType> > gpu_t_right(d_t_right, right_dims);
+ Eigen::TensorMap<Eigen::Tensor<DataType, 0, DataLayout, IndexType> > gpu_t_result(d_t_result);
sycl_device.memcpyHostToDevice(d_t_left, t_left.data(),t_left_bytes);
sycl_device.memcpyHostToDevice(d_t_right, t_right.data(),t_right_bytes);
@@ -188,7 +192,7 @@ void test_scalar(const Device& sycl_device, int m_size, int k_size, int n_size)
t_result = t_left.contract(t_right, dims);
- if (static_cast<float>(fabs(t_result() - t_result_gpu())) > error_threshold &&
+ if (static_cast<DataType>(fabs(t_result() - t_result_gpu())) > error_threshold &&
!Eigen::internal::isApprox(t_result(), t_result_gpu(), error_threshold)) {
std::cout << "mismatch detected: " << t_result()
<< " vs " << t_result_gpu() << std::endl;
@@ -201,47 +205,47 @@ void test_scalar(const Device& sycl_device, int m_size, int k_size, int n_size)
}
-template<int DataLayout, typename Device>
+template<int DataLayout, typename DataType, typename IndexType, typename Device>
void test_sycl_contraction_m(const Device& sycl_device) {
- for (int k = 32; k < 256; k++) {
- test_sycl_contraction<DataLayout>(sycl_device, k, 128, 128);
+ for (IndexType k = 32; k < 256; k++) {
+ test_sycl_contraction<DataLayout, DataType, IndexType>(sycl_device, k, 128, 128);
}
}
-template<int DataLayout, typename Device>
+template<int DataLayout, typename DataType, typename IndexType, typename Device>
void test_sycl_contraction_k(const Device& sycl_device) {
- for (int k = 32; k < 256; k++) {
- test_sycl_contraction<DataLayout>(sycl_device, 128, k, 128);
+ for (IndexType k = 32; k < 256; k++) {
+ test_sycl_contraction<DataLayout, DataType, IndexType>(sycl_device, 128, k, 128);
}
}
-template<int DataLayout, typename Device>
+template<int DataLayout, typename DataType, typename IndexType, typename Device>
void test_sycl_contraction_n(const Device& sycl_device) {
- for (int k = 32; k < 256; k++) {
- test_sycl_contraction<DataLayout>(sycl_device, 128, 128, k);
+ for (IndexType k = 32; k < 256; k++) {
+ test_sycl_contraction<DataLayout, DataType, IndexType>(sycl_device, 128, 128, k);
}
}
-template<int DataLayout, typename Device>
+template<int DataLayout, typename DataType, typename IndexType, typename Device>
void test_sycl_contraction_sizes(const Device& sycl_device) {
- int m_sizes[] = { 31, 39, 63, 64, 65,
+ IndexType m_sizes[] = { 31, 39, 63, 64, 65,
127, 129, 255, 257 , 511,
512, 513, 1023, 1024, 1025};
- int n_sizes[] = { 31, 39, 63, 64, 65,
+ IndexType n_sizes[] = { 31, 39, 63, 64, 65,
127, 129, 255, 257, 511,
512, 513, 1023, 1024, 1025};
- int k_sizes[] = { 31, 39, 63, 64, 65,
+ IndexType k_sizes[] = { 31, 39, 63, 64, 65,
95, 96, 127, 129, 255,
257, 511, 512, 513, 1023,
1024, 1025};
- for (int i = 0; i < 15; i++) {
- for (int j = 0; j < 15; j++) {
- for (int k = 0; k < 17; k++) {
- test_sycl_contraction<DataLayout>(sycl_device, m_sizes[i], n_sizes[j], k_sizes[k]);
+ for (IndexType i = 0; i < 15; i++) {
+ for (IndexType j = 0; j < 15; j++) {
+ for (IndexType k = 0; k < 17; k++) {
+ test_sycl_contraction<DataLayout, DataType,IndexType>(sycl_device, m_sizes[i], n_sizes[j], k_sizes[k]);
}
}
}
@@ -250,26 +254,26 @@ void test_sycl_contraction_sizes(const Device& sycl_device) {
template <typename Dev_selector> void tensorContractionPerDevice(Dev_selector& s){
QueueInterface queueInterface(s);
auto sycl_device=Eigen::SyclDevice(&queueInterface);
- test_sycl_contraction<ColMajor>(sycl_device, 32, 32, 32);
- test_sycl_contraction<RowMajor>(sycl_device, 32, 32, 32);
- test_scalar<ColMajor>(sycl_device, 32, 32, 32);
- test_scalar<RowMajor>(sycl_device, 32, 32, 32);
+ test_sycl_contraction<ColMajor, float,ptrdiff_t>(sycl_device, 32, 32, 32);
+ test_sycl_contraction<RowMajor,float,ptrdiff_t>(sycl_device, 32, 32, 32);
+ test_scalar<ColMajor,float,ptrdiff_t>(sycl_device, 32, 32, 32);
+ test_scalar<RowMajor,float,ptrdiff_t>(sycl_device, 32, 32, 32);
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
- test_sycl_contraction<ColMajor>(sycl_device, 128, 128, 128);
- test_sycl_contraction<RowMajor>(sycl_device, 128, 128, 128);
- test_scalar<ColMajor>(sycl_device, 128, 128, 128);
- test_scalar<RowMajor>(sycl_device, 128, 128, 128);
- test_sycl_contraction_m<ColMajor>(sycl_device);
- test_sycl_contraction_m<RowMajor>(sycl_device);
- test_sycl_contraction_n<ColMajor>(sycl_device);
- test_sycl_contraction_n<RowMajor>(sycl_device);
- test_sycl_contraction_k<ColMajor>(sycl_device);
- test_sycl_contraction_k<RowMajor>(sycl_device);
- test_sycl_contraction_sizes<ColMajor>(sycl_device);
- test_sycl_contraction_sizes<RowMajor>(sycl_device);
- test_TF<RowMajor>(sycl_device);
- test_TF<ColMajor>(sycl_device);
+ test_sycl_contraction<ColMajor,float,ptrdiff_t>(sycl_device, 128, 128, 128);
+ test_sycl_contraction<RowMajor,float,ptrdiff_t>(sycl_device, 128, 128, 128);
+ test_scalar<ColMajor,float,ptrdiff_t>(sycl_device, 128, 128, 128);
+ test_scalar<RowMajor,float,ptrdiff_t>(sycl_device, 128, 128, 128);
+ test_sycl_contraction_m<ColMajor, float, ptrdiff_t>(sycl_device);
+ test_sycl_contraction_m<RowMajor, float, ptrdiff_t>(sycl_device);
+ test_sycl_contraction_n<ColMajor, float, ptrdiff_t>(sycl_device);
+ test_sycl_contraction_n<RowMajor, float, ptrdiff_t>(sycl_device);
+ test_sycl_contraction_k<ColMajor, float, ptrdiff_t>(sycl_device);
+ test_sycl_contraction_k<RowMajor, float, ptrdiff_t>(sycl_device);
+ test_sycl_contraction_sizes<ColMajor, float, ptrdiff_t>(sycl_device);
+ test_sycl_contraction_sizes<RowMajor, float, ptrdiff_t>(sycl_device);
+ test_TF<RowMajor, float, ptrdiff_t>(sycl_device);
+ test_TF<ColMajor, float, ptrdiff_t>(sycl_device);
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;