Skip to content

Fix NVRTC compilation for HyperConnection kernels - #376

Open
nya-a-cat wants to merge 1 commit into
deepseek-ai:mainfrom
nya-a-cat:agent/fix-nvrtc-hc-pdl-header
Open

Fix NVRTC compilation for HyperConnection kernels#376
nya-a-cat wants to merge 1 commit into
deepseek-ai:mainfrom
nya-a-cat:agent/fix-nvrtc-hc-pdl-header

Conversation

@nya-a-cat

Copy link
Copy Markdown

Summary

  • Include <cuda_device_runtime_api.h> in the SM90 and SM100 HyperConnection pre-norm GEMM kernels.
  • Make the cudaGridDependencySynchronize() declaration available to the NVRTC compilation path.

Root cause

Both HyperConnection kernels call the Programmatic Dependent Launch synchronization intrinsic. With DG_JIT_USE_NVRTC=1, the current include chain does not expose its device-runtime declaration, so NVRTC fails with:

identifier "cudaGridDependencySynchronize" is undefined

NVCC provides the declaration implicitly in this path, which is why the failure is NVRTC-specific.

Impact

This restores NVRTC compilation for both SM90 and SM100 HyperConnection kernels. It does not change kernel logic, synchronization behavior, or launch configuration.

Validation

  • CUDA 12.9.1 NVRTC compile-only regression:
    • Before the fix: SM90 compilation fails with the undefined identifier above.
    • After the fix: the SM90 and SM100 header instantiations compile successfully.
  • git diff --check origin/main...HEAD

GPU runtime validation was not performed because the Actions runner did not have an NVIDIA GPU.

Fixes #359

@nya-a-cat
nya-a-cat marked this pull request as ready for review July 11, 2026 07:16
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-attributes"

#include <cuda_device_runtime_api.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 warning: Unconditional, outside-guard placement (same at sm100_tf32_hc_prenorm_gemm.cuh:5). The only reference is at sm90:122 / sm100:139 inside #if (defined(__CUDA_ARCH__) and (__CUDA_ARCH__ >= ...)) ... or defined(__CLION_IDE__), and NVCC already provides the decl only on the device pass. This header is device-runtime-only and is also pulled into host/prebuilt/clang-cuda compilation of the same .cuh. Recommend moving/guarding it consistently (e.g. behind __CUDACC_RTC__/__CUDA_ARCH__, or use a minimal extern "C" cudaError_t cudaGridDependencySynchronize(void); prototype guarded by __CUDACC_RTC__) to avoid fragile/version-dependent effects on the other build paths.

🤖 v4

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-attributes"

#include <cuda_device_runtime_api.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 warning: Validation/scope. The original failure was NVRTC-specific, but the fix is unconditional and is now compiled by the NVCC/clang host/prebuilt and the non-NVRTC device paths as well. The PR only ran NVRTC compile-only regressions and git diff --check, so a green NVRTC compile does not prove those other compiler configurations still compile/link, nor that device behavior is unchanged. A full build (NVCC/clang/prebuilt) and, if possible, a GPU run should be done before merge.

🤖 v4

@ds-review-bot

Copy link
Copy Markdown
Collaborator

🤖 ds-review-bot Code Review

v4

The patch re-enables NVRTC (DG_JIT_USE_NVRTC=1) compilation of the SM90/SM100 HyperConnection pre-norm GEMM kernels by adding #include <cuda_device_runtime_api.h> to both kernel headers, which exposes the cudaGridDependencySynchronize() PDL device-runtime declaration that NVCC supplies implicitly but NVRTC does not. It is minimal, touches only the two affected files, and by inspection does not change kernel logic/sync/launch. The main concern is that the include is placed unconditionally at file scope, outside the device/__CUDACC_RTC__/__CLION_IDE__ guard that surrounds the actual PDL call and the rest of the kernel body; the same .cuh is also parsed by the host/prebuilt/NVCC/clang-cuda compilation paths (through indexing/main.cu and the JIT pipeline), which neither need nor generally expect a device-runtime-only toolkit header. The patch was validated only via NVRTC compile-only regressions, so the effect on those other compiler configurations is unverified. Recommendation: guard/place the include consistently (or use a __CUDACC_RTC__-guarded minimal prototype) and re-run a full build (NVCC/clang/prebuilt) plus a GPU run before merge.

v3

This PR adds #include <cuda_device_runtime_api.h> to the two HyperConnection TF32 pre-norm GEMM kernels (sm90_tf32_hc_prenorm_gemm.cuh:5 and sm100_tf32_hc_prenorm_gemm.cuh:5) so that the cudaGridDependencySynchronize() intrinsic declaration is available on the NVRTC compilation path (DG_JIT_USE_NVRTC=1). The change is correct and minimal: both kernels call cudaGridDependencySynchronize() (sm90 line 122, sm100 line 139), an intrinsic declared in <cuda_device_runtime_api.h> that NVCC pulls in implicitly but NVRTC does not, causing the reported 'identifier cudaGridDependencySynchronize is undefined' failure. The include is placed at the top of the include block before the CUTLASS/deep_gemm headers, which is appropriate. No kernel logic, synchronization behavior, or launch configuration is altered. The scope (2 files) matches the PR description and the affected HyperConnection kernels. The root-cause analysis and fix are sound; the NVRTC compile-only CI validation is a reasonable substitute given no GPU runner was available. No blocking issues found. Non-blocking observation: several other kernels use the same intrinsic without this include (e.g. sm90_bf16_gemm.cuh, smxx_layout.cuh, sm100_bmk_bnk_mn.cuh), so they may hit the same NVRTC failure, but that is outside this PR's stated HyperConnection scope and does not affect approval of this change.

Files reviewed: 2
Issues found: 🟡 2 warning
Inline comments posted: 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] NVRTC build fails for sm90_tf32_hc_prenorm_gemmcudaGridDependencySynchronize undefined (PDL intrinsic not available under NVRTC)

2 participants