From 04bee97d2a21da8b95ce3664aecfd8be5b78e5be Mon Sep 17 00:00:00 2001 From: chenyu Date: Mon, 25 Nov 2024 18:25:33 -0500 Subject: [PATCH] hotfix ctypes.c_ulong(size) for metal _alloc (#7902) fix `Tensor.ones(1000, 1000, 1000).contiguous().realize()` on METAL --- tinygrad/runtime/ops_metal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tinygrad/runtime/ops_metal.py b/tinygrad/runtime/ops_metal.py index a15ff8ed59..e7185b69e3 100644 --- a/tinygrad/runtime/ops_metal.py +++ b/tinygrad/runtime/ops_metal.py @@ -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")