Skip to content

Commit

Permalink
Should run on device
Browse files Browse the repository at this point in the history
  • Loading branch information
haraschax committed Sep 25, 2024
1 parent ab2fa26 commit 0a26c90
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion selfdrive/modeld/dmonitoringmodeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/modeld/modeld.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 6 additions & 5 deletions selfdrive/modeld/runners/runmodel_pyx.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <float*> &input_buffer[0]
cdef float[:] float_buffer_view = <float[:num_floats]> 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)
Expand Down

0 comments on commit 0a26c90

Please sign in to comment.