mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-16 21:55:58 +08:00
Fixed existing test.
This commit is contained in:
parent
c5130dedbe
commit
7878756dea
@ -25,8 +25,7 @@ using Eigen::SyclDevice;
|
|||||||
using Eigen::Tensor;
|
using Eigen::Tensor;
|
||||||
using Eigen::TensorMap;
|
using Eigen::TensorMap;
|
||||||
|
|
||||||
namespace std
|
namespace std {
|
||||||
{
|
|
||||||
template <typename T> T rsqrt(T x) { return 1 / std::sqrt(x); }
|
template <typename T> T rsqrt(T x) { return 1 / std::sqrt(x); }
|
||||||
template <typename T> T square(T x) { return x * x; }
|
template <typename T> T square(T x) { return x * x; }
|
||||||
template <typename T> T cube(T x) { return x * x * x; }
|
template <typename T> T cube(T x) { return x * x * x; }
|
||||||
@ -35,18 +34,25 @@ namespace std
|
|||||||
|
|
||||||
#define TEST_UNARY_BUILTINS_FOR_SCALAR(FUNC, SCALAR) \
|
#define TEST_UNARY_BUILTINS_FOR_SCALAR(FUNC, SCALAR) \
|
||||||
{ \
|
{ \
|
||||||
Tensor<SCALAR, 3> in1(tensorRange); \
|
Tensor<SCALAR, 3> in(tensorRange); \
|
||||||
Tensor<SCALAR, 3> out1(tensorRange); \
|
Tensor<SCALAR, 3> out(tensorRange); \
|
||||||
in1 = in1.random(); \
|
in = in.random(); \
|
||||||
SCALAR* gpu_data1 = static_cast<SCALAR*>(sycl_device.allocate(in1.size()*sizeof(SCALAR))); \
|
SCALAR *gpu_data = static_cast<SCALAR *>( \
|
||||||
TensorMap<Tensor<SCALAR, 3>> gpu1(gpu_data1, tensorRange); \
|
sycl_device.allocate(in.size() * sizeof(SCALAR))); \
|
||||||
sycl_device.memcpyHostToDevice(gpu_data1, in1.data(),(in1.size())*sizeof(SCALAR)); \
|
SCALAR *gpu_data_out = static_cast<SCALAR *>( \
|
||||||
gpu1.device(sycl_device) = gpu1.FUNC(); \
|
sycl_device.allocate(out.size() * sizeof(SCALAR))); \
|
||||||
sycl_device.memcpyDeviceToHost(out1.data(), gpu_data1,(out1.size())*sizeof(SCALAR)); \
|
TensorMap<Tensor<SCALAR, 3>> gpu(gpu_data, tensorRange); \
|
||||||
for (int i = 0; i < in1.size(); ++i) { \
|
TensorMap<Tensor<SCALAR, 3>> gpu_out(gpu_data_out, tensorRange); \
|
||||||
VERIFY_IS_APPROX(out1(i), std::FUNC(in1(i))); \
|
sycl_device.memcpyHostToDevice(gpu_data, in.data(), \
|
||||||
|
(in.size()) * sizeof(SCALAR)); \
|
||||||
|
gpu_out.device(sycl_device) = gpu.FUNC(); \
|
||||||
|
sycl_device.memcpyDeviceToHost(out.data(), gpu_data_out, \
|
||||||
|
(out.size()) * sizeof(SCALAR)); \
|
||||||
|
for (int i = 0; i < in.size(); ++i) { \
|
||||||
|
VERIFY_IS_APPROX(out(i), std::FUNC(in(i))); \
|
||||||
} \
|
} \
|
||||||
sycl_device.deallocate(gpu_data1); \
|
sycl_device.deallocate(gpu_data); \
|
||||||
|
sycl_device.deallocate(gpu_data_out); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TEST_UNARY_BUILTINS(SCALAR) \
|
#define TEST_UNARY_BUILTINS(SCALAR) \
|
||||||
@ -73,8 +79,8 @@ static void test_builtin_unary_sycl(const Eigen::SyclDevice &sycl_device){
|
|||||||
|
|
||||||
TEST_UNARY_BUILTINS(float)
|
TEST_UNARY_BUILTINS(float)
|
||||||
TEST_UNARY_BUILTINS(double)
|
TEST_UNARY_BUILTINS(double)
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void test_cxx11_tensor_builtins_sycl() {
|
void test_cxx11_tensor_builtins_sycl() {
|
||||||
cl::sycl::gpu_selector s;
|
cl::sycl::gpu_selector s;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user