tiny-cuda-nn icon indicating copy to clipboard operation
tiny-cuda-nn copied to clipboard

Unable to install pytorch bindings - lcuda not found

Open akshay-krishnan opened this issue 3 years ago • 31 comments

I am trying to build the pytorch bindings, but I am unable to because lcuda was not found on my system. ld: cannot find -lcuda I have cuda installed in /usr/local/cuda-11.3 and added /usr/local/cuda-11.3/bin to my $PATH and /usr/local/cuda-11.3/lib64/ to my $LD_LIBRARY_PATH.

I am able to build the library itself with cmake, but no success with the torch bindings. The g++ command fails since it is unable to find lcuda. I also cannot find a libcuda.so in my /usr/local/cuda-11.3/lib64/. I found one in /usr/local/cuda-11.3/lib64/stubs/, and added this path to my LD_LIBRARY_PATH, but that did not help.

I appreciate any help on this.

akshay-krishnan avatar Oct 29 '22 05:10 akshay-krishnan

have you solved this problem?

bdfbdf321 avatar Nov 01 '22 12:11 bdfbdf321

Yes, it could have been specific to my environment setup (or to my cuda version 11.3). I had to manually link to the libcuda.so in my conda environment lib.

akshay-krishnan avatar Nov 02 '22 20:11 akshay-krishnan

@akshay-krishnan How to link libcuda.so ? could you say more details about this solution. I still have this problem.

bdfbdf321 avatar Nov 03 '22 03:11 bdfbdf321

@akshay-krishnan How did you manually linked libcuda.so?

ry85 avatar Nov 09 '22 18:11 ry85

Sorry for the late response folks.

There was a libcuda.so in this path on my system /lib/x86_64-linux-gnu/libcuda.so, but I think that path is not included in LD's library path. I saw that the linked library path in my command is the /lib folder in my conda environment (miniconda3/envs/<env_name>/lib/libcuda.so). So I linked the libcuda.so from /lib/x86_64-linux-gnu to this folder with the following command:

ln -s /usr/lib/x86_64-linux-gnu/libcuda.so miniconda3/envs/<env_path>/lib/libcuda.so

I don't know if that is the right libcuda.so to be linked, but installation completed and I was able to import the tinycudann module.

akshay-krishnan avatar Nov 16 '22 18:11 akshay-krishnan

So I tried replicating this in a new environment, and the fix does not work for me anymore. Its not able to find lcuda even though I have a symlink to libcuda.so in the lib folder that it is searching in.

@Tom94 any help here would be great!

akshay-krishnan avatar Nov 17 '22 19:11 akshay-krishnan

I also tried with cuda 11.7, but I face the same problem, so this is probably not version-specific.

akshay-krishnan avatar Nov 17 '22 19:11 akshay-krishnan

I was able to resolve my issue regarding -lcuda which couldn't be found by following @akshay-krishnan's symlink-solution

olestole avatar Nov 18 '22 13:11 olestole

Add the following line to your .bashrc or .zshrc (depending on your shell) should solve the problem:

export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"

yenchenlin avatar Dec 08 '22 14:12 yenchenlin

The answer from @akshay-krishnan worked for me also,

ln -s /usr/lib/x86_64-linux-gnu/libcuda.so anaconda3/envs/nerfstudio/lib/libcuda.so

and not,

export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"

It seems there is no clear-cut solution to this problem, right now.

ry85 avatar Dec 14 '22 16:12 ry85

Add the following line to your .bashrc or .zshrc (depending on your shell) should solve the problem:

export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"

@yenchenlin I'm able to install

pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch

After setting the path to /usr/local/cuda/lib64/stubs, thank you!

However, when I tried to run instant-NGP under nerfstudio I have this error:

