-
Notifications
You must be signed in to change notification settings - Fork 801
[SYCL] Implement free function kernel enqueue functions #20698
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
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b5ac52a
Implement free function kernel enqueue functions
lbushi25 63d860c
Remove unused code
lbushi25 00e0f0d
Improve comments
lbushi25 cd92d0c
Fix LIT command typo
lbushi25 4621ff6
Fix compilation error
lbushi25 76e0f8b
Fix unused argument error
lbushi25 ce2a16b
Fix unit-tests failures
lbushi25 e88b0f9
Fix formatting
lbushi25 b1b3ce9
Add XFAIL for native CPU
lbushi25 8b685ea
Add more tests
lbushi25 4cc1d15
Add a templated kernel test
lbushi25 4e7847d
Add a test to check definition of kernel_function_s
lbushi25 51e7aff
Merge branch 'intel:sycl' into enqueue_free_functions
lbushi25 4dc3224
Update free_function_kernels_enqueue.cpp
lbushi25 0b6a0ac
Apply requested changes
lbushi25 a7c592e
Merge branch 'enqueue_free_functions' of https://github.com/lbushi25/…
lbushi25 c65ffbc
Some more refactoring
lbushi25 5b7c7de
Apply feedback
lbushi25 356b55a
Remove dead code
lbushi25 9830ba4
Remove more dead code
lbushi25 34b0b17
Add more tests
lbushi25 d42cbdc
Merge branch 'sycl' into enqueue_free_functions
lbushi25 1acde56
Address feedback
lbushi25 07d5043
Merge branch 'enqueue_free_functions' of https://github.com/lbushi25/…
lbushi25 efd5cbf
Fix formatting
lbushi25 92671f1
Update free_function_kernels_enqueue.cpp
lbushi25 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
Some comments aren't visible on the classic Files Changed page.
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
189 changes: 189 additions & 0 deletions
189
sycl/test-e2e/FreeFunctionKernels/free_function_kernels_enqueue.cpp
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,189 @@ | ||
| // REQUIRES: aspect-usm_shared_allocations | ||
| // UNSUPPORTED: target-amd | ||
| // UNSUPPORTED-TRACKER: https://github.com/intel/llvm/issues/16072 | ||
|
|
||
| // RUN: %{build} -o %t.out | ||
| // RUN: %{run} %t.out | ||
|
|
||
| // XFAIL: target-native_cpu | ||
| // XFAIL-TRACKER: https://github.com/intel/llvm/issues/20142 | ||
|
|
||
| // This test checks that free function kernels can be submitted using the | ||
| // enqueued functions defined in the free function kernel extension, namely the | ||
| // single_task and the nd_launch functions that take a queue/handler as an | ||
| // argument. These were added in https://github.com/intel/llvm/pull/19995. | ||
|
|
||
| #include <cassert> | ||
| #include <sycl/ext/oneapi/experimental/enqueue_functions.hpp> | ||
| #include <sycl/ext/oneapi/experimental/free_function_traits.hpp> | ||
| #include <sycl/ext/oneapi/free_function_queries.hpp> | ||
| #include <sycl/ext/oneapi/work_group_static.hpp> | ||
| #include <sycl/usm.hpp> | ||
|
|
||
| namespace syclext = sycl::ext::oneapi; | ||
| namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
|
||
| using accType = | ||
| sycl::accessor<int, 1, sycl::access_mode::read_write, sycl::target::device, | ||
| sycl::access::placeholder::true_t>; | ||
|
|
||
| SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::single_task_kernel)) | ||
| void empty() {} | ||
|
|
||
| SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>)) | ||
| void initialize(int *ptr) { | ||
| size_t Lid = syclext::this_work_item::get_nd_item<1>().get_local_linear_id(); | ||
| ptr[Lid] = Lid; | ||
| } | ||
|
|
||
| SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::single_task_kernel)) | ||
| void successor(int *src, int *dst) { *dst = *src + 1; } | ||
|
|
||
| SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>)) | ||
| void square(int *src, int *dst) { | ||
| size_t Lid = syclext::this_work_item::get_nd_item<1>().get_local_linear_id(); | ||
| dst[Lid] = src[Lid] * src[Lid]; | ||
| } | ||
|
|
||
| template <typename T> | ||
| SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>)) | ||
| void squareWithScratchMemoryTemplated(T *src, T *dst) { | ||
| size_t Lid = syclext::this_work_item::get_nd_item<1>().get_local_linear_id(); | ||
| T *LocalMem = reinterpret_cast<T *>(syclexp::get_work_group_scratch_memory()); | ||
| LocalMem[Lid] = src[Lid] * src[Lid]; | ||
| dst[Lid] = LocalMem[Lid]; | ||
| } | ||
|
|
||
| SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>)) | ||
| void squareWithAccessor(accType src, accType dst) { | ||
| size_t Lid = syclext::this_work_item::get_nd_item<1>().get_local_linear_id(); | ||
| dst[Lid] = src[Lid] * src[Lid]; | ||
| } | ||
|
|
||
| constexpr int SIZE = 16; | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
| int *Src = sycl::malloc_shared<int>(SIZE, Q); | ||
| int *Dst = sycl::malloc_shared<int>(SIZE, Q); | ||
|
|
||
| syclexp::single_task(Q, syclexp::kernel_function_s<empty>{}); | ||
vinser52 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| syclexp::nd_launch( | ||
| Q, ::sycl::nd_range<1>(::sycl::range<1>(SIZE), ::sycl::range<1>(SIZE)), | ||
| syclexp::kernel_function<initialize>, Src); | ||
| Q.wait(); | ||
|
|
||
| syclexp::launch_config Config{ | ||
| ::sycl::nd_range<1>(::sycl::range<1>(SIZE), ::sycl::range<1>(SIZE)), | ||
| syclexp::properties{ | ||
| syclexp::work_group_scratch_size(SIZE * sizeof(int))}}; | ||
|
|
||
| static_assert( | ||
| std::is_same_v< | ||
| decltype(syclexp::nd_launch( | ||
| Q, Config, | ||
| syclexp::kernel_function<squareWithScratchMemoryTemplated<int>>, | ||
| Src, Dst)), | ||
| void>); | ||
|
|
||
| syclexp::nd_launch( | ||
| Q, Config, | ||
| syclexp::kernel_function<squareWithScratchMemoryTemplated<int>>, Src, | ||
| Dst); | ||
| Q.wait(); | ||
|
|
||
| for (int I = 0; I < SIZE; I++) { | ||
| assert(Dst[I] == Src[I] * Src[I]); | ||
| } | ||
|
|
||
| syclexp::nd_launch( | ||
| Q, ::sycl::nd_range<1>(::sycl::range<1>(SIZE), ::sycl::range<1>(SIZE)), | ||
| syclexp::kernel_function<square>, Src, Dst); | ||
| Q.wait(); | ||
|
|
||
| for (int I = 0; I < SIZE; I++) { | ||
| assert(Dst[I] == Src[I] * Src[I]); | ||
| } | ||
|
|
||
| static_assert( | ||
| std::is_same_v<decltype(syclexp::single_task( | ||
| Q, syclexp::kernel_function<successor>, Src, Dst)), | ||
| void>); | ||
| syclexp::single_task(Q, syclexp::kernel_function<successor>, Src, Dst); | ||
| Q.wait(); | ||
| assert(Dst[0] == Src[0] + 1); | ||
|
|
||
| int SrcData[SIZE]; | ||
| int DstData[SIZE]; | ||
| for (int I = 0; I < SIZE; ++I) { | ||
| SrcData[I] = I; | ||
| } | ||
|
|
||
| { // Test with accessors | ||
| sycl::buffer<int> SrcBuf{&SrcData[0], SIZE}; | ||
| sycl::buffer<int> DstBuf{&DstData[0], SIZE}; | ||
| accType SrcAcc{SrcBuf}; | ||
| accType DstAcc{DstBuf}; | ||
|
|
||
| Q.submit([&](sycl::handler &CGH) { | ||
| CGH.require(SrcAcc); | ||
| CGH.require(DstAcc); | ||
| syclexp::nd_launch(CGH, Config, | ||
| syclexp::kernel_function<squareWithAccessor>, SrcAcc, | ||
| DstAcc); | ||
| }); | ||
| } | ||
| for (int I = 0; I < SIZE; ++I) { | ||
| assert(DstData[I] == SrcData[I] * SrcData[I]); | ||
| } | ||
|
|
||
| Q.submit([&](sycl::handler &CGH) { | ||
| static_assert( | ||
| std::is_same_v<decltype(syclexp::nd_launch( | ||
| CGH, Config, | ||
| syclexp::kernel_function< | ||
| squareWithScratchMemoryTemplated<int>>, | ||
| Src, Dst)), | ||
| void>); | ||
| syclexp::nd_launch( | ||
| CGH, Config, | ||
| syclexp::kernel_function<squareWithScratchMemoryTemplated<int>>, Src, | ||
| Dst); | ||
| }).wait(); | ||
|
|
||
| for (int I = 0; I < SIZE; I++) { | ||
| assert(Dst[I] == Src[I] * Src[I]); | ||
| } | ||
|
|
||
| Q.submit([&](sycl::handler &CGH) { | ||
| static_assert( | ||
| std::is_same_v<decltype(syclexp::nd_launch( | ||
| CGH, | ||
| ::sycl::nd_range<1>(::sycl::range<1>(SIZE), | ||
| ::sycl::range<1>(SIZE)), | ||
| syclexp::kernel_function<square>, Src, Dst)), | ||
| void>); | ||
|
|
||
| syclexp::nd_launch( | ||
| CGH, | ||
| ::sycl::nd_range<1>(::sycl::range<1>(SIZE), ::sycl::range<1>(SIZE)), | ||
| syclexp::kernel_function<square>, Src, Dst); | ||
| }).wait(); | ||
|
|
||
| for (int I = 0; I < SIZE; I++) { | ||
| assert(Dst[I] == Src[I] * Src[I]); | ||
| } | ||
|
|
||
| Q.submit([&](sycl::handler &CGH) { | ||
| static_assert(std::is_same_v<decltype(syclexp::single_task( | ||
| CGH, syclexp::kernel_function<successor>, | ||
| Src, Dst)), | ||
| void>); | ||
| syclexp::single_task(CGH, syclexp::kernel_function<successor>, Src, Dst); | ||
| }).wait(); | ||
|
|
||
| assert(Dst[0] == Src[0] + 1); | ||
|
|
||
| return 0; | ||
| } | ||
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.