JuliaGPU/CUDA.jl

Option for deterministic sparse matrix vector multiplication

Open

#1,607 建立於 2022年9月30日

在 GitHub 查看
 (2 留言) (0 反應) (0 負責人)Julia (274 fork)batch import
cuda librariesenhancementgood first issue

倉庫指標

Star
 (1,408 star)
PR 合併指標
 (平均合併 5天 5小時) (30 天內合併 16 個 PR)

描述

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?

貢獻者指南