Skip to content
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

Update to latest alloc cache #723

Merged
merged 2 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CEnum = "0.4, 0.5"
ChainRulesCore = "1"
EnzymeCore = "0.8"
ExprTools = "0.1"
GPUArrays = "11.2"
GPUArrays = "11.2.1"
GPUCompiler = "0.27, 1.0"
KernelAbstractions = "0.9.2"
LLD_jll = "15, 16, 17"
Expand Down
11 changes: 3 additions & 8 deletions src/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ mutable struct ROCArray{T, N, B} <: AbstractGPUArray{T, N}
function ROCArray{T, N, B}(::UndefInitializer, dims::Dims{N}) where {T, N, B <: Mem.AbstractAMDBuffer}
@assert isbitstype(T) "ROCArray only supports bits types"
sz::Int64 = prod(dims) * sizeof(T)
x = GPUArrays.cached_alloc((ROCArray, AMDGPU.device(), T, B, sz)) do
ref = GPUArrays.cached_alloc((ROCArray, AMDGPU.device(), B, sz)) do
@debug "Allocate `T=$T`, `dims=$dims`: $(Base.format_bytes(sz))"
data = DataRef(pool_free, pool_alloc(B, sz))
return finalizer(unsafe_free!, new{T, N, B}(data, dims, 0))
DataRef(pool_free, pool_alloc(B, sz))
end
return if size(x) != dims
reshape(x, dims)
else
x
end::ROCArray{T, N, B}
return finalizer(unsafe_free!, new{T, N, B}(ref, dims, 0))
end

function ROCArray{T, N}(buf::DataRef{Managed{B}}, dims::Dims{N}; offset::Integer = 0) where {T, N, B <: Mem.AbstractAMDBuffer}
Expand Down
2 changes: 2 additions & 0 deletions src/memory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ function synchronize(m::Managed)
return
end

Base.sizeof(m::Managed) = sizeof(m.mem)

function Base.convert(::Type{Ptr{T}}, managed::Managed{M}) where {T, M}
strm = AMDGPU.stream()

Expand Down
4 changes: 4 additions & 0 deletions src/runtime/memory/hip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
HIPBuffer(s.device, s.ctx, ptr, bytesize, false)
end

Base.sizeof(b::HIPBuffer) = UInt64(b.bytesize)

Base.convert(::Type{Ptr{T}}, buf::HIPBuffer) where T = convert(Ptr{T}, buf.ptr)

function view(buf::HIPBuffer, bytesize::Int)
Expand Down Expand Up @@ -137,6 +139,8 @@
HostBuffer(stream.device, stream.ctx, ptr, dev_ptr, sz, false)
end

Base.sizeof(b::HostBuffer) = UInt64(b.bytesize)

Check warning on line 142 in src/runtime/memory/hip.jl

View check run for this annotation

Codecov / codecov/patch

src/runtime/memory/hip.jl#L142

Added line #L142 was not covered by tests

function view(buf::HostBuffer, bytesize::Int)
bytesize > buf.bytesize && throw(BoundsError(buf, bytesize))
HostBuffer(
Expand Down