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

[SYCL] Update devicelib tests with latest changes in intel/llvm #27

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SYCL/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: LLVM
CommentPragmas: "(RUN|FAIL|REQUIRES|UNSUPPORTED|CHECK) *:|expected-"
5 changes: 2 additions & 3 deletions SYCL/Basic/devicelib/assert-windows.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// REQUIRES: cpu,windows
//
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/../bin/libsycl-msvc.o -o %t.out
//
// FIXME: OpenCL CPU backend compiler crashes on a call to _wassert.
// Disable the test until the fix reaches SYCL test infrastructure.
// XFAIL: *
//
// RUN: %clangxx -fsycl %s -o %t.out
//
// MSVC implementation of assert does not call an unreachable built-in, so the
// program doesn't terminate when fallback is used.
//
Expand Down
8 changes: 4 additions & 4 deletions SYCL/Basic/devicelib/cmath_fp64_test.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// UNSUPPORTED: windows
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath-fp64.o -o %t.out
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// Disabled on windows due to bug VS 2019 missing math builtins
//
// RUN: %clangxx -fsycl -fsycl-device-lib=libm-fp64 %s -o %t.out
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
// REQUIRES: host || cpu || accelerator

#include <CL/sycl.hpp>
#include <cmath>
Expand Down
86 changes: 57 additions & 29 deletions SYCL/Basic/devicelib/cmath_test.cpp
Original file line number Diff line number Diff line change
@@ -1,53 +1,46 @@
// UNSUPPORTED: windows
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath.o -o %t.out
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// Disabled on windows due to bug VS 2019 missing math builtins

// RUN: %clangxx -fsycl %s -o %t.out
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
// REQUIRES: host || cpu || accelerator

#include "math_utils.hpp"
#include <CL/sycl.hpp>
#include <cmath>
#include <iostream>
#include "math_utils.hpp"

namespace s = cl::sycl;
constexpr s::access::mode sycl_read = s::access::mode::read;
constexpr s::access::mode sycl_write = s::access::mode::write;

#define TEST_NUM 38
#define TEST_NUM 36

float ref[TEST_NUM] = {
1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5,
0, 2, 0, 0, 1, 0, 2, 0, 0, 0,
0, 0, 1, 0, 1, 2, 0, 1, 2, 5,
0, 0, 0, 0, 0.5, 0.5, NAN, NAN,};
float ref[TEST_NUM] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 0,
1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 2,
0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN};

float refIptr = 1;

