# A newbie can not use CUDA by follow official DOC!

**URL:** <https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010>\
**Category:** GPU\
**Created:** [March 15, 2020, 2:14pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010 "2020-03-15T14:14:42Z")\
**Posts on this page:** 14\
**Page:** 2

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [April 24, 2020, 3:08pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/21 "2020-04-24T15:08:16Z")

</div>

I am more than a bit confused here.  
The output of nvidia-smi looks OK to me, and a driver version is printed.  
I though the nvidia driver had to be loaded to allow that command to work?  
I definitely stand to be corrected.

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [April 24, 2020, 3:14pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/22 "2020-04-24T15:14:06Z")

</div>

`nvidia-smi` uses libnvml, and depending on the linux distribution it’s possible that is installed without libcuda being available. Or, on a cluster (where there can be some forwards compatibility of multiple `libcuda`s given a single NVIDIA driver), it might be required to `module load cuda`.

But you’re right, it’s more likely that `libcuda.so` is installed but not discoverable. In that case, the distribution package (or the user, if the NVIDIA driver is installed manually) is responsible for adding a `ld.so.conf` entry to the libcuda path if it isn’t part of the default library search path (or set LD\_LIBRARY\_PATH if that’s not possible).

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [April 24, 2020, 3:28pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/23 "2020-04-24T15:28:47Z")

</div>

Thankyou! That is helpful.

---

<div class="post-metadata">

