Skip to content

Commit 825c924

Browse files
geohotComma Device
and
Comma Device
authored
minor cleanups, fix non binary compile (commaai#23882)
Co-authored-by: Comma Device <[email protected]>
1 parent 8eab496 commit 825c924

8 files changed

+27
-29
lines changed

selfdrive/modeld/thneed/compile.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ int main(int argc, char* argv[]) {
3535
// save model
3636
bool save_binaries = (argc > 3) && (strcmp(argv[3], "--binary") == 0);
3737
mdl.thneed->save(argv[2], save_binaries);
38+
39+
// test model
40+
auto thneed = new Thneed(true);
41+
thneed->record &= ~THNEED_RECORD;
42+
thneed->load(argv[2]);
43+
thneed->clexec();
44+
thneed->find_inputs_outputs();
45+
3846
return 0;
3947
}
4048

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#define SUPPORT_DILATION
22

33
__kernel void convolution_horizontal_reduced_reads(
4-
#include "convolution_.cl"

selfdrive/modeld/thneed/kernels/convolution_horizontal_reduced_reads_1x1.cl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
#define SUPPORT_ACCUMULATION
33

44
__kernel void convolution_horizontal_reduced_reads_1x1(
5-
#include "convolution_.cl"
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#define NUM_OUTPUTS 5
22

33
__kernel void convolution_horizontal_reduced_reads_5_outputs(
4-
#include "convolution_.cl"

selfdrive/modeld/thneed/kernels/convolution_horizontal_reduced_reads_depthwise.cl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
#define SUPPORT_DILATION
33

44
__kernel void convolution_horizontal_reduced_reads_depthwise(
5-
#include "convolution_.cl"
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#define DEPTHWISE
22

33
__kernel void convolution_horizontal_reduced_reads_depthwise_stride_1(
4-
#include "convolution_.cl"

selfdrive/modeld/thneed/optimizer.cc

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <assert.h>
55
#include "thneed.h"
66

7+
#include "selfdrive/common/util.h"
8+
#include "selfdrive/common/clutil.h"
9+
710
extern map<cl_program, string> g_program_source;
811

912
static int is_same_size_image(cl_mem a, cl_mem b) {
@@ -63,40 +66,32 @@ static cl_mem make_image_like(cl_context context, cl_mem val) {
6366
int Thneed::optimize() {
6467
const char *kernel_path = getenv("KERNEL_PATH");
6568
if (!kernel_path) { kernel_path = "/data/openpilot/selfdrive/modeld/thneed/kernels"; printf("no KERNEL_PATH set, defaulting to %s\n", kernel_path); }
69+
70+
string convolution_;
71+
{
72+
char fn[0x100];
73+
snprintf(fn, sizeof(fn), "%s/%s.cl", kernel_path, "convolution_");
74+
convolution_ = util::read_file(fn);
75+
}
76+
6677
// load custom kernels
6778
map<string, cl_program> g_programs;
6879
for (auto &k : kq) {
6980
// replace program?
7081
if (g_programs.find(k->name) == g_programs.end()) {
7182
char fn[0x100];
7283
snprintf(fn, sizeof(fn), "%s/%s.cl", kernel_path, k->name.c_str());
73-
FILE *g = fopen(fn, "rb");
74-
if (g != NULL) {
75-
char *src[0x10000];
76-
const char *srcs[1]; srcs[0] = (const char *)src;
77-
memset(src, 0, sizeof(src));
78-
size_t length = fread(src, 1, sizeof(src), g);
79-
fclose(g);
80-
81-
printf("building kernel %s\n", k->name.c_str());
82-
k->program = clCreateProgramWithSource(context, 1, srcs, &length, NULL);
83-
char options[0x100];
84-
snprintf(options, sizeof(options)-1, "-I %s", kernel_path);
85-
int err = clBuildProgram(k->program, 1, &device_id, options, NULL, NULL);
86-
87-
if (err != 0) {
88-
printf("got err %d\n", err);
89-
size_t err_length;
90-
char buffer[2048];
91-
clGetProgramBuildInfo(k->program, device_id, CL_PROGRAM_BUILD_LOG, sizeof(buffer), buffer, &err_length);
92-
buffer[err_length] = '\0';
93-
printf("%s\n", buffer);
84+
if (util::file_exists(fn)) {
85+
string kernel_src = util::read_file(fn);
86+
if (k->name.rfind("convolution_", 0) == 0) {
87+
kernel_src += convolution_;
9488
}
95-
assert(err == 0);
89+
printf("building kernel %s with len %lu\n", k->name.c_str(), kernel_src.length());
90+
k->program = cl_program_from_source(context, device_id, kernel_src);
9691

9792
// save in cache
9893
g_programs[k->name] = k->program;
99-
g_program_source[k->program] = string((char *)src, length);
94+
g_program_source[k->program] = kernel_src;
10095
} else {
10196
g_programs[k->name] = NULL;
10297
}

selfdrive/modeld/thneed/thneed.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int ioctl(int filedes, unsigned long request, void *argp) {
7070
struct kgsl_gpuobj_sync *cmd = (struct kgsl_gpuobj_sync *)argp;
7171
struct kgsl_gpuobj_sync_obj *objs = (struct kgsl_gpuobj_sync_obj *)(cmd->objs);
7272

73-
if (thneed->record & THNEED_DEBUG) {
73+
if (thneed->record & THNEED_VERBOSE_DEBUG) {
7474
printf("IOCTL_KGSL_GPUOBJ_SYNC count:%d ", cmd->count);
7575
for (int i = 0; i < cmd->count; i++) {
7676
printf(" -- offset:0x%lx len:0x%lx id:%d op:%d ", objs[i].offset, objs[i].length, objs[i].id, objs[i].op);

0 commit comments

Comments
 (0)