PointTransformer编译pointops_cuda报错fatal error: THC/THC.h: No such file or directory

错误信息

  • Ubuntu 20.04
  • CUDA 11.6
  • PyTorch 1.13.0

尝试运行PointTransformer代码, 编译pointops_cuda的时候报错:

> py setup.py install
running install
/home/dl/.conda/envs/dl/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/home/dl/.conda/envs/dl/lib/python3.8/site-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
running bdist_egg
running egg_info
creating pointops.egg-info
writing pointops.egg-info/PKG-INFO
writing dependency_links to pointops.egg-info/dependency_links.txt
writing top-level names to pointops.egg-info/top_level.txt
writing manifest file 'pointops.egg-info/SOURCES.txt'
/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/utils/cpp_extension.py:476: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
  warnings.warn(msg.format('we could not find ninja.'))
reading manifest file 'pointops.egg-info/SOURCES.txt'
writing manifest file 'pointops.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
building 'pointops_cuda' extension
creating build
creating build/temp.linux-x86_64-cpython-38
creating build/temp.linux-x86_64-cpython-38/src
creating build/temp.linux-x86_64-cpython-38/src/aggregation
creating build/temp.linux-x86_64-cpython-38/src/grouping
creating build/temp.linux-x86_64-cpython-38/src/interpolation
creating build/temp.linux-x86_64-cpython-38/src/knnquery
creating build/temp.linux-x86_64-cpython-38/src/sampling
creating build/temp.linux-x86_64-cpython-38/src/subtraction
gcc -pthread -B /home/dl/.conda/envs/dl/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/include -I/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/include/TH -I/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/include/THC -I/home/dl/.conda/envs/dl/include -I/home/dl/.conda/envs/dl/include/python3.8 -c src/aggregation/aggregation_cuda.cpp -o build/temp.linux-x86_64-cpython-38/src/aggregation/aggregation_cuda.o -g -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -DTORCH_EXTENSION_NAME=pointops_cuda -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++14
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
src/aggregation/aggregation_cuda.cpp:2:10: fatal error: THC/THC.h: 没有那个文件或目录
    2 | #include <THC/THC.h>
      |          ^~~~~~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
(dl) dl@kemove-desktop:~/point-transformer/lib/pointops$ py setup.py install
running install
/home/dl/.conda/envs/dl/lib/python3.8/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/home/dl/.conda/envs/dl/lib/python3.8/site-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
running bdist_egg
running egg_info
writing pointops.egg-info/PKG-INFO
writing dependency_links to pointops.egg-info/dependency_links.txt
writing top-level names to pointops.egg-info/top_level.txt
/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/utils/cpp_extension.py:476: UserWarning: Attempted to use ninja as the BuildExtension backend but we could not find ninja.. Falling back to using the slow distutils backend.
  warnings.warn(msg.format('we could not find ninja.'))
reading manifest file 'pointops.egg-info/SOURCES.txt'
writing manifest file 'pointops.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
building 'pointops_cuda' extension
gcc -pthread -B /home/dl/.conda/envs/dl/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/include -I/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/include/torch/csrc/api/include -I/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/include/TH -I/home/dl/.conda/envs/dl/lib/python3.8/site-packages/torch/include/THC -I/home/dl/.conda/envs/dl/include -I/home/dl/.conda/envs/dl/include/python3.8 -c src/aggregation/aggregation_cuda.cpp -o build/temp.linux-x86_64-cpython-38/src/aggregation/aggregation_cuda.o -g -DTORCH_API_INCLUDE_EXTENSION_H -DPYBIND11_COMPILER_TYPE=\"_gcc\" -DPYBIND11_STDLIB=\"_libstdcpp\" -DPYBIND11_BUILD_ABI=\"_cxxabi1011\" -DTORCH_EXTENSION_NAME=pointops_cuda -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++14
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
src/aggregation/aggregation_cuda.cpp:2:10: fatal error: THC/THC.h: 没有那个文件或目录
    2 | #include <THC/THC.h>
      |          ^~~~~~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1

原因

原因是pytorch 1.9之后的某个版本删除了THC.h, 参考 fatal error: THC/THC.h: No such file or directory - CSDN

解决方法

先排除2个正确答案:
老老实实运行储存库提供的env_setup.sh新装一个pytorch=1.9.0的环境。
降级pytorch1.9.0

我使用的是下述方法:
Ctrl+Shift+F全局搜索并删除每一行#include <THC/THC.h>
在这里插入图片描述
然后再编译就能通过了

### 编译错误 `THC/THCNumerics.cuh` 文件不存在的解决办法 当遇到编译过程中报错 `fatal error: THC/THCNumerics.cuh: No such file or directory` 时,可以从以下几个方面着手解决问题。 #### 方法一:删除不必要的头文件包含语句 对于某些项目而言,直接将引起问题的头文件包含语句注释掉可能是一个简单有效的临时措施。具体操作是在源码中找到并修改如下所示的内容: ```cpp // #include <THC/THCNumerics.cuh> ``` 这样做能够绕过找不到该特定CUDA库路径的问题[^1]。 #### 方法二:更新 PyTorch 版本 另一个更为推荐的做法是考虑升级PyTorch版本。随着PyTorch的发展,许多旧版API已经被废弃或迁移至新的命名空间内。因此,通过安装最新稳定版PyTorch来获取最新的功能支持以及更好的兼容性可能是更优的选择。可以通过pip命令轻松完成这一过程: ```bash pip install --upgrade torch torchvision torchaudio ``` 需要注意的是,在执行上述指令前最好先确认当前环境中其他依赖项不会因为此次升级受到影响。 #### 方法三:调整代码逻辑适配新版 API 变化 考虑到自PyTorch 1.11起官方已经不再保留`THC`相关接口而是转向使用`ATen`作为底层张量计算引擎的事实,建议开发者们积极跟进这些变动,并相应地调整自己的程序结构以适应新标准。例如,原本基于`THCudaCheck()`的地方应该替换为`AT_CUDA_CHECK()`等同效替代实现方式[^2]。 #### 方法四:检查 CUDA 工具链配置 有时即使解决了软件层面的问题仍然会遭遇硬件加速器上的障碍。“No kernel image is available for execution on the device”的提示往往意味着所使用的GPU架构与编译参数指定的目标平台不符。此时应当仔细核对项目的构建脚本(如setup.py),确保其正确指定了目标设备特性集;同时也要留意本地开发环境里CUDA驱动及相关工具包是否均已妥善安装且版本号相互匹配[^4]。
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值