This repository was archived by the owner on Mar 28, 2023. It is now read-only.
forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 130
[SYCL][CUDA] Test cases for bfloat16 math/elem wise joint_matrix #975
Merged
Merged
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fc9b2d7
New test cases, bfloat16 builtins/matrix.
JackAKirk e8acad9
format
JackAKirk caed520
format
JackAKirk b178c43
format
JackAKirk ca24153
format
JackAKirk 4013bd0
Do compute capability check at runtime.
JackAKirk e4e7f20
format
JackAKirk 5c5d65c
tests for bfloat16 marray math fcts
JackAKirk 6856b89
format
JackAKirk 4e1d6e4
test case for expected NAN behaviour.
JackAKirk c133f17
Merge branch 'intel:intel' into bfloat16-class-tests
JackAKirk 095f775
Added tests for elem wise ops.
JackAKirk 5347f7e
format
JackAKirk a249c7e
format
JackAKirk b9ebfe9
Use implicit cast to float.
JackAKirk 5ea081a
Adds separate test comparing wi_marray with get_wi_data usage.
JackAKirk 0ede881
format
JackAKirk 32eac9a
Merge branch 'intel' into bfloat16-class-tests
JackAKirk 473f88b
format
JackAKirk e817dba
format
JackAKirk 2211aac
Merge branch 'intel' into bfloat16-class-tests
JackAKirk 1019a8d
Use ext_oneapi_bfloat16 aspect where appropriate.
JackAKirk 3506d29
removed requires cuda (rely on bfloat16 aspect instead)
JackAKirk 7478793
Noted test doesn't compile for other backends.
JackAKirk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// REQUIRES: cuda | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out -Xsycl-target-backend --cuda-gpu-arch=sm_80 | ||
// TODO: Currently the CI does not have a sm_80 capable machine. Enable the test | ||
// execution once it does. | ||
// RUNx: %t.out | ||
|
||
#include <CL/sycl.hpp> | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
#include <cmath> | ||
#include <vector> | ||
|
||
using namespace cl::sycl; | ||
using sycl::ext::oneapi::experimental::bfloat16; | ||
|
||
constexpr int N = 16 * 3; // divisible by all vector sizes | ||
constexpr float bf16_eps = 0.00390625; | ||
|
||
union conv { | ||
float f; | ||
vec<uint16_t, 2> u; | ||
uint32_t u2; | ||
}; | ||
|
||
float from_bf16(uint16_t x) { | ||
conv c; | ||
c.u.y() = x; | ||
c.u.x() = 0; | ||
return c.f; | ||
} | ||
|
||
bool check(float a, float b) { | ||
return fabs(2 * (a - b) / (a + b)) > bf16_eps * 2; | ||
} | ||
|
||
#define TEST_BUILTIN_1_SCAL_IMPL(NAME) \ | ||
{ \ | ||
buffer<float> a_buf(&a[0], N); \ | ||
buffer<int> err_buf(&err, 1); \ | ||
q.submit([&](handler &cgh) { \ | ||
auto A = a_buf.get_access<access::mode::read_write>(cgh); \ | ||
auto ERR = err_buf.get_access<access::mode::write>(cgh); \ | ||
cgh.parallel_for(N, [=](id<1> index) { \ | ||
if (check(from_bf16(NAME(bfloat16{A[index]}).raw()), \ | ||
NAME(A[index]))) { \ | ||
ERR[0] = 1; \ | ||
} \ | ||
}); \ | ||
}); \ | ||
} \ | ||
assert(err == 0); | ||
|
||
#define TEST_BUILTIN_1(NAME) TEST_BUILTIN_1_SCAL_IMPL(NAME) | ||
|
||
#define TEST_BUILTIN_2_SCAL_IMPL(NAME) \ | ||
{ \ | ||
buffer<float> a_buf(&a[0], N); \ | ||
buffer<float> b_buf(&b[0], N); \ | ||
buffer<int> err_buf(&err, 1); \ | ||
q.submit([&](handler &cgh) { \ | ||
auto A = a_buf.get_access<access::mode::read>(cgh); \ | ||
auto B = b_buf.get_access<access::mode::read>(cgh); \ | ||
auto ERR = err_buf.get_access<access::mode::write>(cgh); \ | ||
cgh.parallel_for(N, [=](id<1> index) { \ | ||
if (check( \ | ||
from_bf16(NAME(bfloat16{A[index]}, bfloat16{B[index]}).raw()), \ | ||
NAME(A[index], B[index]))) { \ | ||
ERR[0] = 1; \ | ||
} \ | ||
}); \ | ||
}); \ | ||
} \ | ||
assert(err == 0); | ||
|
||
#define TEST_BUILTIN_2(NAME) TEST_BUILTIN_2_SCAL_IMPL(NAME) | ||
|
||
#define TEST_BUILTIN_3_SCAL_IMPL(NAME) \ | ||
{ \ | ||
buffer<float> a_buf(&a[0], N); \ | ||
buffer<float> b_buf(&b[0], N); \ | ||
buffer<float> c_buf(&c[0], N); \ | ||
buffer<int> err_buf(&err, 1); \ | ||
q.submit([&](handler &cgh) { \ | ||
auto A = a_buf.get_access<access::mode::read>(cgh); \ | ||
auto B = b_buf.get_access<access::mode::read>(cgh); \ | ||
auto C = c_buf.get_access<access::mode::read>(cgh); \ | ||
auto ERR = err_buf.get_access<access::mode::write>(cgh); \ | ||
cgh.parallel_for(N, [=](id<1> index) { \ | ||
if (check(from_bf16(NAME(bfloat16{A[index]}, bfloat16{B[index]}, \ | ||
bfloat16{C[index]}) \ | ||
.raw()), \ | ||
NAME(A[index], B[index], C[index]))) { \ | ||
ERR[0] = 1; \ | ||
} \ | ||
}); \ | ||
}); \ | ||
} \ | ||
assert(err == 0); | ||
|
||
#define TEST_BUILTIN_3(NAME) TEST_BUILTIN_3_SCAL_IMPL(NAME) | ||
|
||
int main() { | ||
queue q; | ||
std::vector<float> a(N), b(N), c(N); | ||
int err = 0; | ||
|
||
for (int i = 0; i < N; i++) { | ||
a[i] = (i - N / 2) / (float)N; | ||
b[i] = (N / 2 - i) / (float)N; | ||
c[i] = (float)(3 * i); | ||
} | ||
|
||
TEST_BUILTIN_1(fabs); | ||
TEST_BUILTIN_2(fmin); | ||
TEST_BUILTIN_2(fmax); | ||
TEST_BUILTIN_3(fma); | ||
|
||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.