Nvidia Cudatoolkit vs Conda Cudatoolkit
Asked Answered
U

3

63

Till date, I have been using Tensorflow-GPU by installing it using pip and the Cuda related software and Nvidia softwares/drivers from Nvidia's website. Recently, I found that using conda install tensorflow-gpu also installs cudatoolkit and cudnn.

So, how are these(the ones provided by conda) different from the ones that I downloaded from Nvidia's website?

In my first (previous) environment, conda list showed that I have installed only TensorFlow(from PyPi) and no cudnn/cudatoolkit, but still everything worked.  This is my base environment where I installed Tensorflow-GPU using pip

Also, in a new environment in which I ran conda install tensorflow-gpu, conda list showed me tensorflow-gpu has been installed along with cudatoolkit and cudnn by Anaconda. And in this environment also, everything worked fine.This is a new environment where I used conda to install tensorflow-gpu

So does this mean, that downloading and installing Cuda from Nvidia's website is only necessary if I use pip to install TensorFlow?

Undertaker answered 30/12, 2019 at 11:7 Comment(0)
D
60

If using anaconda to install tensorflow-gpu, yes it will install cuda and cudnn for you in same conda environment as tensorflow-gpu. All you need to install yourself is the latest nvidia-driver (so that it works with the latest CUDA level and all older CUDA levels you use.)

This has many advantages over the pip install tensorflow-gpu method:

  1. Anaconda will always install the CUDA and CuDNN version that the TensorFlow code was compiled to use.
  2. You can have multiple conda environments with different levels of TensorFlow, CUDA, and CuDNN and just use conda activate to switch between them.
  3. You don't have to deal with installing CUDA and cuDNN manaually at the system wide level.

The disadvantage when compared to pip install tensorflow-gpu, is the latest version of tensorflow is added to pypi weeks before Anaconda is able to update the conda recipe and publish their builds of the latest TensorFlow version.

Denning answered 27/1, 2020 at 23:29 Comment(7)
Do you have any idea what problems could occur if CUDA is installed on the host os? (outside of the conda env)Backfire
Anaconda should ignore any version of CUDA outside of the conda env. It shouldn't be able to find it.Denning
I didn't have any errors. having both installed. I'm not sure if it gets ignored though.Digestant
I never had errors installing CUDA outside conda. @william Between the two methods you suggested, which would offer better performance?Verbatim
I wouldn't expect how CUDA was installed to affect performance. Whatever version offers the most recent version of CUDA I would expect to have the best performance.Denning
Does this mean we do not need to manually install CUDA and cuDNN anymore before using tensorflow-gpu (as the dependencies are already handled by conda).Kassandrakassaraba
@WilliamD.Irons What is the specific Windows 10 Console command to install cuDNN and CUDA using conda? Does conda install tensorflow-gpu install both cudatoolkit and cudnn? What if we also want to install PyTorch-CUDA?Byran
S
9

Nvidia now has official channel for conda. the package name is nvidia/cuda. I prefer conda for easier managing different cuda enviroment.

What I found to be missing in conda-forge/cudatoolkit is nvcc and I guess some other utils for compiling but not running enviroment is also missing.

this post say conda-forge/cudatoolkit-dev will install nvcc, but I haven't tried.

Substitute answered 22/6, 2022 at 3:41 Comment(2)
Is it worth using that as a base image if I'll be using Conda anyway? Might I just start from a Ubuntu20 image>?Greenockite
@Greenockite well, ubuntu image is also the official way. I use conda simply because I dont have enough space on /usr and I dont want to change it. using conda can install cuda in different location.Substitute
S
1

For install cudatoolkit and cudnn by Anaconda you can use these following command conda install -c conda-forge cudatoolkit=11.2 cudnn=8.1.0 on command prompt

You must aware the tensorflow version must be less than 2.11

For check if the everything installed properly

  1. In command prompt check nvidia-smi command. if shows command not found you must install the latest GPU driver

  2. Use this python script to config the GPU in programming


import tensorflow as tf

if tf.config.list_physical_devices('GPU'):

  print('GPU is available.')

else:

  print('GPU is NOT available. Make sure TensorFlow version less than 2.11 and Installed all GPU drivers.')

config = tf.compat.v1.ConfigProto()

config.gpu_options.allow_growth = True 

session = tf.compat.v1.Session(config=config)
Seychelles answered 31/3 at 13:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.