* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#ifndef INC_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_H_
#define INC_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_H_
#include <map>
#include <string>
#include "graph_optimizer_types.h"
#include "optimize_utility.h"
#include "common/ge_common/ge_inner_error_codes.h"
#include "common/opskernel/ops_kernel_info_types.h"
#include "graph/compute_graph.h"
#include "graph/op_kernel_bin.h"
namespace ge {
class GraphOptimizer {
public:
virtual ~GraphOptimizer() {}
virtual Status Initialize(const std::map<std::string, std::string> &options,
OptimizeUtility *const optimize_utility) = 0;
virtual Status Finalize() = 0;
virtual Status FinalizeSessionInfo(ComputeGraph& graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeGraphInit(ComputeGraph& graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeGraphPrepare(ComputeGraph& graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeAfterGraphNormalization(const ComputeGraphPtr& graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeGraphBeforeBuild(ComputeGraph& graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeOriginalGraph(ComputeGraph &graph) = 0;
virtual Status OptimizeOriginalGraphJudgeInsert(ComputeGraph &graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeFusedGraph(ComputeGraph &graph) = 0;
virtual Status OptimizeWholeGraph(ComputeGraph &graph) = 0;
virtual Status GetAttributes(GraphOptimizerAttribute &attrs) const = 0;
virtual Status OptimizeStreamGraph(ComputeGraph &graph, const RunContext &context) {
(void)graph;
(void)context;
return SUCCESS;
}
virtual Status OptimizeStreamedWholeGraph(ComputeGraph &graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeFusedGraphAfterGraphSlice(ComputeGraph &graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeAfterStage1(ComputeGraph &graph) {
(void)graph;
return SUCCESS;
}
using KernelLookup = std::function<OpKernelBinPtr(const std::string &kernel_name)>;
virtual Status OptimizeSubgraphOfPrecompiledOp(ComputeGraph &graph, const KernelLookup &lookup) {
static_cast<void>(graph);
static_cast<void>(lookup);
return SUCCESS;
}
virtual Status OptimizeSubgraphPreProc(ComputeGraph &graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeSubgraphPostProc(ComputeGraph &graph) {
(void)graph;
return SUCCESS;
}
virtual Status OptimizeOriginalGraphJudgeFormatInsert(ComputeGraph &graph) {
(void)graph;
return SUCCESS;
}
};
}
#endif