Files
dragonpilot/selfdrive/modeld/thneed/debug/test.cc
T
George Hotz 302d06ee70 thneed saves 45% of a core (#1512)
* thneed runs the model

* thneed is doing the hooking

* set kernel args

* thneeding the bufferS

* print the images well

* thneeds with better buffers

* includes

* disasm adreno

* parse packets

* disasm works

* disasm better

* more thneeding

* much thneeding

* much more thneeding

* thneed works i think

* thneed is patient

* thneed works

* 7.7%

* gpuobj sync

* yay, it mallocs now

* cleaning it up, Thneed

* sync objs and set power

* thneed needs inputs and outputs

* thneed in modeld

* special modeld runs

* can't thneed the DSP

* test is weird

* thneed modeld uses 6.4% CPU

* add thneed to release

* move to debug

* delete some junk from the pr

* always track the timestamp

* timestamp hacks in thneed

* create a new command queue

* fix timestamp

* pretty much back to what we had, you can't use SNPE with thneed

* improve thneed test

* disable save log

Co-authored-by: Comma Device <device@comma.ai>
2020-05-15 13:53:01 -07:00

96 lines
2.8 KiB
C++

#include "../thneed.h"
#include "../../runners/snpemodel.h"
#define TEMPORAL_SIZE 512
#define DESIRE_LEN 8
#define TRAFFIC_CONVENTION_LEN 2
void hexdump(uint32_t *d, int len);
int main(int argc, char* argv[]) {
float *output = (float*)calloc(0x10000, sizeof(float));
float *golden = (float*)calloc(0x10000, sizeof(float));
SNPEModel mdl(argv[1], output, 0, USE_GPU_RUNTIME);
// cmd line test
if (argc > 2) {
for (int i = 2; i < argc; i++) {
float *buf[5];
FILE *f = fopen(argv[i], "rb");
size_t sz;
for (int j = 0; j < 5; j++) {
fread(&sz, 1, sizeof(sz), f);
printf("reading %zu\n", sz);
buf[j] = (float*)malloc(sz);
fread(buf[j], 1, sz, f);
}
if (sz != 9532) continue;
mdl.addRecurrent(buf[0], TEMPORAL_SIZE);
mdl.addTrafficConvention(buf[1], TRAFFIC_CONVENTION_LEN);
mdl.addDesire(buf[2], DESIRE_LEN);
mdl.execute(buf[3], 0);
hexdump((uint32_t*)buf[4], 0x100);
hexdump((uint32_t*)output, 0x100);
for (int j = 0; j < sz/4; j++) {
if (buf[4][j] != output[j]) {
printf("MISMATCH %d real:%f comp:%f\n", j, buf[4][j], output[j]);
}
}
}
return 0;
}
float state[TEMPORAL_SIZE];
mdl.addRecurrent(state, TEMPORAL_SIZE);
float desire[DESIRE_LEN];
mdl.addDesire(desire, DESIRE_LEN);
float traffic_convention[TRAFFIC_CONVENTION_LEN];
mdl.addTrafficConvention(traffic_convention, TRAFFIC_CONVENTION_LEN);
float *input = (float*)calloc(0x1000000, sizeof(float));;
// first run
printf("************** execute 1 **************\n");
memset(output, 0, sizeof(output));
mdl.execute(input, 0);
hexdump((uint32_t *)output, 0x100);
memcpy(golden, output, sizeof(output));
// second run
printf("************** execute 2 **************\n");
memset(output, 0, sizeof(output));
Thneed *t = new Thneed();
t->record = 3; // debug print with record
mdl.execute(input, 0);
t->stop();
hexdump((uint32_t *)output, 0x100);
if (memcmp(golden, output, sizeof(output)) != 0) { printf("FAILURE\n"); return -1; }
// third run
printf("************** execute 3 **************\n");
memset(output, 0, sizeof(output));
t->record = 2; // debug print w/o record
float *inputs[4] = {state, traffic_convention, desire, input};
t->execute(inputs, output);
hexdump((uint32_t *)output, 0x100);
if (memcmp(golden, output, sizeof(output)) != 0) { printf("FAILURE\n"); return -1; }
printf("************** execute 4 **************\n");
memset(output, 0, sizeof(output));
//t->record = 2; // debug print w/o record
t->execute(inputs, output);
hexdump((uint32_t *)output, 0x100);
if (memcmp(golden, output, sizeof(output)) != 0) { printf("FAILURE\n"); return -1; }
printf("************** execute done **************\n");
}