Browse Source

回退 'Pull Request !208 : fix graphengine compilation'

pull/220/head
王涛 Gitee 4 years ago
parent
commit
6d74596eaf
11 changed files with 3 additions and 1989 deletions
  1. +2
    -2
      src/common/graph/stub/Makefile
  2. +0
    -66
      src/ge/ge_runtime/module.mk
  3. +0
    -1310
      src/ge/offline/main.cc
  4. +0
    -52
      src/ge/offline/module.mk
  5. +0
    -1
      src/ge/offline/proto/ge_ir.proto
  6. +0
    -1
      src/ge/offline/proto/insert_op.proto
  7. +0
    -1
      src/ge/offline/proto/om.proto
  8. +0
    -1
      src/ge/offline/proto/task.proto
  9. +0
    -474
      src/ge/offline/single_op_parser.cc
  10. +0
    -80
      src/ge/offline/single_op_parser.h
  11. +1
    -1
      src/ge/stub/gen_stubapi.py

+ 2
- 2
src/common/graph/stub/Makefile View File

@@ -1,6 +1,6 @@
inc_path := $(shell pwd)/inc/external/
inc_path := $(shell pwd)/metadef/inc/external/
out_path := $(shell pwd)/out/graph/lib64/stub/
stub_path := $(shell pwd)/common/graph/stub/
stub_path := $(shell pwd)/metadef/graph/stub/

mkdir_stub := $(shell mkdir -p $(out_path))
graph_local_stub := $(shell $(HI_PYTHON) $(stub_path)/gen_stubapi.py $(inc_path) $(out_path))

+ 0
- 66
src/ge/ge_runtime/module.mk View File

@@ -1,66 +0,0 @@
LOCAL_PATH := $(call my-dir)

# task.proto is old task, add it for ops_kernel_info_store
local_ge_runtime_src_files := \
model_runner.cc \
runtime_model.cc \
output.cc \
task/aicpu_task.cc \
task/cce_task.cc \
task/tbe_task.cc \
task/event_record_task.cc \
task/event_wait_task.cc \
task/stream_active_task.cc \
task/stream_switch_task.cc \
task/hccl_task.cc \
task/memcpy_async_task.cc \
task/profiler_task.cc \

local_ge_runtime_include := \
$(LOCAL_PATH)/ \
$(TOPDIR)libc_sec/include \
$(TOPDIR)inc/external \
$(TOPDIR)inc/external/graph \
$(TOPDIR)inc/framework \
$(TOPDIR)inc/graph \
$(TOPDIR)inc \
$(LOCAL_PATH)/../ \
third_party/protobuf/include

local_ge_runtime_shared_library := \
libruntime \
libslog \
libc_sec

local_ge_runtime_ldflags := -lrt -ldl

# compile device libge_runtime
include $(CLEAR_VARS)

LOCAL_MODULE := libge_runtime
LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -O2
LOCAL_CFLAGS += -Werror
LOCAL_SRC_FILES := $(local_ge_runtime_src_files)
LOCAL_C_INCLUDES := $(local_ge_runtime_include)
LOCAL_SHARED_LIBRARIES := $(local_ge_runtime_shared_library)
LOCAL_LDFLAGS += $(local_ge_runtime_ldflags)

include $(BUILD_SHARED_LIBRARY)

# compile host libge_runtime
include $(CLEAR_VARS)

LOCAL_MODULE := libge_runtime
LOCAL_CFLAGS += -Werror
LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0
ifeq ($(DEBUG), 1)
LOCAL_CFLAGS += -g -O0
else
LOCAL_CFLAGS += -O2
endif
LOCAL_SRC_FILES := $(local_ge_runtime_src_files)
LOCAL_C_INCLUDES := $(local_ge_runtime_include)
LOCAL_SHARED_LIBRARIES := $(local_ge_runtime_shared_library)
LOCAL_LDFLAGS += $(local_ge_runtime_ldflags)

include $(BUILD_HOST_SHARED_LIBRARY)

+ 0
- 1310
src/ge/offline/main.cc
File diff suppressed because it is too large
View File


+ 0
- 52
src/ge/offline/module.mk View File

