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
@@ -26,47 +26,44 @@ using Eigen::Tensor;
|
||||
using Eigen::TensorMap;
|
||||
|
||||
template <typename DataType, int DataLayout, typename IndexType>
|
||||
static void test_broadcast_sycl_fixed(const Eigen::SyclDevice &sycl_device){
|
||||
|
||||
static void test_broadcast_sycl_fixed(const Eigen::SyclDevice& sycl_device) {
|
||||
// BROADCAST test:
|
||||
IndexType inDim1=2;
|
||||
IndexType inDim2=3;
|
||||
IndexType inDim3=5;
|
||||
IndexType inDim4=7;
|
||||
IndexType bDim1=2;
|
||||
IndexType bDim2=3;
|
||||
IndexType bDim3=1;
|
||||
IndexType bDim4=4;
|
||||
array<IndexType, 4> in_range = {{inDim1, inDim2, inDim3, inDim4}};
|
||||
IndexType inDim1 = 2;
|
||||
IndexType inDim2 = 3;
|
||||
IndexType inDim3 = 5;
|
||||
IndexType inDim4 = 7;
|
||||
IndexType bDim1 = 2;
|
||||
IndexType bDim2 = 3;
|
||||
IndexType bDim3 = 1;
|
||||
IndexType bDim4 = 4;
|
||||
array<IndexType, 4> in_range = {{inDim1, inDim2, inDim3, inDim4}};
|
||||
array<IndexType, 4> broadcasts = {{bDim1, bDim2, bDim3, bDim4}};
|
||||
array<IndexType, 4> out_range; // = in_range * broadcasts
|
||||
for (size_t i = 0; i < out_range.size(); ++i)
|
||||
out_range[i] = in_range[i] * broadcasts[i];
|
||||
for (size_t i = 0; i < out_range.size(); ++i) out_range[i] = in_range[i] * broadcasts[i];
|
||||
|
||||
Tensor<DataType, 4, DataLayout, IndexType> input(in_range);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> input(in_range);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> out(out_range);
|
||||
|
||||
for (size_t i = 0; i < in_range.size(); ++i)
|
||||
VERIFY_IS_EQUAL(out.dimension(i), out_range[i]);
|
||||
for (size_t i = 0; i < in_range.size(); ++i) VERIFY_IS_EQUAL(out.dimension(i), out_range[i]);
|
||||
|
||||
for (IndexType i = 0; i < input.size(); ++i) input(i) = static_cast<DataType>(i);
|
||||
|
||||
for (IndexType i = 0; i < input.size(); ++i)
|
||||
input(i) = static_cast<DataType>(i);
|
||||
|
||||
DataType * gpu_in_data = static_cast<DataType*>(sycl_device.allocate(input.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType * gpu_out_data = static_cast<DataType*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType* gpu_in_data =
|
||||
static_cast<DataType*>(sycl_device.allocate(input.dimensions().TotalSize() * sizeof(DataType)));
|
||||
DataType* gpu_out_data =
|
||||
static_cast<DataType*>(sycl_device.allocate(out.dimensions().TotalSize() * sizeof(DataType)));
|
||||
|
||||
TensorMap<TensorFixedSize<DataType, Sizes<2, 3, 5, 7>, DataLayout, IndexType>> gpu_in(gpu_in_data, in_range);
|
||||
TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_out(gpu_out_data, out_range);
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, input.data(),(input.dimensions().TotalSize())*sizeof(DataType));
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, input.data(), (input.dimensions().TotalSize()) * sizeof(DataType));
|
||||
gpu_out.device(sycl_device) = gpu_in.broadcast(broadcasts);
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(DataType));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data, (out.dimensions().TotalSize()) * sizeof(DataType));
|
||||
|
||||
for (IndexType i = 0; i < inDim1*bDim1; ++i) {
|
||||
for (IndexType j = 0; j < inDim2*bDim2; ++j) {
|
||||
for (IndexType k = 0; k < inDim3*bDim3; ++k) {
|
||||
for (IndexType l = 0; l < inDim4*bDim4; ++l) {
|
||||
VERIFY_IS_APPROX(input(i%2,j%3,k%5,l%7), out(i,j,k,l));
|
||||
for (IndexType i = 0; i < inDim1 * bDim1; ++i) {
|
||||
for (IndexType j = 0; j < inDim2 * bDim2; ++j) {
|
||||
for (IndexType k = 0; k < inDim3 * bDim3; ++k) {
|
||||
for (IndexType l = 0; l < inDim4 * bDim4; ++l) {
|
||||
VERIFY_IS_APPROX(input(i % 2, j % 3, k % 5, l % 7), out(i, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,47 +74,44 @@ static void test_broadcast_sycl_fixed(const Eigen::SyclDevice &sycl_device){
|
||||
}
|
||||
|
||||
template <typename DataType, int DataLayout, typename IndexType>
|
||||
static void test_broadcast_sycl(const Eigen::SyclDevice &sycl_device){
|
||||
|
||||
static void test_broadcast_sycl(const Eigen::SyclDevice& sycl_device) {
|
||||
// BROADCAST test:
|
||||
IndexType inDim1=2;
|
||||
IndexType inDim2=3;
|
||||
IndexType inDim3=5;
|
||||
IndexType inDim4=7;
|
||||
IndexType bDim1=2;
|
||||
IndexType bDim2=3;
|
||||
IndexType bDim3=1;
|
||||
IndexType bDim4=4;
|
||||
array<IndexType, 4> in_range = {{inDim1, inDim2, inDim3, inDim4}};
|
||||
IndexType inDim1 = 2;
|
||||
IndexType inDim2 = 3;
|
||||
IndexType inDim3 = 5;
|
||||
IndexType inDim4 = 7;
|
||||
IndexType bDim1 = 2;
|
||||
IndexType bDim2 = 3;
|
||||
IndexType bDim3 = 1;
|
||||
IndexType bDim4 = 4;
|
||||
array<IndexType, 4> in_range = {{inDim1, inDim2, inDim3, inDim4}};
|
||||
array<IndexType, 4> broadcasts = {{bDim1, bDim2, bDim3, bDim4}};
|
||||
array<IndexType, 4> out_range; // = in_range * broadcasts
|
||||
for (size_t i = 0; i < out_range.size(); ++i)
|
||||
out_range[i] = in_range[i] * broadcasts[i];
|
||||
for (size_t i = 0; i < out_range.size(); ++i) out_range[i] = in_range[i] * broadcasts[i];
|
||||
|
||||
Tensor<DataType, 4, DataLayout, IndexType> input(in_range);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> input(in_range);
|
||||
Tensor<DataType, 4, DataLayout, IndexType> out(out_range);
|
||||
|
||||
for (size_t i = 0; i < in_range.size(); ++i)
|
||||
VERIFY_IS_EQUAL(out.dimension(i), out_range[i]);
|
||||
for (size_t i = 0; i < in_range.size(); ++i) VERIFY_IS_EQUAL(out.dimension(i), out_range[i]);
|
||||
|
||||
for (IndexType i = 0; i < input.size(); ++i) input(i) = static_cast<DataType>(i);
|
||||
|
||||
for (IndexType i = 0; i < input.size(); ++i)
|
||||
input(i) = static_cast<DataType>(i);
|
||||
DataType* gpu_in_data =
|
||||
static_cast<DataType*>(sycl_device.allocate(input.dimensions().TotalSize() * sizeof(DataType)));
|
||||
DataType* gpu_out_data =
|
||||
static_cast<DataType*>(sycl_device.allocate(out.dimensions().TotalSize() * sizeof(DataType)));
|
||||
|
||||
DataType * gpu_in_data = static_cast<DataType*>(sycl_device.allocate(input.dimensions().TotalSize()*sizeof(DataType)));
|
||||
DataType * gpu_out_data = static_cast<DataType*>(sycl_device.allocate(out.dimensions().TotalSize()*sizeof(DataType)));
|
||||
|
||||
TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_in(gpu_in_data, in_range);
|
||||
TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_in(gpu_in_data, in_range);
|
||||
TensorMap<Tensor<DataType, 4, DataLayout, IndexType>> gpu_out(gpu_out_data, out_range);
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, input.data(),(input.dimensions().TotalSize())*sizeof(DataType));
|
||||
sycl_device.memcpyHostToDevice(gpu_in_data, input.data(), (input.dimensions().TotalSize()) * sizeof(DataType));
|
||||
gpu_out.device(sycl_device) = gpu_in.broadcast(broadcasts);
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data,(out.dimensions().TotalSize())*sizeof(DataType));
|
||||
sycl_device.memcpyDeviceToHost(out.data(), gpu_out_data, (out.dimensions().TotalSize()) * sizeof(DataType));
|
||||
|
||||
for (IndexType i = 0; i < inDim1*bDim1; ++i) {
|
||||
for (IndexType j = 0; j < inDim2*bDim2; ++j) {
|
||||
for (IndexType k = 0; k < inDim3*bDim3; ++k) {
|
||||
for (IndexType l = 0; l < inDim4*bDim4; ++l) {
|
||||
VERIFY_IS_APPROX(input(i%inDim1,j%inDim2,k%inDim3,l%inDim4), out(i,j,k,l));
|
||||
for (IndexType i = 0; i < inDim1 * bDim1; ++i) {
|
||||
for (IndexType j = 0; j < inDim2 * bDim2; ++j) {
|
||||
for (IndexType k = 0; k < inDim3 * bDim3; ++k) {
|
||||
for (IndexType l = 0; l < inDim4 * bDim4; ++l) {
|
||||
VERIFY_IS_APPROX(input(i % inDim1, j % inDim2, k % inDim3, l % inDim4), out(i, j, k, l));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,7 +121,8 @@ static void test_broadcast_sycl(const Eigen::SyclDevice &sycl_device){
|
||||
sycl_device.deallocate(gpu_out_data);
|
||||
}
|
||||
|
||||
template<typename DataType> void sycl_broadcast_test_per_device(const cl::sycl::device& d){
|
||||
template <typename DataType>
|
||||
void sycl_broadcast_test_per_device(const cl::sycl::device& d) {
|
||||
std::cout << "Running on " << d.template get_info<cl::sycl::info::device::name>() << std::endl;
|
||||
QueueInterface queueInterface(d);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
@@ -138,7 +133,7 @@ template<typename DataType> void sycl_broadcast_test_per_device(const cl::sycl::
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_broadcast_sycl) {
|
||||
for (const auto& device :Eigen::get_sycl_supported_devices()) {
|
||||
for (const auto& device : Eigen::get_sycl_supported_devices()) {
|
||||
CALL_SUBTEST(sycl_broadcast_test_per_device<half>(device));
|
||||
CALL_SUBTEST(sycl_broadcast_test_per_device<float>(device));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user