Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Raymond Yang committed Feb 26, 2019
1 parent 18241bc commit b3bb0a5
Showing 1 changed file with 75 additions and 76 deletions.
151 changes: 75 additions & 76 deletions onnx/checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,82 +356,6 @@ void check_node(
}
}


void check_function(
const FunctionProto& function,
const CheckerContext& ctx,
const LexicalScopeContext& /*parent_lex*/) {
enforce_non_empty_field(function, name);
enforce_has_field(function, since_version);

std::unordered_set<std::string> output_names;
for (const auto& input : function.input()) {
auto result = output_names.insert(input);
if (!result.second) {
fail_check(
"function (",
function.name(),
") should not have duplicate inputs specified.");
}
}
std::unordered_set<std::string> outputs;
for (const auto& output : function.output()) {
auto result = outputs.insert(output);
if (!result.second) {
fail_check(
"function (",
function.name(),
") should not have duplicate outputs specified.");
}
}
std::unordered_set<std::string> attrs;
for (const auto& attr : function.attribute()) {
auto result = attrs.insert(attr);
if (!result.second) {
fail_check(
"function (",
function.name(),
") should not have duplicate attributes specified.");
}
}

for (const auto& node : function.node()) {
// nodes must be in topologically sorted order
for (const auto& input : node.input()) {
// explicit optional input
if (input.empty()) {
continue;
}
if (!output_names.count(input)) {
fail_check(
"Nodes in a function must be topologically sorted, however input '",
input,
"' of node: \n",
ProtoDebugString(node),
"\n is neither output of any previous nodes nor input of the function.");
}
}

LexicalScopeContext lex_ctx;
lex_ctx.output_names = output_names;
check_node(node, ctx, lex_ctx);
// check for SSA form
for (const auto& output : node.output()) {
// optional output
if (output.empty()) {
continue;
}
if (output_names.count(output)) {
fail_check(
"Function must be in single static assignment (SSA) form, however '",
output,
"' has been used as output names multiple times.");
}
output_names.insert(output);
}
}
}

void check_graph(
const GraphProto& graph,
const CheckerContext& ctx,
Expand Down Expand Up @@ -518,6 +442,81 @@ void check_graph(
}
}

void check_function(
const FunctionProto& function,
const CheckerContext& ctx,
const LexicalScopeContext& /*parent_lex*/) {
enforce_non_empty_field(function, name);
enforce_has_field(function, since_version);

std::unordered_set<std::string> output_names;
for (const auto& input : function.input()) {
auto result = output_names.insert(input);
if (!result.second) {
fail_check(
"function (",
function.name(),
") should not have duplicate inputs specified.");
}
}
std::unordered_set<std::string> outputs;
for (const auto& output : function.output()) {
auto result = outputs.insert(output);
if (!result.second) {
fail_check(
"function (",
function.name(),
") should not have duplicate outputs specified.");
}
}
std::unordered_set<std::string> attrs;
for (const auto& attr : function.attribute()) {
auto result = attrs.insert(attr);
if (!result.second) {
fail_check(
"function (",
function.name(),
") should not have duplicate attributes specified.");
}
}

for (const auto& node : function.node()) {
// nodes must be in topologically sorted order
for (const auto& input : node.input()) {
// explicit optional input
if (input.empty()) {
continue;
}
if (!output_names.count(input)) {
fail_check(
"Nodes in a function must be topologically sorted, however input '",
input,
"' of node: \n",
ProtoDebugString(node),
"\n is neither output of any previous nodes nor input of the function.");
}
}

LexicalScopeContext lex_ctx;
lex_ctx.output_names = output_names;
check_node(node, ctx, lex_ctx);
// check for SSA form
for (const auto& output : node.output()) {
// optional output
if (output.empty()) {
continue;
}
if (output_names.count(output)) {
fail_check(
"Function must be in single static assignment (SSA) form, however '",
output,
"' has been used as output names multiple times.");
}
output_names.insert(output);
}
}
}

void check_model(const ModelProto& model, CheckerContext& ctx) {
if (!model.ir_version()) {
fail_check("The model does not have an ir_version set properly.");
Expand Down

0 comments on commit b3bb0a5

Please sign in to comment.