Skip to content

Commit d1a499a

Browse files
author
NeiroYT
committed
Changes
1 parent 0cbff4e commit d1a499a

5 files changed

Lines changed: 504 additions & 93 deletions

File tree

app/Graph/onnx_subgraphs.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ void alexnet_inf_careless(Graph& graph, const RuntimeOptions& options,
1919
auto* o = new Tensor(output);
2020
auto* i = new Tensor(input);
2121
graph.inference(options);
22-
graph.setOutput(*o);
23-
graph.setInput(*i);
22+
if (graph.getLayersCount() == 0) {
23+
throw std::runtime_error("No layers");
24+
}
25+
graph.setOutput(graph.getLayerFromID(graph.getLayersCount() - 1), *o);
26+
graph.setInput(graph.getLayerFromID(0), *i);
2427
}
2528

2629
void alexnet_comparison() {
@@ -45,7 +48,7 @@ void alexnet_comparison() {
4548
RuntimeOptions options;
4649
Graph graph;
4750
Graph graph2;
48-
build_graph_linear(graph, input, output, options, true);
51+
build_graph_linear(graph, input, output, options, true, false);
4952
Graph subgraph;
5053
std::shared_ptr<Layer> layer_0 = std::make_shared<ConvolutionalLayer>();
5154
std::shared_ptr<Layer> layer_1 = std::make_shared<EWLayer>("relu");
@@ -57,9 +60,11 @@ void alexnet_comparison() {
5760
Tensor input_c = input;
5861
Tensor output_c = output;
5962
auto time1 = elapsed_time_avg<double, std::milli>(
60-
2, alexnet_inf_careless, graph, options, input_c, output_c);
63+
4, alexnet_inf_careless, graph, options, input_c, output_c);
64+
print_time_stats(graph);
6165
auto time2 = elapsed_time_avg<double, std::milli>(
62-
2, alexnet_inf_careless, graph2, options, input_c, output_c);
66+
4, alexnet_inf_careless, graph2, options, input_c, output_c);
67+
print_time_stats(graph2);
6368
std::cout << time1 << " for unchanged graph\n";
6469
std::cout << time2 << " for convrelu graph\n";
6570
}

include/graph/graph.hpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,6 @@ class Graph {
176176
start_ = layer->getID();
177177
}
178178

179-
void setInput(Tensor& vec) {
180-
if (layers_.empty()) {
181-
throw std::invalid_argument("No layers in graph");
182-
}
183-
int id = layers_.front()->getID();
184-
185-
inten_ = {vec};
186-
start_ = id;
187-
}
188-
189179
void addSingleLayer(const std::shared_ptr<Layer>& layer) {
190180
if (!layer) return;
191181

@@ -459,19 +449,6 @@ class Graph {
459449
}
460450
}
461451

462-
void setOutput(Tensor& vec) {
463-
if (layers_.empty()) {
464-
throw std::invalid_argument("No layers in graph");
465-
}
466-
end_ = layers_.back()->getID();
467-
outtenres_ = &vec;
468-
if (outten_.empty()) {
469-
std::vector<int> vec1 = {1, 7, 1, 0};
470-
Tensor start = make_tensor(vec1);
471-
outten_.push_back(start);
472-
}
473-
}
474-
475452
#ifdef ENABLE_STATISTIC_TENSORS
476453
std::vector<Tensor> getTensors() { return tensors_; }
477454
#endif

0 commit comments

Comments
 (0)