* 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 GE_OPSKERNEL_MANAGER_OPS_KERNEL_MANAGER_H_
#define GE_OPSKERNEL_MANAGER_OPS_KERNEL_MANAGER_H_
#include <map>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <mutex>
#include "framework/common/debug/log.h"
#include "graph_metadef/common/plugin/plugin_manager.h"
#include "common/plugin/op_tiling_manager.h"
#include "framework/common/ge_inner_error_codes.h"
#include "common/opskernel/ops_kernel_info_store.h"
#include "common/optimizer/graph_optimizer.h"
#include "graph/optimize/graph_optimize.h"
#include "graph/manager/util/graph_optimize_utility.h"
#include "framework/common/ge_inner_error_codes.h"
#include "ge/ge_api_types.h"
#include "runtime/base.h"
namespace ge {
using OpsKernelInfoStorePtr = std::shared_ptr<OpsKernelInfoStore>;
class GE_FUNC_VISIBILITY OpsKernelManager {
public:
friend class GELib;
static OpsKernelManager &GetInstance();
std::vector<OpInfo> GetOpsKernelInfo(const std::string &op_type);
const std::map<std::string, std::vector<OpInfo>> &GetAllOpsKernelInfo() const;
OpsKernelInfoStorePtr GetOpsKernelInfoStore(const std::string &name) const;
Status RefreshOpsKernelInfo();
const std::map<std::string, OpsKernelInfoStorePtr> &GetAllOpsKernelInfoStores() const;
const std::map<std::string, GraphOptimizerPtr> &GetAllGraphOptimizerObjs() const;
const std::vector<std::pair<std::string, GraphOptimizerPtr>> &GetAllGraphOptimizerObjsByPriority() const {
return atomic_first_optimizers_by_priority_;
}
const std::map<std::string, std::set<std::string>> &GetCompositeEngines() const {
return composite_engines_;
}
const std::map<std::string, std::string> &GetCompositeEngineKernelLibNames() const {
return composite_engine_kernel_lib_names_;
}
void GetGraphOptimizerByEngine(const std::string &engine_name, std::vector<GraphOptimizerPtr> &graph_optimizer);
bool GetEnableFftsFlag() const {
return enable_ffts_flag_;
}
private:
OpsKernelManager();
~OpsKernelManager();
Status Initialize(const std::map<std::string, std::string> &init_options);
Status Finalize();
Status InitOpKernelInfoStores(const std::map<std::string, std::string> &options);
Status CheckPluginPtr() const;
void GetExternalEnginePath(std::string &extern_engine_path, const std::map<std::string, std::string>& options) const;
void InitOpsKernelInfo(bool is_refresh = false);
Status InitGraphOptimizers(const std::map<std::string, std::string> &options);
void ClassifyGraphOptimizers();
void InitGraphOptimizerPriority();
Status FinalizeOpsKernel();
PluginManager plugin_manager_;
OpTilingManager op_tiling_manager_;
GraphOptimizeUtility graph_optimize_utility_;
std::map<std::string, OpsKernelInfoStorePtr> ops_kernel_store_{};
std::map<std::string, GraphOptimizerPtr> graph_optimizers_{};
std::map<std::string, GraphOptimizerPtr> composite_graph_optimizers_{};
std::map<std::string, GraphOptimizerPtr> atomic_graph_optimizers_{};
std::vector<std::pair<std::string, GraphOptimizerPtr>> atomic_graph_optimizers_by_priority_{};
std::vector<std::pair<std::string, GraphOptimizerPtr>> atomic_first_optimizers_by_priority_{};
std::map<std::string, std::set<std::string>> composite_engines_{};
std::map<std::string, std::string> composite_engine_kernel_lib_names_{};
std::map<std::string, std::vector<OpInfo>> ops_kernel_info_{};
std::map<std::string, std::string> initialize_{};
bool init_flag_;
bool enable_ffts_flag_{false};
};
}
#endif