-
Notifications
You must be signed in to change notification settings - Fork 793
[SYCL] Build proper barrier deps if host task is involved in pipeline #13094
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 all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9f15ae2
Revert "[SYCL] Fix unused variable warnings (#12523)"
KseniyaTikhomirova 706fc20
Extend deps structure
KseniyaTikhomirova 3ab87d6
Adapt changes to current code base. Buils is failing due to producesP…
KseniyaTikhomirova ce69929
Fix build
KseniyaTikhomirova 280ccb4
fix braces
KseniyaTikhomirova e6fd2ad
Fix recursive mutex lock
KseniyaTikhomirova c79e215
fix clang-format
KseniyaTikhomirova 5625070
update linux symbols
KseniyaTikhomirova 4d6fb63
Merge branch 'sycl' into barrier_rebase
KseniyaTikhomirova 9080bcc
Merge branch 'sycl' into barrier_rebase
KseniyaTikhomirova 69c53e9
Draft
KseniyaTikhomirova 2640855
fix idea
KseniyaTikhomirova 6454bc4
Fix logic
KseniyaTikhomirova 81e295a
fix clang format
KseniyaTikhomirova 8c5dd95
Merge branch 'sycl' into barrier_rebase
KseniyaTikhomirova 45914f9
Cleanup
KseniyaTikhomirova 2b47556
Add unittests
KseniyaTikhomirova 1646766
add test for barrier with wait list
KseniyaTikhomirova 7590a5d
fix issue
KseniyaTikhomirova 2bee189
FIx clang-format
KseniyaTikhomirova d249da7
Merge branch 'sycl' into barrier_rebase
KseniyaTikhomirova df17b54
Update Win symbols
KseniyaTikhomirova aed5f81
Fix seg fault
KseniyaTikhomirova a9eb8a3
fix comments, part1
KseniyaTikhomirova 166ffd4
Merge branch 'sycl' into barrier_rebase
KseniyaTikhomirova cfb2ef0
fix comments, part 2
KseniyaTikhomirova 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -718,7 +718,7 @@ class queue_impl { | |
std::shared_ptr<ext::oneapi::experimental::detail::graph_impl> Graph) { | ||
std::lock_guard<std::mutex> Lock(MMutex); | ||
MGraph = Graph; | ||
MGraphLastEventPtr = nullptr; | ||
MExtGraphDeps.LastEventPtr = nullptr; | ||
} | ||
|
||
std::shared_ptr<ext::oneapi::experimental::detail::graph_impl> | ||
|
@@ -745,14 +745,27 @@ class queue_impl { | |
std::vector<event> &MutableVec, | ||
std::unique_lock<std::mutex> &QueueLock); | ||
|
||
// Helps to manage host tasks presence in scenario with barrier usage. | ||
// Approach that tracks almost all tasks to provide barrier sync for both pi | ||
// tasks and host tasks is applicable for out of order queues only. No-op | ||
// for in order ones. | ||
void tryToResetEnqueuedBarrierDep(const EventImplPtr &EnqueuedBarrierEvent); | ||
|
||
// Called on host task completion that could block some kernels from enqueue. | ||
// Approach that tracks almost all tasks to provide barrier sync for both pi | ||
// tasks and host tasks is applicable for out of order queues only. Not neede | ||
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. neede -> needed |
||
// for in order ones. | ||
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. Considering that the backend is not aware of host tasks, how in-order property is provided for host tasks? |
||
void revisitUnenqueuedCommandsState(const EventImplPtr &CompletedHostTask); | ||
|
||
protected: | ||
event discard_or_return(const event &Event); | ||
// Hook to the scheduler to clean up any fusion command held on destruction. | ||
void cleanup_fusion_cmd(); | ||
|
||
// template is needed for proper unit testing | ||
template <typename HandlerType = handler> | ||
void finalizeHandler(HandlerType &Handler, event &EventRet) { | ||
void finalizeHandler(HandlerType &Handler, const CG::CGTYPE &Type, | ||
event &EventRet) { | ||
if (MIsInorder) { | ||
// Accessing and changing of an event isn't atomic operation. | ||
// Hence, here is the lock for thread-safety. | ||
|
@@ -764,11 +777,11 @@ class queue_impl { | |
// by a host task. This dependency allows to build the enqueue order in | ||
// the RT but will not be passed to the backend. See getPIEvents in | ||
// Command. | ||
auto &EventToBuildDeps = | ||
MGraph.expired() ? MLastEventPtr : MGraphLastEventPtr; | ||
|
||
auto &EventToBuildDeps = MGraph.expired() ? MDefaultGraphDeps.LastEventPtr | ||
: MExtGraphDeps.LastEventPtr; | ||
if (EventToBuildDeps) | ||
Handler.depends_on( | ||
createSyclObjFromImpl<sycl::event>(EventToBuildDeps)); | ||
Handler.depends_on(EventToBuildDeps); | ||
|
||
// If there is an external event set, add it as a dependency and clear it. | ||
// We do not need to hold the lock as MLastEventMtx will ensure the last | ||
|
@@ -779,8 +792,31 @@ class queue_impl { | |
|
||
EventRet = Handler.finalize(); | ||
EventToBuildDeps = getSyclObjImpl(EventRet); | ||
} else | ||
} else { | ||
// The following code supports barrier synchronization if host task is | ||
// involved in the scenario. Native barriers cannot handle host task | ||
// dependency so in the case where some commands were not enqueued | ||
// (blocked), we track them to prevent barrier from being enqueued | ||
// earlier. | ||
std::lock_guard<std::mutex> Lock{MMutex}; | ||
auto &Deps = MGraph.expired() ? MDefaultGraphDeps : MExtGraphDeps; | ||
if (Type == CG::Barrier && !Deps.UnenqueuedCmdEvents.empty()) { | ||
Handler.depends_on(Deps.UnenqueuedCmdEvents); | ||
} | ||
if (Deps.LastBarrier) | ||
Handler.depends_on(Deps.LastBarrier); | ||
EventRet = Handler.finalize(); | ||
EventImplPtr EventRetImpl = getSyclObjImpl(EventRet); | ||
if (Type == CG::CodeplayHostTask) | ||
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl); | ||
else if (!EventRetImpl->isEnqueued()) { | ||
if (Type == CG::Barrier || Type == CG::BarrierWaitlist) { | ||
Deps.LastBarrier = EventRetImpl; | ||
Deps.UnenqueuedCmdEvents.clear(); | ||
} else | ||
Deps.UnenqueuedCmdEvents.push_back(EventRetImpl); | ||
} | ||
} | ||
} | ||
|
||
/// Performs command group submission to the queue. | ||
|
@@ -836,11 +872,11 @@ class queue_impl { | |
KernelUsesAssert = !(Handler.MKernel && Handler.MKernel->isInterop()) && | ||
ProgramManager::getInstance().kernelUsesAssert( | ||
Handler.MKernelName.c_str()); | ||
finalizeHandler(Handler, Event); | ||
finalizeHandler(Handler, Type, Event); | ||
|
||
(*PostProcess)(IsKernel, KernelUsesAssert, Event); | ||
} else | ||
finalizeHandler(Handler, Event); | ||
finalizeHandler(Handler, Type, Event); | ||
|
||
addEvent(Event); | ||
return Event; | ||
|
@@ -924,13 +960,16 @@ class queue_impl { | |
/// need to emulate it with multiple native in-order queues. | ||
bool MEmulateOOO = false; | ||
|
||
// This event is employed for enhanced dependency tracking with in-order queue | ||
// Access to the event should be guarded with MMutex | ||
EventImplPtr MLastEventPtr; | ||
// Same as above but for graph begin-end recording cycle. | ||
// Track deps within graph commands separately. | ||
// Protected by common queue object mutex MMutex. | ||
EventImplPtr MGraphLastEventPtr; | ||
// Access should be guarded with MMutex | ||
struct DependencyTrackingItems { | ||
// This event is employed for enhanced dependency tracking with in-order | ||
// queue | ||
EventImplPtr LastEventPtr; | ||
// The following two items are employed for proper out of order enqueue | ||
// ordering | ||
std::vector<EventImplPtr> UnenqueuedCmdEvents; | ||
EventImplPtr LastBarrier; | ||
} MDefaultGraphDeps, MExtGraphDeps; | ||
|
||
const bool MIsInorder; | ||
|
||
|
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
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.
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 seems to be a dead code.