@@ -31,9 +31,9 @@ class ONNXInference : public edm::stream::EDAnalyzer<edm::GlobalCache<ONNXRuntim
31
31
static void globalEndJob (const ONNXRuntime*);
32
32
33
33
private:
34
- void beginJob ();
34
+ void beginJob (){} ;
35
35
void analyze (const edm::Event&, const edm::EventSetup&);
36
- void endJob ();
36
+ void endJob (){} ;
37
37
38
38
inline float drawNormal () { return normalPdf_ (rndGen_); }
39
39
@@ -76,10 +76,9 @@ void ONNXInference::fillDescriptions(edm::ConfigurationDescriptions& description
76
76
// the rank (number of dimensions) of each input tensor
77
77
desc.add <std::vector<int >>(" inputRanks" );
78
78
// flat list of sizes of each dimension of each input tensor
79
- // (for a graph with a 1D and a 2D input tensor, this would be a vector of
80
- // three values)
79
+ // (for a graph with a 1D and a 2D input tensor, this would be a vector of three values)
81
80
desc.add <std::vector<int >>(" flatInputSizes" );
82
- // batch sizes to test
81
+ // batch size to test
83
82
desc.add <int >(" batchSize" );
84
83
// the number of calls to the graph to measure the runtime
85
84
desc.add <int >(" nCalls" );
@@ -133,9 +132,10 @@ ONNXInference::ONNXInference(const edm::ParameterSet& iConfig, const ONNXRuntime
133
132
inputType_ = mlprof::InputType::Random;
134
133
} else if (inputTypeStr_ == " zeros" ) {
135
134
inputType_ = mlprof::InputType::Zeros;
135
+ } else if (inputTypeStr_ == " ones" ) {
136
+ inputType_ = mlprof::InputType::Ones;
136
137
} else {
137
- throw cms::Exception (" InvalidInputType" )
138
- << " input type must be either 'incremental', 'zeros' or 'random', got " << inputTypeStr_;
138
+ throw cms::Exception (" InvalidInputType" ) << " input type unknown: " << inputTypeStr_;
139
139
}
140
140
141
141
// initialize the input_shapes array with inputRanks_ and flatInputSizes_
@@ -147,10 +147,12 @@ ONNXInference::ONNXInference(const edm::ParameterSet& iConfig, const ONNXRuntime
147
147
i += rank;
148
148
}
149
149
// initialize the input data arrays
150
- // note there is only one element in the FloatArrays type (i.e.
151
- // vector<vector<float>>) variable
150
+ // note there is only one element in the FloatArrays type (i.e. vector<vector<float>>) variable
152
151
for (int i = 0 ; i < nInputs_; i++) {
153
- inputArrays_.emplace_back (batchSize_ * flatInputSizes_[i], 0 );
152
+ // multiply the size of all dimensions in an input
153
+ int full_size_input = std::accumulate (begin (input_shapes_[i]), end (input_shapes_[i]), 1 , std::multiplies<int >());
154
+ // initialize inputArrays_ with 0s at first
155
+ inputArrays_.emplace_back (full_size_input, 0 );
154
156
}
155
157
}
156
158
@@ -167,7 +169,7 @@ void ONNXInference::analyze(const edm::Event& iEvent, const edm::EventSetup& iSe
167
169
for (int i = 0 ; i < (int )group_data.size (); i++) {
168
170
group_data[i] = inputType_ == mlprof::InputType::Incremental
169
171
? float (i)
170
- : (inputType_ == mlprof::InputType::Zeros ? float ( 0 ) : drawNormal ());
172
+ : float (inputType_ == mlprof::InputType::Zeros ? 0 : drawNormal ());
171
173
}
172
174
}
173
175
@@ -183,7 +185,10 @@ void ONNXInference::analyze(const edm::Event& iEvent, const edm::EventSetup& iSe
183
185
std::vector<float > runtimes;
184
186
for (int r = 0 ; r < nCalls_; r++) {
185
187
auto start = std::chrono::high_resolution_clock::now ();
188
+
189
+ // inference
186
190
outputs = globalCache ()->run (inputTensorNames_, inputArrays_, input_shapes_, outputTensorNames_, batchSize_);
191
+
187
192
auto end = std::chrono::high_resolution_clock::now ();
188
193
std::chrono::duration<float > runtime_in_seconds = (end - start);
189
194
runtimes.push_back (runtime_in_seconds.count () * 1000 );
0 commit comments