If you have an older GPU that only supports CUDA 9.0 you can’t simply install the latest tools on a modern Ubuntu, they just won’t work as it requires an older version of many libraries.
To make it work we’re going to isolate everything we need in a conda environment, and use that whenever we need to work with the GPU. Here’s what you have to do:
Install miniconda and then execute this:
conda create -n cuda python=3.6
conda activate cuda
conda install gcc-6 cudatoolkit=9.0 tensorflow-gpu==1.12.0 numpy==1.16.0 -c pytorch -c hcc -c omgarcia
Now you can use your CUDA 9.0 GPU whenever you are in the cuda environment. Here’s how you can enter and exit your cuda environment at any time:
#To exit your cuda environment:
conda deactivate
#To enter your cuda environment:
conda activate cuda
Now let’s test it with python (make sure you are in the cuda environment, otherwise it will say False):
import tensorflow as tf
value = tf.test.is_gpu_available()
print("GPU available?: ", value)
It should tell you:
GPU available?: True
Now let’s try CUDA with CMake in a simple example. Basically this project creates a function in CUDA that adds two integers, and then the main program uses it to calculate 5 + 3 in the GPU. Amazing stuff. Let’s see if it works:
git clone https://github.com/Yannnnnnnnnnnn/cuda_cmakelists.git
cd cuda_cmakelists
mkdir build
cd build
cmake ..
make
./Demo
You should get the answer, which is 8 by the way. If you see that, it means you can now create a CUDA function, send data to your GPU, and then use that function on a program, all ready to use with CMake.
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.