-
Notifications
You must be signed in to change notification settings - Fork 801
[SYCL] Implement backend content extension #16633
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 58 commits
Commits
Show all changes
65 commits
Select commit
Hold shift + click to select a range
464174d
Implement backend content extension
lbushi25 217270c
Merge branch 'device_image_backend_content' of https://github.com/lbu…
lbushi25 776a3ed
Add tests for extension
lbushi25 3080741
Merge branch 'intel:sycl' into device_image_backend_content
lbushi25 12bdf3f
Change extension spec status section
lbushi25 a4f6372
Merge branch 'device_image_backend_content' of https://github.com/lbu…
lbushi25 c15a31a
Add more tests and fix ABI related failures
lbushi25 0ba58c7
Add checks for span feature
lbushi25 50018cb
Refactoring
lbushi25 b20f042
More refactoring
lbushi25 2c7b110
Formatting
lbushi25 b884eec
Merge branch 'intel:sycl' into device_image_backend_content
lbushi25 36f4095
Add windows symbols
lbushi25 5d4a6bf
Add check for std::span feature
lbushi25 273f6df
Add comments explaining limitations of free function kernel usage
lbushi25 192cf75
Add asserts for extra safety
lbushi25 5d7d500
Define feature macro for device image backend content
lbushi25 5050a3c
Improve testing logic
lbushi25 ab765f9
Make comments more helpful
lbushi25 e8be859
Enhance tests
lbushi25 fa68a24
Resolve merge
lbushi25 74c0772
Remove rogue binary file
lbushi25 78e7ae6
Improve L0_interop_test.cpp to avoid false positives
lbushi25 b2594e8
Use __has_include to guard the inclusion of <span>
lbushi25 5b88761
Update basic_test.cpp
lbushi25 ccdd15c
Apply feedback
lbushi25 e4914b8
Merge branch 'sycl' into device_image_backend_content
lbushi25 21f4a9b
Update sycl_symbols_linux.dump
lbushi25 91853e0
Update sycl_symbols_linux.dump
lbushi25 70c168a
Add windows symbols
lbushi25 a43e3b4
Merge branch 'device_image_backend_content' of https://github.com/lbu…
lbushi25 cc5189e
Apply suggestions
lbushi25 7b8458c
Fix symbols
lbushi25 ab163f7
Add c++20 flag to compilation of tests
lbushi25 247932e
Update negative_test.cpp
lbushi25 688521d
Update sycl_symbols_linux.dump
lbushi25 c1a5ea7
Update sycl_symbols_linux.dump
lbushi25 bb5b787
Update basic_test.cpp
lbushi25 a3f837d
Update basic_test.cpp
lbushi25 d6a2ca5
Modify spec and add windows symbols
lbushi25 d5c214c
Add windows symbols
lbushi25 587941f
Resolve merge conflict in spec
lbushi25 2e38117
Update basic_test.cpp
lbushi25 4ee145e
Update basic_test.cpp
lbushi25 3308fac
Simplify basic_test.cpp
lbushi25 bc695cf
Update sycl_ext_oneapi_device_image_backend_content.asciidoc
lbushi25 3b2691f
Make span const
lbushi25 cf94a3e
Merge branch 'device_image_backend_content' of https://github.com/lbu…
lbushi25 743c9a7
Fix test failures on HIP/CUDA
lbushi25 97637cf
Fix test failures on HIP/CUDA
lbushi25 afe72b8
Fix test failures on HIP/CUDA
lbushi25 d1f2644
Update sycl_symbols_windows.dump
lbushi25 910ce34
Add OpenCL interoperability test
lbushi25 d267155
Add OpenCL interoperability test
lbushi25 a9e1e21
Merge branch 'sycl' into device_image_backend_content
lbushi25 2c916f6
Add CUDA test
lbushi25 16186ba
Merge branch 'device_image_backend_content' of https://github.com/lbu…
lbushi25 77eda18
Add CUDA test
lbushi25 a29db25
Fix typo in CUDA test
lbushi25 248fc93
Update CUDA_interop_test.cpp
lbushi25 c666340
Merge branch 'intel:sycl' into device_image_backend_content
lbushi25 4ccce5a
Fix compilation error in CUDA_interop_test.cpp
lbushi25 2e4d7f8
Apply suggestions
lbushi25 9aa2184
Fix compilation error in L0 test
lbushi25 6a88f93
Adjust symbols
lbushi25 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
33 changes: 33 additions & 0 deletions
33
sycl/test-e2e/DeviceImageBackendContent/CUDA_interop_test.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,33 @@ | ||
| // RUN: %{build} %cuda_options -o %t.out | ||
| // RUN: %{run} %t.out | ||
| // REQUIRES: cuda, cuda_dev_kit | ||
|
|
||
| #include <cuda.h> | ||
| #include <sycl/backend.hpp> | ||
| #include <sycl/detail/core.hpp> | ||
| #include <vector> | ||
|
|
||
| int main() { | ||
| sycl::device d([](const sycl::device &d) { | ||
| return d.get_backend() == sycl::backend::opencl; | ||
lbushi25 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| sycl::queue q{d}; | ||
| sycl::context ctxt = q.get_context(); | ||
| sycl::kernel_id k_id = sycl::get_kernel_id<class mykernel>(); | ||
| auto bundle = | ||
| sycl::get_kernel_bundle<sycl::bundle_state::executable>(ctxt, {k_id}); | ||
| assert(!bundle.empty()); | ||
| sycl::kernel krn = bundle.get_kernel(k_id); | ||
| sycl::buffer<int> buf(sycl::range<1>(1)); | ||
| q.submit([&](sycl::handler &cgh) { | ||
| sycl::accessor acc(buf, cgh); | ||
| cgh.single_task<class mykernel>(krn, [=]() { acc[0] = 42; }); | ||
| }); | ||
| const auto img = *(bundle.begin()); | ||
| const auto bytes = img.ext_oneapi_get_backend_content(); | ||
| CUmodule m; | ||
| CUresult res = | ||
| cuModuleLoadData(&m, reinterpret_cast<const void *>(bytes.data())); | ||
| assert(result == CUDA_SUCCESS); | ||
| return 0; | ||
| } | ||
97 changes: 97 additions & 0 deletions
97
sycl/test-e2e/DeviceImageBackendContent/L0_interop_test.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,97 @@ | ||
| // REQUIRES: level_zero, level_zero_dev_kit, aspect-usm_shared_allocations | ||
| // RUN: %{build} %level_zero_options -fno-sycl-dead-args-optimization -o %t.out | ||
| // RUN: %{run} %t.out | ||
| // | ||
| #include <level_zero/ze_api.h> | ||
| #include <sycl/detail/core.hpp> | ||
| #include <sycl/ext/oneapi/backend/level_zero.hpp> | ||
| #include <sycl/ext/oneapi/free_function_queries.hpp> | ||
| #include <sycl/usm.hpp> | ||
| #include <vector> | ||
|
|
||
| namespace syclext = sycl::ext::oneapi; | ||
| namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
|
||
| extern "C" SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
| (syclexp::nd_range_kernel<1>)) void iota(int *ptr) { | ||
| size_t id = syclext::this_work_item::get_nd_item<1>().get_global_linear_id(); | ||
| ptr[id] = 42; | ||
| } | ||
|
|
||
| int main() { | ||
| sycl::device d([](const sycl::device &d) { | ||
| return d.get_backend() == sycl::backend::ext_oneapi_level_zero; | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| sycl::queue q{d}; | ||
| sycl::context ctxt = q.get_context(); | ||
|
|
||
| // The following ifndef is required due to a number of limitations of free | ||
| // function kernels. See CMPLRLLVM-61498. | ||
| // TODO: Remove it once these limitations are no longer there. | ||
| #ifndef __SYCL_DEVICE_ONLY__ | ||
| // First, run the kernel using the SYCL API. | ||
| auto Bundle = sycl::get_kernel_bundle<sycl::bundle_state::executable>(ctxt); | ||
steffenlarsen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| sycl::kernel_id iota_id = syclexp::get_kernel_id<iota>(); | ||
| sycl::kernel k_iota = Bundle.get_kernel(iota_id); | ||
| int *ptr = sycl::malloc_shared<int>(1, q); | ||
| *ptr = 0; | ||
| q.submit([&](sycl::handler &cgh) { | ||
| cgh.set_args(ptr); | ||
| cgh.parallel_for(sycl::nd_range{{1}, {1}}, k_iota); | ||
| }).wait(); | ||
|
|
||
| // Now, run the kernel by first getting its image as an executable, | ||
| // making an L0 kernel out of it and then making a SYCL kernel out of | ||
| // the L0 kernel. Run this kernel on the SYCL API and verify | ||
| // that it has the same result as the kernel that was run directly on SYCL | ||
| // API. First, get a kernel bundle that contains the kernel "iota". | ||
| auto exe_bndl = sycl::get_kernel_bundle<sycl::bundle_state::executable>( | ||
| ctxt, {d}, | ||
| [&](const sycl::device_image<sycl::bundle_state::executable> &img) { | ||
| return img.has_kernel(iota_id, d); | ||
| }); | ||
| assert(!exe_bndl.empty()); | ||
| std::vector<std::byte> bytes; | ||
| const sycl::device_image<sycl::bundle_state::executable> &img = | ||
| *(exe_bndl.begin()); | ||
| bytes = img.ext_oneapi_get_backend_content(); | ||
|
|
||
| auto ZeContext = sycl::get_native<sycl::backend::ext_oneapi_level_zero>(ctxt); | ||
| auto ZeDevice = sycl::get_native<sycl::backend::ext_oneapi_level_zero>(d); | ||
|
|
||
| ze_result_t status; | ||
| ze_module_desc_t moduleDesc = { | ||
| ZE_STRUCTURE_TYPE_MODULE_DESC, | ||
| nullptr, | ||
| ZE_MODULE_FORMAT_IL_SPIRV, | ||
| bytes.size(), | ||
| reinterpret_cast<unsigned char *>(bytes.data()), | ||
| nullptr, | ||
| nullptr}; | ||
| ze_module_handle_t ZeModule; | ||
| status = zeModuleCreate(ZeContext, ZeDevice, &moduleDesc, &ZeModule, nullptr); | ||
| assert(status == ZE_RESULT_SUCCESS); | ||
|
|
||
| ze_kernel_desc_t kernelDesc = {ZE_STRUCTURE_TYPE_KERNEL_DESC, nullptr, 0, | ||
| "__sycl_kernel_iota"}; | ||
| ze_kernel_handle_t ZeKernel; | ||
| status = zeKernelCreate(ZeModule, &kernelDesc, &ZeKernel); | ||
| assert(status == ZE_RESULT_SUCCESS); | ||
| sycl::kernel k_iota_twin = | ||
| sycl::make_kernel<sycl::backend::ext_oneapi_level_zero>( | ||
| {sycl::make_kernel_bundle<sycl::backend::ext_oneapi_level_zero, | ||
| sycl::bundle_state::executable>({ZeModule}, | ||
| ctxt), | ||
| ZeKernel}, | ||
| ctxt); | ||
| int *ptr_twin = sycl::malloc_shared<int>(1, q); | ||
| *ptr_twin = 1; | ||
| q.submit([&](sycl::handler &cgh) { | ||
| cgh.set_args(ptr_twin); | ||
| cgh.parallel_for(sycl::nd_range{{1}, {1}}, k_iota_twin); | ||
| }).wait(); | ||
| assert(*ptr_twin == *ptr); | ||
| sycl::free(ptr, q); | ||
| sycl::free(ptr_twin, q); | ||
| #endif | ||
| } | ||
83 changes: 83 additions & 0 deletions
83
sycl/test-e2e/DeviceImageBackendContent/OCL_interop_test.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,83 @@ | ||
| // REQUIRES: opencl, opencl_icd, aspect-usm_shared_allocations | ||
| // RUN: %{build} %opencl_lib -fno-sycl-dead-args-optimization -o %t.out | ||
| // RUN: %{run} %t.out | ||
| // | ||
| #include <sycl/backend.hpp> | ||
| #include <sycl/detail/cl.h> | ||
| #include <sycl/detail/core.hpp> | ||
| #include <sycl/ext/oneapi/free_function_queries.hpp> | ||
| #include <sycl/usm.hpp> | ||
| #include <vector> | ||
|
|
||
| namespace syclext = sycl::ext::oneapi; | ||
| namespace syclexp = sycl::ext::oneapi::experimental; | ||
|
|
||
| extern "C" SYCL_EXT_ONEAPI_FUNCTION_PROPERTY( | ||
| (syclexp::nd_range_kernel<1>)) void iota(int *ptr) { | ||
| size_t id = syclext::this_work_item::get_nd_item<1>().get_global_linear_id(); | ||
| ptr[id] = 42; | ||
| } | ||
|
|
||
| int main() { | ||
| sycl::device d([](const sycl::device &d) { | ||
| return d.get_backend() == sycl::backend::opencl; | ||
| }); | ||
| sycl::queue q{d}; | ||
| sycl::context ctxt = q.get_context(); | ||
|
|
||
| // The following ifndef is required due to a number of limitations of free | ||
| // function kernels. See CMPLRLLVM-61498. | ||
| // TODO: Remove it once these limitations are no longer there. | ||
| #ifndef __SYCL_DEVICE_ONLY__ | ||
| // First, run the kernel using the SYCL API. | ||
| auto Bundle = sycl::get_kernel_bundle<sycl::bundle_state::executable>(ctxt); | ||
| sycl::kernel_id iota_id = syclexp::get_kernel_id<iota>(); | ||
| sycl::kernel k_iota = Bundle.get_kernel(iota_id); | ||
|
|
||
| int *ptr = sycl::malloc_shared<int>(1, q); | ||
| *ptr = 0; | ||
| q.submit([&](sycl::handler &cgh) { | ||
| cgh.set_args(ptr); | ||
| cgh.parallel_for(sycl::nd_range{{1}, {1}}, k_iota); | ||
| }).wait(); | ||
| // Now, run the kernel by first getting its image as an executable, | ||
| // making an OCL kernel out of it and then making a SYCL kernel out of | ||
| // the OCL kernel. Run this kernel on the SYCL API and verify | ||
| // that it has the same result as the kernel that was run directly on SYCL | ||
| // API. First, get a kernel bundle that contains the kernel "iota". | ||
| auto exe_bndl = sycl::get_kernel_bundle<sycl::bundle_state::executable>( | ||
| ctxt, {d}, | ||
| [&](const sycl::device_image<sycl::bundle_state::executable> &img) { | ||
| return img.has_kernel(iota_id, d); | ||
| }); | ||
| assert(!exe_bndl.empty()); | ||
| std::vector<std::byte> bytes; | ||
| const sycl::device_image<sycl::bundle_state::executable> &img = | ||
| *(exe_bndl.begin()); | ||
| bytes = img.ext_oneapi_get_backend_content(); | ||
|
|
||
| auto clContext = sycl::get_native<sycl::backend::opencl>(ctxt); | ||
| auto clDevice = sycl::get_native<sycl::backend::opencl>(d); | ||
|
|
||
| cl_int status; | ||
| auto clProgram = clCreateProgramWithIL( | ||
| clContext, reinterpret_cast<unsigned char *>(bytes.data()), bytes.size(), | ||
| &status); | ||
| assert(status == CL_SUCCESS); | ||
| status = clBuildProgram(clProgram, 1, &clDevice, "", nullptr, nullptr); | ||
| assert(status == CL_SUCCESS); | ||
| auto clKernel = clCreateKernel(clProgram, "__sycl_kernel_iota", &status); | ||
| assert(status == CL_SUCCESS); | ||
| sycl::kernel k_iota_twin = | ||
| sycl::make_kernel<sycl::backend::opencl>(clKernel, ctxt); | ||
| int *ptr_twin = sycl::malloc_shared<int>(1, q); | ||
| *ptr_twin = 1; | ||
| q.submit([&](sycl::handler &cgh) { | ||
| cgh.set_args(ptr_twin); | ||
| cgh.parallel_for(sycl::nd_range{{1}, {1}}, k_iota_twin); | ||
| }).wait(); | ||
| assert(*ptr_twin == *ptr); | ||
| sycl::free(ptr, q); | ||
| sycl::free(ptr_twin, q); | ||
| #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.