JuliaGPU/CUDA.jl

[CUSPARSE] error in conversion of CuSparseMatrix{Int} to dense matrices

Open

#1 664 ouverte le 6 nov. 2022

Voir sur GitHub
 (1 commentaire) (0 réactions) (0 assignés)Julia (274 forks)batch import
bugcuda librariesgood first issue

Métriques du dépôt

Stars
 (1 408 stars)
Métriques de merge PR
 (Merge moyen 5j 5h) (16 PRs mergées en 30 j)

Description

Cusparse matrices with float eltype are correctly converted to dense arrays:

julia> using CUDA, SparseArrays

julia> x = sparse([1, 2], [1, 2], [10.0, 20.0]) |> cu
2×2 CuSparseMatrixCSC{Float32, Int32} with 2 stored entries:
 10.0    ⋅ 
   ⋅   20.0

julia> CuArray(x)
2×2 CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}:
 10.0   0.0
  0.0  20.0

julia> Array(x)
2×2 Matrix{Float32}:
 10.0   0.0
  0.0  20.0

With Int eltype instead, we have the following StackOverflow errors:

julia> x = sparse([1,2], [1,2], [10, 20]) |> cu
2×2 CuSparseMatrixCSC{Int64, Int32} with 2 stored entries:
 10   ⋅
  ⋅  20

