paddle/fluid/framework/executor.cc
static bool has_fetch_operators(
    const BlockDesc& block, std::map<std::string, LoDTensor*>& fetch_targets,
    const std::string& fetch_holder_name) {
  size_t fetch_count = 0;
  for (auto* op : block.AllOps()) {
    if (op->Type() == kFetchOpType) {
      fetch_count++;
      PADDLE_ENFORCE_EQ(op->Output("Out")[0], fetch_holder_name,
                        "Output of fetch op should be '%s'", fetch_holder_name);
      std::string fetch_target_name = op->Input("X")[0];
      PADDLE_ENFORCE(
          fetch_targets.find(fetch_target_name) != fetch_targets.end(),
          "Fetch operator input name '%s' cannot be found in 'fetch_targets'",
          fetch_target_name);
    }
  }

  if (fetch_count > 0) {
    PADDLE_ENFORCE_EQ(
        fetch_count, fetch_targets.size(),
        "The number of fetch operators should match 'fetch_targets'");

    // When fetch operator are present, so should be fetch_holder
    auto var = block.FindVar(fetch_holder_name);
    PADDLE_ENFORCE_NOT_NULL(var, "Block should already have a '%s' variable",
                            fetch_holder_name);
    PADDLE_ENFORCE_EQ(var->GetType(), proto::VarType::FETCH_LIST,
                      "'%s' variable should be 'FETCH_LIST' type",
                      fetch_holder_name);
  }

  return fetch_count > 0;
}
// Check whether the block already has fetch operators and fetch_holder.
// Return false if the block does not have any fetch operators.
// If some fetch operators have been appended to the block, check that
// the info contained in these fetch operators matches the fetch_targets
// and fetch_holder_name. Raise exception when any mismatch is found.
// Return true if the block has fetch operators and holder of matching info.
Check whether the block already has fetch operators and fetch_holder.
Return false if the block does not have any fetch operators.
If some fetch operators have been appended to the block, check that
the info contained in these fetch operators matches the fetch_targets
and fetch_holder_name. Raise exception when any mismatch is found.
Return true if the block has fetch operators and holder of matching info.
Check whether the block already has fetch operators and fetch_holder . Return false if the block does not have any fetch operators . If some fetch operators have been appended to the block check that the info contained in these fetch operators matches the fetch_targets and fetch_holder_name . Raise exception when any mismatch is found . Return true if the block has fetch operators and holder of matching info .
static bool has_fetch_operators(
    const BlockDesc& block, std::map<std::string, LoDTensor*>& fetch_targets,
    const std::string& fetch_holder_name) {
  size_t fetch_count = 0;
  for (auto* op : block.AllOps()) {
    if (op->Type() == kFetchOpType) {
      fetch_count++;
      PADDLE_ENFORCE_EQ(op->Output("Out")[0], fetch_holder_name,
                        "Output of fetch op should be '%s'", fetch_holder_name);
      std::string fetch_target_name = op->Input("X")[0];
      PADDLE_ENFORCE(
          fetch_targets.find(fetch_target_name) != fetch_targets.end(),
          "Fetch operator input name '%s' cannot be found in 'fetch_targets'",
          fetch_target_name);
    }
  }
  if (fetch_count > 0) {
    PADDLE_ENFORCE_EQ(
        fetch_count, fetch_targets.size(),
        "The number of fetch operators should match 'fetch_targets'");
    auto var = block.FindVar(fetch_holder_name);
    PADDLE_ENFORCE_NOT_NULL(var, "Block should already have a '%s' variable",
                            fetch_holder_name);
    PADDLE_ENFORCE_EQ(var->GetType(), proto::VarType::FETCH_LIST,
                      "'%s' variable should be 'FETCH_LIST' type",
                      fetch_holder_name);
  }
  return fetch_count > 0;
}
static bool has_fetch_operators ( const BlockDesc & block , std :: map < std :: string , LoDTensor * > & fetch_targets , const std :: string & fetch_holder_name ) { size_t fetch_count = 0 ; for ( auto * op : block . AllOps ( ) ) { if ( op -> Type ( ) == kFetchOpType ) { fetch_count ++ ; PADDLE_ENFORCE_EQ ( op -> Output ( " " ) [ 0 ] , fetch_holder_name , " " , fetch_holder_name ) ; std :: string fetch_target_name = op -> Input ( " " ) [ 0 ] ; PADDLE_ENFORCE ( fetch_targets . find ( fetch_target_name ) != fetch_targets . end ( ) , " " , fetch_target_name ) ; } } if ( fetch_count > 0 ) { PADDLE_ENFORCE_EQ ( fetch_count , fetch_targets . size ( ) , " " ) ; auto var = block . FindVar ( fetch_holder_name ) ; PADDLE_ENFORCE_NOT_NULL ( var , " " , fetch_holder_name ) ; PADDLE_ENFORCE_EQ ( var -> GetType ( ) , proto :: VarType :: FETCH_LIST , " " , fetch_holder_name ) ; } return fetch_count > 0 ; }
Check whether the block already has fetch operators and fetch_holder.
Check whether the block already has fetch operators and fetch_holder .
// When fetch operator are present, so should be fetch_holder