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

Bugged Sparse Matrix-Dense matrix multiplication, where dense matrix is transposed #77

Closed
irhum opened this issue May 23, 2020 · 2 comments
Labels
bug Something isn't working cuda array Stuff about CuArray.

Comments

@irhum
Copy link
Contributor

irhum commented May 23, 2020

Describe the bug
Given A and B are two matrices, where A is of type CuSparseMatrixCSC and B is a regular CuArray (for simplicity assume both are square)

A * B works
transpose(A) * B works
A * transpose(B) does not work
transpose(A) * transpose(B) does not work

The implementations of mul! are there on line 20 and line 22 of CuArrays/src/sparse/interfaces.jl, but instead of them being called properly, both of the failing multiplications throw a scalar getindex is disallowed, suggesting it may be defaulting to a generic method?

To Reproduce
The Minimal Working Example (MWE) for this bug:

using CuArrays
using SparseArrays
using LinearAlgebra

CuArrays.allowscalar(false)

randsparse_cpu = SparseMatrixCSC{Float32, Int32}(sprand(3000, 3000, 0.0008))
sparsecscmatrix = CUSPARSE.CuSparseMatrixCSC(randsparse)

densematrix = cu(rand(Float32, 3000, 3000))

sparsecscmatrix * densematrix
transpose(sparsecscmatrix) * densematrix
sparsecscmatrix * transpose(densematrix) # throws scalar getindex is disallowed, should throw different error
transpose(sparsecscmatrix) * transpose(densematrix) # throws scalar getindex is disallowed, should throw no error

Expected behavior
three of the multiplications should complete correctly, while sparsecscmatrix * transpose(densematrix) should throw a CUSPARSE error (CUSPARSE does not support 'N', 'T' multiplications for CSC matrices)

Build log

# post the output of Pkg.build()
# make sure the error still reproduces after that.
   Building TimeZones → `~/.julia/packages/TimeZones/OjMoF/deps/build.log`
   Building HDF5 ─────→ `~/.julia/packages/HDF5/pAi1D/deps/build.log`
   Building CodecZlib → `~/.julia/packages/CodecZlib/5t9zO/deps/build.log`
   Building NNlib ────→ `~/.julia/packages/NNlib/FAI3o/deps/build.log`
   Building Conda ────→ `~/.julia/packages/Conda/3rPhK/deps/build.log`
   Building PyCall ───→ `~/.julia/packages/PyCall/zqDXB/deps/build.log`
   Building WebIO ────→ `~/.julia/packages/WebIO/nTMDV/deps/build.log`

error still reproduces

Environment details (please complete this section)
Details on Julia:

# please post the output of:
versioninfo()
Julia Version 1.4.1
Commit 381693d3df* (2020-04-14 17:20 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, haswell)
Environment:
  JULIA_NUM_THREADS = 4

Julia packages:

  • CuArrays.jl:
  • CUDAnative.jl:
  • SparseArrays
  • LinearAlgebra

CUDA: toolkit and driver version
10.2, 440.64

Additional context
Add any other context about the problem here.

@irhum
Copy link
Contributor Author

irhum commented May 23, 2020

with some further checking with the @which macro,

@which mul!(similar(densematrix, Float32, (size(sparsecscmatrix,1), size(densematrix,2))), sparsecscmatrix, densematrix)
# mul!(C::CuArray{T,2,P} where P, #A::Union{CuArrays.CUSPARSE.CuSparseMatrixBSR{T}, CuArrays.CUSPARSE.CuSparseMatrixCSC{T}, CuArrays.CUSPARSE.CuSparseMatrixCSR{T}, CuArrays.CUSPARSE.CuSparseMatrixHYB{T}}, B::CuArray{T,2,P} where P) where T at CuArrays/l0gXB/src/sparse/interfaces.jl:19

densematrix_T = transpose(densematrix)
@which mul!(similar(densematrix_T, Float32, (size(sparsecscmatrix,1), size(densematrix_T,2))), sparsecscmatrix, densematrix_T)
# mul!(C, A, B) at stdlib/v1.4/LinearAlgebra/src/matmul.jl:208

not quite sure why the latter isn't picking the appropriate method and falling back to the generic

@maleadt maleadt transferred this issue from JuliaGPU/CuArrays.jl May 27, 2020
@maleadt maleadt added bug Something isn't working cuda array Stuff about CuArray. labels May 27, 2020
@irhum
Copy link
Contributor Author

irhum commented May 27, 2020

Solved by #180, closing issue

@irhum irhum closed this as completed May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cuda array Stuff about CuArray.
Projects
None yet
Development

No branches or pull requests

2 participants