FAILED: nerfacc_cuda.so 
c++ pybind.cuda.o render_weight.cuda.o pack.cuda.o cdf.cuda.o render_transmittance.cuda.o intersection.cuda.o render_transmittance_cub.cuda.o contraction.cuda.o ray_marching.cuda.o -shared -L/home/user/anaconda3/envs/nerfstudio/lib/python3.8/site-packages/torch/lib -lc10 -lc10_cuda -ltorch_cpu -ltorch_cuda_cu -ltorch_cuda_cpp -ltorch -ltorch_python -L/home/user/anaconda3/envs/nerfstudio/lib64 -lcudart -o nerfacc_cuda.so
/usr/bin/ld: cannot find -lcudart: No such file or directory
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

I tried

export LIBRARY_PATH="/usr/local/cuda/lib64:$LIBRARY_PATH"

since I do found libcudart.so under /usr/local/cuda/lib64 but it does not resolve the issue. Any suggestions? Thank you very much!

KamiCalcium avatar Jan 16 '23 00:01 KamiCalcium

@KamiCalcium I'm afraid that's an issue on NerfAcc's side, not tcnn.

That said, if you would like to reproduce instant-ngp's results, I'd warmly encourage using the official implementation as none of the third party re-implementations I've tried match the performance vs. quality tradeoff.

Tom94 avatar Jan 16 '23 08:01 Tom94

I've solved lcuda not found issue, on WSL2

by executing ln -s /usr/lib/wsl/lib/libcuda.so ~/anaconda3/envs/(your env)/lib/libcuda.so

may be helpful to someone.

MilkClouds avatar Jan 26 '23 19:01 MilkClouds

I had the same problem installing it in a conda env on WSL. Here is how I solved it.

the compiler tries to find libcuda.so in ~/miniconda3/envs/(envname)/lib, but for some reason CUDA installed it to ~/miniconda3/envs/(envname)/lib/stubs

