thneed: use util::read_file to read from the file (#22757)

old-commit-hash: 07ad6d7444
commatwo_master
Dean Lee 4 years ago committed by GitHub
parent 15ed1a50a3
commit 0ce639aa3c
  1. 17
      selfdrive/modeld/thneed/serialize.cc

@ -2,6 +2,7 @@
#include <set> #include <set>
#include "json11.hpp" #include "json11.hpp"
#include "selfdrive/common/util.h"
#include "selfdrive/modeld/thneed/thneed.h" #include "selfdrive/modeld/thneed/thneed.h"
using namespace json11; using namespace json11;
@ -10,23 +11,16 @@ extern map<cl_program, string> g_program_source;
void Thneed::load(const char *filename) { void Thneed::load(const char *filename) {
printf("Thneed::load: loading from %s\n", filename); printf("Thneed::load: loading from %s\n", filename);
FILE *f = fopen(filename, "rb"); string buf = util::read_file(filename);
fseek(f, 0L, SEEK_END); int jsz = *(int *)buf.data();
int sz = ftell(f);
fseek(f, 0L, SEEK_SET);
char *buf = (char*)malloc(sz);
fread(buf, 1, sz, f);
fclose(f);
int jsz = *(int *)buf;
string jj(buf+4, jsz);
string err; string err;
string jj(buf.data() + sizeof(int), jsz);
Json jdat = Json::parse(jj, err); Json jdat = Json::parse(jj, err);
map<cl_mem, cl_mem> real_mem; map<cl_mem, cl_mem> real_mem;
real_mem[NULL] = NULL; real_mem[NULL] = NULL;
int ptr = 4+jsz; int ptr = sizeof(int)+jsz;
for (auto &obj : jdat["objects"].array_items()) { for (auto &obj : jdat["objects"].array_items()) {
auto mobj = obj.object_items(); auto mobj = obj.object_items();
int sz = mobj["size"].int_value(); int sz = mobj["size"].int_value();
@ -135,7 +129,6 @@ void Thneed::load(const char *filename) {
kq.push_back(kk); kq.push_back(kk);
} }
free(buf);
clFinish(command_queue); clFinish(command_queue);
} }

Loading…
Cancel
Save