-
Notifications
You must be signed in to change notification settings - Fork 798
[SYCL] Fix linkage adjustment of kernels #19771
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
AlexeySachkov
merged 7 commits into
intel:sycl
from
AlexeySachkov:private/asachkov/fix-kernel-linkage-adjustment
Aug 14, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
79bcea6
[SYCL] Fix linkage adjustment of kernels
AlexeySachkov 380abb1
Fix clang test
AlexeySachkov b55b788
Apply comments
AlexeySachkov 35eb4a6
Merge remote-tracking branch 'origin/sycl' into private/asachkov/fix-…
AlexeySachkov 3df32a2
Expand the new test
AlexeySachkov 94d624b
Merge remote-tracking branch 'origin/sycl' into private/asachkov/fix-…
AlexeySachkov 36ccb69
Un-XFAIL passing Matrix tests. I may have un-xfailed too much, will s…
AlexeySachkov 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
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,78 @@ | ||
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -triple spir64-unknown-unknown -sycl-std=2020 -emit-llvm -o - %s | FileCheck %s | ||
// | ||
// Kernel definition may be shared by multiple translation unit if a kernel is | ||
// defined as a functor in a header file. Therefore, we need to make sure that | ||
// the linkage for emitted kernel is correct, i.e. it allows to merge the same | ||
// symbols without triggering multiple definitions error. | ||
|
||
#include "sycl.hpp" | ||
|
||
// CHECK-DAG: define weak_odr spir_kernel void @_ZTS13FunctorInline | ||
// CHECK-DAG: define weak_odr spir_kernel void @_ZTS14FunctorInline2 | ||
// CHECK-DAG: define dso_local spir_kernel void @_ZTS15FunctorNoInline | ||
// CHECK-DAG: define dso_local spir_kernel void @_ZTSZ4mainE10KernelName | ||
// CHECK-DAG: define dso_local spir_kernel void @_Z32__sycl_kernel_FreeFunctionKernelv | ||
// CHECK-DAG: define weak_odr spir_kernel void @_Z38__sycl_kernel_FreeFunctionKernelInlinev | ||
|
||
class FunctorInline { | ||
public: | ||
void operator()(sycl::id<1>) const {} | ||
}; | ||
AlexeySachkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
class FunctorInline2 { | ||
public: | ||
void operator()(sycl::id<1>) const; | ||
}; | ||
inline void FunctorInline2::operator()(sycl::id<1>) const {} | ||
|
||
class FunctorNoInline { | ||
public: | ||
void operator()(sycl::id<1>) const; | ||
}; | ||
void FunctorNoInline::operator()(sycl::id<1>) const {} | ||
|
||
class FunctorNoInline2 { | ||
public: | ||
void operator()() const; | ||
}; | ||
void FunctorNoInline2::operator()() const {} | ||
|
||
|
||
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]] | ||
void FreeFunctionKernel() {} | ||
|
||
[[__sycl_detail__::add_ir_attributes_function("sycl-nd-range-kernel", 2)]] | ||
inline void FreeFunctionKernelInline() {} | ||
|
||
|
||
struct KernelLaunchWrapper { | ||
template <typename KernelName, typename KernelType> | ||
__attribute__((sycl_kernel)) | ||
static void kernel_single_task(const KernelType &kernelFunc) { | ||
kernelFunc(); | ||
} | ||
}; | ||
|
||
int main() { | ||
sycl::queue q; | ||
|
||
q.submit([&](sycl::handler &cgh) { | ||
FunctorInline f; | ||
cgh.parallel_for(sycl::range<1>(1024), f); | ||
}); | ||
|
||
q.submit([&](sycl::handler &cgh) { | ||
FunctorInline2 f; | ||
cgh.parallel_for(sycl::range<1>(1024), f); | ||
}); | ||
|
||
q.submit([&](sycl::handler &cgh) { | ||
FunctorNoInline f; | ||
cgh.parallel_for(sycl::range<1>(1024), f); | ||
}); | ||
|
||
{ | ||
FunctorNoInline2 f; | ||
KernelLaunchWrapper::kernel_single_task<class KernelName>(f); | ||
} | ||
} |
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
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.
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.
Lol sorry about all the problems caused from unifying the attributes, I originally just wanted to add a new attribute for SPIR kernels but upstream suggested I unify them all, thanks for fixing this
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.
To be fair, this whole thing with fixing-up the linkage is also a little bit weird, so no worries :)