From ebd395b5fc0094ec81f4d61bf985f80c26753a3b Mon Sep 17 00:00:00 2001 From: discountchubbs Date: Sat, 5 Sep 2026 12:50:43 -0700 Subject: [PATCH] stride --- openpilot/sunnypilot/modeld_v2/compile_modeld.py | 5 +++-- openpilot/sunnypilot/modeld_v2/modeld.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/openpilot/sunnypilot/modeld_v2/compile_modeld.py b/openpilot/sunnypilot/modeld_v2/compile_modeld.py index 53e6183747..6a202f7e39 100755 --- a/openpilot/sunnypilot/modeld_v2/compile_modeld.py +++ b/openpilot/sunnypilot/modeld_v2/compile_modeld.py @@ -32,7 +32,7 @@ def _patch_tinygrad_fetch_fw(): helpers.fetch_fw = fetch_fw _patch_tinygrad_fetch_fw() -from openpilot.selfdrive.modeld.compile_modeld import NV12Frame, make_frame_prepare, sample_desire, sample_skip, shift_and_sample +from openpilot.selfdrive.modeld.compile_modeld import NV12Frame, make_frame_prepare, nv12_copy_size, sample_desire, sample_skip, shift_and_sample from tinygrad import dtypes from tinygrad.device import Device from tinygrad.engine.jit import TinyJit @@ -377,8 +377,9 @@ if __name__ == "__main__": for cam_w, cam_h in args.camera_resolutions: print(f"Compiling warp JIT for {cam_w}x{cam_h}...") nv12 = NV12Frame(cam_w, cam_h, *get_nv12_info(cam_w, cam_h)) + frame_copy_size = nv12_copy_size(nv12.stride, nv12.y_height, nv12.uv_height) warp_input_dev = 'NPY' if Device.DEFAULT == 'AMD' else Device.DEFAULT - make_random_warp_inputs = partial(make_random_images, keys=['frame', 'big_frame'], shape=nv12.size, device=warp_input_dev) + make_random_warp_inputs = partial(make_random_images, keys=['frame', 'big_frame'], shape=frame_copy_size, device=warp_input_dev) warp = TinyJit(make_warp(nv12, model_w, model_h), prune=True) output_data[(cam_w, cam_h)] = compile_jit(warp, make_random_warp_inputs, WARP_INPUTS, make_warp_queues) diff --git a/openpilot/sunnypilot/modeld_v2/modeld.py b/openpilot/sunnypilot/modeld_v2/modeld.py index 0c2eb7a7c9..e809e37873 100755 --- a/openpilot/sunnypilot/modeld_v2/modeld.py +++ b/openpilot/sunnypilot/modeld_v2/modeld.py @@ -42,7 +42,9 @@ from openpilot.sunnypilot.modeld_v2.fill_model_msg import fill_model_msg, fill_p from openpilot.sunnypilot.modeld_v2.constants import Plan from openpilot.sunnypilot.modeld_v2.meta_helper import load_meta_constants from openpilot.sunnypilot.modeld_v2.camera_offset_helper import CameraOffsetHelper -from openpilot.sunnypilot.modeld_v2.compile_modeld import derive_frame_skip, make_split_input_queues, make_supercombo_input_queues, WARP_INPUTS, POLICY_INPUTS +from openpilot.sunnypilot.modeld_v2.compile_modeld import (derive_frame_skip, make_split_input_queues, + make_supercombo_input_queues, nv12_copy_size, + WARP_INPUTS, POLICY_INPUTS) from openpilot.sunnypilot.livedelay.helpers import get_lat_delay from openpilot.sunnypilot.modeld_v2.modeld_base import ModelStateBase from openpilot.sunnypilot.models.helpers import get_active_bundle @@ -174,8 +176,9 @@ class ModelState(ModelStateBase): self.frame_buf_params = dict.fromkeys(self._vision_input_names, nv12_info) yuv_size = nv12_info[3] + self.frame_copy_size = nv12_copy_size(*nv12_info[:3]) if self.use_frame_buffers: - self.frame_buffers = {k: np.zeros(yuv_size, dtype=np.uint8) for k in self._vision_input_names} + self.frame_buffers = {k: np.zeros(self.frame_copy_size, dtype=np.uint8) for k in self._vision_input_names} self.full_frames = {k: Tensor(self.frame_buffers[k], device='NPY').realize() for k in self._vision_input_names} else: self.frame_buffers = {} @@ -183,7 +186,8 @@ class ModelState(ModelStateBase): self.warp(**{k: self.input_queues[k] for k in WARP_INPUTS}, frame=self.full_frames[self._road_key], big_frame=self.full_frames[self._wide_key]) def warmup(self) -> None: - dummy_frames = {k: np.zeros(self.frame_buf_params[k][3], dtype=np.uint8) for k in self._vision_input_names} + dummy_size = self.frame_copy_size if self.use_frame_buffers else self.frame_buf_params[self._road_key][3] + dummy_frames = {k: np.zeros(dummy_size, dtype=np.uint8) for k in self._vision_input_names} transforms = {k: np.eye(3, dtype=np.float32) for k in [self._road_key, self._wide_key] if k} dummy_inputs = {} @@ -218,7 +222,7 @@ class ModelState(ModelStateBase): after_enqueue: Callable[[], None] | None = None) -> dict[str, np.ndarray] | None: if self.use_frame_buffers: for key, buf in bufs.items(): - np.copyto(self.frame_buffers[key], np.frombuffer(buf.data, dtype=np.uint8, count=self.frame_buf_params[key][3])) + np.copyto(self.frame_buffers[key], np.frombuffer(buf.data, dtype=np.uint8, count=self.frame_copy_size)) else: for key, buf in bufs.items(): ptr = np.frombuffer(buf.data, dtype=np.uint8).ctypes.data