JuliaGPU/CUDA.jl

Option for deterministic sparse matrix vector multiplication

Open

#1.607 geöffnet am 30. Sept. 2022

Auf GitHub ansehen
 (2 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Julia (274 Forks)batch import
cuda librariesenhancementgood first issue

Repository-Metriken

Stars
 (1.408 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 5T 5h) (16 gemergte PRs in 30 T)

Beschreibung

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