-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL] Add marray support to rest math built-in functions #8912
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
Merged
dm-vodopyanov
merged 13 commits into
intel:sycl
from
dm-vodopyanov:marray_for_rest_math_funcs
Apr 6, 2023
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e7f7929
[SYCL] Add marray support to rest math built-in functions
dm-vodopyanov 100a872
Apply CR comment, fixed other bugs
dm-vodopyanov 59fb71a
Debugging test failures
dm-vodopyanov 8bac796
Debugging test failures
dm-vodopyanov f8c049d
Debugging test failures
dm-vodopyanov 9fdbb6e
Merge branch 'intel:sycl' into marray_for_rest_math_funcs
dm-vodopyanov d745d4b
Debugging test failures
dm-vodopyanov ae65305
Debugging test failures
dm-vodopyanov a084a79
Merge branch 'intel:sycl' into marray_for_rest_math_funcs
dm-vodopyanov f58d684
Fix marray math builtins API test
dm-vodopyanov 6acfc04
Update marray_math.cpp
dm-vodopyanov 052e0cc
Fix marray_math.cpp
dm-vodopyanov 2814d7e
Update marray_math.cpp
dm-vodopyanov 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
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
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,122 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
#ifdef _WIN32 | ||
#define _USE_MATH_DEFINES // To use math constants | ||
#include <cmath> | ||
#endif | ||
|
||
#include <sycl/sycl.hpp> | ||
|
||
#define TEST(FUNC, MARRAY_ELEM_TYPE, DIM, EXPECTED, DELTA, ...) \ | ||
{ \ | ||
{ \ | ||
MARRAY_ELEM_TYPE result[DIM]; \ | ||
{ \ | ||
sycl::buffer<MARRAY_ELEM_TYPE> b(result, sycl::range{DIM}); \ | ||
deviceQueue.submit([&](sycl::handler &cgh) { \ | ||
sycl::accessor res_access{b, cgh}; \ | ||
cgh.single_task([=]() { \ | ||
sycl::marray<MARRAY_ELEM_TYPE, DIM> res = FUNC(__VA_ARGS__); \ | ||
for (int i = 0; i < DIM; i++) \ | ||
res_access[i] = res[i]; \ | ||
}); \ | ||
}); \ | ||
} \ | ||
for (int i = 0; i < DIM; i++) \ | ||
assert(abs(result[i] - EXPECTED[i]) <= DELTA); \ | ||
} \ | ||
} | ||
|
||
#define EXPECTED(TYPE, ...) ((TYPE[]){__VA_ARGS__}) | ||
|
||
int main() { | ||
sycl::queue deviceQueue; | ||
sycl::device dev = deviceQueue.get_device(); | ||
|
||
sycl::marray<float, 2> ma1{1.0f, 2.0f}; | ||
sycl::marray<float, 2> ma2{1.0f, 2.0f}; | ||
sycl::marray<float, 2> ma3{3.0f, 2.0f}; | ||
sycl::marray<double, 2> ma4{1.0, 2.0}; | ||
sycl::marray<float, 3> ma5{M_PI, M_PI, M_PI}; | ||
sycl::marray<double, 3> ma6{M_PI, M_PI, M_PI}; | ||
sycl::marray<sycl::half, 3> ma7{M_PI, M_PI, M_PI}; | ||
sycl::marray<float, 2> ma8{0.3f, 0.6f}; | ||
sycl::marray<double, 2> ma9{5.0, 8.0}; | ||
sycl::marray<float, 3> ma10{180, 180, 180}; | ||
sycl::marray<double, 3> ma11{180, 180, 180}; | ||
sycl::marray<sycl::half, 3> ma12{180, 180, 180}; | ||
sycl::marray<sycl::half, 3> ma13{181, 179, 181}; | ||
sycl::marray<float, 2> ma14{+0.0f, -0.6f}; | ||
sycl::marray<double, 2> ma15{-0.0, 0.6f}; | ||
|
||
// sycl::clamp | ||
TEST(sycl::clamp, float, 2, EXPECTED(float, 1.0f, 2.0f), 0, ma1, ma2, ma3); | ||
TEST(sycl::clamp, float, 2, EXPECTED(float, 1.0f, 2.0f), 0, ma1, 1.0f, 3.0f); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::clamp, double, 2, EXPECTED(double, 1.0, 2.0), 0, ma4, 1.0, 3.0); | ||
// sycl::degrees | ||
TEST(sycl::degrees, float, 3, EXPECTED(float, 180, 180, 180), 0, ma5); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::degrees, double, 3, EXPECTED(double, 180, 180, 180), 0, ma6); | ||
if (dev.has(sycl::aspect::fp16)) | ||
TEST(sycl::degrees, sycl::half, 3, EXPECTED(sycl::half, 180, 180, 180), 0.2, | ||
ma7); | ||
// sycl::max | ||
TEST(sycl::max, float, 2, EXPECTED(float, 3.0f, 2.0f), 0, ma1, ma3); | ||
TEST(sycl::max, float, 2, EXPECTED(float, 1.5f, 2.0f), 0, ma1, 1.5f); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::max, double, 2, EXPECTED(double, 1.5, 2.0), 0, ma4, 1.5); | ||
// sycl::min | ||
TEST(sycl::min, float, 2, EXPECTED(float, 1.0f, 2.0f), 0, ma1, ma3); | ||
TEST(sycl::min, float, 2, EXPECTED(float, 1.0f, 1.5f), 0, ma1, 1.5f); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::min, double, 2, EXPECTED(double, 1.0, 1.5), 0, ma4, 1.5); | ||
// sycl::mix | ||
TEST(sycl::mix, float, 2, EXPECTED(float, 1.6f, 2.0f), 0, ma1, ma3, ma8); | ||
TEST(sycl::mix, float, 2, EXPECTED(float, 1.4f, 2.0f), 0, ma1, ma3, 0.2); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::mix, double, 2, EXPECTED(double, 3.0, 5.0), 0, ma4, ma9, 0.5); | ||
// sycl::radians | ||
TEST(sycl::radians, float, 3, EXPECTED(float, M_PI, M_PI, M_PI), 0, ma10); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::radians, double, 3, EXPECTED(double, M_PI, M_PI, M_PI), 0, ma11); | ||
if (dev.has(sycl::aspect::fp16)) | ||
TEST(sycl::radians, sycl::half, 3, EXPECTED(sycl::half, M_PI, M_PI, M_PI), | ||
0.002, ma12); | ||
// sycl::step | ||
TEST(sycl::step, float, 2, EXPECTED(float, 1.0f, 1.0f), 0, ma1, ma3); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::step, double, 2, EXPECTED(double, 1.0, 1.0), 0, ma4, ma9); | ||
if (dev.has(sycl::aspect::fp16)) | ||
TEST(sycl::step, sycl::half, 3, EXPECTED(sycl::half, 1.0, 0.0, 1.0), 0, | ||
ma12, ma13); | ||
TEST(sycl::step, float, 2, EXPECTED(float, 1.0f, 0.0f), 0, 2.5f, ma3); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::step, double, 2, EXPECTED(double, 0.0f, 1.0f), 0, 6.0f, ma9); | ||
// sycl::smoothstep | ||
TEST(sycl::smoothstep, float, 2, EXPECTED(float, 1.0f, 1.0f), 0, ma8, ma1, | ||
ma2); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::smoothstep, double, 2, EXPECTED(double, 1.0, 1.0f), 0.00000001, | ||
ma4, ma9, ma9); | ||
if (dev.has(sycl::aspect::fp16)) | ||
TEST(sycl::smoothstep, sycl::half, 3, EXPECTED(sycl::half, 1.0, 1.0, 1.0), | ||
0, ma7, ma12, ma13); | ||
TEST(sycl::smoothstep, float, 2, EXPECTED(float, 0.0553936f, 0.0f), 0.0000001, | ||
2.5f, 6.0f, ma3); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::smoothstep, double, 2, EXPECTED(double, 0.0f, 1.0f), 0, 6.0f, | ||
8.0f, ma9); | ||
// sign | ||
TEST(sycl::sign, float, 2, EXPECTED(float, +0.0f, -1.0f), 0, ma14); | ||
if (dev.has(sycl::aspect::fp64)) | ||
TEST(sycl::sign, double, 2, EXPECTED(double, -0.0, 1.0), 0, ma15); | ||
if (dev.has(sycl::aspect::fp16)) | ||
TEST(sycl::sign, sycl::half, 3, EXPECTED(sycl::half, 1.0, 1.0, 1.0), 0, | ||
ma12); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.
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.
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.
Do we have to use a macro here? Seems like we can get away with a function template, which would be preferrable. The same goes for the other test file.
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 would suggest to implement this in a separate PR for all marray builtin tests, including these.