-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL] Implement a builtin to mark a sycl kernel #3894
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
9 commits
Select commit
Hold shift + click to select a range
c2b0991
[SYCL] implement a builtin to mark a sycl kernel
ddb3ae7
Fix the clang-format I'm willing to do
0962bf6
Document kernel_desc.hpp use of this builtin
e6c5f14
Fix a lang-extensions comment, update the diagnostics, add tests
6669b37
Fixes suggested by aaron, clarify language-extensions document
e9aa506
Change tests as Elizabeth requested
234bd2e
Add regression test requested by AlexeySachkov
7f61ef1
Update tests as @elizabethandrews requested in review
4e94a62
Accept @bader 's suggestion toremove sycldevice
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
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 |
---|---|---|
|
@@ -187,6 +187,7 @@ class accessor { | |
template <int dimensions, access::mode accessmode, access::target accesstarget> | ||
struct opencl_image_type; | ||
|
||
#ifdef __SYCL_DEVICE_ONLY__ | ||
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. Note the CFE only provides these types in device mode, so this change lets us uses this in header properly in host mode. |
||
#define IMAGETY_DEFINE(dim, accessmode, amsuffix, Target, ifarray_) \ | ||
template <> \ | ||
struct opencl_image_type<dim, access::mode::accessmode, \ | ||
|
@@ -218,6 +219,8 @@ IMAGETY_WRITE_3_DIM_IMAGE | |
IMAGETY_READ_2_DIM_IARRAY | ||
IMAGETY_WRITE_2_DIM_IARRAY | ||
|
||
#endif | ||
|
||
template <int dim, access::mode accessmode, access::target accesstarget> | ||
struct _ImageImplT { | ||
#ifdef __SYCL_DEVICE_ONLY__ | ||
|
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 -triple x86_64-linux-pc -fsycl-is-host -disable-llvm-passes -fdeclare-spirv-builtins -emit-llvm %s -o - | FileCheck %s | ||
// RUN: %clang_cc1 -triple spir64 -aux-triple x86_64-linux-pc -fsycl-is-device -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s | ||
|
||
erichkeane marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include "Inputs/sycl.hpp" | ||
|
||
// This test validates that the use of __builtin_sycl_mark_kernel_name alters | ||
// the code-gen'ed value of __builtin_unique_stable_name. In this case, lambda1 | ||
// emits the unmodified version like we do typically, while lambda2 is 'marked', | ||
// so it should follow kernel naming (that is, using the E10000 naming). Note | ||
// that the top level kernel lambda (the E10000 in common) is automatically part | ||
// of a kernel name, since it is passed to the kernel function (which is | ||
// necessary so that the 'device' build actually emits the builtins. | ||
|
||
int main() { | ||
|
||
cl::sycl::kernel_single_task<class K>([]() { | ||
auto lambda1 = []() {}; | ||
auto lambda2 = []() {}; | ||
|
||
(void)__builtin_sycl_unique_stable_name(decltype(lambda1)); | ||
// CHECK: [35 x i8] c"_ZTSZZ4mainENKUlvE10000_clEvEUlvE_\00" | ||
|
||
// Should change the unique-stable-name of the lambda. | ||
(void)__builtin_sycl_mark_kernel_name(decltype(lambda2)); | ||
(void)__builtin_sycl_unique_stable_name(decltype(lambda2)); | ||
// CHECK: [40 x i8] c"_ZTSZZ4mainENKUlvE10000_clEvEUlvE10000_\00" | ||
}); | ||
} |
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,54 @@ | ||
// RUN: %clang_cc1 %s -std=c++17 -triple x86_64-linux-gnu -fsycl-is-device -verify -fsyntax-only | ||
|
||
#include "Inputs/sycl.hpp" | ||
|
||
// Test to validate that __builtin_sycl_mark_kernel_name properly updates the | ||
// constexpr checking for __builtin_sycl_unique_stable_name. We need to make | ||
// sure that the KernelInfo change in the library both still stays broken, and | ||
// is then 'fixed', so the definitions below help ensure that is the case. | ||
// We also validate that this works in the event that we have a wrapper that | ||
// first calls for the KernelInfo type, then instantiates a kernel. | ||
|
||
template <typename KN> | ||
erichkeane marked this conversation as resolved.
Show resolved
Hide resolved
|
||
struct KernelInfo { | ||
static constexpr const char *c = __builtin_sycl_unique_stable_name(KN); // #KI_USN | ||
}; | ||
|
||
template <typename KN> | ||
struct FixedKernelInfo { | ||
static constexpr bool b = __builtin_sycl_mark_kernel_name(KN); | ||
// making 'c' dependent on 'b' is necessary to ensure 'b' gets called first. | ||
static constexpr const char *c = b | ||
? __builtin_sycl_unique_stable_name(KN) | ||
: nullptr; | ||
}; | ||
|
||
template <template <typename> class KI, | ||
typename KernelName, | ||
typename KernelType> | ||
void wrapper(KernelType KernelFunc) { | ||
(void)KI<KernelName>::c; | ||
cl::sycl::kernel_single_task<KernelName>(KernelFunc); // #SingleTaskInst | ||
} | ||
|
||
int main() { | ||
[]() { | ||
class KernelName1; | ||
constexpr const char *C = __builtin_sycl_unique_stable_name(KernelName1); | ||
// expected-error@+2 {{kernel naming changes the result of an evaluated '__builtin_sycl_unique_stable_name'}} | ||
// expected-note@-2 {{'__builtin_sycl_unique_stable_name' evaluated here}} | ||
(void)__builtin_sycl_mark_kernel_name(KernelName1); | ||
}(); | ||
|
||
[]() { | ||
// expected-error@#KernelSingleTaskFunc {{kernel instantiation changes the result of an evaluated '__builtin_sycl_unique_stable_name'}} | ||
// expected-note@#SingleTaskInst {{in instantiation of function template}} | ||
// expected-note@+2 {{in instantiation of function template}} | ||
// expected-note@#KI_USN {{'__builtin_sycl_unique_stable_name' evaluated here}} | ||
wrapper<KernelInfo, class KernelName2>([]() {}); | ||
}(); | ||
|
||
[]() { | ||
wrapper<FixedKernelInfo, class KernelName3>([]() {}); | ||
}(); | ||
} |
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,16 @@ | ||
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-device-only -c %s -o %t.temp | ||
|
||
erichkeane marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// This validates that the unnamed lambda logic in the library correctly works | ||
// with a new implementation of __builtin_unique_stable_name, where | ||
// instantiation order matters. parallel_for instantiates the KernelInfo before | ||
// the kernel itself, so this checks that example, which only happens when the | ||
// named kernel is inside another lambda. | ||
|
||
#include "CL/sycl.hpp" | ||
|
||
void foo(cl::sycl::queue queue) { | ||
cl::sycl::event queue_event2 = queue.submit([&](cl::sycl::handler &cgh) { | ||
cgh.parallel_for<class K1>(cl::sycl::range<1>{1}, | ||
[=](cl::sycl::item<1> id) {}); | ||
}); | ||
} |
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.