Statistics functions on GPU?

Are there available any GPU implementations of the Statistics functions (cor, cov etc.)? Many of the functions on the Statistics module throw the “scalar getindex is disallowed” warning/error. Eg:

julia> Statistics.cor(CuArrays.rand(100,10))
ERROR: scalar getindex is disallowed
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] assertscalar(::String) at /home/user/.julia/packages/GPUArrays/JqOUg/src/host/indexing.jl:41
 [3] getindex at /home/user/.julia/packages/GPUArrays/JqOUg/src/host/indexing.jl:96 [inlined]
 [4] _getindex at ./abstractarray.jl:1003 [inlined]
 [5] getindex at ./abstractarray.jl:980 [inlined]
 [6] (::Statistics.var"#43#44"{CuArray{Float32,2,Nothing}})(::Int64) at ./none:0
 [7] iterate at ./generator.jl:47 [inlined]
 [8] collect(::Base.Generator{UnitRange{Int64},Statistics.var"#43#44"{CuArray{Float32,2,Nothing}}}) at ./array.jl:665
 [9] corzm(::CuArray{Float32,2,Nothing}, ::Int64) at /opt/julia/share/julia/stdlib/v1.4/Statistics/src/Statistics.jl:627
 [10] corm(::CuArray{Float32,2,Nothing}, ::CuArray{Float32,2,Nothing}, ::Int64) at /opt/julia/share/julia/stdlib/v1.4/Statistics/src/Statistics.jl:639
 [11] cor(::CuArray{Float32,2,Nothing}; dims::Int64) at /opt/julia/share/julia/stdlib/v1.4/Statistics/src/Statistics.jl:679
 [12] cor(::CuArray{Float32,2,Nothing}) at /opt/julia/share/julia/stdlib/v1.4/Statistics/src/Statistics.jl:679
 [13] top-level scope at none:0

Perhaps a GPU friendly version of them should do batching computations on matrices/list of vectors?

Did nobody had any need of them yet or am I missing something obvious?

There’s some functions implemented, https://github.com/JuliaGPU/CUDA.jl/blob/master/src/statistics.jl, but not many yet. PRs appreciated :slight_smile:

2 Likes