ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Driver.cpp File Reference
#include "Dump.h"
#include <arser/arser.h>
#include <foder/FileLoader.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <vector>
#include <string>
#include <signal.h>

Go to the source code of this file.

Functions

void handle_segfault (int signal, siginfo_t *si, void *arg)
 
int entry (int argc, char **argv)
 

Function Documentation

◆ entry()

int entry ( int  argc,
char **  argv 
)

Definition at line 38 of file Driver.cpp.

39{
40 // TODO add option to dump for all sub-graphs
42 "circle-operator allows users to retrieve operator information from a Circle model file"};
43 arser.add_argument("--name").nargs(0).help("Dump operators name in circle file");
44 arser.add_argument("--code").nargs(0).help("Dump operators code in circle file");
45 arser.add_argument("--output_path").help("Save output to file (default output is console)");
46 arser.add_argument("circle").help("Circle file to dump");
47
48 try
49 {
50 arser.parse(argc, argv);
51 }
52 catch (const std::runtime_error &err)
53 {
54 std::cerr << err.what() << std::endl;
55 std::cerr << arser;
56 return 255;
57 }
58
59 cirops::DumpOption option;
60 option.names = arser["--name"];
61 option.codes = arser["--code"];
62
63 std::ofstream oFstream;
64 std::ostream *oStream = &std::cout;
65 if (arser["--output_path"])
66 {
67 auto output_path = arser.get<std::string>("--output_path");
68 oFstream.open(output_path, std::ofstream::out | std::ofstream::trunc);
69 if (oFstream.fail())
70 {
71 std::cerr << "ERROR: Failed to create output to file " << output_path << std::endl;
72 return 255;
73 }
74 oStream = &oFstream;
75 }
76
77 // hook segment fault
78 struct sigaction sa;
79 memset(&sa, 0, sizeof(struct sigaction));
80 sigemptyset(&sa.sa_mask);
81 sa.sa_sigaction = handle_segfault;
82 sa.sa_flags = SA_SIGINFO;
83 sigaction(SIGSEGV, &sa, NULL);
84
85 std::string modelFile = arser.get<std::string>("circle");
86 // Load Circle model from a circle file
87 try
88 {
89 foder::FileLoader fileLoader{modelFile};
90 std::vector<char> modelData = fileLoader.load();
91 const circle::Model *circleModel = circle::GetModel(modelData.data());
92 if (circleModel == nullptr)
93 {
94 std::cerr << "ERROR: Failed to load circle '" << modelFile << "'" << std::endl;
95 return 255;
96 }
98 dump.run(*oStream, circleModel, option);
99 }
100 catch (const std::runtime_error &err)
101 {
102 std::cerr << "ERROR: " << err.what() << std::endl;
103 return 255;
104 }
105
106 if (oFstream.is_open())
107 {
108 oFstream.close();
109 }
110
111 return 0;
112}
void run(std::ostream &os, const circle::Model *model, const DumpOption &option)
Definition Dump.cpp:70
DataBuffer load(void) const
Definition FileLoader.h:39
void handle_segfault(int signal, siginfo_t *si, void *arg)
Definition Driver.cpp:32
void dump(const coco::Op *op, int indent)
Definition Dump.cpp:177
Definition arser.h:39

References cirops::DumpOption::codes, dump(), handle_segfault(), foder::FileLoader::load(), cirops::DumpOption::names, and cirops::DumpOperators::run().

◆ handle_segfault()

void handle_segfault ( int  signal,
siginfo_t *  si,
void *  arg 
)

Definition at line 32 of file Driver.cpp.

33{
34 std::cerr << "ERROR: Failed to load file" << std::endl;
35 exit(255);
36}

Referenced by entry().