@@ -1,52 +0,0 @@

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := atc

LOCAL_CFLAGS += -Werror
LOCAL_CFLAGS += -DPROTOBUF_INLINE_NOT_IN_HEADERS=0 -DCOMPILE_OMG_PACKAGE -O2

LOCAL_SRC_FILES := \
main.cc \
single_op_parser.cc \
../session/omg.cc \
../ir_build/atc_ir_common.cc \

LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/../ ./ \
$(TOPDIR)inc \
$(TOPDIR)inc/external \
$(TOPDIR)inc/external/graph \
$(TOPDIR)inc/framework \
$(TOPDIR)inc/framework/domi \
$(TOPDIR)libc_sec/include \
$(TOPDIR)inc/common/util \
third_party/json/include \
third_party/gflags/include \
third_party/protobuf/include \
proto/om.proto \
proto/ge_ir.proto \
proto/task.proto \
proto/insert_op.proto \

LOCAL_SHARED_LIBRARIES := \
libc_sec \
libge_common \
libprotobuf \
libslog \
libgraph \
libregister \
liberror_manager \
libge_compiler \
libruntime_compile \
libparser_common \
liberror_manager \

LOCAL_STATIC_LIBRARIES := libgflags

LOCAL_LDFLAGS := -lrt -ldl

include $(BUILD_HOST_EXECUTABLE)


+ 0
- 1
src/ge/offline/proto/ge_ir.proto View File

@@ -1 +0,0 @@
../../../../inc/common/proto/ge_ir.proto

+ 0
- 1
src/ge/offline/proto/insert_op.proto View File

@@ -1 +0,0 @@
../../../../inc/common/proto/insert_op.proto

+ 0
- 1
src/ge/offline/proto/om.proto View File

@@ -1 +0,0 @@
../../../../inc/common/proto/om.proto

+ 0
- 1
src/ge/offline/proto/task.proto View File

@@ -1 +0,0 @@
../../proto/task.proto

+ 0
- 474
src/ge/offline/single_op_parser.cc View File

@@ -1,474 +0,0 @@
/**
* Copyright 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.
*/

#include "single_op_parser.h"

#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>

#include <nlohmann/json.hpp>

#include "framework/common/debug/ge_log.h"
#include "common/util/error_manager/error_manager.h"
#include "common/ge_inner_error_codes.h"
#include "framework/common/util.h"
#include "graph/utils/tensor_utils.h"
#include "graph/utils/op_desc_utils.h"
#include "graph/operator_factory_impl.h"

using Json = nlohmann::json;
using std::map;
using std::string;
using std::vector;