**Author:** ![Mehrdad\_Esfahani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mehrdad_esfahani/32/14208_2.png) [@Mehrdad\_Esfahani](https://discourse.julialang.org/u/Mehrdad_Esfahani)\
**Post date:** [April 24, 2020, 3:54pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/24 "2020-04-24T15:54:18Z")

</div>

> [@Mehrdad\_Esfahani](#):
>
> using Libdl Libdl.dlpath(“libcuda”)

The driver is installed (I mean linux recognize it, so I am assuming it is fine). I followed this post [CuArray can't find libcuda - #7 by cuchxq](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/7)  
to make the library discoverable, but it still fails.

When I write

```julia
using Libdl
Libdl.dlopen("/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libcuda.so")

```

it outputs:

```julia
Ptr{Nothing} @0x0000000002b63b40

```

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [April 24, 2020, 3:59pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/25 "2020-04-24T15:59:52Z")

</div>

But what you’re loading here is an unusable version of the driver. `stubs/libcuda.so` doesn’t contain any functionality. You need the _actual_ `libcuda.so`.

---

<div class="post-metadata">

**Author:** ![Mehrdad\_Esfahani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mehrdad_esfahani/32/14208_2.png) [@Mehrdad\_Esfahani](https://discourse.julialang.org/u/Mehrdad_Esfahani)\
**Post date:** [April 24, 2020, 4:08pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/26 "2020-04-24T16:08:21Z")

</div>

where can I find it? I use

```julia
locate libcuda.so

```

and I get a bunch of output. Is this the way to find it?

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [April 24, 2020, 4:09pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/27 "2020-04-24T16:09:09Z")

</div>

That’s one way, yes. You can paste it here, or in a gist if it’s too long. It would be weird if you have plenty of `libcuda.so` files though.

---

<div class="post-metadata">

**Author:** ![Mehrdad\_Esfahani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mehrdad_esfahani/32/14208_2.png) [@Mehrdad\_Esfahani](https://discourse.julialang.org/u/Mehrdad_Esfahani)\
**Post date:** [April 24, 2020, 4:13pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/28 "2020-04-24T16:13:14Z")

</div>

This is the output which is long and confusing

```julia
/usr/lib/x86_64-linux-gnu/libcuda.so
/usr/lib/x86_64-linux-gnu/libcuda.so.1
/usr/lib/x86_64-linux-gnu/libcuda.so.440.33.01
/usr/lib/x86_64-linux-gnu/stubs/libcuda.so
/usr/local/cuda-10.2/doc/man/man7/libcuda.so.7
/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libcuda.so
/usr/share/man/man7/libcuda.so.7.gz
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL.nvidia-390-129/x86_64/1.4/a392a94e710ba4116ced1538ca146cc456aa470a623cefd1c6a91f043dc7b210/files/extra/libcuda.so
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL.nvidia-390-129/x86_64/1.4/a392a94e710ba4116ced1538ca146cc456aa470a623cefd1c6a91f043dc7b210/files/extra/libcuda.so.1
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL.nvidia-390-129/x86_64/1.4/a392a94e710ba4116ced1538ca146cc456aa470a623cefd1c6a91f043dc7b210/files/extra/libcuda.so.390.129
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL.nvidia-435-21/x86_64/1.4/5662dd4a55bd69b95299a79814cf5bd788b6f84b16fe66ec9e903bf380855f9f/files/extra/libcuda.so
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL.nvidia-435-21/x86_64/1.4/5662dd4a55bd69b95299a79814cf5bd788b6f84b16fe66ec9e903bf380855f9f/files/extra/libcuda.so.1
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL.nvidia-435-21/x86_64/1.4/5662dd4a55bd69b95299a79814cf5bd788b6f84b16fe66ec9e903bf380855f9f/files/extra/libcuda.so.435.21
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL.nvidia-440-33-01/x86_64/1.4/7bd82123228618c583180e638e20a3c7b3ca821dba1eb5ce5e73d16ab4dc0c12/files/extra/libcuda.so
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL.nvidia-440-33-01/x86_64/1.4/7bd82123228618c583180e638e20a3c7b3ca821dba1eb5ce5e73d16ab4dc0c12/files/extra/libcuda.so.1
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL.nvidia-440-33-01/x86_64/1.4/7bd82123228618c583180e638e20a3c7b3ca821dba1eb5ce5e73d16ab4dc0c12/files/extra/libcuda.so.440.33.01
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL32.nvidia-440-33-01/x86_64/1.4/90dd8243590b0eb3630bc10ae4039a0110bb550d06059d88acda7ff6b53616c3/files/extra/libcuda.so
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL32.nvidia-440-33-01/x86_64/1.4/90dd8243590b0eb3630bc10ae4039a0110bb550d06059d88acda7ff6b53616c3/files/extra/libcuda.so.1
/var/lib/flatpak/runtime/org.freedesktop.Platform.GL32.nvidia-440-33-01/x86_64/1.4/90dd8243590b0eb3630bc10ae4039a0110bb550d06059d88acda7ff6b53616c3/files/extra/libcuda.so.440.33.01

```

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [April 24, 2020, 4:15pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/29 "2020-04-24T16:15:13Z")

</div>

> [@Mehrdad\_Esfahani](#):
>
> /usr/lib/x86\_64-linux-gnu/libcuda.so

That’s the one you should be using, and `/usr/lib/x86_64-linux-gnu` should be on the search path. Did you maybe override that by prioritizing `/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/`?

---

<div class="post-metadata">

**Author:** ![Mehrdad\_Esfahani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mehrdad_esfahani/32/14208_2.png) [@Mehrdad\_Esfahani](https://discourse.julialang.org/u/Mehrdad_Esfahani)\
**Post date:** [April 24, 2020, 4:33pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/30 "2020-04-24T16:33:57Z")

</div>

When I type

```julia
echo $LD_LIBRARY_PATH

```

I get the following:

```julia
:/home/mehrdad/gsl/lib
:/home/mehrdad/.openmpi/lib/
:/home/mehrdad/gsl/lib
:/home/mehrdad/.openmpi/lib/
:/usr/local/cuda/lib64/stubs/
:/usr/lib64/:/usr/local/cuda/lib64/
:/usr/local/cuda-10.2/lib64/
:/usr/local/cuda-10.2/lib64/stubs/

```

I think there are a bunch of junk in there, but I do not know where to find this file and delete/add stuff in it.

---

<div class="post-metadata">

**Author:** ![Mehrdad\_Esfahani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mehrdad_esfahani/32/14208_2.png) [@Mehrdad\_Esfahani](https://discourse.julialang.org/u/Mehrdad_Esfahani)\
**Post date:** [April 24, 2020, 5:51pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/31 "2020-04-24T17:51:57Z")

</div>

I deleted everything in the `LD_LIBRARY_PATH`. Then I only added  
`/usr/lib/x86_64-linux-gnu `. The `Libdl` path for `libcuda` still returns `"/usr/local/cuda/lib64/stubs/libcuda.so"`. I assume it should return the path I gave to `LD_LIBRARY_PATH`? How can I change this? (I really appreciate your patience with me!)

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [April 25, 2020, 10:05am UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/32 "2020-04-25T10:05:59Z")

</div>

Check `/etc/ld.so.conf` or the files in `/etc/ld.so.conf.d`. You should not have to add `/usr/lib/x86_64-linux-gnu` to LD\_LIBRARY\_PATH, it should already have an entry there. But more importantly, there should be no `stubs` entry there. LD\_LIBRARY\_PATH could also be set in `/etc/profile` or `/etc/profile.d/*`, or in a variety of places in your home folder (.bashrc, .profile, etc).

---

<div class="post-metadata">

**Author:** ![Mehrdad\_Esfahani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mehrdad_esfahani/32/14208_2.png) [@Mehrdad\_Esfahani](https://discourse.julialang.org/u/Mehrdad_Esfahani)\
**Post date:** [April 25, 2020, 3:12pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/33 "2020-04-25T15:12:22Z")

</div>

> [@maleadt](#):
>
> Int(ans)

I added the path manually in `.bashrc`. I then restarted and now `Libdl` finds the library correctly and the examples all work. Thank you sir for your patience. I really appreciate it.

---

<div class="post-metadata">

**Author:** ![sdewaele](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sdewaele](https://discourse.julialang.org/u/sdewaele)\
**Post date:** [October 16, 2020, 3:52pm UTC](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010/34 "2020-10-16T15:52:13Z")

</div>

Thanks @Mehrdad_Esfahani and @maleadt for this post. I helped my resolve the exact same problem on my system! I added this line to my `.bashrc` to remove the stubs:

```bash
    export LD_LIBRARY_PATH=`echo $LD_LIBRARY_PATH | tr ":" "\n" | grep -v "stubs" | tr "\n" ":"`

```

By the way - would it be possible for `CUDA.jl` to automatically ignore the stub and use the real library instead?

[Previous page](https://discourse.julialang.org/t/a-newbie-can-not-use-cuda-by-follow-official-doc/36010.md?page=1)
