Skip to content

Commit

Permalink
Make buffers always be a multiple of 16 bytes to support MPS rand fun…
Browse files Browse the repository at this point in the history
…ctionality
  • Loading branch information
christiangnrd committed Mar 27, 2024
1 parent b9344fd commit b203523
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/mtl/buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ end


## allocation
bufferbytesize(bytesize::T) where T<:Integer = ceil(T, bytesize / 16) * T(16)

function MTLBuffer(dev::Union{MTLDevice,MTLHeap}, bytesize::Integer;
storage=Private, hazard_tracking=DefaultTracking,
cache_mode=DefaultCPUCache)
opts = convert(MTLResourceOptions, storage) | hazard_tracking | cache_mode

@assert 0 < bytesize <= dev.maxBufferLength # XXX: not supported by MTLHeap
ptr = alloc_buffer(dev, bytesize, opts)
realbytesize = bufferbytesize(bytesize)
@assert 0 < realbytesize <= dev.maxBufferLength # XXX: not supported by MTLHeap
ptr = alloc_buffer(dev, realbytesize, opts)

return MTLBuffer(ptr)
end
Expand All @@ -39,8 +41,9 @@ function MTLBuffer(dev::MTLDevice, bytesize::Integer, ptr::Ptr;
storage == Private && error("Can't create a Private copy-allocated buffer.")
opts = convert(MTLResourceOptions, storage) | hazard_tracking | cache_mode

@assert 0 < bytesize <= dev.maxBufferLength
ptr = alloc_buffer(dev, bytesize, opts, ptr)
realbytesize = bufferbytesize(bytesize)
@assert 0 < realbytesize <= dev.maxBufferLength
ptr = alloc_buffer(dev, realbytesize, opts, ptr)

return MTLBuffer(ptr)
end
Expand Down

0 comments on commit b203523

Please sign in to comment.