mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-08-20 20:13:44 +08:00
committed by
GitHub
parent
eb6c9c7f0d
commit
f1977eaa93
@@ -3,7 +3,6 @@ import argparse
|
||||
import atexit
|
||||
import math
|
||||
import os
|
||||
import pickle
|
||||
import tempfile
|
||||
import time
|
||||
import shutil
|
||||
@@ -31,22 +30,6 @@ def _patch_tinygrad_fetch_fw():
|
||||
helpers.fetch_fw = fetch_fw
|
||||
_patch_tinygrad_fetch_fw()
|
||||
|
||||
def _patch_tinygrad_buffer_reduce():
|
||||
from tinygrad.device import Buffer
|
||||
def __reduce_ex__(self, protocol):
|
||||
buf = None
|
||||
if self._base is not None:
|
||||
return self.__class__, (self.device, self.size, self.dtype, None, None, None, 0, self.base, self.offset, self.is_allocated())
|
||||
if self.device == "NPY":
|
||||
return self.__class__, (self.device, self.size, self.dtype, self._buf, self.options, None, self.uop_refcount)
|
||||
if self.is_allocated():
|
||||
buf = bytearray(self.nbytes)
|
||||
self.copyout(memoryview(buf))
|
||||
if protocol >= 5:
|
||||
buf = pickle.PickleBuffer(buf)
|
||||
return self.__class__, (self.device, self.size, self.dtype, None, self.options, buf, self.uop_refcount)
|
||||
Buffer.__reduce_ex__ = __reduce_ex__
|
||||
_patch_tinygrad_buffer_reduce()
|
||||
|
||||
from tinygrad.tensor import Tensor
|
||||
from tinygrad.helpers import Context
|
||||
|
||||
@@ -38,14 +38,10 @@ def dump_oob(obj, f):
|
||||
def load_oob(f):
|
||||
opcodes = f.read(struct.unpack('<q', f.read(8))[0])
|
||||
def buffers():
|
||||
prev = None
|
||||
while (h := f.read(8)):
|
||||
if prev is not None:
|
||||
prev.release()
|
||||
buf = bytearray(struct.unpack('<q', h)[0])
|
||||
f.readinto(buf)
|
||||
prev = pickle.PickleBuffer(buf)
|
||||
yield prev
|
||||
pb = pickle.PickleBuffer(bytearray(struct.unpack('<q', h)[0]))
|
||||
f.readinto(pb)
|
||||
yield pb
|
||||
return pickle.load(io.BytesIO(opcodes), buffers=buffers())
|
||||
|
||||
def usbgpu_present() -> bool:
|
||||
|
||||
+1
-1
Submodule tinygrad_repo updated: e6fbede157...ef37830d13
Reference in New Issue
Block a user