graph_preprocess.h 2.7 KB
Newer Older
L
lujiale 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
/**
 * Copyright 2019-2020 Huawei Technologies Co., Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef GE_GRAPH_PREPROCESS_GRAPH_PREPROCESS_H_
#define GE_GRAPH_PREPROCESS_GRAPH_PREPROCESS_H_

#include <fstream>
#include <iostream>
#include <memory>
#include <string>
#include <vector>

#include "common/debug/log.h"
#include "common/debug/memory_dumper.h"
#include "common/model_parser/base.h"
#include "common/properties_manager.h"
#include "common/string_util.h"
#include "common/types.h"
#include "common/util.h"
#include "graph/compute_graph.h"
#include "graph/manager/graph_manager_utils.h"
#include "graph/model.h"
#include "graph/node.h"
#include "graph/utils/graph_utils.h"
#include "graph/utils/tensor_utils.h"
#include "omg/omg_inner_types.h"
#include "runtime/context.h"

namespace ge {
class GraphPrepare {
 public:
  GraphPrepare();
  virtual ~GraphPrepare();
  GraphPrepare(const GraphPrepare &in) = delete;
  GraphPrepare &operator=(const GraphPrepare &in) = delete;
  Status Prepare(ConstGraphPtr graph, const std::vector<GeTensor> &user_input,
                 ge::ComputeGraphPtr &compute_graph, uint64_t session_id = 0);
  void SetOptions(const GraphManagerOptions &options);

 private:
  Status Init(const ge::Graph &graph, uint64_t session_id = 0);
  Status Preprocess(const std::vector<GeTensor> &user_input);
  Status CheckGraph();
  Status SetRtContext(rtContext_t rt_context, rtCtxMode_t mode);
  Status AdjustDataOpOutput(const NodePtr &node);
  Status UpdateInput(const std::vector<GeTensor> &user_input);
  Status CheckConstOp();
  Status VerifyConstOp(const NodePtr &node);
  Status CheckUserInput(const std::vector<GeTensor> &user_input);
  Status OptimizeForPreprocess();
  Status InferShapeForPreprocess();
  Status TryDoAipp();
  Status OptimizeForDataAfterInfershape();
  Status UpdateVariableFormats(ComputeGraphPtr &graph);
  Status FormatAndShapeProcess();
  Status ResourcePairProcess(const std::string& action);
  void ProcessCCEFormat();
  Status OptimizeBeforeInfershape();
  void SaveOriginalGraphToOmModel();
  ge::ComputeGraphPtr compute_graph_;
  GraphManagerOptions options_;
};
}  // namespace ge
#endif  // GE_GRAPH_PREPROCESS_GRAPH_PREPROCESS_H_