namespace ge {
namespace {
constexpr char const *kKeyOp = "op";
constexpr char const *kKeyInputDesc = "input_desc";
constexpr char const *kKeyOutputDesc = "output_desc";
constexpr char const *kKeyAttr = "attr";
constexpr char const *kKeyName = "name";
constexpr char const *kKeyType = "type";
constexpr char const *kKeyShape = "shape";
constexpr char const *kKeyShapeRange = "shape_range";
constexpr char const *kKeyValue = "value";
constexpr char const *kKeyFormat = "format";
constexpr char const *kFileSuffix = ".om";
constexpr int kDumpJsonIndent = 2;
constexpr int kShapeRangePairSize = 2;
constexpr int kShapeRangeLow = 0;
constexpr int kShapeRangeHigh = 1;

map<string, GeAttrValue::ValueType> kAttrTypeDict = {
{"bool", GeAttrValue::VT_BOOL},
{"int", GeAttrValue::VT_INT},
{"float", GeAttrValue::VT_FLOAT},
{"string", GeAttrValue::VT_STRING},
{"list_bool", GeAttrValue::VT_LIST_BOOL},
{"list_int", GeAttrValue::VT_LIST_INT},
{"list_float", GeAttrValue::VT_LIST_FLOAT},
{"list_string", GeAttrValue::VT_LIST_STRING},
{"list_list_int", GeAttrValue::VT_LIST_LIST_INT},
{"data_type", GeAttrValue::VT_DATA_TYPE},
};

map<string, DataType> kDataTypeDict = {
{"bool", DT_BOOL}, {"int8", DT_INT8}, {"uint8", DT_UINT8}, {"int16", DT_INT16}, {"uint16", DT_UINT16},
{"int32", DT_INT32}, {"uint32", DT_UINT32}, {"int64", DT_INT64}, {"uint64", DT_UINT64}, {"float16", DT_FLOAT16},
{"half", DT_FLOAT16}, {"fp16", DT_FLOAT16}, {"float", DT_FLOAT}, {"float32", DT_FLOAT}, {"double", DT_DOUBLE},
};

map<string, Format> kFormatDict = {
{"nchw", FORMAT_NCHW}, {"nhwc", FORMAT_NHWC}, {"nd", FORMAT_ND}, {"fractal_nz", FORMAT_FRACTAL_NZ},
{"fractal_z", FORMAT_FRACTAL_Z}, {"nc1hwc0", FORMAT_NC1HWC0},
};
} // namespace

template <typename T>
void SetAttrValue(const Json &j, SingleOpAttr &attr) {
attr.value.SetValue<T>(j.at(kKeyValue).get<T>());
}

template <typename T>
T GetValue(const map<string, T> &dict, string &key, T default_val) {
transform(key.begin(), key.end(), key.begin(), ::tolower);
auto it = dict.find(key);
if (it == dict.end()) {
return default_val;
}

return it->second;
}

void from_json(const Json &j, SingleOpTensorDesc &desc) {
desc.dims = j.at(kKeyShape).get<vector<int64_t>>();
auto it = j.find(kKeyShapeRange);
if (it != j.end()) {
desc.dim_ranges = j.at(kKeyShapeRange).get<vector<std::vector<int64_t>>>();
}
string format_str = j.at(kKeyFormat).get<string>();
string type_str = j.at(kKeyType).get<string>();
desc.format = GetValue(kFormatDict, format_str, FORMAT_RESERVED);
desc.type = GetValue(kDataTypeDict, type_str, DT_UNDEFINED);
auto tensor_name = j.find(kKeyName);
if (tensor_name != j.end()) {
desc.name = tensor_name->get<string>();
}
}

void from_json(const Json &j, SingleOpAttr &attr) {
attr.name = j.at(kKeyName).get<string>();
attr.type = j.at(kKeyType).get<string>();
auto it = kAttrTypeDict.find(attr.type);
if (it == kAttrTypeDict.end()) {
GELOGE(UNSUPPORTED, "Parse attr[%s] failed. Unsupported type: %s", attr.name.c_str(), attr.type.c_str());
return;
}

switch (it->second) {
case GeAttrValue::VT_BOOL:
SetAttrValue<bool>(j, attr);
break;
case GeAttrValue::VT_INT:
SetAttrValue<int64_t>(j, attr);
break;
case GeAttrValue::VT_FLOAT:
SetAttrValue<float>(j, attr);
break;
case GeAttrValue::VT_STRING:
SetAttrValue<string>(j, attr);
break;
case GeAttrValue::VT_LIST_BOOL:
SetAttrValue<vector<bool>>(j, attr);
break;
case GeAttrValue::VT_LIST_INT:
SetAttrValue<vector<int64_t>>(j, attr);
break;
case GeAttrValue::VT_LIST_FLOAT:
SetAttrValue<vector<float>>(j, attr);
break;
case GeAttrValue::VT_LIST_STRING:
SetAttrValue<vector<string>>(j, attr);
break;
case GeAttrValue::VT_LIST_LIST_INT:
SetAttrValue<vector<vector<int64_t>>>(j, attr);
break;
case GeAttrValue::VT_DATA_TYPE:
SetAttrValue<DataType>(j, attr);
break;
default:
GELOGE(UNSUPPORTED, "Parse attr[%s] failed. Unsupported type: %s", attr.name.c_str(), attr.type.c_str());
break;
}
}

void from_json(const Json &j, SingleOpDesc &desc) {
desc.op = j.at(kKeyOp).get<string>();

auto input_desc = j.find(kKeyInputDesc);
if (input_desc != j.end()) {
desc.input_desc = input_desc->get<vector<SingleOpTensorDesc>>();
}

auto output_desc = j.find(kKeyOutputDesc);
if (output_desc != j.end()) {
desc.output_desc = output_desc->get<vector<SingleOpTensorDesc>>();
}

auto attr_field = j.find(kKeyAttr);
if (attr_field != j.end()) {
desc.attrs = attr_field->get<vector<SingleOpAttr>>();
}
}

Status SingleOpParser::ReadJsonFile(const std::string &file, Json &json_obj) {
std::string real_path = RealPath(file.c_str());
if (real_path.empty()) {
ErrorManager::GetInstance().ATCReportErrMessage("E10023", {"value"}, {file});
GELOGE(FAILED, "Input parameter[--singleop]'s value[%s] is not a valid path.", file.c_str());
return INTERNAL_ERROR;
}

std::ifstream ifs(real_path);
if (!ifs.is_open()) {
ErrorManager::GetInstance().ATCReportErrMessage("E10024", {"value"}, {file});
GELOGE(FAILED, "Open file[%s] provided in input parameter[--singleop] failed.", file.c_str());
return FAILED;
}
try {
ifs >> json_obj;
} catch (const std::exception &e) {
ErrorManager::GetInstance().ATCReportErrMessage("E10025", {"realpath", "errmsg"}, {real_path, e.what()});
GELOGE(PARAM_INVALID, "Parse file[%s] provided in input parameter[--singleop] failed, exception = %s.",
real_path.c_str(), e.what());
return PARAM_INVALID;
}

ifs.close();
return SUCCESS;
}

bool SingleOpParser::Validate(const SingleOpDesc &op_desc) {
if (op_desc.op.empty()) {
ErrorManager::GetInstance().ATCReportErrMessage("E10026");
GELOGE(PARAM_INVALID, "Op name is empty");
return false;
}

int index = 0;
for (auto &tensor_desc : op_desc.input_desc) {
if (tensor_desc.type == DT_UNDEFINED) {
ErrorManager::GetInstance().ATCReportErrMessage("E10027", {"input", "index"}, {"input", std::to_string(index)});
GELOGE(false, "Input's dataType is invalid when the index is %d", index);
return false;
}

if (tensor_desc.format == FORMAT_RESERVED) {
ErrorManager::GetInstance().ATCReportErrMessage("E10028", {"input", "index"}, {"input", std::to_string(index)});
GELOGE(PARAM_INVALID, "Input's format is invalid when the index is %d", index);
return false;
}
++index;
}

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

if (tensor_desc.format == FORMAT_RESERVED) {
ErrorManager::GetInstance().ATCReportErrMessage("E10028", {"input", "index"}, {"output", std::to_string(index)});
GELOGE(PARAM_INVALID, "Output's format is invalid when the index is %d", index);
return false;
}
++index;
}

for (auto &attr : op_desc.attrs) {
if (attr.name.empty()) {
ErrorManager::GetInstance().ATCReportErrMessage("E10029");
GELOGE(PARAM_INVALID, "attr name is empty");
return false;
}

if (attr.value.IsEmpty()) {
ErrorManager::GetInstance().ATCReportErrMessage("E10030", {"attrname"}, {attr.name});
GELOGE(PARAM_INVALID, "Parse attr \"%s\" failed. ", attr.name.c_str());
return false;
}
}

return true;
}

