JuliaGPU/CUDA.jl

Option for deterministic sparse matrix vector multiplication

Open

#1,607 opened on Sep 30, 2022

View on GitHub
 (2 comments) (0 reactions) (0 assignees)Julia (274 forks)batch import
cuda librariesenhancementgood first issue

Repository metrics

Stars
 (1,408 stars)
PR merge metrics
 (Avg merge 5d 5h) (16 merged PRs in 30d)

Description

I would like to request deterministic sparse matrix vector multiplications. Essentially, the following code should always return the same result:

using CUDA
using Random

Random.seed!(546784)

A = cu(sprand(Float64, 1000, 1000, 0.6))
x = cu(rand(Float64, 1000))

y1 = A * x
y2 = A * x

maximum(abs.(y2 - y1))

A similar issue is #938.

What I found out so far

We need to use CUSPARSE_SPMV_COO_ALG2 or CUSPARSE_SPMV_CSR_ALG2. This will probably be related to changing the argument algo of mv!(): https://github.com/JuliaGPU/CUDA.jl/blob/33a71872b0aebe13f8210229e1265b779f90b78e/lib/cusparse/generic.jl#L112-L113

Unfortunately, the algorithm information seems to get lost in the wrapper function: https://github.com/JuliaGPU/CUDA.jl/blob/99f962abb8296e36f58963c80a4b52cc116e6560/lib/cusparse/interfaces.jl#L6-L9

The wrapper seems to be used for implementing the operators: https://github.com/JuliaGPU/CUDA.jl/blob/99f962abb8296e36f58963c80a4b52cc116e6560/lib/cusparse/interfaces.jl#L38-L60

The remaining question for the maintainers is now: Where do we pass in the algorithm?

Contributor guide