26

I know that I can install Cuda with the following:

wget http://developer.download.nvidia.com/compute/cuda/7_0/Prod/local_installers/cuda_7.0.28_linux.run
chmod +x cuda_7.0.28_linux.run
./cuda_7.0.28_linux.run -extract=`pwd`/nvidia_installers
cd nvidia_installers
sudo ./NVIDIA-Linux-x86_64-346.46.run 
sudo modprobe nvidia
sudo ./cuda-linux64-rel-7.0.28-19326674.run 

Just wondering if I can install Cuda without root?

Thanks,

user200340
  • 3,301
  • 13
  • 52
  • 74
  • 7
    The GPU driver (e.g. `sudo ./NVIDIA-Linux-x86_64-346.46.run`) is necessary to be able to run CUDA programs on a CUDA GPU, and it requires root privilege to install, the other toolkit components (CUDA toolkit, CUDA samples) can be installed without root privilege, if you direct the installer to place them in your local workspace rather than install to the default locations. If you already have a GPU driver installed on your system that supports the [desired CUDA toolkit version](http://stackoverflow.com/questions/30820513) then it is possible. – Robert Crovella Sep 07 '16 at 23:13
  • @RobertCrovella, looks like I have to ask the admins to install the CUDA installer first, then I can install toolkit myself. Thanks. – user200340 Sep 07 '16 at 23:56
  • Why dont you use CUDA 10.0 – Trect Dec 03 '18 at 10:18
  • 2
    @DheerajMPai This question was asked 2 years, 2 months ago. There was no CUDA 10.0 at that time. – user200340 Dec 04 '18 at 13:57

3 Answers3

67

Update The installation UI for 10.1 changed. The following works:

  • Deselect driver installation (pressing ENTERon it)
  • Change options -> root install path to a non-sudo directory.
  • Press A on the line marked with a + to access advanced options. Deselect create symbolic link, and change the toolkit install path.
  • Now installation should work without root permissions

Thank you very much for the hints in the question! I just want to complete it with an approach that worked for me, also inspired in this gist and that hopefully helps in situations where a valid driver is installed, and installing a more recent CUDA on Linux without root permissions is still needed.

TL;DR: Here are the steps to install CUDA9+CUDNN7 on Debian, and installing a pre-compiled version of TensorFlow1.4 on Python2.7 to test that everything works. Everything without root privileges and via terminal. Should also work for other CUDA, CUDNN, TensorFlow and Python versions on other Linux systems too.


INSTALLATION

  1. Go to NVIDIA's official release web for CUDA (as for Nov. 2017, CUDA9 is out): https://developer.nvidia.com/cuda-downloads.

  2. Under your Linux distro, select the runfile (local)option. Note that the sudo indication present in the installation instructions is deceiving, since it is possible to run this installer without root permissions. On a server, one easy way is to copy the <LINK> of the Download button and, in any location of your home directory, run wget <LINK>. It will download the <INSTALLER> file.

  3. Run chmod +x <INSTALLER> to make it executable, and execute it ./<INSTALLER>.

  4. accept the EULA, say no to driver installation, and enter a <CUDA> location under your home directory to install the toolkit and a <CUDASAMPLES> for the samples.

  5. Not asked here but recommended: Download a compatible CUDNN file from the official web (you need to sign in). In my case, I downloaded the cudnn-9.0-linux-x64-v7.tgz, compatible with CUDA9 into the <CUDNN> folder. Uncompress it: tar -xzvf ....

  6. Optional: compile the samples. cd <CUDASAMPLES> && make. There are some very nice examples there and a very good starting point to write some CUDA scripts of yourself.

  7. (If you did 5.): Copy the required files from <CUDNN> into <CUDA>, and grant reading permission to user (not sure if needed):

cp -P <CUDNN>/cuda/include/cudnn.h <CUDA>/include/
cp -P <CUDNN>/cuda/lib64/libcudnn* <CUDA>/lib64
chmod a+r <CUDA>/include/cudnn.h <CUDA>/lib64/libcudnn*
  1. Add the library to your environment. This is typically done adding this following two lines to your ~/.bashrc file (in this example, the <CUDA> directory was ~/cuda9/:
export PATH=<CUDA>/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<CUDA>/lib64/

FOR QUICK TESTING OR TENSORFLOW USERS

The quickest way to get a TensorFlow compatible with CUDA9 and CUDNN7 (and a very quick way to test this) is to download a precompiled wheel file and install it with pip install <WHEEL>. Most of the versions you need, can be found in mind's repo (thanks a lot guys). A minimal test that confirms that CUDNN is also working involves the use of tf.nn.conv2d:

import tensorflow as tf
x = tf.nn.conv2d(tf.ones([1,1,10,1]), tf.ones([1,5,1,1]), strides=[1, 1, 1, 1], padding='SAME')
with tf.Session() as sess:
    sess.run(x) # this should output a tensor of shape (1,1,10,1) with [3,4,5,5,5,5,5,5,4,3]

In my case, the wheel I installed required Intel's MKL library, as explained here. Again, from terminal and without root users, this are the steps I followed to install the library and make TensorFlow find it (reference):

  1. git clone https://github.com/01org/mkl-dnn.git
  2. cd mkl-dnn/scripts && ./prepare_mkl.sh && cd ..
  3. mkdir -p build && cd build
  4. cmake -D CMAKE_INSTALL_PREFIX:PATH=<TARGET_DIR_IN_HOME> ..
  5. make # this takes a while
    1. make doc # do this optionally if you have doxygen
  6. make test # also takes a while
  7. make install # installs into <TARGET_DIR_IN_HOME>
  8. add the following to your ~/.bashrc: export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<TARGET_DIR_IN_HOME>/lib

Hope this helps!
Andres

fr_andres
  • 5,927
  • 2
  • 31
  • 44
  • This worked because your machine already had an appropriate driver installed, and all you needed was the CUDA runtime library. If the driver is not installed, there is no way to run the program. – lyomi Dec 14 '17 at 09:17
  • 1
    that's right, as I say at the beginning I just wanted to complete the informations given by the OP and the accepted answer. I will clarify it – fr_andres Dec 14 '17 at 09:59
  • 6
    In any case installing CUDA without root is a differentiated task from running CUDA, and it is perfectly legitimate to want to install a newer CUDA version on a machine with an existing driver without root permissions... – fr_andres Dec 14 '17 at 10:04
  • 1
    actually, I wanted to edit it but it is already there, in the first sentence. I put it bold so nobody else gets confused – fr_andres Dec 14 '17 at 10:06
  • @fr_andres: I have a computer with CUDA5. Can I use your tip to install CUDA9 for it? – Gochit Jul 03 '18 at 04:41
  • @Gochit if your OS is debian-based or you can use equivalent commands to do the `chmod`, `wget` etc business it should work. Just make sure that your GPU, GPU drivers, CUDA (and optionally CUDNN) versions that you want to install are all compatible among each other. Try to check the GPU and driver version with `nvidia-smi`, and find the latest version compatible [here](https://developer.nvidia.com/cuda-gpus) – fr_andres Jul 03 '18 at 14:28
  • Did you try Dheeraj's approach? – fr_andres Jul 03 '18 at 14:39
  • @fr_andres: I tried your approach, but it reported `cudaErrorInsufficientDriver`. My driver version is 331.67. I think I can't install tensorflow on this server because the driver is too old. Thank you. – Gochit Jul 04 '18 at 03:26
  • CUDA/10.1 needs root permissions, and I found no way around it. Any suggestions? – Ehsan Apr 08 '19 at 09:26
  • Just tested the `cuda_10.1.105_418.39_linux.run` installation and went fine. They changed the UI with some options, please make sure to change the install paths to directories that your user has control of. – fr_andres Apr 08 '19 at 16:36
  • I updated the answer at the beginning for specific steps, let me know if it works for you! – fr_andres Apr 08 '19 at 16:41
  • Thanks for the elaborate answer.. cp -P /cuda/include/cudnn.h /include/ cp -P cudnn9/cuda/lib64/libcudnn* cuda9/lib64 chmod a+r cuda9/include/cudnn.h cuda9/lib64/libcudnn* helped a lot – Trect Jul 10 '19 at 05:52
  • 1
    @Tessaracter I'm glad to hear that! – fr_andres Oct 14 '19 at 02:16
  • This is actually a quite straightforward answer but thanks for being thorough! It worked fine for me because I had the drivers but not the libraries I needed for tf. – szdrnja Oct 21 '19 at 13:40
  • On step 4, even after entering my own directory, I got `Permission denied. Unable to write to /usr/local/cuda-11.4/` as if it completely ignored my suggestion. I unchecked drivers and left everything else checked. Any suggestions? – demongolem Jul 01 '21 at 12:49
  • It is possible that any errors in the path get silently ignored. Try different paths and combinations, with and without trailing /, no whitespaces... maybe v11 changed for good but hopefully not – fr_andres Jul 02 '21 at 09:30
6

You can install using conda with the following command.

conda install -c anaconda cudatoolkit

But you need to have prior accesss to the device(GPU).

EDIT : If you are finding error in anaconda repository then change the repository to conda-forge which is frequently updated.

conda install -c conda-forge cudatoolkit
Trect
  • 2,759
  • 2
  • 30
  • 35
4

You can install CUDA and compile programs, but you won't be able to run them for a lack of device access.