11
$\begingroup$

I am using Mathematica 10.2 on Ubuntu 15.04 x64. At first, I try to use CUDALink:

Needs["CUDALink`"];

CUDAQ[]

It returns False.

The reason why it returns False is that the default paths for NVidia Driver and CUDA are

/usr/lib64/libnvidia-tls.so 

and

/usr/lib64/libcuda.so

But these two libraries on my system are located at

/usr/lib/nvidia-346/libnvidia-tls.so.346.59

and

/usr/lib/x86_64-linux-gnu/libcuda.so

According to the documentation provided by Mathematica, to resolve this issue I have to set the system environment for NVIDIA_DRIVER_LIBRARY_PATH and CUDA_LIBRARY_PATH.

So, I export these two variables and run Mathematica on a terminal:

$ export NVIDIA_DRIVER_LIBRARY_PATH=/usr/lib32/nvidia-346/libnvidia-tls.so.346.59

$ export CUDA_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/libcuda.so

$ mathematica

and try to use CUDALink again. This time, CUDAQ[] does not return False. Instead, all functions are colored blue (The same effect as calling Exit[]). The kernel may crash but there are no information about it.

My graphics card is NVidia Geforce GTX 750 Ti, so it should have already support CUDA.

I also tested CUDALink on another PC (Ubuntu 14.04 x64, Mathematica 10.0, NVidia Geforce GTX980), and I got the same issue.

Are you able to use CUDALink on Linux?

