From 0a26c9009babbbf00f5aa1078cad6bf34ce60ec6 Mon Sep 17 00:00:00 2001 From: Bruce Wayne Date: Wed, 25 Sep 2024 11:05:27 -0700 Subject: [PATCH] Should run on device --- selfdrive/modeld/dmonitoringmodeld.py | 2 +- selfdrive/modeld/modeld.py | 4 ++-- selfdrive/modeld/runners/runmodel_pyx.pyx | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/selfdrive/modeld/dmonitoringmodeld.py b/selfdrive/modeld/dmonitoringmodeld.py index 0187184a7acf44..774ac9567cb4a0 100755 --- a/selfdrive/modeld/dmonitoringmodeld.py +++ b/selfdrive/modeld/dmonitoringmodeld.py @@ -77,7 +77,7 @@ def run(self, buf:VisionBuf, calib:np.ndarray) -> tuple[np.ndarray, float]: input_data[:] = buf_data[v_offset:v_offset+MODEL_HEIGHT, h_offset:h_offset+MODEL_WIDTH] t1 = time.perf_counter() - self.model.setInputBuffer("input_img", self.inputs['input_img'].view(np.float32)) + self.model.setInputBuffer("input_img", self.inputs['input_img']) self.model.execute() t2 = time.perf_counter() return self.output, t2 - t1 diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index de5c70bd02b7a7..6eb076c5ff1b18 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -65,8 +65,8 @@ def __init__(self, context: CLContext): 'lateral_control_params': np.zeros(ModelConstants.LATERAL_CONTROL_PARAMS_LEN, dtype=np.float32), 'prev_desired_curv': np.zeros(ModelConstants.PREV_DESIRED_CURV_LEN * (ModelConstants.HISTORY_BUFFER_LEN+1), dtype=np.float32), 'features_buffer': np.zeros(ModelConstants.HISTORY_BUFFER_LEN * ModelConstants.FEATURE_LEN, dtype=np.float32), - 'input_imgs': np.zeros(MODEL_FRAME_SIZE*2, dtype=np.uint8), - 'big_input_imgs': np.zeros(MODEL_FRAME_SIZE*2, dtype=np.uint8), + 'input_imgs': None, + 'big_input_imgs': None, } with open(METADATA_PATH, 'rb') as f: diff --git a/selfdrive/modeld/runners/runmodel_pyx.pyx b/selfdrive/modeld/runners/runmodel_pyx.pyx index a2d6fc79a87792..8ef41ea17f7971 100644 --- a/selfdrive/modeld/runners/runmodel_pyx.pyx +++ b/selfdrive/modeld/runners/runmodel_pyx.pyx @@ -22,11 +22,12 @@ cdef class RunModel: else: self.model.addInput(name, NULL, 0) - def setInputBuffer(self, string name, float[:] buffer): - if buffer is not None: - self.model.setInputBuffer(name, &buffer[0], len(buffer)) - else: - self.model.setInputBuffer(name, NULL, 0) + def setInputBuffer(self, string name, unsigned char[:] input_buffer): + cdef int num_floats = len(input_buffer) // sizeof(float) + cdef float* float_ptr = &input_buffer[0] + cdef float[:] float_buffer_view = float_ptr + if float_buffer_view is not None: + self.model.setInputBuffer(name, &float_buffer_view[0], num_floats) def getCLBuffer(self, string name): cdef void * cl_buf = self.model.getCLBuffer(name)