Browse Source

Pre Merge pull request !699 from xuyf/ge_dev

pull/699/MERGE
xuyf Gitee 3 years ago
parent
commit
155992fa70
No known key found for this signature in database GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 26 additions and 31 deletions
  1. +10
    -8
      parser/tensorflow/graph_to_function_def.cc
  2. +9
    -19
      parser/tensorflow/graph_to_function_def.h
  3. +7
    -4
      parser/tensorflow/parser_graph_optimizer.cc

+ 10
- 8
parser/tensorflow/graph_to_function_def.cc View File

@@ -105,7 +105,7 @@ domi::Status ComputeArgRange(const domi::tensorflow::NodeDef &node_def, const do
REPORT_INNER_ERROR("E19999", "Attr:type_list_attr not exist in node:%s, check invalid", node_def.name().c_str());
return domi::INTERNAL_ERROR);
*num = attr_value.list().type_size();
} else if ((!arg_def.type_attr().empty()) || (arg_def.type() != DT_INVALID)) {
} else if ((!arg_def.type_attr().empty()) || (arg_def.type() != domi::tensorflow::DT_INVALID)) {
*num = 1;
} else {
GELOGE(domi::INTERNAL_ERROR, "In NodeDef %s Attr type_list_attr is not exist.", node_def.name().c_str());
@@ -139,7 +139,8 @@ domi::Status NameRangesForNode(const domi::tensorflow::NodeDef &node_def, const
return NameRangesHelper(node_def, op_def.output_arg(), outputs);
}

domi::Status RemapFunctionDef(FunctionDef *fdef, const string &name, NameMapHelper &node_names,
domi::Status RemapFunctionDef(domi::tensorflow::FunctionDef *fdef, const string &name,
NameMapHelper &node_names,
std::map<string, string> &tensor_renaming,
std::map<string, string> &return_values) {
GE_CHECK_NOTNULL(fdef);
@@ -156,7 +157,7 @@ domi::Status RemapFunctionDef(FunctionDef *fdef, const string &name, NameMapHelp
/// Remap input names. We do this as a second pass to allow the nodes to be in
/// any order.
for (int n_index = 0; n_index < fdef->node_def_size(); ++n_index) {
NodeDef *node_def = fdef->mutable_node_def(n_index);
domi::tensorflow::NodeDef *node_def = fdef->mutable_node_def(n_index);
for (int i = 0; i < node_def->input_size(); ++i) {
if (node_def->input(i).find("^") != string::npos) {
// Control input
@@ -360,7 +361,7 @@ domi::Status GraphToFunctionDef::RecordArg(ge::ComputeGraphPtr graph, const vect

// Convert Davinci's graph to tensorflow's functiondef
domi::Status GraphToFunctionDef::DavGraphToFunctionDef(ge::ComputeGraphPtr graph, const string &name,
FunctionDef *fdef) {
domi::tensorflow::FunctionDef *fdef) {
GE_CHECK_NOTNULL(graph);
GE_CHECK_NOTNULL(fdef);
fdef->mutable_signature()->set_name(name);
@@ -433,7 +434,7 @@ domi::Status GraphToFunctionDef::DavGraphToFunctionDef(ge::ComputeGraphPtr graph
GE_CHK_BOOL_RET_STATUS(op_def.ParseFromString(opdef_string), PARAM_INVALID, "parse op_def failed.");

// add nodedef
NodeDef *node_def = fdef->add_node_def();
domi::tensorflow::NodeDef *node_def = fdef->add_node_def();
*node_def = node_def_;

node_def->mutable_attr()->erase(ge::ATTR_NAME_FRAMEWORK_OP_DEF);
@@ -498,7 +499,7 @@ domi::Status GraphToFunctionDef::DavGraphToFunctionDef(ge::ComputeGraphPtr graph
return SUCCESS;
}

void SetInputOut(NodeDef *call_node_def, vector<ge::InDataAnchorPtr> &in_anchor) {
void SetInputOut(domi::tensorflow::NodeDef *call_node_def, vector<ge::InDataAnchorPtr> &in_anchor) {
GE_CHK_BOOL_EXEC(call_node_def != nullptr, return, "call_node_def is null.");
for (const auto &anchor : in_anchor) {
if ((anchor != nullptr) && (anchor->GetPeerOutAnchor() != nullptr)) {
@@ -509,7 +510,8 @@ void SetInputOut(NodeDef *call_node_def, vector<ge::InDataAnchorPtr> &in_anchor)
}

domi::Status GraphToFunctionDef::BuildFunctionDef(ge::ComputeGraphPtr &graph, const string &name_in,
FunctionDefLibrary *library, NodeDef *call_node_def,
domi::tensorflow::FunctionDefLibrary *library,
domi::tensorflow::NodeDef *call_node_def,
vector<ge::InDataAnchorPtr> &in_anchor,
vector<ge::OutDataAnchorPtr> &out_anchor) {
GE_CHECK_NOTNULL(graph);
@@ -557,7 +559,7 @@ domi::Status GraphToFunctionDef::BuildFunctionDef(ge::ComputeGraphPtr &graph, co
GraphToFunctionDef::AddNodeAttr("Tout", tout_value, call_node_def);
}
// Convert DaVinci graph to functiondef
FunctionDef *fdef = library->add_function();
domi::tensorflow::FunctionDef *fdef = library->add_function();
GE_RETURN_IF_ERROR(GraphToFunctionDef::DavGraphToFunctionDef(graph, name, fdef));

return SUCCESS;


+ 9
- 19
parser/tensorflow/graph_to_function_def.h View File

@@ -28,35 +28,25 @@
#include "proto/tensorflow/graph.pb.h"
#include "register/register_error_codes.h"

using domi::tensorflow::AttrValue;
using domi::tensorflow::AttrValue_ListValue;
using domi::tensorflow::DataType;
using domi::tensorflow::DT_INVALID;
using domi::tensorflow::FunctionDef;
using domi::tensorflow::FunctionDefLibrary;
using domi::tensorflow::NodeDef;
using std::string;
using std::to_string;
using std::vector;

namespace ge {
class GraphToFunctionDef {
public:
static domi::Status RecordArg(ge::ComputeGraphPtr graph,
const vector<ge::InDataAnchorPtr> &in_anchor);
const vector<ge::InDataAnchorPtr> &in_anchor);

static domi::Status RecordResult(ge::ComputeGraphPtr graph,
const vector<ge::OutDataAnchorPtr> &out_anchor);
const vector<ge::OutDataAnchorPtr> &out_anchor);

static domi::Status DavGraphToFunctionDef(ge::ComputeGraphPtr graph,
const string &name, FunctionDef *fdef);
const string &name,
domi::tensorflow::FunctionDef *fdef);

static domi::Status BuildFunctionDef(ge::ComputeGraphPtr &graph,
const string &name_in,
FunctionDefLibrary *library,
NodeDef *call_node_def,
vector<ge::InDataAnchorPtr> &in_anchor,
vector<ge::OutDataAnchorPtr> &out_anchor);
const string &name_in,
domi::tensorflow::FunctionDefLibrary *library,
domi::tensorflow::NodeDef *call_node_def,
vector<ge::InDataAnchorPtr> &in_anchor,
vector<ge::OutDataAnchorPtr> &out_anchor);

static bool FindAttrValue(const domi::tensorflow::NodeDef *node_def,
const string attr_name,


+ 7
- 4
parser/tensorflow/parser_graph_optimizer.cc View File

@@ -169,7 +169,7 @@ Status ParserGraphOptimizer::FindFmkNodeCluser(unordered_map<string, vector<Node
return SUCCESS;
}

Status CollectNodeFuncs(vector<ge::NodePtr> &nodes, FunctionDefLibrary *library) {
Status CollectNodeFuncs(vector<ge::NodePtr> &nodes, domi::tensorflow::FunctionDefLibrary *library) {
for (auto node : nodes) {
GE_CHECK_NOTNULL(node);
OpDescPtr opDef = node->GetOpDesc();
@@ -177,7 +177,8 @@ Status CollectNodeFuncs(vector<ge::NodePtr> &nodes, FunctionDefLibrary *library)
ge::Buffer funcDefBytes;

GE_IF_BOOL_EXEC(
AttrUtils::GetBytes(opDef, ge::ATTR_NAME_FRAMEWORK_FUNC_DEF, funcDefBytes), FunctionDefLibrary funcLib;
AttrUtils::GetBytes(opDef, ge::ATTR_NAME_FRAMEWORK_FUNC_DEF, funcDefBytes),
domi::tensorflow::FunctionDefLibrary funcLib;
GE_CHECK_NOTNULL(funcDefBytes.GetData());
string str(PtrToPtr<uint8_t, char_t>(funcDefBytes.GetData()), funcDefBytes.GetSize());
GELOGI("FUNCDEF: Get function -> %s.", str.c_str()); GE_IF_BOOL_EXEC(
@@ -205,9 +206,11 @@ Status ParserGraphOptimizer::UpdateGraph(vector<NodePtr> &nodes) {
"insert node to sub_graph failed.");
GE_CHK_STATUS_RET(LinkInnerAnchor(node_map), "Link inner anchor failed.");

std::unique_ptr<NodeDef> node_def(new (std::nothrow) NodeDef()); // tensorflow NodeDef
std::unique_ptr<domi::tensorflow::NodeDef> node_def(
new (std::nothrow) domi::tensorflow::NodeDef()); // tensorflow NodeDef
GE_CHECK_NOTNULL(node_def);
std::unique_ptr<FunctionDefLibrary> func_def_lib(new (std::nothrow) FunctionDefLibrary());
std::unique_ptr<domi::tensorflow::FunctionDefLibrary> func_def_lib(
new (std::nothrow) domi::tensorflow::FunctionDefLibrary());
GE_CHECK_NOTNULL(func_def_lib);
// convert graph to FunctionDef
if (nodes.size() == 0) {


Loading…
Cancel
Save