Repository: JuliaGPU/CUDA.jl

Issue #1406: CUSPARSE does not support reductions
Created: 2022-02-24T15:06:59Z
On master, even the simplest reduction fails:
julia> using CUDA, CUDA.CUSPARSE, Random, SparseArrays

julia> x = sprand(3, 3, 0.5) |> CuSparseMatrixCSR
3×3 CuSparseMatrixCSR{Float64, Int32} with 4 stored entries:
  ⋅                  0.33280841492717694   ⋅ 
 0.2627012132720039  0.2749904007443871    ⋅ 
  ⋅                   ⋅                   0.009417688176282524

julia> sum(x)
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 are only permitted from the REPL for prototyping purposes.
If you did intend to index this array, annotate the caller with @allowscalar.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] assertscalar(op::String)
    @ GPUArrays ~/.julia/packages/GPUArrays/umZob/src/host/indexing.jl:53
  [3] getindex(xs::CuArray{Int32, 1, CUDA.Mem.DeviceBuffer}, I::Int64)
    @ GPUArrays ~/.julia/packages/GPUArrays/umZob/src/host/indexing.jl:86
  [4] getindex(A::CuSparseMatrixCSR{Float64, Int32}, i0::Int64, i1::Int64)
    @ CUDA.CUSPARSE ~/.julia/packages/CUDA/BJT41/lib/cusparse/array.jl:312
  [5] _getindex
    @ ./abstractarray.jl:1262 [inlined]
  [6] getindex
    @ ./abstractarray.jl:1218 [inlined]
  [7] iterate
    @ ./abstractarray.jl:1144 [inlined]
  [8] iterate
    @ ./abstractarray.jl:1142 [inlined]
  [9] _foldl_impl
    @ ./reduce.jl:56 [inlined]
 [10] foldl_impl(op::Base.BottomRF{typeof(Base.add_sum)}, nt::Base._InitialValue, itr::CuSparseMatrixCSR{Float64, Int32})
    @ Base ./reduce.jl:48
 [11] mapfoldl_impl
    @ ./reduce.jl:44 [inlined]
 [12] #mapfoldl#244
    @ ./reduce.jl:162 [inlined]
 [13] mapfoldl
    @ ./reduce.jl:162 [inlined]
 [14] _mapreduce
    @ ./reduce.jl:423 [inlined]
 [15] _mapreduce_dim
    @ ./reducedim.jl:330 [inlined]
 [16] #mapreduce#725
    @ ./reducedim.jl:322 [inlined]
 [17] mapreduce
    @ ./reducedim.jl:322 [inlined]
 [18] #_sum#735
    @ ./reducedim.jl:894 [inlined]
 [19] _sum
    @ ./reducedim.jl:894 [inlined]
 [20] #_sum#734
    @ ./reducedim.jl:893 [inlined]
 [21] _sum
    @ ./reducedim.jl:893 [inlined]
 [22] #sum#732
    @ ./reducedim.jl:889 [inlined]
 [23] sum(a::CuSparseMatrixCSR{Float64, Int32})
    @ Base ./reducedim.jl:889
 [24] top-level scope
    @ REPL[49]:1
 [25] top-level scope
    @ ~/.julia/packages/CUDA/BJT41/src/initialization.jl:52
I get a similar errors with CuSparseMatrixCSC and sum(x; dims=1).

Duplicate issue #1460: norm does not dispatch on CuSparseMatrixCSC 
Created: 2022-04-04T10:58:30Z
The norm function does not dispatch, when applied to a matrix of type CuSparseMatrixCSC.
To reproduce
using CUDA, CUDA.CUSPARSE, LinearAlgebra, SparseArrays
CUDA.allowscalar(false)
A = CuSparseMatrixCSC(spzeros(Float32,50, 50))
norm(A)
Manifest.toml

# This file is machine-generated - editing it directly is not advised

julia_version = "1.7.2"
manifest_format = "2.0"

[[deps.CUDA]]
deps = ["AbstractFFTs", "Adapt", "BFloat16s", "CEnum", "CompilerSupportLibraries_jll", "ExprTools", "GPUArrays", "GPUCompiler", "LLVM", "LazyArtifacts", "Libdl", "LinearAlgebra", "Logging", "Printf", "Random", "Random123", "RandomNumbers", "Reexport", "Requires", "SparseArrays", "SpecialFunctions", "TimerOutputs"]
git-tree-sha1 = "a28686d7c83026069cc2505016269cca77506ed3"
uuid = "052768ef-5323-5732-b1bb-66c8b64840ba"
version = "3.8.5"



Expected behavior
norm(cu(A)) == norm(A)
Version info
Details on Julia:
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: AMD EPYC 7742 64-Core Processor
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, znver2)

Details on CUDA:
CUDA toolkit 11.6, artifact installation
NVIDIA driver 450.51.6, for CUDA 11.5
CUDA driver 11.6

Libraries: 
- CUBLAS: 11.8.1
- CURAND: 10.2.9
- CUFFT: 10.7.0
- CUSOLVER: 11.3.2
- CUSPARSE: 11.7.1
- CUPTI: 16.0.0
- NVML: 11.0.0+450.51.6

Toolchain:
- Julia: 1.7.2
- LLVM: 12.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
- 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

1 device:
  0: A100-SXM4-40GB (sm_80, 38.677 GiB / 39.587 GiB available)

Additional context

Closing comment (2022-04-05T10:31:09Z): The norm function does not dispatch, when applied to a matrix of type CuSparseMatrixCSC.

Dispatch to what? CUSPARSE doesn't provide an implementation of norm AFAIK. And a native implementation is not going to happen soon, so let's close this as a dup of #1406.