* 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 DFLOW_COMPILER_MODEL_DFLOW_GRAPH_MANAGER_H_
#define DFLOW_COMPILER_MODEL_DFLOW_GRAPH_MANAGER_H_
#include <map>
#include <string>
#include <vector>
#include <mutex>
#include "dflow/inc/data_flow/model/flow_model.h"
#include "dflow/compiler/model/flow_model_builder.h"
#include "flow_graph/data_flow.h"
#include "framework/common/ge_types.h"
#include "graph/preprocess/graph_prepare.h"
namespace ge {
using ge::dflow::FlowGraph;
@brief DflowGraphManager - Dflow-specific graph manager
Acts as the interface layer between dflow_session_impl and the underlying graph_manager
Takes over the management of graphs, while the actual compilation work is handled by graph_manager
*/
class DflowGraphManager {
public:
DflowGraphManager() = default;
~DflowGraphManager();
Status Initialize(const std::map<std::string, std::string> &options,
const std::shared_ptr<ProcessNodeEngineImpl> &pneImpl = nullptr);
void Finalize();
Status AddGraph(uint32_t graph_id, const Graph &graph,
const std::map<std::string, std::string> &options);
Status RemoveGraph(uint32_t graph_id);
Status CompileGraph(uint32_t graph_id, const std::vector<GeTensor> &inputs);
const std::map<std::string, std::string> *GetGraphOptions(uint32_t graph_id);
Status GetGraphModelId(uint32_t graph_id, uint32_t &model_id);
FlowModelPtr GetFlowModel(uint32_t graph_id) const;
bool GetOptionsRunGraphFlag();
private:
bool is_initialized_{false};
std::map<std::string, std::string> options_;
mutable std::mutex mutex_;
mutable std::mutex graph_mutex_;
mutable std::mutex model_mutex_;
std::map<uint32_t, std::map<std::string, std::string>> graph_options_map_;
std::map<uint32_t, FlowModelPtr> flow_model_map_;
std::map<uint32_t, Graph> flow_graph_map_;
std::map<uint32_t, OmgContext> omg_contexts_;
FlowModelBuilder flow_model_builder_;
};
}
#endif