Locate CUDA installation on Linux

16,277

How does something based onldconfig -p | grep libcuda sound ? Considering an appropriate ldconfig setup is explicitly advised at the end of the installation of the CUDA toolkit, it should do the trick without path nicely, I think.

Share:
16,277
Narcolessico
Author by

Narcolessico

Updated on June 08, 2022

Comments

  • Narcolessico
    Narcolessico almost 2 years

    What's the best way? Here are my solutions:

    echo $PATH | sed "s/:/\n/g" | grep "cuda/bin" | sed "s/\/bin//g" |  head -n 1
    which nvcc | sed "s/\/bin\/nvcc//"
    which nvcc | head -c -10
    

    They are all PATH-based. One could locate libraries instead. It would be more robust if there are no CUDA paths in PATH.

    I'm using this in a Makefile.

  • Narcolessico
    Narcolessico about 13 years
    So that's how one can obtain the pure path: "dirname dirname ldconfig -p | grep libcudart | awk '{print $4}' | head -n 1` | head -c -5". This is more robust than the PATH-based approach. However, it is working on a Linux box but not on a Mac. No ldconfig on MAC?
  • Narcolessico
    Narcolessico about 13 years
    Oops, I should have asked: Locate CUDA installation path on Unix. For linux this is probably the best way.