Skip to content

M100 fp32 only regen - #79746

Open
ZhangX-21 wants to merge 13 commits into
PaddlePaddle:developfrom
ZhangX-21:m100_fp32_only_regen
Open

M100 fp32 only regen#79746
ZhangX-21 wants to merge 13 commits into
PaddlePaddle:developfrom
ZhangX-21:m100_fp32_only_regen

Conversation

@ZhangX-21

Copy link
Copy Markdown
Contributor

PR Category

PR Types

Description

是否引起精度变化

RobertLuobo and others added 13 commits March 20, 2026 11:22
This commit adapts the PaddlePaddle build to work with the xtrans
custom CUDA backend (xtrans_cuda_11.7_ubuntu2004_x86_64_mars) which
does not support standard cuDNN or some cuBLAS interfaces.

Key changes:
- cmake: disable WITH_CUTLASS, add clang-rt builtins link, fix
  cudnn/cublas detection for xtrans backend
- backends/dynload: remove unsupported cuBLAS axpy/scal/copy entries;
  wrap cudnn.cc body in WITH_CUDNN_FRONTEND guard
- backends/gpu: add stub InitDnnHandle/DestroyDnnHandle/DnnVersion when
  WITH_CUDNN_FRONTEND is not set; fix forwards.h / gpu_decls.h guards
- resource_manager: restore full implementation, keep cuDNN calls
  commented out
- fuse_bn_act_pass / fuse_bn_add_act_pass: add stub ApplyImpl +
  REGISTER_PASS so USE_PASS() links correctly without cuDNN
- matmul_kernel.cu: restore with int8_t registration + CudaGemm<int8_t>
  stub; cuda_gemm_kernel.cu disabled (renamed .md)
- softmax.cu / cross_entropy.cu: restored with Eigen/CUDA-only paths,
  cuDNN paths removed
- 70+ kernel files renamed to *.md to skip cuDNN/cuBLAS-dependent
  operators during build (batch_norm, conv, layer_norm, softmax, etc.)
- .gitignore: add xtrans compiler intermediate file patterns

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
[XPU] Adaptation for cuDNN
… fixing

the logical operator in the XPU header guard in xpudnn.h.
Introduces a WITH_XPU_CADA build option that lets CINN's existing
CUDA codegen/NVRTC/runtime path target Baidu KUNLUN M100 through
xtrans, a CUDA/NVRTC/Driver-API compatible toolchain, instead of
requiring a real NVIDIA CUDA install.

