-
Notifications
You must be signed in to change notification settings - Fork 793
[SYCL] Relax linking workaround and test SYCL interlinking #19171
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
steffenlarsen
merged 10 commits into
intel:sycl
from
steffenlarsen:steffen/inter_use_case
Jul 3, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b45a7bb
[SYCL] Remove linking workaround and test SYCL interlinking
steffenlarsen aa35a96
Fix formatting
steffenlarsen 7a36ba1
Free your memory!
steffenlarsen d87e098
Relax linking restriction instead
steffenlarsen 1fc0e36
XFAIL on OCL CPU
steffenlarsen fdf07fc
Update requirement comment
steffenlarsen bc1c6ac
Apply suggestions from code review
steffenlarsen 69a3b89
Merge remote-tracking branch 'intel/sycl' into steffen/inter_use_case
steffenlarsen 2c97cb8
Fix sycl/sycl.hpp count
steffenlarsen b02f272
Merge branch 'sycl' into steffen/inter_use_case
steffenlarsen 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,20 @@ | ||
#include <sycl/sycl.hpp> | ||
|
||
namespace syclext = sycl::ext::oneapi; | ||
namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
||
typedef void (*FuncPtrT)(size_t *); | ||
|
||
struct ArgsT { | ||
size_t *Ptr; | ||
FuncPtrT *FuncPtr; | ||
}; | ||
|
||
SYCL_EXTERNAL size_t GetID() { | ||
return syclext::this_work_item::get_nd_item<1>().get_global_id(); | ||
} | ||
|
||
extern "C" SYCL_EXTERNAL SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
(syclexp::nd_range_kernel<1>)) void Kernel(ArgsT Args) { | ||
(**Args.FuncPtr)(Args.Ptr); | ||
} |
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,82 @@ | ||
#include "common.hpp" | ||
|
||
#include <sycl/usm.hpp> | ||
|
||
namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
||
typedef void (*FuncPtrT)(size_t *); | ||
|
||
struct ArgsT { | ||
size_t *Ptr; | ||
FuncPtrT *FuncPtr; | ||
}; | ||
|
||
#ifdef __SYCL_DEVICE_ONLY__ | ||
SYCL_EXTERNAL size_t GetID(); | ||
#else | ||
// Host-side code to avoid linker problems. Will never be called. | ||
SYCL_EXTERNAL size_t GetID() { return 0; } | ||
#endif | ||
|
||
SYCL_EXTERNAL | ||
void Func(size_t *Ptr) { | ||
size_t GlobalID = GetID(); | ||
Ptr[GlobalID] = GlobalID; | ||
} | ||
|
||
SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::single_task_kernel)) | ||
void GetFuncPtr(ArgsT Args) { *Args.FuncPtr = Func; } | ||
|
||
constexpr size_t N = 32; | ||
|
||
int main(int argc, char *argv[]) { | ||
assert(argc == 2); | ||
|
||
sycl::queue Q; | ||
|
||
int Failed = CommonLoadCheck(Q.get_context(), argv[1]); | ||
|
||
#if defined(SYCLBIN_INPUT_STATE) | ||
auto SYCLBINInput = syclexp::get_kernel_bundle<sycl::bundle_state::input>( | ||
Q.get_context(), std::string{argv[1]}); | ||
auto SYCLBINObj = sycl::compile(SYCLBINInput); | ||
#elif defined(SYCLBIN_OBJECT_STATE) | ||
auto SYCLBINObj = syclexp::get_kernel_bundle<sycl::bundle_state::object>( | ||
Q.get_context(), std::string{argv[1]}); | ||
#else // defined(SYCLBIN_EXECUTABLE_STATE) | ||
#error "Test does not work with executable state." | ||
#endif | ||
|
||
auto KBObj = | ||
syclexp::get_kernel_bundle<GetFuncPtr, sycl::bundle_state::object>( | ||
Q.get_context()); | ||
auto KBExe = sycl::link({KBObj, SYCLBINObj}); | ||
|
||
ArgsT Args{}; | ||
Args.FuncPtr = sycl::malloc_shared<FuncPtrT>(N, Q); | ||
Args.Ptr = sycl::malloc_shared<size_t>(N, Q); | ||
|
||
sycl::kernel GetFuncPtrKern = KBExe.ext_oneapi_get_kernel<GetFuncPtr>(); | ||
Q.submit([&](sycl::handler &CGH) { | ||
CGH.set_args(Args); | ||
CGH.single_task(GetFuncPtrKern); | ||
}).wait(); | ||
|
||
sycl::kernel Kern = KBExe.ext_oneapi_get_kernel("Kernel"); | ||
Q.submit([&](sycl::handler &CGH) { | ||
CGH.set_args(Args); | ||
CGH.parallel_for(sycl::nd_range{{N}, {N}}, Kern); | ||
}).wait(); | ||
|
||
for (size_t I = 0; I < N; ++I) { | ||
if (Args.Ptr[I] != I) { | ||
std::cout << Args.Ptr[I] << " != " << I << std::endl; | ||
++Failed; | ||
} | ||
} | ||
|
||
sycl::free(Args.FuncPtr, Q); | ||
sycl::free(Args.Ptr, Q); | ||
|
||
return Failed; | ||
} |
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,31 @@ | ||
//==-------- link_sycl_inline_input.cpp --- SYCLBIN extension tests --------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// REQUIRES: aspect-usm_shared_allocations | ||
|
||
// -- Test for linking between inline SYCL code and SYCLBIN code. | ||
|
||
// ptxas currently fails to compile images with unresolved symbols. Disable for | ||
// other targets than SPIR-V until this has been resolved. (CMPLRLLVM-68810) | ||
// Note: %{sycl_target_opts} should be added to the SYCLBIN compilation lines | ||
// once fixed. | ||
// REQUIRES: target-spir | ||
|
||
// XFAIL: opencl && cpu | ||
// XFAIL-TRACKER: CMPLRLLVM-68800 | ||
|
||
// XFAIL: linux && arch-intel_gpu_bmg_g21 | ||
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/19258 | ||
|
||
// RUN: %clangxx --offload-new-driver -fsyclbin=input -fsycl-allow-device-image-dependencies -Xclang -fsycl-allow-func-ptr %S/Inputs/link_sycl_inline.cpp -o %t.syclbin | ||
// RUN: %{build} -fsycl-allow-device-image-dependencies -o %t.out | ||
// RUN: %{l0_leak_check} %{run} %t.out %t.syclbin | ||
|
||
#define SYCLBIN_INPUT_STATE | ||
|
||
#include "Inputs/link_sycl_inline.hpp" |
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,32 @@ | ||
//==-------- link_sycl_inline_object.cpp --- SYCLBIN extension tests | ||
//--------==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// REQUIRES: aspect-usm_shared_allocations | ||
|
||
// -- Test for linking between inline SYCL code and SYCLBIN code. | ||
|
||
// ptxas currently fails to compile images with unresolved symbols. Disable for | ||
// other targets than SPIR-V until this has been resolved. (CMPLRLLVM-68810) | ||
// Note: %{sycl_target_opts} should be added to the SYCLBIN compilation lines | ||
// once fixed. | ||
// REQUIRES: target-spir | ||
|
||
// XFAIL: opencl && cpu | ||
// XFAIL-TRACKER: CMPLRLLVM-68800 | ||
|
||
steffenlarsen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// XFAIL: linux && arch-intel_gpu_bmg_g21 | ||
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/19258 | ||
|
||
// RUN: %clangxx --offload-new-driver -fsyclbin=object -fsycl-allow-device-image-dependencies -Xclang -fsycl-allow-func-ptr %S/Inputs/link_sycl_inline.cpp -o %t.syclbin | ||
// RUN: %{build} -fsycl-allow-device-image-dependencies -o %t.out | ||
// RUN: %{l0_leak_check} %{run} %t.out %t.syclbin | ||
|
||
#define SYCLBIN_OBJECT_STATE | ||
|
||
#include "Inputs/link_sycl_inline.hpp" |
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
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.