# UndefVarError while importing CUDA

**URL:** <https://discourse.julialang.org/t/undefvarerror-while-importing-cuda/67872>\
**Category:** Machine Learning\
**Created:** [September 8, 2021, 12:34pm UTC](https://discourse.julialang.org/t/undefvarerror-while-importing-cuda/67872 "2021-09-08T12:34:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamza\_Coban](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamza_coban/32/28963_2.png) [@Hamza\_Coban](https://discourse.julialang.org/u/Hamza_Coban)\
**Post date:** [September 8, 2021, 12:34pm UTC](https://discourse.julialang.org/t/undefvarerror-while-importing-cuda/67872/1 "2021-09-08T12:34:37Z")

</div>

Hi all,

I have issues on importing CUDA package. Only active packages are Knet and CUDA. The error as follows when I run “import CUDA” :

Info: Precompiling CUDA [052768ef-5323-5732-b1bb-66c8b64840ba]  
└ @ Base loading.jl:1278  
ERROR: LoadError: LoadError: UndefVarError: finish\_module! not defined  
Stacktrace:  
[1] getproperty(::Module, ::Symbol) at ./Base.jl:26  
[2] top-level scope at /kuacc/users/hcoban15/.julia/packages/CUDA/mbPFj/src/compiler/gpucompiler.jl:14  
[3] include(::Function, ::Module, ::String) at ./Base.jl:380  
[4] include at ./Base.jl:368 [inlined]  
[5] include(::String) at /kuacc/users/hcoban15/.julia/packages/CUDA/mbPFj/src/CUDA.jl:1  
[6] top-level scope at /kuacc/users/hcoban15/.julia/packages/CUDA/mbPFj/src/CUDA.jl:52  
[7] include(::Function, ::Module, ::String) at ./Base.jl:380  
[8] include(::Module, ::String) at ./Base.jl:368  
[9] top-level scope at none:2  
[10] eval at ./boot.jl:331 [inlined]  
[11] eval(::Expr) at ./client.jl:467  
[12] top-level scope at ./none:3  
in expression starting at /kuacc/users/hcoban15/.julia/packages/CUDA/mbPFj/src/compiler/gpucompiler.jl:14  
in expression starting at /kuacc/users/hcoban15/.julia/packages/CUDA/mbPFj/src/CUDA.jl:52  
Failed to precompile CUDA [052768ef-5323-5732-b1bb-66c8b64840ba] to /kuacc/users/hcoban15/.julia/compiled/v1.5/CUDA/oWw5k\_IvUFl.ji.

---

<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:** [September 8, 2021, 1:24pm UTC](https://discourse.julialang.org/t/undefvarerror-while-importing-cuda/67872/2 "2021-09-08T13:24:44Z")

</div>

Which version of CUDA.jl and GPUCompiler.jl?  
It’s also recommended to upgrade to Julia 1.6.

---

<div class="post-metadata">

**Author:** ![Hamza\_Coban](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hamza_coban/32/28963_2.png) [@Hamza\_Coban](https://discourse.julialang.org/u/Hamza_Coban)\
**Post date:** [September 8, 2021, 1:32pm UTC](https://discourse.julialang.org/t/undefvarerror-while-importing-cuda/67872/3 "2021-09-08T13:32:29Z")

</div>

I must use Julia 1.5.3.

The versions are CUDA v2.4.3 GPUCompiler v0.8.3

---

<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:** [September 8, 2021, 3:15pm UTC](https://discourse.julialang.org/t/undefvarerror-while-importing-cuda/67872/4 "2021-09-08T15:15:11Z")

</div>

Works for me:

```julia
tim@taurus ~$ JULIA_VERSION=1.5 jl                                                                                                                                                                           
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.5.4 (2021-03-11)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

(@v1.5) pkg> activate --temp
 Activating new environment at `/tmp/jl_u8TlT7/Project.toml`

(jl_u8TlT7) pkg> add CUDA
   Updating registry at `~/.julia/registries/General`
######################################################################## 100,0%
  Resolving package versions...
  Installed NNlib ────────── v0.7.19
  Installed ChainRulesCore ─ v0.9.45
  Installed TOML ─────────── v1.0.3
  Installed CUDA ─────────── v2.4.3
Updating `/tmp/jl_u8TlT7/Project.toml`
  [052768ef] + CUDA v2.4.3
Updating `/tmp/jl_u8TlT7/Manifest.toml`
  [052768ef] + CUDA v2.4.3
  [61eb1bfa] + GPUCompiler v0.8.3

julia> using CUDA

julia> CuArray([1]).+1
1-element CuArray{Int64,1}:
 2

julia> pathof(CUDA)
"/home/tim/.julia/packages/CUDA/mbPFj/src/CUDA.jl"

julia> pathof(CUDA.GPUCompiler)
"/home/tim/.julia/packages/GPUCompiler/uTpNx/src/GPUCompiler.jl"

shell> rg finish_module /home/tim/.julia/packages/CUDA/mbPFj/src/
/home/tim/.julia/packages/CUDA/mbPFj/src/compiler/gpucompiler.jl
14:function GPUCompiler.finish_module!(job::CUDACompilerJob, mod::LLVM.Module)
15: invoke(GPUCompiler.finish_module!,

shell> rg finish_module /home/tim/.julia/packages/GPUCompiler/uTpNx/src
/home/tim/.julia/packages/GPUCompiler/uTpNx/src/spirv.jl
53:function finish_module!(job::CompilerJob{SPIRVCompilerTarget}, mod::LLVM.Module)

/home/tim/.julia/packages/GPUCompiler/uTpNx/src/interface.jl
144:finish_module!(::CompilerJob, mod::LLVM.Module) = return

/home/tim/.julia/packages/GPUCompiler/uTpNx/src/driver.jl
234: finish_module!(job, ir)

```
