-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Updates for macOS 13 (Ventura); use bindless argument buffers #23
Conversation
Codecov Report
@@ Coverage Diff @@
## main #23 +/- ##
==========================================
- Coverage 64.39% 62.94% -1.45%
==========================================
Files 36 36
Lines 1070 1039 -31
==========================================
- Hits 689 654 -35
- Misses 381 385 +4
Continue to review full report at Codecov.
|
It looks like the const _kernel_cache = Dict{MtlDevice,MtlFunction}()
function gpuAddress(buf::MtlBuffer)
# on Metal 2, we don't have a way to query the GPU address of a buffer. so instead,
# we encode the buffer as the argument of a dummy kernel, and extract the encoded
# address by peeking into the argument encoder's buffer. (note that this requires
# an argument encoder, and thus a struct-valued argument, as the command encoder
# doesn't have a buffer we can peek into).
#
# TODO: with Metal 3, the GPU address is a property of the buffer
dev = current_device()
fun = get!(_kernel_cache, dev) do
code = """
struct Struct {
device void* buffer;
};
kernel void entry(device Struct*) { }"""
lib = MtlLibrary(dev, code)
MtlFunction(lib, "entry")
end
argenc = MtlArgumentEncoder(fun, 1)
argbuf = alloc(Cchar, dev, sizeof(argenc), storage=Shared)
MTL.assign_argument_buffer!(argenc, argbuf)
set_buffer!(argenc, buf, 0, 0)
Base.unsafe_load(Base.convert(Ptr{Ptr{Nothing}}, content(argbuf)), 1)
end Putting this out here so that I can consider it if it's ever needed. |
If all goes well, I'll probably be bumping the requirements for Metal.jl to macOS 13 (Ventura), because it ships Metal 3 which supports bindless arguments.