-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL] Add support for union types as kernel parameter #2285
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
27 commits
Select commit
Hold shift + click to select a range
7be969a
[SYCL] Add support for union
smanna12 6de6dff
add tests
smanna12 60f02ac
Fix Clang-format issue
smanna12 fc3999b
Fix Clang-format issue
smanna12 e71672c
Fix Clang-format issue
smanna12 c36ab3f
Merge remote-tracking branch 'intel_llvm/sycl' into UnionKernelArgument
smanna12 99e8b2a
update tests and code changes
smanna12 2e7b74b
Fix Clang format issue
smanna12 3e4d4fc
Fix Clang format issue
smanna12 d3a5172
Fix test
smanna12 7802eda
Update tests and patch based on review comments
smanna12 2ed64f3
Fix Clang-format issue
smanna12 e9c65c0
Fix runtime test failure and add new integration header test
smanna12 1376cad
Add diagnostic tests
smanna12 bc09151
Fix clang format issue
smanna12 5931e4a
Address review commensts
smanna12 fabd978
Address review comment and fix clang-format issues
smanna12 0e15676
Fix runtime test
smanna12 ede7a0b
Fix typo on runtime test
smanna12 7338c0d
Fix runtime test
smanna12 6a80b99
Fix runtime test
smanna12 fdfbe19
Add empty base case for windows failure
smanna12 03460a1
Fix sema codes
smanna12 f4450a6
Fix clang-format issue
smanna12 f772189
Fix clang-format issue and update source codes
smanna12 db9f49d
Fix clang-format issues
smanna12 347b21c
update test based on reiew
smanna12 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,53 @@ | ||
// RUN: %clang_cc1 -I %S/Inputs -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice -fsycl-int-header=%t.h %s -o %t.out | ||
// RUN: FileCheck -input-file=%t.h %s | ||
|
||
// This test checks the integration header generated when | ||
// the kernel argument is union. | ||
|
||
// CHECK: #include <CL/sycl/detail/kernel_desc.hpp> | ||
|
||
// CHECK: class kernel_A; | ||
|
||
// CHECK: __SYCL_INLINE_NAMESPACE(cl) { | ||
// CHECK-NEXT: namespace sycl { | ||
// CHECK-NEXT: namespace detail { | ||
|
||
// CHECK: static constexpr | ||
// CHECK-NEXT: const char* const kernel_names[] = { | ||
// CHECK-NEXT: "_ZTSZ4mainE8kernel_A" | ||
// CHECK-NEXT: }; | ||
|
||
// CHECK: static constexpr | ||
// CHECK-NEXT: const kernel_param_desc_t kernel_signatures[] = { | ||
// CHECK-NEXT: //--- _ZTSZ4mainE8kernel_A | ||
// CHECK-NEXT: { kernel_param_kind_t::kind_std_layout, 12, 0 }, | ||
bader marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// CHECK-EMPTY: | ||
// CHECK-NEXT:}; | ||
|
||
// CHECK: static constexpr | ||
// CHECK-NEXT: const unsigned kernel_signature_start[] = { | ||
// CHECK-NEXT: 0 // _ZTSZ4mainE8kernel_A | ||
// CHECK-NEXT: }; | ||
|
||
// CHECK: template <> struct KernelInfo<class kernel_A> { | ||
|
||
union MyUnion { | ||
int FldInt; | ||
char FldChar; | ||
float FldArr[3]; | ||
}; | ||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void a_kernel(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
|
||
int main() { | ||
|
||
MyUnion obj; | ||
|
||
a_kernel<class kernel_A>( | ||
[=]() { | ||
float local = obj.FldArr[2]; | ||
}); | ||
} |
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,41 @@ | ||
// RUN: %clang_cc1 -fsycl -fsycl-is-device -I %S/Inputs -triple spir64-unknown-unknown-sycldevice -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s | ||
|
||
// This test checks a kernel argument that is union with both array and non-array fields. | ||
|
||
#include "sycl.hpp" | ||
|
||
using namespace cl::sycl; | ||
|
||
union MyUnion { | ||
int FldInt; | ||
char FldChar; | ||
float FldArr[3]; | ||
}; | ||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void a_kernel(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
|
||
int main() { | ||
|
||
MyUnion obj; | ||
|
||
a_kernel<class kernel_A>( | ||
[=]() { | ||
float local = obj.FldArr[2]; | ||
}); | ||
} | ||
|
||
// CHECK kernel_A parameters | ||
// CHECK: define spir_kernel void @{{.*}}kernel_A(%union.{{.*}}.MyUnion* byval(%union.{{.*}}.MyUnion) align 4 [[MEM_ARG:%[a-zA-Z0-9_]+]]) | ||
|
||
// Check lambda object alloca | ||
// CHECK: [[LOCAL_OBJECT:%0]] = alloca %"class.{{.*}}.anon", align 4 | ||
|
||
// CHECK: [[L_STRUCT_ADDR:%[a-zA-Z0-9_]+]] = getelementptr inbounds %"class.{{.*}}.anon", %"class.{{.*}}.anon"* [[LOCAL_OBJECT]], i32 0, i32 0 | ||
// CHECK: [[MEMCPY_DST:%[0-9a-zA-Z_]+]] = bitcast %union.{{.*}}MyUnion* [[L_STRUCT_ADDR]] to i8* | ||
// CHECK: [[MEMCPY_SRC:%[0-9a-zA-Z_]+]] = bitcast %union.{{.*}}MyUnion* [[MEM_ARG]] to i8* | ||
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 [[MEMCPY_DST]], i8* align 4 [[MEMCPY_SRC]], i64 12, i1 false) | ||
// CHECK: [[ACC_CAST1:%[0-9]+]] = addrspacecast %"class.{{.*}}.anon"* [[LOCAL_OBJECT]] to %"class.{{.*}}.anon" addrspace(4)* | ||
// CHECK: call spir_func void @{{.*}}(%"class.{{.*}}.anon" addrspace(4)* [[ACC_CAST1]]) |
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,42 @@ | ||
//RUN: %clang_cc1 -I %S/Inputs -fsycl -fsycl-is-device -verify -fsyntax-only %s | ||
|
||
// This test checks if compiler reports compilation error on an attempt to pass | ||
// accessor/sampler as SYCL kernel parameter inside union. | ||
|
||
#include "sycl.hpp" | ||
using namespace cl::sycl; | ||
|
||
union union_with_sampler { | ||
cl::sycl::sampler smpl; | ||
// expected-error@-1 {{'cl::sycl::sampler' cannot be used inside a union kernel parameter}} | ||
}; | ||
|
||
template <typename name, typename Func> | ||
__attribute__((sycl_kernel)) void a_kernel(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
|
||
int main() { | ||
|
||
using Accessor = | ||
accessor<int, 1, access::mode::read_write, access::target::global_buffer>; | ||
|
||
union union_with_accessor { | ||
Accessor member_acc[1]; | ||
// expected-error@-1 {{'Accessor' (aka 'accessor<int, 1, access::mode::read_write, access::target::global_buffer>') cannot be used inside a union kernel parameter}} | ||
} union_acc; | ||
|
||
union_with_sampler Sampler; | ||
|
||
a_kernel<class kernel_A>( | ||
[=]() { | ||
Sampler.smpl.use(); | ||
}); | ||
|
||
a_kernel<class kernel_B>( | ||
[=]() { | ||
union_acc.member_acc[1].use(); | ||
}); | ||
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.