-
Notifications
You must be signed in to change notification settings - Fork 842
[SYCL] Native host task submission without thread pool. #22518
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
base: sycl
Are you sure you want to change the base?
Changes from all commits
643e97e
da2129c
f74afae
b420295
e8da167
061df77
7c67b4d
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,32 +24,16 @@ inline namespace _V1 { | |||||||||
| class interop_handle; | ||||||||||
| namespace detail { | ||||||||||
| class HostTask { | ||||||||||
| enum class HostTaskOrigin { | ||||||||||
| SYCLCoreAPI, | ||||||||||
| ExtEnqueueFunctionsAPI, | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| std::function<void()> MHostTask; | ||||||||||
| std::function<void(interop_handle)> MInteropTask; | ||||||||||
| HostTaskOrigin MOrigin; | ||||||||||
|
|
||||||||||
| public: | ||||||||||
| HostTask() : MHostTask([]() {}), MOrigin(HostTaskOrigin::SYCLCoreAPI) {} | ||||||||||
| HostTask(std::function<void()> &&Func, | ||||||||||
| bool IsFromExtEnqueueFunctionsAPI = false) | ||||||||||
| : MHostTask(std::move(Func)), | ||||||||||
| MOrigin(IsFromExtEnqueueFunctionsAPI | ||||||||||
| ? HostTaskOrigin::ExtEnqueueFunctionsAPI | ||||||||||
| : HostTaskOrigin::SYCLCoreAPI) {} | ||||||||||
| HostTask(std::function<void(interop_handle)> &&Func) | ||||||||||
| : MInteropTask(std::move(Func)), MOrigin(HostTaskOrigin::SYCLCoreAPI) {} | ||||||||||
| HostTask() : MHostTask([]() {}) {} | ||||||||||
| HostTask(std::function<void()> &&Func) : MHostTask(Func) {} | ||||||||||
| HostTask(std::function<void(interop_handle)> &&Func) : MInteropTask(Func) {} | ||||||||||
|
Comment on lines
+31
to
+33
Comment on lines
+32
to
+33
Collaborator
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. 🟡 Important: Both constructors accept rvalue references (
Suggested change
|
||||||||||
|
|
||||||||||
| bool isInteropTask() const { return !!MInteropTask; } | ||||||||||
|
|
||||||||||
| bool isCreatedFromEnqueueFunction() const { | ||||||||||
| return MOrigin == HostTaskOrigin::ExtEnqueueFunctionsAPI; | ||||||||||
| } | ||||||||||
|
|
||||||||||
| void call(HostProfilingInfo *HPI) { | ||||||||||
| if (!GlobalHandler::instance().isOkToDefer()) { | ||||||||||
| return; | ||||||||||
|
|
||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -128,6 +128,11 @@ class Command { | |||||
| ur_exp_command_buffer_handle_t CommandBuffer = nullptr, | ||||||
| const std::vector<ur_exp_command_buffer_sync_point_t> &SyncPoints = {}); | ||||||
|
|
||||||
| Command( | ||||||
| CommandType Type, queue_impl *Queue, EventImplPtr Event, | ||||||
| ur_exp_command_buffer_handle_t CommandBuffer = nullptr, | ||||||
| const std::vector<ur_exp_command_buffer_sync_point_t> &SyncPoints = {}); | ||||||
|
|
||||||
| /// \param NewDep dependency to be added | ||||||
| /// \param ToCleanUp container for commands that can be cleaned up. | ||||||
| /// \return an optional connection cmd to enqueue | ||||||
|
|
@@ -666,6 +671,8 @@ class ExecCGCommand : public Command { | |||||
|
|
||||||
| AllocaCommandBase *getAllocaForReq(Requirement *Req); | ||||||
|
|
||||||
| EventImplPtr makeEvent(const detail::CG &CG, queue_impl *Queue); | ||||||
|
Collaborator
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. 🟡 Important:
This is technically safe only because
Suggested change
The corresponding definition in |
||||||
|
|
||||||
| std::unique_ptr<detail::CG> MCommandGroup; | ||||||
|
|
||||||
| friend class Command; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -122,7 +122,8 @@ EventImplPtr Scheduler::addCG( | |||||||||||||||||||
| NewCmd = | ||||||||||||||||||||
| MGraphBuilder.addCGUpdateHost(std::move(CommandGroup), AuxiliaryCmds); | ||||||||||||||||||||
| break; | ||||||||||||||||||||
| case CGType::CodeplayHostTask: { | ||||||||||||||||||||
| case CGType::CodeplayHostTask: | ||||||||||||||||||||
| case CGType::NativeHostTask: { | ||||||||||||||||||||
| NewCmd = MGraphBuilder.addCG(std::move(CommandGroup), nullptr, | ||||||||||||||||||||
| AuxiliaryCmds, EventNeeded); | ||||||||||||||||||||
| break; | ||||||||||||||||||||
|
|
@@ -199,6 +200,8 @@ void Scheduler::enqueueCommandForCG(event_impl &Event, | |||||||||||||||||||
| sycl::exception( | ||||||||||||||||||||
| sycl::make_error_code(errc::runtime), | ||||||||||||||||||||
| std::string("Enqueue process failed.\n") + | ||||||||||||||||||||
| // TODO native host tasks - getWorkerContext() will return | ||||||||||||||||||||
| // nullptr for native host task | ||||||||||||||||||||
| __SYCL_UR_ERROR_REPORT( | ||||||||||||||||||||
| NewCmd->getWorkerContext()->getBackend()) + | ||||||||||||||||||||
|
Comment on lines
+203
to
206
Collaborator
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. 🔴 Critical: Guaranteed null dereference on NativeHostTask enqueue failure The TODO comment on lines 203-204 explicitly documents that The fix should guard the
Suggested change
Alternatively, give |
||||||||||||||||||||
| sycl::detail::codeToString(Res.MErrCode)), | ||||||||||||||||||||
|
|
||||||||||||||||||||
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.
🔵 Suggestion: Document the intentional fallthrough
NativeHostTaskfalls through silently toNoneand returnsnullptr. This is correct — native host tasks cannot be recorded in a graph node (the exception is thrown earlier inhandler::finalize) — but the silent fallthrough may confuse future readers. A brief[[fallthrough]]with a comment (or a separatereturn nullptrwith an explanation) would make the intent clear: