sync-from-trunk-to-blue-zone-0912-c75b220

pull/64/head
wuweikang 5 years ago
parent b6d2dd731c
commit f85f600c14

@ -62,6 +62,9 @@ class GraphOptimizer {
// optimize streamed Graph
virtual Status OptimizeStreamGraph(ComputeGraph &graph, const RunContext &context) { return SUCCESS; }
// op compile
virtual Status OptimizeFusedGraphAfterGraphSlice(ComputeGraph &graph) { return SUCCESS; }
};
} // namespace ge
/*lint +e148*/

@ -35,5 +35,7 @@ static const std::string ATTR_NAME_L2_FUSION_EXTEND_PTR = "l2_fusion_extend_cont
static const std::string L1_OPTIMIZED = "l1_optimized";
static const std::string L2_OPTIMIZED = "l2_optimized";
static const std::string OP_SLICE_INFO = "_op_slice_info";
} // namespace fe
#endif

@ -34,6 +34,7 @@ class ScopeAllocator {
bool HasScopeAttr(ge::ConstOpDescPtr opdef);
bool GetScopeAttr(ge::ConstOpDescPtr opdef, int64_t& scopeId);
bool SetScopeAttr(ge::OpDescPtr opdef, int64_t scopeId);
bool ResetScopeId(int64_t scopeId);
private:
int64_t scopeId;

@ -40,6 +40,7 @@ const char *const OPTION_EXEC_DEPLOY_MODE = "ge.exec.deployMode";
const char *const OPTION_EXEC_RANK_TABLE_FILE = "ge.exec.rankTableFile";
const char *const GE_AICPU_FLAG = "ge.aicpuFlag";
const char *const OPTION_EXEC_EXTERN_PLUGIN_PATH = "ge.soLoadPath";
// Dump flag and para
const char *const OPTION_EXEC_ENABLE_DUMP = "ge.exec.enableDump";
const char *const OPTION_EXEC_DUMP_PATH = "ge.exec.dumpPath";
const char *const OPTION_EXEC_DUMP_STEP = "ge.exec.dumpStep";
@ -48,7 +49,10 @@ const char *const OPTION_EXEC_ENABLE_DUMP_DEBUG = "ge.exec.enableDumpDebug";
const char *const OPTION_EXEC_DUMP_DEBUG_MODE = "ge.exec.dumpDebugMode";
const char *const OPTION_EXEC_ENABLE_INCRE_BUILD = "ge.exec.enableIncreBuild";
const char *const OPTION_EXEC_INCRE_BUILD_CACHE_PATH = "ge.exec.increBuildCachePath";
const char *const OPTION_EXEC_ENABLE_EXCEPTION_DUMP = "ge.exec.enable_exception_dump";
const char *const OPTION_EXEC_ENABLE_SCOPE_FUSION_PASSES = "ge.exec.enableScopeFusionPasses";
const char *const OPTION_EXEC_PROFILING_FPPONIT_OPTIONS = "ge.exec.profilingFpPointOptions";
const char *const OPTION_EXEC_PROFILING_BPPONIT_OPTIONS = "ge.exec.profilingBpPointOptions";
// profiling flag
const char *const OPTION_EXEC_PROFILING_MODE = "ge.exec.profilingMode";
const char *const OPTION_EXEC_PROFILING_OPTIONS = "ge.exec.profilingOptions";

@ -223,6 +223,7 @@ class OpReg {
\
private: \
void __dy_input_##x() { \
Operator::DynamicInputRegister(#x, 0, true); \
(void)OpReg()
#define DYNAMIC_OUTPUT(x, t) \
@ -242,6 +243,7 @@ class OpReg {
\
private: \
void __dy_output_##x() { \
Operator::DynamicOutputRegister(#x, 0, true); \
(void)OpReg()
#define GRAPH(x) \

@ -55,6 +55,28 @@ class Message;
} // namespace google
namespace domi {
const int64_t kMaxNameLength = 1048576; // 1M
enum DynamicType { kInvalid = 0, kInput = 1, kOutput = 2 };
struct DynamicInputOutputInfo {
DynamicType type; // input/output
const char *port_name;
int64_t port_name_len;
const char *attr_name;
int64_t attr_name_len;
DynamicInputOutputInfo()
: type(kInvalid), port_name(nullptr), port_name_len(0), attr_name(nullptr), attr_name_len(0) {}
DynamicInputOutputInfo(DynamicType type, const char *port_name, int64_t port_name_len, const char *attr_name,
int64_t attr_name_len)
: type(type),
port_name(port_name),
port_name_len(port_name_len),
attr_name(attr_name),
attr_name_len(attr_name_len) {}
};
Status AutoMappingByOpFn(const ge::Operator &op_src, ge::Operator &op);
Status AutoMappingByOpFnDynamic(const ge::Operator &op_src, ge::Operator &op,
const vector<DynamicInputOutputInfo> &dynamic_name_attr_value);
Status AutoMappingFn(const google::protobuf::Message *op_src, ge::Operator &op);
Status AutoMappingFnDynamic(const google::protobuf::Message *op_src, ge::Operator &op,
std::map<std::string, std::pair<std::string, std::string>> dynamic_name_attr_value,
@ -71,6 +93,7 @@ using ParseParamFunc = std::function<domi::Status(const google::protobuf::Messag
using ParseParamByOpFunc = std::function<domi::Status(const ge::Operator &, ge::Operator &)>;
using FusionParseParamFunc =
std::function<domi::Status(const std::vector<const google::protobuf::Message *>, ge::Operator &)>;
using FusionParseParamByOpFunc = std::function<domi::Status(const std::vector<ge::Operator> &, ge::Operator &)>;
using ParseSubgraphFunc = std::function<Status(const std::string &subgraph_name, const ge::Graph &graph)>;
class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData {
@ -91,6 +114,8 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData {
OpRegistrationData &FusionParseParamsFn(const FusionParseParamFunc &fusionParseParamFn);
OpRegistrationData &FusionParseParamsFn(const FusionParseParamByOpFunc &fusion_parse_param_fn);
OpRegistrationData &ParseSubgraphPostFn(const ParseSubgraphFunc &subgraph_post_fn);
OpRegistrationData &ImplyType(const domi::ImplyType &imply_type);
@ -108,6 +133,7 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData {
ParseParamFunc GetParseParamFn() const;
ParseParamByOpFunc GetParseParamByOperatorFn() const;
FusionParseParamFunc GetFusionParseParamFn() const;
FusionParseParamByOpFunc GetFusionParseParamByOpFn() const;
ParseSubgraphFunc GetParseSubgraphPostFn() const;
private:

@ -21,6 +21,7 @@
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include "ge/ge_api_error_codes.h"
#include "register/register_error_codes.h"
#include "register/register_types.h"
@ -52,15 +53,16 @@ class ScopePassManager;
class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY Scope {
public:
explicit Scope(const std::string &name, const std::string &sub_type = "", Scope *father_scope = nullptr);
Scope();
Status Init(const std::string &name, const std::string &sub_type = "", Scope *father_scope = nullptr);
~Scope();
std::string Name() const;
std::string SubType() const;
std::map<std::string, ge::OperatorPtr> AllNodesMap() const;
const std::string &Name() const;
const std::string &SubType() const;
const std::unordered_map<std::string, ge::OperatorPtr> &AllNodesMap() const;
Scope *GetSubScope(const std::string &scope_name) const;
std::string LastName() const;
std::vector<Scope *> GetAllSubScopes() const;
const std::string LastName() const;
const std::vector<Scope *> &GetAllSubScopes() const;
const Scope *GetFatherScope() const;
private:
@ -76,12 +78,13 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY Scope {
class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY FusionScopesResult {
public:
FusionScopesResult();
Status Init();
~FusionScopesResult();
void SetName(const std::string &name);
void SetType(const std::string &type);
void SetDescription(const std::string &description);
std::string Name() const;
std::vector<ge::OperatorPtr> Nodes() const;
const std::string &Name() const;
const std::vector<ge::OperatorPtr> &Nodes() const;
void InsertInputs(const std::string &inner_op_name, const std::vector<int32_t> &index_map);
void InsertOutputs(const std::string &inner_op_name, const std::vector<int32_t> &index_map);
@ -136,7 +139,7 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopeTree {
ScopeTree &operator=(const ScopeTree &scopetree) = delete;
~ScopeTree();
std::vector<Scope *> GetAllScopes() const;
const std::vector<Scope *> &GetAllScopes() const;
private:
class ScopeTreeImpl;
@ -154,7 +157,7 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY ScopeGraph {
~ScopeGraph();
const ScopeTree *GetScopeTree() const;
std::map<std::string, ge::OperatorPtr> GetNodesMap() const;
const std::unordered_map<std::string, ge::OperatorPtr> &GetNodesMap() const;
private:
class ScopeGraphImpl;
@ -203,7 +206,7 @@ class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY NodeOpTypeFeature : ScopeBa
class GE_FUNC_HOST_VISIBILITY GE_FUNC_DEV_VISIBILITY NodeAttrFeature : ScopeBaseFeature {
public:
NodeAttrFeature(std::string nodeType, std::string attr_name, ge::DataType datatype, ScopeAttrValue attr_value);
NodeAttrFeature(std::string nodeType, std::string attr_name, ge::DataType datatype, ScopeAttrValue &attr_value);
NodeAttrFeature(NodeAttrFeature const &feature);
NodeAttrFeature &operator=(NodeAttrFeature const &feature);
~NodeAttrFeature();

@ -258,16 +258,19 @@ struct ComputeGraphDescInfo {
struct OpDescInfo {
std::string op_name;
std::string op_type;
uint32_t task_id;
uint32_t stream_id;
std::vector<Format> input_format;
std::vector<std::vector<int64_t>> input_shape;
std::vector<DataType> input_data_type;
std::vector<void *> input_addrs;
std::vector<int64_t> input_size;
std::vector<Format> output_format;
std::vector<std::vector<int64_t>> output_shape;
std::vector<DataType> output_data_type;
std::vector<void *> output_addrs;
std::vector<int64_t> output_size;
};
struct ModelDumpConfig {
std::string model_name;

@ -64,6 +64,7 @@ class ModelHelper {
Status LoadWeights(OmFileLoadHelper& om_load_helper);
Status LoadTask(OmFileLoadHelper& om_load_helper);
Status LoadTBEKernelStore(OmFileLoadHelper& om_load_helper);
Status LoadCustAICPUKernelStore(OmFileLoadHelper& om_load_helper);
Status ReleaseLocalModelData() noexcept;
Status SaveModelPartition(std::shared_ptr<OmFileSaveHelper>& om_file_save_helper, ModelPartitionType type,
const uint8_t* data, size_t size);

@ -851,9 +851,9 @@ static constexpr int32_t PARTITION_TYPE_WEIGHTS = 1;
static constexpr int32_t PARTITION_TYPE_TASK_INFO = 2;
// number of partitions in the current model
static constexpr uint32_t PARTITION_SIZE = 4;
static constexpr uint32_t PARTITION_SIZE = 5;
enum ModelPartitionType { MODEL_DEF = 0, WEIGHTS_DATA, TASK_INFO, TBE_KERNELS };
enum ModelPartitionType { MODEL_DEF = 0, WEIGHTS_DATA, TASK_INFO, TBE_KERNELS, CUST_AICPU_KERNELS };
struct ModelPartitionMemInfo {
ModelPartitionType type;

@ -108,11 +108,11 @@ class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeExecutor {
/// @ingroup ge
/// @brief Get current dynamic dims info by combined dims
/// @param [in] model_id: model id allocate from manager
/// @param [in] combined_dims: array of combined dimensions
/// @param [in] dynamic_dims: cur gear dynamic dims value
/// @param [out] cur_dynamic_dims: current dynamic dims
/// @return execute result
///
ge::Status GetCurDynamicDims(uint32_t model_id, const std::vector<uint64_t> &combined_dims,
ge::Status GetCurDynamicDims(uint32_t model_id, const std::vector<uint64_t> &dynamic_dims,
std::vector<uint64_t> &cur_dynamic_dims);
///

@ -28,6 +28,7 @@
#include "graph/graph.h"
#include "graph/op_desc.h"
#include "graph/detail/attributes_holder.h"
#include "omg/omg_inner_types.h"
namespace ge {
class GeGenerator {
@ -45,6 +46,7 @@ class GeGenerator {
GeGenerator &operator=(const GeGenerator &) = delete;
Status Initialize(const std::map<std::string, std::string> &options);
Status Initialize(const std::map<std::string, std::string> &options, OmgContext &context);
Status Finalize();

@ -98,24 +98,14 @@ struct OmgContext {
std::vector<std::string> out_top_names;
// path for the aicpu custom operator so_file
std::vector<std::string> aicpu_op_run_paths;
// ddk version
std::string ddk_version;
// preferential format used by the entire network
domiTensorFormat_t net_format = DOMI_TENSOR_RESERVED;
domi::FrameworkType type = domi::FRAMEWORK_RESERVED;
RunMode run_mode = ONLY_PRE_CHECK;
bool train_flag = false;
// whether to use FP16 high precision
int32_t fp16_high_precision = HIGH_PRECISION_DEFAULT;
std::string output_type;
// Save the name of the entire network: Some special operators are used to determine a network. Some operators in the
// network require special processing based on the specific network. e.gfaster-rcnn, the FirstStageProcessor module
// is determined as the Faster-R-CNN network based on the scope fusion. Then, the conv+reshape operators in the
// FirstStageBoxPredictor/BoxEncodingPredictor scope are combined. The convolution kernel rearrangement reshape
// operator needs to be deleted for the convolution kernel.
std::string net_name;
// Whether to use dynamic batch size or dynamic image size
bool is_dynamic_input = false;
std::string dynamic_batch_size;

@ -93,6 +93,7 @@ class ComputeGraph : public std::enable_shared_from_this<ComputeGraph>, public A
NodePtr AddNodeFront(const OpDescPtr &op);
NodePtr AddInputNode(NodePtr node);
NodePtr AddOutputNode(NodePtr node);
NodePtr AddOutputNodeByIndex(NodePtr node, int32_t index);
// insert node with specific pre_node
NodePtr AddNodeAfter(OpDescPtr &op, const NodePtr &pre_node);
NodePtr AddNodeAfter(NodePtr node, const NodePtr &pre_node);
@ -138,6 +139,7 @@ class ComputeGraph : public std::enable_shared_from_this<ComputeGraph>, public A
graphStatus TopologicalSorting();
bool IsValid() const;
void InValid() { is_valid_flag_ = false; }
void Dump() const;
void Swap(ComputeGraph &graph);
@ -268,6 +270,7 @@ class ComputeGraph : public std::enable_shared_from_this<ComputeGraph>, public A
friend class ModelSerializeImp;
friend class GraphDebugImp;
friend class OnnxUtils;
friend class TuningUtils;
std::string name_;
uint32_t graph_id_ = 0;

@ -1031,6 +1031,13 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAM
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OP_INPUT_L1_FLAG;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OP_INPUT_L1_ADDR;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OP_INPUT_L1_VALID_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_ENGINE_NAME_FOR_LX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_KKERNEL_LIB_NAME_FOR_LX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_NEED_LX_FUSION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OPTIMIZE_GROUP;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OP_COMPILE_STRATEGY;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_TBE_KERNEL_NAME;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_TBE_KERNEL_BUFFER;
// for unregistered op
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_UNREGST_OPPATH;

@ -174,6 +174,9 @@ class Node : public std::enable_shared_from_this<Node> {
fusion_output_dataflow_list_ = fusion_output_list;
}
bool GetHostNode() const { return host_node_; }
void SetHostNode(bool is_host) { host_node_ = is_host; }
void SetOrigNode(const NodePtr &orignode) { orig_node_ = orignode; }
NodePtr GetOrigNode() { return orig_node_; }
@ -192,6 +195,7 @@ class Node : public std::enable_shared_from_this<Node> {
OutControlAnchorPtr out_control_anchor_;
map<string, GeAttrValue> attrs_; // lint !e1073
bool has_init_{false};
bool host_node_{false};
bool anchor_status_updated_{false};
std::vector<uint32_t> send_event_id_list_;
std::vector<uint32_t> recv_event_id_list_;
@ -202,6 +206,7 @@ class Node : public std::enable_shared_from_this<Node> {
NodePtr orig_node_;
friend class NodeUtils;
friend class OnnxUtils;
friend class TuningUtils;
};
} // namespace ge

@ -18,6 +18,7 @@
#define INC_GRAPH_OP_DESC_H_
#include <functional>
#include <algorithm>
#include <map>
#include <memory>
#include <string>
@ -87,6 +88,8 @@ class OpDesc : public std::enable_shared_from_this<OpDesc>, public AttrHolder {
graphStatus AddInputDescMiddle(const string &name, const unsigned int num, size_t index);
graphStatus AddOutputDescMiddle(const string &name, const unsigned int num, size_t index);
graphStatus AddOutputDescForward(const string &name, const unsigned int num);
graphStatus AddOptionalInputDesc(const string &name, const GeTensorDesc &input_desc);
@ -187,6 +190,14 @@ class OpDesc : public std::enable_shared_from_this<OpDesc>, public AttrHolder {
graphStatus CommonVerify() const;
graphStatus AddRegisterInputName(const string &name);
graphStatus AddRegisterOutputName(const string &name);
vector<string> GetRegisterInputName() const;
vector<string> GetRegisterOutputName() const;
using AttrHolder::AddRequiredAttr;
using AttrHolder::DelAttr;
using AttrHolder::GetAllAttrNames;
@ -297,9 +308,11 @@ class OpDesc : public std::enable_shared_from_this<OpDesc>, public AttrHolder {
vector<GeTensorDescPtr> inputs_desc_{};
map<string, uint32_t> input_name_idx_{};
vector<string> register_input_name_{};
std::unordered_set<string> optional_input_names_{};
vector<GeTensorDescPtr> outputs_desc_{};
map<string, uint32_t> output_name_idx_{};
vector<string> register_output_name_{};
std::function<graphStatus(Operator &)> infer_func_ = nullptr;
std::function<graphStatus(Operator &)> infer_format_func_ = nullptr;
std::function<graphStatus(Operator &)> verifier_func_ = nullptr;

@ -42,6 +42,7 @@ class OpKernelBin {
using OpKernelBinPtr = std::shared_ptr<OpKernelBin>;
const char *const OP_EXTATTR_NAME_TBE_KERNEL = "tbeKernel";
const char *const OP_EXTATTR_CUSTAICPU_KERNEL = "cust_aicpu_kernel";
} // namespace ge
#endif // INC_GRAPH_OP_KERNEL_BIN_H_

@ -23,6 +23,7 @@
#include <map>
#include <string>
#include <vector>
#include <mutex>
namespace ge {
class OpsProtoManager {
@ -30,14 +31,15 @@ class OpsProtoManager {
static OpsProtoManager *Instance();
bool Initialize(const std::map<std::string, std::string> &options);
void Finalize();
private:
void LoadOpsProtoPluginSo(std::string &path);
private:
std::string pluginPath_;
std::vector<void *> handles_;
bool is_init_ = false;
std::mutex mutex_;
};
} // namespace ge

@ -0,0 +1,130 @@
/**
* 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 MAIN_TUNING_UTILS_H
#define MAIN_TUNING_UTILS_H
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <algorithm>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <queue>
#include <mutex>
#include <graph/anchor.h>
#include <graph/detail/attributes_holder.h>
#include <graph/ge_tensor.h>
#include <graph/graph.h>
#include <graph/model.h>
#include <graph/node.h>
#include <graph/utils/graph_utils.h>
#include <graph/utils/type_utils.h>
#include "framework/common/debug/ge_log.h"
#include "utils/attr_utils.h"
#include "utils/node_utils.h"
#include "external/ge/ge_api_types.h"
#include "graph/debug/ge_attr_define.h"
#include "graph/utils/op_desc_utils.h"
#include "graph/utils/tensor_utils.h"
namespace ge {
// Configure build mode, default value is "normal"
const char *const BUILD_MODE = "ge.buildMode";
const char *const BUILD_STEP = "ge.buildStep";
// Configure tuning path
const char *const TUNING_PATH = "ge.tuningPath";
// for interface: aclgrphBuildModel
const std::set<std::string> ir_builder_supported_options_for_lx_fusion = {BUILD_MODE, BUILD_STEP, TUNING_PATH};
// Build model
const char *const BUILD_MODE_NORMAL = "normal";
const char *const BUILD_MODE_TUNING = "tuning";
const char *const BUILD_MODE_BASELINE = "baseline";
const std::set<std::string> build_mode_options = {BUILD_MODE_NORMAL, BUILD_MODE_TUNING, BUILD_MODE_BASELINE};
// Build step
const char *const BUILD_STEP_BEFORE_UB_MATCH = "before_ub_match";
const char *const BUILD_STEP_AFTER_UB_MATCH = "after_ub_match";
const char *const BUILD_STEP_AFTER_BUILDER = "after_builder";
const char *const BUILD_STEP_AFTER_BUILDER_SUB = "after_builder_sub";
const char *const BUILD_STEP_AFTER_MERGE = "after_merge";
const std::set<std::string> build_step_options = {BUILD_STEP_BEFORE_UB_MATCH, BUILD_STEP_AFTER_UB_MATCH,
BUILD_STEP_AFTER_BUILDER, BUILD_STEP_AFTER_BUILDER_SUB,
BUILD_STEP_AFTER_MERGE};
using SubgraphCreateOutNode = std::unordered_map<ComputeGraphPtr, NodePtr>;
using NodetoNodeMap = std::unordered_map<NodePtr, NodePtr>;
using NodeSet = std::set<NodePtr>;
using NodeNametoNodeNameMap = std::unordered_map<std::string, std::string>;
using NodetoNodeNameMap = std::unordered_map<NodePtr, std::string>;
class TuningUtils {
public:
TuningUtils() = default;
~TuningUtils() = default;
// Dump all the subgraphs and modify
// the subgraphs in them to be executable subgraphs if exe_flag is true
// `tuning_path` means path to save the graphs
static graphStatus ConvertGraphToFile(std::vector<ComputeGraphPtr> tuning_subgraphs,
std::vector<ComputeGraphPtr> non_tuning_subgraphs = {}, bool exe_flag = false,
const std::string &path = "", const std::string &user_path = "");
// Recovery `graph` from graph dump files configured in options
static graphStatus ConvertFileToGraph(const map<int64_t, string> &options, ge::Graph &graph);
private:
// part 1
struct HelpInfo {
int64_t index;
bool exe_flag;
bool is_tuning_graph;
const std::string &path;
const std::string &user_path;
};
static graphStatus MakeExeGraph(ComputeGraphPtr &exe_graph, const HelpInfo &help_info);
static graphStatus HandlePld(NodePtr &node);
static graphStatus HandleEnd(NodePtr &node);
static graphStatus ChangePld2Data(NodePtr &node, NodePtr &data_node);
static graphStatus ChangeEnd2NetOutput(NodePtr &node, NodePtr &out_node);
static graphStatus LinkEnd2NetOutput(NodePtr &node, NodePtr &out_node);
static graphStatus CreateDataNode(NodePtr &node, NodePtr &data_node);
static graphStatus CreateNetOutput(NodePtr &node, NodePtr &out_node);
static graphStatus AddAttrToDataNodeForMergeGraph(const NodePtr &pld, NodePtr &data_node);
static graphStatus AddAttrToNetOutputForMergeGraph(const NodePtr &end, NodePtr &out_node);
static void DumpGraphToPath(ComputeGraphPtr &exe_graph, int64_t index, bool is_tuning_graph, std::string path);
static SubgraphCreateOutNode create_output_;
// part 2
static graphStatus MergeAllSubGraph(std::vector<ComputeGraphPtr> &graphs, ComputeGraphPtr &graph);
static graphStatus MergeSubGraph(ComputeGraphPtr &graph);
// Deletes new data and output nodes added by call `MakeExeGraph()` func in part 1
static graphStatus RemoveDataNetoutputEdge(ComputeGraphPtr &graph);
static graphStatus GetInAndOutAnchorPair(NodePtr &data_node, NodePtr &out_node, AnchorPtr &dest_in_anchor,
AnchorPtr &src_out_anchor);
static NodeNametoNodeNameMap data_2_netoutput_;
static NodetoNodeNameMap data_node_2_netoutput_;
static NodetoNodeMap data_node_2_netoutput_node_;
static NodeSet netoutput_nodes_;
static NodeSet merged_graph_nodes_;
static std::mutex mutex_;
// for debug
static std::string PrintCheckLog();
static std::string GetNodeNameByAnchor(const Anchor *anchor);
};
} // namespace ge
#endif // MAIN_TUNING_UTILS_H

@ -36,8 +36,8 @@
do { \
GraphUtils::DumpGEGraph(compute_graph, name); \
GraphUtils::DumpGEGraphToOnnx(*compute_graph, name); \
uint64_t i = 0; \
for (const auto &sub_graph_func : compute_graph->GetAllSubgraphs()) { \
static int8_t i = 0; \
auto sub_graph_func_name = std::string(name) + std::string("_sub_graph_") + std::to_string(i++); \
GraphUtils::DumpGEGraph(sub_graph_func, sub_graph_func_name); \
GraphUtils::DumpGEGraphToOnnx(*sub_graph_func, sub_graph_func_name); \
@ -203,10 +203,13 @@ class GraphUtils {
static bool MatchDumpStr(const std::string &suffix);
static void DumpGEGraph(const ge::ComputeGraphPtr &graph, const std::string &suffix, bool is_always_dump = false);
static void DumpGEGraph(const ge::ComputeGraphPtr &graph, const std::string &suffix, bool is_always_dump = false,
const std::string &user_graph_name = "");
static bool LoadGEGraph(const char *file, ge::ComputeGraph &compute_graph);
static bool LoadGEGraph(const char *file, ge::ComputeGraphPtr &compute_graph);
static void BreakConnect(const std::map<OperatorImplPtr, NodePtr> &all_nodes_infos);
static void DumpGEGraphToOnnx(const ge::ComputeGraph &compute_graph, const std::string &suffix);

@ -24,6 +24,7 @@ file(GLOB_RECURSE PROTO_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
"../../proto/task.proto"
"../../proto/fwk_adaper.proto"
"../../proto/op_mapping_info.proto"
"../proto/dump_task.proto"
)
file(GLOB_RECURSE ONNX_PROTO_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}

@ -36,6 +36,7 @@
namespace ge {
namespace {
const size_t OUTPUT_PARAM_SIZE = 2;
const std::string alias_name_attr = "_aliasName";
bool IsUseBFS() {
string run_mode;
const int base = 10;
@ -133,6 +134,14 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY NodePtr ComputeGraph::FindNode(co
if (node->GetName() == name) {
return node;
}
std::vector<string> out_alias_name;
if (AttrUtils::GetListStr(node->GetOpDesc(), alias_name_attr, out_alias_name)) {
for (const auto &alias_name : out_alias_name) {
if (alias_name == name) {
return node;
}
}
}
}
return nullptr;
}
@ -258,6 +267,7 @@ NodePtr ComputeGraph::AddNodeFront(NodePtr node) {
GELOGE(GRAPH_FAILED, "The node ptr or op desc should not be null.");
return nullptr;
}
node->SetHostNode(is_valid_flag_);
node->GetOpDesc()->SetId(nodes_.size());
if (nodes_.size() > 0 && nodes_[0]->GetType() == DATA) {
(void)nodes_.insert(nodes_.begin() + 1, node);
@ -284,6 +294,7 @@ NodePtr ComputeGraph::AddNodeAfter(NodePtr node, const NodePtr &pre_node) {
GELOGE(GRAPH_FAILED, "The node ptr or op desc should not be null.");
return nullptr;
}
node->SetHostNode(is_valid_flag_);
node->GetOpDesc()->SetId(nodes_.size());
auto node_iter = std::find(nodes_.begin(), nodes_.end(), pre_node);
if (node_iter != nodes_.end()) {
@ -313,6 +324,7 @@ GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY NodePtr ComputeGraph::AddNode(Nod
GELOGE(GRAPH_FAILED, "The node ptr should not be null.");
return nullptr;
}
node->SetHostNode(is_valid_flag_);
node->GetOpDesc()->SetId((int64_t)GetDirectNodesSize());
nodes_.push_back(node);
return node;
@ -339,6 +351,7 @@ NodePtr ComputeGraph::AddNode(OpDescPtr op, int64_t id) { // for unserialize.
NodePtr node = shared_ptr<Node>(new (std::nothrow) Node(op, shared_from_this()));
GE_IF_BOOL_EXEC(node == nullptr, GELOGE(GRAPH_FAILED, "node_ptr is NULL!!!"); return nullptr);
GE_IF_BOOL_EXEC(node->Init() != GRAPH_SUCCESS, GELOGE(GRAPH_FAILED, "node init fail."); return nullptr);
node->SetHostNode(is_valid_flag_);
nodes_.push_back(node);
return node;
}
@ -355,7 +368,9 @@ NodePtr ComputeGraph::AddInputNode(NodePtr node) {
return node;
}
NodePtr ComputeGraph::AddOutputNode(NodePtr node) {
NodePtr ComputeGraph::AddOutputNode(NodePtr node) { return AddOutputNodeByIndex(node, 0); }
NodePtr ComputeGraph::AddOutputNodeByIndex(NodePtr node, int32_t index) {
if (node == nullptr || node->GetOpDesc() == nullptr) {
GELOGE(GRAPH_FAILED, "The node ptr or opdesc should not be null.");
return nullptr;
@ -365,7 +380,7 @@ NodePtr ComputeGraph::AddOutputNode(NodePtr node) {
NodePtr result = node;
// [output_nodes_info_ : should not be null]
for (const auto &item : output_nodes_info_) {
if (item.first->GetName() == node->GetName()) {
if (item.first->GetName() == node->GetName() && item.second == index) {
already_have = true;
result = item.first;
break;
@ -373,7 +388,8 @@ NodePtr ComputeGraph::AddOutputNode(NodePtr node) {
}
if (!already_have) {
output_nodes_info_.emplace_back(std::make_pair(node, 0));
output_nodes_info_.emplace_back(std::make_pair(node, index));
GELOGI("Push back node name:%s, index:%ld, into output_nodes_info_.", node->GetName().c_str(), index);
}
if (std::find(nodes_.begin(), nodes_.end(), node) == nodes_.end()) {

@ -32,6 +32,8 @@ GE_REGISTER_OPTYPE(STATELESSWHILE, "StatelessWhile");
GE_REGISTER_OPTYPE(SQUEEZE, "Squeeze");
GE_REGISTER_OPTYPE(EXPANDDIMS, "ExpandDims");
GE_REGISTER_OPTYPE(SWITCH, "Switch");
GE_REGISTER_OPTYPE(REFSWITCH, "RefSwitch");
GE_REGISTER_OPTYPE(SWITCHN, "SwitchN");
GE_REGISTER_OPTYPE(MERGE, "Merge");
GE_REGISTER_OPTYPE(STREAMMERGE, "StreamMerge");
GE_REGISTER_OPTYPE(ENTER, "Enter");
@ -40,6 +42,7 @@ GE_REGISTER_OPTYPE(NEXTITERATION, "NextIteration");
GE_REGISTER_OPTYPE(REFNEXTITERATION, "RefNextIteration");
GE_REGISTER_OPTYPE(CONSTANT, "Const");
GE_REGISTER_OPTYPE(PLACEHOLDER, "PlaceHolder");
GE_REGISTER_OPTYPE(END, "End");
GE_REGISTER_OPTYPE(FRAMEWORKOP, "FrameworkOp");
GE_REGISTER_OPTYPE(GETNEXT, "GetNext");
GE_REGISTER_OPTYPE(INITDATA, "InitData");

@ -43,7 +43,7 @@ namespace ge {
namespace {
const std::unordered_set<string> kChangeDimNodes = {PERMUTE, EXPANDDIMS, SQUEEZE};
const string kIsGraphInferred = "_is_graph_inferred";
RefRelations reflection_builder;
thread_local RefRelations reflection_builder;
} // namespace
graphStatus ReflectionProcess(const std::unordered_set<RefCell, RefCellHash> &reflection,

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save