JuliaGPU / JuliaGPU/GPUArrays.jl
Scalar indexing for `Base.hash`
- Dominant language
- Julia
- Stars
- 450
- Forks
- 104
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 10
Description
Hello, I've recently noticed that GPUArrays don't define a `Base.hash` implementation and fallback to the default one. This requires one to `@allowscalar` which is slow and also means one has to differentiate between CPU and GPU arrays when calling hash.
MWE:
```julia
using GPUArrays, CUDA
A = cu(rand(1024, 1024))
hash(A) # errors
@allowscalar Base.hash(A) # slow
```
I'm not sure what a good implementation for GPU arrays would be. An inefficient GPU default could be:
```julia
Base.hash(arr::T, h) where T <: AbstractGPUArray = mapreduce(hash, hash, arr; init = hash(T, h))
```
That of course touches every element and works with `UInt64` values, but it would be faster than the normal default.
From what I can tell the default Base.hash for arrays is accessing O(log n) elements. I'm not sure how to neatly map such a pattern onto GPUs, if someone has any pointers I'd be happy to implement it
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.