11#include " build.hpp"
22
3- void build_graph (Tensor& input, Tensor& output, bool comments) {
3+ void build_graph (Tensor& input, Tensor& output, bool comments,
4+ bool parallel = false ) {
45 if (comments) {
56 for (size_t i = 0 ; i < input.get_shape ().dims (); i++) {
67 std::cout << input.get_shape ()[i] << ' ' ;
@@ -20,6 +21,8 @@ void build_graph(Tensor& input, Tensor& output, bool comments) {
2021 std::cout << std::endl << std::endl;
2122 }
2223 }
24+ ImplType impl1 = parallel ? kTBB : kDefault ;
25+ ImplType impl2 = parallel ? kSTL : kDefault ;
2326 std::vector<std::shared_ptr<Layer>> layers;
2427
2528 std::string json_file = MODEL_PATH ;
@@ -68,7 +71,7 @@ void build_graph(Tensor& input, Tensor& output, bool comments) {
6871 Tensor tmp_values = tensor;
6972 Tensor tmp_bias = make_tensor (tensor.get_bias ());
7073 auto conv_layer = std::make_shared<ConvolutionalLayer>(
71- 1 , pads, 1 , tmp_values, tmp_bias);
74+ 1 , pads, 1 , tmp_values, tmp_bias, impl2 );
7275 conv_layer->setName (kConvolution );
7376 layers.push_back (conv_layer);
7477 if (comments) std::cout << " ConvLayer added to layers." << std::endl;
@@ -111,7 +114,7 @@ void build_graph(Tensor& input, Tensor& output, bool comments) {
111114 if (comments)
112115 std::cout << " PoolingLayer shape: " << shape[0 ] << " x" << shape[1 ]
113116 << std::endl;
114- auto pool_layer = std::make_shared<PoolingLayer>(shape, pooltype);
117+ auto pool_layer = std::make_shared<PoolingLayer>(shape, pooltype, impl1 );
115118 pool_layer->setName (kPooling );
116119 layers.push_back (pool_layer);
117120 if (comments) std::cout << " PoolingLayer added to layers." << std::endl;
@@ -161,6 +164,17 @@ void build_graph(Tensor& input, Tensor& output, bool comments) {
161164
162165 if (comments) std::cout << " Starting inference..." << std::endl;
163166 graph.inference ();
167+ #ifdef ENABLE_STATISTIC_TIME
168+ std::vector<std::string> times = graph.getTimeInfo ();
169+ std::cout << " !INFERENCE TIME INFO START!" << std::endl;
170+ for (size_t i = 0 ; i < times.size (); i++) {
171+ std::cout << times[i] << std::endl;
172+ }
173+ std::vector<int > elps_time = graph.getTime ();
174+ int sum = std::accumulate (elps_time.begin (), elps_time.end (), 0 );
175+ std::cout << " Elapsed inference time:" << sum << std::endl;
176+ std::cout << " !INFERENCE TIME INFO END!" << std::endl;
177+ #endif
164178 if (comments) std::cout << " Inference completed." << std::endl;
165179 if (comments) {
166180 std::vector<float > tmp_output = softmax<float >(*output.as <float >());
0 commit comments