mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-08-03 08:41: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.
76 lines
3.0 KiB
C++
76 lines
3.0 KiB
C++
#include "sunnypilot/modeld_v2/transforms/loadyuv.h"
|
|
|
|
#include <cassert>
|
|
#include <cstdio>
|
|
#include <cstring>
|
|
|
|
void loadyuv_init(LoadYUVState* s, cl_context ctx, cl_device_id device_id, int width, int height) {
|
|
memset(s, 0, sizeof(*s));
|
|
|
|
s->width = width;
|
|
s->height = height;
|
|
|
|
char args[1024];
|
|
snprintf(args, sizeof(args),
|
|
"-cl-fast-relaxed-math -cl-denorms-are-zero "
|
|
"-DTRANSFORMED_WIDTH=%d -DTRANSFORMED_HEIGHT=%d",
|
|
width, height);
|
|
cl_program prg = cl_program_from_file(ctx, device_id, LOADYUV_PATH, args);
|
|
|
|
s->loadys_krnl = CL_CHECK_ERR(clCreateKernel(prg, "loadys", &err));
|
|
s->loaduv_krnl = CL_CHECK_ERR(clCreateKernel(prg, "loaduv", &err));
|
|
s->copy_krnl = CL_CHECK_ERR(clCreateKernel(prg, "copy", &err));
|
|
|
|
// done with this
|
|
CL_CHECK(clReleaseProgram(prg));
|
|
}
|
|
|
|
void loadyuv_destroy(LoadYUVState* s) {
|
|
CL_CHECK(clReleaseKernel(s->loadys_krnl));
|
|
CL_CHECK(clReleaseKernel(s->loaduv_krnl));
|
|
CL_CHECK(clReleaseKernel(s->copy_krnl));
|
|
}
|
|
|
|
void loadyuv_queue(LoadYUVState* s, cl_command_queue q,
|
|
cl_mem y_cl, cl_mem u_cl, cl_mem v_cl,
|
|
cl_mem out_cl) {
|
|
cl_int global_out_off = 0;
|
|
|
|
CL_CHECK(clSetKernelArg(s->loadys_krnl, 0, sizeof(cl_mem), &y_cl));
|
|
CL_CHECK(clSetKernelArg(s->loadys_krnl, 1, sizeof(cl_mem), &out_cl));
|
|
CL_CHECK(clSetKernelArg(s->loadys_krnl, 2, sizeof(cl_int), &global_out_off));
|
|
|
|
const size_t loadys_work_size = (s->width*s->height)/8;
|
|
CL_CHECK(clEnqueueNDRangeKernel(q, s->loadys_krnl, 1, NULL,
|
|
&loadys_work_size, NULL, 0, 0, NULL));
|
|
|
|
const size_t loaduv_work_size = ((s->width/2)*(s->height/2))/8;
|
|
global_out_off += (s->width*s->height);
|
|
|
|
CL_CHECK(clSetKernelArg(s->loaduv_krnl, 0, sizeof(cl_mem), &u_cl));
|
|
CL_CHECK(clSetKernelArg(s->loaduv_krnl, 1, sizeof(cl_mem), &out_cl));
|
|
CL_CHECK(clSetKernelArg(s->loaduv_krnl, 2, sizeof(cl_int), &global_out_off));
|
|
|
|
CL_CHECK(clEnqueueNDRangeKernel(q, s->loaduv_krnl, 1, NULL,
|
|
&loaduv_work_size, NULL, 0, 0, NULL));
|
|
|
|
global_out_off += (s->width/2)*(s->height/2);
|
|
|
|
CL_CHECK(clSetKernelArg(s->loaduv_krnl, 0, sizeof(cl_mem), &v_cl));
|
|
CL_CHECK(clSetKernelArg(s->loaduv_krnl, 1, sizeof(cl_mem), &out_cl));
|
|
CL_CHECK(clSetKernelArg(s->loaduv_krnl, 2, sizeof(cl_int), &global_out_off));
|
|
|
|
CL_CHECK(clEnqueueNDRangeKernel(q, s->loaduv_krnl, 1, NULL,
|
|
&loaduv_work_size, NULL, 0, 0, NULL));
|
|
}
|
|
|
|
void copy_queue(LoadYUVState* s, cl_command_queue q, cl_mem src, cl_mem dst,
|
|
size_t src_offset, size_t dst_offset, size_t size) {
|
|
CL_CHECK(clSetKernelArg(s->copy_krnl, 0, sizeof(cl_mem), &src));
|
|
CL_CHECK(clSetKernelArg(s->copy_krnl, 1, sizeof(cl_mem), &dst));
|
|
CL_CHECK(clSetKernelArg(s->copy_krnl, 2, sizeof(cl_int), &src_offset));
|
|
CL_CHECK(clSetKernelArg(s->copy_krnl, 3, sizeof(cl_int), &dst_offset));
|
|
const size_t copy_work_size = size/8;
|
|
CL_CHECK(clEnqueueNDRangeKernel(q, s->copy_krnl, 1, NULL,
|
|
©_work_size, NULL, 0, 0, NULL));
|
|
} |