| 326 | } |
| 327 | |
| 328 | ::testing::AssertionResult HloTestBase::Run(string_view hlo_string, |
| 329 | bool run_hlo_passes, |
| 330 | ExecutionProfile* profile, |
| 331 | string backend_config) { |
| 332 | auto module_or_status = ParseAndReturnVerifiedModule(hlo_string); |
| 333 | if (!module_or_status.ok()) { |
| 334 | return ::testing::AssertionFailure() |
| 335 | << "Error while parsing HLO text format: " |
| 336 | << module_or_status.status().ToString(); |
| 337 | } |
| 338 | |
| 339 | std::unique_ptr<HloModule> module = std::move(module_or_status.ValueOrDie()); |
| 340 | const auto& fake_arguments = |
| 341 | MakeFakeArguments(module.get()).ConsumeValueOrDie(); |
| 342 | std::vector<Literal*> fake_argument_ptrs; |
| 343 | absl::c_transform( |
| 344 | fake_arguments, std::back_inserter(fake_argument_ptrs), |
| 345 | [](const Literal& literal) { return const_cast<Literal*>(&literal); }); |
| 346 | |
| 347 | if (profile != nullptr) { |
| 348 | // We have to enable HLO profiling since otherwise currently the |
| 349 | // ExecutionProfile is not correct. |
| 350 | // |
| 351 | // TODO(b/119432044): Fix collection of the ExecutionProfile |
| 352 | // so that this is not necessary. |
| 353 | HloModuleConfig config = module->config(); |
| 354 | DebugOptions debug_options = config.debug_options(); |
| 355 | debug_options.set_xla_hlo_profile(true); |
| 356 | config.set_debug_options(debug_options); |
| 357 | module->set_config(config); |
| 358 | } |
| 359 | |
| 360 | if (!backend_config.empty()) { |
| 361 | // Set backend configuration if it is given. |
| 362 | HloInstruction* instruction = |
| 363 | module->entry_computation()->root_instruction(); |
| 364 | instruction->set_raw_backend_config_string(backend_config); |
| 365 | } |
| 366 | |
| 367 | auto output = test_runner_.Execute(std::move(module), fake_argument_ptrs, |
| 368 | /*run_hlo_passes=*/run_hlo_passes, |
| 369 | /*profile=*/profile); |
| 370 | |
| 371 | return output.ok() |
| 372 | ? ::testing::AssertionSuccess() |
| 373 | : ::testing::AssertionFailure() << output.status().error_message(); |
| 374 | } |
| 375 | |
| 376 | ::testing::AssertionResult HloTestBase::RunMultipleTimes( |
| 377 | string_view hlo_string, bool run_hlo_passes, |
no test coverage detected