alike-cpp 编译
1. 源码链接:
https://github.com/Shiaoming/ALIKE-cpp
2.已经安装好显卡驱动,cuda,cudnn,没安装的参考:
切记装cuda-11.x的版本
ubuntu重装系统后,安装cuda,cudnn-****博客
3.安装opencv
下载所需要的版本,camke 安装即可
4.libtorch
官网给出了下载链接:https://download.pytorch.org/libtorch/cu113/libtorch-cxx11-abi-shared-with-deps-1.11.0%2Bcu113.zip
但是只支持cuda11.3的版本,由于系统是ubuntu 22.04,无法安装cuda11.3的版本,我这里是安装的cuda12.1的版本,需要pytorch的支持的版本也是12.1的,找到libtorch的下载网址:https://download.pytorch.org/libtorch/cu121,其他版本可参考:清华源和torch源_torch清华源-****博客
将CMakeLists.txt中的torch路径指定到刚才下载的版本上:
set(Torch_DIR "/xx/libtorch/share/cmake/Torch")
然后开始编译:
mkdir build
cd build
cmake ..
make
编译完成后运行时报错:
terminate called after throwing an instance of 'c10::CUDAError' what(): CUDA error: an illegal memory access was encountered CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
应该是torch版本不兼任,我下载的是torch2.1.0+cu121,应该用torch1.11.0+cu121,
这里不要用cuda12以上的版本,编译很浪费时间,直接换成cuda-11.x的版本,别问我怎么知道的
5.下载pytorch源码进行编译
参考:【libtorch】pytorch源码编译生成c++ 17 libtorch记录_libtorch编译-****博客
(1)先下载pytorch源码,不要从官网下载source,里面third_party中的内容还要单独下载,直接用下面的命令下载:
git clone https://github.com/pytorch/pytorch.git
(2)切换到libtorch版本对应tag
cd pytorch
git tag -l *1.11.0* // git tag查看版本,git tag -l搜索特定版本的tag
git checkout v1.11.0 // 切换到特定tag的代码
(3)更新所有显示modified的submodule,如下截图
git submodule sync
git submodule update --init --recursive
(4)cmake 安装:
cd pytorch
mkdir build && cd build
cmake ..
make
make install
make过程中报错,应该是与cuda版本不兼容导致,对于使用最新CUDA版本(如12.1),升级PyTorch到最新版本,2.0以上。 如果必须保持旧版PyTorch(如1.11),切换到与之兼容的CUDA版本(如11.8)。
(1)exception_handler.cc:141:49: error: no matching function for call to ‘max(int, long int)’ static const unsigned kSigStackSize = std::max(16384, SIGSTKSZ);
这个错误是因为 `std::max` 函数的两个参数类型不匹配所导致的。在C++中,`std::max` 要求其参数必须是同一类型的,或者至少可以被隐式转换为同一类型。
`16384` 是一个 `int` 类型的常量,而 `SIGSTKSZ` 是一个 `long int` 类型的常量,可以通过显式地将其中一个参数转换为另一种类型来解决这个问题。可以将 `SIGSTKSZ` 类型转换为 `int`,或者将 `16384` 类型转换为 `long int`。为了避免潜在的类型损失,建议将 `16384` 类型转换为 `long int`。
找到对应的文件改为static const unsigned kSigStackSize = std::max(16384L, SIGSTKSZ);
(2)error: too many arguments to function ‘cudaError_t cudaGraphInstantiate(CUgraphExec_st**, cudaGraph_t, long long unsigned int)’
143 | AT_CUDA_CHECK(cudaGraphInstantiate(&graph_exec_, graph_, NULL, NULL, 0));
CUDA 12.1 版本的 `cudaGraphInstantiate` 函数签名已经发生了变化,只需要三个参数:
将AT_CUDA_CHECK(cudaGraphInstantiate(&graph_exec_, graph_, NULL, NULL, 0));改为:
AT_CUDA_CHECK(cudaGraphInstantiate(&graph_exec_, graph_, 0));
(3)最后还是报错:pytorch/aten/src/ATen/cuda/CUDASparseDescriptors.h:100:74: error: could not convert template argument ‘cusparseDestroyDnMat’ from ‘cusparseStatus_t (*)(cusparseConstDnMatDescr_t)’ {aka ‘cusparseStatus_t (*)(const cusparseDnMatDescr*)’} to ‘cusparseStatus_t (*)(cusparseDnMatDescr*)’
CUDASparseDescriptors.h:123:15: error: ‘class at::cuda::sparse::CuSparseSpMatCsrDescriptor’ has no member named ‘descriptor’
123 | this->descriptor(),
推荐阅读
-
模块编译成功,但 python 运行时找不到依赖项 名称为''的模块
-
在 ubuntu 下将 iconv 库交叉编译到 arm 32 位,将 GB2312 转换为 UTF-8。
-
勇敢者编译指南 2024 Android - 项目结构 (II)
-
AOT 漫谈主题(第 4 部分):如何将 C# 程序编译为本地代码
-
AAOS]安卓汽车 14 仿真器源代码下载与编译
-
为 Windows 10 安装 MinGW 和配置 C/C++ 编译环境的 VS 代码
-
3D 医学影像开发入门<2>:VS2019+VTK9.3.1 编译和环境配置
-
使用静态 OpenSSL 对 MinGW 进行 Qt5.15.2 静态编译
-
编译链接的过程会发生什么?-3:翻译环境工作演示
-
cudnn8 编译 caffe 流程(保姆级图形全流程,涵盖各种错误和解决方案)