Repository navigation
[https://nvbugs/6646568][chore] Make DeepGEMM in-kernel barrier timeout configurable #18179
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
longlee0622
merged 1 commit into
NVIDIA:main
from
longlee0622:fix/deepgemm-barrier-timeout-6646568
Sep 3, 2026
+120
−1
Merged
Changes from all commits
Commits
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
82 changes: 82 additions & 0 deletions
82
3rdparty/patches/deepgemm_configurable_barrier_timeout.patch
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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --- a/csrc/jit/compiler.hpp | ||
| +++ b/csrc/jit/compiler.hpp | ||
| @@ -56,12 +56,18 @@ public: | ||
| "--ptxas-options=--register-usage-level=10", | ||
| get_env<int>("DG_JIT_CPP_STANDARD", 20)); | ||
| if (get_env("DG_JIT_DEBUG", 0) or get_env("DG_JIT_PTXAS_VERBOSE", 0) or get_env("DG_JIT_PTXAS_CHECK", 0)) | ||
| flags += " --ptxas-options=--verbose,--warn-on-local-memory-usage"; | ||
| if (get_env("DG_JIT_WITH_LINEINFO", 0)) | ||
| flags += " -Xcompiler -rdynamic -lineinfo"; | ||
| + | ||
| + // Allow overriding the in-kernel barrier timeout, see `comm/barrier.cuh` | ||
| + // NOTES: `flags` is part of the kernel signature, so changing this value | ||
| + // naturally invalidates the JIT cache | ||
| + if (const auto barrier_timeout_seconds = get_env("DG_JIT_BARRIER_TIMEOUT_SECONDS", 0); barrier_timeout_seconds > 0) | ||
| + flags += fmt::format(" -DDG_BARRIER_TIMEOUT_SECONDS={}", barrier_timeout_seconds); | ||
| } | ||
|
|
||
| virtual ~Compiler() = default; | ||
|
|
||
| std::filesystem::path make_tmp_dir() const { | ||
| return make_dirs(cache_dir_path / "tmp"); | ||
| --- a/deep_gemm/include/deep_gemm/comm/barrier.cuh | ||
| +++ b/deep_gemm/include/deep_gemm/comm/barrier.cuh | ||
| @@ -5,14 +5,22 @@ | ||
| #include <deep_gemm/ptx/ld_st.cuh> | ||
| #include <deep_gemm/layout/sym_buffer.cuh> | ||
| #include <deep_gemm/layout/mega_moe.cuh> | ||
|
|
||
| namespace deep_gemm::comm { | ||
|
|
||
| -// 60s timeout, at 2 GHz | ||
| -constexpr int64_t kNumTimeoutCycles = 60ll * 2000000000ll; | ||
| +// Barrier timeout in seconds, overridable at JIT compile time. The host-side compiler | ||
| +// turns the `DG_JIT_BARRIER_TIMEOUT_SECONDS` environment variable into this definition, | ||
| +// so slow-but-healthy rendezvous (e.g. large expert-parallel groups whose first | ||
| +// collective follows a long warm-up) can be distinguished from a genuine hang. | ||
| +#ifndef DG_BARRIER_TIMEOUT_SECONDS | ||
| +#define DG_BARRIER_TIMEOUT_SECONDS 60 | ||
| +#endif | ||
| + | ||
| +// Timeout in cycles, at 2 GHz | ||
| +constexpr int64_t kNumTimeoutCycles = static_cast<int64_t>(DG_BARRIER_TIMEOUT_SECONDS) * 2000000000ll; | ||
|
longlee0622 marked this conversation as resolved.
Resolved
|
||
|
|
||
| CUTLASS_DEVICE void cluster_sync_with_relaxed_arrive() { | ||
| // Perform cluster_sync with `barrier.cluster.arrive.relaxed` | ||
| // This is slightly faster than `cute::cluster_sync` but has weaker memory ordering guarantee | ||
| cute::cluster_arrive_relaxed(); | ||
| cute::cluster_wait(); | ||
| @@ -31,14 +39,14 @@ CUTLASS_DEVICE void grid_sync(const layout::Workspace& workspace, | ||
| count_ptr, sm_idx == 0 ? (kFinishSumTag - (kNumSMs - 1)) : 1); | ||
| uint32_t new_value; | ||
| const auto start_clock = clock64(); | ||
| do { | ||
| new_value = ptx::ld_acq(count_ptr); | ||
| if (clock64() - start_clock >= kNumTimeoutCycles) { | ||
| - printf("DeepGEMM grid sync timeout: sm=%u, thread=%u, grid_sync_idx=%u, old=%u, current=%u, expected_tag=%u\n", | ||
| - sm_idx, thread_idx, kGridSyncIndex, old_value, new_value, old_value ^ kFinishSumTag); | ||
| + printf("DeepGEMM grid sync timeout (%ds): sm=%u, thread=%u, grid_sync_idx=%u, old=%u, current=%u, expected_tag=%u\n", | ||
| + DG_BARRIER_TIMEOUT_SECONDS, sm_idx, thread_idx, kGridSyncIndex, old_value, new_value, old_value ^ kFinishSumTag); | ||
| DG_DEVICE_ASSERT(false and "Grid sync timeout"); | ||
| } | ||
| } while (((new_value ^ old_value) & kFinishSumTag) == 0); | ||
| } | ||
| sync_scope(); | ||
| } | ||
| @@ -72,14 +80,14 @@ CUTLASS_DEVICE void nvlink_barrier(const layout::Workspace& workspace, | ||
| if (thread_idx == 0) { | ||
| ptx::red_add(counter_ptr, 1); | ||
| const int target = signal_sign ? 0 : static_cast<int>(kNumRanks); | ||
| const auto start_clock = clock64(); | ||
| while (ptx::ld_acq_sys(signal_ptr) != target) { | ||
| if (clock64() - start_clock >= kNumTimeoutCycles) { | ||
| - printf("DeepGEMM NVLink barrier timeout: rank=%d, counter=%d, signal=%d, target=%d, phase=%d, sign=%d, tag=%d\n", | ||
| - sym_buffer.rank_idx, *counter_ptr, ptx::ld_acq_sys(signal_ptr), target, signal_phase, signal_sign, kTag); | ||
| + printf("DeepGEMM NVLink barrier timeout (%ds): rank=%d, counter=%d, signal=%d, target=%d, phase=%d, sign=%d, tag=%d\n", | ||
| + DG_BARRIER_TIMEOUT_SECONDS, sym_buffer.rank_idx, *counter_ptr, ptx::ld_acq_sys(signal_ptr), target, signal_phase, signal_sign, kTag); | ||
| DG_DEVICE_ASSERT(false and "NVLink barrier timeout"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.