Files
dragonpilot/selfdrive/modeld/runners/thneedmodel.cc
George Hotz 59fac9fdc6 Thneed load/save (#19700)
* start thneed load/save

* compiling

* fix loading

* build thneed model in scons

* don't hardcode /data/openpilot

* release files

* those too

* support for loading/saving binary kernels

* save binaries out of json band

* make binary a command line flag to the compiler

* need include assert

* fix shadowed common in SConscript

* cleanup run.h

* hmm, the recurrent buffer wasn't 0ed

* ugh, unique ptr

* remove power constraint, refactor record

* Revert "remove power constraint, refactor record"

This reverts commit bb6fa52db6df59cd9d6420a6f630430e35af8a5e.

* print on thneed stop

* fingers crossed for this one

* recorded

* just curious

* okay okay, pass tests?

* cleanups

* refactor wait

Co-authored-by: Comma Device <device@comma.ai>
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
2021-01-19 18:08:31 -08:00

42 lines
962 B
C++

#include "thneedmodel.h"
#include <assert.h>
ThneedModel::ThneedModel(const char *path, float *loutput, size_t loutput_size, int runtime) {
thneed = new Thneed(true);
thneed->record = 0;
thneed->load(path);
thneed->clexec();
thneed->find_inputs_outputs();
recorded = false;
output = loutput;
}
void ThneedModel::addRecurrent(float *state, int state_size) {
recurrent = state;
}
void ThneedModel::addTrafficConvention(float *state, int state_size) {
trafficConvention = state;
}
void ThneedModel::addDesire(float *state, int state_size) {
desire = state;
}
void ThneedModel::execute(float *net_input_buf, int buf_size) {
float *inputs[4] = {recurrent, trafficConvention, desire, net_input_buf};
if (!recorded) {
thneed->record = THNEED_RECORD;
thneed->copy_inputs(inputs);
thneed->clexec();
thneed->copy_output(output);
thneed->stop();
recorded = true;
} else {
thneed->execute(inputs, output);
}
}