Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to install pytorch bindings - lcuda not found #183

Open
akshay-krishnan opened this issue Oct 29, 2022 · 28 comments
Open

Unable to install pytorch bindings - lcuda not found #183

akshay-krishnan opened this issue Oct 29, 2022 · 28 comments

Comments

@akshay-krishnan
Copy link

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.

@bdfbdf321
Copy link

have you solved this problem?

@akshay-krishnan
Copy link
Author

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.

@bdfbdf321
Copy link

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

@ry85
Copy link

ry85 commented Nov 9, 2022

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

@akshay-krishnan
Copy link
Author

akshay-krishnan commented Nov 16, 2022

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
Copy link
Author

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
Copy link
Author

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

@akshay-krishnan akshay-krishnan changed the title Unable to install pytorch bindings with cuda 11.3 Unable to install pytorch bindings - lcuda not found Nov 17, 2022
@olestole
Copy link

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

@yenchenlin
Copy link

yenchenlin commented Dec 8, 2022

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"

@ry85
Copy link

ry85 commented Dec 14, 2022

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.

@KamiCalcium
Copy link

KamiCalcium commented Jan 16, 2023

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!

@Tom94
Copy link
Collaborator

Tom94 commented Jan 16, 2023

@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.

@MilkClouds
Copy link

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.

@xiechun0318
Copy link

xiechun0318 commented Feb 3, 2023

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.

@Eric-Ho-Matrix
Copy link

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)

@whoiszzj
Copy link

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!

@lenismerino
Copy link

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

@Zazexy
Copy link

Zazexy commented Aug 14, 2023

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!

@samsartor
Copy link

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

@qgli
Copy link

qgli commented Sep 6, 2023

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

@kwand
Copy link

kwand commented Oct 4, 2023

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.

@jeff999955
Copy link

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

This works for me, thanks!

@wy-luke
Copy link

wy-luke commented Nov 24, 2023

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.

@Dynaomit
Copy link

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?

@vule20
Copy link

vule20 commented Dec 12, 2023

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.

@gary-young
Copy link

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!!

@pengc02
Copy link

pengc02 commented Jun 5, 2024

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

@Invisiphantom
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests