hotfix ctypes.c_ulong(size) for metal _alloc (#7902)

fix `Tensor.ones(1000, 1000, 1000).contiguous().realize()` on METAL
This commit is contained in:
chenyu
2024-11-25 18:25:33 -05:00
committed by GitHub
parent 631dc98b52
commit 04bee97d2a

View File

@@ -135,7 +135,8 @@ class MetalAllocator(LRUAllocator):
super().__init__()
def _alloc(self, size:int, options) -> MetalBuffer:
# Buffer is explicitly released in _free() rather than garbage collected via reference count
ret = msg(self.dev.sysdevice, "newBufferWithLength:options:", size, MTLResourceOptions.MTLResourceStorageModeShared, restype=objc_id)
ret = msg(self.dev.sysdevice, "newBufferWithLength:options:", ctypes.c_ulong(size), MTLResourceOptions.MTLResourceStorageModeShared,
restype=objc_id)
if ret.value is None: raise MemoryError(f"Metal OOM while allocating {size=}")
return MetalBuffer(ret, size)
def _free(self, opaque:MetalBuffer, options): msg(opaque.buf, "release")