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?

贡献者指南