mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -30,16 +30,14 @@ using Eigen::Tensor;
|
||||
// (4, 0, 0, 4, 0, 0, 4).
|
||||
|
||||
template <typename DataType, int DataLayout, typename IndexType>
|
||||
void test_simple_inflation_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
|
||||
void test_simple_inflation_sycl(const Eigen::SyclDevice& sycl_device) {
|
||||
IndexType sizeDim1 = 2;
|
||||
IndexType sizeDim2 = 3;
|
||||
IndexType sizeDim3 = 5;
|
||||
IndexType sizeDim4 = 7;
|
||||
array<IndexType, 4> tensorRange = {{sizeDim1, sizeDim2, sizeDim3, sizeDim4}};
|
||||
Tensor<DataType, 4, DataLayout,IndexType> tensor(tensorRange);
|
||||
Tensor<DataType, 4, DataLayout,IndexType> no_stride(tensorRange);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> tensor(tensorRange);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> no_stride(tensorRange);
|
||||
tensor.setRandom();
|
||||
|
||||
array<IndexType, 4> strides;
|
||||
@@ -48,16 +46,15 @@ void test_simple_inflation_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
strides[2] = 1;
|
||||
strides[3] = 1;
|
||||
|
||||
const size_t tensorBuffSize = tensor.size() * sizeof(DataType);
|
||||
DataType* gpu_data_tensor = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
|
||||
DataType* gpu_data_no_stride = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
|
||||
|
||||
const size_t tensorBuffSize =tensor.size()*sizeof(DataType);
|
||||
DataType* gpu_data_tensor = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
|
||||
DataType* gpu_data_no_stride = static_cast<DataType*>(sycl_device.allocate(tensorBuffSize));
|
||||
|
||||
TensorMap<Tensor<DataType, 4, DataLayout,IndexType>> gpu_tensor(gpu_data_tensor, tensorRange);
|
||||
TensorMap<Tensor<DataType, 4, DataLayout,IndexType>> gpu_no_stride(gpu_data_no_stride, tensorRange);
|
||||
TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_tensor(gpu_data_tensor, tensorRange);
|
||||
TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_no_stride(gpu_data_no_stride, tensorRange);
|
||||
|
||||
sycl_device.memcpyHostToDevice(gpu_data_tensor, tensor.data(), tensorBuffSize);
|
||||
gpu_no_stride.device(sycl_device)=gpu_tensor.inflate(strides);
|
||||
gpu_no_stride.device(sycl_device) = gpu_tensor.inflate(strides);
|
||||
sycl_device.memcpyDeviceToHost(no_stride.data(), gpu_data_no_stride, tensorBuffSize);
|
||||
|
||||
VERIFY_IS_EQUAL(no_stride.dimension(0), sizeDim1);
|
||||
@@ -69,13 +66,12 @@ void test_simple_inflation_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
for (IndexType j = 0; j < 3; ++j) {
|
||||
for (IndexType k = 0; k < 5; ++k) {
|
||||
for (IndexType l = 0; l < 7; ++l) {
|
||||
VERIFY_IS_EQUAL(tensor(i,j,k,l), no_stride(i,j,k,l));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l), no_stride(i, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
strides[0] = 2;
|
||||
strides[1] = 4;
|
||||
strides[2] = 2;
|
||||
@@ -89,10 +85,10 @@ void test_simple_inflation_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
|
||||
Tensor<DataType, 4, DataLayout, IndexType> inflated(inflatedTensorRange);
|
||||
|
||||
const size_t inflatedTensorBuffSize =inflated.size()*sizeof(DataType);
|
||||
DataType* gpu_data_inflated = static_cast<DataType*>(sycl_device.allocate(inflatedTensorBuffSize));
|
||||
const size_t inflatedTensorBuffSize = inflated.size() * sizeof(DataType);
|
||||
DataType* gpu_data_inflated = static_cast<DataType*>(sycl_device.allocate(inflatedTensorBuffSize));
|
||||
TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_inflated(gpu_data_inflated, inflatedTensorRange);
|
||||
gpu_inflated.device(sycl_device)=gpu_tensor.inflate(strides);
|
||||
gpu_inflated.device(sycl_device) = gpu_tensor.inflate(strides);
|
||||
sycl_device.memcpyDeviceToHost(inflated.data(), gpu_data_inflated, inflatedTensorBuffSize);
|
||||
|
||||
VERIFY_IS_EQUAL(inflated.dimension(0), inflatedSizeDim1);
|
||||
@@ -104,14 +100,11 @@ void test_simple_inflation_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
for (IndexType j = 0; j < inflatedSizeDim2; ++j) {
|
||||
for (IndexType k = 0; k < inflatedSizeDim3; ++k) {
|
||||
for (IndexType l = 0; l < inflatedSizeDim4; ++l) {
|
||||
if (i % strides[0] == 0 &&
|
||||
j % strides[1] == 0 &&
|
||||
k % strides[2] == 0 &&
|
||||
l % strides[3] == 0) {
|
||||
VERIFY_IS_EQUAL(inflated(i,j,k,l),
|
||||
tensor(i/strides[0], j/strides[1], k/strides[2], l/strides[3]));
|
||||
if (i % strides[0] == 0 && j % strides[1] == 0 && k % strides[2] == 0 && l % strides[3] == 0) {
|
||||
VERIFY_IS_EQUAL(inflated(i, j, k, l),
|
||||
tensor(i / strides[0], j / strides[1], k / strides[2], l / strides[3]));
|
||||
} else {
|
||||
VERIFY_IS_EQUAL(0, inflated(i,j,k,l));
|
||||
VERIFY_IS_EQUAL(0, inflated(i, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,15 +115,15 @@ void test_simple_inflation_sycl(const Eigen::SyclDevice &sycl_device) {
|
||||
sycl_device.deallocate(gpu_data_inflated);
|
||||
}
|
||||
|
||||
template<typename DataType, typename dev_Selector> void sycl_inflation_test_per_device(dev_Selector s){
|
||||
template <typename DataType, typename dev_Selector>
|
||||
void sycl_inflation_test_per_device(dev_Selector s) {
|
||||
QueueInterface queueInterface(s);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
test_simple_inflation_sycl<DataType, RowMajor, int64_t>(sycl_device);
|
||||
test_simple_inflation_sycl<DataType, ColMajor, int64_t>(sycl_device);
|
||||
}
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_inflation_sycl)
|
||||
{
|
||||
for (const auto& device :Eigen::get_sycl_supported_devices()) {
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_inflation_sycl) {
|
||||
for (const auto& device : Eigen::get_sycl_supported_devices()) {
|
||||
CALL_SUBTEST(sycl_inflation_test_per_device<half>(device));
|
||||
CALL_SUBTEST(sycl_inflation_test_per_device<float>(device));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user