Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | |
Won Jeon | 2c34b46 | 2024-02-06 18:37:00 +0000 | [diff] [blame] | 2 | // Copyright (c) 2020-2024, ARM Limited. |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | #include "subgraph_traverser.h" |
James Ward | 24dbc42 | 2022-10-19 12:20:31 +0100 | [diff] [blame] | 17 | #include "arith_util.h" |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 18 | #include "tosa_model_types.h" |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 19 | |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 20 | #ifndef SUBGRAPH_ERROR_IF |
| 21 | #define SUBGRAPH_ERROR_IF(COND, fmt, ...) \ |
| 22 | if ((COND)) \ |
| 23 | { \ |
| 24 | if (this->getGraphStatus() != GraphStatus::TOSA_UNPREDICTABLE) \ |
| 25 | { \ |
| 26 | this->setGraphStatus(GraphStatus::TOSA_ERROR); \ |
| 27 | } \ |
| 28 | fprintf(g_func_debug.func_debug_file, COL_FATAL("SUBGRAPH_ERROR_IF() fails AT %s:%d %s(): (%s)\n"), __FILE__, \ |
| 29 | __LINE__, __func__, #COND); \ |
| 30 | fprintf(g_func_debug.func_debug_file, COL_FATAL(fmt) "\n", ##__VA_ARGS__); \ |
| 31 | func_print_backtrace(g_func_debug.func_debug_file); \ |
| 32 | return 1; \ |
| 33 | } |
| 34 | #endif |
| 35 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 36 | using namespace TosaReference; |
| 37 | using namespace Eigen; |
| 38 | using namespace tosa; |
| 39 | |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 40 | SubgraphTraverser::SubgraphTraverser(TosaSerializationBasicBlock* _block, |
| 41 | TosaSerializationHandler* _tsh, |
| 42 | SubgraphTraverser* _parent_sgt) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 43 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 44 | |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 45 | graph_status = GraphStatus::TOSA_VALID; |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 46 | block = _block; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 47 | |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 48 | tsh = _tsh; |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 49 | parent_sgt = _parent_sgt; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 50 | tensors.clear(); |
| 51 | nodes.clear(); |
| 52 | nextNodeList.clear(); |
| 53 | } |
| 54 | |
| 55 | SubgraphTraverser::~SubgraphTraverser() |
| 56 | { |
| 57 | nextNodeList.clear(); |
| 58 | |
| 59 | for (GraphNode* n : nodes) |
| 60 | { |
| 61 | delete n; |
| 62 | } |
| 63 | nodes.clear(); |
| 64 | |
| 65 | for (TosaReference::Tensor* t : tensors) |
| 66 | { |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 67 | if (t->getIsVariable() && parent_sgt) |
| 68 | { |
| 69 | // variable tensors are owned by top level sgt |
| 70 | continue; |
| 71 | } |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 72 | if (t->is_allocated()) |
| 73 | { |
| 74 | t->deallocate(); |
| 75 | } |
| 76 | delete t; |
| 77 | } |
| 78 | tensors.clear(); |
| 79 | } |
| 80 | |
| 81 | int SubgraphTraverser::getNumInputTensors() const |
| 82 | { |
| 83 | return inputTensors.size(); |
| 84 | } |
| 85 | |
| 86 | TosaReference::Tensor* SubgraphTraverser::getInputTensor(const unsigned int idx) const |
| 87 | { |
| 88 | return inputTensors[idx]; |
| 89 | } |
| 90 | |
| 91 | TosaReference::Tensor* SubgraphTraverser::getInputTensorByName(const std::string name) const |
| 92 | { |
| 93 | for (auto t : inputTensors) |
| 94 | { |
| 95 | if (t->getName() == name) |
| 96 | { |
| 97 | return t; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | return nullptr; |
| 102 | } |
| 103 | |
| 104 | int SubgraphTraverser::getNumOutputTensors() const |
| 105 | { |
| 106 | return outputTensors.size(); |
| 107 | } |
| 108 | |
| 109 | TosaReference::Tensor* SubgraphTraverser::getOutputTensor(const unsigned int idx) const |
| 110 | { |
| 111 | return outputTensors[idx]; |
| 112 | } |
| 113 | |
| 114 | TosaReference::Tensor* SubgraphTraverser::getOutputTensorByName(const std::string name) const |
| 115 | { |
| 116 | for (auto t : outputTensors) |
| 117 | { |
| 118 | if (t->getName() == name) |
| 119 | { |
| 120 | return t; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | return nullptr; |
| 125 | } |
| 126 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 127 | int SubgraphTraverser::getNumVariableTensors() const |
| 128 | { |
| 129 | return variableTensors.size(); |
| 130 | } |
| 131 | |
| 132 | TosaReference::Tensor* SubgraphTraverser::getVariableTensor(const unsigned int idx) const |
| 133 | { |
| 134 | return variableTensors[idx]; |
| 135 | } |
| 136 | |
| 137 | // find variable tensor by name in top level sgt's @a variableTensors |
| 138 | TosaReference::Tensor* SubgraphTraverser::getVariableTensorByName(const std::string name) const |
| 139 | { |
| 140 | // variable tensors are owned by top level sgt |
| 141 | if (parent_sgt) |
| 142 | { |
| 143 | return parent_sgt->getVariableTensorByName(name); |
| 144 | } |
| 145 | |
| 146 | for (auto t : variableTensors) |
| 147 | { |
| 148 | if (t->getName() == name) |
| 149 | { |
| 150 | return t; |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return nullptr; |
| 155 | } |
| 156 | |
| 157 | // add variable tensor to top level sgt's @a variableTensors |
| 158 | int SubgraphTraverser::registerVariableTensor(Tensor* tensor) |
| 159 | { |
| 160 | SUBGRAPH_ERROR_IF(!tensor->getIsVariable(), |
| 161 | "SubgraphTraverser::registerVariableTensor(): tensor %s is not a variable", |
| 162 | tensor->getName().c_str()); |
| 163 | // variable tensors are owned by top level sgt |
| 164 | if (parent_sgt) |
| 165 | { |
| 166 | return parent_sgt->registerVariableTensor(tensor); |
| 167 | } |
| 168 | variableTensors.push_back(tensor); |
| 169 | return 0; |
| 170 | } |
| 171 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 172 | int SubgraphTraverser::initializeGraph() |
| 173 | { |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 174 | int idx = 0; |
Kevin Cheng | c72b59c | 2021-09-29 16:57:55 -0700 | [diff] [blame] | 175 | |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 176 | std::vector<TosaSerializationTensor*> ser_tensor_vec; |
| 177 | // Get all the serialized tensors from TosaSerializationHandler. |
Jiacheng Liang | eb52cc1 | 2023-05-17 16:49:44 +0100 | [diff] [blame] | 178 | if (tsh) |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 179 | { |
Jiacheng Liang | eb52cc1 | 2023-05-17 16:49:44 +0100 | [diff] [blame] | 180 | for (auto region : tsh->GetRegions()) |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 181 | { |
Jiacheng Liang | eb52cc1 | 2023-05-17 16:49:44 +0100 | [diff] [blame] | 182 | for (auto block : region->GetBlocks()) |
Tai Ly | 4e9a977 | 2023-03-16 22:24:05 +0000 | [diff] [blame] | 183 | { |
Jiacheng Liang | eb52cc1 | 2023-05-17 16:49:44 +0100 | [diff] [blame] | 184 | for (auto ser_tensor : block->GetTensors()) |
| 185 | { |
| 186 | ser_tensor_vec.push_back(ser_tensor); |
| 187 | } |
Tai Ly | 4e9a977 | 2023-03-16 22:24:05 +0000 | [diff] [blame] | 188 | } |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 189 | } |
| 190 | } |
Jiacheng Liang | eb52cc1 | 2023-05-17 16:49:44 +0100 | [diff] [blame] | 191 | else |
| 192 | { |
| 193 | for (auto ser_tensor : block->GetTensors()) |
| 194 | { |
| 195 | ser_tensor_vec.push_back(ser_tensor); |
| 196 | } |
| 197 | } |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 198 | |
| 199 | std::vector<GraphNode*> non_const_node_vec; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 200 | for (auto op : block->GetOperators()) |
| 201 | { |
| 202 | // translated TosaSerializationOperator to GraphNode |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 203 | TOSA_REF_TYPE input_dtype = TOSA_REF_TYPE_UNKNOWN; |
| 204 | TOSA_REF_TYPE output_dtype = TOSA_REF_TYPE_UNKNOWN; |
| 205 | TOSA_REF_TYPE weight_dtype = TOSA_REF_TYPE_UNKNOWN; |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 206 | uint32_t input_rank = 0; |
| 207 | uint32_t output_rank = 0; |
| 208 | uint32_t weight_rank = 0; |
| 209 | int32_t input_index = -1; |
| 210 | int32_t weight_index = -1; |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 211 | |
| 212 | switch (op->GetOp()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 213 | { |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 214 | case Op_CONV2D: |
Kevin Cheng | 1533b85 | 2021-09-01 12:51:58 -0700 | [diff] [blame] | 215 | case Op_CONV3D: |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 216 | case Op_DEPTHWISE_CONV2D: |
| 217 | case Op_TRANSPOSE_CONV2D: |
| 218 | case Op_FULLY_CONNECTED: |
| 219 | input_index = 0; |
| 220 | weight_index = 1; |
| 221 | break; |
| 222 | case Op_SELECT: |
| 223 | input_index = 1; |
| 224 | break; |
| 225 | default: |
| 226 | if (!op->GetInputTensorNames().empty()) |
| 227 | input_index = 0; |
| 228 | break; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 231 | if (input_index != -1) |
Kevin Cheng | df86269 | 2021-02-22 15:22:22 -0800 | [diff] [blame] | 232 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 233 | SUBGRAPH_ERROR_IF( |
| 234 | (size_t)input_index >= op->GetInputTensorNames().size(), |
| 235 | "SubgraphTraverser::initializeGraph(): Op=%s, input_index %d must be within [0, num_input - 1]", |
| 236 | EnumNamesOp()[op->GetOp()], input_index); |
Kevin Cheng | df86269 | 2021-02-22 15:22:22 -0800 | [diff] [blame] | 237 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 238 | std::string input_name = op->GetInputTensorNames()[input_index]; |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 239 | TosaSerializationTensor* input_tensor = nullptr; |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 240 | for (auto ser_tensor : ser_tensor_vec) |
| 241 | { |
| 242 | if (ser_tensor->GetName() == input_name) |
| 243 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 244 | input_tensor = ser_tensor; |
| 245 | } |
| 246 | } |
| 247 | |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 248 | SUBGRAPH_ERROR_IF( |
| 249 | !input_tensor, |
| 250 | "SubgraphTraverser::initializeGraph(): fail to get input tensor %s from TosaSerializationHandler", |
| 251 | input_name.c_str()); |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 252 | input_dtype = ConvertDType(input_tensor->GetDtype()); |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 253 | input_rank = input_tensor->GetShape().size(); |
Kevin Cheng | df86269 | 2021-02-22 15:22:22 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 256 | if (weight_index != -1) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 257 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 258 | SUBGRAPH_ERROR_IF( |
| 259 | (size_t)weight_index >= op->GetInputTensorNames().size(), |
| 260 | "SubgraphTraverser::initializeGraph(): Op=%s, weight_index %d must be within [0, num_input - 1]", |
| 261 | EnumNamesOp()[op->GetOp()], weight_index); |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 262 | std::string weight_name = op->GetInputTensorNames()[weight_index]; |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 263 | TosaSerializationTensor* weight_tensor = nullptr; |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 264 | for (auto ser_tensor : ser_tensor_vec) |
| 265 | { |
| 266 | if (ser_tensor->GetName() == weight_name) |
| 267 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 268 | weight_tensor = ser_tensor; |
| 269 | } |
| 270 | } |
| 271 | |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 272 | SUBGRAPH_ERROR_IF( |
| 273 | !weight_tensor, |
| 274 | "SubgraphTraverser::initializeGraph(): fail to get weight tensor %s from TosaSerializationHandler", |
| 275 | weight_name.c_str()); |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 276 | weight_dtype = ConvertDType(weight_tensor->GetDtype()); |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 277 | weight_rank = weight_tensor->GetShape().size(); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 278 | } |
| 279 | |
Kevin Cheng | 478101b | 2021-10-04 10:43:14 -0700 | [diff] [blame] | 280 | SUBGRAPH_ERROR_IF(op->GetOutputTensorNames().size() == 0, |
| 281 | "SubgraphTraverser::initializeGraph(): Op=%s must have at least one output tensor.", |
| 282 | EnumNamesOp()[op->GetOp()]); |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 283 | std::string output_name = op->GetOutputTensorNames()[0]; |
| 284 | TosaSerializationTensor* output_tensor = block->GetTensorByName(output_name); |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 285 | SUBGRAPH_ERROR_IF( |
| 286 | !output_tensor, |
| 287 | "SubgraphTraverser::initializeGraph(): fail to get output tensor %s from TosaSerializationHandler", |
| 288 | output_name.c_str()); |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 289 | output_dtype = ConvertDType(output_tensor->GetDtype()); |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 290 | output_rank = output_tensor->GetShape().size(); |
| 291 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 292 | DEBUG_INFO(GT, "Creating operator id_%03u, %8s, %lu input tensors, %lu output tensors", idx, |
| 293 | EnumNamesOp()[op->GetOp()], op->GetInputTensorNames().size(), op->GetOutputTensorNames().size()); |
| 294 | |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 295 | GraphNode* node = nullptr; |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 296 | if (this->parent_sgt) |
| 297 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 298 | node = OpFactory::newOp(this->parent_sgt, tsh, op->GetOp(), op->GetAttribute(), idx, input_dtype, |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 299 | input_rank, output_dtype, output_rank, weight_dtype, weight_rank); |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 300 | node->setInMainBlock(false); |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 301 | } |
| 302 | else |
| 303 | { |
| 304 | node = OpFactory::newOp(this, tsh, op->GetOp(), op->GetAttribute(), idx, input_dtype, input_rank, |
| 305 | output_dtype, output_rank, weight_dtype, weight_rank); |
| 306 | if (node) |
| 307 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 308 | node->setInMainBlock(true); |
| 309 | } |
| 310 | } |
| 311 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 312 | if (!node) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 313 | { |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 314 | if (weight_index == -1) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 315 | { |
| 316 | fprintf(g_func_debug.func_debug_file, |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 317 | "SubgraphTraverser::initializeGraph(): OpFactory could not allocate op %8s input=(%s rank %d) " |
| 318 | "-> (%s rank %d)", |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 319 | EnumNamesOp()[op->GetOp()], EnumNameTOSAREFTYPE(input_dtype), input_rank, |
| 320 | EnumNameTOSAREFTYPE(output_dtype), output_rank); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 321 | } |
| 322 | else |
| 323 | { |
| 324 | fprintf(g_func_debug.func_debug_file, |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 325 | "SubgraphTraverser::initializeGraph(): OpFactory could not allocate op %8s input=(%s rank %d), " |
| 326 | "weight=(%s rank %d) -> (%s rank %d)", |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 327 | EnumNamesOp()[op->GetOp()], EnumNameTOSAREFTYPE(input_dtype), input_rank, |
| 328 | EnumNameTOSAREFTYPE(weight_dtype), weight_rank, EnumNameTOSAREFTYPE(output_dtype), output_rank); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 331 | for (auto& ts : op->GetInputTensorNames()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 332 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 333 | fprintf(g_func_debug.func_debug_file, "SubgraphTraverser::initializeGraph(): Input: %s\n", ts.c_str()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 336 | for (auto& ts : op->GetOutputTensorNames()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 337 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 338 | fprintf(g_func_debug.func_debug_file, "SubgraphTraverser::initializeGraph(): Output: %s\n", ts.c_str()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 339 | } |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 340 | SUBGRAPH_ERROR_IF(true, "SubgraphTraverser::initializeGraph(): Unsupported operation type or rank."); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Kevin Cheng | c72b59c | 2021-09-29 16:57:55 -0700 | [diff] [blame] | 343 | // Elementwise operator might set TOSA_ERROR when registering lambda function when creating the op. |
| 344 | // Check graph status after the op being constructed. |
| 345 | SUBGRAPH_ERROR_IF(getGraphStatus() == GraphStatus::TOSA_ERROR, |
| 346 | "SubgraphTraverser::initializeGraph(): Op %8s triggered ERROR_IF() when constructing the op.", |
| 347 | EnumNamesOp()[op->GetOp()]); |
| 348 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 349 | for (auto& name : op->GetInputTensorNames()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 350 | { |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 351 | node->addInputName(name); |
Kevin Cheng | c72b59c | 2021-09-29 16:57:55 -0700 | [diff] [blame] | 352 | used_tensor_name_set.insert(name); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | for (auto name : op->GetOutputTensorNames()) |
| 356 | { |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 357 | node->addOutputName(name); |
Kevin Cheng | c72b59c | 2021-09-29 16:57:55 -0700 | [diff] [blame] | 358 | used_tensor_name_set.insert(name); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 359 | } |
| 360 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 361 | addNode(node); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 362 | |
| 363 | // if node doesn't have any inputs (i.e. CONST) |
| 364 | // it should be ready for evaluation |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 365 | if (op->GetInputTensorNames().empty() && !node->getOnNextNodeList()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 366 | { |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 367 | addToNextNodeList(node); |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 368 | } |
| 369 | else if (!node->getInMainBlock()) |
| 370 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 371 | non_const_node_vec.push_back(node); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 374 | // Bug fix: add the ready node in main block for evaluation |
| 375 | if (node->hasAllInputsReady() && !node->getOnNextNodeList() && !node->getEvaluated()) |
| 376 | { |
| 377 | addToNextNodeList(node); |
| 378 | } |
| 379 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 380 | idx++; |
| 381 | } |
| 382 | |
| 383 | for (auto ts : block->GetTensors()) |
| 384 | { |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 385 | addTensor(ts); |
Kevin Cheng | cc61be3 | 2021-10-14 17:09:57 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | DEBUG_INFO(GT, "Enumerating block %s graph inputs", block->GetName().c_str()); |
| 389 | for (auto& input_name : block->GetInputs()) |
| 390 | { |
| 391 | TosaReference::Tensor* tensor = findTensorByName(input_name); |
| 392 | DEBUG_INFO(GT, "input tensor name=%s", input_name.c_str()); |
| 393 | if (tensor) |
| 394 | { |
| 395 | tensor->setIsSubgraphInput(); |
| 396 | inputTensors.push_back(tensor); |
| 397 | } |
| 398 | else |
| 399 | { |
| 400 | SUBGRAPH_ERROR_IF(true, "SubgraphTraverser::initializeGraph(): Failed to find input tensor by name %s", |
| 401 | input_name.c_str()); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | DEBUG_INFO(GT, "Enumerating block %s graph outputs", block->GetName().c_str()); |
| 406 | for (auto& output_name : block->GetOutputs()) |
| 407 | { |
| 408 | TosaReference::Tensor* tensor = findTensorByName(output_name); |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 409 | DEBUG_INFO(GT, "output tensor name=%s", output_name.c_str()); |
Kevin Cheng | cc61be3 | 2021-10-14 17:09:57 -0700 | [diff] [blame] | 410 | if (tensor) |
| 411 | { |
| 412 | tensor->setIsSubgraphOutput(); |
| 413 | outputTensors.push_back(tensor); |
| 414 | } |
| 415 | else |
| 416 | { |
| 417 | SUBGRAPH_ERROR_IF(true, "SubgraphTraverser::initializeGraph(): Failed to find output tensor by name %s", |
| 418 | output_name.c_str()); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | if (DEBUG_ENABLED(DEBUG_VERB_HIGH, GT)) |
| 423 | { |
| 424 | dumpNextNodeList(g_func_debug.func_debug_file); |
| 425 | } |
| 426 | |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 427 | // If the node is not in mainblock and not const |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 428 | for (auto node : non_const_node_vec) |
| 429 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 430 | bool all_inputs_from_parent = true; |
| 431 | for (std::string& name : node->getInputNames()) |
| 432 | { |
| 433 | TosaReference::Tensor* t = findTensorByName(name); |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 434 | if (!t->getIsParentGraphOutput()) |
| 435 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 436 | all_inputs_from_parent = false; |
| 437 | } |
| 438 | } |
| 439 | // In the children block, when a node has all its inputs from parent |
| 440 | // block, we have to manually add this node to the evaluation list |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 441 | if (all_inputs_from_parent && !node->getOnNextNodeList()) |
| 442 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 443 | addToNextNodeList(node); |
| 444 | } |
| 445 | } |
Kevin Cheng | cc61be3 | 2021-10-14 17:09:57 -0700 | [diff] [blame] | 446 | return 0; |
| 447 | } |
| 448 | |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 449 | int SubgraphTraverser::allocateInputTensors() |
Kevin Cheng | cc61be3 | 2021-10-14 17:09:57 -0700 | [diff] [blame] | 450 | { |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 451 | auto input_tensor_names_vec = block->GetInputs(); |
| 452 | |
| 453 | for (auto input_tensor_name : input_tensor_names_vec) |
Kevin Cheng | cc61be3 | 2021-10-14 17:09:57 -0700 | [diff] [blame] | 454 | { |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 455 | this->allocateTensor(input_tensor_name); |
| 456 | } |
| 457 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 458 | // allocate variable tensors if not already allocated |
| 459 | for (auto ts : block->GetTensors()) |
| 460 | { |
| 461 | if (ts->GetVariable()) |
| 462 | { |
| 463 | TosaReference::Tensor* tensor = findTensorByName(ts->GetName()); |
| 464 | SUBGRAPH_ERROR_IF(!tensor, "SubgraphTraverser::allocateInputTensors(): can't find tensor %s.", |
| 465 | ts->GetName().c_str()); |
| 466 | if (!tensor->is_allocated()) |
| 467 | { |
| 468 | DEBUG_INFO(GT, "Is a VariableTensor %s", ts->GetName().c_str()); |
| 469 | this->allocateTensor(ts->GetName()); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | int SubgraphTraverser::allocateTensor(std::string name) |
| 478 | { |
| 479 | auto ts = block->GetTensorByName(name); |
| 480 | |
| 481 | // Bail out if tensor is used and any of its dimension is invalid. |
| 482 | auto got = used_tensor_name_set.find(ts->GetName()); |
| 483 | if (got != used_tensor_name_set.end()) |
| 484 | { |
| 485 | uint32_t elements = 1; |
| 486 | for (auto& dim : ts->GetShape()) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 487 | { |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 488 | if (dim <= 0) |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 489 | { |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 490 | DEBUG_INFO(GT, "Failed to allocate tensor %s with invalid dimension of %d", ts->GetName().c_str(), dim); |
| 491 | this->setGraphStatus(GraphStatus::TOSA_UNPREDICTABLE); |
| 492 | return 1; |
| 493 | } |
| 494 | if (dim > static_cast<int32_t>(TOSA_MAX_TENSOR_SIZE / elements)) |
| 495 | { |
| 496 | // Size greather than maximum defined in spec |
| 497 | DEBUG_INFO(GT, "Tensor %s size is greater than allowed maximum", ts->GetName().c_str()); |
| 498 | this->setGraphStatus(GraphStatus::TOSA_UNPREDICTABLE); |
| 499 | return 1; |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 502 | } |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 503 | |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 504 | TosaReference::Tensor* tensor = findTensorByName(ts->GetName()); |
| 505 | SUBGRAPH_ERROR_IF(!tensor, "SubgraphTraverser::allocateTensor(): can't find tensor %s.", ts->GetName().c_str()); |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 506 | |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 507 | DEBUG_INFO(GT, "Allocating tensor %s", tensor->getName().c_str()); |
| 508 | if (tensor->allocate()) |
| 509 | { |
| 510 | FATAL_ERROR("Failed to allocate tensor %s", tensor->getName().c_str()); |
| 511 | } |
| 512 | |
Tai Ly | 8690a08 | 2023-12-18 20:40:24 +0000 | [diff] [blame] | 513 | // set valid for constant tensors: |
| 514 | if ((ts->GetShape().empty() && ts->GetDtype() == DType_SHAPE)) |
| 515 | { |
| 516 | // corner case: const_shape {} has no data |
| 517 | tensor->setIsValid(); |
| 518 | } |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 519 | if (!ts->GetData().empty()) |
| 520 | { |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 521 | if (ts->GetVariable() && g_func_config.initialize_variable_tensor_from_numpy) |
| 522 | return 0; |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 523 | DEBUG_INFO(GT, "Setting data for tensor %s", tensor->getName().c_str()); |
| 524 | auto serialization_dtype = ts->GetDtype(); |
| 525 | switch (serialization_dtype) |
Kevin Cheng | cc61be3 | 2021-10-14 17:09:57 -0700 | [diff] [blame] | 526 | { |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 527 | case DType_INT4: { |
| 528 | std::vector<int8_t> i4_data; |
| 529 | TosaSerializationHandler::ConvertU8toI4(ts->GetData(), tensor->getElementCount(), i4_data); |
| 530 | std::vector<int32_t> i32_data(i4_data.begin(), i4_data.end()); |
| 531 | tensor->setTensorValueInt32(i32_data.size(), i32_data.data()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 532 | } |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 533 | break; |
| 534 | case DType_INT8: { |
| 535 | std::vector<int8_t> i8_data; |
| 536 | TosaSerializationHandler::ConvertU8toI8(ts->GetData(), tensor->getElementCount(), i8_data); |
| 537 | std::vector<int32_t> i32_data(i8_data.begin(), i8_data.end()); |
| 538 | tensor->setTensorValueInt32(i32_data.size(), i32_data.data()); |
| 539 | } |
| 540 | break; |
| 541 | case DType_INT16: { |
| 542 | std::vector<int16_t> i16_data; |
| 543 | TosaSerializationHandler::ConvertU8toI16(ts->GetData(), tensor->getElementCount(), i16_data); |
| 544 | std::vector<int32_t> i32_data(i16_data.begin(), i16_data.end()); |
| 545 | tensor->setTensorValueInt32(i32_data.size(), i32_data.data()); |
| 546 | } |
| 547 | break; |
| 548 | case DType_INT32: { |
| 549 | std::vector<int32_t> i32_data; |
| 550 | TosaSerializationHandler::ConvertU8toI32(ts->GetData(), tensor->getElementCount(), i32_data); |
| 551 | tensor->setTensorValueInt32(i32_data.size(), i32_data.data()); |
| 552 | } |
| 553 | break; |
Tai Ly | 8690a08 | 2023-12-18 20:40:24 +0000 | [diff] [blame] | 554 | case DType_INT48: { |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 555 | std::vector<int64_t> i64_data; |
| 556 | TosaSerializationHandler::ConvertU8toI48(ts->GetData(), tensor->getElementCount(), i64_data); |
| 557 | tensor->setTensorValueInt64(i64_data.size(), i64_data.data()); |
| 558 | } |
| 559 | break; |
Tai Ly | 8690a08 | 2023-12-18 20:40:24 +0000 | [diff] [blame] | 560 | case DType_SHAPE: { |
| 561 | std::vector<int64_t> i64_data; |
| 562 | TosaSerializationHandler::ConvertU8toI64(ts->GetData(), tensor->getElementCount(), i64_data); |
| 563 | tensor->setTensorValueInt64(i64_data.size(), i64_data.data()); |
| 564 | } |
| 565 | break; |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 566 | case DType_FP16: { |
Jerry Ge | 6878053 | 2024-02-26 14:57:45 -0800 | [diff] [blame^] | 567 | std::vector<half_float::half> f16_data; |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 568 | TosaSerializationHandler::ConvertU8toF16(ts->GetData(), tensor->getElementCount(), f16_data); |
| 569 | if (tensor->getDtype() == TOSA_REF_TYPE_FP64) |
| 570 | { |
| 571 | std::vector<double> f64_data(f16_data.begin(), f16_data.end()); |
| 572 | tensor->setTensorValueDouble(f64_data.size(), f64_data.data()); |
| 573 | } |
| 574 | else |
| 575 | { |
Jerry Ge | 6878053 | 2024-02-26 14:57:45 -0800 | [diff] [blame^] | 576 | std::vector<float> f32_data(f16_data.begin(), f16_data.end()); |
| 577 | tensor->setTensorValueFloat(f32_data.size(), f32_data.data()); |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | break; |
| 581 | case DType_BF16: { |
| 582 | std::vector<float> fp32_data; |
| 583 | TosaSerializationHandler::ConvertU8toF32(ts->GetData(), tensor->getElementCount(), fp32_data); |
| 584 | // Ensure valid bfloat16 stored in each float |
| 585 | for (auto f : fp32_data) |
| 586 | ASSERT_MSG(checkValidBFloat(f), "Float value %f not valid bfloat16", f); |
| 587 | if (tensor->getDtype() == TOSA_REF_TYPE_FP64) |
| 588 | { |
| 589 | std::vector<double> f64_data(fp32_data.begin(), fp32_data.end()); |
| 590 | tensor->setTensorValueDouble(f64_data.size(), f64_data.data()); |
| 591 | } |
| 592 | else |
| 593 | { |
| 594 | tensor->setTensorValueFloat(fp32_data.size(), fp32_data.data()); |
| 595 | } |
| 596 | } |
| 597 | break; |
Won Jeon | 2c34b46 | 2024-02-06 18:37:00 +0000 | [diff] [blame] | 598 | case DType_FP8E4M3: |
| 599 | case DType_FP8E5M2: { |
| 600 | std::vector<float> fp32_data; |
| 601 | TosaSerializationHandler::ConvertU8toF32(ts->GetData(), tensor->getElementCount(), fp32_data); |
| 602 | // Ensure valid fp8 stored in each float |
| 603 | if (tensor->getDtype() == TOSA_REF_TYPE_FP64) |
| 604 | { |
| 605 | std::vector<double> f64_data(fp32_data.begin(), fp32_data.end()); |
| 606 | tensor->setTensorValueDouble(f64_data.size(), f64_data.data()); |
| 607 | } |
| 608 | else |
| 609 | { |
| 610 | tensor->setTensorValueFloat(fp32_data.size(), fp32_data.data()); |
| 611 | } |
| 612 | } |
| 613 | break; |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 614 | case DType_FP32: { |
| 615 | std::vector<float> fp32_data; |
| 616 | TosaSerializationHandler::ConvertU8toF32(ts->GetData(), tensor->getElementCount(), fp32_data); |
| 617 | if (tensor->getDtype() == TOSA_REF_TYPE_FP64) |
| 618 | { |
| 619 | std::vector<double> f64_data(fp32_data.begin(), fp32_data.end()); |
| 620 | tensor->setTensorValueDouble(f64_data.size(), f64_data.data()); |
| 621 | } |
| 622 | else |
| 623 | { |
| 624 | tensor->setTensorValueFloat(fp32_data.size(), fp32_data.data()); |
| 625 | } |
| 626 | } |
| 627 | break; |
| 628 | case DType_BOOL: { |
| 629 | std::vector<bool> bool_data; |
| 630 | TosaSerializationHandler::ConvertU8toBool(ts->GetData(), tensor->getElementCount(), bool_data); |
| 631 | |
| 632 | // std::vector<bool>::data() will return bit mask instead of array of bool array. |
| 633 | // Need to translate manually. |
| 634 | bool* bool_array = (bool*)calloc(bool_data.size(), sizeof(bool)); |
| 635 | for (size_t i = 0; i < bool_data.size(); i++) |
| 636 | { |
| 637 | bool_array[i] = bool_data[i]; |
| 638 | } |
| 639 | tensor->setTensorValueBool(bool_data.size(), bool_array); |
| 640 | } |
| 641 | break; |
| 642 | default: |
| 643 | SUBGRAPH_ERROR_IF(true, "SubgraphTraverser::initializeGraph(): Unsupported tensor type %s.", |
| 644 | EnumNameDType(ts->GetDtype())); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 645 | } |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 646 | tensor->setIsValid(); |
Tai Ly | 8690a08 | 2023-12-18 20:40:24 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | if (tensor->getIsValid()) |
| 650 | { |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 651 | // Push ready consumers to the next node list |
| 652 | for (auto gn : tensor->getConsumers()) |
| 653 | { |
| 654 | if (gn->hasAllInputsReady() && !gn->getOnNextNodeList() && !gn->getEvaluated()) |
| 655 | { |
| 656 | addToNextNodeList(gn); |
| 657 | } |
| 658 | } |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 659 | } |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 660 | return 0; |
| 661 | } |
| 662 | |
| 663 | int SubgraphTraverser::isFullyEvaluated() const |
| 664 | { |
| 665 | return nextNodeList.empty(); |
| 666 | } |
| 667 | |
| 668 | GraphNode* SubgraphTraverser::getNextNode() |
| 669 | { |
| 670 | GraphNode* nextNode = nextNodeList.front(); |
| 671 | ASSERT_MSG(nextNode, "SubgraphTraverser::getNextNode(): called with empty next node list"); |
| 672 | ASSERT_MSG(nextNode->getOnNextNodeList(), |
| 673 | "SubgraphTraverser::getNextNode(): internal state error: node is not listed as being on next node list"); |
| 674 | |
| 675 | nextNodeList.pop_front(); |
| 676 | |
| 677 | nextNode->clearOnNextNodeList(); |
| 678 | return nextNode; |
| 679 | } |
| 680 | |
| 681 | int SubgraphTraverser::addToNextNodeList(GraphNode* nextNode) |
| 682 | { |
| 683 | ASSERT_MSG(nextNode, "SubgraphTraverser::addToNextNodeList(): called with no node"); |
| 684 | ASSERT_MSG(!nextNode->getOnNextNodeList(), |
| 685 | "SubgraphTraverser::addToNextNodeList(): internal state error: node is already on next node list"); |
| 686 | |
| 687 | nextNode->setOnNextNodeList(); |
| 688 | nextNodeList.push_back(nextNode); |
| 689 | |
| 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | int SubgraphTraverser::evaluateNextNode() |
| 694 | { |
| 695 | if (isFullyEvaluated()) |
| 696 | return 0; |
| 697 | |
| 698 | GraphNode* currNode = getNextNode(); |
| 699 | |
| 700 | DEBUG_INFO(GT, "Evaluating node_%03lu, %8s, output tensor=%s", currNode->getID(), EnumNamesOp()[currNode->getOp()], |
| 701 | currNode->getOutputNames()[0].c_str()); |
| 702 | |
| 703 | // Sanity check for never-ending loops |
| 704 | if (currNode->getEvalCount() >= MAX_EVAL_COUNT && (currNode->getEvalCount() % MAX_EVAL_COUNT) == 0) |
| 705 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 706 | WARNING("SubgraphTraverser::evaluateNextNode(): Node %lu has been evaluated %d times. Loop suspected.", |
| 707 | currNode->getID(), currNode->getEvalCount()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 710 | for (auto tensor : currNode->getOutputs()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 711 | { |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 712 | if (!tensor->is_allocated()) |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 713 | { |
| 714 | if (this->allocateTensor(tensor->getName())) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 715 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 716 | FATAL_ERROR("SubgraphTraverser::evaluateNextNode(): Failed to allocate Eigen tensor %s", |
| 717 | tensor->getName().c_str()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 718 | } |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 719 | } |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | if (currNode->eval()) |
| 723 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 724 | WARNING("SubgraphTraverser::evaluateNextNode(): Failed to evaluate node: %lu", currNode->getID()); |
Kevin Cheng | acb550f | 2021-06-29 15:32:19 -0700 | [diff] [blame] | 725 | return 1; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 728 | currNode->setEvaluated(); |
| 729 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 730 | // free input tensor if all of its consumers have all of their outputs ready and it's not block's output |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 731 | for (auto tensor : currNode->getInputs()) |
| 732 | { |
| 733 | bool in_use = false; |
| 734 | |
| 735 | auto tensor_check = findTensorByName(tensor->getName()); |
| 736 | if (tensor_check->getIsParentGraphOutput()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 737 | { |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 738 | // if it's parent's block output tensor, we can't free it |
| 739 | continue; |
| 740 | } |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 741 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 742 | if (tensor->getIsVariable()) |
| 743 | { |
| 744 | // if tensor is a Variable, we cannot free it |
| 745 | continue; |
| 746 | } |
| 747 | |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 748 | for (auto node : tensor->getConsumers()) |
| 749 | { |
| 750 | // If the node is inside a loop, the input tensor is still needed |
| 751 | if (!node->hasAllOutputsReady()) |
Jerry Ge | 9c9c8da | 2023-07-19 23:08:16 +0000 | [diff] [blame] | 752 | { |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 753 | in_use = true; |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 754 | } |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 755 | } |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 756 | |
| 757 | for (auto name : block->GetOutputs()) |
| 758 | { |
| 759 | if (name == tensor->getName()) |
| 760 | { |
| 761 | in_use = true; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | if (!in_use) |
| 766 | { |
| 767 | tensor->deallocate(); |
| 768 | } |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 769 | } |
Jerry Ge | e5cabbf | 2023-07-17 21:33:17 +0000 | [diff] [blame] | 770 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 771 | // Search the output tensors of this node to see if |
| 772 | // there are now new ready nodes available from completing this node |
| 773 | for (TosaReference::Tensor* tensor : currNode->getOutputs()) |
| 774 | { |
| 775 | for (GraphNode* node : tensor->getConsumers()) |
| 776 | { |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 777 | if (!node->getOnNextNodeList() && node->hasAllInputsReady() && !node->getEvaluated()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 778 | { |
| 779 | addToNextNodeList(node); |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | if (DEBUG_ENABLED(DEBUG_VERB_HIGH, GT)) |
| 785 | { |
| 786 | dumpNextNodeList(g_func_debug.func_debug_file); |
| 787 | } |
| 788 | |
| 789 | if (g_func_config.dump_intermediates) |
| 790 | { |
| 791 | currNode->dumpNode(g_func_debug.func_debug_file); |
| 792 | for (auto outs : currNode->getOutputs()) |
| 793 | { |
| 794 | outs->dumpTensorParams(g_func_debug.func_debug_file); |
| 795 | outs->dumpTensor(g_func_debug.func_debug_file); |
| 796 | fprintf(g_func_debug.func_debug_file, "\n"); |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | int SubgraphTraverser::dumpNextNodeList(FILE* out) const |
| 804 | { |
| 805 | |
| 806 | // Dump next node list |
| 807 | fprintf(out, "Next node list\n"); |
| 808 | |
| 809 | if (nextNodeList.empty()) |
| 810 | { |
| 811 | fprintf(out, "<empty>\n"); |
| 812 | } |
| 813 | |
| 814 | for (auto gn : nextNodeList) |
| 815 | { |
| 816 | gn->dumpNode(out); |
| 817 | } |
| 818 | |
| 819 | fprintf(out, "Done.\n"); |
| 820 | return 0; |
| 821 | } |
| 822 | |
| 823 | int SubgraphTraverser::clearAllNodeMarkings() |
| 824 | { |
| 825 | for (GraphNode* currNode : nodes) |
| 826 | { |
| 827 | currNode->clearNodeMarked(); |
| 828 | } |
| 829 | |
| 830 | return false; |
| 831 | } |
| 832 | |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 833 | int SubgraphTraverser::addTensor(const TosaSerializationTensor* ts) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 834 | { |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 835 | TosaReference::Tensor* tensor = nullptr; |
| 836 | |
| 837 | // variable tensors are shared: make new tensor only if not found |
| 838 | if (ts->GetVariable()) |
| 839 | { |
| 840 | tensor = getVariableTensorByName(ts->GetName()); |
| 841 | } |
| 842 | |
| 843 | if (!tensor) |
| 844 | { |
| 845 | DEBUG_INFO(GT, "Creating tensor %s", ts->GetName().c_str()); |
| 846 | tensor = TensorFactory::newTensor(ts->GetName(), ts->GetDtype(), ts->GetShape(), ts->GetShape().size()); |
| 847 | |
| 848 | SUBGRAPH_ERROR_IF(!tensor, "SubgraphTraverser::initializeGraph(): Unsupported tensor name=%s, type=%s, rank=%d", |
| 849 | ts->GetName().c_str(), EnumNameDType(ts->GetDtype()), (int)ts->GetShape().size()); |
| 850 | |
| 851 | if (ts->GetVariable()) |
| 852 | { |
| 853 | tensor->setIsVariable(); |
| 854 | registerVariableTensor(tensor); |
| 855 | } |
| 856 | } |
| 857 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 858 | // Enforce no duplicate tensors/tensor names |
| 859 | // O(N), but the number of tensors is small |
| 860 | for (TosaReference::Tensor* currTensor : tensors) |
| 861 | { |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 862 | if (tensor == currTensor || currTensor->getName() == tensor->getName()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 863 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 864 | FATAL_ERROR("SubgraphTraverser::addTensor(): Duplicate tensor or tensor name being added to graph: %s\n", |
| 865 | tensor->getName().c_str()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 866 | return 1; |
| 867 | } |
| 868 | } |
| 869 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 870 | tensors.push_back(tensor); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 871 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 872 | if (tensor->getIsSubgraphInput()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 873 | { |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 874 | inputTensors.push_back(tensor); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 877 | if (tensor->getIsSubgraphOutput()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 878 | { |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 879 | outputTensors.push_back(tensor); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | return 0; |
| 883 | } |
| 884 | int SubgraphTraverser::addNode(GraphNode* newNode) |
| 885 | { |
| 886 | // Enforce no duplicate nodes |
| 887 | for (GraphNode* currNode : nodes) |
| 888 | { |
| 889 | if (currNode == newNode) |
| 890 | { |
Tai Ly | cf84bc9 | 2023-09-07 20:49:09 +0000 | [diff] [blame] | 891 | FATAL_ERROR("SubgraphTraverser::addNode(): duplicate node being added to graph"); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 892 | return 1; |
| 893 | } |
| 894 | } |
| 895 | |
| 896 | nodes.push_back(newNode); |
| 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
| 901 | TosaReference::Tensor* SubgraphTraverser::findTensorByName(const std::string& name) const |
| 902 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 903 | TosaReference::Tensor* res_tensor = nullptr; |
| 904 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 905 | for (TosaReference::Tensor* currTensor : tensors) |
| 906 | { |
| 907 | if (currTensor->getName() == name) |
| 908 | { |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 909 | res_tensor = currTensor; |
| 910 | return res_tensor; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 914 | if (parent_sgt) |
| 915 | { |
| 916 | for (TosaReference::Tensor* currTensor : parent_sgt->tensors) |
| 917 | { |
| 918 | if (currTensor->getName() == name) |
| 919 | { |
| 920 | res_tensor = currTensor; |
| 921 | res_tensor->setIsParentGraphOutput(); |
| 922 | } |
| 923 | } |
| 924 | } |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 925 | |
Jerry Ge | 9e94af8 | 2022-10-27 09:57:00 -0700 | [diff] [blame] | 926 | if (!res_tensor) |
| 927 | { |
| 928 | WARNING("SubgraphTraverser::findTensorByName(): Unable to find tensor with name: %s\n", name.c_str()); |
| 929 | return nullptr; |
| 930 | } |
| 931 | return res_tensor; |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | int SubgraphTraverser::linkTensorsAndNodes() |
| 935 | { |
| 936 | // Nodes have a list of input/output tensor names |
| 937 | // For each node, read this list, link up the tensors with their inputs/outputs |
| 938 | for (GraphNode* currNode : nodes) |
| 939 | { |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 940 | // Link inputs/consuming nodes |
| 941 | for (std::string& name : currNode->getInputNames()) |
| 942 | { |
| 943 | TosaReference::Tensor* t = findTensorByName(name); |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 944 | SUBGRAPH_ERROR_IF(!t, "SubgraphTraverser::linkTensorsAndNodes(): Cannot find tensor %s in node %lu\n", |
| 945 | name.c_str(), currNode->getID()); |
| 946 | SUBGRAPH_ERROR_IF(currNode->addInputTensor(t), |
| 947 | "SubgraphTraverser::linkTensorsAndNodes(): cannot link tensor %s to node %lu\n", |
| 948 | name.c_str(), currNode->getID()); |
| 949 | SUBGRAPH_ERROR_IF(t->addConsumer(currNode), |
| 950 | "SubgraphTraverser::linkTensorsAndNodes(): cannot link consumer node %lu to tensor %s\n", |
| 951 | currNode->getID(), name.c_str()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | // Link outputs/producing nodes |
| 955 | for (std::string& name : currNode->getOutputNames()) |
| 956 | { |
| 957 | TosaReference::Tensor* t = findTensorByName(name); |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 958 | SUBGRAPH_ERROR_IF(!t, "SubgraphTraverser::linkTensorsAndNodes(): Cannot find tensor %s in node %lu\n", |
| 959 | name.c_str(), currNode->getID()); |
| 960 | SUBGRAPH_ERROR_IF(currNode->addOutputTensor(t), |
| 961 | "SubgraphTraverser::linkTensorsAndNodes(): cannot link tensor %s to node %lu\n", |
| 962 | name.c_str(), currNode->getID()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 963 | |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 964 | SUBGRAPH_ERROR_IF( |
| 965 | t->setProducer(currNode), |
| 966 | "SubgraphTraverser::linkTensorsAndNodes(): cannot link producer node %lu to tensor tensor %s\n", |
| 967 | currNode->getID(), name.c_str()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 968 | } |
| 969 | } |
| 970 | |
| 971 | return 0; |
| 972 | } |
| 973 | |
| 974 | int SubgraphTraverser::validateGraph() |
| 975 | { |
| 976 | // Need to make sure that: |
| 977 | // - each tensor is actually used |
| 978 | // - input and output tesnsors truly are just input and just output |
| 979 | // Graph building already determined that each node has found its input/output tensors |
| 980 | |
| 981 | for (TosaReference::Tensor* currTensor : tensors) |
| 982 | { |
Kevin Cheng | 14d7f7a | 2021-05-12 10:44:49 -0700 | [diff] [blame] | 983 | // It's okay for block input tensor not being consumed by operators. |
| 984 | // This is common in control flow op execution. |
| 985 | if (!currTensor->getIsSubgraphInput()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 986 | { |
Kevin Cheng | 14d7f7a | 2021-05-12 10:44:49 -0700 | [diff] [blame] | 987 | if (!currTensor->getProducer() && currTensor->getConsumers().empty()) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 988 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 989 | WARNING("SubgraphTraverser::validateGraph(): TosaReference::Tensor %s has no producers or consumers\n", |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 990 | currTensor->getName().c_str()); |
| 991 | return 1; |
| 992 | } |
| 993 | } |
| 994 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 995 | if (g_func_config.tosa_profile == 0) |
| 996 | { |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 997 | TOSA_REF_TYPE dtype = currTensor->getDtype(); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 998 | |
| 999 | // Float-point disallowed |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 1000 | if (dtype == TOSA_REF_TYPE_FP32 || dtype == TOSA_REF_TYPE_FP16) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1001 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 1002 | WARNING("SubgraphTraverser::validateGraph(): TOSA Base Inference profile selected: All floating point " |
| 1003 | "disabled, but %s tensor %s found\n", |
Tai Ly | a4d748b | 2023-03-28 22:06:56 +0000 | [diff] [blame] | 1004 | EnumNameTOSAREFTYPE(dtype), currTensor->getName().c_str()); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1005 | return 1; |
| 1006 | } |
| 1007 | } |
| 1008 | else if (g_func_config.tosa_profile == 1 || g_func_config.tosa_profile == 2) |
| 1009 | { |
| 1010 | // Do nothing. All FP types allowed |
| 1011 | // Currently no implementation difference between Main Inference and Main Training modes |
| 1012 | } |
| 1013 | else |
| 1014 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 1015 | FATAL_ERROR("SubgraphTraverser::validateGraph(): TOSA profile not recognized: %d", |
| 1016 | g_func_config.tosa_profile); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | |
| 1020 | for (GraphNode* currNode : nodes) |
| 1021 | { |
Kevin Cheng | 903763c | 2021-09-28 16:14:52 -0700 | [diff] [blame] | 1022 | SUBGRAPH_ERROR_IF(currNode->checkTensorAttributes(), |
| 1023 | "SubgraphTraverser::validateGraph(): TosaReference::Tensor attribute check failed"); |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | if (outputTensors.size() <= 0) |
| 1027 | { |
| 1028 | DEBUG_MED(GT, "Graph output tensor empty"); |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
| 1035 | int SubgraphTraverser::dumpGraph(FILE* out) const |
| 1036 | { |
| 1037 | int i = 0; |
| 1038 | |
| 1039 | fprintf(out, "Full graph dump:\n"); |
| 1040 | for (GraphNode* currNode : nodes) |
| 1041 | { |
| 1042 | fprintf(out, "Node [%d]: ", i++); |
| 1043 | currNode->dumpNode(out); |
| 1044 | } |
| 1045 | |
| 1046 | return 0; |
| 1047 | } |
| 1048 | |
| 1049 | int SubgraphTraverser::evaluateAll() |
| 1050 | { |
| 1051 | // evaluation loop |
| 1052 | while (!isFullyEvaluated()) |
| 1053 | { |
| 1054 | if (evaluateNextNode()) |
| 1055 | { |
| 1056 | return 1; |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | return 0; |
| 1061 | } |