CUDA does not successfully initialise

I installed CUDA by ]add CUDA and tried to test it by test CUDA.
However, I encountered the below error message.

CUDA initialisation error

ERROR: LoadError: CUDA.jl did not successfully initialize, and is not usable.
If you did not see any other error message, try again in a new session
with the JULIA_DEBUG environment variable set to 'CUDA'.

And this message is popped up every time I try to use any functionality of CUDA, for example,

cu error

julia> using CUDA

julia> cu(rand(5))
ERROR: CUDA.jl did not successfully initialize, and is not usable.
If you did not see any other error message, try again in a new session
with the JULIA_DEBUG environment variable set to 'CUDA'.
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] libcuda() at /home/jinrae/.julia/packages/CUDA/YeS8q/src/initialization.jl:51
 [3] (::CUDA.var"#690#cache_fptr!#9")() at /home/jinrae/.julia/packages/CUDA/YeS8q/lib/utils/call.jl:31
 [4] macro expansion at /home/jinrae/.julia/packages/CUDA/YeS8q/lib/utils/call.jl:39 [inlined]
 [5] macro expansion at /home/jinrae/.julia/packages/CUDA/YeS8q/lib/cudadrv/libcuda.jl:29 [inlined]
 [6] macro expansion at /home/jinrae/.julia/packages/CUDA/YeS8q/lib/cudadrv/error.jl:102 [inlined]
 [7] cuDeviceGet(::Base.RefValue{Int32}, ::Int64) at /home/jinrae/.julia/packages/CUDA/YeS8q/lib/utils/call.jl:93
 [8] CuDevice(::Int64) at /home/jinrae/.julia/packages/CUDA/YeS8q/lib/cudadrv/devices.jl:25
 [9] initialize_thread(::Int64) at /home/jinrae/.julia/packages/CUDA/YeS8q/src/state.jl:121
 [10] prepare_cuda_call() at /home/jinrae/.julia/packages/CUDA/YeS8q/src/state.jl:80
 [11] device at /home/jinrae/.julia/packages/CUDA/YeS8q/src/state.jl:227 [inlined]
 [12] alloc at /home/jinrae/.julia/packages/CUDA/YeS8q/src/pool.jl:293 [inlined]
 [13] CuArray{Float32,1}(::UndefInitializer, ::Tuple{Int64}) at /home/jinrae/.julia/packages/CUDA/YeS8q/src/array.jl:20
 [14] CuArray at /home/jinrae/.julia/packages/CUDA/YeS8q/src/array.jl:76 [inlined]
 [15] similar at ./abstractarray.jl:675 [inlined]
 [16] convert(::Type{CuArray{Float32,N} where N}, ::Array{Float64,1}) at /home/jinrae/.julia/packages/GPUArrays/jhRU7/src/host/construction.jl:82
 [17] adapt_storage at /home/jinrae/.julia/packages/CUDA/YeS8q/src/array.jl:330 [inlined]
 [18] adapt_structure at /home/jinrae/.julia/packages/Adapt/8kQMV/src/Adapt.jl:42 [inlined]
 [19] adapt at /home/jinrae/.julia/packages/Adapt/8kQMV/src/Adapt.jl:40 [inlined]
 [20] cu(::Array{Float64,1}) at /home/jinrae/.julia/packages/CUDA/YeS8q/src/array.jl:342
 [21] top-level scope at REPL[7]:1

Note: this is the result of nvidia-smi. It seems not use GPU at all when I tried to train a neural network by Flux.

What should I do?

nvidia-smi

➜  GliderPathPlanning git:(using-gpu) ✗ nvidia-smi
Fri Jan  1 00:28:32 2021
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 455.45.01    Driver Version: 455.45.01    CUDA Version: 11.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce RTX 207...  Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   54C    P8    10W /  N/A |   1500MiB /  7982MiB |     34%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1092      G   /usr/lib/xorg/Xorg                134MiB |
|    0   N/A  N/A      1852      G   /usr/lib/xorg/Xorg                840MiB |
|    0   N/A  N/A      2040      G   /usr/bin/gnome-shell              230MiB |
|    0   N/A  N/A      2306      G   ...mviewer/tv_bin/TeamViewer        2MiB |
|    0   N/A  N/A    673753      G   ...AAAAAAAA== --shared-files      100MiB |
|    0   N/A  N/A    673779      G   ...AAAAAAAA== --shared-files      176MiB |
+-----------------------------------------------------------------------------+

CUDA.has_cuda()

julia> CUDA.has_cuda()
false

I don’t know why but after turned off my laptop the error disappeared.
I have no idea why it works :frowning:

Did you try that suggestion?