@@ -190,17 +190,7 @@ PackedFunc VirtualMachine::GetFunction(const std::string& name,
190190 } else if (name == " get_input_index" ) {
191191 return TypedPackedFunc<int64_t (std::string, std::string)>(
192192 [this ](std::string input_name, std::string func_name) {
193- auto gvit = exec_->global_map .find (func_name);
194- ICHECK (gvit != exec_->global_map .end ()) << " Cannot find function " << func_name;
195- auto func_index = gvit->second ;
196- const auto & vm_func = exec_->functions [func_index];
197- const auto & param_names = vm_func.params ;
198- for (uint64_t i = 0 ; i < param_names.size (); i++) {
199- if (input_name == param_names[i]) {
200- return static_cast <int64_t >(i);
201- }
202- }
203- return static_cast <int64_t >(-1 );
193+ return getInputIndexFromName (input_name, func_name);
204194 });
205195 } else if (name == " init" ) {
206196 return PackedFunc ([sptr_to_self, this ](TVMArgs args, TVMRetValue* rv) {
@@ -277,6 +267,18 @@ void VirtualMachine::SetInputWithIndex(std::string func_name, TVMArgs args) {
277267 SetInputTensorWithIndex (inputs_[func_name], args[2 ], inp_index, dev);
278268}
279269
270+ int64_t VirtualMachine::getInputIndexFromName (const std::string& input_name,
271+ const std::string& func_name) const {
272+ const auto & vm_func = checkAndGetVMFunction (func_name);
273+ const auto & param_names = vm_func.params ;
274+ for (uint64_t i = 0 ; i < param_names.size (); i++) {
275+ if (input_name == param_names[i]) {
276+ return static_cast <int64_t >(i);
277+ }
278+ }
279+ return static_cast <int64_t >(-1 );
280+ }
281+
280282const VMFunction& VirtualMachine::checkAndGetVMFunction (const std::string& func_name) const {
281283 ICHECK (exec_) << " The executable is not created yet." ;
282284 auto gvit = exec_->global_map .find (func_name);
0 commit comments