std::unique_ptr<OpDesc> SingleOpParser::CreateOpDesc(const string &op_type) {
return std::unique_ptr<OpDesc>(new (std::nothrow) OpDesc(op_type, op_type));
}

Status SingleOpParser::ConvertToBuildParam(int index, const SingleOpDesc &single_op_desc,
SingleOpBuildParam &build_param) {
auto op_desc = CreateOpDesc(single_op_desc.op);
if (op_desc == nullptr) {
GELOGE(MEMALLOC_FAILED, "Failed to create instance of opDesc");
return MEMALLOC_FAILED;
}

std::stringstream file_name;
file_name << index;
file_name << "_" << single_op_desc.op;
for (auto &desc : single_op_desc.input_desc) {
file_name << "_" << desc.type << "_" << desc.format;
for (auto dim : desc.dims) {
file_name << "_" << dim;
}
GeTensorDesc ge_tensor_desc(GeShape(desc.dims), desc.format, desc.type);
ge_tensor_desc.SetOriginFormat(desc.format);
GE_CHK_STATUS_RET_NOLOG(SetShapeRange(op_desc->GetName(), desc, ge_tensor_desc));
TensorUtils::SetRealDimCnt(ge_tensor_desc, desc.dims.size());
TensorUtils::SetInputTensor(ge_tensor_desc, true);
TensorUtils::SetOutputTensor(ge_tensor_desc, false);
if (desc.name.empty()) {
op_desc->AddInputDesc(ge_tensor_desc);
} else {
op_desc->AddInputDesc(desc.name, ge_tensor_desc);
}
build_param.inputs.emplace_back(ge_tensor_desc);
}

for (auto &desc : single_op_desc.output_desc) {
file_name << "_" << desc.type << "_" << desc.format;
for (auto dim : desc.dims) {
file_name << "_" << dim;
}

GeTensorDesc ge_tensor_desc(GeShape(desc.dims), desc.format, desc.type);
ge_tensor_desc.SetOriginFormat(desc.format);
GE_CHK_STATUS_RET_NOLOG(SetShapeRange(op_desc->GetName(), desc, ge_tensor_desc));
TensorUtils::SetRealDimCnt(ge_tensor_desc, desc.dims.size());
TensorUtils::SetInputTensor(ge_tensor_desc, false);
TensorUtils::SetOutputTensor(ge_tensor_desc, true);
if (desc.name.empty()) {
op_desc->AddOutputDesc(ge_tensor_desc);
} else {
op_desc->AddOutputDesc(desc.name, ge_tensor_desc);
}
build_param.outputs.emplace_back(ge_tensor_desc);
}

for (const auto &attr : single_op_desc.attrs) {
op_desc->SetAttr(attr.name, attr.value);
}

if (VerifyOpInputOutputSizeByIr(*op_desc) != SUCCESS) {
GELOGE(PARAM_INVALID, "Verify op [%s] input or output size failed.", op_desc->GetType().c_str());
return PARAM_INVALID;
}

file_name << kFileSuffix;
build_param.file_name = file_name.str();
build_param.op_desc.reset(op_desc.release());
return SUCCESS;
}

