-
Notifications
You must be signed in to change notification settings - Fork 802
[Draft] Host task extensions #12921
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
[Draft] Host task extensions #12921
Changes from all commits
dd9e892
3177d1b
349b7ef
c7339e6
5963c3a
a096384
f2bc24b
eb44344
c98acc2
94301c8
0fc0e28
8a2ff6b
c0815f2
a3d0af6
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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| //==-------- host_task_properties.hpp --- SYCL host task properties --------==// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <sycl/context.hpp> | ||
| #include <sycl/detail/property_helper.hpp> | ||
| #include <sycl/properties/property_traits.hpp> | ||
|
|
||
| namespace sycl { | ||
| inline namespace _V1 { | ||
| namespace ext::codeplay::experimental::property::host_task { | ||
|
|
||
| class manual_interop_sync : public ::sycl::detail::DataLessProperty< | ||
| ::sycl::detail::HostTaskManualInteropSync> {}; | ||
|
|
||
| } // namespace ext::codeplay::experimental::property::host_task | ||
|
|
||
| // Forward declaration | ||
| class host_task; | ||
|
|
||
| template <> | ||
| struct is_property< | ||
| ext::codeplay::experimental::property::host_task::manual_interop_sync> | ||
| : std::true_type {}; | ||
|
|
||
| template <> | ||
| struct is_property_of< | ||
| ext::codeplay::experimental::property::host_task::manual_interop_sync, | ||
| host_task> : std::true_type {}; | ||
|
|
||
| } // namespace _V1 | ||
| } // namespace sycl |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,11 @@ class DispatchHostTask; | |
| class queue_impl; | ||
| class device_impl; | ||
| class context_impl; | ||
|
|
||
| // Needed for get_native_events to check if backend_return_t<Backend, event> is | ||
| // a vector | ||
| template <typename T> struct is_std_vector : std::false_type {}; | ||
| template <typename T> struct is_std_vector<std::vector<T>> : std::true_type {}; | ||
| } // namespace detail | ||
|
|
||
| class queue; | ||
|
|
@@ -182,6 +187,66 @@ class interop_handle { | |
| #endif | ||
| } | ||
|
|
||
| // Adds events from the native API so that the SYCL runtime can integrate the | ||
| // async calls in a native API, with other async operations in the SYCL DAG. | ||
| // Using this function removes the requirement that a host task callable must | ||
| // synchronize with any asynchronous operations from within the callable. | ||
| template <backend Backend = backend::opencl> | ||
| void add_native_events(backend_return_t<Backend, event> NativeEvents) { | ||
|
||
| #ifndef __SYCL_DEVICE_ONLY__ | ||
| // TODO: replace the exception thrown below with the SYCL 2020 exception | ||
| // with the error code 'errc::backend_mismatch' when those new exceptions | ||
| // are ready to be used. | ||
| if (Backend != get_backend()) | ||
| throw invalid_object_error("Incorrect backend argument was passed", | ||
| PI_ERROR_INVALID_MEM_OBJECT); | ||
| // All native events can be cast to void*, we use this as a generic entry | ||
| // point to source library | ||
| std::vector<pi_native_handle> NativeEventHolders(NativeEvents.size()); | ||
| for (auto i = 0; i < NativeEvents.size(); ++i) | ||
| NativeEventHolders[i] = | ||
| reinterpret_cast<pi_native_handle>(NativeEvents[i]); | ||
| return addNativeEvents(NativeEventHolders); | ||
| #else | ||
| // we believe this won't be ever called on device side | ||
| return; | ||
| #endif | ||
| } | ||
|
|
||
| // Gets all the native events that the host task depends on, and that are | ||
| // still active | ||
| template <backend Backend = backend::opencl> | ||
| backend_return_t<Backend, event> get_native_events() { | ||
|
||
| #ifndef __SYCL_DEVICE_ONLY__ | ||
| // TODO: replace the exception thrown below with the SYCL 2020 exception | ||
| // with the error code 'errc::backend_mismatch' when those new exceptions | ||
| // are ready to be used. | ||
| if (Backend != get_backend()) | ||
| throw invalid_object_error("Incorrect backend argument was passed", | ||
| PI_ERROR_INVALID_MEM_OBJECT); | ||
| // All native events can be cast to void*, we use this as a generic entry | ||
| // point to source library | ||
| std::vector<pi_native_handle> NativeEventHolders = getNativeEvents(); | ||
| backend_return_t<Backend, event> | ||
| RetNativeEvents; // This may be a vector of native events or a single | ||
| // native event, depending on the backend | ||
| if constexpr (detail::is_std_vector< | ||
| backend_return_t<Backend, event>>::value) { | ||
| using ValueT = typename backend_return_t<Backend, event>::value_type; | ||
| for (auto i = 0; i < NativeEventHolders.size(); ++i) | ||
| RetNativeEvents.push_back( | ||
| reinterpret_cast<ValueT>(NativeEventHolders[i])); | ||
| } else { | ||
| RetNativeEvents = reinterpret_cast<backend_return_t<Backend, event>>( | ||
| NativeEventHolders[0]); | ||
| } | ||
| return RetNativeEvents; | ||
| #else | ||
| // we believe this won't be ever called on device side | ||
| return {}; | ||
| #endif | ||
| } | ||
|
|
||
| private: | ||
| friend class detail::ExecCGCommand; | ||
| friend class detail::DispatchHostTask; | ||
|
|
@@ -190,8 +255,9 @@ class interop_handle { | |
| interop_handle(std::vector<ReqToMem> MemObjs, | ||
| const std::shared_ptr<detail::queue_impl> &Queue, | ||
| const std::shared_ptr<detail::device_impl> &Device, | ||
| const std::shared_ptr<detail::context_impl> &Context) | ||
| : MQueue(Queue), MDevice(Device), MContext(Context), | ||
| const std::shared_ptr<detail::context_impl> &Context, | ||
| const std::shared_ptr<detail::event_impl> &Event) | ||
| : MQueue(Queue), MDevice(Device), MContext(Context), MEvent(Event), | ||
| MMemObjs(std::move(MemObjs)) {} | ||
|
|
||
| template <backend Backend, typename DataT, int Dims> | ||
|
|
@@ -215,10 +281,13 @@ class interop_handle { | |
| getNativeQueue(int32_t &NativeHandleDesc) const; | ||
| __SYCL_EXPORT pi_native_handle getNativeDevice() const; | ||
| __SYCL_EXPORT pi_native_handle getNativeContext() const; | ||
| __SYCL_EXPORT void addNativeEvents(std::vector<pi_native_handle> &); | ||
| __SYCL_EXPORT std::vector<pi_native_handle> getNativeEvents() const; | ||
|
|
||
| std::shared_ptr<detail::queue_impl> MQueue; | ||
| std::shared_ptr<detail::device_impl> MDevice; | ||
| std::shared_ptr<detail::context_impl> MContext; | ||
| std::shared_ptr<detail::event_impl> MEvent; | ||
|
|
||
| std::vector<ReqToMem> MMemObjs; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,14 +99,8 @@ if(SYCL_PI_UR_USE_FETCH_CONTENT) | |
| CACHE PATH "Path to external '${name}' adapter source dir" FORCE) | ||
| endfunction() | ||
|
|
||
| set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git") | ||
| # commit 1e9b1b493fe30e6236bf611ae6d82366c9376f6c | ||
| # Merge: a011f092 d8500a36 | ||
| # Author: Kenneth Benzie (Benie) <[email protected]> | ||
| # Date: Fri Jun 21 10:22:52 2024 +0100 | ||
| # Merge pull request #805 from aarongreig/aaron/kernelSetArgIndirectionFix | ||
| # Correct level of indirection used in KernelSetArgPointer calls. | ||
| set(UNIFIED_RUNTIME_TAG 1e9b1b493fe30e6236bf611ae6d82366c9376f6c) | ||
| set(UNIFIED_RUNTIME_REPO "https://github.com/hdelan/unified-runtime.git") | ||
| set(UNIFIED_RUNTIME_TAG interop-event-check) | ||
|
|
||
| fetch_adapter_source(level_zero | ||
| ${UNIFIED_RUNTIME_REPO} | ||
|
|
||
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 member function is named
ext_oneapi_add_native_eventsin the extension.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.
I think we should remove the default backend so the user must always specify which backend they are targeting.
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.
Good idea RE default backend. Will change