template <class T>
void device_cmath_test(s::queue &deviceQueue) {
template <class T> void device_cmath_test_1(s::queue &deviceQueue) {
s::range<1> numOfItems{TEST_NUM};
T result[TEST_NUM] = {-1};

// Variable exponent is an integer value to store the exponent in frexp function
int exponent = -1;

// Variable iptr stores the integral part of float point in modf function
T iptr = -1;

// Variable quo stores the sign and some bits of x/y in remquo function
int quo = -1;
{
s::buffer<T, 1> buffer1(result, numOfItems);
s::buffer<int, 1> buffer2(&exponent, s::range<1>{1});
s::buffer<T, 1> buffer3(&iptr, s::range<1>{1});
s::buffer<int, 1> buffer4(&quo, s::range<1>{1});
s::buffer<T, 1> buffer2(&iptr, s::range<1>{1});
s::buffer<int, 1> buffer3(&quo, s::range<1>{1});
deviceQueue.submit([&](cl::sycl::handler &cgh) {
auto res_access = buffer1.template get_access<sycl_write>(cgh);
auto exp_access = buffer2.template get_access<sycl_write>(cgh);
auto iptr_access = buffer3.template get_access<sycl_write>(cgh);
auto quo_access = buffer4.template get_access<sycl_write>(cgh);
cgh.single_task<class DeviceMathTest>([=]() {
auto iptr_access = buffer2.template get_access<sycl_write>(cgh);
auto quo_access = buffer3.template get_access<sycl_write>(cgh);
cgh.single_task<class DeviceMathTest1>([=]() {
int i = 0;
res_access[i++] = std::cos(0.0f);
res_access[i++] = std::sin(0.0f);
Expand All @@ -59,8 +52,6 @@ void device_cmath_test(s::queue &deviceQueue) {
res_access[i++] = std::cosh(0.0f);
res_access[i++] = std::exp(0.0f);
res_access[i++] = std::fmod(1.5f, 1.0f);
res_access[i++] = std::frexp(0.0f, &exp_access[0]);
res_access[i++] = std::ldexp(1.0f, 1);
res_access[i++] = std::log10(1.0f);
res_access[i++] = std::modf(1.0f, &iptr_access[0]);
res_access[i++] = std::pow(1.0f, 1.0f);
Expand Down Expand Up @@ -100,16 +91,53 @@ void device_cmath_test(s::queue &deviceQueue) {
// Test modf integral part
assert(approx_equal_fp(iptr, refIptr));

// Test frexp exponent
assert(exponent == 0);

// Test remquo sign
assert(quo == 0);
}

// MSVC implements std::ldexp<float> and std::frexp<float> by invoking the
// 'double' version of corresponding C math functions(ldexp and frexp). Those
// 2 functions can only work on Windows with fp64 extension support from
// underlying device.
#ifndef _WIN32
template <class T> void device_cmath_test_2(s::queue &deviceQueue) {
s::range<1> numOfItems{2};
T result[2] = {-1};
T ref[2] = {0, 2};
// Variable exponent is an integer value to store the exponent in frexp
// function
int exponent = -1;

{
s::buffer<T, 1> buffer1(result, numOfItems);
s::buffer<int, 1> buffer2(&exponent, s::range<1>{1});
deviceQueue.submit([&](cl::sycl::handler &cgh) {
auto res_access = buffer1.template get_access<sycl_write>(cgh);
auto exp_access = buffer2.template get_access<sycl_write>(cgh);
cgh.single_task<class DeviceMathTest2>([=]() {
int i = 0;
res_access[i++] = std::frexp(0.0f, &exp_access[0]);
res_access[i++] = std::ldexp(1.0f, 1);
});
});
}

// Compare result with reference
for (int i = 0; i < 2; ++i) {
assert(approx_equal_fp(result[i], ref[i]));
}

// Test frexp exponent
assert(exponent == 0);
}
#endif

int main() {
s::queue deviceQueue;
device_cmath_test<float>(deviceQueue);
device_cmath_test_1<float>(deviceQueue);
#ifndef _WIN32
device_cmath_test_2<float>(deviceQueue);
#endif
std::cout << "Pass" << std::endl;
return 0;
}
10 changes: 6 additions & 4 deletions SYCL/Basic/devicelib/math_fp64_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// REQUIRES: (host || cpu || accelerator) && linux
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath-fp64.o -o %t.out
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// UNSUPPORTED: windows
// Disabled on windows due to bug VS 2019 missing math builtins

// RUN: %clangxx -fsycl -fsycl-device-lib=libm-fp64 %s -o %t.out
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

#include "math_utils.hpp"
#include <CL/sycl.hpp>
#include <iostream>
Expand Down
3 changes: 3 additions & 0 deletions SYCL/Basic/devicelib/math_fp64_windows_test.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// UNSUPPORTED: windows
// Disabled on windows due to bug VS 2019 missing math builtins

// REQUIRES: (cpu || host || accelerator) && windows
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/../bin/libsycl-cmath-fp64.o -o %t.out
Expand Down
9 changes: 4 additions & 5 deletions SYCL/Basic/devicelib/math_override_test.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// UNSUPPORTED: windows
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath.o -o %t.out
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// REQUIRES: host
// RUN: %clangxx -fsycl %s -o %t.out -fno-builtin
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
#include <CL/sycl.hpp>
#include <iostream>
#include <math.h>
Expand All @@ -17,6 +15,8 @@ constexpr s::access::mode sycl_write = s::access::mode::write;
SYCL_EXTERNAL
extern "C" float sinf(float x) { return x + 100.f; }

SYCL_EXTERNAL
extern "C" float cosf(float x);
class DeviceTest;

void device_test() {
Expand All @@ -38,7 +38,6 @@ void device_test() {
});
});
}

assert(approx_equal_fp(result_sin, 100.f) && approx_equal_fp(result_cos, 1.f));
}

Expand Down
38 changes: 14 additions & 24 deletions SYCL/Basic/devicelib/math_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// REQUIRES: ( host || accelerator || cpu ) && linux
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-cmath.o -o %t.out
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// UNSUPPORTED: windows
// Disabled on windows due to bug VS 2019 missing math builtins

// RUN: %clangxx -fsycl %s -o %t.out
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

#include "math_utils.hpp"
#include <CL/sycl.hpp>
#include <iostream>
Expand All @@ -13,38 +15,31 @@ namespace s = cl::sycl;
constexpr s::access::mode sycl_read = s::access::mode::read;
constexpr s::access::mode sycl_write = s::access::mode::write;

#define TEST_NUM 38
#define TEST_NUM 36

float ref_val[TEST_NUM] = {
1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5,
0, 2, 0, 0, 1, 0, 2, 0, 0, 0,
0, 0, 1, 0, 1, 2, 0, 1, 2, 5,
0, 0, 0, 0, 0.5, 0.5, NAN, NAN};
float ref_val[TEST_NUM] = {1, 0, 0, 0, 0, 0, 0, 1, 1, 0.5, 0, 0,
1, 0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 2,
0, 1, 2, 5, 0, 0, 0, 0, 0.5, 0.5, NAN, NAN};

float refIptr = 1;

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

// Variable exponent is an integer value to store the exponent in frexp function
int exponent = -1;

// Variable iptr stores the integral part of float point in modf function
float iptr = -1;

// Variable quo stores the sign and some bits of x/y in remquo function
int quo = -1;
{
s::buffer<float, 1> buffer1(result, numOfItems);
s::buffer<int, 1> buffer2(&exponent, s::range<1>{1});
s::buffer<float, 1> buffer3(&iptr, s::range<1>{1});
s::buffer<int, 1> buffer4(&quo, s::range<1>{1});
s::buffer<float, 1> buffer2(&iptr, s::range<1>{1});
s::buffer<int, 1> buffer3(&quo, s::range<1>{1});
deviceQueue.submit([&](cl::sycl::handler &cgh) {
auto res_access = buffer1.template get_access<sycl_write>(cgh);
auto exp_access = buffer2.template get_access<sycl_write>(cgh);
auto iptr_access = buffer3.template get_access<sycl_write>(cgh);
auto quo_access = buffer4.template get_access<sycl_write>(cgh);
auto iptr_access = buffer2.template get_access<sycl_write>(cgh);
auto quo_access = buffer3.template get_access<sycl_write>(cgh);
cgh.single_task<class DeviceMathTest>([=]() {
int i = 0;
res_access[i++] = cosf(0.0f);
Expand All @@ -57,8 +52,6 @@ void device_math_test(s::queue &deviceQueue) {
res_access[i++] = coshf(0.0f);
res_access[i++] = expf(0.0f);
res_access[i++] = fmodf(1.5f, 1.0f);
res_access[i++] = frexpf(0.0f, &exp_access[0]);
res_access[i++] = ldexpf(1.0f, 1);
res_access[i++] = log10f(1.0f);
res_access[i++] = modff(1.0f, &iptr_access[0]);
res_access[i++] = powf(1.0f, 1.0f);
Expand Down Expand Up @@ -98,9 +91,6 @@ void device_math_test(s::queue &deviceQueue) {
// Test modf integral part
assert(approx_equal_fp(iptr, refIptr));

// Test frexp exponent
assert(exponent == 0);

// Test remquo sign
assert(quo == 0);
}
Expand Down
5 changes: 5 additions & 0 deletions SYCL/Basic/devicelib/math_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#ifndef MATH_UTILS
#include <cmath>
#include <limits>
// _USE_MATH_DEFINES must be defined in order to use math constants in MSVC
#ifdef _WIN32
#define _USE_MATH_DEFINES 1
#include <math.h>
#endif

// Since it is not proper to compare float point using operator ==, this
// function measures whether the result of cmath function from kernel is
Expand Down
3 changes: 3 additions & 0 deletions SYCL/Basic/devicelib/math_windows_test.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// UNSUPPORTED: windows
// Disabled on windows due to bug VS 2019 missing math builtins

// REQUIRES: (accelerator || cpu || host) && windows
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/../bin/libsycl-cmath.o -o %t.out
Expand Down
15 changes: 7 additions & 8 deletions SYCL/Basic/devicelib/std_complex_math_fp64_test.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// UNSUPPORTED: windows
// RUN: %clangxx -fsycl -c %s -o %t.o
// RUN: %clangxx -fsycl %t.o %sycl_libs_dir/libsycl-complex-fp64.o %sycl_libs_dir/libsycl-cmath-fp64.o -o %t.out
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// Disabled on windows due to bug VS 2019 missing math builtins

// RUN: %clangxx -fsycl -fsycl-device-lib=libm-fp64 %s -o %t.out
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
// REQUIRES: host || cpu || accelerator

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

template <typename T>
bool approx_equal_cmplx(complex<T> x, complex<T> y) {
template <typename T> bool approx_equal_cmplx(complex<T> x, complex<T> y) {
return approx_equal_fp(x.real(), y.real()) &&
approx_equal_fp(x.imag(), y.imag());
}
Expand Down Expand Up @@ -87,8 +86,8 @@ std::array<complex<double>, TestArraySize1> ref1_results = {
complex<double>(M_PI_2, 0.),
complex<double>(M_PI_2, 0.549306144334055)};

std::array<double, TestArraySize2> ref2_results = {0., 25., 169., INFINITY, 0.,
5., 13., INFINITY, 0., M_PI_2};
std::array<double, TestArraySize2> ref2_results = {
0., 25., 169., INFINITY, 0., 5., 13., INFINITY, 0., M_PI_2};

void device_complex_test(s::queue &deviceQueue) {
s::range<1> numOfItems1{TestArraySize1};
Expand Down
Loading