Hi,
I have a problem with Convolutional layers on gpu. It simply does not work. I have installed CUDA and cuDNN. GPU works for “simple” layers like Dense, LayerNorm etc, but when i try evaluate Conv it gives me an error.
julia> CUDA.versioninfo()
CUDA toolchain:
- runtime 13.2.0, artifact installation
- unknown driver for 13.2
- compiler 13.3.33, artifact installation
CUDA libraries:
- cuBLAS: 13.4.0
- cuSPARSE: 12.7.10
- cuSOLVER: 12.2.0
- cuFFT: 12.2.0
- cuRAND: 10.4.2
- CUPTI: 2026.1.1 (API 13.2.1)
- NVML: missing
Julia packages:
- CUDACore: 6.2.1
- GPUArrays: 11.5.9
- GPUCompiler: 1.23.0
- KernelAbstractions: 0.9.42
- CUDA_Driver_jll: 13.3.0+1
- CUDA_Compiler_jll: 0.4.4+1
- CUDA_Runtime_jll: 0.23.0+1
- NVPTX_LLVM_Backend_jll: 22.1.7+1
Toolchain:
- Julia: 1.12.6
- LLVM: 18.1.7
Preferences:
- CUDA_Runtime_jll.version: 13.2
1 device:
0: NVIDIA GeForce RTX 4070 SUPER (sm_89, 10.812 GiB / 11.994 GiB available)
compiles to sm_89 / PTX 9.3 (LLVM: sm_89 / PTX 9.0)
MWE:
using CUDA, Flux
T = Float32
x = randn(T, 28,28,1,16);
xg = cu(x);
c = Flux.Conv((4, 4), 1=>2, relu; stride=2, pad=0);
cg = cu(c);
d = Flux.Dense(28*28, 128, relu)
dg = cu(d)
d(reshape(x, :, 16))
dg(reshape(xg, :, 16))
c(x)
cg(xg) # -> error here!!
julia> cg(xg)
ERROR: Scalar indexing is disallowed.
Invocation of getindex resulted in scalar indexing of a GPU array.
This is typically caused by calling an iterating implementation of a method.
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore should be avoided.
If you want to allow scalar iteration, use `allowscalar` or `@allowscalar`
to enable scalar iteration globally or for the operations in question.
Stacktrace:
[1] error(s::String)
@ Base .\error.jl:44
[2] errorscalar(op::String)
@ GPUArraysCore C:\Users\ghost_000\.julia\packages\GPUArraysCore\aNaXo\src\GPUArraysCore.jl:151
[3] _assertscalar(op::String, behavior::GPUArraysCore.ScalarIndexing)
@ GPUArraysCore C:\Users\ghost_000\.julia\packages\GPUArraysCore\aNaXo\src\GPUArraysCore.jl:124
[4] assertscalar(op::String)
@ GPUArraysCore C:\Users\ghost_000\.julia\packages\GPUArraysCore\aNaXo\src\GPUArraysCore.jl:112
[5] getindex
@ C:\Users\ghost_000\.julia\packages\GPUArrays\usFEA\src\host\indexing.jl:50 [inlined]
[6] scalar_getindex
@ C:\Users\ghost_000\.julia\packages\GPUArrays\usFEA\src\host\indexing.jl:36 [inlined]
[7] _getindex
@ C:\Users\ghost_000\.julia\packages\GPUArrays\usFEA\src\host\indexing.jl:19 [inlined]
[8] getindex
@ C:\Users\ghost_000\.julia\packages\GPUArrays\usFEA\src\host\indexing.jl:17 [inlined]
[9] getindex
@ .\subarray.jl:316 [inlined]
[10] im2col!(col::CuArray{…}, x::SubArray{…}, cdims::DenseConvDims{…}; w_range::Nothing, h_range::Nothing, d_range::Nothing)
@ NNlib C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\impl\conv_im2col.jl:329
[11] im2col!
@ C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\impl\conv_im2col.jl:266 [inlined]
[12] (::NNlib.var"#batch_task#539"{…})(task_n::Int64, part::UnitRange{…})
@ NNlib C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\impl\conv_im2col.jl:69
[13] conv_im2col!(y::SubArray{…}, x::SubArray{…}, w::CuArray{…}, cdims::DenseConvDims{…}; col::CuArray{…}, alpha::Float32, beta::Float32, ntasks::Int64)
@ NNlib C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\impl\conv_im2col.jl:85
[14] conv_im2col!
@ C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\impl\conv_im2col.jl:23 [inlined]
[15] (::NNlib.var"#conv_group#165"{…})(gi::Int64, col::CuArray{…}, ntasks::Int64)
@ NNlib C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\conv.jl:263
[16] run_grouped_im2col!(worker::NNlib.var"#conv_group#165"{…}, ngroups::Int64, refarr::CuArray{…}, M::Int64, K::Int64, inner_threaded::Bool)
@ NNlib C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\conv.jl:236
[17] conv!(out::CuArray{…}, in1::CuArray{…}, in2::CuArray{…}, cdims::DenseConvDims{…}; kwargs::@Kwargs{})
@ NNlib C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\conv.jl:266
[18] conv!
@ C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\conv.jl:294 [inlined]
[19] conv!(y::CuArray{…}, x::CuArray{…}, w::CuArray{…}, cdims::DenseConvDims{…}; kwargs::@Kwargs{})
@ NNlib C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\conv.jl:161
[20] conv!
@ C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\conv.jl:156 [inlined]
[21] conv(x::CuArray{…}, w::CuArray{…}, cdims::DenseConvDims{…}; kwargs::@Kwargs{})
@ NNlib C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\conv.jl:121
[22] conv
@ C:\Users\ghost_000\.julia\packages\NNlib\ZxpGZ\src\conv.jl:116 [inlined]
[23] (::Conv{2, 4, typeof(relu), CuArray{…}, CuArray{…}})(x::CuArray{Float32, 4, CUDACore.DeviceMemory})
@ Flux C:\Users\ghost_000\.julia\packages\Flux\c30bR\src\layers\conv.jl:201
[24] top-level scope
@ REPL[21]:1
Some type information was truncated. Use `show(err)` to see complete types.
Does anyone know what is the problem?