ONE - On-device Neural Engine
Loading...
Searching...
No Matches
partee Namespace Reference

Functions

bool make_dir (const std::string &path)
 create folder
 
std::string get_filename_ext (const std::string &base)
 get filename part of base
 
std::string make_path (const std::string &base, const std::string &input, uint32_t idx, const std::string &backend)
 Make file path from base and backend.
 
bool export_part_conn_json (const std::string &output_base, const std::string &input, const luci::Module *source, luci::PartedModules &pms)
 This will save partition connection to json format file.
 
bool export_part_conn_ini (const std::string &output_base, const std::string &input, const luci::Module *source, luci::PartedModules &pms)
 This will save partition connection to ini format file.
 
luci::PartitionTable read (const std::string &path)
 Reads and parse file and return PartitionTable.
 

Function Documentation

◆ export_part_conn_ini()

bool partee::export_part_conn_ini ( const std::string &  output_base,
const std::string &  input,
const luci::Module source,
luci::PartedModules pms 
)

This will save partition connection to ini format file.

Definition at line 115 of file PartitionExport.cpp.

117{
118 crew::PConfig pconfig;
119
120 // TODO is graph I/O using main graph is enough?
121 auto *graph = source->graph();
122
123 pconfig.source.model_file = input;
124 graph_io_to_config_part(graph, pconfig.source);
125
126 pms2config(pms, pconfig);
127
128 auto filepath_ini = export_file_path(output_base, input, ".ini");
129 std::ofstream fs(filepath_ini.c_str(), std::ofstream::binary | std::ofstream::trunc);
130 if (not fs.good())
131 {
132 std::cerr << "ERROR: Failed to create file: " << filepath_ini;
133 return false;
134 }
135 if (not write_ini(fs, pconfig))
136 {
137 std::cerr << "ERROR: Failed to write ini file: " << filepath_ini;
138 return false;
139 }
140 fs.close();
141
142 return true;
143}
loco::Graph * graph(void) const
provide main graph
Definition Module.cpp:32
Source source
Definition PConfig.h:39
std::string model_file
Definition PConfig.h:29

References luci::Module::graph(), crew::Part::model_file, and crew::PConfig::source.

Referenced by entry().

◆ export_part_conn_json()

bool partee::export_part_conn_json ( const std::string &  output_base,
const std::string &  input,
const luci::Module source,
luci::PartedModules pms 
)

This will save partition connection to json format file.

Definition at line 85 of file PartitionExport.cpp.

87{
88 crew::PConfig pconfig;
89
90 // TODO is graph I/O using main graph is enough?
91 auto *graph = source->graph();
92
93 pconfig.source.model_file = input;
94 graph_io_to_config_part(graph, pconfig.source);
95
96 pms2config(pms, pconfig);
97
98 auto filepath_json = export_file_path(output_base, input, ".json");
99 std::ofstream fs(filepath_json.c_str(), std::ofstream::binary | std::ofstream::trunc);
100 if (not fs.good())
101 {
102 std::cerr << "ERROR: Failed to create file: " << filepath_json;
103 return false;
104 }
105 if (not write_json(fs, pconfig))
106 {
107 std::cerr << "ERROR: Failed to write json file: " << filepath_json;
108 return false;
109 }
110 fs.close();
111
112 return true;
113}

References luci::Module::graph(), crew::Part::model_file, and crew::PConfig::source.

Referenced by entry().

◆ get_filename_ext()

std::string partee::get_filename_ext ( const std::string &  base)

get filename part of base

Definition at line 34 of file HelperPath.cpp.

35{
36 // find last '/' to get filename.ext
37 auto pos = base.find_last_of("/");
38 if (pos == std::string::npos)
39 return base;
40
41 return base.substr(pos + 1);
42}

Referenced by entry(), and make_path().

◆ make_dir()

bool partee::make_dir ( const std::string &  path)

create folder

Definition at line 26 of file HelperPath.cpp.

27{
28 std::string command("mkdir -p ");
29 command += path;
30 int ret = ::system(command.c_str());
31 return ret == 0;
32}

◆ make_path()

std::string partee::make_path ( const std::string &  base,
const std::string &  input,
uint32_t  idx,
const std::string &  backend 
)

Make file path from base and backend.

Definition at line 44 of file HelperPath.cpp.

46{
47 auto filename_ext = get_filename_ext(input);
48
49 // We will assume file type .circle if not given
50 // TODO maybe throw if there is no extension?
51 std::string filename = filename_ext;
52 std::string ext = "circle";
53
54 auto pos = filename_ext.find_last_of(".");
55 if (pos != std::string::npos)
56 {
57 filename = filename_ext.substr(0, pos);
58 ext = filename_ext.substr(pos + 1);
59 }
60
61 // format idx with 5 '0' paddings like '00123'
62 uint32_t length = 5;
63 auto seq = std::string(length, '0').append(std::to_string(idx));
64 auto seq_fmt = seq.substr(seq.size() - length);
65
66 return base + "/" + filename + "." + seq_fmt + "_" + backend + "." + ext;
67}
std::string get_filename_ext(const std::string &base)
get filename part of base

References get_filename_ext().

Referenced by entry().

◆ read()

luci::PartitionTable partee::read ( const std::string &  path)

Reads and parse file and return PartitionTable.

Definition at line 132 of file PartitionRead.cpp.

133{
134 LOGGER(l);
135
136 INFO(l) << "PartitionConfig: " << path << std::endl;
137
138 auto partition_config = crew::read_ini(path);
139
140 INFO(l) << partition_config << std::endl;
141
142 auto partition_table = parse_table(partition_config);
143
144 return partition_table;
145}
#define LOGGER(name)
Definition Log.h:65
#define INFO(name)
Definition Log.h:68
bool read_ini(const std::string &path, PConfig &config)
Read config as ini file, return false if failed.
Definition PConfig.cpp:121

References INFO, LOGGER, and crew::read_ini().

Referenced by entry().