mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-04 07:03:44 +08:00
f84d27c4ee
* tinygrad with snpe * force with snpe to validate * fix path * fix more paths * Adjust modeld execution logic based on active model runner Introduced a check to conditionally execute `modeld` based on the active model runner. Added support for distinguishing between SNPE and TinyGrad runners using new helper functions and updated `custom.capnp` definitions. This change optimizes process management by ensuring compatibility with the selected model runner. * Refactor modeld process function checks. Introduce `is_stock_model` to clarify logic and replace direct uses of `is_snpe_model` where the stock model condition is needed. Additionally, rename the duplicate "modeld" process in sunnyPilot to "modeld_snpe" for clarity and consistency. * ignore tg * fix process name * ruff * fix thneed paths * mypy * remove our own * use upstream compile3 * fix thneed * try this * Revert "remove our own" This reverts commit 1cf4f57502565c274628e185c66f1eb04c4d9bbe. * try using compile2.py again * add back symlink * fix path * more fix * wrong path again * Revert "wrong path again" This reverts commit f5301c19d594defb23cda2604168bcb02c830f3e. * update * hardcode path to our submodule * force path * try this * fix file name * try this * again * Revert "again" This reverts commit 17c8cd73768a2de5aaf2a34d202aa6f03d59d72d. * Revert "try this" This reverts commit 767f78bbcf17b08edbc20f283d10a1990bf4264f. * Revert "fix file name" This reverts commit 485eef68da981da571fe9a9ebf3aecdb95e5588c. * Revert "try this" This reverts commit 41fef87680cdda1ba8cbd7e5c59256e6c57010a0. * Revert "force path" This reverts commit 5c3b408937bff0f61b150971b328d127501c5bf0. * Revert "hardcode path to our submodule" This reverts commit 5ee1950b6f4fce73e7e73b6971b996a9989d0a93. * Revert "update" This reverts commit fb313bd7fbeb50111f3c4a11137b4cfd9cabc3fa. * Reapply "wrong path again" This reverts commit 309639aeb3575e20b215bbbcc27e48923ee95c87. * Revert "wrong path again" This reverts commit f5301c19d594defb23cda2604168bcb02c830f3e. * Revert "more fix" This reverts commit 23dd423e78e60bd6a0bd73e921bfba9a5aad88bd. * Revert "fix path" This reverts commit 75d338f2bda2dfa77044e33f4c6553390621b13b. * Revert "add back symlink" This reverts commit 9f71ad0b8ae2068e431c455af9d4f954d024eec7. * Revert "try using compile2.py again" This reverts commit 914117d2e1c6c4270f7bef1a5305847a1d7bab17. * Reapply "remove our own" This reverts commit b1996377b346658f2094cba9032a66230784cb3e. * don't even compile anymore * need it for default snpe model * add to lfs * bring onnx back for sim * must add this back * need this --------- Co-authored-by: DevTekVE <devtekve@gmail.com>
98 lines
4.5 KiB
C++
98 lines
4.5 KiB
C++
#include "selfdrive/modeld/transforms/transform.h"
|
|
|
|
#include <cassert>
|
|
#include <cstring>
|
|
|
|
#include "common/clutil.h"
|
|
|
|
void transform_init(Transform* s, cl_context ctx, cl_device_id device_id) {
|
|
memset(s, 0, sizeof(*s));
|
|
|
|
cl_program prg = cl_program_from_file(ctx, device_id, TRANSFORM_PATH, "");
|
|
s->krnl = CL_CHECK_ERR(clCreateKernel(prg, "warpPerspective", &err));
|
|
// done with this
|
|
CL_CHECK(clReleaseProgram(prg));
|
|
|
|
s->m_y_cl = CL_CHECK_ERR(clCreateBuffer(ctx, CL_MEM_READ_WRITE, 3*3*sizeof(float), NULL, &err));
|
|
s->m_uv_cl = CL_CHECK_ERR(clCreateBuffer(ctx, CL_MEM_READ_WRITE, 3*3*sizeof(float), NULL, &err));
|
|
}
|
|
|
|
void transform_destroy(Transform* s) {
|
|
CL_CHECK(clReleaseMemObject(s->m_y_cl));
|
|
CL_CHECK(clReleaseMemObject(s->m_uv_cl));
|
|
CL_CHECK(clReleaseKernel(s->krnl));
|
|
}
|
|
|
|
void transform_queue(Transform* s,
|
|
cl_command_queue q,
|
|
cl_mem in_yuv, int in_width, int in_height, int in_stride, int in_uv_offset,
|
|
cl_mem out_y, cl_mem out_u, cl_mem out_v,
|
|
int out_width, int out_height,
|
|
const mat3& projection) {
|
|
const int zero = 0;
|
|
|
|
// sampled using pixel center origin
|
|
// (because that's how fastcv and opencv does it)
|
|
|
|
mat3 projection_y = projection;
|
|
|
|
// in and out uv is half the size of y.
|
|
mat3 projection_uv = transform_scale_buffer(projection, 0.5);
|
|
|
|
CL_CHECK(clEnqueueWriteBuffer(q, s->m_y_cl, CL_TRUE, 0, 3*3*sizeof(float), (void*)projection_y.v, 0, NULL, NULL));
|
|
CL_CHECK(clEnqueueWriteBuffer(q, s->m_uv_cl, CL_TRUE, 0, 3*3*sizeof(float), (void*)projection_uv.v, 0, NULL, NULL));
|
|
|
|
const int in_y_width = in_width;
|
|
const int in_y_height = in_height;
|
|
const int in_y_px_stride = 1;
|
|
const int in_uv_width = in_width/2;
|
|
const int in_uv_height = in_height/2;
|
|
const int in_uv_px_stride = 2;
|
|
const int in_u_offset = in_uv_offset;
|
|
const int in_v_offset = in_uv_offset + 1;
|
|
|
|
const int out_y_width = out_width;
|
|
const int out_y_height = out_height;
|
|
const int out_uv_width = out_width/2;
|
|
const int out_uv_height = out_height/2;
|
|
|
|
CL_CHECK(clSetKernelArg(s->krnl, 0, sizeof(cl_mem), &in_yuv)); // src
|
|
CL_CHECK(clSetKernelArg(s->krnl, 1, sizeof(cl_int), &in_stride)); // src_row_stride
|
|
CL_CHECK(clSetKernelArg(s->krnl, 2, sizeof(cl_int), &in_y_px_stride)); // src_px_stride
|
|
CL_CHECK(clSetKernelArg(s->krnl, 3, sizeof(cl_int), &zero)); // src_offset
|
|
CL_CHECK(clSetKernelArg(s->krnl, 4, sizeof(cl_int), &in_y_height)); // src_rows
|
|
CL_CHECK(clSetKernelArg(s->krnl, 5, sizeof(cl_int), &in_y_width)); // src_cols
|
|
CL_CHECK(clSetKernelArg(s->krnl, 6, sizeof(cl_mem), &out_y)); // dst
|
|
CL_CHECK(clSetKernelArg(s->krnl, 7, sizeof(cl_int), &out_y_width)); // dst_row_stride
|
|
CL_CHECK(clSetKernelArg(s->krnl, 8, sizeof(cl_int), &zero)); // dst_offset
|
|
CL_CHECK(clSetKernelArg(s->krnl, 9, sizeof(cl_int), &out_y_height)); // dst_rows
|
|
CL_CHECK(clSetKernelArg(s->krnl, 10, sizeof(cl_int), &out_y_width)); // dst_cols
|
|
CL_CHECK(clSetKernelArg(s->krnl, 11, sizeof(cl_mem), &s->m_y_cl)); // M
|
|
|
|
const size_t work_size_y[2] = {(size_t)out_y_width, (size_t)out_y_height};
|
|
|
|
CL_CHECK(clEnqueueNDRangeKernel(q, s->krnl, 2, NULL,
|
|
(const size_t*)&work_size_y, NULL, 0, 0, NULL));
|
|
|
|
const size_t work_size_uv[2] = {(size_t)out_uv_width, (size_t)out_uv_height};
|
|
|
|
CL_CHECK(clSetKernelArg(s->krnl, 2, sizeof(cl_int), &in_uv_px_stride)); // src_px_stride
|
|
CL_CHECK(clSetKernelArg(s->krnl, 3, sizeof(cl_int), &in_u_offset)); // src_offset
|
|
CL_CHECK(clSetKernelArg(s->krnl, 4, sizeof(cl_int), &in_uv_height)); // src_rows
|
|
CL_CHECK(clSetKernelArg(s->krnl, 5, sizeof(cl_int), &in_uv_width)); // src_cols
|
|
CL_CHECK(clSetKernelArg(s->krnl, 6, sizeof(cl_mem), &out_u)); // dst
|
|
CL_CHECK(clSetKernelArg(s->krnl, 7, sizeof(cl_int), &out_uv_width)); // dst_row_stride
|
|
CL_CHECK(clSetKernelArg(s->krnl, 8, sizeof(cl_int), &zero)); // dst_offset
|
|
CL_CHECK(clSetKernelArg(s->krnl, 9, sizeof(cl_int), &out_uv_height)); // dst_rows
|
|
CL_CHECK(clSetKernelArg(s->krnl, 10, sizeof(cl_int), &out_uv_width)); // dst_cols
|
|
CL_CHECK(clSetKernelArg(s->krnl, 11, sizeof(cl_mem), &s->m_uv_cl)); // M
|
|
|
|
CL_CHECK(clEnqueueNDRangeKernel(q, s->krnl, 2, NULL,
|
|
(const size_t*)&work_size_uv, NULL, 0, 0, NULL));
|
|
CL_CHECK(clSetKernelArg(s->krnl, 3, sizeof(cl_int), &in_v_offset)); // src_ofset
|
|
CL_CHECK(clSetKernelArg(s->krnl, 6, sizeof(cl_mem), &out_v)); // dst
|
|
|
|
CL_CHECK(clEnqueueNDRangeKernel(q, s->krnl, 2, NULL,
|
|
(const size_t*)&work_size_uv, NULL, 0, 0, NULL));
|
|
}
|