| 445 | } |
| 446 | |
| 447 | void compute_persistent_node(GraphNode& node, const std::vector<std::unique_ptr<GraphNode>>& nodes, const std::unordered_map<size_t, size_t>& node_index_map) { |
| 448 | if (node.input_ids.empty()) { |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | auto it = node_index_map.find(node.input_ids[0]); |
| 453 | |
| 454 | if (it != node_index_map.end()) { |
| 455 | const auto& input_buffer = nodes[it->second]->output_buffer; |
| 456 | |
| 457 | if (!node.output_buffer.get_data()) { |
| 458 | node.output_buffer.allocate(); |
| 459 | } |
| 460 | |
| 461 | std::memcpy(node.output_buffer.get_data(), |
| 462 | input_buffer.get_data(), |
| 463 | input_buffer.byte_size); |
| 464 | } else { |
| 465 | if (node.output_buffer.get_data()) { |
| 466 | return; |
| 467 | } |
| 468 | throw std::runtime_error("PERSISTENT node input not found and not populated - this should not happen"); |
| 469 | } |
| 470 | } |