-
Notifications
You must be signed in to change notification settings - Fork 233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support GPUArrays allocations cache #2593
Conversation
5d585c4
to
c850163
Compare
90ac2fa
to
56d9fcc
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2593 +/- ##
===========================================
- Coverage 73.64% 61.04% -12.60%
===========================================
Files 157 157
Lines 15220 14955 -265
===========================================
- Hits 11209 9130 -2079
- Misses 4011 5825 +1814 ☔ View full report in Codecov by Sentry. |
It's also kinda weird that we're always attaching a finalizer to the array, even when it's put inside of cache (meaning it should get freed when the cache goes out of scope). Should we move the finalizer into |
But we need them anyway, so it might be fine to attach them in ctor and have a single place for this, rather than catching when they go out of cache. |
Passing bytesize as a key results in errors, where arrays are of the same bytesize, but of different dims. julia> GPUArrays.@cached cache ROCArray(zeros(Float32, 16));
julia> GPUArrays.@cached cache ROCArray(zeros(Float32, 4, 4))
ERROR: TypeError: in typeassert, expected ROCArray{Float32, 2, AMDGPU.Runtime.Mem.HIPBuffer}, got a value of type ROCArray{Float32, 1, AMDGPU.Runtime.Mem.HIPBuffer}
Stacktrace:
[1] ROCArray
@ ~/.julia/dev/AMDGPU/src/array.jl:9 [inlined]
[2] ROCArray
@ ~/.julia/dev/AMDGPU/src/array.jl:111 [inlined]
[3] ROCArray
@ ~/.julia/dev/AMDGPU/src/array.jl:116 [inlined]
[4] ROCArray(A::Matrix{Float32})
@ AMDGPU ~/.julia/dev/AMDGPU/src/array.jl:119
[5] macro expansion
@ ~/.julia/packages/GPUArrays/2FKRj/src/host/alloc_cache.jl:147 [inlined]
[6] top-level scope
@ REPL[4]:1 To fix this we can either revert to dims or reshape an array post return if size(x) != dims
reshape(x, dims)
else
x
end::ROCArray{T, N, B} |
julia> GPUArrays.@cached cache ROCArray(zeros(Float32, 16));
julia> GPUArrays.@cached cache ROCArray(zeros(Float32, 4, 4))
ERROR: TypeError: in typeassert, expected ROCArray{Float32, 2, AMDGPU.Runtime.Mem.HIPBuffer}, got a value of type ROCArray{Float32, 1, AMDGPU.Runtime.Mem.HIPBuffer} Yes, that's what I meant in #2593 (comment), and I have reverted the change before merging this PR already. |
That said, it would be nice if the cache could fulfill such requests. I considered storing the |
Co-authored-by: Tim Besard <[email protected]>
Ref: JuliaGPU/GPUArrays.jl#576