Browse Source

single op parser add check for json input

pull/580/head
wxl 5 years ago
parent
commit
2d4bc965fb
1 changed files with 21 additions and 0 deletions
  1. +21
    -0
      ge/offline/single_op_parser.cc

+ 21
- 0
ge/offline/single_op_parser.cc View File

@@ -26,6 +26,7 @@
#include "common/util/error_manager/error_manager.h"
#include "common/ge_inner_error_codes.h"
#include "framework/common/util.h"
#include "graph/utils/attr_utils.h"
#include "graph/utils/tensor_utils.h"
#include "graph/utils/op_desc_utils.h"
#include "graph/operator_factory_impl.h"
@@ -52,6 +53,7 @@ constexpr char const *kKeyOriginFormat = "origin_format";
constexpr char const *kFileSuffix = ".om";
constexpr char const *kKeyDynamicInput = "dynamic_input";
constexpr char const *kKeyDynamicOutput = "dynamic_output";
constexpr char const *kSingleOpTensorDescValid = "_ge_single_op_tensor_desc_valid";
constexpr int kDumpJsonIndent = 2;
constexpr int kShapeRangePairSize = 2;
constexpr int kShapeRangeLow = 0;
@@ -176,6 +178,7 @@ T GetValue(const map<string, T> &dict, string &key, T default_val) {
}

void from_json(const Json &j, SingleOpTensorDesc &desc) {
bool is_tensor_valid = true;
desc.dims = j.at(kKeyShape).get<vector<int64_t>>();
auto it = j.find(kKeyShapeRange);
if (it != j.end()) {
@@ -187,11 +190,14 @@ void from_json(const Json &j, SingleOpTensorDesc &desc) {
}
string format_str = j.at(kKeyFormat).get<string>();
string type_str = j.at(kKeyType).get<string>();
is_tensor_valid &&= ge::TypeUtils::IsFormatValid(format_str);
is_tensor_valid &&= ge::TypeUtils::IsDataTypeValid(type_str);
desc.format = GetValue(kFormatDict, format_str, FORMAT_RESERVED);
desc.type = GetValue(kDataTypeDict, type_str, DT_UNDEFINED);
it = j.find(kKeyOriginFormat);
if (it != j.end()) {
string origin_format_str = j.at(kKeyOriginFormat).get<string>();
is_tensor_valid &&= ge::TypeUtils::IsFormatValid(origin_format_str);
desc.ori_format = GetValue(kFormatDict, origin_format_str, FORMAT_RESERVED);
}
auto tensor_name = j.find(kKeyName);
@@ -202,6 +208,9 @@ void from_json(const Json &j, SingleOpTensorDesc &desc) {
if (dynamic_input_name != j.end()) {
desc.dynamic_input_name = dynamic_input_name->get<string>();
}
if (!is_tensor_valid) {
ge::AttrUtils::SetBool(&desc, kSingleOpTensorDescValid, is_tensor_valid);
}
}

void from_json(const Json &j, SingleOpAttr &attr) {
@@ -305,6 +314,12 @@ bool SingleOpParser::Validate(const SingleOpDesc &op_desc) {

int index = 0;
for (auto &tensor_desc : op_desc.input_desc) {
if (ge::AttrUtils::GetBool(&tensor_desc)) {
ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"},
{"intput", "datatype or format", std::to_string(index)});
GELOGE(PARAM_INVALID, "Input's dataType or format is invalid when the index is %d", index);
return false;
}
if ((tensor_desc.type == DT_UNDEFINED && tensor_desc.format != FORMAT_RESERVED) ||
(tensor_desc.type != DT_UNDEFINED && tensor_desc.format == FORMAT_RESERVED)){
ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"},
@@ -317,6 +332,12 @@ bool SingleOpParser::Validate(const SingleOpDesc &op_desc) {

index = 0;
for (auto &tensor_desc : op_desc.output_desc) {
if (ge::AttrUtils::GetBool(&tensor_desc)) {
ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"},
{"output", "datatype", std::to_string(index)});
GELOGE(PARAM_INVALID, "Output's dataType is invalid when the index is %d", index);
return false;
}
if (tensor_desc.type == DT_UNDEFINED) {
ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "type", "index"},
{"output", "datatype", std::to_string(index)});


Loading…
Cancel
Save