ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnc::cli Namespace Reference

Data Structures

class  BadOption
 simple exception class for invalid options More...
 
class  CommandLine
 this class describes a common command line interface More...
 
class  IOption
 interface for Option class More...
 
class  Option
 this class describes command line option More...
 
class  OptionType
 a class models option type More...
 
class  OptionType< T, false >
 
class  OptionType< T, true >
 

Functions

std::vector< std::string > optname (const char *names)
 convert option names for Option constructor
 
std::string overview (const char *descr)
 convert option overview for Option constructor
 
bool optional (bool is_optional)
 convert option overview for Option constructor
 
std::vector< std::string > optvalues (const char *vals)
 register valid values for option
 
std::vector< char > separators (const char *seps)
 separators that separate option name and its value
 
bool showopt (bool is_shown)
 
void checkInFile (const Option< std::string > &in_file)
 
void checkOutFile (const Option< std::string > &out_file)
 
void checkInDir (const Option< std::string > &dir)
 
void checkOutDir (const Option< std::string > &dir)
 

Variables

Option< bool > Help (optname("--help, -h"), overview("print usage and exit"), false, optional(true))
 
Option< bool > caffeFrontend (optname("--caffe"), overview("treat input file as Caffe model"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(false))
 
Option< bool > onnxFrontend (optname("--onnx"), overview("treat input file as ONNX model"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(false))
 
Option< bool > caffe2Frontend (optname("--caffe2"), overview("treat input file as Caffe2 model (predict_net.pb)"), false, optional(false), optvalues(""), nullptr, separators(""), showopt(false), IOption::Group::caffe2)
 
Option< std::vector< int > > inputShapes (optname("--input-shape"), overview("Shape of caffe2 input"), std::vector< int >{}, optional(false), optvalues(""), nullptr, separators(""), showopt(false), IOption::Group::caffe2)
 
Option< std::string > initNet (optname("--init-net"), overview("path to Caffe2 model weights (init_net.pb)"), std::string(), optional(false), optvalues(""), checkInFile, separators(""), showopt(false), IOption::Group::caffe2)
 
Option< bool > tflFrontend (optname("--tflite"), overview("treat input file as Tensor Flow Lite model"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(false))
 
Option< std::string > target (optname("--target"), overview("select target language to emit for given architecture." "Valid values are '" NNC_TARGET_ARM_CPP "', '" NNC_TARGET_X86_CPP "', '" NNC_TARGET_ARM_GPU_CPP "', '" NNC_TARGET_INTERPRETER "'"), std::string(), optional(false), optvalues(NNC_TARGET_ARM_CPP "," NNC_TARGET_X86_CPP "," NNC_TARGET_ARM_GPU_CPP "," NNC_TARGET_INTERPRETER), nullptr, separators("="))
 
Option< std::string > inputFile (optname("--nnmodel, -m"), overview("specify input file with serialized NN models"), std::string(), optional(false), optvalues(""), checkInFile)
 
Option< bool > doOptimizationPass (optname("-O"), overview("whether to optimize model or not"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(true))
 
Option< bool > dumpGraph (optname("--dump, -D"), overview("dump graph to dot files after optimization passes"), false, optional(true), optvalues(""), nullptr, separators(""), showopt(true))
 
Option< std::string > artifactName (optname("--output, -o"), overview("specify name for output files"), "nnmodel", optional(true), optvalues(""), checkOutFile)
 
Option< std::string > artifactDir (optname("--output-dir, -d"), overview("specify directory for output files"), ".", optional(true), optvalues(""), checkOutDir, separators("="))
 
Option< std::string > interInputDataDir (optname("--input-data-dir"), overview("specify directory with binary files " "containing the input data for the model " "(one file for each input with the same name)"), ".", optional(true), optvalues(""), checkInDir)
 

Function Documentation

◆ checkInDir()

void nnc::cli::checkInDir ( const Option< std::string > &  dir)

Definition at line 47 of file CLOptionChecker.cpp.

48{
49 auto stream = opendir(dir.c_str());
50
51 if (stream == nullptr)
52 throw BadOption(std::string("Could not open directory: ") + std::strerror(errno) + ".");
53
54 closedir(stream);
55} // checkInDir
simple exception class for invalid options
Definition CommandLine.h:38

◆ checkInFile()

void nnc::cli::checkInFile ( const Option< std::string > &  in_file)

Definition at line 27 of file CLOptionChecker.cpp.

28{
29 if (in_file.empty())
30 throw BadOption("Input file name should not be empty");
31
32 auto f = fopen(in_file.c_str(), "rb");
33 if (!f)
34 throw BadOption("Cannot open file <" + in_file + ">");
35 fclose(f);
36} // checkInFile

◆ checkOutDir()

void nnc::cli::checkOutDir ( const Option< std::string > &  dir)

Definition at line 57 of file CLOptionChecker.cpp.

58{
59 auto stream = opendir(dir.c_str());
60
61 if (stream == nullptr)
62 {
63 // Do not consider the missing directory an error.
64 if (errno == ENOENT)
65 return;
66
67 throw BadOption(std::string("Could not open directory: ") + std::strerror(errno) + ".");
68 }
69
70 closedir(stream);
71} // checkOutDir

◆ checkOutFile()

void nnc::cli::checkOutFile ( const Option< std::string > &  out_file)

Definition at line 38 of file CLOptionChecker.cpp.

39{
40 if (out_file.empty())
41 throw BadOption("Output file name should not be empty");
42
44
45} // checkOutFile

◆ optional()

bool nnc::cli::optional ( bool  is_optional)
inline

convert option overview for Option constructor

Definition at line 413 of file CommandLine.h.

413{ return is_optional; }

◆ optname()

std::vector< std::string > nnc::cli::optname ( const char *  names)

convert option names for Option constructor

Parameters
names- name of option, if option has several names then names must be represented by a string separated by a comma

Definition at line 71 of file CommandLine.cpp.

71{ return splitByComma(names); }

Referenced by nnc::cli::CommandLine::parseCommandLine().

◆ optvalues()

std::vector< std::string > nnc::cli::optvalues ( const char *  vals)

register valid values for option

Parameters
vals- valid values of option, if option has several that values then vals must be represented by a string separated by a comma

Definition at line 73 of file CommandLine.cpp.

73{ return splitByComma(vals); }

◆ overview()

std::string nnc::cli::overview ( const char *  descr)
inline

convert option overview for Option constructor

Definition at line 404 of file CommandLine.h.

405{
406 std::string overview(descr);
407 assert(!overview.empty());
408
409 return overview;
410}
std::string overview(const char *descr)
convert option overview for Option constructor

References overview().

Referenced by overview().

◆ separators()

std::vector< char > nnc::cli::separators ( const char *  seps)

separators that separate option name and its value

Parameters
seps- chars of separators separated by a comma

Definition at line 75 of file CommandLine.cpp.

76{
77 std::vector<char> ret;
78 int i;
79
80 if (std::string(seps).empty())
81 return ret;
82
83 for (i = 0; isspace(seps[i]); i++)
84 ;
85
86 if (seps[i])
87 {
88 ret.push_back(seps[i]);
89 i++;
90 }
91
92 for (; seps[i] != '\0'; i++)
93 {
94 if (seps[i] == ',')
95 {
96 for (i++; isspace(seps[i]); i++)
97 ;
98
99 ret.push_back(seps[i]);
100 }
101 }
102
103 return ret;
104}

◆ showopt()

bool nnc::cli::showopt ( bool  is_shown)
inline
Parameters
is_shown- if set to false, then option won't be shown in help message

Definition at line 431 of file CommandLine.h.

431{ return is_shown; }

Variable Documentation

◆ artifactDir

Option< std::string > nnc::cli::artifactDir ( optname("--output-dir, -d")  ,
overview("specify directory for output files")  ,
"."  ,
optional(true)  ,
optvalues("")  ,
checkOutDir  ,
separators("=")   
)

Options for backend

Definition at line 57 of file Options.h.

◆ artifactName

Option< std::string > nnc::cli::artifactName ( optname("--output, -o")  ,
overview("specify name for output files")  ,
"nnmodel"  ,
optional(true)  ,
optvalues("")  ,
checkOutFile   
)

Options for backend

Definition at line 58 of file Options.h.

◆ caffe2Frontend

Option< bool > nnc::cli::caffe2Frontend ( optname("--caffe2")  ,
overview("treat input file as Caffe2 model (predict_net.pb)")  ,
false  ,
optional(false)  ,
optvalues("")  ,
nullptr  ,
separators("")  ,
showopt(false)  ,
IOption::Group::caffe2   
)

Options for compiler driver

Definition at line 31 of file Options.h.

◆ caffeFrontend

Option< bool > nnc::cli::caffeFrontend ( optname("--caffe")  ,
overview("treat input file as Caffe model")  ,
false  ,
optional(true)  ,
optvalues("")  ,
nullptr  ,
separators("")  ,
showopt(false)   
)

Definition at line 35 of file Options.h.

◆ doOptimizationPass

Option< bool > nnc::cli::doOptimizationPass ( optname("-O")  ,
overview("whether to optimize model or not")  ,
false  ,
optional(true)  ,
optvalues("")  ,
nullptr  ,
separators("")  ,
showopt(true)   
)

Options for optimizer

Definition at line 39 of file Options.h.

◆ dumpGraph

Option< bool > nnc::cli::dumpGraph ( optname("--dump, -D")  ,
overview("dump graph to dot files after optimization passes")  ,
false  ,
optional(true)  ,
optvalues("")  ,
nullptr  ,
separators("")  ,
showopt(true)   
)

Definition at line 40 of file Options.h.

◆ Help

Option< bool > nnc::cli::Help(optname("--help, -h"), overview("print usage and exit"), false, optional(true)) ( optname("--help, -h")  ,
overview("print usage and exit")  ,
false  ,
optional(true)   
)

Options for compiler driver

◆ initNet

Option< std::string > nnc::cli::initNet ( optname("--init-net")  ,
overview("path to Caffe2 model weights (init_net.pb)")  ,
std::string()  ,
optional(false)  ,
optvalues("")  ,
checkInFile  ,
separators("")  ,
showopt(false)  ,
IOption::Group::caffe2   
)

Definition at line 33 of file Options.h.

◆ inputFile

Option< std::string > nnc::cli::inputFile ( optname("--nnmodel, -m")  ,
overview("specify input file with serialized NN models")  ,
std::string()  ,
optional(false)  ,
optvalues("")  ,
checkInFile   
)

Options for frontend

Frontend options

Definition at line 52 of file Options.h.

◆ inputShapes

Option< std::vector< int > > nnc::cli::inputShapes ( optname("--input-shape")  ,
overview("Shape of caffe2 input")  ,
std::vector< int >{}  ,
optional(false)  ,
optvalues("")  ,
nullptr  ,
separators("")  ,
showopt(false)  ,
IOption::Group::caffe2   
)

Definition at line 32 of file Options.h.

◆ interInputDataDir

Option< std::string > nnc::cli::interInputDataDir ( optname("--input-data-dir")  ,
overview("specify directory with binary files " "containing the input data for the model " "(one file for each input with the same name)")  ,
"."  ,
optional(true)  ,
optvalues("")  ,
checkInDir   
)

Options for interpreter

Options for interpreter

Definition at line 63 of file Options.h.

◆ onnxFrontend

Option< bool > nnc::cli::onnxFrontend ( optname("--onnx")  ,
overview("treat input file as ONNX model")  ,
false  ,
optional(true)  ,
optvalues("")  ,
nullptr  ,
separators("")  ,
showopt(false)   
)

Definition at line 37 of file Options.h.

◆ target

Option< std::string > nnc::cli::target ( optname("--target")  ,
overview("select target language to emit for given architecture." "Valid values are '" NNC_TARGET_ARM_CPP "', '" NNC_TARGET_X86_CPP "', '" NNC_TARGET_ARM_GPU_CPP "', '" NNC_TARGET_INTERPRETER "'")  ,
std::string()  ,
optional(false)  ,
optvalues(NNC_TARGET_ARM_CPP "," NNC_TARGET_X86_CPP "," NNC_TARGET_ARM_GPU_CPP "," NNC_TARGET_INTERPRETER ,
nullptr  ,
separators("=")   
)

Definition at line 47 of file Options.h.

◆ tflFrontend

Option< bool > nnc::cli::tflFrontend ( optname("--tflite")  ,
overview("treat input file as Tensor Flow Lite model")  ,
false  ,
optional(true)  ,
optvalues("")  ,
nullptr  ,
separators("")  ,
showopt(false)   
)

Definition at line 36 of file Options.h.