| 1490 | } |
| 1491 | |
| 1492 | size_t CactusGraph::add_node(OpType op_type, const std::vector<size_t>& inputs, const std::vector<size_t>& output_shape, const OpParams& params) { |
| 1493 | auto node = std::make_unique<GraphNode>(next_node_id_, op_type); |
| 1494 | node->input_ids = inputs; |
| 1495 | node->params = params; |
| 1496 | |
| 1497 | std::vector<size_t> result_shape = output_shape; |
| 1498 | if (result_shape.empty() && !inputs.empty()) { |
| 1499 | result_shape = nodes_[node_index_map_[inputs[0]]]->output_buffer.shape; |
| 1500 | } |
| 1501 | |
| 1502 | Precision result_precision = params.output_precision; |
| 1503 | if (op_type == OpType::PRECISION_CAST) { |
| 1504 | result_precision = params.output_precision; |
| 1505 | } else if (result_precision == Precision::INT8 && !inputs.empty()) { |
| 1506 | result_precision = nodes_[node_index_map_[inputs[0]]]->output_buffer.precision; |
| 1507 | } |
| 1508 | |
| 1509 | node->output_buffer = BufferDesc(result_shape, result_precision); |
| 1510 | |
| 1511 | size_t node_id = next_node_id_++; |
| 1512 | node_index_map_[node_id] = nodes_.size(); |
| 1513 | nodes_.push_back(std::move(node)); |
| 1514 | |
| 1515 | return node_id; |
| 1516 | } |
| 1517 | |
| 1518 | const BufferDesc& CactusGraph::get_output_buffer(size_t node_id) const { |
| 1519 | return nodes_[node_index_map_.at(node_id)]->output_buffer; |
no test coverage detected