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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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 @@ function HIPBuffer(ptr::Ptr{Cvoid}, bytesize::Int)
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 @@ function HostBuffer(
HostBuffer(stream.device, stream.ctx, ptr, dev_ptr, sz, false)
end

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

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