summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAjay Jayaraj2018-08-09 13:33:58 -0500
committerAjay Jayaraj2018-08-09 13:33:58 -0500
commit6932d34f1ea0395099cd8ecb5a948a0832cc02dd (patch)
tree01be8e9aeb389d0dc22b082cff9670984f9a1d2e /tidl_api
parent2357b3abd2635985447338875e06447fd873cf7d (diff)
downloadtidl-api-6932d34f1ea0395099cd8ecb5a948a0832cc02dd.tar.gz
tidl-api-6932d34f1ea0395099cd8ecb5a948a0832cc02dd.tar.xz
tidl-api-6932d34f1ea0395099cd8ecb5a948a0832cc02dd.zip
Support layer group id assignment updates
Provide API support for updating layer -> layer group id assignments before executing network. (MCT-1028)
Diffstat (limited to 'tidl_api')
-rw-r--r--tidl_api/inc/configuration.h9
-rw-r--r--tidl_api/src/configuration_parser.cpp68
-rw-r--r--tidl_api/src/executor.cpp8
3 files changed, 72 insertions, 13 deletions
diff --git a/tidl_api/inc/configuration.h b/tidl_api/inc/configuration.h
index 4bd3754..d1ebf09 100644
--- a/tidl_api/inc/configuration.h
+++ b/tidl_api/inc/configuration.h
@@ -31,6 +31,7 @@
31//! @file configuration.h 31//! @file configuration.h
32 32
33#include <string> 33#include <string>
34#include <map>
34#include <iostream> 35#include <iostream>
35 36
36namespace tidl { 37namespace tidl {
@@ -53,6 +54,8 @@ class Configuration
53 54
54 //! Number of channels in the input frame (e.g. 3 for BGR) 55 //! Number of channels in the input frame (e.g. 3 for BGR)
55 int inNumChannels; 56 int inNumChannels;
57
58 //! @private
56 int noZeroCoeffsPercentage; 59 int noZeroCoeffsPercentage;
57 60
58 //! Pre-processing type applied to the input frame 61 //! Pre-processing type applied to the input frame
@@ -89,6 +92,11 @@ class Configuration
89 //! Enable tracing of output buffers associated with each layer 92 //! Enable tracing of output buffers associated with each layer
90 bool enableOutputTrace; 93 bool enableOutputTrace;
91 94
95 //! Map of layer index to layer group id. Used to override layer group
96 //! assigment for layers. Any layer not specified in this map will
97 //! retain its existing mapping.
98 std::map<int, int> layerIndex2LayerGroupId;
99
92 //! Default constructor. 100 //! Default constructor.
93 Configuration(); 101 Configuration();
94 102
@@ -100,6 +108,7 @@ class Configuration
100 108
101 //! Read a configuration from the specified file and validate 109 //! Read a configuration from the specified file and validate
102 bool ReadFromFile(const std::string& file_name); 110 bool ReadFromFile(const std::string& file_name);
111
103}; 112};
104 113
105} 114}
diff --git a/tidl_api/src/configuration_parser.cpp b/tidl_api/src/configuration_parser.cpp
index e9df4c8..5871e71 100644
--- a/tidl_api/src/configuration_parser.cpp
+++ b/tidl_api/src/configuration_parser.cpp
@@ -28,12 +28,15 @@
28 28
29#include <boost/spirit/include/qi.hpp> 29#include <boost/spirit/include/qi.hpp>
30#include <boost/spirit/include/phoenix_operator.hpp> 30#include <boost/spirit/include/phoenix_operator.hpp>
31#include <boost/fusion/include/std_pair.hpp>
31 32
32#include <string> 33#include <string>
33#include <fstream> 34#include <fstream>
34#include <iostream> 35#include <iostream>
35#include <algorithm> 36#include <algorithm>
36#include <cctype> 37#include <cctype>
38#include <utility>
39#include <map>
37 40
38#include "configuration.h" 41#include "configuration.h"
39 42
@@ -55,29 +58,38 @@ struct ConfigParser : qi::grammar<Iterator, ascii::space_type>
55 using ascii::char_; 58 using ascii::char_;
56 using qi::_1; 59 using qi::_1;
57 60
58 path %= lexeme[+(char_ - '"')]; 61 // Rules for parsing layer id assignments: { {int, int}, ... }
62 id2group = '{' >> int_ >> ',' >> int_ >> '}';
63 id2groups = '{' >> id2group >> *(qi::lit(',') >> id2group) >> '}';
59 64
60 // Discard '"' 65 // Rules for parsing paths. Discard '"'
66 path %= lexeme[+(char_ - '"')];
61 q_path = qi::omit[*char_('"')] >> path >> qi::omit[*char_('"')]; 67 q_path = qi::omit[*char_('"')] >> path >> qi::omit[*char_('"')];
62 68
69 // Grammar for parsing configuration file
63 entry %= 70 entry %=
64 lit("#") >> *(char_) /* discard comments */ | 71 lit("layerIndex2LayerGroupId") >> '=' >>
65 lit("numFrames") >> '=' >> int_[ph::ref(x.numFrames) = _1] | 72 id2groups[ph::ref(x.layerIndex2LayerGroupId) = _1] |
66 lit("preProcType") >> '=' >> int_[ph::ref(x.preProcType) = _1] | 73 lit("#") >> *(char_) /* discard comments */ |
67 lit("inWidth") >> '=' >> int_[ph::ref(x.inWidth) = _1] | 74 lit("numFrames") >> '=' >> int_[ph::ref(x.numFrames) = _1] |
68 lit("inHeight") >> '=' >> int_[ph::ref(x.inHeight) = _1] | 75 lit("preProcType") >> '=' >> int_[ph::ref(x.preProcType) = _1] |
69 lit("inNumChannels") >> '=' >> int_[ph::ref(x.inNumChannels) = _1] | 76 lit("inWidth") >> '=' >> int_[ph::ref(x.inWidth) = _1] |
70 lit("inData") >> "=" >> q_path[ph::ref(x.inData) = _1] | 77 lit("inHeight") >> '=' >> int_[ph::ref(x.inHeight) = _1] |
71 lit("outData") >> "=" >> q_path[ph::ref(x.outData) = _1] | 78 lit("inNumChannels") >> '=' >> int_[ph::ref(x.inNumChannels) = _1] |
72 lit("netBinFile") >> "=" >> q_path[ph::ref(x.netBinFile) = _1] | 79 lit("inData") >> '=' >> q_path[ph::ref(x.inData) = _1] |
73 lit("paramsBinFile") >> "=" >> q_path[ph::ref(x.paramsBinFile) = _1] | 80 lit("outData") >> '=' >> q_path[ph::ref(x.outData) = _1] |
74 lit("enableTrace") >> "=" >> bool_[ph::ref(x.enableOutputTrace) = _1] 81 lit("netBinFile") >> '=' >> q_path[ph::ref(x.netBinFile) = _1] |
82 lit("paramsBinFile") >> '=' >> q_path[ph::ref(x.paramsBinFile) = _1] |
83 lit("enableTrace") >> '=' >> bool_[ph::ref(x.enableOutputTrace)= _1]
75 ; 84 ;
76 } 85 }
77 86
78 qi::rule<Iterator, std::string(), ascii::space_type> path; 87 qi::rule<Iterator, std::string(), ascii::space_type> path;
79 qi::rule<Iterator, std::string(), ascii::space_type> q_path; 88 qi::rule<Iterator, std::string(), ascii::space_type> q_path;
80 qi::rule<Iterator, ascii::space_type> entry; 89 qi::rule<Iterator, ascii::space_type> entry;
90
91 qi::rule<Iterator, std::pair<int, int>(), ascii::space_type> id2group;
92 qi::rule<Iterator, std::map<int, int>(), ascii::space_type> id2groups;
81}; 93};
82 94
83bool Configuration::ReadFromFile(const std::string &file_name) 95bool Configuration::ReadFromFile(const std::string &file_name)
@@ -126,3 +138,33 @@ bool Configuration::ReadFromFile(const std::string &file_name)
126 138
127 return true; 139 return true;
128} 140}
141
142#if 0
143--- test.cfg ---
144numFrames = 1
145preProcType = 0
146inData = ../test/testvecs/input/preproc_0_224x224.y
147outData = stats_tool_out.bin
148netBinFile = ../test/testvecs/config/tidl_models/tidl_net_imagenet_jacintonet11v2.bin
149paramsBinFile = ../test/testvecs/config/tidl_models/tidl_param_imagenet_jacintonet11v2.bin
150inWidth = 224
151inHeight = 224
152inNumChannels = 3
153
154# Enable tracing of output buffers
155enableTrace = true
156
157# Override layer group id assignments in the network
158layerIndex2LayerGroupId = { {12, 2}, {13, 2}, {14, 2} }
159----------------
160#endif
161
162#if TEST_PARSING
163int main()
164{
165 Configuration c;
166 c.ReadFromFile("test.cfg");
167
168 return 0;
169}
170#endif
diff --git a/tidl_api/src/executor.cpp b/tidl_api/src/executor.cpp
index d67f683..7929c42 100644
--- a/tidl_api/src/executor.cpp
+++ b/tidl_api/src/executor.cpp
@@ -122,6 +122,14 @@ bool ExecutorImpl::Initialize(const Configuration& configuration)
122 net->TIDLLayers[i].layersGroupId = layers_group_id_m; 122 net->TIDLLayers[i].layersGroupId = layers_group_id_m;
123 } 123 }
124 124
125 // If the user has specified an override mapping, apply it
126 else if (!configuration.layerIndex2LayerGroupId.empty())
127 {
128 for (const auto &item : configuration.layerIndex2LayerGroupId)
129 if (item.first < net->numLayers)
130 net->TIDLLayers[item.first].layersGroupId = item.second;
131 }
132
125 // Call a setup kernel to allocate and fill network parameters 133 // Call a setup kernel to allocate and fill network parameters
126 InitializeNetworkParams(shared_createparam.get()); 134 InitializeNetworkParams(shared_createparam.get());
127 135