Repository navigation
Update CUSPARSE.sum_dim<n> to allow for arbitrary function on elements - #1987
Conversation
|
Why are you calling these functions directly? |
|
The main reason is scalar indexing when using julia> using CUDA, SparseArrays
julia> a = sprand(10, 10, 0.1);
julia> ad = CUDA.CUSPARSE.CuSparseMatrixCSR(a);
julia> sum(ad, dims=2)
┌ Warning: Performing scalar indexing on task Task (runnable) @0x00007f2882ffc010.
│ Invocation of getindex resulted in scalar indexing of a GPU array.
│ This is typically caused by calling an iterating implementation of a method.
│ Such implementations *do not* execute on the GPU, but very slowly on the CPU,
│ and therefore are only permitted from the REPL for prototyping purposes.
│ If you did intend to index this array, annotate the caller with @allowscalar.
└ @ GPUArraysCore ~/.julia/packages/GPUArraysCore/uOYfN/src/GPUArraysCore.jl:106
10×1 Matrix{Float64}:
0.7312257183333077
0.2736255562180383
0.0
0.8569093552724679
0.24512118904635305
0.0
0.0
0.0
0.0
0.9815900426493798 |
|
Right, but then we should hook up |
|
I just noticed that the julia> using CUDA, SparseArrays
julia> A = sprand(4, 4, 0.8);
julia> dA = CUDA.CUSPARSE.CuSparseMatrixCSR(A);
julia> CUDA.CUSPARSE.sum_dim1(dA)
4-element CuArray{Float64, 1, CUDA.Mem.DeviceBuffer}:
2.2032459284126857
1.2487818875938437
0.7308272178094658
1.9313369732308794
julia> sum(A, dims=1)
1×4 Matrix{Float64}:
1.40888 1.72323 0.602062 2.38003
julia> sum(A, dims=2)
4×1 Matrix{Float64}:
2.2032459284126857
1.2487818875938437
0.7308272178094658
1.9313369732308794All my previous inputs were symmetric, so it didn't show. Am I missing something or is this a bug? |
|
Yeah, looks like the functions are named incorrectly. |
|
Hmm, I still don't like this. Those internal functions aren't meant to be reused. As I mention, this should be implemented as I've tried something like that, reusing the device iterators we have for the native broadcast. As a result, this now supports most of |
This fixes #1983
EDIT: also fixes #1406