| 543 | graph_(std::move(graph)) {} |
| 544 | |
| 545 | Status Initialize() { |
| 546 | // Select precision based on given options. |
| 547 | CalculationsPrecision precision = CalculationsPrecision::F32; |
| 548 | if (options_.allow_precision_loss) { |
| 549 | precision = options_.priority == InferencePriority::MAX_PRECISION |
| 550 | ? CalculationsPrecision::F32_F16 |
| 551 | : CalculationsPrecision::F16; |
| 552 | } |
| 553 | |
| 554 | // Increase precision if not supported. |
| 555 | if (!environment_->IsSupported(precision)) { |
| 556 | precision = CalculationsPrecision::F32_F16; |
| 557 | if (!environment_->IsSupported(precision)) { |
| 558 | precision = CalculationsPrecision::F32; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | context_ = absl::make_unique<InferenceContext>(); |
| 563 | InferenceContext::CreateInferenceInfo create_info; |
| 564 | create_info.precision = precision; |
| 565 | create_info.storage_type = GetOptimalStorageType(environment_->device()); |
| 566 | create_info.hints.Add(ModelHints::kReduceKernelsCount); |
| 567 | // TODO(sorokin) temporary hack to speed up init time in some cases. |
| 568 | // TODO(sorokin): move this check to the place where hint is applied. |
| 569 | if ((precision == CalculationsPrecision::F16 || |
| 570 | precision == CalculationsPrecision::F32_F16) && |
| 571 | create_info.storage_type == TensorStorageType::TEXTURE_ARRAY && |
| 572 | environment_->device().IsAdreno6xxOrHigher()) { |
| 573 | create_info.hints.Add(ModelHints::kFastTuning); |
| 574 | } |
| 575 | RETURN_IF_ERROR( |
| 576 | context_->InitFromGraph(create_info, *graph_, environment_)); |
| 577 | |
| 578 | if (env_options_.IsGlAware()) { |
| 579 | gl_interop_fabric_ = absl::make_unique<GlInteropFabric>( |
| 580 | env_options_.egl_display, environment_); |
| 581 | } |
| 582 | tie_factory_ = absl::make_unique<TensorTieFactory>( |
| 583 | environment_, context_.get(), gl_interop_fabric_.get()); |
| 584 | |
| 585 | inputs_ = LinkTensors(graph_->inputs()); |
| 586 | outputs_ = LinkTensors(graph_->outputs()); |
| 587 | return OkStatus(); |
| 588 | } |
| 589 | |
| 590 | std::vector<TensorObjectDef> inputs() const override { |
| 591 | return GetExternalDefinitions(inputs_); |
nothing calls this directly
no test coverage detected