Repository navigation
[SYCL] Consistent is_device_copyable for sycl::accessor #23250
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
base: sycl
Are you sure you want to change the base?
Changes from all commits
54550f9
4771df0
4bc0a59
74cbd87
3b87544
7478b51
8d933d1
faecfa9
37e133a
82c5e91
47f7932
e966767
f011bd9
7b15c7c
0adb720
f5b64c5
9da10c4
6c63dd6
0bcf79c
9ab98ad
a70516d
1ad3ee2
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| #include "CGHLSLRuntime.h" | ||
| #include "CGObjCRuntime.h" | ||
| #include "CGOpenMPRuntime.h" | ||
| #include "CGSYCLRuntime.h" | ||
| #include "CodeGenFunction.h" | ||
| #include "TargetInfo.h" | ||
| #include "clang/AST/Attr.h" | ||
|
|
@@ -73,6 +74,17 @@ static void EmitDeclInit(CodeGenFunction &CGF, const VarDecl &D, | |
| /// static storage duration. | ||
| static void EmitDeclDestroy(CodeGenFunction &CGF, const VarDecl &D, | ||
| ConstantAddress Addr) { | ||
| // SYCL work-group scope variables (e.g. the kernel object of a | ||
| // parallel_for_work_group kernel) are local variables promoted to | ||
| // work-group local memory. There is no program exit on the device to run | ||
| // their destructor at, and SYCL 2020 requires the destructors of device | ||
| // copyable types to have no effect on the device, so don't register one. | ||
| if (CGF.getLangOpts().SYCLIsDevice) { | ||
| if (CGSYCLRuntime::getWorkGroupVarKind(D) != | ||
| CGSYCLRuntime::WorkGroupVarKind::None) | ||
| return; | ||
| } | ||
|
|
||
|
Contributor
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. Remove this. |
||
| // Honor __attribute__((no_destroy)) and bail instead of attempting | ||
| // to emit a reference to a possibly nonexistent destructor, which | ||
| // in turn can cause a crash. This will result in a global constructor | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -244,3 +244,28 @@ void ff_8(sycl::ext::oneapi::experimental::annotated_ptr<int> ptr) { | |
| // CHECK-NEXT: store ptr addrspace(4) %__arg__obj, ptr addrspace(4) %__arg__obj.addr.ascast, align 8 | ||
| // CHECK-NEXT: %0 = load ptr addrspace(4), ptr addrspace(4) %__arg__obj.addr.ascast, align 8 | ||
| // CHECK-NEXT: call spir_func void @{{.*}}annotated_ptr{{.*}}__init{{.*}} | ||
|
|
||
| // Special type with a non-trivial destructor, like the device accessors. The | ||
|
Contributor
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. Nit: Comment says "the device accessors". Test is for |
||
| // destructor of the object created in the kernel to pass to the free function | ||
| // must be instantiated and defined, not just declared. | ||
| template <typename DataT> | ||
|
Contributor
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. I'm not sure if we should update the mock headers to include the destructor under some macro for now? @tahonermann can you weigh in? |
||
| class __attribute__((sycl_special_class)) | ||
| __SYCL_TYPE(work_group_memory) SpecialWithDtor { | ||
| public: | ||
| SpecialWithDtor() = default; | ||
| ~SpecialWithDtor() {} | ||
| void __init(__attribute((opencl_local)) DataT *Ptr) { this->Ptr = Ptr; } | ||
|
|
||
| private: | ||
| __attribute((opencl_local)) DataT *Ptr; | ||
| }; | ||
|
|
||
| __attribute__((sycl_device)) | ||
| [[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 0)]] | ||
| void ff_9(SpecialWithDtor<int> S) { | ||
| } | ||
|
|
||
| // CHECK: define dso_local spir_kernel void @{{.*}}__sycl_kernel_ff_9{{.*}}(ptr addrspace(3) noundef align 4 %__arg_Ptr) | ||
| // CHECK: call spir_func void @{{.*}}SpecialWithDtor{{.*}}__init{{.*}}(ptr addrspace(4) {{.*}} %S.ascast, ptr addrspace(3) noundef %{{.*}}) | ||
| // CHECK: call spir_func void @[[DTOR:_ZN15SpecialWithDtorIiED1Ev]](ptr addrspace(4) {{.*}} %S.ascast) | ||
| // CHECK: define linkonce_odr spir_func void @[[DTOR]]( | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -Wno-sycl-work-group-dtor -emit-llvm %s -o - | FileCheck %s | ||
|
Contributor
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. I see you passed |
||
|
|
||
| // This test checks that the kernel object of a parallel_for_work_group kernel, | ||
| // which is promoted to a work group local variable in addrspace(3), does not | ||
| // get its destructor registered with __cxa_atexit, even if a captured variable | ||
| // has a non-trivial destructor. | ||
|
|
||
| #include "Inputs/sycl.hpp" | ||
|
|
||
| using namespace sycl; | ||
|
|
||
| struct NonTrivial { | ||
| int I; | ||
| ~NonTrivial() {} | ||
| }; | ||
|
|
||
| int main() { | ||
| queue q; | ||
| q.submit([&](handler &h) { | ||
| NonTrivial Captured; | ||
| h.parallel_for_work_group<class kernel>( | ||
| range<1>{1}, range<1>{1}, [=](group<1> G) { (void)Captured; }); | ||
|
Contributor
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. Could you also add a local declared inside the |
||
| }); | ||
| return 0; | ||
| } | ||
|
|
||
| // CHECK: @{{.*}}__SYCLKernel = internal addrspace(3) global %class.anon undef | ||
| // CHECK-NOT: __cxa_atexit | ||
| // CHECK-NOT: @__dso_handle | ||
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.
The comment does not fully cover the actual code changes. All locals are affected IIUC. The SYCL 2020 rule refers to only kernel captures but this change affects a variable declared in the kernel bocy as well right?.
In any case is this code even hit after after #23702 ?
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 believe you are correct that the changes to this file can be reverted once #23702 is in. But I'm not sure whether #23702 should go in until #23700 is fixed. So I'm not entirely sure how to proceed here.
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 think you can just update the comment to describe the status as well. Maybe add a FIXME so we can keep track of its removal.