# I am getting an error when building CuArrays

**URL:** <https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059>\
**Category:** GPU\
**Created:** [April 12, 2019, 12:37am UTC](https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059 "2019-04-12T00:37:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgalenb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgalenb/32/5645_2.png) [@mgalenb](https://discourse.julialang.org/u/mgalenb)\
**Post date:** [April 12, 2019, 12:37am UTC](https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059/1 "2019-04-12T00:37:12Z")

</div>

I have installed CUDA 9.0 toolkit and Xcode and i have exported to PATH but when i build CuArrays i get this error:

````julia
  Building SpecialFunctions → `~/.julia/packages/SpecialFunctions/fvheQ/deps/build.log`
  Building CUDAdrv ─────────→ `~/.julia/packages/CUDAdrv/lu32K/deps/build.log`
┌ Error: Error building `CUDAdrv`: 
│ Initializing CUDA driver failed with code 3..
└ @ Pkg.Operations /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Operations.jl:1075
  Building LLVM ────────────→ `~/.julia/packages/LLVM/tg8MX/deps/build.log`
  Building CUDAnative ──────→ `~/.julia/packages/CUDAnative/PFgO3/deps/build.log`
┌ Error: Error building `CUDAnative`: 
│ Dependent package CUDAdrv.jl has not been built successfully.
│ 
│ This is not a fatal error, but GPU functionality will be unavailable.
│ If you expected this to work, please open a thread on
│ https://discourse.julialang.org/c/domain/gpu
└ @ Pkg.Operations /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Operations.jl:1075
  Building Conda ───────────→ `~/.julia/packages/Conda/CpuvI/deps/build.log`
  Building FFTW ────────────→ `~/.julia/packages/FFTW/p7sLQ/deps/build.log`
  Building CuArrays ────────→ `~/.julia/packages/CuArrays/qZCAt/deps/build.log`
┌ Error: Error building `CuArrays`: 
│ Dependent package CUDAdrv.jl has not been built successfully
└ @ Pkg.Operations /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Operations.jl:1075```
````

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [April 12, 2019, 1:47am UTC](https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059/2 "2019-04-12T01:47:35Z")

</div>

Do you have the drivers installed? I believe the CUDA drivers are a separate install from the toolkit.

---

<div class="post-metadata">

**Author:** ![mgalenb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgalenb/32/5645_2.png) [@mgalenb](https://discourse.julialang.org/u/mgalenb)\
**Post date:** [April 12, 2019, 1:51am UTC](https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059/3 "2019-04-12T01:51:56Z")

</div>

Yes i have cuda drivers 418 installed and cuda toolkit 9.2 with the patch

---

<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 12, 2019, 6:01am UTC](https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059/4 "2019-04-12T06:01:29Z")

</div>

Copying from Slack (best not to post in multiple places):

> it doesn’t make much sense that calling `cuInit` would return `CUDA_ERROR_NOT_INITIALIZED` (error 3)…  
> the NVIDIA docs also don’t specify that this error could ever be thrown.  
> do you have multiple `libcuda`s in your system? if so, could you try running with `JULIA_DEBUG=CUDAapi`, find out which `libcuda` it detects (it’s in the output), and see if that library is the correct one?

---

<div class="post-metadata">

**Author:** ![mgalenb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgalenb/32/5645_2.png) [@mgalenb](https://discourse.julialang.org/u/mgalenb)\
**Post date:** [April 12, 2019, 9:06pm UTC](https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059/5 "2019-04-12T21:06:10Z")

</div>

Sorry, total n00b to julia here. How do i run with JULIA\_DEBUG=CUDAapi?

also i only have CUDA 9.2 installed as far as i know

---

<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 13, 2019, 6:42am UTC](https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059/6 "2019-04-13T06:42:01Z")

</div>

Specify it as an environment variable, eg. in your command prompt: `JULIA_DEBUG=CUDAapi julia`

---

<div class="post-metadata">

**Author:** ![mgalenb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgalenb/32/5645_2.png) [@mgalenb](https://discourse.julialang.org/u/mgalenb)\
**Post date:** [April 15, 2019, 1:32am UTC](https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059/7 "2019-04-15T01:32:58Z")

</div>

ah got it. i installed CUDA toolkit 10.1. one problem was my environmental variable wasnt set to the cuda install directory. still doesnt build properly after fixing that however. here is the output:

```julia
(v1.1) pkg> build CuArrays
  Building SpecialFunctions → `~/.julia/packages/SpecialFunctions/fvheQ/deps/build.log`
  Building CUDAdrv ─────────→ `~/.julia/packages/CUDAdrv/lu32K/deps/build.log`
┌ Error: Error building `CUDAdrv`: 
│ ┌ Debug: Request to look for binary nvcc
│ │ locations = 0-element Array{String,1}
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/CUDAapi.jl:8
│ ┌ Debug: Looking for binary nvcc
│ │ locations =
│ │ 8-element Array{String,1}:
│ │ "/Users/Galen/.cargo/bin"        
│ │ "/Developer/NVIDIA/CUDA-10.1/bin"
│ │ "/usr/local/bin"                 
│ │ "/usr/bin"                       
│ │ "/bin"                           
│ │ "/usr/sbin"                      
│ │ "/sbin"                          
│ │ "/Library/TeX/texbin"            
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/CUDAapi.jl:8
│ ┌ Debug: Found binary nvcc at /Developer/NVIDIA/CUDA-10.1/bin
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/discovery.jl:142
│ ┌ Debug: Looking for CUDA toolkit via nvcc binary
│ │ path = "/Developer/NVIDIA/CUDA-10.1/bin/nvcc"
│ │ dir = "/Developer/NVIDIA/CUDA-10.1"
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/CUDAapi.jl:8
│ ┌ Debug: Request to look for library cudart
│ │ locations = 0-element Array{String,1}
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/CUDAapi.jl:8
│ ┌ Debug: Looking for library libcudart.dylib, libcudart.dylib.10, libcudart.dylib.10.1, libcudart.dylib.10.0, libcudart.dylib.9, libcudart.dylib.9.2, libcudart.dylib.9.1, libcudart.dylib.9.0, libcudart.dylib.8, libcudart.dylib.8.0, libcudart.dylib.7, libcudart.dylib.7.5, libcudart.dylib.7.0, libcudart.dylib.6, libcudart.dylib.6.5, libcudart.dylib.6.0, libcudart.dylib.5, libcudart.dylib.5.5, libcudart.dylib.5.0, libcudart.dylib.4, libcudart.dylib.4.2, libcudart.dylib.4.1, libcudart.dylib.4.0, libcudart.dylib.3, libcudart.dylib.3.2, libcudart.dylib.3.1, libcudart.dylib.3.0, libcudart.dylib.2, libcudart.dylib.2.2, libcudart.dylib.2.1, libcudart.dylib.2.0, libcudart.dylib.1, libcudart.dylib.1.1, libcudart.dylib.1.0
│ │ locations = 0-element Array{String,1}
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/CUDAapi.jl:8
│ ┌ Debug: Found library libcudart.dylib at /Developer/NVIDIA/CUDA-10.1/lib/libcudart.dylib
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/discovery.jl:91
│ ┌ Debug: Looking for CUDA toolkit via CUDA runtime library
│ │ path = "/Developer/NVIDIA/CUDA-10.1/lib/libcudart.dylib"
│ │ dir = "/Developer/NVIDIA/CUDA-10.1"
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/CUDAapi.jl:8
│ ┌ Debug: Looking for CUDA toolkit via default installation directories
│ │ dirs =
│ │ 1-element Array{Any,1}:
│ │ "/usr/local/cuda"
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/CUDAapi.jl:8
│ ┌ Debug: Found CUDA toolkit at /Developer/NVIDIA/CUDA-10.1, /usr/local/cuda
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/discovery.jl:271
│ ┌ Debug: Request to look for library cuda
│ │ locations =
│ │ 2-element Array{String,1}:
│ │ "/Developer/NVIDIA/CUDA-10.1"
│ │ "/usr/local/cuda"            
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/CUDAapi.jl:8
│ ┌ Debug: Looking for library libcuda.dylib, libcuda.dylib.10, libcuda.dylib.10.1, libcuda.dylib.10.0, libcuda.dylib.9, libcuda.dylib.9.2, libcuda.dylib.9.1, libcuda.dylib.9.0, libcuda.dylib.8, libcuda.dylib.8.0, libcuda.dylib.7, libcuda.dylib.7.5, libcuda.dylib.7.0, libcuda.dylib.6, libcuda.dylib.6.5, libcuda.dylib.6.0, libcuda.dylib.5, libcuda.dylib.5.5, libcuda.dylib.5.0, libcuda.dylib.4, libcuda.dylib.4.2, libcuda.dylib.4.1, libcuda.dylib.4.0, libcuda.dylib.3, libcuda.dylib.3.2, libcuda.dylib.3.1, libcuda.dylib.3.0, libcuda.dylib.2, libcuda.dylib.2.2, libcuda.dylib.2.1, libcuda.dylib.2.0, libcuda.dylib.1, libcuda.dylib.1.1, libcuda.dylib.1.0
│ │ locations =
│ │ 6-element Array{String,1}:
│ │ "/Developer/NVIDIA/CUDA-10.1"      
│ │ "/Developer/NVIDIA/CUDA-10.1/lib"  
│ │ "/Developer/NVIDIA/CUDA-10.1/lib64"
│ │ "/usr/local/cuda"                  
│ │ "/usr/local/cuda/lib"              
│ │ "/usr/local/cuda/lib64"            
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/CUDAapi.jl:8
│ ┌ Debug: Found library /usr/local/cuda/lib/libcuda.dylib at /usr/local/cuda/lib/libcuda.dylib
│ └ @ CUDAapi ~/.julia/packages/CUDAapi/0Ozyy/src/discovery.jl:91
│ Initializing CUDA driver failed with code 3..
└ @ Pkg.Operations /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Operations.jl:1075
  Building LLVM ────────────→ `~/.julia/packages/LLVM/tg8MX/deps/build.log`
  Building CUDAnative ──────→ `~/.julia/packages/CUDAnative/PFgO3/deps/build.log`
┌ Error: Error building `CUDAnative`: 
│ Dependent package CUDAdrv.jl has not been built successfully.
│ 
│ This is not a fatal error, but GPU functionality will be unavailable.
│ If you expected this to work, please open a thread on
│ https://discourse.julialang.org/c/domain/gpu
└ @ Pkg.Operations /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Operations.jl:1075
  Building Conda ───────────→ `~/.julia/packages/Conda/CpuvI/deps/build.log`
  Building FFTW ────────────→ `~/.julia/packages/FFTW/p7sLQ/deps/build.log`
  Building CuArrays ────────→ `~/.julia/packages/CuArrays/qZCAt/deps/build.log`
┌ Error: Error building `CuArrays`: 
│ Dependent package CUDAdrv.jl has not been built successfully
└ @ Pkg.Operations /Users/osx/buildbot/slave/package_osx64/build/usr/share/julia/stdlib/v1.1/Pkg/src/Operations.jl:1075

```

---

<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 15, 2019, 5:22am UTC](https://discourse.julialang.org/t/i-am-getting-an-error-when-building-cuarrays/23059/8 "2019-04-15T05:22:54Z")

</div>

> [@mgalenb](#):
>
> one problem was my environmental variable wasnt set to the cuda install directory.

That shouldn’t be necessary. CUDAapi.jl should detect your CUDA installation.

I’m afraid I can’t help though. It looks like `libcuda` gets picked up correctly, but doesn’t initialize. Can you try the following:

```julia
julia -e 'using Libdl; @show ccall((:cuInit, "/usr/local/cuda/lib/libcuda.dylib"), Cint, (Cint,), 0)'

```

Can you also test whether CUDA C programs work (just try some GPU hello world)?