Status SingleOpParser::VerifyOpInputOutputSizeByIr(const OpDesc &current_op_desc) {
ge::Operator operator_ir = ge::OperatorFactory::CreateOperator("tmp_operator", current_op_desc.GetType());
if (!operator_ir.IsEmpty()) {
auto opdesc_ir = ge::OpDescUtils::GetOpDescFromOperator(operator_ir);
GE_CHECK_NOTNULL(opdesc_ir);
size_t current_opdesc_inputs_num = current_op_desc.GetInputsSize();
size_t ir_opdesc_inputs_num = opdesc_ir->GetInputsSize();
if (current_opdesc_inputs_num < ir_opdesc_inputs_num) {
string reason = "is smaller than the ir needed input size " + std::to_string(ir_opdesc_inputs_num);
ErrorManager::GetInstance().ATCReportErrMessage(
"E19014", {"opname", "value", "reason"},
{current_op_desc.GetName(), "input size " + std::to_string(current_opdesc_inputs_num), reason});
GELOGE(PARAM_INVALID, "This op [%s] input size %zu is smaller than the ir needed input size %zu",
current_op_desc.GetName().c_str(), current_opdesc_inputs_num, ir_opdesc_inputs_num);
return PARAM_INVALID;
}
size_t current_opdesc_outputs_num = current_op_desc.GetOutputsSize();
size_t ir_opdesc_outputs_num = opdesc_ir->GetOutputsSize();
if (current_opdesc_outputs_num < ir_opdesc_outputs_num) {
string reason = "is smaller than the ir needed output size " + std::to_string(ir_opdesc_outputs_num);
ErrorManager::GetInstance().ATCReportErrMessage(
"E19014", {"opname", "value", "reason"},
{current_op_desc.GetName(), "output size " + std::to_string(current_opdesc_outputs_num), reason});
GELOGE(PARAM_INVALID, "This op [%s] output size %zu is smaller than the ir needed output size %zu",
current_op_desc.GetName().c_str(), current_opdesc_outputs_num, ir_opdesc_outputs_num);
return PARAM_INVALID;
}
}
return SUCCESS;
}

