Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 48dfdf2

Browse files
authored
[SYCL] Update devicelib tests with latest changes in intel/llvm (#27)
1 parent df2724a commit 48dfdf2

12 files changed

+191
-161
lines changed

SYCL/.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BasedOnStyle: LLVM
2+
CommentPragmas: "(RUN|FAIL|REQUIRES|UNSUPPORTED|CHECK) *:|expected-"

SYCL/Basic/devicelib/assert-windows.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// REQUIRES: cpu,windows
22
//
3-
// RUN: %clangxx -fsycl -c %s -o %t.o
4-
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/../bin/libsycl-msvc.o -o %t.out
5-
//
63
// FIXME: OpenCL CPU backend compiler crashes on a call to _wassert.
74
// Disable the test until the fix reaches SYCL test infrastructure.
85
// XFAIL: *
96
//
7+
// RUN: %clangxx -fsycl %s -o %t.out
8+
//
109
// MSVC implementation of assert does not call an unreachable built-in, so the
1110
// program doesn't terminate when fallback is used.
1211
//

SYCL/Basic/devicelib/cmath_fp64_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// UNSUPPORTED: windows
2-
// RUN: %clangxx -fsycl -c %s -o %t.o
3-
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath-fp64.o -o %t.out
4-
// RUN: %HOST_RUN_PLACEHOLDER %t.out
2+
// Disabled on windows due to bug VS 2019 missing math builtins
3+
//
4+
// RUN: %clangxx -fsycl -fsycl-device-lib=libm-fp64 %s -o %t.out
5+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
56
// RUN: %CPU_RUN_PLACEHOLDER %t.out
67
// RUN: %ACC_RUN_PLACEHOLDER %t.out
7-
// REQUIRES: host || cpu || accelerator
88

99
#include <CL/sycl.hpp>
1010
#include <cmath>

SYCL/Basic/devicelib/cmath_test.cpp

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,46 @@
11
// UNSUPPORTED: windows
2-
// RUN: %clangxx -fsycl -c %s -o %t.o
3-
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath.o -o %t.out
4-
// RUN: %HOST_RUN_PLACEHOLDER %t.out
2+
// Disabled on windows due to bug VS 2019 missing math builtins
3+
4+
// RUN: %clangxx -fsycl %s -o %t.out
5+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
56
// RUN: %CPU_RUN_PLACEHOLDER %t.out
67
// RUN: %ACC_RUN_PLACEHOLDER %t.out
7-
// REQUIRES: host || cpu || accelerator
8+
9+
#include "math_utils.hpp"
810
#include <CL/sycl.hpp>
911
#include <cmath>
1012
#include <iostream>
11-
#include "math_utils.hpp"
1213

1314
namespace s = cl::sycl;
1415
constexpr s::access::mode sycl_read = s::access::mode::read;
1516
constexpr s::access::mode sycl_write = s::access::mode::write;
1617

17-
#define TEST_NUM 38
18+
#define TEST_NUM 36
1819

19-
float ref[TEST_NUM] = {
20-
1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5,
21-
0, 2, 0, 0, 1, 0, 2, 0, 0, 0,
22-
0, 0, 1, 0, 1, 2, 0, 1, 2, 5,
23-
0, 0, 0, 0, 0.5, 0.5, NAN, NAN,};
20+
float ref[TEST_NUM] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 0,
21+
1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 2,
22+
0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN};
2423

2524
float refIptr = 1;
2625

