parent
9d6f983611
commit
a4868ca4f5
@ -0,0 +1,3 @@
|
||||
[submodule "parser"]
|
||||
path = parser
|
||||
url = https://gitee.com/ascend/parser.git
|
@ -1,79 +0,0 @@
|
||||
# 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.
|
||||
# ============================================================================
|
||||
|
||||
# libgraph.so
|
||||
# compiling proto files generates some warnings, use no-unused-variable to suppress them
|
||||
set(CMAKE_CXX_FLAGS "-Wno-unused-variable ${CMAKE_CXX_FLAGS}")
|
||||
# add all proto files, generate corresponding .h and .cc files
|
||||
file(GLOB_RECURSE PROTO_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
|
||||
"${GE_SOURCE_DIR}/metadef/proto/om.proto"
|
||||
"${GE_SOURCE_DIR}/metadef/proto/ge_ir.proto"
|
||||
"${GE_SOURCE_DIR}/metadef/proto/insert_op.proto"
|
||||
"${GE_SOURCE_DIR}/metadef/proto/task.proto"
|
||||
"${GE_SOURCE_DIR}/metadef/proto/fwk_adaper.proto"
|
||||
"${GE_SOURCE_DIR}/metadef/proto/op_mapping_info.proto"
|
||||
"${GE_SOURCE_DIR}/metadef/proto/dump_task.proto"
|
||||
)
|
||||
|
||||
file(GLOB_RECURSE ONNX_PROTO_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
|
||||
"${onnx_INC}/onnx/onnx.proto"
|
||||
)
|
||||
|
||||
ge_protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST})
|
||||
ge_protobuf_generate(ge PROTO_ONNX_SRCS PROTO_ONNX_HDRS ${ONNX_PROTO_LIST})
|
||||
|
||||
# need to remove dependencies on pb files later
|
||||
file(GLOB SRC_LIST RELATIVE ${CMAKE_CURRENT_LIST_DIR}
|
||||
"*.cc"
|
||||
"utils/*.cc"
|
||||
"opsproto/*.cc"
|
||||
"detail/*.cc"
|
||||
"debug/*.cc"
|
||||
"option/*.cc"
|
||||
)
|
||||
|
||||
# include directories
|
||||
include_directories(${CMAKE_CURRENT_LIST_DIR})
|
||||
include_directories(${GE_SOURCE_DIR})
|
||||
#include_directories(${GE_SOURCE_DIR}/src)
|
||||
include_directories(${GE_SOURCE_DIR}/ge)
|
||||
include_directories(${GE_SOURCE_DIR}/metadef)
|
||||
include_directories(${GE_SOURCE_DIR}/metadef/graph)
|
||||
include_directories(${GE_SOURCE_DIR}/inc)
|
||||
include_directories(${GE_SOURCE_DIR}/inc/framework)
|
||||
include_directories(${GE_SOURCE_DIR}/inc/external)
|
||||
include_directories(${GE_SOURCE_DIR}/metadef/inc)
|
||||
include_directories(${GE_SOURCE_DIR}/metadef/inc/external/graph)
|
||||
include_directories(${GE_SOURCE_DIR}/metadef/inc/external)
|
||||
include_directories(${GE_SOURCE_DIR}/metadef/inc/graph)
|
||||
include_directories(${GE_SOURCE_DIR}/inc/common)
|
||||
include_directories(${GE_SOURCE_DIR}/third_party/fwkacllib/inc)
|
||||
include_directories(${GE_SOURCE_DIR}/third_party/fwkacllib/inc/ops)
|
||||
include_directories(${CMAKE_BINARY_DIR})
|
||||
include_directories(${CMAKE_BINARY_DIR}/proto/ge)
|
||||
include_directories(${GE_SOURCE_DIR}/build)
|
||||
|
||||
######### libgraph.so #############
|
||||
add_library(graph SHARED ${SRC_LIST} ${PROTO_SRCS} ${PROTO_ONNX_SRCS})
|
||||
target_compile_definitions(graph PRIVATE
|
||||
DAVINCI_CLOUD
|
||||
Werror)
|
||||
target_link_libraries(graph PRIVATE
|
||||
${PROTOBUF_LIBRARY}
|
||||
${c_sec}
|
||||
${slog}
|
||||
${error_manager}
|
||||
rt
|
||||
dl)
|
File diff suppressed because it is too large
Load Diff
@ -1,38 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "external/graph/attr_value.h"
|
||||
#include "debug/ge_log.h"
|
||||
#include "debug/ge_util.h"
|
||||
#include "framework/common/debug/ge_log.h"
|
||||
#include "graph/ge_attr_value.h"
|
||||
|
||||
namespace ge {
|
||||
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AttrValue::AttrValue() { impl = ComGraphMakeShared<AttrValueImpl>(); }
|
||||
|
||||
#define ATTR_VALUE_SET_GET_IMP(type) \
|
||||
graphStatus AttrValue::GetValue(type &val) const { \
|
||||
if (impl != nullptr) { \
|
||||
GELOGW("GetValue failed."); \
|
||||
return impl->geAttrValue_.GetValue<type>(val); \
|
||||
} \
|
||||
return GRAPH_FAILED; \
|
||||
}
|
||||
|
||||
ATTR_VALUE_SET_GET_IMP(AttrValue::STR)
|
||||
ATTR_VALUE_SET_GET_IMP(AttrValue::INT)
|
||||
ATTR_VALUE_SET_GET_IMP(AttrValue::FLOAT)
|
||||
} // namespace ge
|
@ -1,112 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "graph/buffer.h"
|
||||
#include "proto/ge_ir.pb.h"
|
||||
#include "framework/common/debug/ge_log.h"
|
||||
|
||||
namespace ge {
|
||||
Buffer::Buffer() {
|
||||
data_.InitDefault();
|
||||
if (data_.GetProtoMsg()) {
|
||||
buffer_ = data_.GetProtoMsg()->mutable_bt();
|
||||
}
|
||||
}
|
||||
|
||||
Buffer::Buffer(const Buffer &other) {
|
||||
// Share data
|
||||
data_ = other.data_;
|
||||
buffer_ = other.buffer_;
|
||||
}
|
||||
|
||||
Buffer::Buffer(std::size_t buffer_size, std::uint8_t default_val) : Buffer() { // default
|
||||
auto proto_msg = data_.GetProtoMsg();
|
||||
if (proto_msg != nullptr) {
|
||||
try {
|
||||
proto_msg->set_bt(std::string(buffer_size, default_val));
|
||||
buffer_ = proto_msg->mutable_bt();
|
||||
} catch (std::bad_alloc &e) {
|
||||
GELOGE(MEMALLOC_FAILED, "Failed to alloc buffer memory, buffer size %zu", buffer_size);
|
||||
buffer_ = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Buffer Buffer::CopyFrom(const std::uint8_t *data, std::size_t buffer_size) {
|
||||
Buffer buffer;
|
||||
auto proto_msg = buffer.data_.GetProtoMsg();
|
||||
if (proto_msg != nullptr && data != nullptr) {
|
||||
try {
|
||||
proto_msg->set_bt(data, buffer_size);
|
||||
buffer.buffer_ = proto_msg->mutable_bt();
|
||||
} catch (std::bad_alloc &e) {
|
||||
GELOGE(MEMALLOC_FAILED, "Failed to alloc buffer memory, buffer size %zu", buffer_size);
|
||||
buffer.buffer_ = nullptr;
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
Buffer::Buffer(const std::shared_ptr<google::protobuf::Message> &proto_owner, proto::AttrDef *buffer)
|
||||
: data_(proto_owner, buffer) {
|
||||
if (data_.GetProtoMsg() != nullptr) {
|
||||
buffer_ = data_.GetProtoMsg()->mutable_bt();
|
||||
}
|
||||
}
|
||||
|
||||
Buffer::Buffer(const std::shared_ptr<google::protobuf::Message> &proto_owner, std::string *buffer)
|
||||
: data_(proto_owner, nullptr) {
|
||||
buffer_ = buffer;
|
||||
}
|
||||
|
||||
Buffer &Buffer::operator=(const Buffer &other) {
|
||||
if (&other != this) {
|
||||
// Share data
|
||||
data_ = other.data_;
|
||||
buffer_ = other.buffer_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
const std::uint8_t *Buffer::GetData() const {
|
||||
if (buffer_ != nullptr) {
|
||||
return (const std::uint8_t *)buffer_->data();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::uint8_t *Buffer::GetData() {
|
||||
if (buffer_ != nullptr && !buffer_->empty()) {
|
||||
// Avoid copy on write
|
||||
(void)(*buffer_)[0];
|
||||
return reinterpret_cast<uint8_t *>(const_cast<char *>(buffer_->data()));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::size_t Buffer::GetSize() const {
|
||||
if (buffer_ != nullptr) {
|
||||
return buffer_->size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Buffer::ClearBuffer() {
|
||||
if (buffer_ != nullptr) {
|
||||
buffer_->clear();
|
||||
}
|
||||
}
|
||||
} // namespace ge
|
File diff suppressed because it is too large
Load Diff
@ -1,147 +0,0 @@
|
||||
/**
|
||||
* 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 COMMON_GRAPH_DEBUG_GE_LOG_H_
|
||||
#define COMMON_GRAPH_DEBUG_GE_LOG_H_
|
||||
|
||||
#include "graph/ge_error_codes.h"
|
||||
#include "framework/common/debug/ge_log.h"
|
||||
|
||||
#define GE_LOGE(...) GE_LOG_ERROR(GE_MODULE_NAME, ge::FAILED, __VA_ARGS__)
|
||||
|
||||
#define GE_LOGI_IF(condition, ...) \
|
||||
if ((condition)) { \
|
||||
GELOGI(__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define GE_LOGW_IF(condition, ...) \
|
||||
if ((condition)) { \
|
||||
GELOGW(__VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define GE_LOGE_IF(condition, ...) \
|
||||
if ((condition)) { \
|
||||
GELOGE(ge::FAILED, __VA_ARGS__); \
|
||||
}
|
||||
|
||||
#define GE_CHK_STATUS_RET_NOLOG(expr) \
|
||||
do { \
|
||||
const ge::graphStatus _status = (expr); \
|
||||
if (ge::SUCCESS != _status) { \
|
||||
return _status; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \
|
||||
do { \
|
||||
bool b = (expr); \
|
||||
if (!b) { \
|
||||
GELOGE(ge::FAILED, __VA_ARGS__); \
|
||||
return _status; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
|
||||
{ \
|
||||
bool b = (expr); \
|
||||
if (!b) { \
|
||||
exec_expr; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define GE_IF_BOOL_EXEC(expr, exec_expr) \
|
||||
{ \
|
||||
if (expr) { \
|
||||
exec_expr; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define GE_RETURN_WITH_LOG_IF_ERROR(expr, ...) \
|
||||
do { \
|
||||
const ge::graphStatus _status = (expr); \
|
||||
if (_status) { \
|
||||
GELOGE(ge::FAILED, __VA_ARGS__); \
|
||||
return _status; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// If expr is true, the log is printed and a custom statement is executed
|
||||
#define GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(expr, exec_expr, ...) \
|
||||
{ \
|
||||
bool b = (expr); \
|
||||
if (b) { \
|
||||
GELOGE(ge::FAILED, __VA_ARGS__); \
|
||||
exec_expr; \
|
||||
} \
|
||||
}
|
||||
|
||||
// Only check error log
|
||||
#define GE_CHK_BOOL_ONLY_LOG(expr, ...) \
|
||||
do { \
|
||||
bool b = (expr); \
|
||||
if (!b) { \
|
||||
GELOGI(__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// If expr is not true, do not print the log and return the specified status
|
||||
#define GE_CHK_BOOL_RET_STATUS_NOLOG(expr, _status, ...) \
|
||||
do { \
|
||||
bool b = (expr); \
|
||||
if (!b) { \
|
||||
return _status; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// If expr is not true, the log is printed and a custom statement is executed
|
||||
#define GE_CHK_BOOL_EXEC(expr, exec_expr, ...) \
|
||||
{ \
|
||||
bool b = (expr); \
|
||||
if (!b) { \
|
||||
GELOGE(ge::FAILED, __VA_ARGS__); \
|
||||
exec_expr; \
|
||||
} \
|
||||
}
|
||||
|
||||
// If expr is not true, the log is printed and a custom statement is executed
|
||||
#define GE_CHK_BOOL_EXEC_INFO(expr, exec_expr, ...) \
|
||||
{ \
|
||||
bool b = (expr); \
|
||||
if (!b) { \
|
||||
GELOGI(__VA_ARGS__); \
|
||||
exec_expr; \
|
||||
} \
|
||||
}
|
||||
|
||||
// If expr is not GRAPH_SUCCESS, print the log and return the same value
|
||||
#define GE_CHK_STATUS_RET(expr, ...) \
|
||||
do { \
|
||||
const ge::graphStatus _status = (expr); \
|
||||
if (ge::SUCCESS != _status) { \
|
||||
GELOGE(ge::FAILED, __VA_ARGS__); \
|
||||
return _status; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
|
||||
try { \
|
||||
exec_expr0; \
|
||||
} catch (...) { \
|
||||
GELOGE(ge::FAILED, "Make shared failed"); \
|
||||
exec_expr1; \
|
||||
}
|
||||
|
||||
#endif // COMMON_GRAPH_DEBUG_GE_LOG_H_
|
@ -1,69 +0,0 @@
|
||||
/**
|
||||
* 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 COMMON_GRAPH_DEBUG_GE_OP_TYPES_H_
|
||||
#define COMMON_GRAPH_DEBUG_GE_OP_TYPES_H_
|
||||
|
||||
namespace ge {
|
||||
#define GE_REGISTER_OPTYPE(var_name, str_name) static const char *var_name __attribute__((unused)) = str_name
|
||||
|
||||
GE_REGISTER_OPTYPE(DATA, "Data");
|
||||
GE_REGISTER_OPTYPE(AIPPDATA, "AippData");
|
||||
GE_REGISTER_OPTYPE(MATMUL, "MatMul");
|
||||
GE_REGISTER_OPTYPE(RESHAPE, "Reshape");
|
||||
GE_REGISTER_OPTYPE(PERMUTE, "Permute");
|
||||
GE_REGISTER_OPTYPE(NETOUTPUT, "NetOutput");
|
||||
GE_REGISTER_OPTYPE(_WHILE, "_While");
|
||||
GE_REGISTER_OPTYPE(WHILE, "While");
|
||||
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");
|
||||
GE_REGISTER_OPTYPE(REFENTER, "RefEnter");
|
||||
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");
|
||||
GE_REGISTER_OPTYPE(REFIDENTITY, "RefIdentity");
|
||||
GE_REGISTER_OPTYPE(ANN_DATA, "AnnData");
|
||||
|
||||
GE_REGISTER_OPTYPE(CONSTANTOP, "Constant");
|
||||
GE_REGISTER_OPTYPE(VARIABLE, "Variable");
|
||||
GE_REGISTER_OPTYPE(VARIABLEV2, "VariableV2");
|
||||
|
||||
GE_REGISTER_OPTYPE(INPUT_TYPE, "Input");
|
||||
|
||||
// Horovod operator
|
||||
GE_REGISTER_OPTYPE(HVDCALLBACKALLREDUCE, "hvdCallbackAllreduce");
|
||||
GE_REGISTER_OPTYPE(HVDCALLBACKALLGATHER, "hvdCallbackAllgather");
|
||||
GE_REGISTER_OPTYPE(HVDCALLBACKBROADCAST, "hvdCallbackBroadcast");
|
||||
GE_REGISTER_OPTYPE(HVDWAIT, "hvdWait");
|
||||
|
||||
GE_REGISTER_OPTYPE(NODE_NAME_NET_OUTPUT, "Node_Output");
|
||||
|
||||
GE_REGISTER_OPTYPE(RECV, "Recv");
|
||||
GE_REGISTER_OPTYPE(SEND, "Send");
|
||||
}; // namespace ge
|
||||
#endif // COMMON_GRAPH_DEBUG_GE_OP_TYPES_H_
|
File diff suppressed because it is too large
Load Diff
@ -1,246 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "graph/debug/graph_debug.h"
|
||||
#include <algorithm>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
#include "debug/ge_util.h"
|
||||
#include "framework/common/debug/ge_log.h"
|
||||
|
||||
#define TAB " "
|
||||
#define STR_FMT(str) (" \"" + std::string(str) + "\" ")
|
||||
#define INPUT_ANCHOR_PORT(name) ("__input__" + (name))
|
||||
#define OUTPUT_ANCHOR_PORT(name) ("__output__" + (name))
|
||||
|
||||
namespace ge {
|
||||
std::unordered_set<std::string> control_anchor;
|
||||
std::vector<string> types = {
|
||||
"DT_FLOAT", "DT_FLOAT16", "DT_INT8", "DT_INT32", "DT_UINT8", "",
|
||||
"DT_INT16", "DT_UINT16", "DT_UINT32", "DT_INT64", "DT_UINT64", "DT_DOUBLE",
|
||||
"DT_BOOL", "DT_DUAL", "DT_DUAL_SUB_INT8", "DT_DUAL_SUB_UINT8", "DT_UNDEFINED"};
|
||||
|
||||
std::vector<string> formats = {"FORMAT_NCHW",
|
||||
"FORMAT_NHWC",
|
||||
"FORMAT_ND",
|
||||
"FORMAT_NC1HWC0",
|
||||
"FORMAT_FRACTAL_Z",
|
||||
"FORMAT_NC1C0HWPAD",
|
||||
"FORMAT_NHWC1C0",
|
||||
"FORMAT_FSR_NCHW",
|
||||
"FORMAT_FRACTAL_DECONV",
|
||||
"FORMAT_C1HWNC0",
|
||||
"FORMAT_FRACTAL_DECONV_TRANSPOSE",
|
||||
"FORMAT_FRACTAL_DECONV_SP_STRIDE_TRANS",
|
||||
"FORMAT_NC1HWC0_C04",
|
||||
"FORMAT_FRACTAL_Z_C04",
|
||||
"FORMAT_CHWN",
|
||||
"FORMAT_FRACTAL_DECONV_SP_STRIDE8_TRANS",
|
||||
"FORMAT_HWCN",
|
||||
"FORMAT_NC1KHKWHWC0",
|
||||
"FORMAT_BN_WEIGHT",
|
||||
"FORMAT_FILTER_HWCK",
|
||||
"FORMAT_HASHTABLE_LOOKUP_LOOKUPS",
|
||||
"FORMAT_HASHTABLE_LOOKUP_KEYS",
|
||||
"FORMAT_HASHTABLE_LOOKUP_VALUE",
|
||||
"FORMAT_HASHTABLE_LOOKUP_OUTPUT",
|
||||
"FORMAT_HASHTABLE_LOOKUP_HITS",
|
||||
"FORMAT_RESERVED"};
|
||||
|
||||
std::vector<string> data_nodes = {"Const", "Data"};
|
||||
|
||||
void GraphDebugPrinter::DumpNodeToDot(const NodePtr node, std::ostringstream &out_) {
|
||||
if (node == nullptr) {
|
||||
GELOGI("Some nodes are null.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool in_control = false;
|
||||
auto name = node->GetName();
|
||||
out_ << TAB << STR_FMT(name);
|
||||
auto input_cnt = std::max(static_cast<size_t>(1), node->GetAllInDataAnchors().size());
|
||||
auto output_cnt = std::max(static_cast<size_t>(1), node->GetAllOutDataAnchors().size());
|
||||
if (control_anchor.find(node->GetName()) != control_anchor.end()) {
|
||||
input_cnt++;
|
||||
in_control = true;
|
||||
}
|
||||
auto max_col = input_cnt * output_cnt;
|
||||
out_ << "[\n";
|
||||
if (find(data_nodes.begin(), data_nodes.end(), node->GetType()) != data_nodes.end()) {
|
||||
out_ << TAB << TAB << "shape=plaintext, color=goldenrod\n";
|
||||
} else {
|
||||
out_ << TAB << TAB << "shape=plaintext, color=deepskyblue\n";
|
||||
}
|
||||
out_ << TAB << TAB << "label=<\n";
|
||||
out_ << TAB << TAB << R"(<table border="0" cellborder="1" align="center")"
|
||||
<< ">" << std::endl;
|
||||
|
||||
auto input_anchors = node->GetAllInDataAnchors();
|
||||
auto op_desc = node->GetOpDesc();
|
||||
GE_CHECK_NOTNULL_EXEC(op_desc, return );
|
||||
if (!input_anchors.empty()) {
|
||||
out_ << TAB << TAB << "<tr>";
|
||||
}
|
||||
for (const auto &anchor : input_anchors) {
|
||||
string anchor_text = op_desc->GetInputNameByIndex(anchor->GetIdx());
|
||||
|
||||
out_ << "<td port = " << STR_FMT(INPUT_ANCHOR_PORT(anchor_text)) << " colspan='" << output_cnt << "'>"
|
||||
<< anchor_text << "</td>";
|
||||
}
|
||||
if (in_control) {
|
||||
string anchor_text = "ctrl";
|
||||
out_ << "<td port = " << STR_FMT(INPUT_ANCHOR_PORT(anchor_text)) << " colspan='" << output_cnt << "'>"
|
||||
<< anchor_text << "</td>";
|
||||
}
|
||||
if (!input_anchors.empty()) {
|
||||
out_ << "</tr>\n";
|
||||
}
|
||||
// Node type
|
||||
out_ << TAB << TAB << "<tr><td colspan='" << max_col << "'>"
|
||||
<< "<b>" << node->GetType() << "</b></td></tr>\n";
|
||||
// Output
|
||||
auto output_anchors = node->GetAllOutDataAnchors();
|
||||
if (!output_anchors.empty()) {
|
||||
out_ << TAB << TAB << "<tr>";
|
||||
}
|
||||
for (const auto &anchor : output_anchors) {
|
||||
string anchor_text = op_desc->GetOutputNameByIndex(anchor->GetIdx());
|
||||
|
||||
out_ << "<td port = " << STR_FMT(OUTPUT_ANCHOR_PORT(anchor_text)) << " colspan='" << input_cnt << "'>"
|
||||
<< anchor_text << "</td>";
|
||||
}
|
||||
|
||||
if (!output_anchors.empty()) {
|
||||
out_ << "</tr>\n";
|
||||
}
|
||||
out_ << TAB << TAB << "</table>\n" << TAB << ">];\n";
|
||||
}
|
||||
|
||||
void GraphDebugPrinter::DumpEdgeToDot(const NodePtr node, std::ostringstream &out_, uint32_t flag) {
|
||||
if (node == nullptr) {
|
||||
GELOGI("Some nodes are null.");
|
||||
return;
|
||||
}
|
||||
auto all_out_anchor = node->GetAllOutDataAnchors();
|
||||
auto op_desc = node->GetOpDesc();
|
||||
GE_CHECK_NOTNULL_EXEC(op_desc, return );
|
||||
for (const auto &anchor : all_out_anchor) {
|
||||
auto src_anchor = anchor;
|
||||
auto src_node_name = node->GetName();
|
||||
auto src_anchor_index = op_desc->GetOutputNameByIndex(static_cast<uint32_t>(src_anchor->GetIdx()));
|
||||
auto des_anchors = anchor->GetPeerAnchors();
|
||||
for (const auto &peer_in_anchor : des_anchors) {
|
||||
auto in_data_anchor = Anchor::DynamicAnchorCast<InDataAnchor>(peer_in_anchor);
|
||||
std::string dst_node_name;
|
||||
out_ << TAB << STR_FMT(src_node_name);
|
||||
out_ << ":" << OUTPUT_ANCHOR_PORT(src_anchor_index);
|
||||
auto op = peer_in_anchor->GetOwnerNode()->GetOpDesc();
|
||||
GE_CHECK_NOTNULL_EXEC(op, continue);
|
||||
if (in_data_anchor != nullptr) {
|
||||
dst_node_name = in_data_anchor->GetOwnerNode()->GetName();
|
||||
string des_anchor_index = op->GetInputNameByIndex(static_cast<uint32_t>(in_data_anchor->GetIdx()));
|
||||
out_ << " -> " << STR_FMT(dst_node_name);
|
||||
out_ << ":" << INPUT_ANCHOR_PORT(des_anchor_index);
|
||||
out_ << "[";
|
||||
}
|
||||
auto in_control_anchor = Anchor::DynamicAnchorCast<InControlAnchor>(peer_in_anchor);
|
||||
if (in_control_anchor != nullptr) {
|
||||
dst_node_name = in_control_anchor->GetOwnerNode()->GetName();
|
||||
string des_anchor_index = "ctrl";
|
||||
out_ << " -> " << STR_FMT(dst_node_name);
|
||||
out_ << ":" << INPUT_ANCHOR_PORT(des_anchor_index);
|
||||
out_ << "[";
|
||||
out_ << " style=dashed ";
|
||||
}
|
||||
if (flag != DOT_NOT_SHOW_EDGE_LABEL && in_data_anchor) {
|
||||
string label;
|
||||
auto src_ops = src_anchor->GetOwnerNode()->GetOpDesc();
|
||||
GE_CHECK_NOTNULL_EXEC(src_ops, return );
|
||||
auto src_shape = src_ops->GetOutputDesc(src_anchor->GetIdx()).GetShape();
|
||||
auto dim = src_shape.GetDims();
|
||||
std::ostringstream tensor_info;
|
||||
if (dim.size() > 0) {
|
||||
for (size_t i = 0; i < dim.size(); i++) {
|
||||
if (i != dim.size() - 1) {
|
||||
tensor_info << dim[i] << "x";
|
||||
} else {
|
||||
tensor_info << dim[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
tensor_info << "?";
|
||||
}
|
||||
auto src_tensor_desc = src_ops->GetOutputDescPtr(src_anchor->GetIdx());
|
||||
GE_CHECK_NOTNULL_EXEC(src_tensor_desc, return );
|
||||
auto format = src_tensor_desc->GetFormat();
|
||||
auto datatype = src_tensor_desc->GetDataType();
|
||||
tensor_info << " : " << formats[format] << " : " << types[datatype];
|
||||
label = tensor_info.str();
|
||||
out_ << "label=" << STR_FMT(label);
|
||||
}
|
||||
out_ << "]" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
graphStatus GraphDebugPrinter::DumpGraphDotFile(const Graph &graph, const std::string &output_dot_file_name,
|
||||
uint32_t flag) {
|
||||
auto compute_graph = GraphUtils::GetComputeGraph(graph);
|
||||
if (compute_graph == nullptr) {
|
||||
GELOGI("Compute graph is NULL .");
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
return DumpGraphDotFile(compute_graph, output_dot_file_name, flag);
|
||||
}
|
||||
|
||||
graphStatus GraphDebugPrinter::DumpGraphDotFile(const ComputeGraphPtr graph, const std::string &output_dot_file_name,
|
||||
uint32_t flag) {
|
||||
if (graph == nullptr) {
|
||||
GELOGI("graph is null.");
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
std::ostringstream out_;
|
||||
out_ << "digraph G{\n";
|
||||
out_ << TAB << R"(ratio=compress;size="8, 100")" << std::endl;
|
||||
out_ << TAB << R"(node[fontname="Consolas"])" << std::endl;
|
||||
out_ << TAB << R"(edge[fontsize = "8" fontname = "Consolas" color="dimgray" ])" << std::endl;
|
||||
auto all_nodes = graph->GetAllNodes();
|
||||
for (const auto &node : all_nodes) {
|
||||
for (const auto &temp : node->GetAllOutDataAnchors()) {
|
||||
for (const auto &peer : temp->GetPeerAnchors()) {
|
||||
auto temp_control_anchor = Anchor::DynamicAnchorCast<InControlAnchor>(peer);
|
||||
if (temp_control_anchor) {
|
||||
(void)control_anchor.insert(peer->GetOwnerNode()->GetName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto &node : all_nodes) {
|
||||
DumpNodeToDot(node, out_);
|
||||
}
|
||||
for (const auto &node : all_nodes) {
|
||||
DumpEdgeToDot(node, out_, flag);
|
||||
}
|
||||
out_ << "}";
|
||||
std::ofstream output_file(output_dot_file_name);
|
||||
if (output_file.is_open()) {
|
||||
output_file << out_.str();
|
||||
} else {
|
||||
GELOGW("%s open error.", output_dot_file_name.c_str());
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
} // namespace ge
|
@ -1,48 +0,0 @@
|
||||
/**
|
||||
* 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 COMMON_GRAPH_DEBUG_GRAPH_DEBUG_H_
|
||||
#define COMMON_GRAPH_DEBUG_GRAPH_DEBUG_H_
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "external/graph/graph.h"
|
||||
#include "./ge_error_codes.h"
|
||||
#include "graph/compute_graph.h"
|
||||
#include "graph/debug/ge_log.h"
|
||||
#include "graph/node.h"
|
||||
#include "utils/graph_utils.h"
|
||||
|
||||
namespace ge {
|
||||
enum DotFileFlag {
|
||||
// Show nodes, edges, size, type and format
|
||||
DOT_FLAG_DEFAULT = 0,
|
||||
DOT_NOT_SHOW_EDGE_LABEL = 1,
|
||||
};
|
||||
class GraphDebugPrinter {
|
||||
public:
|
||||
static graphStatus DumpGraphDotFile(const Graph &graph, const std::string &output_dot_file_name,
|
||||
uint32_t flag = DOT_FLAG_DEFAULT);
|
||||
static graphStatus DumpGraphDotFile(const ComputeGraphPtr graph, const std::string &output_dot_file_name,
|
||||
uint32_t flag = DOT_FLAG_DEFAULT);
|
||||
static void DumpNodeToDot(const NodePtr node, std::ostringstream &out_);
|
||||
static void DumpEdgeToDot(const NodePtr node, std::ostringstream &out_, uint32_t flag = DOT_FLAG_DEFAULT);
|
||||
};
|
||||
} // namespace ge
|
||||
|
||||
#endif // COMMON_GRAPH_DEBUG_GRAPH_DEBUG_H_
|
@ -1,241 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "detail/attributes_holder.h"
|
||||
#include <map>
|
||||
#include "debug/ge_log.h"
|
||||
#include "debug/ge_util.h"
|
||||
#include "framework/common/debug/ge_log.h"
|
||||
#include "graph/ge_attr_value.h"
|
||||
#include "proto/ge_ir.pb.h"
|
||||
|
||||
namespace ge {
|
||||
using std::map;
|
||||
using std::unordered_set;
|
||||
void AttrHolder::CopyAttrsFrom(const AttrHolder &holder) { MutableAttrMap().CopyValueFrom(holder.GetAttrMap()); }
|
||||
graphStatus AttrHolder::SetAttr(const std::string &name, const GeAttrValue &value) {
|
||||
if (value.IsEmpty()) {
|
||||
GELOGE(GRAPH_FAILED, "value is empty, key %s", name.c_str());
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
auto proto_map = MutableAttrMap().GetProtoMsg();
|
||||
auto proto_val = value.value_.GetProtoMsg();
|
||||
if (proto_map == nullptr || proto_val == nullptr) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
auto it = proto_map->find(name);
|
||||
if (it != proto_map->end()) {
|
||||
if (it->second.value_case() != proto::AttrDef::VALUE_NOT_SET &&
|
||||
it->second.value_case() != proto_val->value_case()) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
}
|
||||
(*proto_map)[name] = *proto_val;
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
graphStatus AttrHolder::AddRequiredAttr(const std::string &name) {
|
||||
if (HasAttr(name)) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
requiredAttrs_.push_back(name);
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
graphStatus AttrHolder::GetAttr(const std::string &name, GeAttrValue &value) const {
|
||||
auto proto_map = GetAttrMap().GetProtoMsg();
|
||||
auto proto_val = value.value_.GetProtoMsg();
|
||||
if (proto_map == nullptr || proto_val == nullptr) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
auto it = proto_map->find(name);
|
||||
if (it != proto_map->end()) {
|
||||
*proto_val = it->second;
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
bool AttrHolder::HasAttr(const std::string &name) const {
|
||||
auto proto_map = GetAttrMap().GetProtoMsg();
|
||||
if (proto_map != nullptr) {
|
||||
if (proto_map->find(name) != proto_map->end()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return std::find(requiredAttrs_.begin(), requiredAttrs_.end(), name) != requiredAttrs_.end();
|
||||
}
|
||||
|
||||
graphStatus AttrHolder::DelAttr(const std::string &name) {
|
||||
auto proto_map = MutableAttrMap().GetProtoMsg();
|
||||
if (proto_map == nullptr) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
auto it = proto_map->find(name);
|
||||
if (it != proto_map->end()) {
|
||||
(void)proto_map->erase(it);
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
const std::map<string, GeAttrValue> AttrHolder::GetAllAttrs() const {
|
||||
std::map<string, GeAttrValue> attr_value_map;
|
||||
auto proto_map = GetAttrMap().GetProtoMsg();
|
||||
if (proto_map != nullptr) {
|
||||
auto proto_owner = GetAttrMap().GetProtoOwner();
|
||||
GE_CHK_BOOL_EXEC(proto_owner != nullptr, return attr_value_map, "proto_owner is nullptr");
|
||||
for (const auto &it : *proto_map) {
|
||||
attr_value_map[it.first] = GeAttrValue(proto_owner, const_cast<proto::AttrDef *>(&it.second));
|
||||
}
|
||||
}
|
||||
return attr_value_map;
|
||||
}
|
||||
|
||||
const std::unordered_set<string> AttrHolder::GetAllAttrNames() const {
|
||||
std::unordered_set<string> names;
|
||||
auto proto_map = GetAttrMap().GetProtoMsg();
|
||||
if (proto_map != nullptr) {
|
||||
for (const auto &it : *proto_map) {
|
||||
(void)names.insert(it.first);
|
||||
}
|
||||
}
|
||||
for (const string &it : requiredAttrs_) {
|
||||
(void)names.insert(it);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<proto::AttrDef>::InitDefault() {
|
||||
std::shared_ptr<proto::AttrDef> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::AttrDef>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::AttrDef make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = proto_owner.get();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<proto::TensorDef>::InitDefault() {
|
||||
std::shared_ptr<proto::TensorDef> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::TensorDef>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::TensorDef make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = proto_owner.get();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<proto::TensorDescriptor>::InitDefault() {
|
||||
std::shared_ptr<proto::TensorDescriptor> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::TensorDescriptor>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::TensorDescriptor make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = proto_owner.get();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<proto::ShapeDef>::InitDefault() {
|
||||
std::shared_ptr<proto::ShapeDef> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::ShapeDef>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::ShapeDef make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = proto_owner.get();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<proto::NamedAttrs>::InitDefault() {
|
||||
std::shared_ptr<proto::NamedAttrs> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::NamedAttrs>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::NamedAttrs make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = proto_owner.get();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<proto::ModelDef>::InitDefault() {
|
||||
std::shared_ptr<proto::ModelDef> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::ModelDef>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::ModelDef make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = proto_owner.get();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<proto::OpDef>::InitDefault() {
|
||||
std::shared_ptr<proto::OpDef> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::OpDef>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::OpDef make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = proto_owner.get();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<proto::GraphDef>::InitDefault() {
|
||||
std::shared_ptr<proto::GraphDef> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::GraphDef>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::GraphDef make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = proto_owner.get();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<ProtoAttrMap>::InitDefault() {
|
||||
std::shared_ptr<proto::TensorDescriptor> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::TensorDescriptor>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::TensorDescriptor make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = proto_owner->mutable_attr();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
|
||||
template <>
|
||||
void GeIrProtoHelper<const ProtoAttrMap>::InitDefault() {
|
||||
std::shared_ptr<proto::TensorDescriptor> proto_owner;
|
||||
proto_owner = ComGraphMakeShared<proto::TensorDescriptor>();
|
||||
if (proto_owner == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "proto::TensorDescriptor make shared failed");
|
||||
return;
|
||||
}
|
||||
protoMsg_ = &proto_owner->attr();
|
||||
protoOwner_ = proto_owner;
|
||||
}
|
||||
} // namespace ge
|
File diff suppressed because it is too large
Load Diff
@ -1,50 +0,0 @@
|
||||
/**
|
||||
* 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 COMMON_GRAPH_FORMAT_REFINER_H_
|
||||
#define COMMON_GRAPH_FORMAT_REFINER_H_
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include "./compute_graph.h"
|
||||
#include "./external/graph/types.h"
|
||||
#include "./ge_error_codes.h"
|
||||
|
||||
namespace ge {
|
||||
// ShapeRefiner performs shape inference for compute graphs
|
||||
class FormatRefiner {
|
||||
public:
|
||||
static graphStatus InferOrigineFormat(const ge::ComputeGraphPtr &graph);
|
||||
|
||||
private:
|
||||
static graphStatus RefreshConstantOutProcess(const ComputeGraphPtr &graph, const OpDescPtr &op_desc);
|
||||
static graphStatus GetAnchorPoints(const ge::ComputeGraphPtr &graph, std::vector<ge::NodePtr> &anchor_points,
|
||||
std::vector<ge::NodePtr> &data_nodes,
|
||||
std::unordered_map<ge::NodePtr, bool> &node_status);
|
||||
static graphStatus AnchorProcess(const ge::NodePtr &anchor_node, std::unordered_map<ge::NodePtr, bool> &node_status);
|
||||
static void RefreshOriginFormatOfAnchor(std::vector<ge::NodePtr> &anchor_points);
|
||||
static graphStatus BackInferProcess(std::deque<ge::NodePtr> &nodes, ge::NodePtr &node,
|
||||
std::unordered_map<ge::NodePtr, bool> &node_status);
|
||||
static graphStatus ForwardInferProcess(std::deque<ge::NodePtr> &nodes, ge::NodePtr &node,
|
||||
std::unordered_map<ge::NodePtr, bool> &node_status);
|
||||
static graphStatus DataNodeFormatProcess(const ComputeGraphPtr &graph, std::vector<ge::NodePtr> &data_nodes,
|
||||
ge::Format data_format, std::unordered_map<ge::NodePtr, bool> &node_status);
|
||||
static bool IsGraphInferred(const ComputeGraphPtr &graph);
|
||||
};
|
||||
} // namespace ge
|
||||
#endif // COMMON_GRAPH_FORMAT_REFINER_H_
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,112 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "external/graph/inference_context.h"
|
||||
#include "debug/ge_util.h"
|
||||
|
||||
namespace ge {
|
||||
class ShapeAndTypeImpl {
|
||||
public:
|
||||
ShapeAndTypeImpl() = default;
|
||||
~ShapeAndTypeImpl() = default;
|
||||
|
||||
ShapeAndTypeImpl(const Shape &shape, DataType data_type) : shape_(shape), data_type_(data_type) {}
|
||||
|
||||
Shape shape_;
|
||||
DataType data_type_ = DT_UNDEFINED;
|
||||
};
|
||||
|
||||
class InferenceContextImpl {
|
||||
public:
|
||||
InferenceContextImpl() = default;
|
||||
~InferenceContextImpl() = default;
|
||||
|
||||
// For deliver to op in pair, help to support dynamic shape
|
||||
std::vector<std::string> marks_;
|
||||
std::vector<std::vector<ShapeAndType>> input_handle_shapes_and_types_;
|
||||
std::vector<std::vector<ShapeAndType>> output_handle_shapes_and_types_;
|
||||
};
|
||||
|
||||
ShapeAndType::ShapeAndType() { shape_and_type_impl_ = ComGraphMakeShared<ShapeAndTypeImpl>(); }
|
||||
|
||||
ShapeAndType::ShapeAndType(const Shape &shape, DataType data_type) {
|
||||
shape_and_type_impl_ = ComGraphMakeShared<ShapeAndTypeImpl>(shape, data_type);
|
||||
}
|
||||
|
||||
void ShapeAndType::SetShape(const Shape &shape) {
|
||||
if (shape_and_type_impl_ != nullptr) {
|
||||
shape_and_type_impl_->shape_ = shape;
|
||||
}
|
||||
}
|
||||
|
||||
void ShapeAndType::SetType(DataType data_type) {
|
||||
if (shape_and_type_impl_ != nullptr) {
|
||||
shape_and_type_impl_->data_type_ = data_type;
|
||||
}
|
||||
}
|
||||
|
||||
Shape ShapeAndType::GetShape() const {
|
||||
if (shape_and_type_impl_ != nullptr) {
|
||||
return shape_and_type_impl_->shape_;
|
||||
}
|
||||
return Shape();
|
||||
}
|
||||
|
||||
DataType ShapeAndType::GetDataType() const {
|
||||
if (shape_and_type_impl_ != nullptr) {
|
||||
return shape_and_type_impl_->data_type_;
|
||||
}
|
||||
return DT_UNDEFINED;
|
||||
}
|
||||
|
||||
InferenceContext::InferenceContext(std::unique_ptr<InferenceContextImpl> &impl) {
|
||||
inference_context_impl_ = std::move(impl);
|
||||
}
|
||||
|
||||
std::unique_ptr<InferenceContext> InferenceContext::Create() {
|
||||
std::unique_ptr<InferenceContextImpl> impl =
|
||||
std::unique_ptr<InferenceContextImpl>(new (std::nothrow) InferenceContextImpl());
|
||||
if (impl == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::unique_ptr<InferenceContext>(new (std::nothrow) InferenceContext(impl));
|
||||
}
|
||||
|
||||
void InferenceContext::SetInputHandleShapesAndTypes(std::vector<std::vector<ShapeAndType>> &&shapes_and_types) {
|
||||
inference_context_impl_->input_handle_shapes_and_types_.swap(shapes_and_types);
|
||||
}
|
||||
|
||||
const std::vector<std::vector<ShapeAndType>> &InferenceContext::GetInputHandleShapesAndTypes() const {
|
||||
return inference_context_impl_->input_handle_shapes_and_types_;
|
||||
}
|
||||
|
||||
const std::vector<std::vector<ShapeAndType>> &InferenceContext::GetOutputHandleShapesAndTypes() const {
|
||||
return inference_context_impl_->output_handle_shapes_and_types_;
|
||||
}
|
||||
|
||||
void InferenceContext::SetOutputHandleShapesAndTypes(const std::vector<std::vector<ShapeAndType>> &shapes_and_types) {
|
||||
inference_context_impl_->output_handle_shapes_and_types_ = shapes_and_types;
|
||||
}
|
||||
|
||||
void InferenceContext::SetOutputHandleShapesAndTypes(std::vector<std::vector<ShapeAndType>> &&shapes_and_types) {
|
||||
inference_context_impl_->output_handle_shapes_and_types_.swap(shapes_and_types);
|
||||
}
|
||||
|
||||
void InferenceContext::SetMarks(const std::vector<std::string> &marks) { inference_context_impl_->marks_ = marks; }
|
||||
|
||||
const std::vector<std::string> &InferenceContext::GetMarks() const { return inference_context_impl_->marks_; }
|
||||
} // namespace ge
|
@ -1,190 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "graph/model.h"
|
||||
#include <fcntl.h>
|
||||
#include <google/protobuf/io/coded_stream.h>
|
||||
#include <google/protobuf/io/zero_copy_stream.h>
|
||||
#include <google/protobuf/io/zero_copy_stream_impl.h>
|
||||
#include <google/protobuf/text_format.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include "debug/ge_attr_define.h"
|
||||
#include "debug/ge_util.h"
|
||||
#include "framework/common/debug/ge_log.h"
|
||||
#include "graph/model_serialize.h"
|
||||
#include "proto/ge_ir.pb.h"
|
||||
#include "utils/attr_utils.h"
|
||||
#include "utils/ge_ir_utils.h"
|
||||
|
||||
using google::protobuf::io::FileInputStream;
|
||||
using google::protobuf::io::FileOutputStream;
|
||||
using google::protobuf::io::ZeroCopyInputStream;
|
||||
|
||||
namespace {
|
||||
const int DEFAULT_VERSION = 1;
|
||||
const int ACCESS_PERMISSION_BITS = 0400;
|
||||
} // namespace
|
||||
|
||||
namespace ge {
|
||||
void Model::Init() {
|
||||
(void)AttrUtils::SetInt(this, ATTR_MODEL_MEMORY_SIZE, 0);
|
||||
(void)AttrUtils::SetInt(this, ATTR_MODEL_STREAM_NUM, 0);
|
||||
(void)AttrUtils::SetInt(this, ATTR_MODEL_EVENT_NUM, 0);
|
||||
(void)AttrUtils::SetInt(this, ATTR_MODEL_LABEL_NUM, 0);
|
||||
(void)AttrUtils::SetInt(this, ATTR_MODEL_WEIGHT_SIZE, 0);
|
||||
(void)AttrUtils::SetStr(this, ATTR_MODEL_TARGET_TYPE, TARGET_TYPE_MINI);
|
||||
version_ = 0;
|
||||
}
|
||||
|
||||
Model::Model() {
|
||||
attrs_.InitDefault();
|
||||
Init();
|
||||
}
|
||||
|
||||
Model::Model(const string &name, const string &custom_version)
|
||||
: name_(name), version_(DEFAULT_VERSION), platform_version_(custom_version) {
|
||||
attrs_.InitDefault();
|
||||
Init();
|
||||
}
|
||||
|
||||
string Model::GetName() const { return name_; }
|
||||
|
||||
void Model::SetName(const string &name) { name_ = name; }
|
||||
|
||||
uint32_t Model::GetVersion() const { return version_; }
|
||||
|
||||
string Model::GetPlatformVersion() const { return platform_version_; }
|
||||
|
||||
void Model::SetGraph(const ge::Graph &graph) { graph_ = graph; }
|
||||
|
||||
Graph Model::GetGraph() const { return graph_; }
|
||||
|
||||
graphStatus Model::Save(Buffer &buffer, bool is_dump) const {
|
||||
ModelSerialize serialize;
|
||||
buffer = serialize.SerializeModel(*this, is_dump);
|
||||
return buffer.GetSize() > 0 ? GRAPH_SUCCESS : GRAPH_FAILED;
|
||||
}
|
||||
|
||||
void Model::SetAttr(const ProtoAttrMapHelper &attrs) { attrs_ = attrs; }
|
||||
|
||||
graphStatus Model::Load(const uint8_t *data, size_t len, Model &model) {
|
||||
ModelSerialize serialize;
|
||||
model = serialize.UnserializeModel(data, len);
|
||||
return model.IsValid() ? GRAPH_SUCCESS : GRAPH_FAILED;
|
||||
}
|
||||
|
||||
graphStatus Model::SaveToFile(const string &file_name) const {
|
||||
Buffer buffer;
|
||||
if ((*this).Save(buffer) != GRAPH_SUCCESS) {
|
||||
GE_LOGE("save to file fail.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
// Write file
|
||||
ge::proto::ModelDef ge_proto;
|
||||
if (buffer.GetData() != nullptr) {
|
||||
std::string str((const char *)buffer.GetData(), buffer.GetSize());
|
||||
if (!ge_proto.ParseFromString(str)) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
char real_path[PATH_MAX] = {0x00};
|
||||
if (strlen(file_name.c_str()) >= PATH_MAX) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (realpath(file_name.c_str(), real_path) == nullptr) {
|
||||
GELOGI("file %s does not exit, it will be created.", file_name.c_str());
|
||||
}
|
||||
int fd = open(real_path, O_WRONLY | O_CREAT | O_TRUNC, ACCESS_PERMISSION_BITS);
|
||||
if (fd < 0) {
|
||||
GELOGE(GRAPH_FAILED, "open file failed, file path [%s], %s ", real_path, strerror(errno));
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
bool ret = ge_proto.SerializeToFileDescriptor(fd);
|
||||
if (!ret) {
|
||||
GELOGE(GRAPH_FAILED, "SerializeToFileDescriptor failed");
|
||||
if (close(fd) != 0) {
|
||||
GELOGE(GRAPH_FAILED, "close file descriptor fail.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (close(fd) != 0) {
|
||||
GELOGE(GRAPH_FAILED, "close file descriptor fail.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (!ret) {
|
||||
GELOGE(GRAPH_FAILED, "function [SerializeToFileDescriptor] failed");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
}
|
||||
return GRAPH_SUCCESS;
|
||||
}
|
||||
|
||||
graphStatus Model::Load(ge::proto::ModelDef &model_def) {
|
||||
ModelSerialize serialize;
|
||||
*this = serialize.UnserializeModel(model_def);
|
||||
return this->IsValid() ? GRAPH_SUCCESS : GRAPH_FAILED;
|
||||
}
|
||||
|
||||
bool Model::IsValid() const { return graph_.IsValid(); }
|
||||
|
||||
graphStatus Model::LoadFromFile(const string &file_name) {
|
||||
char real_path[PATH_MAX] = {0x00};
|
||||
if (strlen(file_name.c_str()) >= PATH_MAX) {
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (realpath(file_name.c_str(), real_path) == nullptr) {
|
||||
GELOGE(GRAPH_FAILED, "file %s does not exit, can not load.", file_name.c_str());
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
int fd = open(real_path, O_RDONLY);
|
||||
if (fd < 0) {
|
||||
GELOGE(GRAPH_FAILED, "open file failed, %s", strerror(errno));
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
|
||||
ge::proto::ModelDef model_def;
|
||||
bool ret = model_def.ParseFromFileDescriptor(fd);
|
||||
if (!ret) {
|
||||
GELOGE(GRAPH_FAILED, "ParseFromFileDescriptor failed");
|
||||
if (close(fd) != 0) {
|
||||
GELOGE(GRAPH_FAILED, "close file descriptor fail.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (close(fd) != 0) {
|
||||
GELOGE(GRAPH_FAILED, "close file descriptor fail.");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
if (!ret) {
|
||||
GELOGE(GRAPH_FAILED, "function [ParseFromFileDescriptor] failed");
|
||||
return GRAPH_FAILED;
|
||||
}
|
||||
return Load(model_def);
|
||||
}
|
||||
|
||||
ProtoAttrMapHelper Model::MutableAttrMap() { return attrs_; }
|
||||
|
||||
ConstProtoAttrMapHelper Model::GetAttrMap() const {
|
||||
return ConstProtoAttrMapHelper(attrs_.GetProtoOwner(), attrs_.GetProtoMsg());
|
||||
}
|
||||
} // namespace ge
|
File diff suppressed because it is too large
Load Diff
@ -1,3 +0,0 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(LOCAL_PATH)/graph.mk
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue