Linker error when compiling PyTorch from source (CUDA_cublas_device_LIBRARY-NOTFOUND)

I’m trying to compile PyTorch from source, as I need it with the new ABI and OpenCV (which I also compiled from source) support.

I cloned the repo checked out the submodules, installed the requirements and compiled it with the following command:

CFLAGS=' -D_GLIBCXX_USE_CXX11_ABI=1 ' USE_NCCL=False  USE_OPENCV=1 USE_CUDA=1 USE_DISTRIBUTED=0 TORCH_CUDA_ARCH_LIST="5.3;6.2;7.2" MAX_JOBS=5 python3 setup.py install

Building works until around 86%, then it fails with the following trace:

[ 86%] Building CXX object caffe2/CMakeFiles/torch.dir/__/torch/csrc/cuda/comm.cpp.o
[ 86%] Linking CXX shared library ../lib/libtorch.so
/usr/bin/ld: cannot find -lCUDA_cublas_device_LIBRARY-NOTFOUND
collect2: error: ld returned 1 exit status
caffe2/CMakeFiles/torch.dir/build.make:27077: recipe for target 'lib/libtorch.so' failed
make[2]: *** [lib/libtorch.so] Error 1
CMakeFiles/Makefile2:5011: recipe for target 'caffe2/CMakeFiles/torch.dir/all' failed
make[1]: *** [caffe2/CMakeFiles/torch.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Traceback (most recent call last):
  File "setup.py", line 759, in <module>
    build_deps()
  File "setup.py", line 321, in build_deps
    cmake=cmake)
  File "/opt/pytorch/tools/build_pytorch_libs.py", line 63, in build_caffe2
    cmake.build(my_env)
  File "/opt/pytorch/tools/setup_helpers/cmake.py", line 330, in build
    self.run(build_args, my_env)
  File "/opt/pytorch/tools/setup_helpers/cmake.py", line 143, in run
    check_call(command, cwd=self.build_dir, env=env)
  File "/usr/lib/python3.6/subprocess.py", line 311, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install', '--config', 'Release', '--', '-j', '5']' returned non-zero exit status 2.

I can’t seem to find the issue here, does anyone have an idea?

If you need more info, just let me know.

Hi,

Would you mind to use wheel output instead to see if helps?
We can build pyTorch successfully with this command:

$ python3 setup.py bdist_wheel

Here is the complete building steps for your reference:
https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/

Thanks.

I tried it with your command, but I’m still getting the error…

Is there any data I can provide you with for more information?

Hi,

Could you try to follow the instructions shared in this topic:
https://devtalk.nvidia.com/default/topic/1049071/jetson-nano/pytorch-for-jetson-nano/

We can successfully compile a pyTorch package with the steps.
Thanks.