27-
template <class T>
28-
void device_cmath_test(s::queue &deviceQueue) {
26+
template <class T> void device_cmath_test_1(s::queue &deviceQueue) {
2927
s::range<1> numOfItems{TEST_NUM};
3028
T result[TEST_NUM] = {-1};
3129

32-
// Variable exponent is an integer value to store the exponent in frexp function
33-
int exponent = -1;
34-
3530
// Variable iptr stores the integral part of float point in modf function
3631
T iptr = -1;
3732

3833
// Variable quo stores the sign and some bits of x/y in remquo function
3934
int quo = -1;
4035
{
4136
s::buffer<T, 1> buffer1(result, numOfItems);
42-
s::buffer<int, 1> buffer2(&exponent, s::range<1>{1});
43-
s::buffer<T, 1> buffer3(&iptr, s::range<1>{1});
44-
s::buffer<int, 1> buffer4(&quo, s::range<1>{1});
37+
s::buffer<T, 1> buffer2(&iptr, s::range<1>{1});
38+
s::buffer<int, 1> buffer3(&quo, s::range<1>{1});
4539
deviceQueue.submit([&](cl::sycl::handler &cgh) {
4640
auto res_access = buffer1.template get_access<sycl_write>(cgh);
47-
auto exp_access = buffer2.template get_access<sycl_write>(cgh);
48-
auto iptr_access = buffer3.template get_access<sycl_write>(cgh);
49-
auto quo_access = buffer4.template get_access<sycl_write>(cgh);
50-
cgh.single_task<class DeviceMathTest>([=]() {
41+
auto iptr_access = buffer2.template get_access<sycl_write>(cgh);
42+
auto quo_access = buffer3.template get_access<sycl_write>(cgh);
43+
cgh.single_task<class DeviceMathTest1>([=]() {
5144
int i = 0;
5245
res_access[i++] = std::cos(0.0f);
5346
res_access[i++] = std::sin(0.0f);
@@ -59,8 +52,6 @@ void device_cmath_test(s::queue &deviceQueue) {
5952
res_access[i++] = std::cosh(0.0f);
6053
res_access[i++] = std::exp(0.0f);
6154
res_access[i++] = std::fmod(1.5f, 1.0f);
62-
res_access[i++] = std::frexp(0.0f, &exp_access[0]);
63-
res_access[i++] = std::ldexp(1.0f, 1);
6455
res_access[i++] = std::log10(1.0f);
6556
res_access[i++] = std::modf(1.0f, &iptr_access[0]);
6657
res_access[i++] = std::pow(1.0f, 1.0f);
@@ -100,16 +91,53 @@ void device_cmath_test(s::queue &deviceQueue) {
10091
// Test modf integral part
10192
assert(approx_equal_fp(iptr, refIptr));
10293

103-
// Test frexp exponent
104-
assert(exponent == 0);
105-
10694
// Test remquo sign
10795
assert(quo == 0);
10896
}
10997

98+
// MSVC implements std::ldexp<float> and std::frexp<float> by invoking the
99+
// 'double' version of corresponding C math functions(ldexp and frexp). Those
100+
// 2 functions can only work on Windows with fp64 extension support from
101+
// underlying device.
102+
#ifndef _WIN32
103+
template <class T> void device_cmath_test_2(s::queue &deviceQueue) {
104+
s::range<1> numOfItems{2};
105+
T result[2] = {-1};
106+
T ref[2] = {0, 2};
107+
// Variable exponent is an integer value to store the exponent in frexp
108+
// function
109+
int exponent = -1;
110+
111+
{
112+
s::buffer<T, 1> buffer1(result, numOfItems);
113+
s::buffer<int, 1> buffer2(&exponent, s::range<1>{1});
114+
deviceQueue.submit([&](cl::sycl::handler &cgh) {
115+
auto res_access = buffer1.template get_access<sycl_write>(cgh);
116+
auto exp_access = buffer2.template get_access<sycl_write>(cgh);
117+
cgh.single_task<class DeviceMathTest2>([=]() {
118+
int i = 0;
119+
res_access[i++] = std::frexp(0.0f, &exp_access[0]);
120+
res_access[i++] = std::ldexp(1.0f, 1);
121+
});
122+
});
123+
}
124+
125+
// Compare result with reference
126+
for (int i = 0; i < 2; ++i) {
127+
assert(approx_equal_fp(result[i], ref[i]));
128+
}
129+
130+
// Test frexp exponent
131+
assert(exponent == 0);
132+
}
133+
#endif
134+
110135
int main() {
111136
s::queue deviceQueue;
112-
device_cmath_test<float>(deviceQueue);
137+
device_cmath_test_1<float>(deviceQueue);
138+
#ifndef _WIN32
139+
device_cmath_test_2<float>(deviceQueue);
140+
#endif
113141
std::cout << "Pass" << std::endl;
114142
return 0;
115143
}

SYCL/Basic/devicelib/math_fp64_test.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// REQUIRES: (host || cpu || accelerator) && linux
2-
// RUN: %clangxx -fsycl -c %s -o %t.o
3-
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath-fp64.o -o %t.out
4-
// RUN: %HOST_RUN_PLACEHOLDER %t.out
1+
// UNSUPPORTED: windows
2+
// Disabled on windows due to bug VS 2019 missing math builtins
3+
4+
// RUN: %clangxx -fsycl -fsycl-device-lib=libm-fp64 %s -o %t.out
5+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
56
// RUN: %CPU_RUN_PLACEHOLDER %t.out
67
// RUN: %ACC_RUN_PLACEHOLDER %t.out
8+
79
#include "math_utils.hpp"
810
#include <CL/sycl.hpp>
911
#include <iostream>

SYCL/Basic/devicelib/math_fp64_windows_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// UNSUPPORTED: windows
2+
// Disabled on windows due to bug VS 2019 missing math builtins
3+
14
// REQUIRES: (cpu || host || accelerator) && windows
25
// RUN: %clangxx -fsycl -c %s -o %t.o
36
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/../bin/libsycl-cmath-fp64.o -o %t.out

SYCL/Basic/devicelib/math_override_test.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// UNSUPPORTED: windows
2-
// RUN: %clangxx -fsycl -c %s -o %t.o
3-
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath.o -o %t.out
4-
// RUN: %HOST_RUN_PLACEHOLDER %t.out
5-
// REQUIRES: host
2+
// RUN: %clangxx -fsycl %s -o %t.out -fno-builtin
3+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
64
#include <CL/sycl.hpp>
75
#include <iostream>
86
#include <math.h>
@@ -17,6 +15,8 @@ constexpr s::access::mode sycl_write = s::access::mode::write;
1715
SYCL_EXTERNAL
1816
extern "C" float sinf(float x) { return x + 100.f; }
1917

18+
SYCL_EXTERNAL
19+
extern "C" float cosf(float x);
2020
class DeviceTest;
2121

2222
void device_test() {
@@ -38,7 +38,6 @@ void device_test() {
3838
});
3939
});
4040
}
41-
4241
assert(approx_equal_fp(result_sin, 100.f) && approx_equal_fp(result_cos, 1.f));
4342
}
4443

SYCL/Basic/devicelib/math_test.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// REQUIRES: ( host || accelerator || cpu ) && linux
2-
// RUN: %clangxx -fsycl -c %s -o %t.o
3-
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath.o -o %t.out
4-
// RUN: %HOST_RUN_PLACEHOLDER %t.out
1+
// UNSUPPORTED: windows
2+
// Disabled on windows due to bug VS 2019 missing math builtins
3+
4+
// RUN: %clangxx -fsycl %s -o %t.out
5+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
56
// RUN: %CPU_RUN_PLACEHOLDER %t.out
67
// RUN: %ACC_RUN_PLACEHOLDER %t.out
8+
79
#include "math_utils.hpp"
810
#include <CL/sycl.hpp>
911
#include <iostream>
@@ -13,38 +15,31 @@ namespace s = cl::sycl;
1315
constexpr s::access::mode sycl_read = s::access::mode::read;
1416
constexpr s::access::mode sycl_write = s::access::mode::write;
1517

16-
#define TEST_NUM 38
18+
#define TEST_NUM 36
1719

18-
float ref_val[TEST_NUM] = {
19-
1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5,
20-
0, 2, 0, 0, 1, 0, 2, 0, 0, 0,
21-
0, 0, 1, 0, 1, 2, 0, 1, 2, 5,
22-
0, 0, 0, 0, 0.5, 0.5, NAN, NAN};
20+
float ref_val[TEST_NUM] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 0,
21+
1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 2,
22+
0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN};
2323

2424
float refIptr = 1;
2525

2626
void device_math_test(s::queue &deviceQueue) {
2727
s::range<1> numOfItems{TEST_NUM};
2828
float result[TEST_NUM] = {-1};
2929

30-
// Variable exponent is an integer value to store the exponent in frexp function
31-
int exponent = -1;
32-
3330
// Variable iptr stores the integral part of float point in modf function
3431
float iptr = -1;
3532

3633
// Variable quo stores the sign and some bits of x/y in remquo function
3734
int quo = -1;
3835
{
3936
s::buffer<float, 1> buffer1(result, numOfItems);
40-
s::buffer<int, 1> buffer2(&exponent, s::range<1>{1});
41-
s::buffer<float, 1> buffer3(&iptr, s::range<1>{1});
42-
s::buffer<int, 1> buffer4(&quo, s::range<1>{1});
37+
s::buffer<float, 1> buffer2(&iptr, s::range<1>{1});
38+
s::buffer<int, 1> buffer3(&quo, s::range<1>{1});
4339
deviceQueue.submit([&](cl::sycl::handler &cgh) {
4440
auto res_access = buffer1.template get_access<sycl_write>(cgh);
45-
auto exp_access = buffer2.template get_access<sycl_write>(cgh);
46-
auto iptr_access = buffer3.template get_access<sycl_write>(cgh);
47-
auto quo_access = buffer4.template get_access<sycl_write>(cgh);
41+
auto iptr_access = buffer2.template get_access<sycl_write>(cgh);
42+
auto quo_access = buffer3.template get_access<sycl_write>(cgh);
4843
cgh.single_task<class DeviceMathTest>([=]() {
4944
int i = 0;
5045
res_access[i++] = cosf(0.0f);
@@ -57,8 +52,6 @@ void device_math_test(s::queue &deviceQueue) {
5752
res_access[i++] = coshf(0.0f);
5853
res_access[i++] = expf(0.0f);
5954
res_access[i++] = fmodf(1.5f, 1.0f);
60-
res_access[i++] = frexpf(0.0f, &exp_access[0]);
61-
res_access[i++] = ldexpf(1.0f, 1);
6255
res_access[i++] = log10f(1.0f);
6356
res_access[i++] = modff(1.0f, &iptr_access[0]);
6457
res_access[i++] = powf(1.0f, 1.0f);
@@ -98,9 +91,6 @@ void device_math_test(s::queue &deviceQueue) {
9891
// Test modf integral part
9992
assert(approx_equal_fp(iptr, refIptr));
10093

101-
// Test frexp exponent
102-
assert(exponent == 0);
103-
10494
// Test remquo sign
10595
assert(quo == 0);
10696
}

SYCL/Basic/devicelib/math_utils.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#ifndef MATH_UTILS
22
#include <cmath>
33
#include <limits>
4+
// _USE_MATH_DEFINES must be defined in order to use math constants in MSVC
5+
#ifdef _WIN32
6+
#define _USE_MATH_DEFINES 1
7+
#include <math.h>
8+
#endif
49

510
// Since it is not proper to compare float point using operator ==, this
611
// function measures whether the result of cmath function from kernel is

SYCL/Basic/devicelib/math_windows_test.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// UNSUPPORTED: windows
2+
// Disabled on windows due to bug VS 2019 missing math builtins
3+
14
// REQUIRES: (accelerator || cpu || host) && windows
25
// RUN: %clangxx -fsycl -c %s -o %t.o
36
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/../bin/libsycl-cmath.o -o %t.out

SYCL/Basic/devicelib/std_complex_math_fp64_test.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// UNSUPPORTED: windows
2-
// RUN: %clangxx -fsycl -c %s -o %t.o
3-
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-complex-fp64.o %sycl_libs_dir/libsycl-cmath-fp64.o -o %t.out
4-
// RUN: %HOST_RUN_PLACEHOLDER %t.out
2+
// Disabled on windows due to bug VS 2019 missing math builtins
3+
4+
// RUN: %clangxx -fsycl -fsycl-device-lib=libm-fp64 %s -o %t.out
5+
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
56
// RUN: %CPU_RUN_PLACEHOLDER %t.out
67
// RUN: %ACC_RUN_PLACEHOLDER %t.out
7-
// REQUIRES: host || cpu || accelerator
88

99
#include <CL/sycl.hpp>
1010
#include <array>
@@ -18,8 +18,7 @@ namespace s = cl::sycl;
1818
constexpr s::access::mode sycl_read = s::access::mode::read;
1919
constexpr s::access::mode sycl_write = s::access::mode::write;
2020

21-
template <typename T>
22-
bool approx_equal_cmplx(complex<T> x, complex<T> y) {
21+
template <typename T> bool approx_equal_cmplx(complex<T> x, complex<T> y) {
2322
return approx_equal_fp(x.real(), y.real()) &&
2423
approx_equal_fp(x.imag(), y.imag());
2524
}
@@ -87,8 +86,8 @@ std::array<complex<double>, TestArraySize1> ref1_results = {
8786
complex<double>(M_PI_2, 0.),
8887
complex<double>(M_PI_2, 0.549306144334055)};
8988

90-
std::array<double, TestArraySize2> ref2_results = {0., 25., 169., INFINITY, 0.,
91-
5., 13., INFINITY, 0., M_PI_2};
89+
std::array<double, TestArraySize2> ref2_results = {
90+
0., 25., 169., INFINITY, 0., 5., 13., INFINITY, 0., M_PI_2};
9291

9392
void device_complex_test(s::queue &deviceQueue) {
9493
s::range<1> numOfItems1{TestArraySize1};

0 commit comments

Comments
 (0)