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

Fix loading on unsupported platforms #459

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Changes from 1 commit
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
13 changes: 10 additions & 3 deletions lib/mtl/buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,23 @@ function MTLBuffer(dev::MTLDevice, bytesize::Integer, ptr::Ptr;
return MTLBuffer(ptr)
end

const PAGESIZE = ccall(:getpagesize, Cint, ())
const _page_size::Ref{Int} = Ref{Int}(0)
function page_size()
if _page_size[] == 0
_page_size[] = Int(ccall(:getpagesize, Cint, ()))
end
_page_size[]
end

function can_alloc_nocopy(ptr::Ptr, bytesize::Integer)
# newBufferWithBytesNoCopy has several restrictions:
## the pointer has to be page-aligned
if Int64(ptr) % PAGESIZE != 0
if Int(ptr) % page_size() != 0
return false
end
## the new buffer needs to be page-aligned
## XXX: on macOS 14, this doesn't seem required; is this a documentation issue?
if bytesize % PAGESIZE != 0
if bytesize % page_size() != 0
return false
end
return true
Expand Down