Repository navigation
[SYCL][NewOffloadModel] Reference an undefined function in the host object and define it in the wrapped device object #23388
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
22 commits
Select commit
Hold shift + click to select a range
34014ac
[SYCL] Fix linking of fat static archives
sarnex 72b85a5
Address feedback and fix -fsycl-host-only
sarnex e9c8450
Merge remote-tracking branch 'upstream/sycl' into HEAD
sarnex c7101ff
fix typo
sarnex 629ecd3
fix lto and spir64_gen no arch
sarnex 92b57f7
make clang link test case clearer
sarnex 99608f0
add lto test
sarnex 116f732
reuse Binaries vector
sarnex e8cf02c
avoid odr violation and cleanup comments
sarnex ca731f7
add spir64_gen no device test
sarnex e8e09e4
dedup
sarnex 69e17a7
fix generic case and add test
sarnex 3250e52
return early and remove magic arg
sarnex 9b3b23f
add lit test for no device code
sarnex 343d451
address nits
sarnex 040ede7
fix comment
sarnex 6f02036
fix nits
sarnex c602681
Merge remote-tracking branch 'upstream/sycl' into HEAD
sarnex f31d8a9
remove spir64_gen no device test
sarnex 5513605
address tom's feedback and fix test bug
sarnex d176840
add assert for empty unique ident
sarnex a538b9f
Merge remote-tracking branch 'upstream/sycl' into HEAD
sarnex 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Verify that we don't emit __sycl_registerlib_<unique identifier> or __sycl_registerlib_ctor if -fembed-offload-object is not passed, as | ||
| // there is no device code in that case. | ||
|
|
||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsycl-is-host --offload-new-driver -fsycl-unique-prefix=uid42 -emit-llvm %s -o - | FileCheck %s | ||
|
|
||
| // CHECK-NOT: __sycl_ |
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 @@ | ||
| // Check the per-translation-unit __sycl_registerlib_<id> reference that SYCL | ||
| // host code generation emits under the new offload driver. The id is the | ||
| // translation unit's -fsycl-unique-prefix, which the driver generates. | ||
|
|
||
| // RUN: touch %t.o | ||
|
|
||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsycl-is-host --offload-new-driver -fsycl-unique-prefix=uid42 -emit-llvm -fembed-offload-object=%t.o %s -o - | FileCheck %s | ||
|
|
||
| // Nothing is emitted without the new offload driver. | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsycl-is-host -fsycl-unique-prefix=uid42 -emit-llvm -fembed-offload-object=%t.o %s -o - | FileCheck %s --check-prefix=OLD | ||
|
|
||
| // Nor when the module embeds its device binary (-fno-sycl-rdc), as it then | ||
| // registers the binary itself. | ||
| // RUN: echo -n 'FAKE_SYCL_DEVICE_IMAGE' > %t.bin | ||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsycl-is-host --offload-new-driver -foffload-include-binary %t.bin -fsycl-unique-prefix=uid42 -emit-llvm %s -o - | FileCheck %s --check-prefix=EMBED --implicit-check-not=__sycl_registerlib_ | ||
|
|
||
| // CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__sycl_registerlib_ctor, ptr null }] | ||
| // CHECK: declare void @__sycl_registerlib_uid42() | ||
| // CHECK: define internal void @__sycl_registerlib_ctor() | ||
| // CHECK-NEXT: entry: | ||
| // CHECK-NEXT: call void @__sycl_registerlib_uid42() | ||
| // CHECK-NEXT: ret void | ||
|
|
||
| // OLD-NOT: __sycl_registerlib_ | ||
|
|
||
| // EMBED: @.sycl_offloading.binary | ||
|
|
||
| void foo() {} |
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
47 changes: 47 additions & 0 deletions
47
clang/test/OffloadTools/clang-linker-wrapper/linker-wrapper-sycl-registerlib.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,47 @@ | ||
| // REQUIRES: system-linux, x86-registered-target, spirv-to-ir-wrapper, sycl-post-link | ||
|
|
||
| // Check that the SYCL wrapper object for a target defines the | ||
| // __sycl_registerlib_<id> symbols referenced by the host objects whose device | ||
| // code is for that target, including archive members found through -l. | ||
|
|
||
| // RUN: %clang_cc1 -fsycl-is-device -disable-llvm-passes -triple=spir64-unknown-unknown %s -emit-llvm-bc -o %t.bc | ||
| // RUN: llvm-offload-binary -o %t.fat --image=file=%t.bc,kind=sycl,triple=spir64-unknown-unknown | ||
| // RUN: llvm-offload-binary -o %t.gen.fat --image=file=%t.bc,kind=sycl,triple=spir64_gen-unknown-unknown,arch=pvc | ||
| // RUN: %clang_cc1 -DMAIN %s -triple=x86_64-unknown-linux-gnu -fsycl-is-host --offload-new-driver -fsycl-unique-prefix=main -emit-obj -fembed-offload-object=%t.fat -o %t.main.o | ||
| // RUN: %clang_cc1 -DFN=lib_fn %s -triple=x86_64-unknown-linux-gnu -fsycl-is-host --offload-new-driver -fsycl-unique-prefix=lib -emit-obj -fembed-offload-object=%t.fat -o %t.lib.o | ||
| // RUN: %clang_cc1 -DFN=gen_fn %s -triple=x86_64-unknown-linux-gnu -fsycl-is-host --offload-new-driver -fsycl-unique-prefix=gen -emit-obj -fembed-offload-object=%t.gen.fat -o %t.gen.o | ||
| // RUN: rm -rf %t.dir && mkdir -p %t.dir | ||
| // RUN: llvm-ar rc %t.dir/libsyclreg.a %t.lib.o %t.gen.o | ||
| // RUN: touch %t.devicelib.bc | ||
| // RUN: clang-linker-wrapper --print-wrapped-module --host-triple=x86_64-unknown-linux-gnu \ | ||
| // RUN: --bitcode-library=spir64-unknown-unknown=%t.devicelib.bc \ | ||
| // RUN: -sycl-post-link-options=-split=auto -sycl-post-link-options=-symbols \ | ||
| // RUN: -sycl-post-link-options=-properties --linker-path=/usr/bin/ld \ | ||
| // RUN: %t.main.o -L%t.dir -lsyclreg -o %t.out 2>&1 \ | ||
| // RUN: | FileCheck %s --implicit-check-not=__sycl_registerlib_gen | ||
|
|
||
| // No spir64_gen device code is linked, so nothing defines that reference. | ||
| // CHECK: define weak void @__sycl_registerlib_main() | ||
| // CHECK: define weak void @__sycl_registerlib_lib() | ||
|
|
||
| template <typename t, typename Func> | ||
| __attribute__((sycl_kernel)) void kernel(const Func &func) { | ||
| func(); | ||
| } | ||
|
|
||
| #ifdef MAIN | ||
| extern "C" { | ||
| // Define stub versions of the SYCL runtime image registration functions that are called by | ||
| // the wrapped host code so we don't need to link against the real SYCL runtime. | ||
| void __sycl_register_lib(void *) {} | ||
| void __sycl_unregister_lib(void *) {} | ||
|
tahonermann marked this conversation as resolved.
|
||
| } | ||
|
|
||
| void lib_fn(); | ||
| int main() { | ||
| kernel<class main_kernel>([]() {}); | ||
| lib_fn(); | ||
| } | ||
| #else | ||
| void FN() { kernel<class lib_kernel>([]() {}); } | ||
| #endif | ||
Oops, something went wrong.
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.
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.
This code is not new, nor is the below
Options.tdchange.It was previously upstream code but was removed when upstream removed the old driver in llvm/llvm-project@feea42c
We just pulled down that change a couple of days ago, I am just adding it back here because I want to use it to restrict this fix.