Clang-format tests, examples, libraries, benchmarks, etc.

This commit is contained in:
Antonio Sánchez
2023-12-05 21:22:55 +00:00
committed by Rasmus Munk Larsen
parent 3252ecc7a4
commit 46e9cdb7fe
876 changed files with 33453 additions and 37795 deletions

View File

@@ -38,30 +38,24 @@ static void test_simple_reverse(const Eigen::SyclDevice& sycl_device) {
dim_rev[2] = true;
dim_rev[3] = false;
DataType* gpu_in_data = static_cast<DataType*>(
sycl_device.allocate(tensor.dimensions().TotalSize() * sizeof(DataType)));
DataType* gpu_out_data = static_cast<DataType*>(sycl_device.allocate(
reversed_tensor.dimensions().TotalSize() * sizeof(DataType)));
DataType* gpu_in_data =
static_cast<DataType*>(sycl_device.allocate(tensor.dimensions().TotalSize() * sizeof(DataType)));
DataType* gpu_out_data =
static_cast<DataType*>(sycl_device.allocate(reversed_tensor.dimensions().TotalSize() * sizeof(DataType)));
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > in_gpu(gpu_in_data,
tensorRange);
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > out_gpu(gpu_out_data,
tensorRange);
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > in_gpu(gpu_in_data, tensorRange);
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > out_gpu(gpu_out_data, tensorRange);
sycl_device.memcpyHostToDevice(
gpu_in_data, tensor.data(),
(tensor.dimensions().TotalSize()) * sizeof(DataType));
sycl_device.memcpyHostToDevice(gpu_in_data, tensor.data(), (tensor.dimensions().TotalSize()) * sizeof(DataType));
out_gpu.device(sycl_device) = in_gpu.reverse(dim_rev);
sycl_device.memcpyDeviceToHost(
reversed_tensor.data(), gpu_out_data,
reversed_tensor.dimensions().TotalSize() * sizeof(DataType));
sycl_device.memcpyDeviceToHost(reversed_tensor.data(), gpu_out_data,
reversed_tensor.dimensions().TotalSize() * sizeof(DataType));
// Check that the CPU and GPU reductions return the same result.
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),
reversed_tensor(i, 2 - j, 4 - k, l));
VERIFY_IS_EQUAL(tensor(i, j, k, l), reversed_tensor(i, 2 - j, 4 - k, l));
}
}
}
@@ -72,9 +66,8 @@ static void test_simple_reverse(const Eigen::SyclDevice& sycl_device) {
dim_rev[3] = false;
out_gpu.device(sycl_device) = in_gpu.reverse(dim_rev);
sycl_device.memcpyDeviceToHost(
reversed_tensor.data(), gpu_out_data,
reversed_tensor.dimensions().TotalSize() * sizeof(DataType));
sycl_device.memcpyDeviceToHost(reversed_tensor.data(), gpu_out_data,
reversed_tensor.dimensions().TotalSize() * sizeof(DataType));
for (IndexType i = 0; i < 2; ++i) {
for (IndexType j = 0; j < 3; ++j) {
@@ -91,16 +84,14 @@ static void test_simple_reverse(const Eigen::SyclDevice& sycl_device) {
dim_rev[2] = false;
dim_rev[3] = true;
out_gpu.device(sycl_device) = in_gpu.reverse(dim_rev);
sycl_device.memcpyDeviceToHost(
reversed_tensor.data(), gpu_out_data,
reversed_tensor.dimensions().TotalSize() * sizeof(DataType));
sycl_device.memcpyDeviceToHost(reversed_tensor.data(), gpu_out_data,
reversed_tensor.dimensions().TotalSize() * sizeof(DataType));
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),
reversed_tensor(1 - i, j, k, 6 - l));
VERIFY_IS_EQUAL(tensor(i, j, k, l), reversed_tensor(1 - i, j, k, 6 - l));
}
}
}
@@ -111,8 +102,7 @@ static void test_simple_reverse(const Eigen::SyclDevice& sycl_device) {
}
template <typename DataType, int DataLayout, typename IndexType>
static void test_expr_reverse(const Eigen::SyclDevice& sycl_device,
bool LValue) {
static void test_expr_reverse(const Eigen::SyclDevice& sycl_device, bool LValue) {
IndexType dim1 = 2;
IndexType dim2 = 3;
IndexType dim3 = 5;
@@ -130,32 +120,26 @@ static void test_expr_reverse(const Eigen::SyclDevice& sycl_device,
dim_rev[2] = false;
dim_rev[3] = true;
DataType* gpu_in_data = static_cast<DataType*>(
sycl_device.allocate(tensor.dimensions().TotalSize() * sizeof(DataType)));
DataType* gpu_out_data_expected = static_cast<DataType*>(sycl_device.allocate(
expected.dimensions().TotalSize() * sizeof(DataType)));
DataType* gpu_out_data_result = static_cast<DataType*>(
sycl_device.allocate(result.dimensions().TotalSize() * sizeof(DataType)));
DataType* gpu_in_data =
static_cast<DataType*>(sycl_device.allocate(tensor.dimensions().TotalSize() * sizeof(DataType)));
DataType* gpu_out_data_expected =
static_cast<DataType*>(sycl_device.allocate(expected.dimensions().TotalSize() * sizeof(DataType)));
DataType* gpu_out_data_result =
static_cast<DataType*>(sycl_device.allocate(result.dimensions().TotalSize() * sizeof(DataType)));
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > in_gpu(gpu_in_data,
tensorRange);
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > out_gpu_expected(
gpu_out_data_expected, tensorRange);
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > out_gpu_result(
gpu_out_data_result, tensorRange);
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > in_gpu(gpu_in_data, tensorRange);
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > out_gpu_expected(gpu_out_data_expected, tensorRange);
TensorMap<Tensor<DataType, 4, DataLayout, IndexType> > out_gpu_result(gpu_out_data_result, tensorRange);
sycl_device.memcpyHostToDevice(
gpu_in_data, tensor.data(),
(tensor.dimensions().TotalSize()) * sizeof(DataType));
sycl_device.memcpyHostToDevice(gpu_in_data, tensor.data(), (tensor.dimensions().TotalSize()) * sizeof(DataType));
if (LValue) {
out_gpu_expected.reverse(dim_rev).device(sycl_device) = in_gpu;
} else {
out_gpu_expected.device(sycl_device) = in_gpu.reverse(dim_rev);
}
sycl_device.memcpyDeviceToHost(
expected.data(), gpu_out_data_expected,
expected.dimensions().TotalSize() * sizeof(DataType));
sycl_device.memcpyDeviceToHost(expected.data(), gpu_out_data_expected,
expected.dimensions().TotalSize() * sizeof(DataType));
array<IndexType, 4> src_slice_dim;
src_slice_dim[0] = 2;
@@ -172,9 +156,8 @@ static void test_expr_reverse(const Eigen::SyclDevice& sycl_device,
for (IndexType i = 0; i < 5; ++i) {
if (LValue) {
out_gpu_result.slice(dst_slice_start, dst_slice_dim)
.reverse(dim_rev)
.device(sycl_device) = in_gpu.slice(src_slice_start, src_slice_dim);
out_gpu_result.slice(dst_slice_start, dst_slice_dim).reverse(dim_rev).device(sycl_device) =
in_gpu.slice(src_slice_start, src_slice_dim);
} else {
out_gpu_result.slice(dst_slice_start, dst_slice_dim).device(sycl_device) =
in_gpu.slice(src_slice_start, src_slice_dim).reverse(dim_rev);
@@ -182,9 +165,8 @@ static void test_expr_reverse(const Eigen::SyclDevice& sycl_device,
src_slice_start[2] += 1;
dst_slice_start[2] += 1;
}
sycl_device.memcpyDeviceToHost(
result.data(), gpu_out_data_result,
result.dimensions().TotalSize() * sizeof(DataType));
sycl_device.memcpyDeviceToHost(result.data(), gpu_out_data_result,
result.dimensions().TotalSize() * sizeof(DataType));
for (IndexType i = 0; i < expected.dimension(0); ++i) {
for (IndexType j = 0; j < expected.dimension(1); ++j) {
@@ -198,23 +180,20 @@ static void test_expr_reverse(const Eigen::SyclDevice& sycl_device,
dst_slice_start[2] = 0;
result.setRandom();
sycl_device.memcpyHostToDevice(
gpu_out_data_result, result.data(),
(result.dimensions().TotalSize()) * sizeof(DataType));
sycl_device.memcpyHostToDevice(gpu_out_data_result, result.data(),
(result.dimensions().TotalSize()) * sizeof(DataType));
for (IndexType i = 0; i < 5; ++i) {
if (LValue) {
out_gpu_result.slice(dst_slice_start, dst_slice_dim)
.reverse(dim_rev)
.device(sycl_device) = in_gpu.slice(dst_slice_start, dst_slice_dim);
out_gpu_result.slice(dst_slice_start, dst_slice_dim).reverse(dim_rev).device(sycl_device) =
in_gpu.slice(dst_slice_start, dst_slice_dim);
} else {
out_gpu_result.slice(dst_slice_start, dst_slice_dim).device(sycl_device) =
in_gpu.reverse(dim_rev).slice(dst_slice_start, dst_slice_dim);
}
dst_slice_start[2] += 1;
}
sycl_device.memcpyDeviceToHost(
result.data(), gpu_out_data_result,
result.dimensions().TotalSize() * sizeof(DataType));
sycl_device.memcpyDeviceToHost(result.data(), gpu_out_data_result,
result.dimensions().TotalSize() * sizeof(DataType));
for (IndexType i = 0; i < expected.dimension(0); ++i) {
for (IndexType j = 0; j < expected.dimension(1); ++j) {
@@ -240,8 +219,7 @@ void sycl_reverse_test_per_device(const cl::sycl::device& d) {
}
EIGEN_DECLARE_TEST(cxx11_tensor_reverse_sycl) {
for (const auto& device : Eigen::get_sycl_supported_devices()) {
std::cout << "Running on "
<< device.get_info<cl::sycl::info::device::name>() << std::endl;
std::cout << "Running on " << device.get_info<cl::sycl::info::device::name>() << std::endl;
CALL_SUBTEST_1(sycl_reverse_test_per_device<short>(device));
CALL_SUBTEST_2(sycl_reverse_test_per_device<int>(device));
CALL_SUBTEST_3(sycl_reverse_test_per_device<unsigned int>(device));