Status SingleOpParser::SetShapeRange(const std::string &op_name, const SingleOpTensorDesc &tensor_desc,
GeTensorDesc &ge_tensor_desc) {
auto num_shape_ranges = tensor_desc.dim_ranges.size();
GELOGD("Number of shape ranges = %zu", num_shape_ranges);
auto it = std::find(tensor_desc.dims.begin(), tensor_desc.dims.end(), ge::UNKNOWN_DIM_NUM);
if (it != tensor_desc.dims.end()) {
if (tensor_desc.dims != ge::UNKNOWN_RANK) {
ErrorManager::GetInstance().ATCReportErrMessage("E19014", {"opname", "value", "reason"},
{op_name, "shape", "has unknown rank but dim size is not one"});
GELOGE(PARAM_INVALID, "Invalid tensor shape: [%s]", ge_tensor_desc.MutableShape().ToString().c_str());
return PARAM_INVALID;
}
if (!tensor_desc.dim_ranges.empty()) {
ErrorManager::GetInstance().ATCReportErrMessage(
"E19014", {"opname", "value", "reason"},
{op_name, "shape range", "is not needed while the rank the shape is unknown"});
GELOGE(PARAM_INVALID, "Shape range is not needed while the rank the shape is unknown");
return PARAM_INVALID;
}

GELOGD("Shape is unknown rank, do not set shape range");
return SUCCESS;
}

std::vector<std::pair<int64_t, int64_t>> shape_range;
size_t range_index = 0;
for (auto dim : tensor_desc.dims) {
if (dim >= 0) {
shape_range.emplace_back(dim, dim);
GELOGD("Adding shape range: [%ld, %ld]", dim, dim);
} else {
GELOGD("To get shape range by index = %zu", range_index);
if (range_index >= num_shape_ranges) {
string reason = "is smaller than the unknown dim size " + std::to_string(++range_index);
ErrorManager::GetInstance().ATCReportErrMessage(
"E19014", {"opname", "value", "reason"},
{op_name, "shape range size " + std::to_string(num_shape_ranges), reason});
GELOGE(PARAM_INVALID, "The number of shape_range mismatches that of unknown dims.");
return PARAM_INVALID;
}

auto &range = tensor_desc.dim_ranges[range_index];
if (range.size() != kShapeRangePairSize) {
string reason = "has " + std::to_string(range.size()) + " item(s)";
ErrorManager::GetInstance().ATCReportErrMessage(
"E19014", {"opname", "value", "reason"}, {op_name, "shape range " + std::to_string(range_index), reason});
GELOGE(PARAM_INVALID, "Invalid shape range entry. index = %zu, size = %zu", range_index, range.size());
return PARAM_INVALID;
}

shape_range.emplace_back(range[kShapeRangeLow], range[kShapeRangeHigh]);
GELOGD("Adding shape range: [%ld, %ld]", range[kShapeRangeLow], range[kShapeRangeHigh]);
++range_index;
}
}

if (num_shape_ranges != range_index) {
string reason = "is greater than the unknown dim size " + std::to_string(range_index);
ErrorManager::GetInstance().ATCReportErrMessage(
"E19014", {"opname", "value", "reason"},
{op_name, "shape range size " + std::to_string(num_shape_ranges), reason});
GELOGE(PARAM_INVALID, "The number of shape_range(%zu) mismatches that of unknown dims(%zu).", num_shape_ranges,
range_index);
return PARAM_INVALID;
}

if (range_index > 0) {
ge_tensor_desc.SetShapeRange(shape_range);
}

return SUCCESS;
}

