NVCC won't look for libraries in /usr/lib/x86_64-linux-gnu - why?

淺唱寂寞╮ 提交于 2020-01-07 09:23:24

问题


Consider the following CUDA program, in a file named 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();
}

This program needs to be compiled with -rdc=true (see this question); and needs to be explicitly linked against libcudadevrt. Ok, no problem... or is it?

$ 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'

Only if I explicitly add the library's folder with -L/usr/lib/x86_64-linux-gnu, is it willing to build my program.

This is strange, because all of the CUDA libraries on my system are in that folder. Why isn't NVCC/nvlink looking in there?

Notes:

  • I'm using Devuan GNU/Linux 3.0.
  • CUDA 10.1 is installed as a distribution package.
  • An x86_64 machine with a GeForce 1050 Ti card.

回答1:


NVCC, or perhaps nvlink, looks for paths in an environment variable named LIBRARIES. But - before doing so, the shell script /etc/nvcc.profile is executed (at least, it is on Devuan).

On Devuan 3.0, that file has a line saying:

LIBRARIES   =+ $(_SPACE_) -L/usr/lib/x86_64-linux-gnu/stubs

so that's where your NVCC looks to by default.

You can therefore do one of two things:

  1. Set the environment variable outside NVCC, e.g. in your ~/.profile or ~/.bashrc file:

    export LIBRARIES=-L/usr/lib/x86_64-linux-gnu/stubs
    
  2. Change that nvcc.profile line to say:

    LIBRARIES   =+ $(_SPACE_) -L/usr/lib/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu/stubs
    

and NVCC will successfully build your binary.



来源:https://stackoverflow.com/questions/59481689/nvcc-wont-look-for-libraries-in-usr-lib-x86-64-linux-gnu-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!