| 
						
						
						
					 | 
					 | 
					@ -1,4 +1,5 @@ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include <cstring> | 
					 | 
					 | 
					 | 
					#include <cstring> | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					#include <getopt.h> | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include "selfdrive/modeld/runners/snpemodel.h" | 
					 | 
					 | 
					 | 
					#include "selfdrive/modeld/runners/snpemodel.h" | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					#include "selfdrive/modeld/thneed/thneed.h" | 
					 | 
					 | 
					 | 
					#include "selfdrive/modeld/thneed/thneed.h" | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -10,10 +11,36 @@ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					// TODO: This should probably use SNPE directly.
 | 
					 | 
					 | 
					 | 
					// TODO: This should probably use SNPE directly.
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					int main(int argc, char* argv[]) { | 
					 | 
					 | 
					 | 
					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 | 
					 | 
					 | 
					 | 
					  #define OUTPUT_SIZE 0x10000 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  float *output = (float*)calloc(OUTPUT_SIZE, sizeof(float)); | 
					 | 
					 | 
					 | 
					  float *output = (float*)calloc(OUTPUT_SIZE, sizeof(float)); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  SNPEModel mdl(argv[1], output, 0, USE_GPU_RUNTIME, true); | 
					 | 
					 | 
					 | 
					  SNPEModel mdl(input_file, output, 0, USE_GPU_RUNTIME, true); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  mdl.thneed->run_optimizer = run_optimizer; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  float state[TEMPORAL_SIZE] = {0}; | 
					 | 
					 | 
					 | 
					  float state[TEMPORAL_SIZE] = {0}; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  float desire[DESIRE_LEN] = {0}; | 
					 | 
					 | 
					 | 
					  float desire[DESIRE_LEN] = {0}; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -32,14 +59,20 @@ int main(int argc, char* argv[]) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  memset(output, 0, OUTPUT_SIZE * sizeof(float)); | 
					 | 
					 | 
					 | 
					  memset(output, 0, OUTPUT_SIZE * sizeof(float)); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  mdl.execute(); | 
					 | 
					 | 
					 | 
					  mdl.execute(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  // don't save?
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  if (!output_file) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    printf("no output file, exiting\n"); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    return 0; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					  } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  // save model
 | 
					 | 
					 | 
					 | 
					  // save model
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  bool save_binaries = (argc > 3) && (strcmp(argv[3], "--binary") == 0); | 
					 | 
					 | 
					 | 
					  printf("saving %s with binary %d\n", output_file, save_binaries); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  mdl.thneed->save(argv[2], save_binaries); | 
					 | 
					 | 
					 | 
					  mdl.thneed->save(output_file, save_binaries); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  // test model
 | 
					 | 
					 | 
					 | 
					  // test model
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  auto thneed = new Thneed(true); | 
					 | 
					 | 
					 | 
					  auto thneed = new Thneed(true); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  thneed->record = false; | 
					 | 
					 | 
					 | 
					  thneed->record = false; | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  thneed->load(argv[2]); | 
					 | 
					 | 
					 | 
					  thneed->load(output_file); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  thneed->clexec(); | 
					 | 
					 | 
					 | 
					  thneed->clexec(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					  thneed->find_inputs_outputs(); | 
					 | 
					 | 
					 | 
					  thneed->find_inputs_outputs(); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					 | 
					
  |