Compare commits

...
Author SHA1 Message Date
geohot d4552bce5d needed for mock 2026-09-08 10:08:34 -07:00
geohot 7170b68036 that's needed to fix openpilot 2026-09-08 10:06:12 -07:00
geohot 1207c2af22 that too 2026-09-08 10:05:30 -07:00
geohot c6f21fd918 always clone in copy 2026-09-08 10:04:13 -07:00
3 changed files with 9 additions and 5 deletions
+2
View File
@@ -29,6 +29,8 @@ class TrackedMemoryView:
self.mv = self.mv.cast('B').cast(new_type, **kwargs)
return self
@property
def obj(self): return self.mv.obj
@property
def nbytes(self): return self.mv.nbytes
def __len__(self): return len(self.mv)
+4 -1
View File
@@ -201,7 +201,10 @@ class Buffer:
return self._trace_num
def _host_mv(self) -> memoryview|None:
if self.is_allocated() and hasattr(host:=self.get_storage()[1], 'mv'): return unwrap(host).view(fmt='B').mv
if self.is_allocated() and hasattr(host:=self.get_storage()[1], 'mv'):
mv = unwrap(host).view(fmt='B').mv
mv.obj._buffer = self # raw ctypes views do not own their memory; keep the allocation alive for asynchronous copies
return mv
if self.is_allocated() and hasattr(self.allocator, '_as_buffer'): return self.allocator._as_buffer(self._buf)
return None
+3 -4
View File
@@ -312,7 +312,7 @@ class Tensor(RandMixin):
if not isinstance(data, UOp): raise RuntimeError(f"can't create Tensor from {data!r} with type {type(data)}")
# data might be on a different device
self.uop:UOp = data if data.device is None or data.device == _device else data.copy_to_device(_device)
self.uop:UOp = data if data.device is None or data.device == _device else data.copy_to_device(_device).clone()
# cast on the target device, the source may not hold the dtype (numpy has no fp8/bfloat16) or be able to compute it (DISK)
if _dtype is not None: self.uop = self.uop.cast(_dtype)
@@ -545,9 +545,8 @@ class Tensor(RandMixin):
"""
if self.uop.device is None: return self
if (device:=canonicalize_device(device)) == self.device: return self
# a copy to disk wants to persist, so it inserts a clone: the disk buffer is the storage of the copied value
if isinstance(device, str) and device.startswith("DISK"): ret = Tensor(self.uop.clone(device))
else: ret = Tensor(self.uop.copy_to_device(device))
# The transfer owns its destination from construction; COPY itself only describes the transfer.
ret = Tensor(self.uop.copy_to_device(device).clone())
if self.grad is not None: ret.grad = self.grad.to(device)
return ret.is_param_(self.is_param)