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
@@ -23,31 +23,25 @@ using Eigen::Tensor;
|
||||
typedef Tensor<float, 1>::DimensionPair DimPair;
|
||||
|
||||
template <typename DataType, int DataLayout, typename IndexType>
|
||||
void test_sycl_cumsum(const Eigen::SyclDevice& sycl_device, IndexType m_size,
|
||||
IndexType k_size, IndexType n_size, int consume_dim,
|
||||
bool exclusive) {
|
||||
void test_sycl_cumsum(const Eigen::SyclDevice& sycl_device, IndexType m_size, IndexType k_size, IndexType n_size,
|
||||
int consume_dim, bool exclusive) {
|
||||
static const DataType error_threshold = 1e-4f;
|
||||
std::cout << "Testing for (" << m_size << "," << k_size << "," << n_size
|
||||
<< " consume_dim : " << consume_dim << ")" << std::endl;
|
||||
std::cout << "Testing for (" << m_size << "," << k_size << "," << n_size << " consume_dim : " << consume_dim << ")"
|
||||
<< std::endl;
|
||||
Tensor<DataType, 3, DataLayout, IndexType> t_input(m_size, k_size, n_size);
|
||||
Tensor<DataType, 3, DataLayout, IndexType> t_result(m_size, k_size, n_size);
|
||||
Tensor<DataType, 3, DataLayout, IndexType> t_result_gpu(m_size, k_size,
|
||||
n_size);
|
||||
Tensor<DataType, 3, DataLayout, IndexType> t_result_gpu(m_size, k_size, n_size);
|
||||
|
||||
t_input.setRandom();
|
||||
std::size_t t_input_bytes = t_input.size() * sizeof(DataType);
|
||||
std::size_t t_result_bytes = t_result.size() * sizeof(DataType);
|
||||
|
||||
DataType* gpu_data_in =
|
||||
static_cast<DataType*>(sycl_device.allocate(t_input_bytes));
|
||||
DataType* gpu_data_out =
|
||||
static_cast<DataType*>(sycl_device.allocate(t_result_bytes));
|
||||
DataType* gpu_data_in = static_cast<DataType*>(sycl_device.allocate(t_input_bytes));
|
||||
DataType* gpu_data_out = static_cast<DataType*>(sycl_device.allocate(t_result_bytes));
|
||||
|
||||
array<IndexType, 3> tensorRange = {{m_size, k_size, n_size}};
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_t_input(
|
||||
gpu_data_in, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_t_result(
|
||||
gpu_data_out, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_t_input(gpu_data_in, tensorRange);
|
||||
TensorMap<Tensor<DataType, 3, DataLayout, IndexType>> gpu_t_result(gpu_data_out, tensorRange);
|
||||
sycl_device.memcpyHostToDevice(gpu_data_in, t_input.data(), t_input_bytes);
|
||||
sycl_device.memcpyHostToDevice(gpu_data_out, t_input.data(), t_input_bytes);
|
||||
|
||||
@@ -55,21 +49,18 @@ void test_sycl_cumsum(const Eigen::SyclDevice& sycl_device, IndexType m_size,
|
||||
|
||||
t_result = t_input.cumsum(consume_dim, exclusive);
|
||||
|
||||
sycl_device.memcpyDeviceToHost(t_result_gpu.data(), gpu_data_out,
|
||||
t_result_bytes);
|
||||
sycl_device.memcpyDeviceToHost(t_result_gpu.data(), gpu_data_out, t_result_bytes);
|
||||
sycl_device.synchronize();
|
||||
|
||||
for (IndexType i = 0; i < t_result.size(); i++) {
|
||||
if (static_cast<DataType>(std::fabs(static_cast<DataType>(
|
||||
t_result(i) - t_result_gpu(i)))) < error_threshold) {
|
||||
if (static_cast<DataType>(std::fabs(static_cast<DataType>(t_result(i) - t_result_gpu(i)))) < error_threshold) {
|
||||
continue;
|
||||
}
|
||||
if (Eigen::internal::isApprox(t_result(i), t_result_gpu(i),
|
||||
error_threshold)) {
|
||||
if (Eigen::internal::isApprox(t_result(i), t_result_gpu(i), error_threshold)) {
|
||||
continue;
|
||||
}
|
||||
std::cout << "mismatch detected at index " << i << " CPU : " << t_result(i)
|
||||
<< " vs SYCL : " << t_result_gpu(i) << std::endl;
|
||||
std::cout << "mismatch detected at index " << i << " CPU : " << t_result(i) << " vs SYCL : " << t_result_gpu(i)
|
||||
<< std::endl;
|
||||
assert(false);
|
||||
}
|
||||
sycl_device.deallocate(gpu_data_in);
|
||||
@@ -78,64 +69,44 @@ void test_sycl_cumsum(const Eigen::SyclDevice& sycl_device, IndexType m_size,
|
||||
|
||||
template <typename DataType, typename Dev>
|
||||
void sycl_scan_test_exclusive_dim0_per_device(const Dev& sycl_device) {
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 2049, 1023, 127, 0,
|
||||
true);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 2049, 1023, 127, 0,
|
||||
true);
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 2049, 1023, 127, 0, true);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 2049, 1023, 127, 0, true);
|
||||
}
|
||||
template <typename DataType, typename Dev>
|
||||
void sycl_scan_test_exclusive_dim1_per_device(const Dev& sycl_device) {
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 1023, 2049, 127, 1,
|
||||
true);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 1023, 2049, 127, 1,
|
||||
true);
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 1023, 2049, 127, 1, true);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 1023, 2049, 127, 1, true);
|
||||
}
|
||||
template <typename DataType, typename Dev>
|
||||
void sycl_scan_test_exclusive_dim2_per_device(const Dev& sycl_device) {
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 1023, 127, 2049, 2,
|
||||
true);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 1023, 127, 2049, 2,
|
||||
true);
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 1023, 127, 2049, 2, true);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 1023, 127, 2049, 2, true);
|
||||
}
|
||||
template <typename DataType, typename Dev>
|
||||
void sycl_scan_test_inclusive_dim0_per_device(const Dev& sycl_device) {
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 2049, 1023, 127, 0,
|
||||
false);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 2049, 1023, 127, 0,
|
||||
false);
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 2049, 1023, 127, 0, false);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 2049, 1023, 127, 0, false);
|
||||
}
|
||||
template <typename DataType, typename Dev>
|
||||
void sycl_scan_test_inclusive_dim1_per_device(const Dev& sycl_device) {
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 1023, 2049, 127, 1,
|
||||
false);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 1023, 2049, 127, 1,
|
||||
false);
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 1023, 2049, 127, 1, false);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 1023, 2049, 127, 1, false);
|
||||
}
|
||||
template <typename DataType, typename Dev>
|
||||
void sycl_scan_test_inclusive_dim2_per_device(const Dev& sycl_device) {
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 1023, 127, 2049, 2,
|
||||
false);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 1023, 127, 2049, 2,
|
||||
false);
|
||||
test_sycl_cumsum<DataType, ColMajor, int64_t>(sycl_device, 1023, 127, 2049, 2, false);
|
||||
test_sycl_cumsum<DataType, RowMajor, int64_t>(sycl_device, 1023, 127, 2049, 2, false);
|
||||
}
|
||||
EIGEN_DECLARE_TEST(cxx11_tensor_scan_sycl) {
|
||||
for (const auto& device : Eigen::get_sycl_supported_devices()) {
|
||||
std::cout << "Running on "
|
||||
<< device.template get_info<cl::sycl::info::device::name>()
|
||||
<< std::endl;
|
||||
std::cout << "Running on " << device.template get_info<cl::sycl::info::device::name>() << std::endl;
|
||||
QueueInterface queueInterface(device);
|
||||
auto sycl_device = Eigen::SyclDevice(&queueInterface);
|
||||
CALL_SUBTEST_1(
|
||||
sycl_scan_test_exclusive_dim0_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_2(
|
||||
sycl_scan_test_exclusive_dim1_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_3(
|
||||
sycl_scan_test_exclusive_dim2_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_4(
|
||||
sycl_scan_test_inclusive_dim0_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_5(
|
||||
sycl_scan_test_inclusive_dim1_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_6(
|
||||
sycl_scan_test_inclusive_dim2_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_1(sycl_scan_test_exclusive_dim0_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_2(sycl_scan_test_exclusive_dim1_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_3(sycl_scan_test_exclusive_dim2_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_4(sycl_scan_test_inclusive_dim0_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_5(sycl_scan_test_inclusive_dim1_per_device<float>(sycl_device));
|
||||
CALL_SUBTEST_6(sycl_scan_test_inclusive_dim2_per_device<float>(sycl_device));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user