mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-09-04 07:13:41 +08:00
1a8dd310ae
* Add support for TinyGrad model runner processing Introduced a new function `is_tinygrad_model` to detect TinyGrad as an active model runner. Updated the `is_stock_model` logic to account for TinyGrad models and added a new process entry for TinyGrad in the model manager. This enables handling TinyGrad models alongside existing configurations. adding modeld back Add support for `modeld_v2` and update paths for consistency Updated `SConscript` files to integrate `modeld_v2` alongside `modeld` and adjusted script paths for correct metadata handling. Adjusted various configurations and scripts, such as `labeler.yaml` and `build_release.sh`, to include `modeld_v2` and ensure cohesive project structure. Refactor imports to use updated `modeld_v2` paths. Replaced outdated `modeld` references with their `modeld_v2` counterparts for consistency and clarity across the codebase. Also updated `.gitignore` to accommodate new directory structure. This change ensures better maintainability and alignment with the new directory schema. Refactor and reorganize modeld to sunnypilot/modeld_v2 structure. Moved and renamed `modeld` components to the new `sunnypilot/modeld_v2` directory for better organization and modularity. Updated imports and file references to align with the new structure, ensuring compatibility and functionality. Streamlined project structure to improve maintainability and future development. * typo * Use `stock` model runner and refactor model checks. Replaces outdated model detection logic with unified `stock` runner integration, simplifying the decision flow for model selection. Includes `stock` as a new enum in the `Runner` type and updates affected references accordingly. * Handle missing 'sim_pose' in model outputs gracefully. Added conditional checks to ensure the code handles cases where 'sim_pose' is absent in the model outputs. Fallback behaviors use 'plan' data when 'sim_pose' is unavailable, preventing potential errors and enhancing robustness.
63 lines
2.9 KiB
C++
63 lines
2.9 KiB
C++
#include "sunnypilot/modeld_v2/models/commonmodel.h"
|
|
|
|
#include <cmath>
|
|
#include <cstring>
|
|
|
|
#include "common/clutil.h"
|
|
|
|
DrivingModelFrame::DrivingModelFrame(cl_device_id device_id, cl_context context, uint8_t buffer_length) : ModelFrame(device_id, context), buffer_length(buffer_length) {
|
|
input_frames = std::make_unique<uint8_t[]>(buf_size);
|
|
input_frames_cl = CL_CHECK_ERR(clCreateBuffer(context, CL_MEM_READ_WRITE, buf_size, NULL, &err));
|
|
img_buffer_20hz_cl = CL_CHECK_ERR(clCreateBuffer(context, CL_MEM_READ_WRITE, buffer_length*frame_size_bytes, NULL, &err));
|
|
region.origin = (buffer_length - 1) * frame_size_bytes;
|
|
region.size = frame_size_bytes;
|
|
last_img_cl = CL_CHECK_ERR(clCreateSubBuffer(img_buffer_20hz_cl, CL_MEM_READ_WRITE, CL_BUFFER_CREATE_TYPE_REGION, ®ion, &err));
|
|
// printf("Buffer length: %d, region origin: %lu, region size: %lu\n", buffer_length, region.origin, region.size);
|
|
|
|
loadyuv_init(&loadyuv, context, device_id, MODEL_WIDTH, MODEL_HEIGHT);
|
|
init_transform(device_id, context, MODEL_WIDTH, MODEL_HEIGHT);
|
|
}
|
|
|
|
cl_mem* DrivingModelFrame::prepare(cl_mem yuv_cl, int frame_width, int frame_height, int frame_stride, int frame_uv_offset, const mat3& projection) {
|
|
run_transform(yuv_cl, MODEL_WIDTH, MODEL_HEIGHT, frame_width, frame_height, frame_stride, frame_uv_offset, projection);
|
|
|
|
for (int i = 0; i < (buffer_length - 1); i++) {
|
|
CL_CHECK(clEnqueueCopyBuffer(q, img_buffer_20hz_cl, img_buffer_20hz_cl, (i+1)*frame_size_bytes, i*frame_size_bytes, frame_size_bytes, 0, nullptr, nullptr));
|
|
}
|
|
loadyuv_queue(&loadyuv, q, y_cl, u_cl, v_cl, last_img_cl);
|
|
|
|
copy_queue(&loadyuv, q, img_buffer_20hz_cl, input_frames_cl, 0, 0, frame_size_bytes);
|
|
copy_queue(&loadyuv, q, last_img_cl, input_frames_cl, 0, frame_size_bytes, frame_size_bytes);
|
|
|
|
// NOTE: Since thneed is using a different command queue, this clFinish is needed to ensure the image is ready.
|
|
clFinish(q);
|
|
return &input_frames_cl;
|
|
}
|
|
|
|
DrivingModelFrame::~DrivingModelFrame() {
|
|
deinit_transform();
|
|
loadyuv_destroy(&loadyuv);
|
|
CL_CHECK(clReleaseMemObject(img_buffer_20hz_cl));
|
|
CL_CHECK(clReleaseMemObject(last_img_cl));
|
|
CL_CHECK(clReleaseCommandQueue(q));
|
|
}
|
|
|
|
|
|
MonitoringModelFrame::MonitoringModelFrame(cl_device_id device_id, cl_context context) : ModelFrame(device_id, context) {
|
|
input_frames = std::make_unique<uint8_t[]>(buf_size);
|
|
input_frame_cl = CL_CHECK_ERR(clCreateBuffer(context, CL_MEM_READ_WRITE, buf_size, NULL, &err));
|
|
|
|
init_transform(device_id, context, MODEL_WIDTH, MODEL_HEIGHT);
|
|
}
|
|
|
|
cl_mem* MonitoringModelFrame::prepare(cl_mem yuv_cl, int frame_width, int frame_height, int frame_stride, int frame_uv_offset, const mat3& projection) {
|
|
run_transform(yuv_cl, MODEL_WIDTH, MODEL_HEIGHT, frame_width, frame_height, frame_stride, frame_uv_offset, projection);
|
|
clFinish(q);
|
|
return &y_cl;
|
|
}
|
|
|
|
MonitoringModelFrame::~MonitoringModelFrame() {
|
|
deinit_transform();
|
|
CL_CHECK(clReleaseCommandQueue(q));
|
|
}
|