onnxruntime/core/framework/utils.cc
// execute graph with cached info from FeedsFetchesManager.
execute graph with cached info from FeedsFetchesManager.
execute graph with cached info from FeedsFetchesManager .
common::Status ExecuteGraphWithCachedInfo(const SessionState& session_state,
                                          const FeedsFetchesManager& feeds_fetches_manager,
                                          const std::vector<MLValue>& feeds,
                                          std::vector<MLValue>& fetches,
                                          const std::unordered_map<size_t, IExecutor::CustomAllocator>& fetch_allocators,
                                          bool sequential_execution,
                                          const bool& terminate_flag,
                                          const logging::Logger& logger) {
  const auto& feeds_fetches_info = feeds_fetches_manager.GetFeedsFetchesInfo();
  auto device_copy_checks = feeds_fetches_manager.GetDeviceCopyChecks();
  std::unique_ptr<IExecutor> p_exec;
  if (sequential_execution) {
    p_exec = std::unique_ptr<IExecutor>(new SequentialExecutor(terminate_flag));
  } else {
    p_exec = std::unique_ptr<IExecutor>(new ParallelExecutor(session_state, terminate_flag));
  }
  if (device_copy_checks.status == DeviceCopyCheck::NoCopy) {
    ORT_RETURN_IF_ERROR(p_exec->Execute(session_state,
                                        feeds_fetches_info.feeds_mlvalue_idxs, feeds,
                                        feeds_fetches_info.fetches_mlvalue_idxs, fetches, fetch_allocators, logger));
  } else {
    const std::vector<MLValue>* p_feeds = &feeds;
    std::vector<MLValue>* p_fetches = &fetches;
    std::vector<MLValue> device_feeds;
    std::vector<MLValue> device_fetches;
    if (device_copy_checks.input_copy_needed == DeviceCopyCheck::Copy) {
      ORT_RETURN_IF_ERROR(CachedCopyInputsAcrossDevices(feeds, device_feeds,
                                                        feeds_fetches_manager.GetFeedsDeviceCopiers()));
      p_feeds = &device_feeds;
    }
    if (fetches.empty()) {
      fetches.resize(feeds_fetches_info.output_names.size());
    }
    if (device_copy_checks.output_copy_needed == DeviceCopyCheck::Copy) {
      ORT_RETURN_IF_ERROR(CachedSetupFetchesForExecute(fetches, device_fetches,
                                                       feeds_fetches_manager.GetCanUseFetchDuringExecutionFlags()));
      p_fetches = &device_fetches;
    }
    ORT_RETURN_IF_ERROR(p_exec->Execute(session_state,
                                        feeds_fetches_info.feeds_mlvalue_idxs, *p_feeds,
                                        feeds_fetches_info.fetches_mlvalue_idxs, *p_fetches, fetch_allocators,
                                        logger));
    if (device_copy_checks.output_copy_needed == DeviceCopyCheck::Copy) {
      ORT_RETURN_IF_ERROR(CachedCopyOutputsAcrossDevices(*p_fetches, fetches,
                                                         feeds_fetches_manager.GetFetchesDeviceCopiers()));
    }
  }
  return Status::OK();
}
common :: Status ExecuteGraphWithCachedInfo ( const SessionState & session_state , const FeedsFetchesManager & feeds_fetches_manager , const std :: vector < MLValue > & feeds , std :: vector < MLValue > & fetches , const std :: unordered_map < size_t , IExecutor :: CustomAllocator > & fetch_allocators , bool sequential_execution , const bool & terminate_flag , const logging :: Logger & logger ) { const auto & feeds_fetches_info = feeds_fetches_manager . GetFeedsFetchesInfo ( ) ; auto device_copy_checks = feeds_fetches_manager . GetDeviceCopyChecks ( ) ; std :: unique_ptr < IExecutor > p_exec ; if ( sequential_execution ) { p_exec = std :: unique_ptr < IExecutor > ( new SequentialExecutor ( terminate_flag ) ) ; } else { p_exec = std :: unique_ptr < IExecutor > ( new ParallelExecutor ( session_state , terminate_flag ) ) ; } if ( device_copy_checks . status == DeviceCopyCheck :: NoCopy ) { ORT_RETURN_IF_ERROR ( p_exec -> Execute ( session_state , feeds_fetches_info . feeds_mlvalue_idxs , feeds , feeds_fetches_info . fetches_mlvalue_idxs , fetches , fetch_allocators , logger ) ) ; } else { const std :: vector < MLValue > * p_feeds = & feeds ; std :: vector < MLValue > * p_fetches = & fetches ; std :: vector < MLValue > device_feeds ; std :: vector < MLValue > device_fetches ; if ( device_copy_checks . input_copy_needed == DeviceCopyCheck :: Copy ) { ORT_RETURN_IF_ERROR ( CachedCopyInputsAcrossDevices ( feeds , device_feeds , feeds_fetches_manager . GetFeedsDeviceCopiers ( ) ) ) ; p_feeds = & device_feeds ; } if ( fetches . empty ( ) ) { fetches . resize ( feeds_fetches_info . output_names . size ( ) ) ; } if ( device_copy_checks . output_copy_needed == DeviceCopyCheck :: Copy ) { ORT_RETURN_IF_ERROR ( CachedSetupFetchesForExecute ( fetches , device_fetches , feeds_fetches_manager . GetCanUseFetchDuringExecutionFlags ( ) ) ) ; p_fetches = & device_fetches ; } ORT_RETURN_IF_ERROR ( p_exec -> Execute ( session_state , feeds_fetches_info . feeds_mlvalue_idxs , * p_feeds , feeds_fetches_info . fetches_mlvalue_idxs , * p_fetches , fetch_allocators , logger ) ) ; if ( device_copy_checks . output_copy_needed == DeviceCopyCheck :: Copy ) { ORT_RETURN_IF_ERROR ( CachedCopyOutputsAcrossDevices ( * p_fetches , fetches , feeds_fetches_manager . GetFetchesDeviceCopiers ( ) ) ) ; } } return Status :: OK ( ) ; }
execute graph with cached info from FeedsFetchesManager.
execute graph with cached info from FeedsFetchesManager .
// no device copies are needed so simple execute // Copy inputs // setup fetches. // if no output copy is needed, we can just use the fetches directly. otherwise we need to use a temporary set // and run CopyOutputsAcrossDevices.