Files
StarPilot/selfdrive/modeld/thneed/compile.cc
T
HaraldSchafer b0b1aff5cc Rocket league model (#24869)
* dd9a502d-c8e2-4831-b365-804b0ae0739d/600 80041070-d276-4fed-bdb9-0075e5442908/420

* no elementwise op

* 9dabf0fe-2e60-44bf-8d3a-d20a74aca072/600 ae746590-0bb5-4a16-80db-15f02d314f03/300 c4663a12-b499-4c9b-90dd-b169e3948cb1/60

* explicit slice

* some copies are useful

* 1456d261-d232-4654-8885-4d9fde883894/440 c06eba55-1931-4e00-9d63-acad00161be0/700 af2eb6ba-1935-4318-aaf8-868db81a4932/425

* 154f663e-d3e9-4020-ad49-0e640588ebbe/399 badb5e69-504f-4544-a99e-ba75ed204b74/800 08330327-7663-4874-af7a-dcbd2c994ba7/800

* set steer rate cost to 1.0

* smaller temporal size

* Update model reg

* update model ref again

* This did upload somehow

* Update steer rate cost

Co-authored-by: Yassine Yousfi <yyousfi1@binghamton.edu>
old-commit-hash: 9283040d847b120fdf7759d5bd12000863e12f73
2022-06-15 15:29:42 -07:00

82 lines
2.3 KiB
C++

#include <cstring>
#include <getopt.h>
#include "selfdrive/modeld/runners/snpemodel.h"
#include "selfdrive/modeld/thneed/thneed.h"
#include "system/hardware/hw.h"
#define TEMPORAL_SIZE 512+256
#define DESIRE_LEN 8
#define TRAFFIC_CONVENTION_LEN 2
// TODO: This should probably use SNPE directly.
int main(int argc, char* argv[]) {
bool run_optimizer = false, save_binaries = false;
const char *input_file = NULL, *output_file = NULL;
static struct option long_options[] = {
{"in", required_argument, 0, 'i' },
{"out", required_argument, 0, 'o' },
{"binary", no_argument, 0, 'b' },
{"optimize", no_argument, 0, 'f' },
{0, 0, 0, 0 }
};
int long_index = 0, opt = 0;
while ((opt = getopt_long_only(argc, argv,"", long_options, &long_index)) != -1) {
switch (opt) {
case 'i': input_file = optarg; break;
case 'o': output_file = optarg; break;
case 'b': save_binaries = true; break;
case 'f': run_optimizer = true; break;
}
}
// no input?
if (!input_file) {
printf("usage: -i <input file> -o <output file> --binary --optimize\n");
return -1;
}
#define OUTPUT_SIZE 0x10000
float *output = (float*)calloc(OUTPUT_SIZE, sizeof(float));
SNPEModel mdl(input_file, output, 0, USE_GPU_RUNTIME, true);
mdl.thneed->run_optimizer = run_optimizer;
float state[TEMPORAL_SIZE] = {0};
float desire[DESIRE_LEN] = {0};
float traffic_convention[TRAFFIC_CONVENTION_LEN] = {0};
float *input = (float*)calloc(0x1000000, sizeof(float));
float *extra = (float*)calloc(0x1000000, sizeof(float));
mdl.addRecurrent(state, TEMPORAL_SIZE);
mdl.addDesire(desire, DESIRE_LEN);
mdl.addTrafficConvention(traffic_convention, TRAFFIC_CONVENTION_LEN);
mdl.addImage(input, 0);
mdl.addExtra(extra, 0);
// first run
printf("************** execute 1 **************\n");
memset(output, 0, OUTPUT_SIZE * sizeof(float));
mdl.execute();
// don't save?
if (!output_file) {
printf("no output file, exiting\n");
return 0;
}
// save model
printf("saving %s with binary %d\n", output_file, save_binaries);
mdl.thneed->save(output_file, save_binaries);
// test model
auto thneed = new Thneed(true);
thneed->record = false;
thneed->load(output_file);
thneed->clexec();
thneed->find_inputs_outputs();
return 0;
}