-
Notifications
You must be signed in to change notification settings - Fork 790
[SYCL] Adjust kernel parameters requirements #1014
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
bader
merged 6 commits into
intel:sycl
from
Fznamznon:private/mpodchis/non-standard-layout
Jan 23, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f9f765d
[SYCL] Replace standard layout requirement with trivially copyable
Fznamznon ab9dd08
Apply code review comments
Fznamznon e002ee0
Apply comments
Fznamznon d6830e2
Apply comment
Fznamznon 18a87c5
[SYCL] Enable trivially copyable requirement by default
Fznamznon 4cb2eca
fsycl_std_layout_requirement -> fsycl_std_layout_kernel_params
Fznamznon 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
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
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,21 @@ | ||
// RUN: %clang_cc1 -I %S/Inputs -triple spir64-unknown-unknown-sycldevice -aux-triple x86_64-unknown-windows-unknown -fsycl-is-device -disable-llvm-passes -S -emit-llvm %s -o - | FileCheck --check-prefix CHK-WIN %s | ||
// RUN: %clang_cc1 -I %S/Inputs -triple spir64-unknown-unknown-sycldevice -aux-triple x86_64-unknown-linux-unknown -fsycl-is-device -disable-llvm-passes -S -emit-llvm %s -o - | FileCheck --check-prefix CHK-LIN %s | ||
|
||
#include "sycl.hpp" | ||
// CHK-WIN: %struct{{.*}}F = type { i8, i8 } | ||
// CHK-LIN: %struct{{.*}}F = type { i8 } | ||
struct F1 {}; | ||
struct F2 {}; | ||
struct F : F1, F2 { | ||
char x; | ||
}; | ||
|
||
int main() { | ||
cl::sycl::accessor<F, 1, cl::sycl::access::mode::read_write> accessorA; | ||
cl::sycl::handler cgh; | ||
cgh.single_task<class kernel_function>( | ||
[=]() { | ||
accessorA.use(); | ||
}); | ||
return 0; | ||
} |
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
28 changes: 28 additions & 0 deletions
28
clang/test/SemaSYCL/non-trivially-copyable-kernel-param.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: %clang_cc1 -fsycl-is-device -verify -fsyntax-only %s | ||
|
||
// This test checks if compiler reports compilation error on an attempt to pass | ||
// a struct with non-trivially copyable type as SYCL kernel parameter. | ||
|
||
struct A { int i; }; | ||
|
||
struct B { | ||
int i; | ||
B (int _i) : i(_i) {} | ||
B (const B& x) : i(x.i) {} | ||
}; | ||
|
||
template <typename Name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
|
||
void test() { | ||
A IamGood; | ||
IamGood.i = 0; | ||
B IamBad(1); | ||
kernel_single_task<class kernel_capture_refs>([=] { | ||
int a = IamGood.i; | ||
// expected-error@+1 {{kernel parameter has non-trivially copyable class/struct type}} | ||
int b = IamBad.i; | ||
}); | ||
} |
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,36 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -verify -fsyntax-only %s | ||
|
||
// This test checks if compiler reports compilation error on an attempt to pass | ||
// a reference as SYCL kernel parameter. | ||
|
||
template <typename Name, typename Func> | ||
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) { | ||
kernelFunc(); | ||
} | ||
|
||
void test_capture_explicit_ref() { | ||
int p = 0; | ||
double q = 0; | ||
float s = 0; | ||
kernel_single_task<class kernel_capture_single_ref>([ | ||
// expected-error@+1 {{'int &' cannot be used as the type of a kernel parameter}} | ||
&p, | ||
q, | ||
// expected-error@+1 {{'float &' cannot be used as the type of a kernel parameter}} | ||
&s] { | ||
(void) q; | ||
(void) p; | ||
(void) s; | ||
}); | ||
} | ||
|
||
void test_capture_implicit_refs() { | ||
int p = 0; | ||
double q = 0; | ||
kernel_single_task<class kernel_capture_refs>([&] { | ||
// expected-error@+1 {{'int &' cannot be used as the type of a kernel parameter}} | ||
(void) p; | ||
// expected-error@+1 {{'double &' cannot be used as the type of a kernel parameter}} | ||
(void) q; | ||
}); | ||
} |
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,45 @@ | ||
// RUN: %clangxx -fsycl %s -o %t.out | ||
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
using namespace cl::sycl; | ||
|
||
struct F1 {}; | ||
struct F2 {}; | ||
struct F : F1, F2 { | ||
cl::sycl::cl_char x; | ||
}; | ||
|
||
bool test0() { | ||
F S; | ||
S.x = 0; | ||
F S0; | ||
S0.x = 1; | ||
{ | ||
buffer<F, 1> Buf(&S0, range<1>(1)); | ||
queue myQueue; | ||
myQueue.submit([&](handler &cgh) { | ||
auto B = Buf.get_access<access::mode::write>(cgh); | ||
cgh.single_task<class NonStandard>([=] { B[0] = S; }); | ||
}); | ||
} | ||
bool Passed = (S.x == S0.x); | ||
|
||
if (!Passed) { | ||
std::cout << "test0 failed" << std::endl; | ||
} | ||
return Passed; | ||
} | ||
|
||
int main() { | ||
|
||
bool Pass = test0(); | ||
|
||
std::cout << "Test " << (Pass ? "passed" : "FAILED") << std::endl; | ||
return Pass ? 0 : 1; | ||
|
||
} |
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.
What if we change parameter type to
TargetInfo
?usage
Uh oh!
There was an error while loading. Please reload this page.
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.
Then we will need to change usage of this function for 3 additional times not including the one which I changed. And these 3 additional places of
isMsLayout
usage aren't connected with my current patch. Are you sure?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 don't see any problems with this refactoring.
The benefit I see from this change is that we move
if
statement higher in the call stack as exactly the same logic is already implemented higher in the calls stack. On the other hand, I hope allisMsLayout
calls are inlined and this might not be a problem.I'll leave final decision to you.
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'd like to keep unrelated parts of code unchanged.