Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CUSPARSE] Type error with mm! #1743

Closed
gautierronan opened this issue Jan 25, 2023 · 1 comment
Closed

[CUSPARSE] Type error with mm! #1743

gautierronan opened this issue Jan 25, 2023 · 1 comment

Comments

@gautierronan
Copy link

Using mm! with a type T = ComplexF64 returns the following error.

using LinearAlgebra
using SparseArrays
using CUDA

T = ComplexF64
N = 100
A = cu(sprand(T, N, N, 0.1))
X = cu(rand(T, N, N))
Y = cu(zeros(T, N, N))

println(typeof(A))
println(typeof(X))
println(typeof(Y))

CUSPARSE.mm!('N', 'N', T(1.0), A, X, T(0.0), Y, 'O')
 > julia benchmark_mul_GPU.jl 
CUDA.CUSPARSE.CuSparseMatrixCSC{ComplexF64, Int32}
CuArray{ComplexF32, 2, CUDA.Mem.DeviceBuffer}
CuArray{ComplexF32, 2, CUDA.Mem.DeviceBuffer}
ERROR: LoadError: MethodError: no method matching mm!(::Char, ::Char, ::ComplexF64, ::CUDA.CUSPARSE.CuSparseMatrixCSC{ComplexF64, Int32}, ::CuArray{ComplexF32, 2, CUDA.Mem.DeviceBuffer}, ::ComplexF64, ::CuArray{ComplexF32, 2, CUDA.Mem.DeviceBuffer}, ::Char)
Closest candidates are:
  mm!(::Char, ::Char, ::Number, ::CUDA.CUSPARSE.CuSparseMatrixBSR{ComplexF32}, ::StridedCuMatrix{ComplexF32}, ::Number, ::StridedCuMatrix{ComplexF32}, ::Char) at ~/.julia/packages/CUDA/BbliS/lib/cusparse/level3.jl:21
  mm!(::Char, ::Char, ::Number, ::CUDA.CUSPARSE.CuSparseMatrixCSR{T}, ::CuArray{T, 2}, ::Number, ::CuArray{T, 2}, ::Char) where T at ~/.julia/packages/CUDA/BbliS/lib/cusparse/generic.jl:197
  mm!(::Char, ::Char, ::Number, ::CUDA.CUSPARSE.CuSparseMatrixCSR{T}, ::CuArray{T, 2}, ::Number, ::CuArray{T, 2}, ::Char, ::CUDA.CUSPARSE.cusparseSpMMAlg_t) where T at ~/.julia/packages/CUDA/BbliS/lib/cusparse/generic.jl:197
  ...
Stacktrace:
 [1] top-level scope

For T = Float32 instead, the error returned is

ERROR: LoadError: 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:35
  [2] assertscalar(op::String)
    @ GPUArraysCore ~/.julia/packages/GPUArraysCore/B3xv7/src/GPUArraysCore.jl:100
  [3] getindex(xs::CuArray{Int32, 1, CUDA.Mem.DeviceBuffer}, I::Int64)
    @ GPUArrays ~/.julia/packages/GPUArrays/w0b6Z/src/host/indexing.jl:9
  [4] getindex(A::CUDA.CUSPARSE.CuSparseMatrixCSC{Float32, Int32}, i0::Int64, i1::Int64)
    @ CUDA.CUSPARSE ~/.julia/packages/CUDA/BbliS/lib/cusparse/array.jl:311
  [5] isassigned(::CUDA.CUSPARSE.CuSparseMatrixCSC{Float32, Int32}, ::Int64, ::Int64)
    @ Base ./abstractarray.jl:565
  [6] _show_nonempty(io::IOContext{IOBuffer}, X::AbstractMatrix, prefix::String, drop_brackets::Bool, axs::Tuple{Base.OneTo{Int64}, Base.OneTo{Int64}})
    @ Base ./arrayshow.jl:441
  [7] _show_nonempty(io::IOContext{IOBuffer}, X::CUDA.CUSPARSE.CuSparseMatrixCSC{Float32, Int32}, prefix::String)
    @ Base ./arrayshow.jl:413
  [8] show
    @ ./arrayshow.jl:489 [inlined]
  [9] print(io::IOBuffer, x::CUDA.CUSPARSE.CuSparseMatrixCSC{Float32, Int32})
    @ Base ./strings/io.jl:35
 [10] print_to_string(::String, ::Vararg{Any})
    @ Base ./strings/io.jl:144
 [11] string(::String, ::CuArray{Float32, 2, CUDA.Mem.DeviceBuffer}, ::Vararg{Any})
    @ Base ./strings/io.jl:185
 [12] top-level scope
@gautierronan gautierronan added the bug Something isn't working label Jan 25, 2023
@maleadt
Copy link
Member

maleadt commented Jan 25, 2023

mm!(::Char, ::Char, ::ComplexF64, ::CUDA.CUSPARSE.CuSparseMatrixCSC{ComplexF64, Int32}, ::CuArray{ComplexF32, 2, CUDA.Mem.DeviceBuffer}, ::ComplexF64, ::CuArray{ComplexF32, 2, CUDA.Mem.DeviceBuffer}, ::Char)

You are mixing types, ComplexF32 and ComplexF64. mm! and friends are low-level methods that do not convert arguments. cu auto-promotes to 32-bits float, see the docstring (so here you just want to use the CuArray constructor).

@maleadt maleadt closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2023
@maleadt maleadt removed the bug Something isn't working label Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants