-
Notifications
You must be signed in to change notification settings - Fork 769
Added missing math APIs for devicelib. #2558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c2b55ba
1725ea3
ffecdcb
7761d25
5f6e2e3
0e8fd04
94a833f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,22 @@ | |
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
#include "math_utils.hpp" | ||
#include <CL/sycl.hpp> | ||
#include <cmath> | ||
#include <cstdint> | ||
#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 63 | ||
|
||
double 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,}; | ||
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, 2, 0, 0, 0, | ||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | ||
|
||
double refIptr = 1; | ||
|
||
|
@@ -47,6 +47,12 @@ void device_cmath_test(s::queue &deviceQueue) { | |
auto quo_access = buffer4.template get_access<sycl_write>(cgh); | ||
cgh.single_task<class DeviceMathTest>([=]() { | ||
int i = 0; | ||
T nan = NAN; | ||
T minus_nan = -NAN; | ||
T infinity = INFINITY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do I understand correctly that this test uses C macro instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really. The C macro is just shorter to write. |
||
T minus_infinity = -INFINITY; | ||
double subnormal; | ||
*((uint64_t *)&subnormal) = 0xFFFFFFFFFFFFFULL; | ||
res_access[i++] = std::cos(0.0); | ||
res_access[i++] = std::sin(0.0); | ||
res_access[i++] = std::log(1.0); | ||
|
@@ -83,9 +89,58 @@ void device_cmath_test(s::queue &deviceQueue) { | |
res_access[i++] = std::logb(1.0); | ||
res_access[i++] = std::remainder(0.5, 1.0); | ||
res_access[i++] = std::remquo(0.5, 1.0, &quo_access[0]); | ||
T a = NAN; | ||
res_access[i++] = std::tgamma(a); | ||
res_access[i++] = std::lgamma(a); | ||
res_access[i++] = std::tgamma(nan); | ||
res_access[i++] = std::lgamma(nan); | ||
res_access[i++] = std::scalbn(1.0, 1); | ||
|
||
res_access[i++] = !(std::signbit(infinity) == 0); | ||
res_access[i++] = !(std::signbit(minus_infinity) != 0); | ||
res_access[i++] = !(std::signbit(nan) == 0); | ||
res_access[i++] = !(std::signbit(minus_nan) != 0); | ||
|
||
res_access[i++] = !(std::isunordered(minus_nan, nan) != 0); | ||
res_access[i++] = !(std::isunordered(minus_infinity, infinity) == 0); | ||
res_access[i++] = !(std::isgreater(minus_infinity, infinity) == 0); | ||
res_access[i++] = !(std::isgreater(0.0f, minus_nan) == 0); | ||
#ifdef _WIN32 | ||
res_access[i++] = !(std::isfinite(0.0f) != 0); | ||
res_access[i++] = !(std::isfinite(nan) == 0); | ||
res_access[i++] = !(std::isfinite(infinity) == 0); | ||
res_access[i++] = !(std::isfinite(minus_infinity) == 0); | ||
|
||
res_access[i++] = !(std::isinf(0.0f) == 0); | ||
res_access[i++] = !(std::isinf(nan) == 0); | ||
res_access[i++] = !(std::isinf(infinity) != 0); | ||
res_access[i++] = !(std::isinf(minus_infinity) != 0); | ||
#else // !_WIN32 | ||
// __builtin_isfinite is unsupported. | ||
res_access[i++] = 0; | ||
res_access[i++] = 0; | ||
res_access[i++] = 0; | ||
res_access[i++] = 0; | ||
|
||
// __builtin_isinf is unsupported. | ||
res_access[i++] = 0; | ||
res_access[i++] = 0; | ||
res_access[i++] = 0; | ||
res_access[i++] = 0; | ||
#endif // !_WIN32 | ||
res_access[i++] = !(std::isnan(0.0f) == 0); | ||
res_access[i++] = !(std::isnan(nan) != 0); | ||
res_access[i++] = !(std::isnan(infinity) == 0); | ||
res_access[i++] = !(std::isnan(minus_infinity) == 0); | ||
#ifdef _WIN32 | ||
res_access[i++] = !(std::isnormal(nan) == 0); | ||
res_access[i++] = !(std::isnormal(minus_infinity) == 0); | ||
res_access[i++] = !(std::isnormal(subnormal) == 0); | ||
res_access[i++] = !(std::isnormal(1.0f) != 0); | ||
#else // !_WIN32 | ||
// __builtin_isnormal() is unsupported. | ||
res_access[i++] = 0; | ||
res_access[i++] = 0; | ||
res_access[i++] = 0; | ||
res_access[i++] = 0; | ||
#endif // !_WIN32 | ||
}); | ||
}); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I correct that we assume here that FLT_RADIX is always == 2?
Should we make a comment about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we assume it is 2. Do you suggest mentioning this in the documentation for
devicelib
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if it worth mentioning and how obvious is this that it is 100% equal to 2. If you think that it is obvious I am ok to leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to GCC documentation, it is 2 on the majority of the machines, so I would say it is quite expected to be equal to 2. At the same time, I was not able to find any documentation regarding floating point representation for
SPIR-V
devices.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thx.