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
@@ -29,32 +29,26 @@ using Eigen::SyclDevice;
|
||||
using Eigen::Tensor;
|
||||
using Eigen::TensorMap;
|
||||
|
||||
|
||||
template <typename DataType, int DataLayout, typename IndexType>
|
||||
static void test_simple_striding(const Eigen::SyclDevice& sycl_device)
|
||||
{
|
||||
|
||||
Eigen::array<IndexType, 4> tensor_dims = {{2,3,5,7}};
|
||||
Eigen::array<IndexType, 4> stride_dims = {{1,1,3,3}};
|
||||
|
||||
static void test_simple_striding(const Eigen::SyclDevice& sycl_device) {
|
||||
Eigen::array<IndexType, 4> tensor_dims = {{2, 3, 5, 7}};
|
||||
Eigen::array<IndexType, 4> stride_dims = {{1, 1, 3, 3}};
|
||||
|
||||
Tensor<DataType, 4, DataLayout, IndexType> tensor(tensor_dims);
|
||||
Tensor<DataType, 4, DataLayout,IndexType> no_stride(tensor_dims);
|
||||
Tensor<DataType, 4, DataLayout,IndexType> stride(stride_dims);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> no_stride(tensor_dims);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> stride(stride_dims);
|
||||
|
||||
|
||||
std::size_t tensor_bytes = tensor.size() * sizeof(DataType);
|
||||
std::size_t tensor_bytes = tensor.size() * sizeof(DataType);
|
||||
std::size_t no_stride_bytes = no_stride.size() * sizeof(DataType);
|
||||
std::size_t stride_bytes = stride.size() * sizeof(DataType);
|
||||
DataType * d_tensor = static_cast<DataType*>(sycl_device.allocate(tensor_bytes));
|
||||
DataType * d_no_stride = static_cast<DataType*>(sycl_device.allocate(no_stride_bytes));
|
||||
DataType * d_stride = static_cast<DataType*>(sycl_device.allocate(stride_bytes));
|
||||
DataType* d_tensor = static_cast<DataType*>(sycl_device.allocate(tensor_bytes));
|
||||
DataType* d_no_stride = static_cast<DataType*>(sycl_device.allocate(no_stride_bytes));
|
||||
DataType* d_stride = static_cast<DataType*>(sycl_device.allocate(stride_bytes));
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_tensor(d_tensor, tensor_dims);
|
||||
Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_no_stride(d_no_stride, tensor_dims);
|
||||
Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_stride(d_stride, stride_dims);
|
||||
|
||||
|
||||
tensor.setRandom();
|
||||
array<IndexType, 4> strides;
|
||||
strides[0] = 1;
|
||||
@@ -62,10 +56,10 @@ static void test_simple_striding(const Eigen::SyclDevice& sycl_device)
|
||||
strides[2] = 1;
|
||||
strides[3] = 1;
|
||||
sycl_device.memcpyHostToDevice(d_tensor, tensor.data(), tensor_bytes);
|
||||
gpu_no_stride.device(sycl_device)=gpu_tensor.stride(strides);
|
||||
gpu_no_stride.device(sycl_device) = gpu_tensor.stride(strides);
|
||||
sycl_device.memcpyDeviceToHost(no_stride.data(), d_no_stride, no_stride_bytes);
|
||||
|
||||
//no_stride = tensor.stride(strides);
|
||||
// no_stride = tensor.stride(strides);
|
||||
|
||||
VERIFY_IS_EQUAL(no_stride.dimension(0), 2);
|
||||
VERIFY_IS_EQUAL(no_stride.dimension(1), 3);
|
||||
@@ -76,7 +70,7 @@ static void test_simple_striding(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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -86,10 +80,10 @@ static void test_simple_striding(const Eigen::SyclDevice& sycl_device)
|
||||
strides[1] = 4;
|
||||
strides[2] = 2;
|
||||
strides[3] = 3;
|
||||
//Tensor<float, 4, DataLayout> stride;
|
||||
// stride = tensor.stride(strides);
|
||||
// Tensor<float, 4, DataLayout> stride;
|
||||
// stride = tensor.stride(strides);
|
||||
|
||||
gpu_stride.device(sycl_device)=gpu_tensor.stride(strides);
|
||||
gpu_stride.device(sycl_device) = gpu_tensor.stride(strides);
|
||||
sycl_device.memcpyDeviceToHost(stride.data(), d_stride, stride_bytes);
|
||||
|
||||
VERIFY_IS_EQUAL(stride.dimension(0), 1);
|
||||
@@ -101,7 +95,7 @@ static void test_simple_striding(const Eigen::SyclDevice& sycl_device)
|
||||
for (IndexType j = 0; j < 1; ++j) {
|
||||
for (IndexType k = 0; k < 3; ++k) {
|
||||
for (IndexType l = 0; l < 3; ++l) {
|
||||
VERIFY_IS_EQUAL(tensor(2*i,4*j,2*k,3*l), stride(i,j,k,l));
|
||||
VERIFY_IS_EQUAL(tensor(2 * i, 4 * j, 2 * k, 3 * l), stride(i, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,31 +107,27 @@ static void test_simple_striding(const Eigen::SyclDevice& sycl_device)
|
||||
}
|
||||
|
||||
template <typename DataType, int DataLayout, typename IndexType>
|
||||
static void test_striding_as_lvalue(const Eigen::SyclDevice& sycl_device)
|
||||
{
|
||||
|
||||
Eigen::array<IndexType, 4> tensor_dims = {{2,3,5,7}};
|
||||
Eigen::array<IndexType, 4> stride_dims = {{3,12,10,21}};
|
||||
|
||||
static void test_striding_as_lvalue(const Eigen::SyclDevice& sycl_device) {
|
||||
Eigen::array<IndexType, 4> tensor_dims = {{2, 3, 5, 7}};
|
||||
Eigen::array<IndexType, 4> stride_dims = {{3, 12, 10, 21}};
|
||||
|
||||
Tensor<DataType, 4, DataLayout, IndexType> tensor(tensor_dims);
|
||||
Tensor<DataType, 4, DataLayout,IndexType> no_stride(stride_dims);
|
||||
Tensor<DataType, 4, DataLayout,IndexType> stride(stride_dims);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> no_stride(stride_dims);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> stride(stride_dims);
|
||||
|
||||
|
||||
std::size_t tensor_bytes = tensor.size() * sizeof(DataType);
|
||||
std::size_t tensor_bytes = tensor.size() * sizeof(DataType);
|
||||
std::size_t no_stride_bytes = no_stride.size() * sizeof(DataType);
|
||||
std::size_t stride_bytes = stride.size() * sizeof(DataType);
|
||||
|
||||
DataType * d_tensor = static_cast<DataType*>(sycl_device.allocate(tensor_bytes));
|
||||
DataType * d_no_stride = static_cast<DataType*>(sycl_device.allocate(no_stride_bytes));
|
||||
DataType * d_stride = static_cast<DataType*>(sycl_device.allocate(stride_bytes));
|
||||
DataType* d_tensor = static_cast<DataType*>(sycl_device.allocate(tensor_bytes));
|
||||
DataType* d_no_stride = static_cast<DataType*>(sycl_device.allocate(no_stride_bytes));
|
||||
DataType* d_stride = static_cast<DataType*>(sycl_device.allocate(stride_bytes));
|
||||
|
||||
Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_tensor(d_tensor, tensor_dims);
|
||||
Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_no_stride(d_no_stride, stride_dims);
|
||||
Eigen::TensorMap<Eigen::Tensor<DataType, 4, DataLayout, IndexType> > gpu_stride(d_stride, stride_dims);
|
||||
|
||||
//Tensor<float, 4, DataLayout> tensor(2,3,5,7);
|
||||
// Tensor<float, 4, DataLayout> tensor(2,3,5,7);
|
||||
tensor.setRandom();
|
||||
array<IndexType, 4> strides;
|
||||
strides[0] = 2;
|
||||
@@ -145,17 +135,17 @@ static void test_striding_as_lvalue(const Eigen::SyclDevice& sycl_device)
|
||||
strides[2] = 2;
|
||||
strides[3] = 3;
|
||||
|
||||
// Tensor<float, 4, DataLayout> result(3, 12, 10, 21);
|
||||
// result.stride(strides) = tensor;
|
||||
// Tensor<float, 4, DataLayout> result(3, 12, 10, 21);
|
||||
// result.stride(strides) = tensor;
|
||||
sycl_device.memcpyHostToDevice(d_tensor, tensor.data(), tensor_bytes);
|
||||
gpu_stride.stride(strides).device(sycl_device)=gpu_tensor;
|
||||
gpu_stride.stride(strides).device(sycl_device) = gpu_tensor;
|
||||
sycl_device.memcpyDeviceToHost(stride.data(), d_stride, stride_bytes);
|
||||
|
||||
for (IndexType i = 0; i < 2; ++i) {
|
||||
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), stride(2*i,4*j,2*k,3*l));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l), stride(2 * i, 4 * j, 2 * k, 3 * l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -166,17 +156,17 @@ static void test_striding_as_lvalue(const Eigen::SyclDevice& sycl_device)
|
||||
no_strides[1] = 1;
|
||||
no_strides[2] = 1;
|
||||
no_strides[3] = 1;
|
||||
// Tensor<float, 4, DataLayout> result2(3, 12, 10, 21);
|
||||
// result2.stride(strides) = tensor.stride(no_strides);
|
||||
// Tensor<float, 4, DataLayout> result2(3, 12, 10, 21);
|
||||
// result2.stride(strides) = tensor.stride(no_strides);
|
||||
|
||||
gpu_no_stride.stride(strides).device(sycl_device)=gpu_tensor.stride(no_strides);
|
||||
gpu_no_stride.stride(strides).device(sycl_device) = gpu_tensor.stride(no_strides);
|
||||
sycl_device.memcpyDeviceToHost(no_stride.data(), d_no_stride, no_stride_bytes);
|
||||
|
||||
for (IndexType i = 0; i < 2; ++i) {
|
||||
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(2*i,4*j,2*k,3*l));
|
||||
VERIFY_IS_EQUAL(tensor(i, j, k, l), no_stride(2 * i, 4 * j, 2 * k, 3 * l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -186,10 +176,10 @@ static void test_striding_as_lvalue(const Eigen::SyclDevice& sycl_device)
|
||||
sycl_device.deallocate(d_stride);
|
||||
}
|
||||
|
||||
|
||||
template <typename Dev_selector> void tensorStridingPerDevice(Dev_selector& s){
|
||||
template <typename Dev_selector>
|
||||
void tensorStridingPerDevice(Dev_selector& s) {
|
||||
QueueInterface queueInterface(s);
|
||||
auto sycl_device=Eigen::SyclDevice(&queueInterface);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
test_simple_striding<float, ColMajor, int64_t>(sycl_device);
|
||||
test_simple_striding<float, RowMajor, int64_t>(sycl_device);
|
||||
test_striding_as_lvalue<float, ColMajor, int64_t>(sycl_device);
|
||||
@@ -197,7 +187,7 @@ template <typename Dev_selector> void tensorStridingPerDevice(Dev_selector& s){
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_striding_sycl) {
|
||||
for (const auto& device :Eigen::get_sycl_supported_devices()) {
|
||||
for (const auto& device : Eigen::get_sycl_supported_devices()) {
|
||||
CALL_SUBTEST(tensorStridingPerDevice(device));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user