Status SingleOpParser::ParseSingleOpList(const std::string &file, std::vector<SingleOpBuildParam> &op_list) {
Json single_op_list_json;
auto ret = ReadJsonFile(file, single_op_list_json);
if (ret != SUCCESS) {
return ret;
}

int index = 0;
for (const Json &single_op_json : single_op_list_json) {
SingleOpDesc single_op_desc;
try {
GELOGI("Parsing op[%d], jsonStr = %s", index, single_op_json.dump(kDumpJsonIndent).c_str());
single_op_desc = single_op_json;
} catch (const nlohmann::json::exception &e) {
ErrorManager::GetInstance().ATCReportErrMessage("E10032", {"index", "jsonfile", "exception"},
{std::to_string(index), file, e.what()});
GELOGE(PARAM_INVALID, "Parse the index[%d] of op failed when read json file[%s], exception %s", index,
file.c_str(), e.what());
return PARAM_INVALID;
}

if (!Validate(single_op_desc)) {
GELOGE(PARAM_INVALID, "Validate the index[%d] of op failed when read json file[%s].", index, file.c_str());
return PARAM_INVALID;
}

SingleOpBuildParam param;
ret = ConvertToBuildParam(index, single_op_desc, param);
if (ret != SUCCESS) {
return ret;
}

op_list.emplace_back(param);
GELOGI("Parse the index[%d] of op success", index);
index += 1;
}

return SUCCESS;
}
} // namespace ge

+ 0
- 80
src/ge/offline/single_op_parser.h View File

@@ -1,80 +0,0 @@
/**
* Copyright 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 ACL_TOOLS_COMPILE_PARSER_H
#define ACL_TOOLS_COMPILE_PARSER_H

#include <vector>
#include <string>

#include <nlohmann/json.hpp>

#include "ge/ge_api_error_codes.h"
#include "graph/types.h"
#include "graph/ge_attr_value.h"
#include "graph/op_desc.h"

namespace ge {
struct SingleOpTensorDesc {
std::string name;
std::vector<int64_t> dims;
std::vector<std::vector<int64_t>> dim_ranges;
ge::Format format = ge::FORMAT_RESERVED;
ge::DataType type = ge::DT_UNDEFINED;
};

struct SingleOpAttr {
std::string name;
std::string type;
ge::GeAttrValue value;
};

struct SingleOpDesc {
std::string op;
std::vector<SingleOpTensorDesc> input_desc;
std::vector<SingleOpTensorDesc> output_desc;
std::vector<SingleOpAttr> attrs;
};

struct SingleOpBuildParam {
ge::OpDescPtr op_desc;
std::vector<ge::GeTensor> inputs;
std::vector<ge::GeTensor> outputs;
std::string file_name;
};

void from_json(const nlohmann::json &json, SingleOpTensorDesc &desc);

void from_json(const nlohmann::json &json, SingleOpAttr &desc);

void from_json(const nlohmann::json &json, SingleOpDesc &desc);

class SingleOpParser {
public:
static Status ParseSingleOpList(const std::string &file, std::vector<SingleOpBuildParam> &op_list);

private:
static Status ReadJsonFile(const std::string &file, nlohmann::json &json_obj);
static bool Validate(const SingleOpDesc &op_desc);
static std::unique_ptr<OpDesc> CreateOpDesc(const std::string &op_type);
static Status ConvertToBuildParam(int index, const SingleOpDesc &single_op_desc, SingleOpBuildParam &build_param);
static Status VerifyOpInputOutputSizeByIr(const OpDesc &current_op_desc);
static Status SetShapeRange(const std::string &op_name, const SingleOpTensorDesc &tensor_desc,
GeTensorDesc &ge_tensor_desc);
};
} // namespace ge

#endif // ACL_TOOLS_COMPILE_PARSER_H

+ 1
- 1
src/ge/stub/gen_stubapi.py View File

@@ -64,7 +64,7 @@ max_code_len_per_line = 100
when DEBUG on
"""
white_list_for_debug = ["attr_value.h", "operator.h", "tensor.h", "graph.h", "operator_factory.h",
"ge_ir_build.h", "ge_api.h", "ge_prof.h", "tensorflow_parser.h", "caffe_parser.h"]
"ge_ir_build.h", "ge_api.h", "tensorflow_parser.h", "caffe_parser.h"]
include_dir_key_words = ["ge", "graph", "parser"]
DEBUG = True



Loading…
Cancel
Save