computations ::= (computation)+
| 531 | |
| 532 | // computations ::= (computation)+ |
| 533 | bool HloParserImpl::ParseComputations(HloModule* module) { |
| 534 | HloComputation* entry_computation = nullptr; |
| 535 | do { |
| 536 | if (!ParseComputation(&entry_computation)) { |
| 537 | return false; |
| 538 | } |
| 539 | } while (lexer_.GetKind() != TokKind::kEof); |
| 540 | |
| 541 | for (int i = 0; i < computations_.size(); i++) { |
| 542 | // If entry_computation is not nullptr, it means the computation it pointed |
| 543 | // to is marked with "ENTRY"; otherwise, no computation is marked with |
| 544 | // "ENTRY", and we use the last computation as the entry computation. We |
| 545 | // add the non-entry computations as embedded computations to the module. |
| 546 | if ((entry_computation != nullptr && |
| 547 | computations_[i].get() != entry_computation) || |
| 548 | (entry_computation == nullptr && i != computations_.size() - 1)) { |
| 549 | module->AddEmbeddedComputation(std::move(computations_[i])); |
| 550 | continue; |
| 551 | } |
| 552 | auto computation = module->AddEntryComputation(std::move(computations_[i])); |
| 553 | // The parameters and result layouts were set to default layout. Here we |
| 554 | // set the layouts to what the hlo text says. |
| 555 | for (int p = 0; p < computation->num_parameters(); p++) { |
| 556 | const Shape& param_shape = computation->parameter_instruction(p)->shape(); |
| 557 | TF_CHECK_OK(module->mutable_entry_computation_layout() |
| 558 | ->mutable_parameter_layout(p) |
| 559 | ->CopyLayoutFromShape(param_shape)); |
| 560 | } |
| 561 | const Shape& result_shape = computation->root_instruction()->shape(); |
| 562 | TF_CHECK_OK(module->mutable_entry_computation_layout() |
| 563 | ->mutable_result_layout() |
| 564 | ->CopyLayoutFromShape(result_shape)); |
| 565 | } |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | // computation ::= ('ENTRY')? name (param_list_to_shape)? instruction_list |
| 570 | bool HloParserImpl::ParseComputation(HloComputation** entry_computation) { |
nothing calls this directly
no test coverage detected