-
Notifications
You must be signed in to change notification settings - Fork 803
[NFC] Rename ext_codeplay_enqueue_native_command to ext_oneapi_enqueue_native_command #14854
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
Changes from 6 commits
ebdbbcf
169510e
26dff62
7e6dc41
a5fbfd2
ae91acf
14e0060
918fdd6
e27e910
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,12 +116,13 @@ if(SYCL_PI_UR_USE_FETCH_CONTENT) | |
| endfunction() | ||
|
|
||
| set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git") | ||
| # commit bc1a28ede0df7f837047b632e00437587672c134 | ||
| # commit 99489ad46853c24a078d7ad35259cc6278498fe5 | ||
| # Merge: 3e762e00 3f13f69e | ||
| # Author: Omar Ahmed <[email protected]> | ||
| # Date: Mon Jul 29 16:44:58 2024 +0100 | ||
| # Merge pull request #1819 from DBDuncan/sean/rename-interop-to-external | ||
| # [Bindless][Exp] Rename interop related structs/funcs with "external" | ||
| set(UNIFIED_RUNTIME_TAG bc1a28ede0df7f837047b632e00437587672c134) | ||
| # Date: Wed Jul 31 13:23:29 2024 +0100 | ||
| # Merge pull request #1880 from hdelan/l0-native-enqueue | ||
| # [L0] L0 impl for enqueue native command | ||
| set(UNIFIED_RUNTIME_TAG 99489ad46853c24a078d7ad35259cc6278498fe5) | ||
|
|
||
| set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "EXAMPLES") | ||
| # Due to the use of dependentloadflag and no installer for UMF and hwloc we need | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| // RUN: %{build} %level_zero_options -o %t.out | ||
| // RUN: %{run} %t.out | ||
|
|
||
| // REQUIRES: level_zero, level_zero_dev_kit | ||
|
|
||
| // TODO: Reenable, see https://github.com/intel/llvm/issues/14598 | ||
| // UNSUPPORTED: windows | ||
hdelan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #include <level_zero/ze_api.h> | ||
|
|
||
| #include <iostream> | ||
| #include <sycl/backend.hpp> | ||
| #include <sycl/detail/core.hpp> | ||
| #include <sycl/interop_handle.hpp> | ||
|
|
||
| using namespace sycl; | ||
| using namespace sycl::access; | ||
|
|
||
| static constexpr size_t BUFFER_SIZE = 1024; | ||
|
|
||
| template <typename T> class Modifier; | ||
|
|
||
| template <typename T> class Init; | ||
|
|
||
| template <typename BufferT, typename ValueT> | ||
| void checkBufferValues(BufferT Buffer, ValueT Value) { | ||
| auto Acc = Buffer.get_host_access(); | ||
| for (size_t Idx = 0; Idx < Acc.get_count(); ++Idx) { | ||
| if (Acc[Idx] != Value) { | ||
| std::cerr << "buffer[" << Idx << "] = " << Acc[Idx] | ||
| << ", expected val = " << Value << '\n'; | ||
| exit(1); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| template <typename DataT> | ||
| void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) { | ||
| Q.submit([&](handler &CGH) { | ||
| auto SrcA = Src.template get_access<mode::read>(CGH); | ||
| auto DstA = Dst.template get_access<mode::write>(CGH); | ||
|
|
||
| auto Func = [=](interop_handle IH) { | ||
| auto CommandList = IH.get_native_queue<backend::ext_oneapi_level_zero>(); | ||
| auto SrcMem = IH.get_native_mem<backend::ext_oneapi_level_zero>(SrcA); | ||
| auto DstMem = IH.get_native_mem<backend::ext_oneapi_level_zero>(DstA); | ||
|
|
||
| // If L0 interop becomes a real use case we should make a new UR entry | ||
| // point to propagate events into and out of the the interop func. | ||
|
Contributor
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. What does this comment mean?
Contributor
Author
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. In order to make this entry point more performant on L0 we would need something like the previous host task extensions so we can pass in and out events to the As it stands there is no point making this more performant for L0 since no one that we are aware of are using L0 interop in SYCL.
Contributor
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. ???? We have had a SYCL Level Zero interop specification for a long time and many people are using it. |
||
| if (zeCommandListAppendMemoryCopy( | ||
| CommandList, DstMem, SrcMem, sizeof(DataT) * SrcA.get_count(), | ||
| nullptr, 0, nullptr) != ZE_RESULT_SUCCESS) | ||
| throw; | ||
| if (Q.get_backend() != IH.get_backend()) | ||
| throw; | ||
| }; | ||
| CGH.ext_oneapi_enqueue_native_command(Func); | ||
| }); | ||
| } | ||
|
|
||
| template <typename DataT> void modify(buffer<DataT, 1> &B, queue &Q) { | ||
| Q.submit([&](handler &CGH) { | ||
| auto Acc = B.template get_access<mode::read_write>(CGH); | ||
|
|
||
| auto Kernel = [=](item<1> Id) { Acc[Id] += 1; }; | ||
|
|
||
| CGH.parallel_for<Modifier<DataT>>(Acc.get_count(), Kernel); | ||
| }); | ||
| } | ||
|
|
||
| template <typename DataT, DataT B1Init, DataT B2Init> | ||
| void init(buffer<DataT, 1> &B1, buffer<DataT, 1> &B2, queue &Q) { | ||
| Q.submit([&](handler &CGH) { | ||
| auto Acc1 = B1.template get_access<mode::write>(CGH); | ||
| auto Acc2 = B2.template get_access<mode::write>(CGH); | ||
|
|
||
| CGH.parallel_for<Init<DataT>>(BUFFER_SIZE, [=](item<1> Id) { | ||
| Acc1[Id] = B1Init; | ||
| Acc2[Id] = B2Init; | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| // Check that a single host-interop-task with a buffer will work. | ||
| void test_ht_buffer(queue &Q) { | ||
| buffer<int, 1> Buffer{BUFFER_SIZE}; | ||
|
|
||
| Q.submit([&](handler &CGH) { | ||
| auto Acc = Buffer.get_access<mode::write>(CGH); | ||
| auto Func = [=](interop_handle IH) { /*A no-op */ }; | ||
| CGH.ext_oneapi_enqueue_native_command(Func); | ||
| }); | ||
| } | ||
|
|
||
| // A test that uses level_zero interop to copy data from buffer A to buffer B, | ||
| // by getting level_zero ptrs and calling the cuMemcpyWithAsync. Then run a SYCL | ||
| // kernel that modifies the data in place for B, e.g. increment one, then copy | ||
| // back to buffer A. Run it on a loop, to ensure the dependencies and the | ||
| // reference counting of the objects is not leaked. | ||
| void test_ht_kernel_dependencies(queue &Q) { | ||
| static constexpr int COUNT = 4; | ||
| buffer<int, 1> Buffer1{BUFFER_SIZE}; | ||
| buffer<int, 1> Buffer2{BUFFER_SIZE}; | ||
|
|
||
| // Init the buffer with a'priori invalid data. | ||
| init<int, -1, -2>(Buffer1, Buffer2, Q); | ||
|
|
||
| // Repeat a couple of times. | ||
| for (size_t Idx = 0; Idx < COUNT; ++Idx) { | ||
| copy(Buffer1, Buffer2, Q); | ||
| modify(Buffer2, Q); | ||
| copy(Buffer2, Buffer1, Q); | ||
| } | ||
|
|
||
| checkBufferValues(Buffer1, COUNT - 1); | ||
| checkBufferValues(Buffer2, COUNT - 1); | ||
| } | ||
|
|
||
| void tests(queue &Q) { | ||
| test_ht_buffer(Q); | ||
| test_ht_kernel_dependencies(Q); | ||
| } | ||
|
|
||
| int main() { | ||
| queue Q([](sycl::exception_list ExceptionList) { | ||
| if (ExceptionList.size() != 1) { | ||
| std::cerr << "Should be one exception in exception list" << std::endl; | ||
| std::abort(); | ||
| } | ||
| std::rethrow_exception(*ExceptionList.begin()); | ||
| }); | ||
| tests(Q); | ||
| std::cout << "Test PASSED" << std::endl; | ||
| return 0; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.