-
Notifications
You must be signed in to change notification settings - Fork 801
[SYCL] Use custom type to pass CGF around instead of std::function
#16668
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 all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -75,10 +75,8 @@ auto get_native(const SyclObjectT &Obj) | |||||
| namespace detail { | ||||||
| class queue_impl; | ||||||
|
|
||||||
| #if __SYCL_USE_FALLBACK_ASSERT | ||||||
| inline event submitAssertCapture(queue &, event &, queue *, | ||||||
| const detail::code_location &); | ||||||
| #endif | ||||||
|
|
||||||
| // Function to postprocess submitted command | ||||||
| // Arguments: | ||||||
|
|
@@ -375,8 +373,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> { | |||||
| std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event> submit( | ||||||
| T CGF, | ||||||
| const detail::code_location &CodeLoc = detail::code_location::current()) { | ||||||
| return submit_with_event( | ||||||
| sycl::ext::oneapi::experimental::empty_properties_t{}, CGF, | ||||||
| return submit_with_event<__SYCL_USE_FALLBACK_ASSERT>( | ||||||
| sycl::ext::oneapi::experimental::empty_properties_t{}, | ||||||
| detail::type_erased_cgfo_ty{CGF}, | ||||||
| /*SecondaryQueuePtr=*/nullptr, CodeLoc); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -395,9 +394,9 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> { | |||||
| std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event> submit( | ||||||
| T CGF, queue &SecondaryQueue, | ||||||
| const detail::code_location &CodeLoc = detail::code_location::current()) { | ||||||
| return submit_with_event( | ||||||
| sycl::ext::oneapi::experimental::empty_properties_t{}, CGF, | ||||||
| &SecondaryQueue, CodeLoc); | ||||||
| return submit_with_event<__SYCL_USE_FALLBACK_ASSERT>( | ||||||
| sycl::ext::oneapi::experimental::empty_properties_t{}, | ||||||
| detail::type_erased_cgfo_ty{CGF}, &SecondaryQueue, CodeLoc); | ||||||
| } | ||||||
|
|
||||||
| /// Prevents any commands submitted afterward to this queue from executing | ||||||
|
|
@@ -2786,6 +2785,7 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> { | |||||
|
|
||||||
| #ifndef __INTEL_PREVIEW_BREAKING_CHANGES | ||||||
| /// TODO: Unused. Remove these when ABI-break window is open. | ||||||
| /// Not using `type_erased_cgfo_ty` on purpose. | ||||||
| event submit_impl(std::function<void(handler &)> CGH, | ||||||
| const detail::code_location &CodeLoc); | ||||||
| event submit_impl(std::function<void(handler &)> CGH, | ||||||
|
|
@@ -2815,16 +2815,28 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> { | |||||
| std::function<void(handler &)> CGH, queue secondQueue, | ||||||
| const detail::code_location &CodeLoc, | ||||||
| const detail::SubmitPostProcessF &PostProcess, bool IsTopCodeLoc); | ||||||
|
|
||||||
| // Old version when `std::function` was used in place of | ||||||
| // `std::function<void(handler &)>`. | ||||||
| event submit_with_event_impl(std::function<void(handler &)> CGH, | ||||||
| const detail::SubmissionInfo &SubmitInfo, | ||||||
| const detail::code_location &CodeLoc, | ||||||
| bool IsTopCodeLoc); | ||||||
|
|
||||||
| void submit_without_event_impl(std::function<void(handler &)> CGH, | ||||||
| const detail::SubmissionInfo &SubmitInfo, | ||||||
| const detail::code_location &CodeLoc, | ||||||
| bool IsTopCodeLoc); | ||||||
| #endif // __INTEL_PREVIEW_BREAKING_CHANGES | ||||||
|
|
||||||
| /// A template-free versions of submit. | ||||||
| event submit_with_event_impl(std::function<void(handler &)> CGH, | ||||||
| event submit_with_event_impl(const detail::type_erased_cgfo_ty &CGH, | ||||||
| const detail::SubmissionInfo &SubmitInfo, | ||||||
| const detail::code_location &CodeLoc, | ||||||
| bool IsTopCodeLoc); | ||||||
|
|
||||||
| /// A template-free version of submit_without_event. | ||||||
| void submit_without_event_impl(std::function<void(handler &)> CGH, | ||||||
| void submit_without_event_impl(const detail::type_erased_cgfo_ty &CGH, | ||||||
| const detail::SubmissionInfo &SubmitInfo, | ||||||
| const detail::code_location &CodeLoc, | ||||||
| bool IsTopCodeLoc); | ||||||
|
|
@@ -2836,32 +2848,35 @@ class __SYCL_EXPORT queue : public detail::OwnerLessBase<queue> { | |||||
| /// \param CGF is a function object containing command group. | ||||||
| /// \param CodeLoc is the code location of the submit call (default argument) | ||||||
| /// \return a SYCL event object for the submitted command group. | ||||||
| template <typename T, typename PropertiesT> | ||||||
| std::enable_if_t<std::is_invocable_r_v<void, T, handler &>, event> | ||||||
| submit_with_event( | ||||||
| PropertiesT Props, T CGF, queue *SecondaryQueuePtr, | ||||||
| // | ||||||
| // UseFallBackAssert as template param vs `#if` in function body is necessary | ||||||
| // to prevent ODR-violation between TUs built with different fallback assert | ||||||
| // modes. | ||||||
|
||||||
| /// NOTE: Function is dependent to prevent the fallback kernels from | |
| /// materializing without the use of the function. |
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.
The "fallback kernel" in this case is not referring to fallback asserts. It's because the implementation of ext_oneapi_memcpy2d has a kernel it uses if the operation isn't natively supported, but we don't want that kernel to pop up unless the user calls ext_oneapi_memcpy2d in their code, so we make it dependent.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // RUN: %{build} -o %t.out | ||
| // RUN: %{run} %t.out | ||
|
|
||
| #include <sycl/detail/core.hpp> | ||
| #include <sycl/usm.hpp> | ||
|
|
||
| int *p = nullptr; | ||
|
|
||
| void foo(sycl::handler &cgh) { | ||
| auto *copy = p; | ||
| cgh.single_task([=]() { *copy = 42; }); | ||
| } | ||
|
|
||
| int main() { | ||
| sycl::queue q; | ||
| p = sycl::malloc_shared<int>(1, q); | ||
| *p = 0; | ||
| q.submit(foo).wait(); | ||
| assert(*p == 42); | ||
| sycl::free(p, q); | ||
| return 0; | ||
| } |
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.
When I first saw this I was wondering if we could use
std::invokableinstead, but I think that'd change the ABI, plus it might have the same too-much-templating problem asstd::functionThere 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 don't see how it's applicable here.
std::invokableis a concept, not a data type; so more likestd::is_invokable_rtrait that we are already using.