You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在CuPy项目中正确引入Cutlass?解决编译报错问题

在CuPy中引入Cutlass的路径配置问题

我尝试通过以下代码在CuPy项目中引入Cutlass:

kernel = r"""
#include <include/cutlass/cutlass.h>
extern "C" __global__ void entry0() {
    return ;
}
"""
import cupy as cp

raw_module = cp.RawModule(code=kernel, backend='nvcc', options=("-I G:/cutlass-3.3.0",))
raw_module.get_function("entry0")((1, 1, 1),(1, 1, 1),())

运行时出现编译错误:

cupy.cuda.compiler.CompileException: `nvcc` command returns non-zero exit status.
command: ['C:\\Program', 'Files\\NVIDIA', 'GPU', 'Computing', 'Toolkit\\CUDA\\v12.2\\bin\\nvcc.EXE', '-gencode=arch=compute_89,code=sm_89', '--cubin', '-I G:/cutlass-3.3.0', '-IC:\\Users\\mrakg\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\cupy\\_core\\include', '-IC:\\Users\\mrakg\\AppData\\Local\\Programs\\Python\\Python311\\Lib\\site-packages\\cupy\\_core\\include\\cupy\\_cuda\\cuda-12', '-IC:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.2\\include', '-ftz=true', 'C:\\Users\\mrakg\\AppData\\Local\\Temp\\tmpdwwgnwt7\\e63b826e4265f53d72fc550972a60778d4e87cc0.cu']
return-code: 2
stdout/stderr:
G:/cutlass-3.3.0\include/cutlass/cutlass.h(48): fatal error C1083: Cannot open include file: 'cutlass/detail/helper_macros.hpp': No such file or directory
e63b826e4265f53d72fc550972a60778d4e87cc0.cu

排查发现,Cutlass的cutlass.h中使用#include "cutlass/detail/helper_macros.hpp"引入内部头文件,当前路径配置导致编译器无法找到该文件。手动修改cutlass.h中的include语句为#include "detail/helper_macros.hpp"可临时解决,但需要找到正确的路径配置方式。


解决方案

问题核心是编译器include路径与Cutlass头文件目录结构不匹配,推荐采用以下标准方式修复:

调整NVCC的include路径并修正头文件引用

Cutlass的头文件全部存放在G:/cutlass-3.3.0/include目录下,正确的做法是将该目录添加到NVCC的include路径中,同时简化kernel中的头文件引用语句:

修改后的代码:

kernel = r"""
#include <cutlass/cutlass.h>
extern "C" __global__ void entry0() {
    return ;
}
"""
import cupy as cp

# 将include路径指向cutlass的include目录
raw_module = cp.RawModule(code=kernel, backend='nvcc', options=("-I G:/cutlass-3.3.0/include",))
raw_module.get_function("entry0")((1, 1, 1),(1, 1, 1),())

为什么这样有效:

  • 添加-I G:/cutlass-3.3.0/include后,编译器会在该目录下查找头文件,#include <cutlass/cutlass.h>会对应到G:/cutlass-3.3.0/include/cutlass/cutlass.h
  • cutlass.h内部的#include "cutlass/detail/helper_macros.hpp"会基于当前头文件所在目录(G:/cutlass-3.3.0/include/cutlass/)查找,最终定位到G:/cutlass-3.3.0/include/cutlass/detail/helper_macros.hpp,完全匹配文件实际位置

这种方式符合Cutlass官方推荐的使用规范,无需修改Cutlass源码,避免后续版本升级时的兼容问题。


内容的提问来源于stack exchange,提问作者Marko Grdinić

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 20:02:20