# CuArray can't find libcuda

**URL:** <https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175>\
**Category:** GPU\
**Created:** [February 4, 2020, 4:41pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175 "2020-02-04T16:41:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![cuchxq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cuchxq/32/3830_2.png) [@cuchxq](https://discourse.julialang.org/u/cuchxq)\
**Post date:** [February 4, 2020, 4:41pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/1 "2020-02-04T16:41:00Z")

</div>

I installed cuda10.2 on a ubuntu 18.10, and was able to build and run the some examples from the Cuda example folder, such as devicequery.

But when I use Julia1.0.5LTS, and CuArray can’t find libcuda.

and using JULIA\_DEBUG=CUDAapi does not show me the directory probe information… Not sure how to solve this issue at this point. Would someone be able to point me to the right direction? Thanks in advance.

```julia
$ JULIA_DEBUG=CUDAapi julia-1.0.5
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.0.5 (2019-09-09)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using CuArrays
[ Info: CUDAdrv.jl failed to initialize, GPU functionality unavailable (set JULIA_CUDA_SILENT or JULIA_CUDA_VERBOSE to silence or expand this message)
[Info: Recompiling stale cache file /home/ctrotter/.julia/compiled/v1.0/CuArrays/7YFE0.ji for CuArrays [3a865a2d-5b23-5a0f-bc46-62713ec82fae]

```

---

<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:** [February 4, 2020, 4:42pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/2 "2020-02-04T16:42:36Z")

</div>

> [@cuchxq](#):
>
> set JULIA\_CUDA\_VERBOSE

Did you try out the suggestion from the error message?

---

<div class="post-metadata">

**Author:** ![cuchxq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cuchxq/32/3830_2.png) [@cuchxq](https://discourse.julialang.org/u/cuchxq)\
**Post date:** [February 4, 2020, 4:47pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/3 "2020-02-04T16:47:57Z")

</div>

> [@maleadt](#):
>
> set JULIA\_CUDA\_VERBOSE

Here is the information printed. But it doesn’t show where it is looking for libcuda.so

```julia
julia> ENV["JULIA_CUDA_VERBOSE"]=true
true
julia> using CuArrays
┌ Error: CUDAdrv.jl failed to initialize
│ exception =
│ could not load library "libcuda"
│ libcuda.so: cannot open shared object file: No such file or directory
│ Stacktrace:
│ [1] dlopen(::String, ::UInt32) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Libdl/src/Libdl.jl:97
│ [2] dlopen at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Libdl/src/Libdl.jl:94 [inlined] (repeats 2 times)
│ [3] (::getfield(CUDAdrv, Symbol("##408#lookup_fptr#83")))() at /home/ctrotter/.julia/packages/CUDAapi/K94wY/src/call.jl:29
│ [4] __init__ () at /home/ctrotter/.julia/packages/CUDAapi/K94wY/src/call.jl:37
│ [5] _include_from_serialized(::String, ::Array{Any,1}) at ./loading.jl:633
│ [6] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:713
│ [7] _tryrequire_from_serialized(::Base.PkgId, ::UInt64, ::String) at ./loading.jl:648
│ [8] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:702
│ [9] _tryrequire_from_serialized(::Base.PkgId, ::UInt64, ::String) at ./loading.jl:648
│ [10] _require_search_from_serialized(::Base.PkgId, ::String) at ./loading.jl:702
│ [11] _require(::Base.PkgId) at ./loading.jl:937
│ [12] require(::Base.PkgId) at ./loading.jl:858
│ [13] require(::Module, ::Symbol) at ./loading.jl:853
│ [14] eval(::Module, ::Any) at ./boot.jl:319
│ [15] eval_user_input(::Any, ::REPL.REPLBackend) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:85
│ [16] macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:117 [inlined]
│ [17] (::getfield(REPL, Symbol("##28#29")){REPL.REPLBackend})() at ./task.jl:259
└ @ CUDAdrv ~/.julia/packages/CUDAdrv/aBgcd/src/CUDAdrv.jl:67
┌ Warning: CUDAnative.jl did not initialize because CUDAdrv.jl failed to
└ @ CUDAnative ~/.julia/packages/CUDAnative/Phjco/src/CUDAnative.jl:66
┌ Warning: CuArrays.jl did not initialize because CUDAdrv.jl or CUDAnative.jl failed to
└ @ CuArrays ~/.julia/packages/CuArrays/rNxse/src/CuArrays.jl:64

```

---

<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:** [February 4, 2020, 4:50pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/4 "2020-02-04T16:50:30Z")

</div>

> [@cuchxq](#):
>
> where it is looking for libcuda.so

Nowhere, it should be readily available since it’s a OS/kernel-dependent library. So it should be discoverable using `dlopen` without additional arguments. If it isn’t, you might had to add it to `ld.so.conf` or use LD\_LIBRARY\_PATH as a workaround.

---

<div class="post-metadata">

**Author:** ![cuchxq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cuchxq/32/3830_2.png) [@cuchxq](https://discourse.julialang.org/u/cuchxq)\
**Post date:** [February 4, 2020, 4:54pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/5 "2020-02-04T16:54:10Z")

</div>

```julia
$ echo $LD_LIBRARY_PATH
/usr/lib/x86_64-linux-gnu/:/usr/local/cuda-10.2/lib64

$ locate libcuda.so
/usr/lib/x86_64-linux-gnu/libcuda.so.1
/usr/lib/x86_64-linux-gnu/libcuda.so.440.33.01
/usr/local/cuda-10.2/doc/man/man7/libcuda.so.7
/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/libcuda.so

```

I added `/usr/lib/x86_64-linux-gnu/` to LD\_LIBRARY\_PATH in an effort to solve this issue. Originally it was just `/usr/local/cuda-10.2/lib64` and I see that libcuda.so is not there.

---

<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:** [February 4, 2020, 5:25pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/6 "2020-02-04T17:25:46Z")

</div>

So does it work now? Can you `dlopen` libcuda? FWIW, installing CUDA (however you did) should have added an entry to `/etc/ld.so.conf.d/`.

---

<div class="post-metadata">

**Author:** ![cuchxq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cuchxq/32/3830_2.png) [@cuchxq](https://discourse.julialang.org/u/cuchxq)\
**Post date:** [February 4, 2020, 6:10pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/7 "2020-02-04T18:10:47Z")

</div>

Thank you for the reply.

There is an entry:

```julia
$ sudo cat /etc/ld.so.conf.d/cuda-10-2.conf
/usr/local/cuda-10.2/targets/x86_64-linux/lib

```

~~Looking at where `libcuda.so` is located, I notice there is one more level down the directory where libcuda.so (…/lib/stub/libcuda.so). But adding `/stubs` to the conf file didn’t solve the issue~~ Edit: I put `/usr/local/cuda-10.2` in `cuda-10-2.conf` file, and reboot, and it worked, too.

Eventually, I solved this by doing one of the following.

1. Add the location of `libcuda.so` to LD\_LIBRARY\_PATH. In my case, the last line of the result shown with `locate libcuda.so`  
`$export LD_LIBRARY_PATH=/usr/local/cuda-10.2/targets/x86_64-linux/lib/stubs/:$LD_LIBRARY_PATH`

2. Or make a link in `/usr/lib/x86_64-linux-gnu/`  
`$sudo ln -s /usr/lib/x86_64-linux-gnu/libcuda.so.1 /usr/lib/x86_64-linux-gnu/libcuda.so`  
I found out this solution because `Libdl.dlopen("libcuda.so.1")` works.

Given that not everyone have sudo privilege, maybe the first one is a better solution.

Thanks for your help! @maleadt

---

<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:** [February 4, 2020, 9:15pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/8 "2020-02-04T21:15:45Z")

</div>

> [@cuchxq](#):
>
> Given that not everyone have sudo privilege, maybe the first one is a better solution.

But you need root privileges to install CUDA anyway, at which point an ld.so.conf entry should have been set-up.

Anyway, glad you got it to work! And FWIW, after modifying the ld.so settings you need to run `ldconfig` (a reboot wouldn’t have been necessary then).

---

<div class="post-metadata">

**Author:** ![cuchxq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cuchxq/32/3830_2.png) [@cuchxq](https://discourse.julialang.org/u/cuchxq)\
**Post date:** [February 4, 2020, 10:02pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/9 "2020-02-04T22:02:06Z")

</div>

I did try ldconfig after, but somehow it didn’t update the cache. I was getting the same error.

Also, I am so happy to see documentation for CUDA.jl. It is very appreciated!

---

<div class="post-metadata">

**Author:** ![cuchxq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cuchxq/32/3830_2.png) [@cuchxq](https://discourse.julialang.org/u/cuchxq)\
**Post date:** [February 4, 2020, 10:06pm UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/10 "2020-02-04T22:06:22Z")

</div>

I probably should open another thread for this question, but maybe you @maleadt have a quick answer.

Can the CUDA.jl calls be compiled into an executable?  
In other words, I am compiling everything in my application to an executable for deployment, some of the functions require GPU. If this is not a short answer, I will be happy to create another question and include a minimal working example.

---

<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:** [February 5, 2020, 6:59am UTC](https://discourse.julialang.org/t/cuarray-cant-find-libcuda/34175/11 "2020-02-05T06:59:33Z")

</div>

> [@cuchxq](#):
>
> Can the CUDA.jl calls be compiled into an executable?  
> In other words, I am compiling everything in my application to an executable for deployment, some of the functions require GPU.

PackageCompiler-style? No, that’s not supported. It used to be possible to write the compiled PTX kernels to disk and load them instead of recompiling, but that didn’t help much (compilation is fairly quickly, tens of ms for reasonable kernels, it’s the initial compilation of CUDAnative that takes long).