Key changes:
- CMakeLists.txt / cmake/cinn.cmake / cmake/cinn/*.cmake: new
  WITH_XPU_CADA option, xtrans toolchain root/library discovery
  (XTRANS_ROOT), and isolation of the handful of spots where xtrans's
  layout differs from a stock NVIDIA CUDA install (no lib64/stubs,
  0-byte NVTX stub, cusolver->cusparse link dependency, etc).
- paddle/cinn/backends/cuda_util.h, paddle/cinn/runtime/cuda/cuda_util.cc,
  paddle/phi/backends/dynload/cudnn.h: CINN's cudnn calls are ported to
  phi's existing dynload/lazy-dlopen wrapper instead of link-time
  linking libcudnn.so. This avoids pulling xtrans's own libLLVM-15.so
  (a transitive dependency of xtrans's libcudnn.so) into any process
  that also links CINN's statically-linked LLVM 12, which otherwise
  collides at the global llvm::cl::opt registry and aborts at startup
  (hit in eager_generator).
- paddle/cinn/backends/nvrtc/header_generator.cc: skip injecting
  jitify's JIT-safe stub headers under WITH_XPU_CADA (xtrans already
  provides a real, self-consistent stdlib via --include-path, and
  jitify's <limits>/<cmath> stubs conflict with it).
- paddle/cinn/backends/nvrtc/nvrtc_util.cc: propagate
  -DPADDLE_WITH_XPU_CADA into the NVRTC device-code compile itself
  (previously only visible to host-side C++), so the WITH_XPU_CADA-only
  code paths injected into runtime headers actually activate.
- paddle/cinn/runtime/cuda/float16_xpu_cada.h (new),
  paddle/cinn/runtime/cuda/bfloat16.h,
  paddle/cinn/runtime/cuda/cinn_cuda_runtime_source.cuh,
  paddle/cinn/backends/codegen_cuda_dev.cc: xtrans/clang's stricter
  overload resolution (vs nvcc) makes cinn::common::float16/bfloat16's
  implicit float+double conversions ambiguous in several call sites
  (shuffle intrinsics, cmath max/min promotion, generic struct
  shuffling). A SFINAE-based generic struct-shuffle overload is added
  for WITH_XPU_CADA; float16/bfloat16/fp8/welford/argidx reduce code
  paths that still hit the remaining ambiguity are temporarily scoped
  out for WITH_XPU_CADA (float32 reduce is unaffected and verified
  working end-to-end via CINN on M100/xtrans).
- paddle/cinn/runtime/cuda/xtrans_cublas_v2_compat.h (new),
  paddle/cinn/runtime/cuda/cublas_util.h: work around xtrans's
  cublas_v2.h textually rewriting several cublas symbols to _v2
  variants that xtrans's own libcublas.so does not export.
- paddle/ap/*: fix xtrans/clang not implicitly instantiating member
  function templates reached only through `if constexpr` branches
  inside lambdas (explicit instantiation added), plus narrowing-
  conversion and API-usage fixes required to compile under xtrans/clang.

Verified: WITH_XPU_CADA+CINN build completes, and
simple_add_cinn.py (fp32 elementwise add) passes end-to-end through
CINN's JIT/NVRTC path on M100 via xtrans.
@CLAassistant

CLAassistant commented Sep 7, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
4 out of 5 committers have signed the CLA.

✅ ZibinGuo
✅ ZhangX-21
✅ xuanyuanminzheng
✅ xinruiM
❌ RobertLuobo
You have signed the CLA already but the status is still pending? Let us recheck it.

@Paddle-Bot Paddle-Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

发现 1 条 P0 与 5 条 P1 问题,详见行内评论与 Review Board。

Powered by Nyanpasu with gpt-5.6-sol 默认推理级别, please check the suggestions carefully.

Comment thread CMakeLists.txt
set(PADDLE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

include(system)
add_compile_options("-fpermissive")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1
这里把 -fpermissive 无条件加入所有 C/C++/平台目标,而该选项只对 C++ 有效;例如当前 GCC 对 C 源文件会发出“valid for C++/ObjC++ but not for C”的诊断,在项目或用户重新启用 -Werror 时会直接阻断 C 编译。请将该选项限制在 WITH_XPU_CADA 的 C++/xtrans 目标,避免改变普通 CPU/GPU/Windows 构建。

Comment thread cmake/flags.cmake
endif()


string(APPEND CMAKE_CXX_FLAGS " -Wno-error")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1
这里对整个 Paddle 的 CMAKE_C_FLAGS/CMAKE_CXX_FLAGS 追加 -Wno-error,同时上方移除了 Linux GPU 的 -Werror,会让所有普通 CPU/GPU 目标失去项目和用户要求的 warning-as-error 约束,隐藏未初始化、弃用 API 等回归。请只在 CADA 需要的目标/工具链范围内覆盖相关诊断,不要全局改写告警策略。

Comment thread cmake/third_party.cmake
endif()

if(WITH_GPU
AND 0 # 先跳过FA

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1
AND 0 使这个条件在所有配置下恒为假,因而所有满足原有架构条件的 NVIDIA GPU 构建都会永久跳过 FlashAttention(包括 CUDA 12.3+、SM80/90 的路径),造成明显性能回退。请移除该硬编码禁用,或至少将其限定为已验证不兼容的 CADA 配置。

Comment thread CMakeLists.txt
set(WITH_MKL_CBLAS ${WITH_MKL})
if(WITH_GPU)
set(WITH_CUDA ${WITH_GPU})
if(WITH_GPU OR WITH_XPU_CADA)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P0
WITH_XPU_CADA=ON 且默认 WITH_GPU=OFF 时,这里仍把 WITH_CUDNN 设为默认开启并定义 CINN_WITH_CUDNN,但 cmake/configure.cmake 只在 WITH_GPU 下定义 PADDLE_WITH_CUDApaddle/phi/backends/dynload/CMakeLists.txt 也只在 WITH_GPU 下编译 cuDNN dynload。于是 cinn/runtime/cuda_util.cc 会包含被 PADDLE_WITH_CUDA 整体屏蔽的 cudnn.h 并使用未定义的 cuDNN 类型/包装器,CADA 默认配置无法编译。请让 CADA 的 cuDNN 依赖与这些宏/目标保持一致,或默认关闭 CINN_WITH_CUDNN

// GetNvidiaAllIncludePath expects, nor is it installed under
// /usr/local/cuda; its headers live under XTRANS_ROOT/targets/<arch>/include
// (see cmake/cinn.cmake XTRANS_ROOT/XTRANS_INCLUDE_DIR).
const char* xtrans_root_env = std::getenv("XTRANS_ROOT");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1
CMake 的 CADA 配置接受 -DXTRANS_ROOT=<path>,但运行时这里只读取环境变量 getenv("XTRANS_ROOT")(且先检查 CUDA_PATH)。因此按构建说明只传 CMake 变量、未额外导出环境变量的部署,在首次 NVRTC JIT 编译时会走到 Fatal,找不到 xtrans 头文件。请把配置的根路径传入运行时(例如生成宏/配置值),并保留环境变量作为覆盖。

// longer needs these types (CINN_CUDA_FP16/CINN_CUDA_BF16 are suppressed
// for WITH_XPU_CADA), so skip including/using them entirely here rather
// than injecting a variant that never gets referenced; re-add once fixed.
const std::string CodeGenCudaDev::source_header_ = // NOLINT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1
CADA 只替换了 source_header_,但 compiler.cc:438-439FLAGS_enable_cinn_kernel_cache=true 时改用未替换的 GetGeneralSourceHeader();该 header 仍注入普通 float16.h/bfloat16.h 和旧的 cinn_cuda_runtime_source.cuh,会重新触发 xtrans 的重载歧义。开启 kernel cache 的 CADA 首次编译因此绕过本补丁的兼容头文件。请让 general header 也采用同一 CADA 变体,或禁止该缓存路径。

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.

7 participants