26 auto *main_runtime_graph = runtime_graph;
30 const auto *options = cur_op->builtin_options_as_IfOptions();
32 const auto cond_index = cur_op->inputs()->operator[](0);
33 const auto output_index = cur_op->outputs()->operator[](0);
35 const auto then_subgraph_index = options->then_subgraph_index();
36 const auto else_subgraph_index = options->else_subgraph_index();
38 assert(cond_index != -1);
39 assert(output_index != -1);
41 assert(then_subgraph_index != -1);
42 assert(else_subgraph_index != -1);
49 auto *then_subgraph = runtime_module->getRuntimeGraphAt(then_subgraph_index);
50 auto *else_subgraph = runtime_module->getRuntimeGraphAt(else_subgraph_index);
51 for (
RuntimeGraph *graph : {then_subgraph, else_subgraph})
53 graph->selectOwnSubgraph();
54 const auto graph_input_size = graph->getNumOfInputTensors();
55 const auto graph_output_size = graph->getNumOfOutputTensors();
59 graph->configure(
false);
61 main_runtime_graph->selectOwnSubgraph();
66 auto *main_runtime_graph = runtime_graph;
69 const auto input_size = cur_op->inputs()->size() - 1;
70 const auto output_size = cur_op->outputs()->size();
72 std::vector<uint8_t *> operation_inputs_data(input_size);
73 std::vector<uint8_t *> operation_outputs_data(output_size);
75 std::vector<int32_t> input_sizes(input_size);
76 std::vector<int32_t> output_sizes(output_size);
78 const auto *options = cur_op->builtin_options_as_IfOptions();
79 const auto cond_index = cur_op->inputs()->operator[](0);
81 const auto then_subgraph_index = options->then_subgraph_index();
82 const auto else_subgraph_index = options->else_subgraph_index();
84 auto *then_subgraph = runtime_module->getRuntimeGraphAt(then_subgraph_index);
85 auto *else_subgraph = runtime_module->getRuntimeGraphAt(else_subgraph_index);
90 const bool cond_value = kernels::getTensorData<bool>(cond_data)[0];
92 RuntimeGraph *active_graph = cond_value ? then_subgraph : else_subgraph;
94 for (int32_t i = 0; i < input_size; ++i)
96 const auto op_input_index = cur_op->inputs()->operator[](i + 1);
97 assert(op_input_index != -1);
98 const auto input = main_runtime_graph->getCircleTensorByIndex(op_input_index);
99 input_sizes[i] = Tensor::num_elements(input) *
size(Tensor::element_type(input));
101 auto *input_data = main_runtime_graph->getDataByTensor(input);
103 uint8_t *tensor_data =
nullptr;
104 if (input_data ==
nullptr)
105 input_data = main_runtime_graph->getConstDataByTensor(input);
106 assert(input_data !=
nullptr);
107 tensor_data = main_runtime_graph->getDataByTensor(input);
108 assert(tensor_data !=
nullptr);
110 operation_inputs_data[i] = tensor_data;
112 for (int32_t i = 0; i < output_size; ++i)
114 const auto op_output_index = cur_op->outputs()->operator[](i);
115 assert(op_output_index != -1);
116 const auto output = main_runtime_graph->getCircleTensorByIndex(op_output_index);
117 output_sizes[i] = Tensor::num_elements(output) *
size(Tensor::element_type(output));
119 auto *output_data = main_runtime_graph->getDataByTensor(output);
121 uint8_t *tensor_data =
nullptr;
122 if (output_data ==
nullptr)
123 output_data = main_runtime_graph->getConstDataByTensor(output);
124 assert(output_data !=
nullptr);
125 tensor_data = main_runtime_graph->getDataByTensor(output);
126 assert(tensor_data !=
nullptr);
128 operation_outputs_data[i] = tensor_data;
131 for (int32_t i = 0; i < input_size; ++i)
135 for (int32_t i = 0; i < output_size; ++i)
138 if (cur_output_active_data ==
nullptr)
140 std::memcpy(operation_outputs_data[i], cur_output_active_data, output_sizes[i]);
144 main_runtime_graph->selectOwnSubgraph();