Skip to content

[Bugfix][Layout] Add cuda_fp8.h include to fix __nv_fp8_e4m3 undefined - #439

Open
XFDG wants to merge 1 commit into
deepseek-ai:mainfrom
XFDG:fix/438-mega-mhc-fp8-include
Open

XFDG wants to merge 1 commit into
deepseek-ai:mainfrom
XFDG:fix/438-mega-mhc-fp8-include

Conversation

@XFDG

@XFDG XFDG commented Sep 11, 2026

Copy link
Copy Markdown

Summary

mega_mhc.cuh uses __nv_fp8_e4m3 in NormArgs, which is compiled by host g++ via csrc/python_api.cpp. CUTLASS gates cuda_fp8.h behind CUDA_FP8_ENABLED which requires __CUDACC_VER_* — defined only by nvcc, not g++ — so the type is invisible during host compilation.

Fix

Add #include <cuda_fp8.h> directly in mega_mhc.cuh before any other includes, so the type is visible to both nvcc and g++.

Testing

  • Built successfully with bash ./develop.sh on B200 (SM100, CUDA 13.1, gcc-13)
  • python3 -c "import deep_gemm; print(deep_gemm.__version__)" passes

Fixes #438

mega_mhc.cuh uses __nv_fp8_e4m3 in NormArgs, which is compiled by host
g++ via csrc/python_api.cpp. CUTLASS gates cuda_fp8.h behind
CUDA_FP8_ENABLED which requires __CUDACC_VER_* (nvcc-only), so the type
is invisible to g++. Add an explicit include to fix the build error.

Fixes deepseek-ai#438

Signed-off-by: zhaoye <yzhao04@iquestlab.com>
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Comment thread deep_gemm/include/deep_gemm/layout/mega_mhc.cuh
@ds-review-bot

Copy link
Copy Markdown
Collaborator

🤖 ds-review-bot Code Review

v6

直接包含 cuda_fp8.h 为主机编译提供了所需的 FP8 类型定义,符合项目 CUDA 版本要求,未发现该变更引入回归。当前环境缺少 CUDA 工具链,未实际验证构建。

v5

该 MR 在 deep_gemm/include/deep_gemm/layout/mega_mhc.cuh 顶部显式添加 #include &lt;cuda_fp8.h&gt;,修复主机端 g++ 编译 csrc/python_api.cpp 时 __nv_fp8_e4m3 未定义的问题。已核实包含链:python_api.cpp → apis/mega_mhc.hpp → jit_kernels/impls/sm100_mega_mhc.hpp → layout/mega_mhc.cuh,其中第 66 行 NormArgs::y_fp8 使用了 __nv_fp8_e4m3*。CUTLASS 的 cutlass/arch/barrier.h 依赖 CUDA_FP8_ENABLED(需 __CUDACC_VER_*,仅 nvcc 定义)才会间接引入 cuda_fp8.h,因此主机编译下该类型确实不可见。修复方式正确、最小、无副作用:cuda_fp8.h 自带 include guard,对 nvcc 路径无影响,且自 CUDA 11.8 起提供,与 SM100/CUDA 13 环境兼容。变更仅 2 行、1 个文件,与描述一致。建议合并。

v4

This MR adds an explicit #include &lt;cuda_fp8.h&gt; at the top of deep_gemm/include/deep_gemm/layout/mega_mhc.cuh, placed directly after #pragma once and before the CUTLASS/DeepGEMM includes. The header is pulled into host (g++) translation units such as csrc/jit_kernels/impls/sm100_mega_mhc.hpp, where NormArgs::y_fp8 is declared as __nv_fp8_e4m3*. CUTLASS only includes &lt;cuda_fp8.h&gt; when CUDA_FP8_ENABLED is defined, and that macro requires __CUDACC_VER_* (nvcc-only), so the type was invisible during host compilation and the build failed with __nv_fp8_e4m3 undefined. The fix is minimal, correct, and sufficient: it makes the type visible to both nvcc and g++, while being harmless for device builds because cuda_fp8.h has its own include guards. The nv_bfloat16 type used in the same struct already remains available unconditionally through cutlass/bfloat16.h -> &lt;cuda_bf16.h&gt;, so no additional include is needed, and placing this include before the CUTLASS headers avoids any include-ordering dependency.

Review outcome: approved. No defects, regressions, or required changes were identified.

Files reviewed: 1
Issues found: 🔵 1 suggestion
Inline comments posted: 1

@XFDG

XFDG commented Sep 16, 2026

Copy link
Copy Markdown
Author

Resolved the remaining bot thread after rechecking it: the comment explicitly marks the repository-wide header scan as optional and out of scope for this focused fix. The PR remains the minimal one-header correction, and the bot review found no regression. No code change was needed.

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.

Build fails with __nv_fp8_e4m3 undefined (CUDA 12.9, H100 and B200)

2 participants