julia> CuArray(x)
ERROR: StackOverflowError:
Stacktrace:
     [1] macro expansion
       @ ~/.julia/dev/CUDA/lib/cudadrv/libcuda.jl:3136 [inlined]
     [2] cuMemAllocAsync(dptr::Base.RefValue{CuPtr{Nothing}}, bytesize::Int64, hStream::CuStream)
       @ CUDA ~/.julia/dev/CUDA/lib/utils/call.jl:26
     [3] #alloc#1
       @ ~/.julia/dev/CUDA/lib/cudadrv/memory.jl:83 [inlined]
     [4] actual_alloc(bytes::Int64; async::Bool, stream::CuStream)
       @ CUDA ~/.julia/dev/CUDA/src/pool.jl:39
     [5] macro expansion
       @ ~/.julia/dev/CUDA/src/pool.jl:222 [inlined]
     [6] macro expansion
       @ ./timing.jl:382 [inlined]
     [7] #_alloc#164
       @ ~/.julia/dev/CUDA/src/pool.jl:303 [inlined]
     [8] #alloc#163
       @ ~/.julia/dev/CUDA/src/pool.jl:289 [inlined]
     [9] alloc
       @ ~/.julia/dev/CUDA/src/pool.jl:283 [inlined]
    [10] CuArray{Int64, 2, CUDA.Mem.DeviceBuffer}(#unused#::UndefInitializer, dims::Tuple{Int64, Int64})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:85
    [11] CuArray{Int64, 2, CUDA.Mem.DeviceBuffer}(xs::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:334
    [12] (CuArray{Int64, 2})(xs::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:339
    [13] copyto!(dest::Matrix{Int64}, src::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA.CUSPARSE ~/.julia/dev/CUDA/lib/cusparse/conversions.jl:596
    [14] copyto_axcheck!(dest::Matrix{Int64}, src::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./abstractarray.jl:1127
    [15] Matrix{Int64}(x::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./array.jl:626
    [16] (Array{Int64})(A::CuSparseMatrixCSC{Int64, Int32})
       @ Core ./boot.jl:484
    [17] convert(#unused#::Type{Array{Int64}}, a::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./array.jl:617
    [18] CuArray{Int64, 2, CUDA.Mem.DeviceBuffer}(xs::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:335
--- the last 7 lines are repeated 11423 more times ---
 [79980] (CuArray{Int64, 2})(xs::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:339
 [79981] copyto!(dest::Matrix{Int64}, src::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA.CUSPARSE ~/.julia/dev/CUDA/lib/cusparse/conversions.jl:596
 [79982] copyto_axcheck!(dest::Matrix{Int64}, src::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./abstractarray.jl:1127
 [79983] Matrix{Int64}(x::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./array.jl:626

julia> Array(x)
ERROR: StackOverflowError:
Stacktrace:
     [1] macro expansion
       @ ~/.julia/dev/CUDA/lib/cudadrv/libcuda.jl:3136 [inlined]
     [2] cuMemAllocAsync(dptr::Base.RefValue{CuPtr{Nothing}}, bytesize::Int64, hStream::CuStream)
       @ CUDA ~/.julia/dev/CUDA/lib/utils/call.jl:26
     [3] #alloc#1
       @ ~/.julia/dev/CUDA/lib/cudadrv/memory.jl:83 [inlined]
     [4] actual_alloc(bytes::Int64; async::Bool, stream::CuStream)
       @ CUDA ~/.julia/dev/CUDA/src/pool.jl:39
     [5] macro expansion
       @ ~/.julia/dev/CUDA/src/pool.jl:222 [inlined]
     [6] macro expansion
       @ ./timing.jl:382 [inlined]
     [7] #_alloc#164
       @ ~/.julia/dev/CUDA/src/pool.jl:303 [inlined]
     [8] #alloc#163
       @ ~/.julia/dev/CUDA/src/pool.jl:289 [inlined]
     [9] alloc
       @ ~/.julia/dev/CUDA/src/pool.jl:283 [inlined]
    [10] CuArray{Int64, 2, CUDA.Mem.DeviceBuffer}(#unused#::UndefInitializer, dims::Tuple{Int64, Int64})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:85
    [11] CuArray{Int64, 2, CUDA.Mem.DeviceBuffer}(xs::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:334
    [12] (CuArray{Int64, 2})(xs::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:339
    [13] copyto!(dest::Matrix{Int64}, src::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA.CUSPARSE ~/.julia/dev/CUDA/lib/cusparse/conversions.jl:596
    [14] copyto_axcheck!(dest::Matrix{Int64}, src::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./abstractarray.jl:1127
    [15] Matrix{Int64}(x::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./array.jl:626
    [16] (Array{Int64})(A::CuSparseMatrixCSC{Int64, Int32})
       @ Core ./boot.jl:484
    [17] convert(#unused#::Type{Array{Int64}}, a::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./array.jl:617
    [18] CuArray{Int64, 2, CUDA.Mem.DeviceBuffer}(xs::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:335
--- the last 7 lines are repeated 11423 more times ---
 [79980] (CuArray{Int64, 2})(xs::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA ~/.julia/dev/CUDA/src/array.jl:339
 [79981] copyto!(dest::Matrix{Int64}, src::CuSparseMatrixCSC{Int64, Int32})
       @ CUDA.CUSPARSE ~/.julia/dev/CUDA/lib/cusparse/conversions.jl:596
 [79982] copyto_axcheck!(dest::Matrix{Int64}, src::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./abstractarray.jl:1127
 [79983] Matrix{Int64}(x::CuSparseMatrixCSC{Int64, Int32})
       @ Base ./array.jl:626

Same errors occur with SparseMatrixCSR and with both Int32 and Int64.

Tested on CUDA.jl master and the following versioninfo

julia> CUDA.versioninfo()
CUDA runtime 11.8, artifact installation
CUDA driver 11.6
NVIDIA driver 510.39.1

Libraries: 
- CUBLAS: 11.11.3
- CURAND: 10.3.0
- CUFFT: 10.9.0
- CUSOLVER: 11.4.1
- CUSPARSE: 11.7.5
- CUPTI: 18.0.0
- NVML: 11.0.0+510.39.1

Toolchain:
- Julia: 1.8.2
- LLVM: 13.0.1
- PTX ISA support: 3.2, 4.0, 4.1, 4.2, 4.3, 5.0, 6.0, 6.1, 6.3, 6.4, 6.5, 7.0, 7.1, 7.2
- Device capability support: sm_35, sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72, sm_75, sm_80, sm_86

4 devices:
  0: Tesla V100-SXM2-32GB (sm_70, 2.550 GiB / 32.000 GiB available)
  1: Tesla V100-SXM2-32GB (sm_70, 21.359 GiB / 32.000 GiB available)
  2: Tesla V100-SXM2-32GB (sm_70, 28.537 GiB / 32.000 GiB available)
  3: Tesla V100-SXM2-32GB (sm_70, 9.699 GiB / 32.000 GiB available)

Guide contributeur