You may been seeing the the power of GPU’s in recent years. Deep learning is using GPUs for obtaining complex calculations in CONVNETS and Sequence modelling done in a fair amount of time. Nvidia, the leader in manufacturing graphics card , has created CUDA a parallel computing platform. Nvidia is also really forward in deep learning and has been really advanced in deep learning applications.
Only Nvidia GPUs have the CUDA extension which allows GPU support for Tensorflow and PyTorch.( So this post is for only Nvidia GPUs only)
Today I am going to show how to install pytorch or tensorflow with CUDA enabled GPU. I try to cover all the relevant topics required.
I myself had certain difficulties while downloading and installing the programs and drivers. I thought I should write a post on it.
Prerequisites : If you have laptop of below requirements you can download the CUDA software.
- RAM : A minimum of 16 gb RAM is required. You can also get on with a 8gb ram, but it has it’s own complications.
- GPU : CUDA is compatible with almost all the models from 2006 but a minimum of gtx 1050ti, 1060 and above are required.
- SSD or HDD : A SSD with atleast 256gb is required for faster processing.The 128gb SSD falls short of space after the installation of the softwares.
NOTE : I’m writing this post keeping in mind that you have already installed anaconda or anyother platform (preferably anaconda) and keeping in mind you already have nvidia graphics card(To check you have nvidia graphics card — goto —
“Device Manager” -> click on “Display adapters” -> Hopefully a Nvidia chip is listed”.
STEP 1: Check for compatibility of your graphics card. The latest environment, called “CUDA Toolkit 9”, requires a compute capability of 3 or higher
You can check the compute capabilities and compatibility below :
NVIDIA GPUs power millions of desktops, notebooks, workstations and supercomputers around the world, accelerating…
Programming Guide :: CUDA Toolkit Documentation
The programming guide to the CUDA model and interface.
NOTE : The nvidia geforce gtx 1050ti is not listed on the listed but it is compatible and has compute capability of 6.1.
STEP 2 : Download visual studio 17(community). When you click download an executable file is download and a window is popped.
Then check all the above boxes in the workload i.e “Desktop development with C++”, “Universal Windows platform development” and “.NET desktop development”. And click install.
Then it takes some time and restarts your computer.
STEP 3 : Then close the visual studio completely and open visual studio installer and in the installed banner part under the visual studio community 2017 click modify. It is shown below
Then go to individual components which will be beside workload and got to compilers build tools and runtime section and check the following boxes as shown in the picture, from VC++ v14.00 toolset for desktop to VC++2017 latest v141 tools
Click install and it is about 17gb and it takes for about an hour for downloading and an hour for installing and the system restarts.
STEP 4 : After successfully installing Visual studio 17, you have to download and install CUDA.
Select installer type exe(local) and download the download list in a sequence and install them one after the other in a sequence.
NOTE : While downloading choose express if you don’t have any idea about the software. Also ensure VS 17 is completely closed while downloading CUDA.
STEP 5: After installing the CUDA , you should now check the CUDA is running or not. So open visual studio 17 and go to as below,
Click “File” in the upper left-hand corner → “New” — -> “Project”. On the left sidebar, click the arrow beside “NVIDIA” then “CUDA 9.0”. Click “CUDA 9.0 Runtime” in the center. Name the project as whatever you want. Click “OK” in the lower right hand corner. Visual Studio will start creating the project.
STEP 6 : Now that the project is created and you have got a default program already written. Then if you go and rebuild the project after clicking the rebuild button in build option, you may get errors(Possibly). If this error occurs simply go to — Project button in the options pane and click properties of the project you have created , like this,
Then a window pops up and here you have to change as follows :
general >>platform toolset , then change the visual studio 17 v141 to visual studio 15 v140 and click ok .
Then run the code and if it runs without errors , GREAT!!. If not, try to find the error.
Then in the debug button click start without debugging and if it shows the output , you have successfully ran a cuda program.
Then you are good to go.
STEP 7 : Now that you have successfully ran a CUDA program, now you have to give path for the CUDA. For setting the path you have to go to — -
right click on my computer>> properties>>advance system settings>>environmental variables >> system variables>> path
After finding the path, go to this , in the CUDA folder and copy the path.
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin
Now the paste the path in the path in system varables i.e select path and hit edit , in edit click the new button and paste the path there. Like this
Now comeback and do the same for “libnvvp” folder and do as same as above.
STEP 8 : Now the download the nvidia drivers for your laptop . Check the system requirements and download the drivers specifically for your laptops.
Download Drivers | NVIDIA
Download drivers for NVIDIA products including GeForce graphics cards, nForce motherboards, Quadro workstations, and…
STEP 9 : Now download cudnn ( A deep neural network library). It is a zip file and extract it. Cut the cudnn folder from downloads to c drive and paste it there ( anywhere in c drive).
Now same as we did above giving the path locations, we have to do same for cudnn folder. open the bin folder in cudnn folder and copy the path location to system variables .
system variables>>path>> edit>> new — then paste the path there.
STEP 10 : Now you can install the pytorch or tensorflow .
For downloading pytorch : run this command
conda install pytorch -c pytorch
pip3 install torchvision
Check the output by running any code .
For downloading tensorflow : First you have to create conda environment for tensorflow
pip install tensorflow-gpu
Now you are ready and good to go . Now that you have a CUDA enabled GPUs you will have more processing power and swiftness in operations.
You can watch this video
Now that you have installed all the required things for GPU computing, let me warn you do not train huge datasets it will just damage your computer. Take all the necessary precautions because GPUs get heated up very soon . So take care while programming.
That’s it for now and happy deep learning/machine learning.