-
Notifications
You must be signed in to change notification settings - Fork 30
[codex] fix Cube kernel hang in generated C++ #443
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: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -253,7 +253,7 @@ SmallVector<bool> SyncEventIdAllocation::GetEventPool(const SyncOperation *sync, | |
| return eventIdPool; | ||
| } | ||
|
|
||
| int SyncEventIdAllocation::ScopePair(const SyncOperation *s) { | ||
| int SyncEventIdAllocation::ScopePair(const SyncOperation *s) const { | ||
| if (s->GetType() == SyncOperation::TYPE::SYNC_BLOCK_SET || | ||
| s->GetType() == SyncOperation::TYPE::SYNC_BLOCK_WAIT) { | ||
| return 0; | ||
|
|
@@ -480,11 +480,37 @@ void SyncEventIdAllocation::WidenEventId(SyncOps syncVector) { | |
| bool canWiden = TryWidenByOtherSync(sync); | ||
| if (!canWiden) { | ||
| int scopePair = ScopePair(sync); | ||
| reallocatedPipePair.insert(scopePair); | ||
| // Loop-carried syncs need a fully initialized head/tail schedule. | ||
| // Reallocating an entire scope that already contains back-edge pairs can | ||
| // rewrite those safe preheat/drain edges into mismatched waits. | ||
| if (!scopePairHasLoopCarriedSync(scopePair)) | ||
| reallocatedPipePair.insert(scopePair); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bool SyncEventIdAllocation::scopePairHasLoopCarriedSync(int scopePair) const { | ||
| for (auto &element : syncIR_) { | ||
| for (auto *sync : element->pipeBefore) { | ||
| if (!sync || sync->uselessSync) | ||
| continue; | ||
| if (!sync->GetForEndIndex().has_value()) | ||
| continue; | ||
| if (ScopePair(sync) == scopePair) | ||
| return true; | ||
| } | ||
| for (auto *sync : element->pipeAfter) { | ||
| if (!sync || sync->uselessSync) | ||
| continue; | ||
| if (!sync->GetForEndIndex().has_value()) | ||
| continue; | ||
| if (ScopePair(sync) == scopePair) | ||
| return true; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
Comment on lines
+493
to
+513
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. The Consider pre-calculating the set of scope pairs that contain loop-carried syncs once at the beginning of the |
||
|
|
||
| void SyncEventIdAllocation::clearAllocatedEventId() { | ||
| // Remove generated BackwardSync | ||
|
|
||
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 guard skips
reallocatedPipePairfor the entire(src,dst)scope as soon as any loop-carried sync exists in that scope, so unrelated non-loopSET_EVENTsyncs in the same pipe pair can no longer use the reallocation path when they run out of IDs. In that case they fall through toChangeNoEventIdSyncToPipeAlland are downgraded toPIPE_ALL, which serializes execution globally and can cause major performance regressions for mixed loop/non-loop kernels that previously stayed on event-based sync.Useful? React with 👍 / 👎.