-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL] Implement restrict kernel argument property #16090
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
steffenlarsen
merged 3 commits into
intel:sycl
from
steffenlarsen:steffen/restrict_args
Dec 10, 2024
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| // RUN: %clang_cc1 -fsycl-is-device %s -emit-llvm -triple spir64-unknown-unknown -o - | FileCheck %s | ||
|
|
||
| struct __attribute__((sycl_special_class)) | ||
| [[__sycl_detail__::sycl_type(annotated_arg)]] | ||
| AnnotatedIntPtr { | ||
| void __init([[__sycl_detail__::add_ir_attributes_kernel_parameter( | ||
| "sycl-restrict", nullptr)]] | ||
| __attribute__((opencl_global)) int* InPtr) { | ||
| Ptr = InPtr; | ||
| } | ||
|
|
||
| int &operator[](unsigned I) const { return Ptr[I]; } | ||
|
|
||
| __attribute__((opencl_global)) int *Ptr; | ||
| }; | ||
|
|
||
| template <typename name, typename Func> | ||
| __attribute__((sycl_kernel)) void kernel(const Func &kernelFunc) { | ||
| kernelFunc(); | ||
| } | ||
|
|
||
| int main() { | ||
| { | ||
| int *a; | ||
| int *b; | ||
| int *c; | ||
| kernel<class kernel_norestrict>([a, b, c]() { c[0] = a[0] + b[0]; }); | ||
| // CHECK-DAG: define {{.*}}spir_kernel {{.*}}kernel_norestrict(ptr addrspace(1) noundef align 4 %{{.*}}, ptr addrspace(1) noundef align 4 %{{.*}}, ptr addrspace(1) noundef align 4 %{{.*}}) | ||
| } | ||
| { | ||
| AnnotatedIntPtr a; | ||
| int *b; | ||
| int *c; | ||
| kernel<class kernel_restrict1>([a, b, c]() { c[0] = a[0] + b[0]; }); | ||
| // CHECK-DAG: define {{.*}}spir_kernel {{.*}}kernel_restrict1(ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}, ptr addrspace(1) noundef align 4 %{{.*}}, ptr addrspace(1) noundef align 4 %{{.*}}) | ||
| } | ||
| { | ||
| int *a; | ||
| AnnotatedIntPtr b; | ||
| int *c; | ||
| kernel<class kernel_restrict2>([a, b, c]() { c[0] = a[0] + b[0]; }); | ||
| // CHECK-DAG: define {{.*}}spir_kernel {{.*}}kernel_restrict2(ptr addrspace(1) noundef align 4 %{{.*}}, ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}, ptr addrspace(1) noundef align 4 %{{.*}}) | ||
| } | ||
| { | ||
| int *a; | ||
| int *b; | ||
| AnnotatedIntPtr c; | ||
| kernel<class kernel_restrict3>([a, b, c]() { c[0] = a[0] + b[0]; }); | ||
| // CHECK-DAG: define {{.*}}spir_kernel {{.*}}kernel_restrict3(ptr addrspace(1) noundef align 4 %{{.*}}, ptr addrspace(1) noundef align 4 %{{.*}}, ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}) | ||
| } | ||
| { | ||
| AnnotatedIntPtr a; | ||
| AnnotatedIntPtr b; | ||
| int *c; | ||
| kernel<class kernel_restrict4>([a, b, c]() { c[0] = a[0] + b[0]; }); | ||
| // CHECK-DAG: define {{.*}}spir_kernel {{.*}}kernel_restrict4(ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}, ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}, ptr addrspace(1) noundef align 4 %{{.*}}) | ||
| } | ||
| { | ||
| AnnotatedIntPtr a; | ||
| int *b; | ||
| AnnotatedIntPtr c; | ||
| kernel<class kernel_restrict5>([a, b, c]() { c[0] = a[0] + b[0]; }); | ||
| // CHECK-DAG: define {{.*}}spir_kernel {{.*}}kernel_restrict5(ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}, ptr addrspace(1) noundef align 4 %{{.*}}, ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}) | ||
| } | ||
| { | ||
| int *a; | ||
| AnnotatedIntPtr b; | ||
| AnnotatedIntPtr c; | ||
| kernel<class kernel_restrict6>([a, b, c]() { c[0] = a[0] + b[0]; }); | ||
| // CHECK-DAG: define {{.*}}spir_kernel {{.*}}kernel_restrict6(ptr addrspace(1) noundef align 4 %{{.*}}, ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}, ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}) | ||
| } | ||
| { | ||
| AnnotatedIntPtr a; | ||
| AnnotatedIntPtr b; | ||
| AnnotatedIntPtr c; | ||
| kernel<class kernel_restrict7>([a, b, c]() { c[0] = a[0] + b[0]; }); | ||
| // CHECK-DAG: define {{.*}}spir_kernel {{.*}}kernel_restrict7(ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}, ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}, ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %{{.*}}) | ||
| } | ||
| } |
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
27 changes: 27 additions & 0 deletions
27
sycl/test-e2e/Annotated_arg_ptr/annotated_arg_restrict.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,27 @@ | ||
| // RUN: %{build} -o %t.out | ||
| // RUN: %{run} %t.out | ||
| // REQUIRES: aspect-usm_shared_allocations | ||
|
|
||
| // Checks that restrict annotated_arg works in device code. | ||
|
|
||
| #include <sycl/detail/core.hpp> | ||
| #include <sycl/ext/oneapi/experimental/annotated_arg/annotated_arg.hpp> | ||
| #include <sycl/usm.hpp> | ||
|
|
||
| namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
|
|
||
| int *Ptr = sycl::malloc_shared<int>(1, Q); | ||
| syclexp::annotated_arg<int *, | ||
| decltype(syclexp::properties(syclexp::restrict))> | ||
| AnnotArg{Ptr}; | ||
| Q.submit([&](sycl::handler &CGH) { | ||
| CGH.single_task([=]() { *AnnotArg = 42; }); | ||
| }).wait(); | ||
| assert(*Ptr == 42); | ||
| free(Ptr, Q); | ||
|
|
||
| return 0; | ||
| } |
28 changes: 28 additions & 0 deletions
28
sycl/test-e2e/Annotated_arg_ptr/annotated_ptr_restrict.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,28 @@ | ||
| // RUN: %{build} -o %t.out | ||
| // RUN: %{run} %t.out | ||
| // REQUIRES: aspect-usm_shared_allocations | ||
|
|
||
| // Checks that restrict annotated_ptr works in device code. | ||
|
|
||
| #include <sycl/detail/core.hpp> | ||
| #include <sycl/ext/oneapi/experimental/annotated_ptr/annotated_ptr.hpp> | ||
| #include <sycl/usm.hpp> | ||
|
|
||
| namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
|
|
||
| auto Ptr = sycl::malloc_shared<int>(1, Q); | ||
| syclexp::annotated_ptr<int, decltype(syclexp::properties(syclexp::restrict))> | ||
| AnnotPtr{Ptr}; | ||
| Q.submit([&](sycl::handler &CGH) { | ||
| CGH.single_task([=]() { *AnnotPtr = 42; }); | ||
| }).wait(); | ||
| assert(*Ptr == 42); | ||
| free(Ptr, Q); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| // CHECK-IR: spir_kernel void @_ZTSZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_EUlvE_(ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %_arg_AnnotPtr) |
22 changes: 22 additions & 0 deletions
22
sycl/test/check_device_code/extensions/annotated_arg/restrict.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,22 @@ | ||
| // RUN: %clangxx -fsycl-device-only -S -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK-IR | ||
|
|
||
| #include "sycl/sycl.hpp" | ||
|
|
||
| namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
|
|
||
| auto Ptr = sycl::malloc_shared<int>(1, Q); | ||
| syclexp::annotated_arg<int *, | ||
| decltype(syclexp::properties(syclexp::restrict))> | ||
| AnnotArg{Ptr}; | ||
| Q.submit([&](sycl::handler &CGH) { | ||
| CGH.single_task([=]() { *AnnotArg = 42; }); | ||
| }).wait(); | ||
| free(Ptr, Q); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| // CHECK-IR: spir_kernel void @_ZTSZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_EUlvE_(ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %_arg_AnnotArg) |
21 changes: 21 additions & 0 deletions
21
sycl/test/check_device_code/extensions/annotated_ptr/restrict.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,21 @@ | ||
| // RUN: %clangxx -fsycl-device-only -S -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK-IR | ||
|
|
||
| #include "sycl/sycl.hpp" | ||
|
|
||
| namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
|
||
| int main() { | ||
| sycl::queue Q; | ||
|
|
||
| auto Ptr = sycl::malloc_shared<int>(1, Q); | ||
| syclexp::annotated_ptr<int, decltype(syclexp::properties(syclexp::restrict))> | ||
| AnnotPtr{Ptr}; | ||
| Q.submit([&](sycl::handler &CGH) { | ||
| CGH.single_task([=]() { *AnnotPtr = 42; }); | ||
| }).wait(); | ||
| free(Ptr, Q); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| // CHECK-IR: spir_kernel void @_ZTSZZ4mainENKUlRN4sycl3_V17handlerEE_clES2_EUlvE_(ptr addrspace(1) noalias noundef align 4 "sycl-restrict" %_arg_AnnotPtr) |
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.
Uh oh!
There was an error while loading. Please reload this page.