1 #include <ATen/core/ivalue.h>
2 #include <torch/csrc/jit/mobile/parse_operators.h>
3
4 namespace torch::jit::mobile {
5
parseOperators(c10::ivalue::TupleElements && ops_list,const uint64_t & module_load_options,mobile::Function * function)6 void parseOperators(
7 c10::ivalue::TupleElements&& ops_list,
8 const uint64_t& module_load_options,
9 mobile::Function* function) {
10 for (auto& op : std::move(ops_list)) {
11 auto op_item = std::move(*std::move(op).toTuple()).elements();
12 TORCH_CHECK(
13 op_item.size() >= 2,
14 "There should be either two parts (name and overload name), ",
15 "or three parts (name, overload name and number of specified args) ",
16 "for an operator");
17 std::optional<int> num_args;
18 if (op_item.size() > 2) {
19 num_args = op_item[2].toInt();
20 }
21 function->append_operator(
22 op_item[0].toStringRef(), op_item[1].toStringRef(), num_args);
23 }
24 function->initialize_operators(
25 (module_load_options & MobileModuleLoadOptions::OPERATOR_CHECK));
26 }
27
28 } // namespace torch::jit::mobile
29