NVCC 不会在 /usr/lib/x86_64-linux-gnu 中查找库 - 为什么?
NVCC won't look for libraries in /usr/lib/x86_64-linux-gnu - why?
考虑以下 CUDA 程序,在名为 foo.cu
的文件中:
#include <cooperative_groups.h>
#include <stdio.h>
__global__ void my_kernel() {
auto g = cooperative_groups::this_grid();
g.sync();
}
int main(int, char **) {
cudaLaunchCooperativeKernel( (const void*) my_kernel, 2, 2, nullptr, 0, nullptr);
cudaDeviceSynchronize();
}
此程序需要用-rdc=true
编译(参见this question);并且需要明确链接到 libcudadevrt
。好的,没问题……是吗?
$ nvcc -rdc=true -o foo -gencode arch=compute_61,code=sm_61 foo.cu -lcudadevrt
nvlink error : Undefined reference to 'cudaCGGetIntrinsicHandle' in '/tmp/tmpxft_000036ec_00000000-10_foo.o'
nvlink error : Undefined reference to 'cudaCGSynchronizeGrid' in '/tmp/tmpxft_000036ec_00000000-10_foo.o'
只有当我用 -L/usr/lib/x86_64-linux-gnu
显式添加库的文件夹时,它才愿意构建我的程序。
这很奇怪,因为我系统上的所有 CUDA 库都在该文件夹中。为什么 NVCC/nvlink 不往里面看?
备注:
- 我正在使用 Devuan GNU/Linux 3.0.
- CUDA 10.1 作为分发包安装。
- 带有 GeForce 1050 Ti 卡的 x86_64 机器。
NVCC,或者 nvlink,在名为 LIBRARIES
的环境变量中查找路径。但是 - 在这样做之前,shell 脚本 /etc/nvcc.profile
被执行(至少,它在 Devuan 上)。
在 Devuan 3.0 上,该文件有一行内容为:
LIBRARIES =+ $(_SPACE_) -L/usr/lib/x86_64-linux-gnu/stubs
这就是您的 NVCC 默认查找的位置。
因此,您可以执行以下两项操作之一:
在 NVCC 之外设置环境变量,例如在您的 ~/.profile
或 ~/.bashrc
文件中:
export LIBRARIES=-L/usr/lib/x86_64-linux-gnu/
将 nvcc.profile
行更改为:
LIBRARIES =+ $(_SPACE_) -L/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu/stubs
NVCC 将成功构建您的二进制文件。
考虑以下 CUDA 程序,在名为 foo.cu
的文件中:
#include <cooperative_groups.h>
#include <stdio.h>
__global__ void my_kernel() {
auto g = cooperative_groups::this_grid();
g.sync();
}
int main(int, char **) {
cudaLaunchCooperativeKernel( (const void*) my_kernel, 2, 2, nullptr, 0, nullptr);
cudaDeviceSynchronize();
}
此程序需要用-rdc=true
编译(参见this question);并且需要明确链接到 libcudadevrt
。好的,没问题……是吗?
$ nvcc -rdc=true -o foo -gencode arch=compute_61,code=sm_61 foo.cu -lcudadevrt
nvlink error : Undefined reference to 'cudaCGGetIntrinsicHandle' in '/tmp/tmpxft_000036ec_00000000-10_foo.o'
nvlink error : Undefined reference to 'cudaCGSynchronizeGrid' in '/tmp/tmpxft_000036ec_00000000-10_foo.o'
只有当我用 -L/usr/lib/x86_64-linux-gnu
显式添加库的文件夹时,它才愿意构建我的程序。
这很奇怪,因为我系统上的所有 CUDA 库都在该文件夹中。为什么 NVCC/nvlink 不往里面看?
备注:
- 我正在使用 Devuan GNU/Linux 3.0.
- CUDA 10.1 作为分发包安装。
- 带有 GeForce 1050 Ti 卡的 x86_64 机器。
NVCC,或者 nvlink,在名为 LIBRARIES
的环境变量中查找路径。但是 - 在这样做之前,shell 脚本 /etc/nvcc.profile
被执行(至少,它在 Devuan 上)。
在 Devuan 3.0 上,该文件有一行内容为:
LIBRARIES =+ $(_SPACE_) -L/usr/lib/x86_64-linux-gnu/stubs
这就是您的 NVCC 默认查找的位置。
因此,您可以执行以下两项操作之一:
在 NVCC 之外设置环境变量,例如在您的
~/.profile
或~/.bashrc
文件中:export LIBRARIES=-L/usr/lib/x86_64-linux-gnu/
将
nvcc.profile
行更改为:LIBRARIES =+ $(_SPACE_) -L/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu/stubs
NVCC 将成功构建您的二进制文件。