$\endgroup$
  • $\begingroup$ Please, use the bugs tag when it is confirmed that the issue you are having is really a bug. $\endgroup$ – Sektor Aug 6 '15 at 8:54
  • $\begingroup$ I suspect the problem is related to the fact that WRI only supports old CUDA driver, runtime, and toolkit versions. I sent them an email and asked if they support toolkit version 7 now (because the link below on this page goes to a page that reveals it's toolkit version 6), and the reply was the confirmation that they do indeed only support toolkit version 6 and not 7 and that I should downgrade to 6. Obviously I won't do that, kinda silly, but the person confirmed my suspicion about 7 not being supported. Also your NVidia drivers themselves are plenty old, 346.xx, whereas current is 352.30. $\endgroup$ – Andreas Lauschke Aug 20 '15 at 21:45
8
$\begingroup$

Finally I got a solution. The libcuda.so which is originally from Ubuntu cannot be used.

I follow this instructions to install CUDA and it works!

$\endgroup$
  • 2
    $\begingroup$ Excellent! Thank you very much for answering your own question and sharing this information with us! (+1) $\endgroup$ – MarcoB Aug 11 '15 at 4:40
  • $\begingroup$ Still, that means you're on an old toolkit version. The current CUDA version is 7, we have 7.5 as release candidate, and WRI just confirmed to me they only support 6. Toolkit 7 came out several months ago! $\endgroup$ – Andreas Lauschke Aug 20 '15 at 21:46
  • $\begingroup$ @AndreasLauschke The instructions provided by the post is about the installation of CUDA 6.5, that's true. But what I have installed is CUDA 7.0 with the 346.82 NVidia drivers. It works on Mathematica 10.1. $\endgroup$ – Purboo Aug 21 '15 at 6:44
  • $\begingroup$ @AndreasLauschke However, surprisingly, CUDA functions are slower than ordinary functions. Maybe CUDA 7.0 is the issue. $\endgroup$ – Purboo Aug 21 '15 at 6:47
  • $\begingroup$ @Purboo: Try upgrading the NVidia drivers to 352.30, that's really the current version. $\endgroup$ – Andreas Lauschke Aug 21 '15 at 12:30
3
$\begingroup$

I have managed to get CUDALink working on an ubuntu 14.04 with an NVidia GTX 750 Ti with CUDA 7 toolkit (installed the toolkit following these instructions; http://www.r-tutor.com/gpu-computing/cuda-installation/cuda7.0-ubuntu ).

I have never been able to change NVIDIA_DRIVER_LIBRARY_PATH and CUDA_LIBRARY_PATH using env variables and get CUDALink to work.

I assume the Mathematica CUDA and Nvidia library paths as hardwired and I use symlinks from the libraries to the default locations where Mathematica is looking. It works for me! Mathematica is looking in /usr/lib64, this does not exist on my system, so;

cd /usr
sudo mkdir lib64

Locate your libnvidia-tls.so file, I used find

stuart@stuart-2015:~$ find / -name libnvidia-tls.so* 2>/dev/null
/usr/lib/nvidia-346/libnvidia-tls.so.346.82
/usr/lib/nvidia-346/tls/libnvidia-tls.so.346.82
/usr/lib32/nvidia-346/libnvidia-tls.so.346.82
/usr/lib32/nvidia-346/tls/libnvidia-tls.so.346.82

I have a 64bit system, I ignore the lib32 libraries, I have 2 choices;

/usr/lib/nvidia-346/libnvidia-tls.so.346.82
/usr/lib/nvidia-346/tls/libnvidia-tls.so.346.82

these are actually different files, I dont know what the difference is, or which is preferred, but there are only two choices, so I try the second file first and symlink like so;

sudo ln -s /usr/lib/nvidia-346/tls/libnvidia-tls.so.346.82 /usr/lib64/libnvidia-tls.so.346.82

With the cuda library, we find these files;

find / -name libcuda.so 2>/dev/null
/usr/lib/i386-linux-gnu/libcuda.so
/usr/lib/x86_64-linux-gnu/libcuda.so
/usr/local/cuda-7.0/targets/x86_64-linux/lib/stubs/libcuda.so

I need the 64-bit version, issue the symlink command;

sudo ln -s /usr/lib/x86_64-linux-gnu/libcuda.so.346.82 /usr/lib64/libcuda.so

Now open Mathematica and test; CUDA Mathematica test

$\endgroup$
  • $\begingroup$ Have you compared the computational speed with and without CUDA? For instance, randM = RandomReal[1, {4000, 4000}]; randM = RandomReal[1, {4000, 4000}]; AbsoluteTiming[CUDADot[randM, randM];] On my system, the dot operation without CUDA is twice the speed of CUDA. $\endgroup$ – Purboo Aug 23 '15 at 8:28
  • $\begingroup$ Thank you, Stuart. Only your tip about tricking Mathematica with soft links worked for me. Incidentally, my machine (an 8-double-core Xeon) has a Quadro 2000 and a Tesla C2050, and my results for Purboo's CUDADot test were: 4.127769 for AbsoluteTiming[Dot[randM, randN];], and 1.807647 for AbsoluteTiming[CUDADot[randM, randN];] (I'm assuming there was a typo in Purboo's test, with definitions for the matrices as given by randM = RandomReal[1, {4000, 4000}]; randN = RandomReal[1, {4000, 4000}];) $\endgroup$ – user38571 Mar 14 '16 at 19:57
  • 1
    $\begingroup$ An update, Sept 2016. I've installed Ubuntu 16.04 and the 7.5 CUDA kit and the above method does not work with Mathematica 10.0.02, however the good news is that this method does work with Ubuntu 16.04, CUDA 7.5 and Mathematica 11.0.0.0. Mathematica 11 introduces a high-performance neural network framework with both CPU and GPU training support, so it appears an effort has been made to improve CUDA in this version. $\endgroup$ – Stuart Anderson Sep 22 '16 at 14:19
  • $\begingroup$ Confirmed. But CUDADot[] is still much slower than Dot[] on my system. $\endgroup$ – Purboo Sep 23 '16 at 5:32
  • $\begingroup$ yes, I did a test; $\endgroup$ – Stuart Anderson Sep 26 '16 at 12:12
2
$\begingroup$

January 2017 I have installed Mathematica 10.2 on Ububtu 16.04(64bit) Nvidia GeForce GTX 760M after installing NvidiaDriver 367.57.0 and CUDA Toolkit 7.5 from the Ubuntu repos. The method above:

cd /usr

sudo mkdir lib64

sudo ln -s /usr/lib/nvidia-367/tls/libnvidia-tls.so.367.57 /usr/lib64/libnvidia-tls.so.367.57

sudo ln -s /usr/lib/x86_64-linux-gnu/libcuda.so /usr/lib64/libcuda.so

works fine for me

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.