so I just created a link for libcuda.so outside the /stubs folder by ln -s ~/miniconda3/envs/(envname/lib/stubs/libcuda.so ~/miniconda3/envs/xrnerf/lib/libcuda.so

Then it compiled with no error.

I hope it helps.

xiechun0318 avatar Feb 03 '23 09:02 xiechun0318

Add the following line to your .bashrc or .zshrc (depending on your shell) should solve the problem:

export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"

Just to record, this method also works for WSL2 (Ubuntu 20.02 LTS)

Eric-Ho-Matrix avatar Mar 13 '23 20:03 Eric-Ho-Matrix

I meet the same problem and solve it with ln -s /usr/lib/x86_64-linux-gnu/libcuda.so miniconda3/envs/<env_path>/lib/libcuda.so Note that the libcuda.so must from the Nvidia Driver Lib, not Cuda Lib Nvidia Driver Lib: image Cuda lib: <cuda_home>/lib64/stubs: image

Good luck!

whoiszzj avatar May 26 '23 03:05 whoiszzj

Add the following line to your .bashrc or .zshrc (depending on your shell) should solve the problem:

export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"

Just to record, this method also works for WSL2 (Ubuntu 20.02 LTS)

This also worked on WSL2 Ubuntu 22.04.02, cuda 11.8 with cudnn, Python 3.10 via pip

lenismerino avatar Jul 04 '23 08:07 lenismerino

Add the following line to your .bashrc or .zshrc (depending on your shell) should solve the problem:

export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"

It works perfectly! thx!

Zazexy avatar Aug 14 '23 10:08 Zazexy

The LIBRARY_PATH solution did not work for me, but export LDFLAGS=-L/usr/local/cuda/lib64/stub did.

samsartor avatar Aug 23 '23 18:08 samsartor

I tried with @Zazexy and @samsartor's method:

export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"
export LDFLAGS=-L/usr/local/cuda/lib64/stub

and it works for me, thank you! specs: RTX4070ti, windows11, cuda11.8, gcc 11 and pytorch 2.0.1

qgli avatar Sep 06 '23 14:09 qgli

~~I can confirm the above solution works, though there seems to be a typo (second line should be export LDFLAGS=-L/usr/local/cuda/lib64/stubs, with an 's' for stubs).~~

~~On CUDA 11.8, PyTorch 2.0, GCC11 (all within an conda env).~~

~~Many thanks, and I hope this is fixed soon.~~

EDIT: Unfortunately, it is still broken. When I try to run it, I get an undefined symbol: _ZN3c104cuda9SetDeviceEi error.

kwand avatar Oct 04 '23 16:10 kwand

The LIBRARY_PATH solution did not work for me, but export LDFLAGS=-L/usr/local/cuda/lib64/stub did.

This works for me, thanks!

jeff999955 avatar Nov 08 '23 05:11 jeff999955

I had the same problem installing it in a conda env on WSL. Here is how I solved it.

the compiler tries to find libcuda.so in ~/miniconda3/envs/(envname)/lib, but for some reason CUDA installed it to ~/miniconda3/envs/(envname)/lib/stubs

so I just created a link for libcuda.so outside the /stubs folder by ln -s ~/miniconda3/envs/(envname/lib/stubs/libcuda.so ~/miniconda3/envs/xrnerf/lib/libcuda.so

Then it compiled with no error.

I hope it helps.

Great! It's the problem.

You could also run export LIBRARY_PATH=".../conda/envs/env_name/lib/stubs/:$LIBRARY_PATH".

Replace the path to yours

It works for me. Thanks.

wy-luke avatar Nov 24 '23 10:11 wy-luke

Add the following line to your .bashrc or .zshrc (depending on your shell) should solve the problem:

export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"

@yenchenlin I'm able to install

pip install git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch

After setting the path to /usr/local/cuda/lib64/stubs, thank you!

However, when I tried to run instant-NGP under nerfstudio I have this error:

FAILED: nerfacc_cuda.so 
c++ pybind.cuda.o render_weight.cuda.o pack.cuda.o cdf.cuda.o render_transmittance.cuda.o intersection.cuda.o render_transmittance_cub.cuda.o contraction.cuda.o ray_marching.cuda.o -shared -L/home/user/anaconda3/envs/nerfstudio/lib/python3.8/site-packages/torch/lib -lc10 -lc10_cuda -ltorch_cpu -ltorch_cuda_cu -ltorch_cuda_cpp -ltorch -ltorch_python -L/home/user/anaconda3/envs/nerfstudio/lib64 -lcudart -o nerfacc_cuda.so
/usr/bin/ld: cannot find -lcudart: No such file or directory
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

I tried

export LIBRARY_PATH="/usr/local/cuda/lib64:$LIBRARY_PATH"

since I do found libcudart.so under /usr/local/cuda/lib64 but it does not resolve the issue. Any suggestions? Thank you very much!

Did you find a solution to this Nerfacc related problem?

Dynaomit avatar Nov 27 '23 14:11 Dynaomit

Add the following line to your .bashrc or .zshrc (depending on your shell) should solve the problem:

export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"

Thanks so much. This works and solved my problem.

vule20 avatar Dec 12 '23 08:12 vule20

The LIBRARY_PATH solution did not work for me, but export LDFLAGS=-L/usr/local/cuda/lib64/stub did.

This works for me, thanks!

LDFLAGS works for me!! Thanks!!

haotong-yang avatar Jan 06 '24 02:01 haotong-yang

Sorry for the late response folks.

There was a libcuda.so in this path on my system /lib/x86_64-linux-gnu/libcuda.so, but I think that path is not included in LD's library path. I saw that the linked library path in my command is the /lib folder in my conda environment (miniconda3/envs/<env_name>/lib/libcuda.so). So I linked the libcuda.so from /lib/x86_64-linux-gnu to this folder with the following command:

ln -s /usr/lib/x86_64-linux-gnu/libcuda.so miniconda3/envs/<env_path>/lib/libcuda.so

I don't know if that is the right libcuda.so to be linked, but installation completed and I was able to import the tinycudann module.

this works, and if there's no libcuda.so in /usr/lib/x86_64-linux-gnu/, you can symlink one using libcuda.so.1 or something like that by

ln -s libcuda.so.1 libcuda.so

pengc02 avatar Jun 05 '24 12:06 pengc02

export LIBRARY_PATH=$LIBRARY_PATH:/usr/lib/wsl/lib This works for me.

Invisiphantom avatar Jun 10 '24 00:06 Invisiphantom