Browse Source

initial version

tags/v0.2.0-alpha
lujiale 4 years ago
commit
5f763679fa
100 changed files with 13532 additions and 0 deletions
  1. +152
    -0
      .clang-format
  2. +29
    -0
      .gitignore
  3. +134
    -0
      CMakeLists.txt
  4. +201
    -0
      LICENSE
  5. +2
    -0
      NOTICE
  6. +107
    -0
      README.md
  7. +17
    -0
      RELEASE.md
  8. +460
    -0
      Third_Party_Open_Source_Software_Notice
  9. +172
    -0
      build.sh
  10. +13
    -0
      cmake/external_libs/eigen.cmake
  11. +16
    -0
      cmake/external_libs/gtest.cmake
  12. +9
    -0
      cmake/external_libs/json.cmake
  13. +5
    -0
      cmake/external_libs/onnx.cmake
  14. +57
    -0
      cmake/external_libs/protobuf.cmake
  15. +349
    -0
      cmake/ge_utils.cmake
  16. BIN
      docs/GE_Architecture.png
  17. +3
    -0
      docs/README.md
  18. +121
    -0
      inc/common/blocking_queue.h
  19. +104
    -0
      inc/common/dynamic_aipp.h
  20. +94
    -0
      inc/common/npu_error_define.h
  21. +55
    -0
      inc/common/opskernel/ge_task_info.h
  22. +87
    -0
      inc/common/opskernel/ops_kernel_info_store.h
  23. +63
    -0
      inc/common/opskernel/ops_kernel_info_types.h
  24. +61
    -0
      inc/common/optimizer/graph_optimizer.h
  25. +36
    -0
      inc/common/optimizer/graph_optimizer_types.h
  26. +102
    -0
      inc/external/ge/ge_api.h
  27. +76
    -0
      inc/external/ge/ge_api_error_codes.h
  28. +195
    -0
      inc/external/ge/ge_api_types.h
  29. +73
    -0
      inc/external/graph/attr_value.h
  30. +38
    -0
      inc/external/graph/ge_error_codes.h
  31. +77
    -0
      inc/external/graph/graph.h
  32. +79
    -0
      inc/external/graph/inference_context.h
  33. +257
    -0
      inc/external/graph/operator.h
  34. +68
    -0
      inc/external/graph/operator_factory.h
  35. +313
    -0
      inc/external/graph/operator_reg.h
  36. +123
    -0
      inc/external/graph/tensor.h
  37. +224
    -0
      inc/external/graph/types.h
  38. +134
    -0
      inc/external/graph/usr_types.h
  39. +199
    -0
      inc/external/register/register.h
  40. +38
    -0
      inc/external/register/register_error_codes.h
  41. +42
    -0
      inc/external/register/register_fmk_types.h
  42. +55
    -0
      inc/external/register/register_types.h
  43. +22
    -0
      inc/framework/common/aicpu_op.h
  44. +96
    -0
      inc/framework/common/debug/ge_log.h
  45. +254
    -0
      inc/framework/common/debug/log.h
  46. +85
    -0
      inc/framework/common/fmk_error_codes.h
  47. +23
    -0
      inc/framework/common/fmk_types.h
  48. +40
    -0
      inc/framework/common/ge_format_util.h
  49. +295
    -0
      inc/framework/common/ge_inner_error_codes.h
  50. +153
    -0
      inc/framework/common/ge_types.h
  51. +76
    -0
      inc/framework/common/gflags_util.h
  52. +67
    -0
      inc/framework/common/helper/model_helper.h
  53. +91
    -0
      inc/framework/common/helper/om_file_helper.h
  54. +120
    -0
      inc/framework/common/l2_cache_optimize.h
  55. +161
    -0
      inc/framework/common/op/attr_value_util.h
  56. +280
    -0
      inc/framework/common/op/ge_op_utils.h
  57. +425
    -0
      inc/framework/common/op/op_parser_util.h
  58. +62
    -0
      inc/framework/common/op_types.h
  59. +60
    -0
      inc/framework/common/scope_guard.h
  60. +156
    -0
      inc/framework/common/string_util.h
  61. +1048
    -0
      inc/framework/common/types.h
  62. +378
    -0
      inc/framework/common/util.h
  63. +66
    -0
      inc/framework/dlog/log.h
  64. +55
    -0
      inc/framework/engine/dnnengine.h
  65. +166
    -0
      inc/framework/executor/ge_executor.h
  66. +113
    -0
      inc/framework/ge_runtime/davinci_model.h
  67. +58
    -0
      inc/framework/ge_runtime/model_runner.h
  68. +72
    -0
      inc/framework/ge_runtime/op_info.h
  69. +394
    -0
      inc/framework/ge_runtime/task_info.h
  70. +67
    -0
      inc/framework/generator/ge_generator.h
  71. +172
    -0
      inc/framework/generator/generator_api.h
  72. +42
    -0
      inc/framework/memory/memory_assigner.h
  73. +130
    -0
      inc/framework/omg/omg_inner_types.h
  74. +22
    -0
      inc/framework/omg/omg_types.h
  75. +53
    -0
      inc/framework/omg/version.h
  76. +278
    -0
      inc/graph/anchor.h
  77. +190
    -0
      inc/graph/attr_value_serializable.h
  78. +83
    -0
      inc/graph/buffer.h
  79. +242
    -0
      inc/graph/compute_graph.h
  80. +778
    -0
      inc/graph/debug/ge_attr_define.h
  81. +198
    -0
      inc/graph/def_types.h
  82. +118
    -0
      inc/graph/detail/any_map.h
  83. +154
    -0
      inc/graph/detail/attributes_holder.h
  84. +90
    -0
      inc/graph/detail/model_serialize_imp.h
  85. +342
    -0
      inc/graph/ge_attr_value.h
  86. +45
    -0
      inc/graph/ge_context.h
  87. +26
    -0
      inc/graph/ge_global_options.h
  88. +44
    -0
      inc/graph/ge_local_context.h
  89. +171
    -0
      inc/graph/ge_tensor.h
  90. +134
    -0
      inc/graph/graph_util.h
  91. +95
    -0
      inc/graph/model.h
  92. +54
    -0
      inc/graph/model_serialize.h
  93. +208
    -0
      inc/graph/node.h
  94. +256
    -0
      inc/graph/op_desc.h
  95. +47
    -0
      inc/graph/op_kernel_bin.h
  96. +58
    -0
      inc/graph/operator_factory_impl.h
  97. +44
    -0
      inc/graph/opsproto_manager.h
  98. +53
    -0
      inc/graph/range_vistor.h
  99. +37
    -0
      inc/graph/shape_refiner.h
  100. +45
    -0
      inc/graph/utils/anchor_utils.h

+ 152
- 0
.clang-format View File

@@ -0,0 +1,152 @@
---
Language: Cpp
# BasedOnStyle: Google
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DerivePointerAlignment: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
# - foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 2
UseTab: Never
SortIncludes: false
...


+ 29
- 0
.gitignore View File

@@ -0,0 +1,29 @@
# GraphEngine
/build
/output
/prebuilts
*.ir
*.out
# Dynamic libraries
# *.so
*.dylib
# Static libraries
*.la
*.lai
*.a
*.lib
# Protocol buffers
*_pb2.py
*.pb.h
*.pb.cc
# Object files
*.o
# Editor
.vscode
.idea/
cmake-build-*

+ 134
- 0
CMakeLists.txt View File

@@ -0,0 +1,134 @@
# 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.
# ============================================================================

cmake_minimum_required(VERSION 3.14)
project (GraphEngine[CXX])
set(CMAKE_CXX_STANDARD 14)

set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR})
set(GE_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
set(GE_PROTO_DIR ${GE_SOURCE_DIR}/src)

if (NOT BUILD_PATH)
set(BUILD_PATH "${CMAKE_SOURCE_DIR}/build")
endif()
# architecture: aarch64 or x86_64
message(STATUS "System architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
# system: euleros or ubuntu
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
execute_process(
COMMAND bash "-c" "cat /etc/os-release | grep ^ID= | awk -F '=' '{print $2}'"
OUTPUT_VARIABLE SYSTEM_TYPE
)
MESSAGE(STATUS "System type: ${SYSTEM_TYPE}.")
endif()

# download json headers, rather than whole repository
include(${GE_SOURCE_DIR}/cmake/ge_utils.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/json.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/eigen.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/gtest.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/protobuf.cmake)
include(${GE_SOURCE_DIR}/cmake/external_libs/onnx.cmake)
set(CMAKE_SKIP_RPATH TRUE)

# for CPU/GPU mode, find c_sec and slog from local prebuild
if(NOT ENABLE_D AND NOT GE_ONLY)
set(GE_PREBUILD_PATH ${GE_SOURCE_DIR}/third_party/prebuild/${CMAKE_HOST_SYSTEM_PROCESSOR})
find_library(c_sec libc_sec.so ${GE_PREBUILD_PATH})
find_library(slog libslog.so ${GE_PREBUILD_PATH})
# if D_LINK_PATH is set in environment variables, search libraries in given path
elseif(DEFINED ENV{D_LINK_PATH})
# D_LINK_PATH is set
set(GE_LIB_PATH $ENV{D_LINK_PATH})
set(GE_SYS_ARCH "")
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64")
# x86 ubuntu
set(GE_SYS_ARCH "x86_64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64")
# arm euleros
set(GE_SYS_ARCH "aarch64")
else()
message(FATAL_ERROR "Running on a unsupported architecture: ${SYSTEM_TYPE}, build terminated")
endif()
set(GE_LIB_PATH ${GE_LIB_PATH}/${GE_SYS_ARCH})
find_library(c_sec libc_sec.so ${GE_LIB_PATH})
find_library(slog libslog.so ${GE_LIB_PATH})
find_library(mmpa libmmpa.so ${GE_LIB_PATH})
find_library(runtime libruntime.so ${GE_LIB_PATH})
find_library(msprof libmsprof.so ${GE_LIB_PATH})
find_library(register libregister.so ${GE_LIB_PATH})
find_library(hccl libhccl.so ${GE_LIB_PATH})
find_library(cce libcce.so ${GE_LIB_PATH})
find_library(resource libresource.so ${GE_LIB_PATH})
else()
# Ascend mode
set(HIAI_INSTALLED_DIR /usr/local/HiAI)
set(HIAI_DRIVER_DIR ${HIAI_INSTALLED_DIR}/driver/lib64)
set(HIAI_RUNTIME_DIR ${HIAI_INSTALLED_DIR}/runtime/lib64)
find_library(c_sec libc_sec.so ${HIAI_DRIVER_DIR})
find_library(slog libslog.so ${HIAI_DRIVER_DIR})
find_library(mmpa libmmpa.so ${HIAI_DRIVER_DIR})

find_library(cce libcce.so ${HIAI_RUNTIME_DIR})
find_library(hccl libhccl.so ${HIAI_RUNTIME_DIR})
find_library(runtime libruntime.so ${HIAI_RUNTIME_DIR})
find_library(msprof libmsprof.so ${HIAI_RUNTIME_DIR})
find_library(register libregister.so ${HIAI_RUNTIME_DIR})
find_library(resource libresource.so ${HIAI_RUNTIME_DIR})
endif()

# add compile flags
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
message("Build in Debug mode")
set(CMAKE_C_FLAGS "-O0 -g -Wall -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe -fPIC ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-O0 -g -Wall -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe -fPIC ${CMAKE_CXX_FLAGS}")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -rdynamic")
endif()
else()
set(CMAKE_C_FLAGS "-O2 -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-O2 -Wall -fPIC -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack -pipe ${CMAKE_CXX_FLAGS}")
endif ()

# force __FILE__ to show relative path of file, from source directory, as cmake project makes __FILE__ absolute directory
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILE__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"' -Wno-builtin-macro-redefined")

# compile libraries from following directories
# libgraph is compiled in any situation
add_subdirectory(${GE_SOURCE_DIR}/src/common/graph)
if(ENABLE_D)
# if MindSpore compiles in D mode, compile the following libraries
add_subdirectory(${GE_SOURCE_DIR}/src/ge/common)
add_subdirectory(${GE_SOURCE_DIR}/src/ge/ge_runtime)
elseif(GE_ONLY)
# standalone GraphEngine compiles all following libraries
add_subdirectory(${GE_SOURCE_DIR}/src/ge/common)
add_subdirectory(${GE_SOURCE_DIR}/src/ge/ge_runtime)
add_subdirectory(${GE_SOURCE_DIR}/src/ge/ge_local_engine)
add_subdirectory(${GE_SOURCE_DIR}/src/ge/graph/build/memory)
add_subdirectory(${GE_SOURCE_DIR}/src/ge/)
add_subdirectory(${GE_SOURCE_DIR}/src/ge/executor)
add_subdirectory(${GE_SOURCE_DIR}/src/ge/client)
add_subdirectory(${GE_SOURCE_DIR}/src/ge/plugin/engine)
endif()

if (ENABLE_GE_COV OR ENABLE_GE_UT OR ENABLE_GE_ST)
add_subdirectory(tests)
endif()


+ 201
- 0
LICENSE View File

@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS

APPENDIX: How to apply the Apache License to your work.

To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

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.

+ 2
- 0
NOTICE View File

@@ -0,0 +1,2 @@
MindSpore GraphEngine
Copyright 2019-2020 Huawei Technologies Co., Ltd

+ 107
- 0
README.md View File

@@ -0,0 +1,107 @@
GraphEngine(GE) is a sub-module of MindSpore connecting the front end and devices which was designed by the researches and engineers within Huawei Technologies Co.,Ltd. GE is implemented via C++. It takes the graph of front end as its input and a series of graph operations are carried out to adapt the graph to a certain form which can be effectively operated on devices. GE is specifically designed for an efficient operation on Ascend Chips. GE is automatically called without any exposure to the users. GE mainly consists of two parts, i.e. GE API and GE Core. The architecture diagram of GE is illustrated as follows

![GE_schema](docs/GE_Architecture.png)

- GE API

GE API is the interface between GE Core and front end which controls the initialization and finalization of GE Core and Sessions. It also provides the interfaces for graph adding and running.

- GE Core

GE Core acts as the core module of GE and is responsible for graph processing operations. It consist of six parts, i.e. graph preparation, graph partition, graph optimization, graph compilation, graph loading and graph execution. These six parts are performed in series and all together complete the complicated graph processing operations.

- Graph preparation

All the shapes of feature maps and variables in the graph are inferred in this stage for memory allocation later. Some aggregations of operators like allreduce are performed as well. Ascend Chips are heterogeneous chips including CPUs and vector calculation units, i.e. AICORE. Each operator in the graph is assigned to a certain operating cores according to the costs and supports. These two cores correspond to two different abstract engines in software.

- Graph partition

The whole graph is split into several sub-graphs based on the assigned engine in previous stage. Certain operators are added to the sub-graphs as the marks for graph edges. Such a partition enables an efficient optimization, compilation in next stages.

- Graph optimization

Different optimizer interfaces are called due to different engines that each sub-graph belongs to. To thoroughly utilize the calculation ability of the CUBE module in AICORE, A novel data layout format for faster hardware fetch is applied and the transition between normal 4D to this special format is performed in this stage. Such an operation guarantees less data handling between RAMs and CUBEs. Certain combination of operators is fused into a single big operator to further reduce the computation costs. This fusion is carried out in this stage as well.

- Graph compilation

This stage can be divided into two parts, i.e. resources allocation and graph compilation. Memory allocation is completed considering memory reuse strategy in resources allocation stage. According to the graph information, the queue, event, stream resources are allocated. Each operator is compiled to a task bound to a certain stream. Tasks on the same stream are performed in series and task on different streams can be executed in parallel. This stream partition is completed in this stage.

- Graph loading

According to the engine information, the operators of graph are assigned to different engines and in this stage, the graph is loaded on the devices for running.

- Graph execution

The graph is executed on devices efficiently in this stage and the corresponding outputs are returned to the hosts. For efficiency consideration, a sink mode is provided where the graph is executed several times with the last output returned. Such a mode effectively reduces the data handling between devices and hosts.

In training or evaluating process, the aforementioned graph processing operations are carried out automatically. All in all, GE is a linked up module between MindSpore front end and Ascend Chips aiming to adapt the graph designed by users to a more efficient form that can be directly executed on Ascend Chips.

- [Installation](#installation)
- [Community](#community)
- [Contributing](#contributing)
- [Release Notes](#release-notes)
- [License](#license)

# Installation

## Installing GraphEngine

GE is automatically installed and compiled once you finish installing MindSpore. There are three dynamic link libraries corresponding to GE.

## Installing Using the Source Code

You may also build GraphEngine from source.
To build GraphEngine, please make sure that you have access to an [Ascend 910](https://e.huawei.com/se/products/cloud-computing-dc/atlas/ascend-910) environment as compiling environment, and make sure that following software requirements are fulfilled.
> - GCC >= 7.3.0
> - CMake >= 3.14.0
> - Autoconf >= 2.64
> - Libtool >= 2.4.6
> - Automake >= 1.15.1

as your compiling environment and have GCC version >= 7.3.0 and CMake version >= 3.14.0 installed. It is necessary to be using an Ascend 910 environment to build GraphEngine.
The output of building GraphEngine is a set of shared libraries which can be linked with MindSpore, they are not meant to be used independently.

1. Download GraphEngine source code.

GraphEngine source code is available on [Gitee](https://gitee.com/mindspore/graphengine):
```shell
git clone https://gitee.com/mindspore/graphengine.git
cd graphengine
```
2. Run the following command in the root directory of the source code to compile GraphEngine:
To build with default options, simply:
```shell
bash build.sh
```
> - Before running the preceding command, ensure that the relevant paths have been added to the environment variable PATH.
> - In the build.sh script, the git clone command will be executed to obtain code from Gitee.com. Ensure that the network settings of Git are correct.
> - In the build.sh script, the default number of compilation threads is 8. If the compiler performance is poor, compilation errors may occur. You can add -j{Number of threads} in to bash command to reduce the number of threads. For example, `bash build.sh -j4`.

3. Access the output directory of the source code, obtain the generated GraphEngine libraries which can be linked with MindSpore for further installation/testing.

For more information on other options of building GraphEngine:
```shell
bash build.sh -h
```

If you wish to clean all outputs from last build and try again:
```shell
rm -rf build/ output/
bash build.sh
```

## Community

- [MindSpore Slack](https://join.slack.com/t/mindspore/shared_invite/enQtOTcwMTIxMDI3NjM0LTNkMWM2MzI5NjIyZWU5ZWQ5M2EwMTQ5MWNiYzMxOGM4OWFhZjI4M2E5OGI2YTg3ODU1ODE2Njg1MThiNWI3YmQ) - Ask questions and find answers.

## Contributing

Welcome contributions. See our [Contributor Wiki](https://gitee.com/mindspore/mindspore/blob/master/CONTRIBUTING.md) for more details.

## Release Notes

The release notes, see our [RELEASE](RELEASE.md).

## License

[Apache License 2.0](LICENSE)

+ 17
- 0
RELEASE.md View File

@@ -0,0 +1,17 @@
# Release 0.1.0-alpha

This is the initial release of GraphEngine(GE) which was designed by the researchers and engineers in Huawei Technologies Co.,Ltd. GE is implemented via C++ and acts as a powerful backing force for MindSpore. GE is a linked up module between MindSpore front end and Ascend Chips.

## Main features

- GE API
- GE provides an unified interface with the front end including graph management interfaces i.e., graph loading and graph execution, and GE core initiallization and finalization interfaces.

- Graph Processing
- Six parts of graph processing operations are executed within GE, i.e. graph preparation, graph partition, graph optimization, graph compilation, graph loading and graph execution.
- GE highly optimizes the graph defined by the front end to a form which can be effectively executed on Ascend Chips.
- GE supports several optimizations to reduce computation costs, e.g. operator fusion, parallel operation, data format transition.

- Debugging
- GE supports data dump and graph dump for debugging.
- GE provides profiling tools to thoroughly analyze the speed performances.

+ 460
- 0
Third_Party_Open_Source_Software_Notice View File

@@ -0,0 +1,460 @@
OPEN SOURCE SOFTWARE NOTICE

Please note we provide an open source software notice along with this product and/or this product firmware (in the following just “this product”). The open source software licenses are granted by the respective right holders. And the open source licenses prevail all other license information with regard to the respective open source software contained in the product, including but not limited to End User Software Licensing Agreement. This notice is provided on behalf of Huawei Technologies Co. Ltd. and any of its local subsidiaries which may have provided this product to you in your local country.

Warranty Disclaimer
THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.

Copyright Notice and License Texts

Software: Eigen 3.3.7
Copyright notice:
Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
Copyright (C) 2013 Christian Seiler <christian@iwakd.de>
Copyright (C) 2015 Eugene Brevdo <ebrevdo@gmail.com>
Copyright (C) 2014-2015 Benoit Steiner <benoit.steiner.goog@gmail.com>
Copyright (C) 2015 Navdeep Jaitly <ndjaitly@google.com>
Copyright (C) 2014 Eric Martin <eric@ericmart.in>
Copyright (C) 2015 Benoit Steiner <benoit.steiner.goog@gmail.com>
Copyright (C) 2016 Rasmus Munk Larsen <rmlarsen@google.com>
Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com>
Copyright (C) 2015 Jianwei Cui <thucjw@gmail.com>
Copyright (C) 2016 Eugene Brevdo <ebrevdo@gmail.com>
Copyright (C) 2015 Ke Yang <yangke@gmail.com>
Copyright (C) 2016 Mehdi Goli, Codeplay Software Ltd <eigen@codeplay.com>
Copyright (C) 2014 Navdeep Jaitly <ndjaitly@google.com>
Copyright (C) 2016 Igor Babuschkin <igor@babuschk.in>
Copyright (C) 2016 Dmitry Vyukov <dvyukov@google.com>
Copyright (C) EDF R&D, lun sep 30 14:23:30 CEST 2002
Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) EDF R&D, lun sep 30 14:23:31 CEST 2002
Copyright (C) 2008-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2008-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2009 Mark Borgerding mark a borgerding net
Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2013 Desire Nuentsa <desire.nuentsawakam@inria.fr>
Copyright (C) 2013 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2011 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2012 Desire NUENTSA WAKAM <desire.nuentsawakam@inria.fr>
Copyright (C) 2009 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2006-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) EDF R&D, lun sep 30 14:23:28 CEST 2002
Copyright (C) 2010 Manuel Yguel <manuel.yguel@gmail.com>
Copyright (C) 2009 Claire Maurice
Copyright (C) 2010,2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (c) 2011, Intel Corporation. All rights reserved.
Copyright (C) 2012-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2016 Tobias Wood <tobias@spinicist.org.uk>
Copyright (C) 2010 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2012 Alexey Korepanov <kaikaikai@yandex.ru>
Copyright (C) 2010 Vincent Lejeune
Copyright (C) 2010 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2017 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2009 Mathieu Gautier <mathieu.gautier@cea.fr>
Copyright (C) 2010 Hauke Heibel <hauke.heibel@gmail.com>
Copyright (C) 2009 Hauke Heibel <hauke.heibel@gmail.com>
Copyright (C) 2008-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) EDF R&D, mar déc 3 18:59:36 CET 2002
Copyright (C) EDF R&D, lun sep 30 14:23:17 CEST 2002
Copyright (C) EDF R&D, mar déc 3 18:59:35 CET 2002
Copyright (C) 2016 Konstantinos Margaritis <markos@freevec.org>
Copyright (C) 2007 Julien Pommier
Copyright (C) 2008-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2009 Keir Mierle <mierle@gmail.com>
Copyright (C) 2011 Timothy E. Holy <tim.holy@gmail.com >
Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com>
Copyright (C) 2012 Desire Nuentsa <desire.nuentsawakam@inria.fr>
Copyright (C) 2014 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2015 Tal Hadad <talhd@hotmail.com>
@copyright (c) 2009-2014 The University of Tennessee and The University of Tennessee Research Foundation.
@copyright (c) 2012-2016 Inria. All rights reserved.
@copyright (c) 2012-2014 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, Univ. Bordeaux. All rights reserved.
Copyright 2007-2009 Kitware, Inc.
Copyright 2012-2013 Inria
Copyright 2012-2013 Emmanuel Agullo
Copyright 2012-2013 Mathieu Faverge
Copyright 2012 Cedric Castagnede
Copyright 2013-2016 Florent Pruvost
Copyright 2016 Codeplay Software Ltd.
Copyright (c) 2006, 2007 Montel Laurent, <montel@kde.org>
Copyright (c) 2008, 2009 Gael Guennebaud, <g.gael@free.fr>
Copyright (c) 2009 Boudewijn Rempt <boud@valdyas.org>
@copyright (c) 2012-2014 Inria. All rights reserved.
Copyright 2013 Florent Pruvost
Copyright (c) 2010 Jitse Niesen, <jitse@maths.leeds.ac.uk>
Copyright (C) 2009 Benjamin Schindler <bschindler@inf.ethz.ch>
Copyright (C) 2016 Pedro Gonnet (pedro.gonnet@gmail.com)
Copyright (C) 2016 Benoit Steiner (benoit.steiner.goog@gmail.com)
Copyright (C) 2009 Thomas Capricelli <orzel@freehackers.org>
Copyright (C) 2012-2013 Desire Nuentsa <desire.nuentsawakam@inria.fr>
Copyright (C) 2012-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright Jorge More - Argonne National Laboratory
Copyright Burt Garbow - Argonne National Laboratory
Copyright Ken Hillstrom - Argonne National Laboratory
Copyright (C) 2009 Ilya Baran <ibaran@mit.edu>
Copyright (c) 2010, Intel Corp.
Copyright (C) 2009-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2013-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2013 Gauthier Brun <brun.gauthier@gmail.com>
Copyright (C) 2013 Nicolas Carre <nicolas.carre@ensimag.fr>
Copyright (C) 2013 Jean Ceccato <jean.ceccato@ensimag.fr>
Copyright (C) 2013 Pierre Zoppitelli <pierre.zoppitelli@ensimag.fr>
Copyright (C) 2013 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2014-2017 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2013-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2011-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsawakam@inria.fr>
Copyright (C) 2015 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2012 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (c) 1994 by Xerox Corporation. All rights reserved.
Copyright (C) 2001 Intel Corporation
Copyright (c) 2001 Intel Corporation.
Copyright (C) 2009 Gael Guennebaud <g.gael@free.fr>
Copyright (C) 2013 Christoph Hertzberg <chtz@informatik.uni-bremen.de>
Copyright (C) 2015 Eugene Brevdo <ebrevdo@google.com>
Copyright (C) 2016
Mehdi Goli Codeplay Software Ltd.
Ralph Potter Codeplay Software Ltd.
Luke Iwanski Codeplay Software Ltd.
Copyright (C) 2014 Jianwei Cui <thucjw@gmail.com>
Copyright (C) 2015 Vijay Vasudevan <vrv@google.com>
Copyright (C) 2015
Mehdi Goli Codeplay Software Ltd.
Ralph Potter Codeplay Software Ltd.
Luke Iwanski Codeplay Software Ltd.
Copyright (C) 2014 Navdeep Jaitly <ndjaitly@google.com and Benoit Steiner <benoit.steiner.goog@gmail.com>
Copyright (C) 2011 Gael Guennebaud <g.gael@free.fr>
Copyright (C) 2012 desire Nuentsa <desire.nuentsawakam@inria.fr
Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
Copyright (C) 2012 Kolja Brix <brix@igpm.rwth-aaachen.de>
Copyright (C) 2011 Kolja Brix <brix@igpm.rwth-aachen.de>
Copyright (C) 2011 Andreas Platen <andiplaten@gmx.de>
Copyright (C) 2012 Chen-Pang He <jdh8@ms63.hinet.net>
Copyright (C) 2009 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2009-2011 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2012, 2013 Chen-Pang He <jdh8@ms63.hinet.net>
Copyright (C) 2011 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2012 Giacomo Po <gpo@ucla.edu>
Copyright (C) 2008-2010 Gael Guennebaud <g.gael@free.fr>
Copyright (C) 2016 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2010-2011 Hauke Heibel <heibel@gmail.com>
Copyright (C) 2012 David Harmon <dharmon@gmail.com>
Copyright (C) 2007-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2007-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2008-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2009 Kenneth Riddile <kfriddile@yahoo.com>
Copyright (C) 2010 Thomas Capricelli <orzel@freehackers.org>
Copyright (C) 2013 Pavel Holoborodko <pavel@holoborodko.com>
Copyright (C) EDF R&D, lun sep 30 14:23:16 CEST 2002
Copyright (C) EDF R&D, mar déc 3 18:59:37 CET 2002
Copyright (C) 2006-2009 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2008-2010 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (c) 2008-2015 Pavel Holoborodko
Copyright (C) 20010-2011 Hauke Heibel <hauke.heibel@gmail.com>
Copyright (c) 2006, Montel Laurent, <montel@kde.org>
Copyright (c) 2007, Allen Winter, <winter@kde.org>
Copyright (c) 2007, Alexander Neundorf, <neundorf@kde.org>
Copyright (C) 2008 Guillaume Saupin <guillaume.saupin@cea.fr>
Copyright (C) 2008-2009 Guillaume Saupin <guillaume.saupin@cea.fr>
Copyright (C) 2009 Guillaume Saupin <guillaume.saupin@cea.fr>
Copyright (C) 2010-2016 Konstantinos Margaritis <markos@freevec.org>
Copyright (C) 2008-2016 Konstantinos Margaritis <markos@freevec.org>
Copyright (C) 2014 Benoit Steiner (benoit.steiner.goog@gmail.com)
Copyright (C) 2014 Pedro Gonnet (pedro.gonnet@gmail.com)
Copyright (c) Fabian Giesen, 2016
Copyright (C) 2010 Konstantinos Margaritis <markos@freevec.org>
Copyright (C) 2007 Michael Olbrich <michael.olbrich@gmx.net>
Copyright (C) 2011 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2011-2012 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2016 Rasmus Munk Larsen (rmlarsen@google.com)
Copyright (C) 2008-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2010-2013 Hauke Heibel <hauke.heibel@gmail.com>
Copyright (C) 2006-2008, 2010 Benoit Jacob <jacob.benoit.1@gmail.com>
Copyright (C) 2010-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2009 Ricard Marxer <email@ricardmarxer.com>
Copyright (C) 2009-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2010-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2009 Rohit Garg <rpg.314@gmail.com>
Copyright (c) 2006, Timothy A. Davis.
Copyright (c) 1998-2003 by the University of Florida.
Copyright (C) 2012 Désiré Nuentsa-Wakam <desire.nuentsawakam@inria.fr>
Copyright (C) 2008-2012 Gael Guennebaud <gael.guennebaud@inria.fr>
LDL Copyright (c) 2005 by Timothy A. Davis. All Rights Reserved.
Copyright (C) 2010 Daniel Lowengrub <lowdanie@gmail.com>
Copyright (C) EDF R&D, lun sep 30 14:23:20 CEST 2002
Copyright (C) EDF R&D, lun sep 30 14:23:19 CEST 2002
Copyright (C) 2009, 2010, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2011, 2013 Chen-Pang He <jdh8@ms63.hinet.net>
Copyright (C) 2009-2011, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2011, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2011 Chen-Pang He <jdh8@ms63.hinet.net>
Copyright (C) 2010, 2013 Jitse Niesen <jitse@maths.leeds.ac.uk>
Copyright (C) 2010-2014 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2012 The Android Open Source Project
(C) Desire NUENTSA WAKAM, INRIA
Copyright (C) EDF R&D, lun sep 30 14:23:18 CEST 2002
Copyright (C) 2012 Keir Mierle <mierle@gmail.com>
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
Copyright (C) EDF R&D, lun sep 30 14:23:23 CEST 2002
Copyright (C) EDF R&D, lun sep 30 14:23:24 CEST 2002
Copyright (C) EDF R&D, lun sep 30 14:23:27 CEST 2002
Copyright (C) 2007 Free Software Foundation, Inc. <http:fsf.org/>
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
Copyright (C) 2015 Benoit Jacob <benoitjacob@google.com>
Geometric Tools, LLC Copyright (c) 1998-2010
Copyright (C) EDF R&D, lun sep 30 14:23:15 CEST 2002
Copyright (C) 2002-2007 Yves Renard
Copyright (C) 2012, 2014 Kolja Brix <brix@igpm.rwth-aaachen.de>
Copyright (C) 1997-2001 Andrew Lumsdaine <lums@osl.iu.edu> Lie-Quan Lee <llee@osl.iu.edu>
Copyright (C) 2012 Desire NUENTSA WAKAM <desire.nuentsawakam@inria.fr
Copyright (C) 2015-2016 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2013 Hauke Heibel <hauke.heibel@gmail.com>
Copyright (C) 2010-2011 Jitse Niesen <jitse@maths.leeds.ac.uk>
Intel Copyright (C) ....
Copyright (C) 2010-2017 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 20013 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2008 Daniel Gomez Ferro <dgomezferro@gmail.com>
Copyright (C) 2013 Désiré Nuentsa-Wakam <desire.nuentsawakam@inria.fr>
Copyright (C) 2011-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 20015 Gael Guennebaud <gael.guennebaud@inria.fr>
Copyright (C) 2014-2015 Gael Guennebaud <gael.guennebaud@inria.fr>


License: Mozilla Public License (MPL) V2.0

Mozilla Public License
Version 2.0
1. Definitions
1.1. “Contributor”
means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software.
1.2. “Contributor Version”
means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor’s Contribution.
1.3. “Contribution”
means Covered Software of a particular Contributor.
1.4. “Covered Software”
means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof.
1.5. “Incompatible With Secondary Licenses”
means
that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or
that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License.
1.6. “Executable Form”
means any form of the work other than Source Code Form.
1.7. “Larger Work”
means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software.
1.8. “License”
means this document.
1.9. “Licensable”
means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License.
1.10. “Modifications”
means any of the following:
any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or
any new file in Source Code Form that contains any Covered Software.
1.11. “Patent Claims” of a Contributor
means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version.
1.12. “Secondary License”
means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses.
1.13. “Source Code Form”
means the form of the work preferred for making modifications.
1.14. “You” (or “Your”)
means an individual or a legal entity exercising rights under this License. For legal entities, “You” includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, “control” means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity.
2. License Grants and Conditions
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license:
under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and
under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor:
for any code that a Contributor has removed from Covered Software; or
for infringements caused by: (i) Your and any other third party’s modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or
under Patent Claims infringed by Covered Software in the absence of its Contributions.
This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1.
3. Responsibilities
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients’ rights in the Source Code Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and
You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients’ rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s).
3.4. Notices
You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction.
4. Inability to Comply Due to Statute or Regulation
If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it.
5. Termination
5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination.
6. Disclaimer of Warranty
Covered Software is provided under this License on an “as is” basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that the Covered Software is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of the Covered Software is with You. Should any Covered Software prove defective in any respect, You (not any Contributor) assume the cost of any necessary servicing, repair, or correction. This disclaimer of warranty constitutes an essential part of this License. No use of any Covered Software is authorized under this License except under this disclaimer.
7. Limitation of Liability
Under no circumstances and under no legal theory, whether tort (including negligence), contract, or otherwise, shall any Contributor, or anyone who distributes Covered Software as permitted above, be liable to You for any direct, indirect, special, incidental, or consequential damages of any character including, without limitation, damages for lost profits, loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses, even if such party shall have been informed of the possibility of such damages. This limitation of liability shall not apply to liability for death or personal injury resulting from such party’s negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
8. Litigation
Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party’s ability to bring cross-claims or counter-claims.
9. Miscellaneous
This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor.
10. Versions of the License
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - “Incompatible With Secondary Licenses” Notice
This Source Code Form is “Incompatible With Secondary Licenses”, as defined by the Mozilla Public License, v. 2.0.


Software: JSON for Modern C++ 3.6.1
Copyright notice:
Copyright 2015 Google Inc. All rights reserved.
Copyright 2018 Google Inc. All rights reserved.
Copyright 2016 Ismael Jimenez Martinez. All rights reserved.
Copyright 2017 Roman Lebedev. All rights reserved.
Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
Copyright (c) 2015 Max Woolf
Copyright 2014 The Authors
Copyright (c) 2016 Nicolas Seriot
Copyright (c) 2015-2017 Niels Lohmann.
Copyright (c) 2015-2017 Niels Lohmann
Copyright (c) 2013-2019 Niels Lohmann <http:nlohmann.me>.
Copyright (c) 2018 Vitaliy Manushkin <agri@akamo.info>.
Copyright (c) 2012, Erik Edlund <erik.edlund@32767.se>
Copyright (c) 2013-2019 Niels Lohmann
Copyright 2013-2019 [Niels Lohmann](http:nlohmann.me)
Copyright (c) 2009 Google Inc. All rights reserved.
Copyright (C) 2009 Google Inc.


License: MIT License
The MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


Software: google/protobuf 3.8.0
Copyright notice:
Copyright 2008, Google Inc.
Copyright 2008 Google Inc. All Rights Reserved.
Copyright [2007] Neal Norwitz
Portions Copyright [2007] Google Inc.
Copyright 2008 Google Inc. All rights reserved.
Copyright 2007 Google Inc. All Rights Reserved.
Copyright 2007, Google Inc.
Copyright 2013, Google Inc.
Copyright 2009, Google Inc.
Copyright 2006, Google Inc.
Copyright 2009 Google Inc. All rights reserved.
Copyright 2005, Google Inc.
Copyright 2008 Google Inc.
Copyright 2015, Google Inc.
Copyright (C) 1996-2015 Free Software Foundation, Inc.
Copyright (c) 2007-2010 Baptiste Lepilleur
Copyright 2007 Neal Norwitz
Copyright 2007 Google Inc.
Copyright 2008 Google Inc. All Rights Reserved.
Copyright 2014 Google Inc. All rights reserved.
Copyright 2015 Google Inc. All rights reserved.
Copyright (c) 2006, Google Inc.
Copyright 2012 Google Inc. All rights reserved.
Copyright 2005 Google Inc.
Copyright 2010 Google Inc. All Rights Reserved.
Copyright 2010, Google Inc.
Copyright 2005 Google Inc. All Rights Reserved.
Copyright 2009 Google Inc. All rights reserved.
Copyright 2009 Google Inc. All Rights Reserved.


License: BSD 3-Clause License
Copyright (c) <YEAR>, <OWNER>
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


Software: googletest 1.8.1
Copyright notice:
Copyright 2009, Google Inc.
Copyright 2008, Google Inc.
Copyright 2007 Google Inc.
Copyright 2007, Google Inc.
Copyright 2013, Google Inc.
Copyright 2015, Google Inc.
Copyright 2005, Google Inc.
Copyright 2008 Google Inc.
Copyright 2006, Google Inc.
Copyright 2009 Google Inc. All Rights Reserved.
Copyright 2013 Google Inc. All Rights Reserved.
Copyright 2017 Google Inc.
Copyright 2007 Neal Norwitz
Copyright 2008 Google Inc. All Rights Reserved.
Copyright 2009 Neal Norwitz All Rights Reserved.
Copyright 2003 Google Inc.
Copyright 2009 Google Inc.
Copyright 2008 Google Inc. All Rights Reserved.
Copyright [2007] Neal Norwitz
Portions Copyright [2007] Google Inc.
Copyright 2010 Google Inc. All Rights Reserved.
Copyright 2010, Google Inc.
Copyright 2005 Google Inc. All Rights Reserved.
Copyright 2018, Google Inc.
Copyright 2003, Google Inc.
Copyright 2009 Google Inc. All rights reserved.
Copyright 2015 Google Inc. All rights reserved.
Copyright 2009 Google Inc. All rights reserved.
Copyright 2018 Google LLC. All rights reserved.
Copyright 2018, Google LLC.


License: BSD 3-Clause License
Please see above.


Software: onnx 1.6.0
Copyright notice:
Copyright (c) ONNX Project Contributors.
Copyright (c) Facebook Inc. and Microsoft Corporation.


License: MIT License
Please see above.

+ 172
- 0
build.sh View File

@@ -0,0 +1,172 @@
#!/bin/bash
# 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.
# ============================================================================

set -e
BASEPATH=$(cd "$(dirname $0)"; pwd)
OUTPUT_PATH="${BASEPATH}/output"
export BUILD_PATH="${BASEPATH}/build/"

# print usage message
usage()
{
echo "Usage:"
echo "sh build.sh [-j[n]] [-A] [-h] [-v] [-s] [-t] [-u] [-c]"
echo ""
echo "Options:"
echo " -h Print usage"
echo " -u Only compile ut, not execute"
echo " -s Build st"
echo " -j[n] Set the number of threads used for building GraphEngine, default is 8"
echo " -t Build and execute ut"
echo " -c Build ut with coverage tag"
echo " -v Display build command"
echo "to be continued ..."
}

# parse and set optionss
checkopts()
{
VERBOSE=""
THREAD_NUM=8
ENABLE_GE_UT_ONLY_COMPILE="off"
ENABLE_GE_UT="off"
ENABLE_GE_ST="off"
ENABLE_GE_COV="off"
GE_ONLY="on"
# Process the options
while getopts 'ustchj:vA' opt
do
OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]')
case "${opt}" in
u)
ENABLE_GE_UT_ONLY_COMPILE="on"
ENABLE_GE_UT="on"
;;
s)
ENABLE_GE_ST="on"
;;
t)
ENABLE_GE_UT="on"
;;
c)
ENABLE_GE_COV="on"
;;
h)
usage
exit 0
;;
j)
THREAD_NUM=$OPTARG
;;
v)
VERBOSE="VERBOSE=1"
;;
A)
usage
;;
*)
echo "Undefined option: ${opt}"
usage
exit 1
esac
done
}
checkopts "$@"

mk_dir() {
local create_dir="$1" # the target to make

mkdir -pv "${create_dir}"
echo "created ${create_dir}"
}

# GraphEngine build start
echo "---------------- GraphEngine build start ----------------"

# create build path
build_graphengine()
{
echo "create build directory and build GraphEngine";
mk_dir "${BUILD_PATH}/graphengine"
cd "${BUILD_PATH}/graphengine"
CMAKE_ARGS="-DBUILD_PATH=$BUILD_PATH -DGE_ONLY=$GE_ONLY"

if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_COV=ON"
fi

if [[ "X$ENABLE_GE_UT" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_UT=ON"
fi


if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GE_ST=ON"
fi

echo "${CMAKE_ARGS}"
cmake ${CMAKE_ARGS} ../..
make ${VERBOSE} -j${THREAD_NUM}
echo "GraphEngine build success!"
}
g++ -v
build_graphengine
echo "---------------- GraphEngine build finished ----------------"
mk_dir ${OUTPUT_PATH}
cp -rf "${BUILD_PATH}/graphengine/"*.so "${OUTPUT_PATH}"
rm -rf "${OUTPUT_PATH}/"libproto*
rm -f ${OUTPUT_PATH}/libgmock*.so
rm -f ${OUTPUT_PATH}/libgtest*.so
rm -f ${OUTPUT_PATH}/lib*_stub.so

chmod -R 750 ${OUTPUT_PATH}
find ${OUTPUT_PATH} -name "*.so*" -print0 | xargs -0 chmod 500

echo "---------------- GraphEngine output package generated ----------------"

if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then
cp ${BUILD_PATH}/graphengine/tests/st/st_resnet50_train ${OUTPUT_PATH}
fi

if [[ "X$ENABLE_GE_UT" = "Xon" || "X$ENABLE_GE_COV" = "Xon" ]]; then
cp ${BUILD_PATH}/graphengine/tests/ut/common/graph/ut_libgraph ${OUTPUT_PATH}
cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_multiparts_utest ${OUTPUT_PATH}
cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_distinct_load_utest ${OUTPUT_PATH}
cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_others_utest ${OUTPUT_PATH}
cp ${BUILD_PATH}/graphengine/tests/ut/ge/ut_libge_kernel_utest ${OUTPUT_PATH}

if [[ "X${ENABLE_GE_UT_ONLY_COMPILE}" != "Xon" ]]; then
export LD_LIBRARY_PATH=${D_LINK_PATH}/x86_64/:${BUILD_PATH}/graphengine/:/usr/local/HiAI/driver/lib64:/usr/local/HiAI/runtime/lib64:${LD_LIBRARY_PATH}
echo ${LD_LIBRARY_PATH}
${OUTPUT_PATH}/ut_libgraph &&
${OUTPUT_PATH}/ut_libge_multiparts_utest &&
${OUTPUT_PATH}/ut_libge_distinct_load_utest &&
${OUTPUT_PATH}/ut_libge_others_utest &&
${OUTPUT_PATH}/ut_libge_kernel_utest
if [[ "$?" -ne 0 ]]; then
echo "!!! UT FAILED, PLEASE CHECK YOUR CHANGES !!!"
exit 1;
fi
fi

if [[ "X$ENABLE_GE_COV" = "Xon" ]]; then
echo "Generating coverage statistics, please wait..."
cd ${BASEPATH}
rm -rf ${BASEPATH}/cov
mkdir ${BASEPATH}/cov
gcovr -r ./ --exclude 'third_party' --exclude 'build' --exclude 'tests' --exclude 'prebuild' --exclude 'inc' --print-summary --html --html-details -d -o cov/index.html
fi
fi

+ 13
- 0
cmake/external_libs/eigen.cmake View File

@@ -0,0 +1,13 @@
set(Eigen3_CXXFLAGS "-D_FORTIFY_SOURCE=2 -O2")
set(Eigen3_CFLAGS "-D_FORTIFY_SOURCE=2 -O2")
set(Eigen3_NS "ge_")
graphengine_add_pkg(Eigen3
VER 3.3.7
URL https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.gz
MD5 9e30f67e8531477de4117506fe44669b
CMAKE_OPTION -DBUILD_TESTING=OFF)

find_package(Eigen3 3.3.7 REQUIRED ${GE_FIND_NO_DEFAULT_PATH})
set_property(TARGET Eigen3::Eigen PROPERTY IMPORTED_GLOBAL TRUE)
add_library(graphengine::eigen ALIAS Eigen3::Eigen)
include_directories(${EIGEN3_INCLUDE_DIRS})

+ 16
- 0
cmake/external_libs/gtest.cmake View File

@@ -0,0 +1,16 @@
set(ge_gtest_CXXFLAGS "-D_FORTIFY_SOURCE=2 -O2")
set(ge_gtest_CFLAGS "-D_FORTIFY_SOURCE=2 -O2")

graphengine_add_pkg(ge_gtest
VER 1.8.0
LIBS gtest gtest_main
URL https://github.com/google/googletest/archive/release-1.8.0.tar.gz
MD5 16877098823401d1bf2ed7891d7dce36
CMAKE_OPTION -DBUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=ON
-DCMAKE_MACOSX_RPATH=TRUE -Dgtest_disable_pthreads=ON)

add_library(graphengine::gtest ALIAS ge_gtest::gtest)
add_library(graphengine::gtest_main ALIAS ge_gtest::gtest_main)
include_directories(${ge_gtest_INC})
file(COPY ${ge_gtest_INC}/../lib/libgtest.so DESTINATION ${CMAKE_SOURCE_DIR}/build/graphengine)
file(COPY ${ge_gtest_INC}/../lib/libgtest_main.so DESTINATION ${CMAKE_SOURCE_DIR}/build/graphengine)

+ 9
- 0
cmake/external_libs/json.cmake View File

@@ -0,0 +1,9 @@
set(nlohmann_json_CXXFLAGS "-D_FORTIFY_SOURCE=2 -O2")
set(nlohmann_json_CFLAGS "-D_FORTIFY_SOURCE=2 -O2")
graphengine_add_pkg(ge_nlohmann_json
VER 3.6.1
HEAD_ONLY ./
URL https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip
MD5 0dc903888211db3a0f170304cd9f3a89)
include_directories(${ge_nlohmann_json_INC})
add_library(graphengine::json ALIAS ge_nlohmann_json)

+ 5
- 0
cmake/external_libs/onnx.cmake View File

@@ -0,0 +1,5 @@
graphengine_add_pkg(onnx
VER 1.6.0
HEAD_ONLY ./
URL https://github.com/onnx/onnx/releases/download/v1.6.0/onnx-1.6.0.tar.gz
MD5 512f2779d6215d4a36f366b6b9acdf1e)

+ 57
- 0
cmake/external_libs/protobuf.cmake View File

@@ -0,0 +1,57 @@
if (NOT TARGET protobuf::libprotobuf)
graphengine_add_pkg(protobuf
VER 3.8.0
HEAD_ONLY ./
URL https://github.com/protocolbuffers/protobuf/archive/v3.8.0.tar.gz
MD5 3d9e32700639618a4d2d342c99d4507a)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Disahble protobuf test")
set(protobuf_BUILD_SHARED_LIBS ON CACHE BOOL "Gen shared library")
set(_ms_tmp_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE " -Wall" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

set(PROTOBUF_CMAKE_FILE "${protobuf_DIRPATH}/cmake/libprotobuf.cmake" )
FILE(READ ${PROTOBUF_CMAKE_FILE} GE_MR_PROTOBUF_CMAKE)
STRING(REPLACE "VERSION \${protobuf_VERSION}" "VERSION 19" GE_MR_PROTOBUF_CMAKE_V19 "${GE_MR_PROTOBUF_CMAKE}" )
FILE(WRITE ${PROTOBUF_CMAKE_FILE} "${GE_MR_PROTOBUF_CMAKE_V19}")

add_subdirectory(${protobuf_DIRPATH}/cmake ${protobuf_DIRPATH}/build)
set(CMAKE_CXX_FLAGS ${_ms_tmp_CMAKE_CXX_FLAGS})
endif()

set(PROTOBUF_LIBRARY protobuf::libprotobuf)
include_directories(${protobuf_DIRPATH}/src)
add_library(ge_protobuf::protobuf ALIAS libprotobuf)

function(ge_protobuf_generate comp c_var h_var)
if(NOT ARGN)
message(SEND_ERROR "Error: ge_protobuf_generate() called without any proto files")
return()
endif()

set(${c_var})
set(${h_var})

foreach(file ${ARGN})
get_filename_component(abs_file ${file} ABSOLUTE)
get_filename_component(file_name ${file} NAME_WE)
get_filename_component(file_dir ${abs_file} PATH)

list(APPEND ${c_var} "${CMAKE_BINARY_DIR}/proto/${comp}/proto/${file_name}.pb.cc")
list(APPEND ${h_var} "${CMAKE_BINARY_DIR}/proto/${comp}/proto/${file_name}.pb.h")

add_custom_command(
OUTPUT "${CMAKE_BINARY_DIR}/proto/${comp}/proto/${file_name}.pb.cc"
"${CMAKE_BINARY_DIR}/proto/${comp}/proto/${file_name}.pb.h"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/proto/${comp}/proto"
COMMAND protobuf::protoc -I${file_dir} --cpp_out=${CMAKE_BINARY_DIR}/proto/${comp}/proto ${abs_file}
DEPENDS protobuf::protoc ${abs_file}
COMMENT "Running C++ protocol buffer compiler on ${file}" VERBATIM )
endforeach()

set_source_files_properties(${${c_var}} ${${h_var}} PROPERTIES GENERATED TRUE)
set(${c_var} ${${c_var}} PARENT_SCOPE)
set(${h_var} ${${h_var}} PARENT_SCOPE)

endfunction()

+ 349
- 0
cmake/ge_utils.cmake View File

@@ -0,0 +1,349 @@
include(FetchContent)
set(FETCHCONTENT_QUIET OFF)

function(graphengine_add_submodule_obj des_submodule_objs sub_dir submodule_name_obj)

add_subdirectory(${sub_dir})

if(NOT TARGET ${submodule_name_obj})
message(FATAL_ERROR "Can not find submodule '${submodule_name_obj}'. in ${CMAKE_CURRENT_LIST_FILE}")
endif()
if("$<TARGET_OBJECTS:${submodule_name_obj}>" IN_LIST ${des_submodule_objs})
message(FATAL_ERROR "submodule '${submodule_name_obj}' added more than once. in ${CMAKE_CURRENT_LIST_FILE}")
endif()

set(${des_submodule_objs} ${${des_submodule_objs}} $<TARGET_OBJECTS:${submodule_name_obj}> PARENT_SCOPE)

endfunction()

get_filename_component(_MS_LIB_CACHE ~/.mslib REALPATH)
if (NOT EXISTS ${_MS_LIB_CACHE})
file(MAKE_DIRECTORY ${_MS_LIB_CACHE})
endif ()
# set(FETCHCONTENT_BASE_DIR ${_MS_LIB_CACHE})
# set(CMAKE_PREFIX_PATH ${_MS_LIB_CACHE})
if (DEFINED ENV{MSLIBS_SERVER})
set(LOCAL_LIBS_SERVER $ENV{MSLIBS_SERVER})
message("LOCAL_LIBS_SERVER: ${LOCAL_LIBS_SERVER}")
endif ()
if(LOCAL_LIBS_SERVER)
if (NOT ENV{no_proxy})
set(ENV{no_proxy} "${LOCAL_LIBS_SERVER}")
else()
string(FIND $ENV{no_proxy} ${LOCAL_LIBS_SERVER} IP_POS)
if (${IP_POS} EQUAL -1)
set(ENV{no_proxy} "$ENV{no_proxy},${LOCAL_LIBS_SERVER}")
endif ()
endif ()
endif()

function(__download_pkg pkg_name pkg_url pkg_md5)

if(LOCAL_LIBS_SERVER)
get_filename_component(_URL_FILE_NAME ${pkg_url} NAME)
set(pkg_url "http://${LOCAL_LIBS_SERVER}:8081/libs/${pkg_name}/${_URL_FILE_NAME}" ${pkg_url})
endif()

FetchContent_Declare(
${pkg_name}
URL ${pkg_url}
URL_HASH MD5=${pkg_md5}
)
FetchContent_GetProperties(${pkg_name})
message("download: ${${pkg_name}_SOURCE_DIR} , ${pkg_name} , ${pkg_url}")
if(NOT ${pkg_name}_POPULATED)
FetchContent_Populate(${pkg_name})
set(${pkg_name}_SOURCE_DIR ${${pkg_name}_SOURCE_DIR} PARENT_SCOPE)
endif()

endfunction()

function(__download_pkg_with_git pkg_name pkg_url pkg_git_commit pkg_md5)

if(LOCAL_LIBS_SERVER)
set(pkg_url "http://${LOCAL_LIBS_SERVER}:8081/libs/${pkg_name}/${pkg_git_commit}")
FetchContent_Declare(
${pkg_name}
URL ${pkg_url}
URL_HASH MD5=${pkg_md5}
)
else()
FetchContent_Declare(
${pkg_name}
GIT_REPOSITORY ${pkg_url}
GIT_TAG ${pkg_git_commit})
endif()
FetchContent_GetProperties(${pkg_name})
message("download: ${${pkg_name}_SOURCE_DIR} , ${pkg_name} , ${pkg_url}")
if(NOT ${pkg_name}_POPULATED)
FetchContent_Populate(${pkg_name})
set(${pkg_name}_SOURCE_DIR ${${pkg_name}_SOURCE_DIR} PARENT_SCOPE)
endif()

endfunction()


function(__find_pkg_then_add_target pkg_name pkg_exe)

unset(${pkg_name}_LIBS)

message("_FIND:${${pkg_name}_BASE_DIR}")

if(pkg_exe)
find_program(${pkg_exe}_EXE ${pkg_exe} PATHS ${${pkg_name}_BASE_DIR}/bin NO_DEFAULT_PATH)
if(NOT ${pkg_exe}_EXE)
return()
endif()
add_executable(${pkg_name}::${pkg_exe} IMPORTED GLOBAL)
set_target_properties(${pkg_name}::${pkg_exe} PROPERTIES
IMPORTED_LOCATION ${${pkg_exe}_EXE}
)
message("found ${${pkg_exe}_EXE}")
endif()

foreach(_LIB_NAME ${ARGN})
set(_LIB_SEARCH_NAME ${_LIB_NAME})
set(_LIB_TYPE SHARED)
if (${pkg_name}_USE_STATIC_LIBS)
set(_LIB_SEARCH_NAME "${CMAKE_STATIC_LIBRARY_PREFIX}${_LIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}")
set(_LIB_TYPE STATIC)
endif ()
set(${_LIB_NAME}_LIB ${_LIB_NAME}_LIB-NOTFOUND)
find_library(${_LIB_NAME}_LIB ${_LIB_SEARCH_NAME} PATHS ${${pkg_name}_BASE_DIR}/lib NO_DEFAULT_PATH)
if(NOT ${_LIB_NAME}_LIB)
return()
endif()
add_library(${pkg_name}::${_LIB_NAME} ${_LIB_TYPE} IMPORTED GLOBAL)
set_target_properties(${pkg_name}::${_LIB_NAME} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${${pkg_name}_BASE_DIR}/include"
IMPORTED_LOCATION ${${_LIB_NAME}_LIB}
)
list(APPEND ${pkg_name}_LIBS ${pkg_name}::${_LIB_NAME})
message("found ${${_LIB_NAME}_LIB}")
STRING( REGEX REPLACE "(.+)/(.+)" "\\1" LIBPATH ${${_LIB_NAME}_LIB})
set(${pkg_name}_LIBPATH ${LIBPATH} CACHE STRING INTERNAL)
endforeach(_LIB_NAME)

set(${pkg_name}_LIBS ${${pkg_name}_LIBS} PARENT_SCOPE)
endfunction()

function(__exec_cmd)
set(options )
set(oneValueArgs WORKING_DIRECTORY)
set(multiValueArgs COMMAND)

cmake_parse_arguments(EXEC "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

execute_process(COMMAND ${EXEC_COMMAND}
WORKING_DIRECTORY ${EXEC_WORKING_DIRECTORY}
RESULT_VARIABLE RESULT)
if(NOT RESULT EQUAL "0")
message(FATAL_ERROR "error! when ${EXEC_COMMAND} in ${EXEC_WORKING_DIRECTORY}")
endif()
endfunction()

function(__check_patches pkg_patches)
# check patches
if (PKG_PATCHES)
file(TOUCH ${_MS_LIB_CACHE}/${pkg_name}_patch.md5)
file(READ ${_MS_LIB_CACHE}/${pkg_name}_patch.md5 ${pkg_name}_PATCHES_MD5)

message("patches md5:${${pkg_name}_PATCHES_MD5}")

set(${pkg_name}_PATCHES_NEW_MD5 )
foreach(_PATCH ${PKG_PATCHES})
file(MD5 ${_PATCH} _PF_MD5)
set(${pkg_name}_PATCHES_NEW_MD5 "${${pkg_name}_PATCHES_NEW_MD5},${_PF_MD5}")
endforeach(_PATCH)

if (NOT ${pkg_name}_PATCHES_MD5 STREQUAL ${pkg_name}_PATCHES_NEW_MD5)
set(${pkg_name}_PATCHES ${PKG_PATCHES})
file(REMOVE_RECURSE "${_MS_LIB_CACHE}/${pkg_name}-subbuild")
file(WRITE ${_MS_LIB_CACHE}/${pkg_name}_patch.md5 ${${pkg_name}_PATCHES_NEW_MD5})
message("patches changed : ${${pkg_name}_PATCHES_NEW_MD5}")
endif ()
endif ()
endfunction()

set(GE_FIND_NO_DEFAULT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH
NO_CMAKE_BUILDS_PATH NO_CMAKE_PACKAGE_REGISTRY NO_CMAKE_SYSTEM_PATH
NO_CMAKE_SYSTEM_PACKAGE_REGISTRY)
set(GE_FIND_NO_DEFAULT_PATH ${GE_FIND_NO_DEFAULT_PATH} PARENT_SCOPE)

function(graphengine_add_pkg pkg_name )
set(options )
set(oneValueArgs URL MD5 GIT_REPOSITORY GIT_TAG VER EXE DIR HEAD_ONLY)
set(multiValueArgs CMAKE_OPTION LIBS PRE_CONFIGURE_COMMAND CONFIGURE_COMMAND BUILD_OPTION INSTALL_INCS INSTALL_LIBS PATCHES)
cmake_parse_arguments(PKG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

set(__FIND_PKG_NAME ${pkg_name})
string(TOLOWER ${pkg_name} pkg_name)
message("pkg name:${__FIND_PKG_NAME},${pkg_name}")

set(${pkg_name}_PATCHES_HASH )
foreach(_PATCH ${PKG_PATCHES})
file(MD5 ${_PATCH} _PF_MD5)
set(${pkg_name}_PATCHES_HASH "${${pkg_name}_PATCHES_HASH},${_PF_MD5}")
endforeach(_PATCH)

# check options
set(${pkg_name}_CONFIG_TXT
"${CMAKE_CXX_COMPILER_VERSION}-${CMAKE_C_COMPILER_VERSION}
${ARGN} - ${${pkg_name}_USE_STATIC_LIBS}- ${${pkg_name}_PATCHES_HASH}
${${pkg_name}_CXXFLAGS}--${${pkg_name}_CFLAGS}--${${pkg_name}_LDFLAGS}")
string(REPLACE ";" "-" ${pkg_name}_CONFIG_TXT ${${pkg_name}_CONFIG_TXT})
string(MD5 ${pkg_name}_CONFIG_HASH ${${pkg_name}_CONFIG_TXT})

message("${pkg_name} config hash: ${${pkg_name}_CONFIG_HASH}")

set(${pkg_name}_BASE_DIR ${_MS_LIB_CACHE}/${pkg_name}_${${pkg_name}_CONFIG_HASH})
set(${pkg_name}_DIRPATH ${${pkg_name}_BASE_DIR} CACHE STRING INTERNAL)

if(EXISTS ${${pkg_name}_BASE_DIR}/options.txt AND PKG_HEAD_ONLY)
set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/${PKG_HEAD_ONLY} PARENT_SCOPE)
add_library(${pkg_name} INTERFACE)
target_include_directories(${pkg_name} INTERFACE ${${pkg_name}_INC})
return()
endif ()

if(NOT PKG_EXE)
set(PKG_EXE 0)
endif()

set(${__FIND_PKG_NAME}_ROOT ${${pkg_name}_BASE_DIR})
set(${__FIND_PKG_NAME}_ROOT ${${pkg_name}_BASE_DIR} PARENT_SCOPE)

if (PKG_LIBS)
__find_pkg_then_add_target(${pkg_name} ${PKG_EXE} ${PKG_LIBS})
if(${pkg_name}_LIBS)
set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/include PARENT_SCOPE)
message("Found libs: ${${pkg_name}_LIBS}")
return()
endif()
elseif(NOT PKG_HEAD_ONLY)
find_package(${__FIND_PKG_NAME} ${PKG_VER} NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH)
if (${__FIND_PKG_NAME}_FOUND)
set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/include PARENT_SCOPE)
message("Found pkg: ${__FIND_PKG_NAME}")
return()
endif ()
endif ()

if (NOT PKG_DIR)
if (PKG_GIT_REPOSITORY)
__download_pkg_with_git(${pkg_name} ${PKG_GIT_REPOSITORY} ${PKG_GIT_TAG} ${PKG_MD5})
else()
__download_pkg(${pkg_name} ${PKG_URL} ${PKG_MD5})
endif()
else()
set(${pkg_name}_SOURCE_DIR ${PKG_DIR})
endif ()
file(WRITE ${${pkg_name}_BASE_DIR}/options.txt ${${pkg_name}_CONFIG_TXT})
message("${pkg_name}_SOURCE_DIR : ${${pkg_name}_SOURCE_DIR}")

foreach(_PATCH_FILE ${PKG_PATCHES})
message("patching ${${pkg_name}_SOURCE_DIR} -p1 < ${_PATCH_FILE}")
execute_process(COMMAND patch -p1 INPUT_FILE ${_PATCH_FILE}
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR}
RESULT_VARIABLE Result)
if(NOT Result EQUAL "0")
message(FATAL_ERROR "Failed patch: ${_PATCH_FILE}")
endif()
endforeach(_PATCH_FILE)

file(LOCK ${${pkg_name}_BASE_DIR} DIRECTORY GUARD FUNCTION RESULT_VARIABLE ${pkg_name}_LOCK_RET TIMEOUT 600)
if(NOT ${pkg_name}_LOCK_RET EQUAL "0")
message(FATAL_ERROR "error! when try lock ${${pkg_name}_BASE_DIR} : ${${pkg_name}_LOCK_RET}")
endif()

if(${pkg_name}_SOURCE_DIR)
if (PKG_HEAD_ONLY)
file(GLOB ${pkg_name}_SOURCE_SUBDIRS ${${pkg_name}_SOURCE_DIR}/*)
file(COPY ${${pkg_name}_SOURCE_SUBDIRS} DESTINATION ${${pkg_name}_BASE_DIR})
set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/${PKG_HEAD_ONLY} PARENT_SCOPE)
add_library(${pkg_name} INTERFACE)
target_include_directories(${pkg_name} INTERFACE ${${pkg_name}_INC})

elseif (PKG_CMAKE_OPTION)
# in cmake
file(MAKE_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build)
if (${pkg_name}_CFLAGS)
set(${pkg_name}_CMAKE_CFLAGS "-DCMAKE_C_FLAGS=${${pkg_name}_CFLAGS}")
endif ()
if (${pkg_name}_CXXFLAGS)
set(${pkg_name}_CMAKE_CXXFLAGS "-DCMAKE_CXX_FLAGS=${${pkg_name}_CXXFLAGS}")
endif ()

if (${pkg_name}_LDFLAGS)
if (${pkg_name}_USE_STATIC_LIBS)
#set(${pkg_name}_CMAKE_LDFLAGS "-DCMAKE_STATIC_LINKER_FLAGS=${${pkg_name}_LDFLAGS}")
else()
set(${pkg_name}_CMAKE_LDFLAGS "-DCMAKE_SHARED_LINKER_FLAGS=${${pkg_name}_LDFLAGS}")
endif ()
endif ()

__exec_cmd(COMMAND ${CMAKE_COMMAND} ${PKG_CMAKE_OPTION} -G ${CMAKE_GENERATOR}
${${pkg_name}_CMAKE_CFLAGS} ${${pkg_name}_CMAKE_CXXFLAGS} ${${pkg_name}_CMAKE_LDFLAGS}
-DCMAKE_INSTALL_PREFIX=${${pkg_name}_BASE_DIR} ..
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build)

__exec_cmd(COMMAND ${CMAKE_COMMAND} --build . --target install -- -j8
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR}/_build)

else()
if (${pkg_name}_CFLAGS)
set(${pkg_name}_MAKE_CFLAGS "CFLAGS=${${pkg_name}_CFLAGS}")
endif ()
if (${pkg_name}_CXXFLAGS)
set(${pkg_name}_MAKE_CXXFLAGS "CXXFLAGS=${${pkg_name}_CXXFLAGS}")
endif ()
if (${pkg_name}_LDFLAGS)
set(${pkg_name}_MAKE_LDFLAGS "LDFLAGS=${${pkg_name}_LDFLAGS}")
endif ()
# in configure && make
if (PKG_PRE_CONFIGURE_COMMAND)
__exec_cmd(COMMAND ${PKG_PRE_CONFIGURE_COMMAND}
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR})
endif ()

if (PKG_CONFIGURE_COMMAND)
__exec_cmd(COMMAND ${PKG_CONFIGURE_COMMAND}
${${pkg_name}_MAKE_CFLAGS} ${${pkg_name}_MAKE_CXXFLAGS} ${${pkg_name}_MAKE_LDFLAGS}
--prefix=${${pkg_name}_BASE_DIR}
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR})
endif ()
set(${pkg_name}_BUILD_OPTION ${PKG_BUILD_OPTION})
if (NOT PKG_CONFIGURE_COMMAND)
set(${pkg_name}_BUILD_OPTION ${${pkg_name}_BUILD_OPTION}
${${pkg_name}_MAKE_CFLAGS} ${${pkg_name}_MAKE_CXXFLAGS} ${${pkg_name}_MAKE_LDFLAGS})
endif ()
# build
__exec_cmd(COMMAND ${CMAKE_MAKE_PROGRAM} ${${pkg_name}_BUILD_OPTION} -j8
WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR})

if (PKG_INSTALL_INCS OR PKG_INSTALL_LIBS)
file(GLOB ${pkg_name}_INSTALL_INCS ${${pkg_name}_SOURCE_DIR}/${PKG_INSTALL_INCS})
file(GLOB ${pkg_name}_INSTALL_LIBS ${${pkg_name}_SOURCE_DIR}/${PKG_INSTALL_LIBS})
file(COPY ${${pkg_name}_INSTALL_INCS} DESTINATION ${${pkg_name}_BASE_DIR}/include)
file(COPY ${${pkg_name}_INSTALL_LIBS} DESTINATION ${${pkg_name}_BASE_DIR}/lib)
else()
__exec_cmd(COMMAND ${CMAKE_MAKE_PROGRAM} install WORKING_DIRECTORY ${${pkg_name}_SOURCE_DIR})
endif ()
endif ()
endif()

if (PKG_LIBS)
__find_pkg_then_add_target(${pkg_name} ${PKG_EXE} ${PKG_LIBS})
set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/include PARENT_SCOPE)
if(NOT ${pkg_name}_LIBS)
message(FATAL_ERROR "Can not find pkg: ${pkg_name}")
endif()
else()
find_package(${__FIND_PKG_NAME} ${PKG_VER} QUIET)
if (${__FIND_PKG_NAME}_FOUND)
set(${pkg_name}_INC ${${pkg_name}_BASE_DIR}/include PARENT_SCOPE)
message("Found pkg: ${${__FIND_PKG_NAME}_LIBRARIES}")
return()
endif ()
endif ()
endfunction()

BIN
docs/GE_Architecture.png View File

Before After
Width: 940  |  Height: 532  |  Size: 30 kB

+ 3
- 0
docs/README.md View File

@@ -0,0 +1,3 @@
# GraphEngine Documentation

The GraphEngine documentation is in the [MindSpore Docs](https://gitee.com/mindspore/docs) repository.

+ 121
- 0
inc/common/blocking_queue.h View File

@@ -0,0 +1,121 @@
/**
* 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 INC_COMMON_BLOCKING_QUEUE_H_
#define INC_COMMON_BLOCKING_QUEUE_H_

#include <stdint.h>

#include <condition_variable>
#include <list>
#include <mutex>

static const int kDefaultMaxQueueSize = 2048;

template <typename T>
class BlockingQueue {
public:
explicit BlockingQueue(uint32_t max_size = kDefaultMaxQueueSize) : max_size_(max_size), is_stoped_(false) {}

~BlockingQueue() {}

bool Pop(T &item) {
std::unique_lock<std::mutex> lock(mutex_);

while (queue_.empty() && !is_stoped_) {
empty_cond_.wait(lock);
}

if (is_stoped_) {
return false;
}

item = queue_.front();
queue_.pop_front();

full_cond_.notify_one();

return true;
}

bool Push(const T &item, bool is_wait = true) {
std::unique_lock<std::mutex> lock(mutex_);

while (queue_.size() >= max_size_ && !is_stoped_) {
if (!is_wait) {
return false;
}
full_cond_.wait(lock);
}

if (is_stoped_) {
return false;
}

queue_.push_back(item);

empty_cond_.notify_one();

return true;
}

void Stop() {
{
std::unique_lock<std::mutex> lock(mutex_);
is_stoped_ = true;
}

full_cond_.notify_all();
empty_cond_.notify_all();
}

void Restart() {
std::unique_lock<std::mutex> lock(mutex_);
is_stoped_ = false;
}

// if the queue stop , the function to release the unprocessed items will be call
std::list<T> GetRemainItems() {
std::unique_lock<std::mutex> lock(mutex_);

if (!is_stoped_) {
return std::list<T>();
}

return queue_;
}

bool IsFull() {
std::unique_lock<std::mutex> lock(mutex_);
return queue_.size() >= max_size_;
}

void Clear() {
std::unique_lock<std::mutex> lock(mutex_);
queue_.clear();
}

private:
std::list<T> queue_;
std::mutex mutex_;
std::condition_variable empty_cond_;
std::condition_variable full_cond_;
uint32_t max_size_;

bool is_stoped_;
};

#endif // INC_COMMON_BLOCKING_QUEUE_H_

+ 104
- 0
inc/common/dynamic_aipp.h View File

@@ -0,0 +1,104 @@
/**
* 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 INC_COMMON_DYNAMIC_AIPP_H_
#define INC_COMMON_DYNAMIC_AIPP_H_

#include <stdint.h>

///
/// @ingroup dnn
/// @brief struct define of dynamic aipp batch parameter.
///
typedef struct tagAippDynamicBatchPara {
int8_t cropSwitch; // crop switch
int8_t scfSwitch; // resize switch
int8_t paddingSwitch; // 0: unable padding
// 1: padding config value,sfr_filling_hblank_ch0 ~ sfr_filling_hblank_ch2
// 2: padding source picture data, single row/collumn copy
// 3: padding source picture data, block copy
// 4: padding source picture data, mirror copy
int8_t rotateSwitch; // rotate switch,0: non-ratate,
// 1: ratate 90° clockwise,2: ratate 180° clockwise,3: ratate 270° clockwise
int8_t reserve[4];
int32_t cropStartPosW; // the start horizontal position of cropping
int32_t cropStartPosH; // the start vertical position of cropping
int32_t cropSizeW; // crop width
int32_t cropSizeH; // crop height

int32_t scfInputSizeW; // input width of scf
int32_t scfInputSizeH; // input height of scf
int32_t scfOutputSizeW; // output width of scf
int32_t scfOutputSizeH; // output height of scf

int32_t paddingSizeTop; // top padding size
int32_t paddingSizeBottom; // bottom padding size
int32_t paddingSizeLeft; // left padding size
int32_t paddingSizeRight; // right padding size

int16_t dtcPixelMeanChn0; // mean value of channel 0
int16_t dtcPixelMeanChn1; // mean value of channel 1
int16_t dtcPixelMeanChn2; // mean value of channel 2
int16_t dtcPixelMeanChn3; // mean value of channel 3

uint16_t dtcPixelMinChn0; // min value of channel 0
uint16_t dtcPixelMinChn1; // min value of channel 1
uint16_t dtcPixelMinChn2; // min value of channel 2
uint16_t dtcPixelMinChn3; // min value of channel 3
uint16_t dtcPixelVarReciChn0; // sfr_dtc_pixel_variance_reci_ch0
uint16_t dtcPixelVarReciChn1; // sfr_dtc_pixel_variance_reci_ch1
uint16_t dtcPixelVarReciChn2; // sfr_dtc_pixel_variance_reci_ch2
uint16_t dtcPixelVarReciChn3; // sfr_dtc_pixel_variance_reci_ch3

int8_t reserve1[16]; // 32B assign, for ub copy
} kAippDynamicBatchPara;

///
/// @ingroup dnn
/// @brief struct definition of dynamic aipp parameter. lite:64+96*batchNum byte ; tiny:64+64*batchNum byte
///
typedef struct tagAippDynamicPara {
uint8_t inputFormat; // input format:YUV420SP_U8/XRGB8888_U8/RGB888_U8
int8_t cscSwitch; // csc switch
int8_t rbuvSwapSwitch; // rb/ub swap switch
int8_t axSwapSwitch; // RGBA->ARGB, YUVA->AYUV swap switch
int8_t batchNum; // batch parameter number
int8_t reserve1[3];
int32_t srcImageSizeW; // source image width
int32_t srcImageSizeH; // source image height
int16_t cscMatrixR0C0; // csc_matrix_r0_c0
int16_t cscMatrixR0C1; // csc_matrix_r0_c1
int16_t cscMatrixR0C2; // csc_matrix_r0_c2
int16_t cscMatrixR1C0; // csc_matrix_r1_c0
int16_t cscMatrixR1C1; // csc_matrix_r1_c1
int16_t cscMatrixR1C2; // csc_matrix_r1_c2
int16_t cscMatrixR2C0; // csc_matrix_r2_c0
int16_t cscMatrixR2C1; // csc_matrix_r2_c1
int16_t cscMatrixR2C2; // csc_matrix_r2_c2
int16_t reserve2[3];
uint8_t cscOutputBiasR0; // output Bias for RGB to YUV, element of row 0, unsigned number
uint8_t cscOutputBiasR1; // output Bias for RGB to YUV, element of row 1, unsigned number
uint8_t cscOutputBiasR2; // output Bias for RGB to YUV, element of row 2, unsigned number
uint8_t cscInputBiasR0; // input Bias for YUV to RGB, element of row 0, unsigned number
uint8_t cscInputBiasR1; // input Bias for YUV to RGB, element of row 1, unsigned number
uint8_t cscInputBiasR2; // input Bias for YUV to RGB, element of row 2, unsigned number
uint8_t reserve3[2];
int8_t reserve4[16]; // 32B assign, for ub copy

kAippDynamicBatchPara aippBatchPara; // allow transfer several batch para.
} kAippDynamicPara;

#endif // INC_COMMON_DYNAMIC_AIPP_H_

+ 94
- 0
inc/common/npu_error_define.h View File

@@ -0,0 +1,94 @@
/**
* 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 INC_COMMON_NPU_ERROR_DEFINE_H_
#define INC_COMMON_NPU_ERROR_DEFINE_H_

typedef enum tagHiAiNpuLocal {
HIAI_HOST = 1,
HIAI_DEVICE = 2,
} HiAiNpuLocal;

typedef enum tagHiAiNpuCodeType {
ERROR_CODE = 1,
EXCEPTION_CODE = 2,
} HiAiNpuCodeType;

typedef enum tagHiAiNpuErrLevel {
NONE_LEVEL = 0,
SUGGESTION_LEVEL = 1,
NORMAL_LEVEL = 2,
SERIOUS_LEVEL = 3,
CRITICAL_ERROR = 4,
} HiAiNpuErrLevel;

typedef enum tagHiAiNpuModuleId {
HIAI_DRIVER = 1,
HIAI_CTRLCPU = 2,
HIAI_TS = 3,
HIAI_RUNTIME = 4,
HIAI_AICPU = 5,
HIAI_CCE = 6,
HIAI_TVM = 7,
HIAI_FRAMEWORK = 8,
HiAI_ENGINE = 9,
HIAI_DVPP = 10,
HIAI_AIPP = 11,
HIAI_LOWPOWER = 12,
HIAI_MDC = 13,
HIAI_COMPILE = 14,
HIAI_TOOLCHIAN = 15,
HIAI_ALG = 16,
HIAI_PROFILING = 17,
HIAI_HCCL = 18,
HIAI_SIMULATION = 19,
HIAI_BIOS = 20,
HIAI_SEC = 21,
HIAI_TINY = 22,
HIAI_DP = 23,
} HiAiNpuModuleId;

// bit 31-bit30 to be hiai local
#define HIAI_NPULOCAL_MASK 0xC0000000
#define SHIFT_LOCAL_MASK 30
#define HIAI_NPULOCAL_VAL_MASK 0x3
// bit 29 -bit28 to be hiai aicpu code type
#define HIAI_CODE_TYPE_MASK 0x30000000
#define SHIFT_CODE_MASK 28
#define HIAI_CODE_TYPE_VAL_MASK 0x3
// bit 27 -bit25 to be hiai error level
#define HIAI_ERROR_LEVEL_MASK 0x0E000000
#define SHIFT_ERROR_LVL_MASK 25
#define HIAI_ERROR_LEVEL_VAL_MASK 0x7
// bit 24 -bit17 to be hiai mod
#define HIAI_MODE_ID_MASK 0x01FE0000
#define SHIFT_MODE_MASK 17
#define HIAI_MODE_ID_VAL_MASK 0xFF

#define HIAI_NPU_LOC_BIT(a) \
(HIAI_NPULOCAL_MASK & ((unsigned int)((HiAiNpuLocal)(a)) & HIAI_NPULOCAL_VAL_MASK) << SHIFT_LOCAL_MASK)
#define HIAI_NPU_CODE_TYPE_BIT(a) \
(HIAI_CODE_TYPE_MASK & ((unsigned int)((HiAiNpuCodeType)(a)) & HIAI_CODE_TYPE_VAL_MASK) << SHIFT_CODE_MASK)
#define HIAI_NPU_ERR_LEV_BIT(a) \
(HIAI_ERROR_LEVEL_MASK & ((unsigned int)((HiAiNpuErrLevel)(a)) & HIAI_ERROR_LEVEL_VAL_MASK) << SHIFT_ERROR_LVL_MASK)
#define HIAI_NPU_MOD_ID_BIT(a) \
(HIAI_MODE_ID_MASK & ((unsigned int)((HiAiNpuModuleId)(a)) & HIAI_MODE_ID_VAL_MASK) << SHIFT_MODE_MASK)

#define HIAI_NPU_ERR_CODE_HEAD(npuLocal, codeType, errLevel, moduleId) \
(HIAI_NPU_LOC_BIT(npuLocal) + HIAI_NPU_CODE_TYPE_BIT(codeType) + HIAI_NPU_ERR_LEV_BIT(errLevel) + \
HIAI_NPU_MOD_ID_BIT(moduleId))

#endif // INC_COMMON_NPU_ERROR_DEFINE_H_

+ 55
- 0
inc/common/opskernel/ge_task_info.h View File

@@ -0,0 +1,55 @@
/**
* 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 INC_COMMON_OPSKERNEL_GE_TASK_INFO_H_
#define INC_COMMON_OPSKERNEL_GE_TASK_INFO_H_

#include <runtime/rt.h>
#include <stdint.h>

#include <string>
#include <vector>

using std::string;
namespace ge {
// DAVINCI_TRAIN/DAVINCI_CLOUD is not needed when GETaskKernelHcclInfo needed
struct GETaskKernelHcclInfo {
string hccl_type;
void *inputDataAddr;
void *outputDataAddr;
void *workSpaceAddr;
int32_t count;
int32_t dataType;
int32_t opType;
int64_t rootId;
uint64_t workSpaceMemSize;
std::vector<rtStream_t> hcclStreamList;
};

struct GETaskInfo {
uint32_t id;
uint16_t type;
uint32_t streamID;
void *stream; // rtKernelLaunch input argument
void *event;
void *privateDef;
uint32_t privateDefLen;
void *opsKernelStorePtr;

GETaskKernelHcclInfo kernelHcclInfo;
};
} // namespace ge
#endif // INC_COMMON_OPSKERNEL_GE_TASK_INFO_H_

+ 87
- 0
inc/common/opskernel/ops_kernel_info_store.h View File

@@ -0,0 +1,87 @@
/**
* 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 INC_COMMON_OPSKERNEL_OPS_KERNEL_INFO_STORE_H_
#define INC_COMMON_OPSKERNEL_OPS_KERNEL_INFO_STORE_H_

#include <iostream>
#include <map>
#include <string>
#include <vector>

#include "./ge_task_info.h"
#include "./ops_kernel_info_types.h"
#include "cce/aicpu_engine_struct.h"
#include "cce/fwk_adpt_struct.h"
#include "common/ge_inner_error_codes.h"
#include "graph/node.h"
#include "proto/task.pb.h"

using std::map;
using std::string;
using std::to_string;
using std::vector;

namespace ge {
class OpDesc;

class OpsKernelInfoStore {
public:
OpsKernelInfoStore() {}

virtual ~OpsKernelInfoStore() {}

// initialize opsKernelInfoStore
virtual Status Initialize(const map<string, string> &options) = 0;

// finalize opsKernelInfoStore
virtual Status Finalize() = 0;

virtual Status CreateSession(const std::map<std::string, std::string> &session_options) { return SUCCESS; }

virtual Status DestroySession(const std::map<std::string, std::string> &session_options) { return SUCCESS; }

// get all opsKernelInfo
virtual void GetAllOpsKernelInfo(map<string, OpInfo> &infos) const = 0;

// check whether opsKernelInfoStore is supported based on the operator attribute
virtual bool CheckSupported(const OpDescPtr &opDescPtr, std::string &un_supported_reason) const = 0;

virtual bool CheckAccuracySupported(const OpDescPtr &opDescPtr, std::string &un_supported_reason,
bool realQuery = false) const {
return CheckSupported(opDescPtr, un_supported_reason);
}

// requirement of memory allocation
virtual Status CalcOpRunningParam(Node &node) = 0;

// generate task for op
virtual Status GenerateTask(const Node &node, RunContext &context, std::vector<domi::TaskDef> &tasks) = 0;

// only call fe engine interface to compile single op
virtual Status CompileOp(vector<ge::NodePtr> &node_vec) { return SUCCESS; }

// load task for op
virtual Status LoadTask(GETaskInfo &task) { return SUCCESS; }

// only to call aicpu interface for generating task struct
virtual Status GenSingleOpRunTask(const NodePtr &node, STR_FWK_OP_KERNEL &task, string &task_info) { return SUCCESS; }

// only to call aicpu interface for generating task struct
virtual Status GenMemCopyTask(uint64_t count, STR_FWK_OP_KERNEL &task, string &task_info) { return SUCCESS; }
};
} // namespace ge
#endif // INC_COMMON_OPSKERNEL_OPS_KERNEL_INFO_STORE_H_

+ 63
- 0
inc/common/opskernel/ops_kernel_info_types.h View File

@@ -0,0 +1,63 @@
/**
* 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 INC_COMMON_OPSKERNEL_OPS_KERNEL_INFO_TYPES_H_
#define INC_COMMON_OPSKERNEL_OPS_KERNEL_INFO_TYPES_H_

#include <stdint.h>

#include <string>
#include <vector>

#include "graph/buffer.h"
#include "runtime/rt_model.h"

using std::string;

namespace ge {
struct RunContext {
rtModel_t model;
rtStream_t stream;
uint64_t sessionId;
uint64_t dataMemSize;
uint8_t *dataMemBase;
uint64_t weightMemSize;
uint8_t *weightMemBase;
ge::Buffer weightsBuffer;
std::vector<rtStream_t> graphStreamList; // all streams of graph which are sort by ge stream id(0,1,...)
std::vector<rtEvent_t> graphEventList; // all events of graph which are sort by ge event id(0,1,...)
};

struct Task {
uint32_t id;
uint16_t type;
void *stream;
void *event;
};

struct OpInfo {
string engine; // engine name
string opKernelLib; // opsKernelStore name
int computeCost; // compute cost
bool flagPartial; // whether to support related shape
bool flagAsync; // Whether to support asynchronous
bool isAtomic; // whether to support atomic addr clean
string opFileName; // op file name
string opFuncName; // op function name
};
} // namespace ge

#endif // INC_COMMON_OPSKERNEL_OPS_KERNEL_INFO_TYPES_H_

+ 61
- 0
inc/common/optimizer/graph_optimizer.h View File

@@ -0,0 +1,61 @@
/**
* 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 INC_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_H_
#define INC_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_H_

#include <map>
#include <string>

#include "./graph_optimizer_types.h"
#include "common/ge_inner_error_codes.h"
#include "common/opskernel/ops_kernel_info_types.h"
#include "graph/compute_graph.h"

using std::map;
using std::string;

namespace ge {
class GraphOptimizer {
public:
virtual ~GraphOptimizer() {}

// initialize graphOptimizer
virtual Status Initialize(const map<string, string> &options) = 0;

// close graphOptimizer
virtual Status Finalize() = 0;

// optimize original graph for FE quant optimization
virtual Status OptimizeGraphPrepare(ComputeGraph &graph) { return SUCCESS; }

// optimize original graph used in the graph preparation stage
virtual Status OptimizeOriginalGraph(ComputeGraph &graph) = 0;

// optimize fused graph
virtual Status OptimizeFusedGraph(ComputeGraph &graph) = 0;

// optimize the whole graph which will be used after graph merged
virtual Status OptimizeWholeGraph(ComputeGraph &graph) = 0;

// get attributes of graph optimizer
virtual Status GetAttributes(GraphOptimizerAttribute &attrs) const = 0;

// optimize streamed Graph
virtual Status OptimizeStreamGraph(ComputeGraph &graph, const RunContext &context) { return SUCCESS; }
};
} // namespace ge
#endif // INC_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_H_

+ 36
- 0
inc/common/optimizer/graph_optimizer_types.h View File

@@ -0,0 +1,36 @@
/**
* 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 INC_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_TYPES_H_
#define INC_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_TYPES_H_

#include <stdint.h>
#include <string>

using std::string;
namespace ge {
enum OPTIMIZER_SCOPE {
UNIT = 0,
ENGINE,
};

struct GraphOptimizerAttribute {
string engineName;
OPTIMIZER_SCOPE scope;
};
} // namespace ge

#endif // INC_COMMON_OPTIMIZER_GRAPH_OPTIMIZER_TYPES_H_

+ 102
- 0
inc/external/ge/ge_api.h View File

@@ -0,0 +1,102 @@
/**
* 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 INC_EXTERNAL_GE_GE_API_H_
#define INC_EXTERNAL_GE_GE_API_H_

#include <map>
#include <string>
#include <vector>

#include "ge/ge_api_error_codes.h"
#include "ge/ge_api_types.h"
#include "graph/graph.h"
#include "graph/tensor.h"

namespace ge {
typedef uint32_t (*pCallBackFunc)(uint32_t graph_id, const std::map<std::string, ge::Tensor> &params_list);

// Initialize GE
Status GEInitialize(const std::map<std::string, std::string> &options);

// Finalize GE, release all resources
Status GEFinalize();

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Session {
public:
explicit Session(const std::map<std::string, std::string> &options);

~Session();

///
/// @ingroup client
/// @brief add a graph with a specific graphId
/// @param [in] graphId graph id
/// @return Status result of function
///
Status AddGraph(uint32_t graphId, const Graph &graph);

///
/// @ingroup ge_graph
/// @brief remove a graph of the session with specific session id
/// @param [in] graphId graph id
/// @return Status result of function
///
Status RemoveGraph(uint32_t graphId);

///
/// @ingroup ge_graph
/// @brief run a graph of the session with specific session id
/// @param [in] graphId graph id
/// @param [in] inputs input data
/// @param [out] outputs output data
/// @return Status result of function
///
Status RunGraph(uint32_t graphId, const std::vector<Tensor> &inputs, std::vector<Tensor> &outputs);

///
/// @ingroup ge_graph
/// @brief run graph in the session with specific session id asynchronously
/// @param [in] graphId: graph id
/// @param [in] inputs: input data
/// @param [out] outputs: output data
/// @param [out] callback: callback while runing graph has been finished.
/// The callback function will not be checked.
/// Please ensure that the implementation of the function is trusted.
/// @return Status result of function
///
Status RunGraphAsync(uint32_t graphId, const std::vector<ge::TensorInfo> &inputs,
std::vector<ge::TensorInfo> &outputs, std::function<void(Status)> callback);

///
/// @ingroup ge_graph
/// @brief register callback func with specific summary or checkpoint by users
/// @param [in] key: func key
/// @param [in] callback: callback specific summary or checkpoint.
/// The callback function will not be checked.
/// Please ensure that the implementation of the function is trusted.
/// @return Status result of function
///
Status RegisterCallBackFunc(const std::string &key, const pCallBackFunc &callback);

bool IsGraphNeedRebuild(uint32_t graphId);

private:
uint64_t sessionId_;
};
} // namespace ge

#endif // INC_EXTERNAL_GE_GE_API_H_

+ 76
- 0
inc/external/ge/ge_api_error_codes.h View File

@@ -0,0 +1,76 @@
/**
* 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 INC_EXTERNAL_GE_GE_API_ERROR_CODES_H_
#define INC_EXTERNAL_GE_GE_API_ERROR_CODES_H_

#include <map>
#include <string>

namespace ge {
class StatusFactory {
public:
static StatusFactory *Instance() {
static StatusFactory instance;
return &instance;
}

void RegisterErrorNo(uint32_t err, const std::string &desc) {
// Avoid repeated addition
if (err_desc_.find(err) != err_desc_.end()) {
return;
}
err_desc_[err] = desc;
}

std::string GetErrDesc(uint32_t err) {
auto iter_find = err_desc_.find(err);
if (iter_find == err_desc_.end()) {
return "";
}
return iter_find->second;
}

protected:
StatusFactory() {}
~StatusFactory() {}

private:
std::map<uint32_t, std::string> err_desc_;
};

class ErrorNoRegisterar {
public:
ErrorNoRegisterar(uint32_t err, const std::string &desc) { StatusFactory::Instance()->RegisterErrorNo(err, desc); }
~ErrorNoRegisterar() {}
};

// Code compose(4 byte), runtime: 2 bit, type: 2 bit, level: 3 bit, sysid: 8 bit, modid: 5 bit, value: 12 bit
#define GE_ERRORNO(runtime, type, level, sysid, modid, name, value, desc) \
constexpr ge::Status name = \
((0xFF & (static_cast<uint8_t>(runtime))) << 30) | ((0xFF & (static_cast<uint8_t>(type))) << 28) | \
((0xFF & (static_cast<uint8_t>(level))) << 25) | ((0xFF & (static_cast<uint8_t>(sysid))) << 17) | \
((0xFF & (static_cast<uint8_t>(modid))) << 12) | (0x0FFF & (static_cast<uint16_t>(value))); \
const ErrorNoRegisterar g_##name##_errorno(name, desc);

using Status = uint32_t;

// General error code
GE_ERRORNO(0, 0, 0, 0, 0, SUCCESS, 0, "success");
GE_ERRORNO(0b11, 0b11, 0b111, 0xFF, 0b11111, FAILED, 0xFFF, "failed");
} // namespace ge

#endif // INC_EXTERNAL_GE_GE_API_ERROR_CODES_H_

+ 195
- 0
inc/external/ge/ge_api_types.h View File

@@ -0,0 +1,195 @@
/**
* 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 INC_EXTERNAL_GE_GE_API_TYPES_H_
#define INC_EXTERNAL_GE_GE_API_TYPES_H_

#include <cstdint>
#include <string>
#include <vector>

namespace ge {
// Option key: graph run mode
const char *const OPTION_GRAPH_RUN_MODE = "ge.graphRunMode";

// Option key: ome init
const char *const OPTION_EXEC_SESSION_ID = "ge.exec.sessionId";
const char *const OPTION_EXEC_DEVICE_ID = "ge.exec.deviceId";
const char *const OPTION_EXEC_JOB_ID = "ge.exec.jobId";
const char *const OPTION_EXEC_IS_USEHCOM = "ge.exec.isUseHcom";
const char *const OPTION_EXEC_RANK_ID = "ge.exec.rankId";
const char *const OPTION_EXEC_POD_NAME = "ge.exec.podName";
const char *const OPTION_EXEC_DEPLOY_MODE = "ge.exec.deployMode";
const char *const OPTION_EXEC_RANK_TABLE_FILE = "ge.exec.rankTableFile";
const char *const GE_AICPU_FLAG = "ge.aicpuFlag";
const char *const OPTION_EXEC_EXTERN_PLUGIN_PATH = "ge.soLoadPath";
const char *const OPTION_EXEC_ENABLE_DUMP = "ge.exec.enableDump";
const char *const OPTION_EXEC_DUMP_PATH = "ge.exec.dumpPath";
// Hccl flag, if ge.exec.hcclFlag =1, it means load plugin for opskernel, else:ge.exec.hcclFlag =0
const char *const OPTION_EXEC_HCCL_FLAG = "ge.exec.hcclFlag";
const char *const OPTION_EXEC_ATOMIC_FLAG = "ge.exec.enable_atomic";

// Option key: memory init
const char *const GRAPH_MEMORY_MAX_SIZE = "ge.graphMemoryMaxSize";
const char *const VARIABLE_MEMORY_MAX_SIZE = "ge.variableMemoryMaxSize";

// Configure stream num by Session constructor options param,
// its value should be int32_t type, default value is "1"
const std::string STREAM_NUM = "ge.streamNum";

// Configure add head stream to model,
// its value should be "0" or "1", default value is "0"
const std::string HEAD_STREAM = "ge.headStream";

// Configure perf level by Session constructor options param,
// its value please see enum PerfLevel, default value is "4"
const std::string PERF_LEVEL = "ge.perfLevel";

// Configure encrypt mode by Session constructor options param,
// its value should be int32_t type, default value is "-1"
const std::string ENCRYPT_MODE = "ge.encryptMode";

// configure ek file by Session constructor options param,
// its value should be file path, default value is ""
const std::string EK_FILE = "ge.ekFile";

// Configure cert file by Session constructor options param,
// its value should be file path, default value is ""
const std::string CERT_FILE = "ge.certFile";

// Configure hw key file by Session constructor options param,
// its value should be file path, default value is ""
const std::string HW_KEY_FILE = "ge.hwKeyFile";

// Configure private file by Session constructor options param,
// its value should be file path, default value is ""
const std::string PRIVATE_KEY_FILE = "ge.privateKeyFile";

// Configure framework type by Session constructor options param,
// its value please see enum FrameworkType, default value is "3"
const std::string FRAMEWORK_TYPE = "ge.frameworkType";

// Configure calibration info file by Session constructor options param,
// its value should be file path, default value is ""
const std::string CALIBRATION_CONF_FILE = "ge.calibrationConfFile";

// Configure insert op info file by Session constructor options param,
// its value should be file path, default value is ""
const std::string INSERT_OP_FILE = "ge.insertOpFile";

// Configure output node name by Session constructor options param,
// its value should be std::string type, default value is ""
const std::string OUTPUT_NODE_NAME = "ge.outputNodeName";

// Configure weight compress flag by Session constructor options param,
// its value should be "0" or "1", default value is "0"
const std::string COMPRESS_FLAG = "ge.compressFlag";

const std::string ATUO_PRECISION_FLAG = "ge.exec.auto_mix_precision";

// Configure single op flag for FE
// its value should be "0" or "1", default value is "0"
const std::string SINGLE_OP_FLAG = "ge.exec.single_op";

// Configure train flag by Session constructor options param,
// its value should be "0" or "1", default value is "0"
const std::string TRAIN_FLAG = "ge.trainFlag";

// Configure run flag by Session constructor options param,
// its value should be "0" or "1", default value is "0"
const std::string RUN_FLAG = "ge.runFlag";

// Configure run flag by Session constructor options param,
// its value should be "0" or "1", default value is "0"
// this option is to enable local framework op feature
const std::string LOCAL_FMKOP_FLAG = "ge.enabledLocalFmkop";

// Configure run flag by Session constructor options param,
// its value should be a path
// this option is to obtain the TBE op plugin path
const std::string TBE_PLUGIN_PATH_FLAG = "ge.TBE_plugin_path";

// Configure run flag by Session constructor options param,
// its value should be a path
// this option is to obtain the DDK Version info
const std::string DDK_VERSION_FLAG = "ge.DDK_version";

// Configure run flag by Session constructor options param,
// its value should be a path
// this option is to obtain fe flag
const std::string GE_FE_FLAG = "ge.feFlag";

// Configure stream max parallel num only by Session constructor options param,
// its value should be stream:int, such as "DNN_V100:2,DNN_HCCL:3",
// default value is "1", such as "DNN_V100:1,DNN_HCCL:1"
// this option is to obtain stream max parallel num
const std::string STREAM_MAX_PARALLEL_NUM = "ge.streamMaxParallelNum";

// configure outputDatatype to setting net output type
const std::string OUTPUT_DATATYPE = "ge.outputDatatype";

// configure whether to enable hcom parallel by session constructor options param,
// its value should be "0" or "1", default value is "0"
const std::string HCOM_PARALLEL = "ge.hcomParallel";

// Configure auto tune mode, this option only take effect while AUTO_TUNE_FLAG is Y,
// example: GA|RL, support configure multiple, split by |
const std::string AUTO_TUNE_MODE = "ge.autoTuneMode";

// Configure core type "VectorEngine", default value is "AICoreEngine"
const std::string CORE_TYPE = "ge.engineType";

// Configure soc version , example: "Ascend310"
const std::string SOC_VERSION = "ge.socVersion";

// Save original model
const std::string SAVE_ORIGINAL_MODEL = "ge.saveOriginalModel";

// Save original model file name
const std::string ORIGINAL_MODEL_FILE = "ge.originalModelFile";

const char *const OPTION_GE_MAX_DUMP_FILE_NUM = "ge.maxDumpFileNum";
const char *const OPTION_GE_MAX_DUMP_FILE_SIZE = "ge.maxDumpFileSize";
const char *const OPTION_GE_MAX_DUMP_OP_NUM = "ge.maxDumpOpNum";

// Graph run mode
enum GraphRunMode { PREDICTION = 0, TRAIN };

// Data description
struct DataDesc {
void *data = nullptr; // data address
uint32_t length = 0; // data size
bool isDataSupportMemShare = false;
};

// Input/Output shape description
struct ShapeDesc {
int64_t num = 0;
int64_t channel = 0;
int64_t height = 0;
int64_t width = 0;
std::vector<int64_t> dims;
};

// Input/Output tensor info
struct TensorInfo {
uint32_t dataType; // data type
DataDesc data; // tensor data
ShapeDesc shapeInfo; // tensor shape
};
} // namespace ge

#endif // INC_EXTERNAL_GE_GE_API_TYPES_H_

+ 73
- 0
inc/external/graph/attr_value.h View File

@@ -0,0 +1,73 @@
/**
* 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 INC_EXTERNAL_GRAPH_ATTR_VALUE_H_
#define INC_EXTERNAL_GRAPH_ATTR_VALUE_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "external/graph/ge_error_codes.h"

using std::make_shared;
using std::map;
using std::pair;
using std::string;
using std::to_string;
using std::unique_ptr;
using std::vector;

namespace ge {
class AttrValueImpl;
class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AttrValue {
public:
using INT = int64_t;
using FLOAT = float;
using STR = std::string;

AttrValue();
~AttrValue() = default;

// GetValue, not list type
template <typename T, typename DT>
graphStatus GetValue(DT &val) const {
T valGet;
auto status = GetValue(valGet);
if (status != GRAPH_SUCCESS) {
return status;
}
val = DT(valGet);
return GRAPH_SUCCESS;
}

template <typename T, typename DT>
static T CreateFrom(DT &&val) {
return val;
}

std::shared_ptr<AttrValueImpl> impl;

private:
#define VALUE_SET_GET_DEC(DT) graphStatus GetValue(DT &val) const;
VALUE_SET_GET_DEC(AttrValue::STR)
VALUE_SET_GET_DEC(AttrValue::INT)
VALUE_SET_GET_DEC(AttrValue::FLOAT)
#undef VALUE_SET_GET_DEC
};
} // namespace ge
#endif // INC_EXTERNAL_GRAPH_ATTR_VALUE_H_

+ 38
- 0
inc/external/graph/ge_error_codes.h View File

@@ -0,0 +1,38 @@
/**
* 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 INC_EXTERNAL_GRAPH_GE_ERROR_CODES_H_
#define INC_EXTERNAL_GRAPH_GE_ERROR_CODES_H_

namespace ge {
#ifdef HOST_VISIBILITY
#define GE_FUNC_HOST_VISIBILITY __attribute__((visibility("default")))
#else
#define GE_FUNC_HOST_VISIBILITY
#endif
#ifdef DEV_VISIBILITY
#define GE_FUNC_DEV_VISIBILITY __attribute__((visibility("default")))
#else
#define GE_FUNC_DEV_VISIBILITY
#endif

using graphStatus = uint32_t;
const graphStatus GRAPH_FAILED = 0xFFFFFFFF;
const graphStatus GRAPH_SUCCESS = 0;
const graphStatus GRAPH_PARAM_INVALID = 50331649;
} // namespace ge

#endif // INC_EXTERNAL_GRAPH_GE_ERROR_CODES_H_

+ 77
- 0
inc/external/graph/graph.h View File

@@ -0,0 +1,77 @@
/**
* 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 INC_EXTERNAL_GRAPH_GRAPH_H_
#define INC_EXTERNAL_GRAPH_GRAPH_H_

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "external/graph/operator.h"

namespace ge {
class GraphImpl;

using GraphImplPtr = std::shared_ptr<GraphImpl>;

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Graph {
friend class GraphUtils;

public:
explicit Graph(const std::string &name);

Graph() = default;

~Graph() = default;

Graph &SetInputs(const std::vector<Operator> &inputs);

Graph &SetOutputs(const std::vector<Operator> &outputs);

Graph &SetOutputs(const std::vector<std::pair<Operator, std::vector<size_t>>> &output_indexs);

Graph &SetOutputs(const std::vector<std::pair<ge::Operator, std::string>> &outputs);

Graph &SetTargets(const std::vector<Operator> &targets);

bool IsValid() const;

graphStatus AddOp(const ge::Operator &op);

graphStatus FindOpByName(const string &name, ge::Operator &op) const;

graphStatus GetAllOpName(std::vector<string> &op_name) const;

graphStatus SaveToFile(const string &file_name) const;

graphStatus LoadFromFile(const string &file_name);

///
/// Set is need train iteration.
/// If set true, it means this graph need to be run iteration some
/// times(according variant "npu_runconfig/iterations_per_loop").
/// @param need_iteration need_iteration:whether to set iteration or not
///
void SetNeedIteration(bool need_iteration);

private:
GraphImplPtr impl_{nullptr};
};
} // namespace ge

#endif // INC_EXTERNAL_GRAPH_GRAPH_H_

+ 79
- 0
inc/external/graph/inference_context.h View File

@@ -0,0 +1,79 @@
/**
* 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 INC_EXTERNAL_GRAPH_INFERENCE_CONTEXT_H_
#define INC_EXTERNAL_GRAPH_INFERENCE_CONTEXT_H_

#include <memory>
#include <string>
#include <vector>

#include "external/graph/tensor.h"
#include "external/graph/types.h"

namespace ge {
class InferenceContext;
using InferenceContextPtr = std::shared_ptr<InferenceContext>;

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY ShapeAndType {
public:
ShapeAndType() = default;
~ShapeAndType() = default;

ShapeAndType(const Shape &shape, DataType data_type);

void SetShape(const Shape &shape);

void SetType(DataType data_type);

const Shape &GetShape() const;

DataType GetDataType() const;

private:
Shape shape_;
DataType data_type_ = DT_UNDEFINED;
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InferenceContext {
public:
InferenceContext() = default;
~InferenceContext() = default;
InferenceContext(const InferenceContext &context) = delete;
InferenceContext(const InferenceContext &&context) = delete;
InferenceContext &operator=(const InferenceContext &context) = delete;
InferenceContext &operator=(const InferenceContext &&context) = delete;

void SetInputHandleShapesAndTypes(std::vector<std::vector<ShapeAndType>> &&shapes_and_types);

const std::vector<std::vector<ShapeAndType>> &GetInputHandleShapesAndTypes() const;

const std::vector<std::vector<ShapeAndType>> &GetOutputHandleShapesAndTypes() const;

void SetOutputHandleShapesAndTypes(const std::vector<std::vector<ShapeAndType>> &shapes_and_types);
void SetOutputHandleShapesAndTypes(std::vector<std::vector<ShapeAndType>> &&shapes_and_types);

void SetMarks(const std::vector<std::string> &marks);
const std::vector<std::string> &GetMarks() const;

private:
// 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_;
};
} // namespace ge
#endif // INC_EXTERNAL_GRAPH_INFERENCE_CONTEXT_H_

+ 257
- 0
inc/external/graph/operator.h View File

@@ -0,0 +1,257 @@
/**
* 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 INC_EXTERNAL_GRAPH_OPERATOR_H_
#define INC_EXTERNAL_GRAPH_OPERATOR_H_

#include <functional>
#include <map>
#include <memory>
#include <string>
#include <vector>

#include "external/graph/ge_error_codes.h"
#include "external/graph//inference_context.h"
#include "external/graph//tensor.h"
#include "external/graph//usr_types.h"

#ifndef USER_GE_LOGI
#define USER_GE_LOGI(...)
#endif // USER_GE_LOGI

#ifndef USER_GE_LOGW
#define USER_GE_LOGW(...)
#endif // USER_GE_LOGW

#ifndef USER_GE_LOGE
#define USER_GE_LOGE(...)
#endif // USER_GE_LOGE

#define DYNAMIC_OUTPUT_TD_NUM(name) ("__dynamic_output_" + name + "_cnt")
#define DYNAMIC_INPUT_TD_NUM(name) ("__dynamic_input_" + name + "_cnt")

namespace ge {
class OperatorImpl;

class AttrValue;

using OperatorImplPtr = std::shared_ptr<OperatorImpl>;

class OpIO;
using OutHandler = std::shared_ptr<OpIO>;
using InHandler = std::shared_ptr<OpIO>;

using std::function;
using std::shared_ptr;
using std::string;

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Operator {
public:
friend class OperatorImpl;

friend class GraphBuilderImpl;

using OpInt = int64_t;
using OpFloat = float;
using OpString = string;
using OpBool = bool;
using OpTensor = Tensor;
using OpType = ge::DataType;
using OpListInt = std::vector<int64_t>;
using OpListFloat = std::vector<float>;
using OpListString = std::vector<string>;
using OpListBool = std::vector<bool>;
using OpListTensor = std::vector<Tensor>;
using OpBytes = std::vector<uint8_t>;
using OpListListInt = std::vector<std::vector<int64_t>>;
using OpListType = std::vector<ge::DataType>;

Operator() {}

explicit Operator(const string &type);

Operator(const string &name, const string &type);

virtual ~Operator() = default;

bool IsEmpty() const;

string GetName() const;

string GetOpType() const;

// Only has one output index = 0
Operator &SetInput(const string &dst_name, const Operator &src_oprt);

Operator &SetInput(const string &dst_name, const Operator &src_oprt, const string &name);

Operator &AddControlInput(const Operator &src_oprt);

graphStatus GetInputConstData(const string &dst_name, Tensor &data) const;

TensorDesc GetInputDesc(const string &name) const;

TensorDesc GetInputDesc(uint32_t index) const;

int GetDynamicOutputNum(const string &name) const;

int GetDynamicInputNum(const string &name) const;

graphStatus TryGetInputDesc(const string &name, TensorDesc &tensor_desc) const;

graphStatus UpdateInputDesc(const string &name, const TensorDesc &tensor_desc);

TensorDesc GetOutputDesc(const string &name) const;

TensorDesc GetOutputDesc(uint32_t index) const;

graphStatus UpdateOutputDesc(const string &name, const TensorDesc &tensor_desc);

TensorDesc GetDynamicInputDesc(const string &name, uint32_t index) const;

graphStatus UpdateDynamicInputDesc(const string &name, uint32_t index, const TensorDesc &tensor_desc);

TensorDesc GetDynamicOutputDesc(const string &name, uint32_t index) const;

graphStatus UpdateDynamicOutputDesc(const string &name, uint32_t index, const TensorDesc &tensor_desc);

graphStatus InferShapeAndType();

void SetInferenceContext(const InferenceContextPtr &inference_context);
InferenceContextPtr GetInferenceContext() const;

graphStatus VerifyAllAttr(bool disable_common_verifier = false);

size_t GetInputsSize() const;

size_t GetOutputsSize() const;

const std::map<std::string, std::string> GetAllAttrNamesAndTypes() const;

Operator &SetAttr(const string &name, int64_t attr_value);
Operator &SetAttr(const string &name, int32_t attr_value);
Operator &SetAttr(const string &name, uint32_t attr_value);
graphStatus GetAttr(const string &name, int64_t &attr_value) const;
graphStatus GetAttr(const string &name, int32_t &attr_value) const;
graphStatus GetAttr(const string &name, uint32_t &attr_value) const;
Operator &SetAttr(const string &name, const std::vector<int64_t> &attr_value);
Operator &SetAttr(const string &name, const std::vector<int32_t> &attr_value);
Operator &SetAttr(const string &name, const std::vector<uint32_t> &attr_value);
Operator &SetAttr(const string &name, std::initializer_list<int64_t> &&attr_value);
graphStatus GetAttr(const string &name, std::vector<int64_t> &attr_value) const;
graphStatus GetAttr(const string &name, std::vector<int32_t> &attr_value) const;
graphStatus GetAttr(const string &name, std::vector<uint32_t> &attr_value) const;

Operator &SetAttr(const string &name, float attr_value);
graphStatus GetAttr(const string &name, float &attr_value) const;
Operator &SetAttr(const string &name, const std::vector<float> &attr_value);
graphStatus GetAttr(const string &name, std::vector<float> &attr_value) const;
Operator &SetAttr(const string &name, AttrValue &&attr_value);
graphStatus GetAttr(const string &name, AttrValue &attr_value) const;

Operator &SetAttr(const string &name, const string &attr_value);
graphStatus GetAttr(const string &name, string &attr_value) const;
Operator &SetAttr(const string &name, const std::vector<string> &attr_value);
graphStatus GetAttr(const string &name, std::vector<string> &attr_value) const;

Operator &SetAttr(const string &name, bool attr_value);
graphStatus GetAttr(const string &name, bool &attr_value) const;
Operator &SetAttr(const string &name, const std::vector<bool> &attr_value);
graphStatus GetAttr(const string &name, std::vector<bool> &attr_value) const;

Operator &SetAttr(const string &name, const Tensor &attr_value);
graphStatus GetAttr(const string &name, Tensor &attr_value) const;
Operator &SetAttr(const string &name, const std::vector<Tensor> &attr_value);
graphStatus GetAttr(const string &name, std::vector<Tensor> &attr_value) const;

// Bytes type
Operator &SetAttr(const string &name, const OpBytes &attr_value);
// Bytes type
graphStatus GetAttr(const string &name, OpBytes &attr_value) const;

Operator &SetAttr(const string &name, const UsrQuantizeFactorParams &attr_value);
graphStatus GetAttr(const string &name, UsrQuantizeFactorParams &attr_value) const;

Operator &SetAttr(const string &name, const std::vector<std::vector<int64_t>> &attr_value);
graphStatus GetAttr(const string &name, std::vector<std::vector<int64_t>> &attr_value) const;

Operator &SetAttr(const string &name, const std::vector<ge::DataType> &attr_value);
graphStatus GetAttr(const string &name, std::vector<ge::DataType> &attr_value) const;

Operator &SetAttr(const string &name, const ge::DataType &attr_value);
graphStatus GetAttr(const string &name, ge::DataType &attr_value) const;

void BreakConnect() const;

protected:
void AttrRegister(const string &name, float attr_value);
void AttrRegister(const string &name, const std::vector<float> &attr_value);
void AttrRegister(const string &name, int64_t attr_value);
void AttrRegister(const string &name, const std::vector<int64_t> &attr_value);
void AttrRegister(const string &name, const string &attr_value);
void AttrRegister(const string &name, const std::vector<string> &attr_value);
void AttrRegister(const string &name, bool attr_value);
void AttrRegister(const string &name, const std::vector<bool> &attr_value);
void AttrRegister(const string &name, const Tensor &attr_value);
void AttrRegister(const string &name, const std::vector<Tensor> &attr_value);
void AttrRegister(const string &name, const OpBytes &attr_value);
void AttrRegister(const string &name, const std::vector<std::vector<int64_t>> &attr_value);
void AttrRegister(const string &name, const std::vector<ge::DataType> &attr_value);
void AttrRegister(const string &name, const ge::DataType &attr_value);

explicit Operator(OperatorImplPtr &&op_impl);

void InputRegister(const string &name);

void OptionalInputRegister(const string &name);

void InferFuncRegister(const std::function<graphStatus(Operator &)> &func);

void VerifierFuncRegister(const std::function<graphStatus(Operator &)> &func);

void InferFormatFuncRegister(const std::function<graphStatus(Operator &)> &func);

void OutputRegister(const string &name);

void DynamicInputRegister(const string &name, const unsigned int num, bool is_push_back = true);

void DynamicOutputRegister(const string &name, const unsigned int num, bool is_push_back = true);

void RequiredAttrRegister(const string &name);

graphStatus VerifyAll();

// Only has one output index = 0
Operator &SetInput(const string &dst_name, uint32_t dst_index,
const Operator &src_oprt);

Operator &SetInput(const string &dst_name, uint32_t dst_index, const Operator &src_oprt,
const string &name);

private:
Operator &SetInput(const string &dst_name, const OutHandler &out_handler);

OutHandler GetOutput(const string &name) const;

OperatorImplPtr GetOperatorImplPtr() const;

OperatorImplPtr operator_impl_{nullptr};

graphStatus GetInputConstDataOut(const string &dst_name, Tensor &data) const;
};
} // namespace ge

#endif // INC_EXTERNAL_GRAPH_OPERATOR_H_

+ 68
- 0
inc/external/graph/operator_factory.h View File

@@ -0,0 +1,68 @@
/**
* 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 INC_EXTERNAL_GRAPH_OPERATOR_FACTORY_H_
#define INC_EXTERNAL_GRAPH_OPERATOR_FACTORY_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "external/graph//operator.h"
#include "external/graph/ge_error_codes.h"

namespace ge {
using OpCreator = std::function<Operator(const std::string &)>;
using InferShapeFunc = std::function<graphStatus(Operator &)>;
using InferFormatFunc = std::function<graphStatus(Operator &)>;
using VerifyFunc = std::function<graphStatus(Operator &)>;

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OperatorFactory {
public:
static Operator CreateOperator(const std::string &operator_name, const std::string &operator_type);

static graphStatus GetOpsTypeList(std::vector<std::string> &all_ops);

static bool IsExistOp(const string &operator_type);
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OperatorCreatorRegister {
public:
OperatorCreatorRegister(const string &operator_type, OpCreator const &op_creator);
~OperatorCreatorRegister() = default;
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InferShapeFuncRegister {
public:
InferShapeFuncRegister(const std::string &operator_type, const InferShapeFunc &infer_shape_func);
~InferShapeFuncRegister() = default;
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InferFormatFuncRegister {
public:
InferFormatFuncRegister(const std::string &operator_type, const InferFormatFunc &infer_format_func);
~InferFormatFuncRegister() = default;
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY VerifyFuncRegister {
public:
VerifyFuncRegister(const std::string &operator_type, const VerifyFunc &verify_func);
~VerifyFuncRegister() = default;
};
} // namespace ge

#endif // INC_EXTERNAL_GRAPH_OPERATOR_FACTORY_H_

+ 313
- 0
inc/external/graph/operator_reg.h View File

@@ -0,0 +1,313 @@
/**
* 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 INC_EXTERNAL_GRAPH_OPERATOR_REG_H_
#define INC_EXTERNAL_GRAPH_OPERATOR_REG_H_

#include <functional>
#include <memory>
#include <string>
#include <vector>

#include "external/graph/operator.h"
#include "external/graph/operator_factory.h"
#include "external/graph/tensor.h"
#include "external/graph/types.h"

namespace ge {
using std::function;
using std::string;
using std::vector;

class OpReg {
public:
OpReg &N() { return *this; }

OpReg &ATTR() { return *this; }

OpReg &REQUIRED_ATTR() { return *this; }

OpReg &INPUT() { return *this; }

OpReg &OPTIONAL_INPUT() { return *this; }

OpReg &OUTPUT() { return *this; }

OpReg &INFER_SHAPE_AND_TYPE() { return *this; }
};

#define REG_OP(x) \
namespace op { \
class x : public Operator { \
typedef x _THIS_TYPE; \
\
public: \
explicit x(const string &name) : Operator(name, #x) { __##x(); } \
x() : Operator(#x) { __##x(); } \
\
private: \
void __##x() { \
OpReg()

#define ATTR(x, Type, ...) \
N(); \
__attr_##x(); \
} \
\
public: \
static const string name_attr_##x() { return #x; } \
Op##Type get_attr_##x() const { \
Op##Type ret = __VA_ARGS__; \
if (Operator::GetAttr(#x, ret) == GRAPH_FAILED) { \
return ret; \
} \
return ret; \
} \
_THIS_TYPE &set_attr_##x(const Op##Type &v) { \
Operator::SetAttr(#x, v); \
return *this; \
} \
_THIS_TYPE &set_attr_##x(const function<Op##Type()> &v) { return *this; } \
\
private: \
void __attr_##x() { \
Operator::AttrRegister(#x, Op##Type(__VA_ARGS__)); \
string attr_name(#x); \
(void)OpReg()

#define REQUIRED_ATTR(x, Type) \
N(); \
__required_attr_##x(); \
} \
\
public: \
static const string name_attr_##x() { return #x; } \
Op##Type get_attr_##x() const { \
Op##Type ret; \
if (Operator::GetAttr(#x, ret) == GRAPH_FAILED) { \
return ret; \
} \
return ret; \
} \
_THIS_TYPE &set_attr_##x(const Op##Type &v) { \
Operator::SetAttr(#x, v); \
return *this; \
} \
_THIS_TYPE &set_attr_##x(const function<Op##Type()> &v) { return *this; } \
\
private: \
void __required_attr_##x() { \
Operator::RequiredAttrRegister(#x); \
string attr_name(#x); \
(void)OpReg()

#define INPUT(x, t) \
N(); \
__input_##x(); \
} \
\
public: \
static const string name_in_##x() { return #x; } \
_THIS_TYPE &set_input_##x(Operator &v, const string &srcName) { \
Operator::SetInput(#x, v, srcName); \
return *this; \
} \
_THIS_TYPE &set_input_##x(Operator &v) { \
Operator::SetInput(#x, v); \
return *this; \
} \
TensorDesc get_input_desc_##x() const { return Operator::GetInputDesc(#x); } \
graphStatus update_input_desc_##x(const TensorDesc &tensorDesc) { \
return Operator::UpdateInputDesc(#x, tensorDesc); \
} \
\
private: \
void __input_##x() { \
Operator::InputRegister(#x); \
(void)OpReg()

#define OPTIONAL_INPUT(x, t) \
N(); \
__optional_input_##x(); \
} \
\
public: \
static const string name_in_##x() { return #x; } \
_THIS_TYPE &set_input_##x(Operator &v) { \
Operator::SetInput(#x, v); \
return *this; \
} \
_THIS_TYPE &set_input_##x(Operator &v, const string &srcName) { \
Operator::SetInput(#x, v, srcName); \
return *this; \
} \
TensorDesc get_input_desc_##x() const { return Operator::GetInputDesc(#x); } \
graphStatus update_input_desc_##x(const TensorDesc &tensorDesc) { \
return Operator::UpdateInputDesc(#x, tensorDesc); \
} \
\
private: \
void __optional_input_##x() { \
Operator::OptionalInputRegister(#x); \
(void)OpReg()

#define OUTPUT(x, t) \
N(); \
__out_##x(); \
} \
\
public: \
static const string name_out_##x() { return #x; } \
TensorDesc get_output_desc_##x() const { return Operator::GetOutputDesc(#x); } \
graphStatus update_output_desc_##x(const TensorDesc &tensorDesc) { \
return Operator::UpdateOutputDesc(#x, tensorDesc); \
} \
\
private: \
void __out_##x() { \
Operator::OutputRegister(#x); \
(void)OpReg()

#define DYNAMIC_INPUT(x, t) \
N(); \
__dy_input_##x(); \
} \
\
public: \
_THIS_TYPE &create_dynamic_input_##x(unsigned int num, bool isPushBack = true) { \
Operator::DynamicInputRegister(#x, num, isPushBack); \
return *this; \
} \
TensorDesc get_dynamic_input_desc_##x(unsigned int index) const { return Operator::GetDynamicInputDesc(#x, index); } \
graphStatus update_dynamic_input_desc_##x(unsigned int index, const TensorDesc &tensorDesc) { \
return Operator::UpdateDynamicInputDesc(#x, index, tensorDesc); \
} \
_THIS_TYPE &set_dynamic_input_##x(unsigned int dstIndex, Operator &v) { \
Operator::SetInput(#x, dstIndex, v); \
return *this; \
} \
_THIS_TYPE &set_dynamic_input_##x(unsigned int dstIndex, Operator &v, const string &srcName) { \
Operator::SetInput(#x, dstIndex, v, srcName); \
return *this; \
} \
\
private: \
void __dy_input_##x() { \
(void)OpReg()

#define DYNAMIC_OUTPUT(x, t) \
N(); \
__dy_output_##x(); \
} \
\
public: \
_THIS_TYPE &create_dynamic_output_##x(unsigned int num, bool isPushBack = true) { \
Operator::DynamicOutputRegister(#x, num, isPushBack); \
return *this; \
} \
TensorDesc get_dynamic_output_desc_##x(unsigned int index) const { \
return Operator::GetDynamicOutputDesc(#x, index); \
} \
graphStatus update_dynamic_output_desc_##x(unsigned int index, const TensorDesc &tensorDesc) { \
return Operator::UpdateDynamicOutputDesc(#x, index, tensorDesc); \
} \
\
private: \
void __dy_output_##x() { \
(void)OpReg()

#define PASTE(g_register, y) g_register##y
#define __OP_END_IMPL__(x, y) \
N(); \
} \
static_assert( \
std::is_same<x, _THIS_TYPE>::value, \
"The class name entered into the OP_END_FACTORY_REG needs to be the same as the operator name you define."); \
} \
; \
static const OperatorCreatorRegister PASTE(g_register, y)(#x, [](const std::string &name) { return x(name); }); \
}
#define OP_END_FACTORY_REG(x) __OP_END_IMPL__(x, __COUNTER__)

// Specialized shape inferencer macro

#define IMPLEMT_INFERFUNC(op_name, func_name) \
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY static graphStatus func_name(op::op_name &op)

#define IMPLEMT_COMMON_INFERFUNC(func_name) \
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY static graphStatus func_name(Operator &op)

#define IMPLEMT_INFERFORMAT_FUNC(op_name, func_name) \
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY static graphStatus func_name(op::op_name &op)

// Specialized verifier macro

#define IMPLEMT_VERIFIER(op_name, func_name) \
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY static graphStatus func_name(op::op_name op)

#define INFER_VERIFY_FUNC(op_name, x) [&](Operator &v) { return x((op::op_name &)v); }

#define COMMON_INFER_VERIFY_FUNC(x) [&](Operator &v) { return x(v); }

#define INFER_FORMAT_FUNC(op_name, x) [&](Operator &v) { return x((op::op_name &)v); }

#define __INFER_FUNC_REG_IMPL__(op_name, x, n) static const InferShapeFuncRegister PASTE(if_register, n)(#op_name, x)

#define __VERIFY_FUNC_REG_IMPL__(op_name, x, n) static const VerifyFuncRegister PASTE(vf_register, n)(#op_name, x)
// Infer format func register
#define __INFER_FORMAT_FUNC_REG_IMPL__(op_name, x, n) \
static const InferFormatFuncRegister PASTE(ff_register, n)(#op_name, x)

// Shape inferencer & verifier register macro

#define INFER_FUNC_REG(op_name, x) __INFER_FUNC_REG_IMPL__(op_name, INFER_VERIFY_FUNC(op_name, x), __COUNTER__)

#define COMMON_INFER_FUNC_REG(op_name, x) __INFER_FUNC_REG_IMPL__(op_name, COMMON_INFER_VERIFY_FUNC(x), __COUNTER__)

#define VERIFY_FUNC_REG(op_name, x) __VERIFY_FUNC_REG_IMPL__(op_name, INFER_VERIFY_FUNC(op_name, x), __COUNTER__)

// Infer format func reg
#define INFER_FORMAT_FUNC_REG(op_name, x) \
__INFER_FORMAT_FUNC_REG_IMPL__(op_name, INFER_FORMAT_FUNC(op_name, x), __COUNTER__)

// Common shape inferencer

#define ELMTWISE_INFER_SHAPEANDTYPE(in_name, out_name) \
[](Operator op)->graphStatus { \
auto x_shape = op.GetInputDesc(in_name).GetShape().GetDims(); \
auto x_type = op.GetInputDesc(in_name).GetDataType(); \
TensorDesc op_output_desc = op.GetOutputDesc(out_name); \
op_output_desc.SetShape(ge::Shape(x_shape)); \
op_output_desc.SetDataType(x_type); \
return op.UpdateOutputDesc(out_name, op_output_desc); \
}

graphStatus BroadCastInfer(const function<vector<int64_t>()> &get_in1_shape,
const function<vector<int64_t>()> &get_in2_shape,
const function<void(const vector<int64_t> &y_shape)> &set_out_shape);

#define BROADCAST_INFER(in1_name, in2_name, out_name) \
[](Operator op)->graphStatus { \
return BroadCastInfer([&]() { return op.GetInputDesc(in1_name).GetShape().GetDims(); }, \
[&]() { return op.GetInputDesc(in2_name).GetShape().GetDims(); }, \
[&](const vector<int64_t> &y_shape) { \
TensorDesc op_output_desc = op.GetOutputDesc(out_name); \
op_output_desc.SetShape(ge::Shape(y_shape)); \
(void)op.UpdateOutputDesc(out_name, op_output_desc); \
}); \
}
} // namespace ge
#endif // INC_EXTERNAL_GRAPH_OPERATOR_REG_H_

+ 123
- 0
inc/external/graph/tensor.h View File

@@ -0,0 +1,123 @@
/**
* 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 INC_EXTERNAL_GRAPH_TENSOR_H_
#define INC_EXTERNAL_GRAPH_TENSOR_H_

#include <atomic>
#include <memory>
#include <string>
#include <vector>

#include "external/graph/ge_error_codes.h"
#include "external/graph/types.h"

namespace ge {
class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Shape {
public:
Shape() = default;
~Shape() = default;
explicit Shape(const std::vector<int64_t> &dims);

size_t GetDimNum() const;
// If the idx is invalid, return 0
int64_t GetDim(size_t idx) const;
graphStatus SetDim(size_t idx, int64_t value);
std::vector<int64_t> GetDims() const;
int64_t GetShapeSize() const;

private:
std::vector<int64_t> dims_;
};

class TensorDescImpl;
class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY TensorDesc {
public:
TensorDesc();
~TensorDesc() = default;
explicit TensorDesc(Shape shape, Format format = FORMAT_ND, DataType dt = DT_FLOAT);
// Copy
TensorDesc(const TensorDesc &desc);
// Move
TensorDesc(TensorDesc &&desc);
// Copy
TensorDesc &operator=(const TensorDesc &desc);
// Move
TensorDesc &operator=(TensorDesc &&desc);

void Update(const Shape &shape, Format format = FORMAT_ND, DataType dt = DT_FLOAT);
Shape GetShape() const;
void SetShape(const Shape &shape);

Format GetFormat() const;
void SetFormat(Format format);

Shape GetOriginShape() const;
void SetOriginShape(const Shape &origin_shape);

Format GetOriginFormat() const;
void SetOriginFormat(Format origin_format);

DataType GetDataType() const;
void SetDataType(DataType dt);

std::string GetName() const;
void SetName(const std::string &name);

// Attr acess
void SetSize(int64_t size);
int64_t GetSize() const;

int64_t GetRealDimCnt() const;
void SetRealDimCnt(const int64_t real_dim_cnt);

private:
std::shared_ptr<TensorDescImpl> impl;
};

class TensorImpl;
class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Tensor {
public:
Tensor();
~Tensor() = default;
explicit Tensor(const TensorDesc &tensorDesc);
Tensor(const TensorDesc &tensorDesc, const std::vector<uint8_t> &data);
Tensor(const TensorDesc &tensorDesc, const uint8_t *data, size_t size);
Tensor(TensorDesc &&tensorDesc, std::vector<uint8_t> &&data);

TensorDesc GetTensorDesc() const;
graphStatus SetTensorDesc(const TensorDesc &tensorDesc);

const uint8_t *GetData() const;
uint8_t *GetData();
size_t GetSize() const;

graphStatus SetData(std::vector<uint8_t> &&data);
graphStatus SetData(const std::vector<uint8_t> &data);
graphStatus SetData(const uint8_t *data, size_t size);
graphStatus SetData(const std::string &data);
graphStatus SetData(const std::vector<std::string> &data);
graphStatus IsValid();

Tensor Clone() const;

private:
std::shared_ptr<TensorImpl> impl;
friend class TensorAdapter;
};
} // namespace ge

#endif // INC_EXTERNAL_GRAPH_TENSOR_H_

+ 224
- 0
inc/external/graph/types.h View File

@@ -0,0 +1,224 @@
/**
* 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 INC_EXTERNAL_GRAPH_TYPES_H_
#define INC_EXTERNAL_GRAPH_TYPES_H_

#include <atomic>
#include <memory>
#include <vector>

namespace ge {
static const int64_t UNKNOWN_DIM = -1;
static const std::vector<int64_t> UNKNOWN_SHAPE = {0};

#ifdef HOST_VISIBILITY
#define GE_FUNC_HOST_VISIBILITY __attribute__((visibility("default")))
#else
#define GE_FUNC_HOST_VISIBILITY
#endif
#ifdef DEV_VISIBILITY
#define GE_FUNC_DEV_VISIBILITY __attribute__((visibility("default")))
#else
#define GE_FUNC_DEV_VISIBILITY
#endif

enum DataType {
DT_FLOAT = 0, // float type
DT_FLOAT16 = 1, // fp16 type
DT_INT8 = 2, // int8 type
DT_INT16 = 6, // int16 type
DT_UINT16 = 7, // uint16 type
DT_UINT8 = 4, // uint8 type
DT_INT32 = 3, //
DT_INT64 = 9, // int64 type
DT_UINT32 = 8, // unsigned int32
DT_UINT64 = 10, // unsigned int64
DT_BOOL = 12, // bool type
DT_DOUBLE = 11, // double type
DT_STRING = 13, // string type
DT_DUAL_SUB_INT8 = 14, // dual output int8 type
DT_DUAL_SUB_UINT8 = 15, // dual output uint8 type
DT_COMPLEX64 = 16, // complex64 type
DT_COMPLEX128 = 17, // complex128 type
DT_QINT8 = 18, // qint8 type
DT_QINT16 = 19, // qint16 type
DT_QINT32 = 20, // qint32 type
DT_QUINT8 = 21, // quint8 type
DT_QUINT16 = 22, // quint16 type
DT_RESOURCE = 23, // resource type
DT_STRING_REF = 24, // string ref type
DT_DUAL = 25, // dual output type
DT_UNDEFINED // Used to indicate a DataType field has not been set.
};

inline int GetSizeByDataType(DataType data_type) {
static int data_type_size[DT_UNDEFINED] = {
4, // DT_FLOAT = 0, float type
2, // DT_FLOAT16 = 1, fp16 type
1, // DT_INT8 = 2, int8 type
4, // DT_INT32 = 3,
1, // DT_UINT8 = 4, uint8 type
-1,
2, // DT_INT16 = 6, int16 type
2, // DT_UINT16 = 7, uint16 type
4, // DT_UINT32 = 8, unsigned int32
8, // DT_INT64 = 9, int64 type
8, // DT_UINT64 = 10, unsigned int64
8, // DT_DOUBLE = 11, double type
1, // DT_BOOL = 12, bool type
-1, // DT_STRING = 13, string type
1, // DT_DUAL_SUB_INT8 = 14, dual output int8 type
1, // DT_DUAL_SUB_UINT8 = 15, dual output uint8 type
8, // DT_COMPLEX64 = 16, complex64 type
16, // DT_COMPLEX128 = 17, complex128 type
1, // DT_QINT8 = 18, qint8 type
2, // DT_QINT16 = 19, qint16 type
4, // DT_QINT32 = 20, qint32 type
1, // DT_QUINT8 = 21, quint8 type
2, // DT_QUINT16 = 22, quint16 type
-1, // DT_RESOURCE = 23, resource type
-1, // DT_STRING_REF = 24, string ref type
5, // DT_DUAL = 25, dual output type (float + int8)
// DT_UNDEFINED Used to indicate a DataType field has not been set.
};
if (data_type >= DT_UNDEFINED) {
return -1;
}
return data_type_size[data_type];
}

enum Format {
FORMAT_NCHW = 0, // NCHW
FORMAT_NHWC, // NHWC
FORMAT_ND, // Nd Tensor
FORMAT_NC1HWC0, // NC1HWC0
FORMAT_FRACTAL_Z, // 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, // NC1HWC0, C0 =4
FORMAT_FRACTAL_Z_C04, // FRACZ, C0 =4
FORMAT_CHWN,
FORMAT_FRACTAL_DECONV_SP_STRIDE8_TRANS,
FORMAT_HWCN,
FORMAT_NC1KHKWHWC0, // KH,KW kernel h& kernel w maxpooling max output format
FORMAT_BN_WEIGHT,
FORMAT_FILTER_HWCK, // filter input tensor format
FORMAT_HASHTABLE_LOOKUP_LOOKUPS = 20,
FORMAT_HASHTABLE_LOOKUP_KEYS,
FORMAT_HASHTABLE_LOOKUP_VALUE,
FORMAT_HASHTABLE_LOOKUP_OUTPUT,
FORMAT_HASHTABLE_LOOKUP_HITS = 24,
FORMAT_C1HWNCoC0,
FORMAT_MD,
FORMAT_NDHWC,
FORMAT_FRACTAL_ZZ,
FORMAT_FRACTAL_NZ,
FORMAT_NCDHW,
FORMAT_DHWCK, // 3D filter input tensor format
FORMAT_NDC1HWC0,
FORMAT_FRACTAL_Z_3D,
FORMAT_CN,
FORMAT_NC,
FORMAT_RESERVED,
FORMAT_ALL
};

struct TensorDescInfo {
Format format_ = FORMAT_RESERVED; // tbe op register support format
DataType dataType_ = DT_UNDEFINED; // tbe op register support datatype
};

enum DeviceType {
NPU = 0,
CPU = 1,
};

struct TensorType {
explicit TensorType(DataType dt) { dt_vec_.push_back(dt); }

TensorType(const std::initializer_list<DataType> &types) { dt_vec_ = types; }

static TensorType ALL() {
return TensorType{DT_BOOL, DT_COMPLEX128, DT_COMPLEX64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, DT_INT16,
DT_INT32, DT_INT64, DT_INT8, DT_QINT16, DT_QINT32, DT_QINT8, DT_QUINT16,
DT_QUINT8, DT_RESOURCE, DT_STRING, DT_UINT16, DT_UINT32, DT_UINT64, DT_UINT8};
}

static TensorType QuantifiedType() { return TensorType{DT_QINT16, DT_QINT32, DT_QINT8, DT_QUINT16, DT_QUINT8}; }

static TensorType OrdinaryType() {
return TensorType{DT_BOOL, DT_COMPLEX128, DT_COMPLEX64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, DT_INT16,
DT_INT32, DT_INT64, DT_INT8, DT_UINT16, DT_UINT32, DT_UINT64, DT_UINT8};
}

static TensorType BasicType() {
return TensorType{DT_COMPLEX128, DT_COMPLEX64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, DT_INT16,
DT_INT32, DT_INT64, DT_INT8, DT_QINT16, DT_QINT32, DT_QINT8,
DT_QUINT16, DT_QUINT8, DT_UINT16, DT_UINT32, DT_UINT64, DT_UINT8};
}

static TensorType NumberType() {
return TensorType{DT_COMPLEX128, DT_COMPLEX64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16, DT_INT16, DT_INT32, DT_INT64,
DT_INT8, DT_QINT32, DT_QINT8, DT_QUINT8, DT_UINT16, DT_UINT32, DT_UINT64, DT_UINT8};
}

static TensorType RealNumberType() {
return TensorType{DT_DOUBLE, DT_FLOAT, DT_FLOAT16, DT_INT16, DT_INT32, DT_INT64,
DT_INT8, DT_UINT16, DT_UINT32, DT_UINT64, DT_UINT8};
}

static TensorType ComplexDataType() { return TensorType{DT_COMPLEX128, DT_COMPLEX64}; }

static TensorType IntegerDataType() {
return TensorType{DT_INT16, DT_INT32, DT_INT64, DT_INT8, DT_UINT16, DT_UINT32, DT_UINT64, DT_UINT8};
}

static TensorType SignedDataType() { return TensorType{DT_INT16, DT_INT32, DT_INT64, DT_INT8}; }

static TensorType UnsignedDataType() { return TensorType{DT_UINT16, DT_UINT32, DT_UINT64, DT_UINT8}; }

static TensorType FloatingDataType() { return TensorType{DT_DOUBLE, DT_FLOAT, DT_FLOAT16}; }

static TensorType IndexNumberType() { return TensorType{DT_INT32, DT_INT64}; }

static TensorType UnaryDataType() { return TensorType{DT_COMPLEX128, DT_COMPLEX64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16}; }

static TensorType FLOAT() { return TensorType{DT_FLOAT, DT_FLOAT16}; }

std::vector<DataType> dt_vec_;
};
} // namespace ge

namespace domi {
enum class ImplyType : unsigned int {
BUILDIN = 0, // Built in operator, normally executed by OME
TVM, // Compile to TVM bin file for execution
CUSTOM, // User defined calculation logic, executed by CPU
AI_CPU, // AICPU
CCE, // Cce
GELOCAL, // GE local, do node need execute by device
HCCL, // Hccl
INVALID = 0xFFFFFFFF,
};
} // namespace domi

#endif // INC_EXTERNAL_GRAPH_TYPES_H_

+ 134
- 0
inc/external/graph/usr_types.h View File

@@ -0,0 +1,134 @@
/**
* 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 INC_EXTERNAL_GRAPH_USR_TYPES_H_
#define INC_EXTERNAL_GRAPH_USR_TYPES_H_

#include <atomic>
#include <memory>
#include <vector>

namespace ge {
#define USR_TYPE_DEC(type, name) \
inline void set_##name(const type &value) { name = value; } \
type *mutable_##name() { return &name; }

#define USR_TYPE_HAS_DEC(type, name) \
inline void set_##name(const type &value) { name = value; } \
\
private: \
bool has_mutable_##name{false}; \
\
public: \
bool has_##name() const { return (has_mutable_##name) || QuantizeFactorHasData(name); } \
type *mutable_##name() { \
has_mutable_##name = true; \
return &name; \
}

#define USR_TYPE_BYTES_DEC(name) \
inline void clear_##name() { name.clear(); } \
inline void set_##name(const void *value, size_t size) { \
name.assign(reinterpret_cast<uint8_t *>(const_cast<void *>(value)), \
reinterpret_cast<uint8_t *>(const_cast<void *>(value)) + size); \
}

enum UsrQuantizeScaleType { USR_VECTOR_SCALE = 0, USR_SCALAR_SCALE = 1 };
enum UsrQuantizeScaleMode { USR_NORMAL_MODE = 0, USR_SQRT_MODE = 1 };
enum UsrQuantizeAlgorithm {
USR_NON_OFFSET_ALGO = 0,
USR_HALF_OFFSET_ALGO = 1,
USR_ALL_OFFSET_ALGO = 2,
};

struct UsrQuantizeFactor {
public:
// QuantizeScaleMode scale_mode;
UsrQuantizeScaleMode scale_mode{USR_NORMAL_MODE};
std::vector<uint8_t> scale_value;
int64_t scale_offset{0};
std::vector<uint8_t> offset_data_value;
int64_t offset_data_offset{0};
std::vector<uint8_t> offset_weight_value;
int64_t offset_weight_offset{0};
std::vector<uint8_t> offset_pad_value;
int64_t offset_pad_offset{0};

USR_TYPE_DEC(UsrQuantizeScaleMode, scale_mode);
USR_TYPE_BYTES_DEC(scale_value);

USR_TYPE_DEC(int64_t, scale_offset);
USR_TYPE_BYTES_DEC(offset_data_value);
USR_TYPE_DEC(int64_t, offset_data_offset);

USR_TYPE_BYTES_DEC(offset_weight_value);
USR_TYPE_DEC(int64_t, offset_weight_offset);
USR_TYPE_BYTES_DEC(offset_pad_value);
USR_TYPE_DEC(int64_t, offset_pad_offset);
};

static inline bool QuantizeFactorHasData(const UsrQuantizeFactor &factor) {
return factor.scale_value.size() > 0 || factor.offset_data_value.size() > 0 ||
factor.offset_weight_value.size() > 0 || factor.offset_pad_value.size() > 0;
}

struct UsrQuantizeCalcFactor {
public:
std::vector<uint8_t> offsetw;
int64_t offsetw_offset{0};
std::vector<uint8_t> offsetd;
int64_t offsetd_offset{0};
std::vector<uint8_t> scalereq;
int64_t scaledreq_offset{0};
std::vector<uint8_t> offsetdnext;
int64_t offsetdnext_offset{0};

USR_TYPE_BYTES_DEC(offsetw);
USR_TYPE_DEC(int64_t, offsetw_offset);
USR_TYPE_BYTES_DEC(offsetd);
USR_TYPE_DEC(int64_t, offsetd_offset);
USR_TYPE_BYTES_DEC(scalereq);
USR_TYPE_DEC(int64_t, scaledreq_offset);
USR_TYPE_BYTES_DEC(offsetdnext);
USR_TYPE_DEC(int64_t, offsetdnext_offset);
};

static inline bool QuantizeFactorHasData(const UsrQuantizeCalcFactor &factor) {
return factor.offsetw.size() > 0 || factor.offsetd.size() > 0 || factor.scalereq.size() > 0 ||
factor.offsetdnext.size() > 0;
}

struct UsrQuantizeFactorParams {
UsrQuantizeAlgorithm quantize_algo{USR_NON_OFFSET_ALGO};
UsrQuantizeScaleType scale_type{USR_VECTOR_SCALE};
UsrQuantizeFactor quantize_param;
UsrQuantizeFactor dequantize_param;
UsrQuantizeFactor requantize_param;
UsrQuantizeCalcFactor quantizecalc_param;
USR_TYPE_DEC(UsrQuantizeAlgorithm, quantize_algo);
USR_TYPE_DEC(UsrQuantizeScaleType, scale_type);
USR_TYPE_HAS_DEC(UsrQuantizeFactor, quantize_param);
USR_TYPE_HAS_DEC(UsrQuantizeFactor, dequantize_param);
USR_TYPE_HAS_DEC(UsrQuantizeFactor, requantize_param);
USR_TYPE_HAS_DEC(UsrQuantizeCalcFactor, quantizecalc_param);
};

#undef USR_TYPE_DEC
#undef USR_TYPE_HAS_DEC
#undef USR_TYPE_BYTES_DEC
} // namespace ge

#endif // INC_EXTERNAL_GRAPH_USR_TYPES_H_

+ 199
- 0
inc/external/register/register.h View File

@@ -0,0 +1,199 @@
/**
* 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 INC_EXTERNAL_REGISTER_REGISTER_H_
#define INC_EXTERNAL_REGISTER_REGISTER_H_

#include <google/protobuf/message.h>
#include <functional>
#include <initializer_list>
#include <map>
#include <memory>
#include <set>
#include <string>
#include <utility>
#include <unordered_map>
#include <vector>

#include "graph/operator.h"
#include "register/register_error_codes.h"
#include "register/register_fmk_types.h"
#include "register/register_types.h"

using std::unique_ptr;
using std::map;
using std::make_shared;
using std::to_string;
using std::string;
using std::pair;
using std::vector;

namespace ge {
class Operator;
class TensorDesc;
class Tensor;
class TBEPluginManager;
}

namespace domi {
struct OpOutput {
ge::Operator op;
// The output name of op
std::string outputName;
};

struct InferShapeContext {
ge::Operator op;
// Input name, input
std::map<std::string, OpOutput> inputs;
};

struct InferShapeOutput {
std::vector<ge::TensorDesc> outputDescs;
std::vector<uint32_t> realDimCnt;
};

enum OmgMoveTypeToAttr {
OMG_MOVE_TYPE_DTYPE = 0,
OMG_MOVE_TYPE_VALUE,
OMG_MOVE_TYPE_SHAPE,
OMG_MOVE_TYPE_FORMAT,
OMG_MOVE_TYPE_AXIS,
OMG_MOVE_TYPE_SCALAR_VALUE,
OMG_REMOVE_TYPE_WITH_COND = 1000,
};

struct MoveInputToAttrStu {
int inputIdx;
std::string attrName;
OmgMoveTypeToAttr moveType;
bool attrValue;
};

Status AutoMappingFn(const google::protobuf::Message *op_src, ge::Operator &op);
Status AutoMappingFnDynamic(const google::protobuf::Message *op_src, ge::Operator &op,
std::map<std::string, std::pair<std::string, std::string>> dynamic_name_attr_value,
int in_pos = -1, int out_pos = -1);
using google::protobuf::Message;

using ParseParamFunc = std::function<domi::Status(const google::protobuf::Message *, ge::Operator &)>;
using InferShapeFunc = std::function<domi::Status(const ge::Operator &, std::vector<ge::TensorDesc> &)>;
using InferShapeFuncV2 = std::function<domi::Status(const InferShapeContext &, InferShapeOutput &)>;
using GetWorkspaceSizeFunc = std::function<domi::Status(const ge::Operator &, std::vector<int64_t> &)>;
using UpdateOpDescFunc = std::function<domi::Status(ge::Operator &)>;
using BuildTeBinFunc = std::function<domi::Status(const ge::Operator &, TEBinInfo &)>;

class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpRegistrationData {
public:
OpRegistrationData(const std::string &om_optype);

~OpRegistrationData();

OpRegistrationData &FrameworkType(const domi::FrameworkType &fmk_type);

OpRegistrationData &OriginOpType(const std::initializer_list<std::string> &ori_optype_list);

OpRegistrationData &OriginOpType(const std::string &ori_optype);

OpRegistrationData &ParseParamsFn(const ParseParamFunc &parseParamFn);

OpRegistrationData &InferShapeAndTypeFn(const InferShapeFunc &inferShapeFn);

OpRegistrationData &InferShapeAndTypeFn(const InferShapeFuncV2 &inferShapeFn);

OpRegistrationData &UpdateOpDescFn(const UpdateOpDescFunc &updateOpDescFn);

OpRegistrationData &GetWorkspaceSizeFn(const GetWorkspaceSizeFunc &getWorkspaceSizeFn);

OpRegistrationData &TEBinBuildFn(const BuildTeBinFunc &buildTeBinFn);

OpRegistrationData &ImplyType(const domi::ImplyType &imply_type);

OpRegistrationData &Formats(const std::initializer_list<domi::tagDomiTensorFormat> &input_formats,
const std::initializer_list<domi::tagDomiTensorFormat> &output_formats);

OpRegistrationData &WeightFormats(const std::initializer_list<domi::tagDomiTensorFormat> &weight_formats);

OpRegistrationData &InputFormat(const std::initializer_list<std::initializer_list<ge::Format>> &inputFormats);
OpRegistrationData &OutputFormat(const std::initializer_list<std::initializer_list<ge::Format>> &outputFormats);
OpRegistrationData &InputDataType(const std::initializer_list<std::initializer_list<ge::DataType>> &inputDataTypes);
OpRegistrationData &OutputDataType(const std::initializer_list<std::initializer_list<ge::DataType>> &outputDataTypes);
OpRegistrationData &InputLimitedTensorDescInfo(
const std::initializer_list<std::initializer_list<ge::TensorDescInfo>> &limitedTensorDescs);
OpRegistrationData &OutputLimitedTensorDescInfo(
const std::initializer_list<std::initializer_list<ge::TensorDescInfo>> &limitedTensorDescs);

OpRegistrationData &MoveInputToAttr(int inputIdx, const std::string &attrName, OmgMoveTypeToAttr moveType);
OpRegistrationData &DelInputWithCond(int inputIdx, const std::string &attrName, bool attrValue);

private:
domi::FrameworkType fmk_type_; // Framework type
std::set<std::string> ori_optype_set_; // OP type in the original model, there may be multiple
std::string om_optype_; // OP type in OM model
domi::ImplyType imply_type_; // Execution type
std::vector<domi::tagDomiTensorFormat> input_formats_; // Data formats supported by operator input
std::vector<domi::tagDomiTensorFormat> output_formats_; // Data formats supported by operator output
std::vector<domi::tagDomiTensorFormat> weight_formats_; // Data format supported by operator weight

ParseParamFunc parseParamFn_; // ParseParam function
InferShapeFunc inferShapeFn_; // InferShape function
InferShapeFuncV2 inferShapeFnV2_; // InferShape function
GetWorkspaceSizeFunc getWorkspaceSizeFn_; // GetWorkspaceSizeFunc function
UpdateOpDescFunc updateOpDescFn_;
BuildTeBinFunc buildTeBinFn_;
// Input formats list supported by tbe operators
std::vector<std::vector<ge::Format>> supportedInputFormats_;
// Output formats list supported by tbe operators
std::vector<std::vector<ge::Format>> supportedOutputFormats_;
// Input datatypes list supported by tbe operators
std::vector<std::vector<ge::DataType>> supportedInputDataTypes_;
// Output datatypes list supported by tbe operators
std::vector<std::vector<ge::DataType>> supportedOutputDataTypes_;
// Input tensordesinfo list supported by tbe operator
std::vector<std::vector<ge::TensorDescInfo>> inputLimitedTensorDescs_;
// Output tensordesinfo list supported by tbe operator
std::vector<std::vector<ge::TensorDescInfo>> outputLimitedTensorDescs_;

std::vector<MoveInputToAttrStu> moveInputToAttrVec_;
friend class OpRegistry;
friend class OpRegistrationTbe;
friend class ge::TBEPluginManager;
};

class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY OpReceiver {
public:
OpReceiver(OpRegistrationData &reg_data);
~OpReceiver() {}
};

#define REGISTER_CUSTOM_OP(name) REGISTER_CUSTOM_OP_UNIQ_HELPER(__COUNTER__, name)
#define REGISTER_CUSTOM_OP_UNIQ_HELPER(ctr, name) REGISTER_CUSTOM_OP_UNIQ(ctr, name)
#define REGISTER_CUSTOM_OP_UNIQ(ctr, name) \
static OpReceiver register_op##ctr \
__attribute__((unused)) = \
OpRegistrationData(name)
} // namespace domi

namespace ge {
using OpOutput = domi::OpOutput;
using InferShapeContext = domi::InferShapeContext;
using InferShapeOutput = domi::InferShapeOutput;
using OmgMoveTypeToAttr = domi::OmgMoveTypeToAttr;
using MoveInputToAttrStu = domi::MoveInputToAttrStu;
using OpRegistrationData = domi::OpRegistrationData;
using OpReceiver = domi::OpReceiver;
}
#endif // INC_EXTERNAL_REGISTER_REGISTER_H_

+ 38
- 0
inc/external/register/register_error_codes.h View File

@@ -0,0 +1,38 @@
/**
* 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 INC_EXTERNAL_REGISTER_REGISTER_ERROR_CODES_H_
#define INC_EXTERNAL_REGISTER_REGISTER_ERROR_CODES_H_

#define SYSID_FWK 3 // Subsystem ID
#define MODID_COMMON 0 // Common module ID

#define DECLARE_ERRORNO(sysid, modid, name, value) \
const domi::Status name = \
((0xFF & ((uint8_t)sysid)) << 24) | ((0xFF & ((uint8_t)modid)) << 16) | (0xFFFF & ((uint16_t)value));

#define DECLARE_ERRORNO_COMMON(name, value) DECLARE_ERRORNO(SYSID_FWK, MODID_COMMON, name, value)

namespace domi {
using Status = uint32_t;

// General error code
DECLARE_ERRORNO(0, 0, SUCCESS, 0);
DECLARE_ERRORNO(0xFF, 0xFF, FAILED, 0xFFFFFFFF);
DECLARE_ERRORNO_COMMON(PARAM_INVALID, 1); // 50331649
} // namespace domi

#endif // INC_EXTERNAL_REGISTER_REGISTER_ERROR_CODES_H_

+ 42
- 0
inc/external/register/register_fmk_types.h View File

@@ -0,0 +1,42 @@
/**
* 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 INC_EXTERNAL_REGISTER_REGISTER_FMK_TYPES_H_
#define INC_EXTERNAL_REGISTER_REGISTER_FMK_TYPES_H_

#include <string>

namespace domi {
///
/// @ingroup domi_omg
/// @brief AI framework types
///
enum FrameworkType {
FMK_TYPE_C = 0,
FMK_TYPE_MINDSPORE = 1,
FMK_TYPE_T = 3,
FMK_TYPE_A_NN,
FMK_TYPE_RESERVED,
};

struct TEBinInfo {
std::string bin_file_path;
std::string json_file_path;
std::string ddk_version;
};
} // namespace domi

#endif // INC_EXTERNAL_REGISTER_REGISTER_FMK_TYPES_H_

+ 55
- 0
inc/external/register/register_types.h View File

@@ -0,0 +1,55 @@
/**
* 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 INC_EXTERNAL_REGISTER_REGISTER_TYPES_H_
#define INC_EXTERNAL_REGISTER_REGISTER_TYPES_H_

namespace domi {
#ifdef HOST_VISIBILITY
#define FMK_FUNC_HOST_VISIBILITY __attribute__((visibility("default")))
#else
#define FMK_FUNC_HOST_VISIBILITY
#endif
#ifdef DEV_VISIBILITY
#define FMK_FUNC_DEV_VISIBILITY __attribute__((visibility("default")))
#else
#define FMK_FUNC_DEV_VISIBILITY
#endif

/// CCE defined constant

///
/// @ingroup domi
/// @brief original tensor type
///
typedef enum tagDomiTensorFormat {
DOMI_TENSOR_NCHW = 0, // < NCHW
DOMI_TENSOR_NHWC, // < NHWC
DOMI_TENSOR_ND, // < Nd Tensor
DOMI_TENSOR_NC1HWC0, // < NC1HWC0
DOMI_TENSOR_FRACTAL_Z, // < FRACTAL_Z
DOMI_TENSOR_NC1C0HWPAD,
DOMI_TENSOR_NHWC1C0,
DOMI_TENSOR_FSR_NCHW,
DOMI_TENSOR_FRACTAL_DECONV,
DOMI_TENSOR_BN_WEIGHT,
DOMI_TENSOR_CHWN, // Android NN Depth CONV
DOMI_TENSOR_FILTER_HWCK, // filter input tensor format
DOMI_TENSOR_RESERVED
} domiTensorFormat_t;
} // namespace domi

#endif // INC_EXTERNAL_REGISTER_REGISTER_TYPES_H_

+ 22
- 0
inc/framework/common/aicpu_op.h View File

@@ -0,0 +1,22 @@
/**
* 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 INC_FRAMEWORK_COMMON_AICPU_OP_H_
#define INC_FRAMEWORK_COMMON_AICPU_OP_H_

#include "cce/customize.h"

#endif // INC_FRAMEWORK_COMMON_AICPU_OP_H_

+ 96
- 0
inc/framework/common/debug/ge_log.h View File

@@ -0,0 +1,96 @@
/**
* 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 INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_
#define INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_

#include <cstdint>

#include "framework/common/ge_inner_error_codes.h"
#include "toolchain/slog.h"

#define GE_MODULE_NAME GE

// trace status of log
enum TraceStatus { TRACE_INIT = 0, TRACE_RUNNING, TRACE_WAITING, TRACE_STOP };

#define GELOGE(ERROR_CODE, ...) GE_LOG_ERROR(GE_MODULE_NAME, ERROR_CODE, __VA_ARGS__)
#define GELOGW(...) GE_LOG_WARN(GE_MODULE_NAME, __VA_ARGS__)
#define GELOGI(...) GE_LOG_INFO(GE_MODULE_NAME, __VA_ARGS__)
#define GELOGD(...) GE_LOG_DEBUG(GE_MODULE_NAME, __VA_ARGS__)
#define GEEVENT(...) GE_LOG_EVENT(GE_MODULE_NAME, __VA_ARGS__)
#define GELOGO(...) GE_LOG_OPLOG(GE_MODULE_NAME, __VA_ARGS__)
#define GELOGT(VALUE, ...) GE_LOG_TRACE(GE_MODULE_NAME, VALUE, __VA_ARGS__)

inline bool IsLogEnable(int module_name, int log_level) noexcept {
int32_t enable_event = 0;
int32_t dlog_level = dlog_getlevel(module_name, &enable_event);
if (dlog_level <= log_level) {
return true;
}
return false;
}

#define GE_TIMESTAMP_START(stage) uint64_t startUsec_##stage = ge::GetCurrentTimestap()

#define GE_TIMESTAMP_END(stage, stage_name) \
do { \
uint64_t endUsec_##stage = ge::GetCurrentTimestap(); \
GEEVENT("[GEPERFTRACE] The time cost of %s is [%lu] micro second.", (stage_name), \
(endUsec_##stage - startUsec_##stage)); \
} while (0);

#define GE_TIMESTAMP_CALLNUM_START(stage) \
uint64_t startUsec_##stage = ge::GetCurrentTimestap(); \
uint64_t call_num_of##stage = 0; \
uint64_t time_of##stage = 0

#define GE_TIMESTAMP_RESTART(stage) (startUsec_##stage = ge::GetCurrentTimestap())

#define GE_TIMESTAMP_ADD(stage) \
time_of##stage += ge::GetCurrentTimestap() - startUsec_##stage; \
call_num_of##stage++

#define GE_TIMESTAMP_CALLNUM_END(stage, stage_name) \
GEEVENT("[GEPERFTRACE] The time cost of %s is [%lu] micro second, call num is %lu", (stage_name), time_of##stage, \
call_num_of##stage)

#define GE_LOG_ERROR(MOD_NAME, ERROR_CODE, fmt, ...) \
dlog_error(static_cast<int>(MOD_NAME), "%s: ErrorNo: %d(%s) " fmt, __FUNCTION__, ERROR_CODE, \
((GE_GET_ERRORNO_STR(ERROR_CODE)).c_str()), ##__VA_ARGS__)
#define GE_LOG_WARN(MOD_NAME, fmt, ...) \
if (IsLogEnable(static_cast<int>(MOD_NAME), DLOG_WARN)) \
dlog_warn(static_cast<int>(MOD_NAME), "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
#define GE_LOG_INFO(MOD_NAME, fmt, ...) \
if (IsLogEnable(static_cast<int>(MOD_NAME), DLOG_INFO)) \
dlog_info(static_cast<int>(MOD_NAME), "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
#define GE_LOG_DEBUG(MOD_NAME, fmt, ...) \
if (IsLogEnable(static_cast<int>(MOD_NAME), DLOG_DEBUG)) \
dlog_debug(static_cast<int>(MOD_NAME), "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
#define GE_LOG_EVENT(MOD_NAME, fmt, ...) dlog_event(static_cast<int>(MOD_NAME), "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
#define GE_LOG_OPLOG(MOD_NAME, fmt, ...) \
Dlog(static_cast<int>(MOD_NAME), DLOG_OPLOG, "%s:" fmt, __FUNCTION__, ##__VA_ARGS__)
#define GE_LOG_TRACE(MOD_NAME, value, fmt, ...) \
do { \
TraceStatus stat = value; \
const char *const TraceStatStr[] = {"INIT", "RUNNING", "WAITING", "STOP"}; \
int idx = static_cast<int>(stat); \
char *k = const_cast<char *>("status"); \
char *v = const_cast<char *>(TraceStatStr[idx]); \
KeyValue kv = {k, v}; \
DlogWithKV(static_cast<int>(MOD_NAME), DLOG_TRACE, &kv, 1, "%s:" fmt, __FUNCTION__, ##__VA_ARGS__); \
} while (0)
#endif // INC_FRAMEWORK_COMMON_DEBUG_GE_LOG_H_

+ 254
- 0
inc/framework/common/debug/log.h View File

@@ -0,0 +1,254 @@
/**
* 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 INC_FRAMEWORK_COMMON_DEBUG_LOG_H_
#define INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

#include <string>

#include "cce/cce_def.hpp"
#include "common/string_util.h"
#include "common/util.h"
#include "dlog/log.h"
#include "framework/common/debug/ge_log.h"
#include "ge/ge_api_error_codes.h"

using cce::CC_STATUS_SUCCESS;
using cce::ccStatus_t;

#if !defined(__ANDROID__) && !defined(ANDROID)
#define DOMI_LOGE(...) DAV_LOGE("DOMI", __VA_ARGS__)
#else
#include <android/log.h>
#if defined(BUILD_VERSION_PERF)
#define DOMI_LOGE(fmt, ...)
#else
// The Android system has strict log control. Do not modify the log.
#define DOMI_LOGE(fmt, ...) \
__android_log_print(ANDROID_LOG_ERROR, "NPU_FMK", "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#endif
#endif

// ge marco
#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__); \
}

// If expr is not SUCCESS, print the log and return the same value
#define GE_CHK_STATUS_RET(expr, ...) \
do { \
const ge::Status _status = (expr); \
if (_status != ge::SUCCESS) { \
GELOGE(ge::FAILED, __VA_ARGS__); \
return _status; \
} \
} while (0);

// If expr is not SUCCESS, print the log and do not execute return
#define GE_CHK_STATUS(expr, ...) \
do { \
const ge::Status _status = (expr); \
if (_status != ge::SUCCESS) { \
GELOGE(ge::FAILED, __VA_ARGS__); \
} \
} while (0);

// If expr is not SUCCESS, return the same value
#define GE_CHK_STATUS_RET_NOLOG(expr) \
do { \
const ge::Status _status = (expr); \
if (_status != ge::SUCCESS) { \
return _status; \
} \
} while (0);

// If expr is not SUCCESS, print the log and execute a custom statement
#define GE_CHK_STATUS_EXEC(expr, exec_expr, ...) \
do { \
const ge::Status _status = (expr); \
GE_CHK_BOOL_EXEC(_status == SUCCESS, exec_expr, __VA_ARGS__); \
} while (0);

// If expr is not true, print the log and return the specified status
#define GE_CHK_BOOL_RET_STATUS(expr, _status, ...) \
do { \
bool b = (expr); \
if (!b) { \
std::string msg; \
(void)msg.append(ge::StringUtils::FormatString(__VA_ARGS__)); \
(void)msg.append( \
ge::StringUtils::FormatString(" Error Code:0x%X(%s)", _status, GET_ERRORNO_STR(_status).c_str())); \
GELOGE(ge::FAILED, "%s", msg.c_str()); \
return _status; \
} \
} while (0);

// If expr is not true, 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, print the log and execute a custom statement
#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, print the log and execute a custom statement
#define GE_CHK_BOOL_EXEC_WARN(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (!b) { \
GELOGW(__VA_ARGS__); \
exec_expr; \
} \
};
// If expr is not true, print the log and execute a custom statement
#define GE_CHK_BOOL_EXEC_INFO(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (!b) { \
GELOGI(__VA_ARGS__); \
exec_expr; \
} \
};

// If expr is true, print logs and execute custom statements
#define GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (b) { \
GELOGE(ge::FAILED, __VA_ARGS__); \
exec_expr; \
} \
};
// If expr is true, print the Information log and execute a custom statement
#define GE_CHK_TRUE_EXEC_INFO(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (b) { \
GELOGI(__VA_ARGS__); \
exec_expr; \
} \
};

// If expr is not SUCCESS, print the log and execute the expression + return _status
#define GE_CHK_BOOL_TRUE_EXEC_RET_STATUS(expr, _status, exec_expr, ...) \
{ \
bool b = (expr); \
if (b) { \
GELOGE(ge::FAILED, __VA_ARGS__); \
exec_expr; \
return _status; \
} \
};

// If expr is not true, execute a custom statement
#define GE_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
{ \
bool b = (expr); \
if (!b) { \
exec_expr; \
} \
};

// -----------------runtime related macro definitions-------------------------------
// If expr is not RT_ERROR_NONE, print the log
#define GE_CHK_RT(expr) \
do { \
rtError_t _rt_ret = (expr); \
if (_rt_ret != RT_ERROR_NONE) { \
GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
} \
} while (0);

// If expr is not RT_ERROR_NONE, print the log and execute the exec_expr expression
#define GE_CHK_RT_EXEC(expr, exec_expr) \
{ \
rtError_t _rt_ret = (expr); \
if (_rt_ret != RT_ERROR_NONE) { \
GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
exec_expr; \
} \
}

// If expr is not RT_ERROR_NONE, print the log and return
#define GE_CHK_RT_RET(expr) \
do { \
rtError_t _rt_ret = (expr); \
if (_rt_ret != RT_ERROR_NONE) { \
GELOGE(ge::RT_FAILED, "Call rt api failed, ret: 0x%X", _rt_ret); \
return ge::RT_FAILED; \
} \
} while (0);

// ------------------------cce related macro definitions----------------------------
// If expr is not CC_STATUS_SUCCESS, print the log
#define GE_CHK_CCE(expr) \
do { \
ccStatus_t _cc_ret = (expr); \
if (_cc_ret != CC_STATUS_SUCCESS) { \
GELOGE(ge::CCE_FAILED, "Call cce api failed, ret: 0x%X", _cc_ret); \
} \
} while (0);

// If expr is not CC_STATUS_SUCCESS, print the log and return
#define GE_CHK_CCE_RET(expr) \
do { \
ccStatus_t _cc_ret = (expr); \
if (_cc_ret != CC_STATUS_SUCCESS) { \
GELOGE(ge::CCE_FAILED, "Call cce api failed, ret: 0x%X", _cc_ret); \
return ge::CCE_FAILED; \
} \
} while (0);

// If expr is true, execute exec_expr without printing logs
#define GE_IF_BOOL_EXEC(expr, exec_expr) \
{ \
if (expr) { \
exec_expr; \
} \
}

// If make_shared is abnormal, print the log and execute the statement
#define GE_MAKE_SHARED(exec_expr0, exec_expr1) \
try { \
exec_expr0; \
} catch (const std::bad_alloc &) { \
GELOGE(ge::FAILED, "Make shared failed"); \
exec_expr1; \
}

#endif // INC_FRAMEWORK_COMMON_DEBUG_LOG_H_

+ 85
- 0
inc/framework/common/fmk_error_codes.h View File

@@ -0,0 +1,85 @@
/**
* 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 INC_FRAMEWORK_COMMON_FMK_ERROR_CODES_H_
#define INC_FRAMEWORK_COMMON_FMK_ERROR_CODES_H_

#include <map>
#include <string>

#include "framework/common/fmk_types.h"
#include "register/register_error_codes.h"

#define MODID_OMG 1 // OMG module ID
#define MODID_OME 2 // OME module ID
#define MODID_CALIBRATION 3 // Calibration module ID

// Each module uses the following four macros to define error codes:
#define DECLARE_ERRORNO_OMG(name, value) DECLARE_ERRORNO(SYSID_FWK, MODID_OMG, name, value)
#define DECLARE_ERRORNO_OME(name, value) DECLARE_ERRORNO(SYSID_FWK, MODID_OME, name, value)
#define DECLARE_ERRORNO_CALIBRATION(name, value) DECLARE_ERRORNO(SYSID_FWK, MODID_CALIBRATION, name, value)

#define DEF_ERRORNO(name, desc) const ErrorNoRegisterar g_##name##_errorno(name, desc);

// Interface for Obtaining Error Code Description
#define GET_ERRORNO_STR(value) domi::StatusFactory::Instance()->GetErrDesc(value)

namespace domi {
class StatusFactory {
public:
static StatusFactory *Instance();

void RegisterErrorNo(uint32_t err, const std::string &desc);

std::string GetErrDesc(uint32_t err);

protected:
StatusFactory() {}
~StatusFactory() {}

private:
std::map<uint32_t, std::string> err_desc_;
};

class ErrorNoRegisterar {
public:
ErrorNoRegisterar(uint32_t err, const std::string &desc) { StatusFactory::Instance()->RegisterErrorNo(err, desc); }
~ErrorNoRegisterar() {}
};

// Common errocode
DECLARE_ERRORNO_COMMON(MEMALLOC_FAILED, 0); // 50331648
DECLARE_ERRORNO_COMMON(CCE_FAILED, 2); // 50331650
DECLARE_ERRORNO_COMMON(RT_FAILED, 3); // 50331651
DECLARE_ERRORNO_COMMON(INTERNAL_ERROR, 4); // 50331652
DECLARE_ERRORNO_COMMON(CSEC_ERROR, 5); // 50331653
DECLARE_ERRORNO_COMMON(TEE_ERROR, 6); // 50331653
DECLARE_ERRORNO_COMMON(UNSUPPORTED, 100);
DECLARE_ERRORNO_COMMON(OUT_OF_MEMORY, 101);

// Omg errorcode
DECLARE_ERRORNO_OMG(PARSE_MODEL_FAILED, 0);
DECLARE_ERRORNO_OMG(PARSE_WEIGHTS_FAILED, 1);
DECLARE_ERRORNO_OMG(NOT_INITIALIZED, 2);
DECLARE_ERRORNO_OMG(TIMEOUT, 3);

// Ome errorcode
DECLARE_ERRORNO_OME(MODEL_NOT_READY, 0);
DECLARE_ERRORNO_OME(PUSH_DATA_FAILED, 1);
DECLARE_ERRORNO_OME(DATA_QUEUE_ISFULL, 2);
} // namespace domi

#endif // INC_FRAMEWORK_COMMON_FMK_ERROR_CODES_H_

+ 23
- 0
inc/framework/common/fmk_types.h View File

@@ -0,0 +1,23 @@
/**
* 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 INC_FRAMEWORK_COMMON_FMK_TYPES_H_
#define INC_FRAMEWORK_COMMON_FMK_TYPES_H_

#include "graph/types.h"
#include "register/register_types.h"

#endif // INC_FRAMEWORK_COMMON_FMK_TYPES_H_

+ 40
- 0
inc/framework/common/ge_format_util.h View File

@@ -0,0 +1,40 @@
/**
* 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 INC_FRAMEWORK_COMMON_GE_FORMAT_UTIL_H_
#define INC_FRAMEWORK_COMMON_GE_FORMAT_UTIL_H_

#include <vector>

#include "common/ge_inner_error_codes.h"
#include "graph/tensor.h"

namespace ge {
class GeFormatUtil {
public:
///
/// @name TransShape
/// @brief transform the shape of tensor according to destination format
/// @param [in] src_desc source tensor desc
/// @param [in] dst_format destination format
/// @param [out] dst_shape destination shape
/// @return Status
///
static Status TransShape(const TensorDesc &src_desc, Format dst_format, std::vector<int64_t> &dst_shape);
};
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_GE_FORMAT_UTIL_H_

+ 295
- 0
inc/framework/common/ge_inner_error_codes.h View File

@@ -0,0 +1,295 @@
/**
* 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 INC_FRAMEWORK_COMMON_GE_INNER_ERROR_CODES_H_
#define INC_FRAMEWORK_COMMON_GE_INNER_ERROR_CODES_H_

#include <map>
#include <string>

#include "ge/ge_api_error_codes.h"

namespace ge {
// System ID
enum SystemIdType { kSysidGE = 8 };

// Runtime location
enum LogRuntime {
KRtHost = 0b01,
kRtDevice = 0b10,
};

// Sub model
enum SubModuleId {
kCommonModule = 0,
kClientModule = 1,
kInitModule = 2,
kSessionModule = 3,
kGraphModule = 4,
kEngineMOdule = 5,
kOpsModule = 6,
kPluginModule = 7,
kRuntimeModule = 8,
kExecutorModule = 9,
kGeneratorModule = 10,
};

// Error code type
enum ErrorCodeType {
kErrorCode = 0b01,
kExceptionCode = 0b10,
};

// Error level
enum ErrorLevel {
kCommonLevel = 0b000,
kSuggestionLevel = 0b001,
kMinorLevel = 0b010,
kMajorLevel = 0b011,
kCriticalLevel = 0b100,
};

// The error code is defined by the following macros
#define GE_ERRORNO_COMMON(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kCommonModule, name, value, desc)
#define GE_ERRORNO_CLIENT(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kClientModule, name, value, desc)
#define GE_ERRORNO_INIT(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kInitModule, name, value, desc)
#define GE_ERRORNO_SESSION(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kSessionModule, name, value, desc)
#define GE_ERRORNO_GRAPH(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kGraphModule, name, value, desc)
#define GE_ERRORNO_ENGINE(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kEngineMOdule, name, value, desc)
#define GE_ERRORNO_OPS(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kOpsModule, name, value, desc)
#define GE_ERRORNO_PLUGIN(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kPluginModule, name, value, desc)
#define GE_ERRORNO_RUNTIME(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kRuntimeModule, name, value, desc)
#define GE_ERRORNO_EXECUTOR(name, value, desc) \
GE_ERRORNO(kRtDevice, kErrorCode, kCommonLevel, kSysidGE, kExecutorModule, name, value, desc)
#define GE_ERRORNO_GENERATOR(name, value, desc) \
GE_ERRORNO(KRtHost, kErrorCode, kCommonLevel, kSysidGE, kGeneratorModule, name, value, desc)

// Get the description of the error code
#define GE_GET_ERRORNO_STR(value) ge::StatusFactory::Instance()->GetErrDesc(value)

// Common module error code definition
GE_ERRORNO_COMMON(MEMALLOC_FAILED, 0, "Failed to allocate memory!"); // 1343225856
GE_ERRORNO_COMMON(PARAM_INVALID, 1, "Parameter's invalid!"); // 1343225857
GE_ERRORNO_COMMON(CCE_FAILED, 2, "Failed to call CCE API!"); // 1343225858
GE_ERRORNO_COMMON(RT_FAILED, 3, "Failed to call runtime API!"); // 1343225859
GE_ERRORNO_COMMON(INTERNAL_ERROR, 4, "Internal errors"); // 1343225860
GE_ERRORNO_COMMON(CSEC_ERROR, 5, "Failed to call libc_sec API!"); // 1343225861
GE_ERRORNO_COMMON(TEE_ERROR, 6, "Failed to call tee API!"); // 1343225862
GE_ERRORNO_COMMON(END_OF_SEQUENCE, 7, "End of sequence!"); // 1343225863

// Error code for plugin manager
GE_ERRORNO_COMMON(GE_PLGMGR_PATH_INVALID, 30, "Path is invalid!"); // 1343225886
GE_ERRORNO_COMMON(GE_PLGMGR_SO_NOT_EXIST, 31, "Failed to find any valid so file!"); // 1343225887
GE_ERRORNO_COMMON(GE_PLGMGR_FUNC_NOT_EXIST, 32, "Failed to find any function!"); // 1343225888
GE_ERRORNO_COMMON(GE_PLGMGR_INVOKE_FAILED, 33, "Failed to invoke any function!"); // 1343225889

GE_ERRORNO_COMMON(UNSUPPORTED, 100, "Parameter's unsupported!");

GE_ERRORNO_COMMON(OUT_OF_MEMORY, 101, "Out of memory!");

// Client module error code definition
GE_ERRORNO_CLIENT(GE_CLI_INIT_FAILED, 1, "GEInitialize Failed."); // 1343229953
GE_ERRORNO_CLIENT(GE_CLI_FINAL_FAILED, 2, "GEFinalize Failed."); // 1343229954
GE_ERRORNO_CLIENT(GE_CLI_SESS_CONSTRUCT_FAILED, 3, "Session constructor Failed."); // 1343229955
GE_ERRORNO_CLIENT(GE_CLI_SESS_DESTROY_FAILED, 4, "Session destructor Failed."); // 1343229956
GE_ERRORNO_CLIENT(GE_CLI_SESS_ADD_FAILED, 5, "Session AddGraph Failed."); // 1343229957
GE_ERRORNO_CLIENT(GE_CLI_SESS_ADD_GRAPH_FAILED, 6,
"Session AddGraph Failed converting protobuf GraphProto."); // 1343229958
GE_ERRORNO_CLIENT(GE_CLI_SESS_REMOVE_FAILED, 7, "Session RemoveGraph Failed."); // 1343229959
GE_ERRORNO_CLIENT(GE_CLI_SESS_RUN_FAILED, 8, "Session RunGraph Failed."); // 1343229960
GE_ERRORNO_CLIENT(GE_CLI_SESS_RUN_TENSOR_FAILED, 9,
"Session RunGraph Failed converting protobuf TensorProto."); // 1343229961
GE_ERRORNO_CLIENT(GE_CLI_GE_ALREADY_INITIALIZED, 10, "GE is already initialized."); // 1343229962
GE_ERRORNO_CLIENT(GE_CLI_GE_NOT_INITIALIZED, 11, "GE is not yet initialized or is finalized."); // 1343229963

// Init module error code definition
GE_ERRORNO_INIT(GE_MULTI_INIT, 0, "Multiple initializations are not supported."); // 1343234048
GE_ERRORNO_INIT(GE_FINALIZE_NOT_INIT, 1, "Finalize is not allowed before initialization."); // 1343234049
GE_ERRORNO_INIT(GE_MULTI_FINALIZE, 2, "Multiple finalizations are not supported."); // 1343234050

// Session module error code definition
GE_ERRORNO_SESSION(GE_SESS_INIT_FAILED, 0, "Failed to initialize session."); // 1343238144
GE_ERRORNO_SESSION(GE_SESS_ALREADY_RUNNING, 1, "Session already running,not support parallel run."); // 1343238145
GE_ERRORNO_SESSION(GE_SESS_GRAPH_NOT_EXIST, 2, "Graph ID not exist."); // 1343238146
GE_ERRORNO_SESSION(GE_SESS_GRAPH_ALREADY_EXIST, 3, "Graph ID already exist."); // 1343238147
GE_ERRORNO_SESSION(GE_SESS_GRAPH_IS_RUNNING, 4, "Graph is running."); // 1343238148
GE_ERRORNO_SESSION(GE_SESSION_NOT_EXIST, 5, "Can not find session with specific session id."); // 1343238149
GE_ERRORNO_SESSION(GE_SESSION_MANAGER_NOT_INIT, 6, "Session manager has not been initialized."); // 1343238150

// Graph module error code definition
GE_ERRORNO_GRAPH(GE_GRAPH_INIT_FAILED, 0, "Failed to initialize graph."); // 1343242240
GE_ERRORNO_GRAPH(GE_GRAPH_ALREADY_RUNNING, 1, "graph already running,not support parallel run."); // 1343242241
GE_ERRORNO_GRAPH(GE_GRAPH_GRAPH_NOT_EXIST, 2, "graph ID not exist."); // 1343242242
GE_ERRORNO_GRAPH(GE_GRAPH_GRAPH_ALREADY_EXIST, 3, "Graph ID already exist."); // 1343242243
GE_ERRORNO_GRAPH(GE_GRAPH_GRAPH_IS_RUNNING, 4, "Graph is running."); // 1343242244
GE_ERRORNO_GRAPH(GE_GRAPH_MALLOC_FAILED, 5, "Graph malloc failed."); // 1343242245
GE_ERRORNO_GRAPH(GE_GRAPH_FREE_FAILED, 6, "Graph FREE failed."); // 1343242246
GE_ERRORNO_GRAPH(GE_GRAPH_NOT_MALLOC_BUFFER, 7, "Graph FREE failed, not malloc buffer."); // 1343242247
GE_ERRORNO_GRAPH(GE_GRAPH_PARAM_NULLPTR, 8, "Graph param is NULL."); // 1343242248
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_COMPUTE_GRAPH_NULL, 9, "Get computeGraph by graphNode failed."); // 1343242249
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_RUN_GRAPH_NODE_NULL, 10, "Run graph node is null."); // 1343242250
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_RUN_GRAPH_INVALID, 11, "Get computeGraph by graphNode failed."); // 1343242251
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_INSERT_DYN_OP_FAILED, 12, "Graph which insert dynamic op failed."); // 1343242252
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_PREPROCESS_FAILED, 13, "Graph preprocess failed."); // 1343242253
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_GRAPH_FUSION_FAILED, 14, "Graph fusion failed."); // 1343242254
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_TINY_CAL_CHECK_FAILED, 15, "Check tiny calibration failed."); // 1343242255
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_CALIBRATION_FAILED, 16, "Calibration failed."); // 1343242256
GE_ERRORNO_GRAPH(GE_GRAPH_SUBGRAPH_NUM_ZERO, 17, "Graph partition success, but subGraph num is 0."); // 1343242257
GE_ERRORNO_GRAPH(GE_GRAPH_SUBGRAPH_ENGINENAME_REPEATED, 18, "Graph subGraph engine name is repeated."); // 1343242258
GE_ERRORNO_GRAPH(GE_GRAPH_GET_IN_OUT_FAILED, 19, "OME GetInputOutputDescInfo failed."); // 1343242259
GE_ERRORNO_GRAPH(GE_GRAPH_DATA_INPUT_FAILED, 20, "OME DataInput failed."); // 1343242260
GE_ERRORNO_GRAPH(GE_GRAPH_EXECUTE_FAILED, 21, "Execute graph failed."); // 1343242261
GE_ERRORNO_GRAPH(GE_GRAPH_DUPLICATE_ENGINE, 22, "Duplicate engine."); // 1343242262
GE_ERRORNO_GRAPH(GE_GRAPH_EMPTY_SUBGRAPH, 23, "Empty sub graph info."); // 1343242263
GE_ERRORNO_GRAPH(GE_GRAPH_EXECUTE_NOT_INIT, 24, "Call SetCondition first."); // 1343242264
GE_ERRORNO_GRAPH(GE_GRAPH_PREPARE_FAILED, 25, "Prepare failed."); // 1343242265
GE_ERRORNO_GRAPH(GE_GRAPH_SERIALIZE_FAILED, 26, "OMG SerializeModelDef failed."); // 1343242266
GE_ERRORNO_GRAPH(GE_GRAPH_SAVE_FAILED, 27, "OMG SaveModel failed."); // 1343242267
GE_ERRORNO_GRAPH(GE_GRAPH_PRERUN_FAILED, 28, "PreRun failed."); // 1343242268
GE_ERRORNO_GRAPH(GE_GRAPH_SUBGRAPH_ID_INVALID, 29, "Graph subGraph id is invalid."); // 1343242269
GE_ERRORNO_GRAPH(GE_GRAPH_INFERSHAPE_FAILED, 30, "Prepare Graph infershape failed"); // 1343242270
GE_ERRORNO_GRAPH(GE_GRAPH_ISNULL, 31, "RunGraph input compute graph is NULL."); // 1343242271
GE_ERRORNO_GRAPH(GE_GRAPH_SYNC_MODEL_FAILED, 32, "Graph SyncExecuteModel failed."); // 1343242272
GE_ERRORNO_GRAPH(GE_GRAPH_RUNGRAPH_FAILED, 33, "Graph RunGraph failed."); // 1343242273
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_PARSE_DYN_OP_FAILED, 34, "Parse dynamic node config file failed"); // 1343242274
GE_ERRORNO_GRAPH(GE_GRAPH_MULTI_SUBGRAPH_BUILD, 35, "Save model with multiple sub graph"); // 1343242275
GE_ERRORNO_GRAPH(GE_GRAPH_GRAPH_NODE_NULL, 36, "Graph get graph node failed."); // 1343242276
GE_ERRORNO_GRAPH(GE_GRAPH_NOT_INIT, 37, "Graph do not init."); // 1343242277
GE_ERRORNO_GRAPH(GE_GRAPH_NULL_INPUT, 38, "input graph is null"); // 1343242278
GE_ERRORNO_GRAPH(GE_GRAPH_TOPO_SORT_FAILED, 39, "topological sorting an partition failed"); // 1343242279
GE_ERRORNO_GRAPH(GE_GRAPH_EMPTY_PARTITION, 40, "accessing an empty partition"); // 1343242280
GE_ERRORNO_GRAPH(GE_GRAPH_UNSUPPORTED, 41, "unsupported feature in partition"); // 1343242281
GE_ERRORNO_GRAPH(GE_GRAPH_ASSIGN_ENGINE_FAILED, 42, "assign engine failed"); // 1343242282
GE_ERRORNO_GRAPH(GE_GRAPH_ADD_PLC_END_FAILED, 43, "add placeholder end node failed"); // 1343242283
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_PARSE_OUT_NODE_FAILED, 44, "Parse out node failed."); // 1343242284
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIMIZE_INSERT_OP_PARSE_FAILED, 45,
"OMG parse dynamic node config file failed."); // 1343242285
GE_ERRORNO_GRAPH(GE_GRAPH_SAVE_WEIGHTS_FAILED, 46, "OMG Save Weights to Model failed."); // 1343242286
GE_ERRORNO_GRAPH(GE_GRAPH_EMPTY_STRING_NAME, 47, "Empty string name."); // 1343242287
GE_ERRORNO_GRAPH(GE_GRAPH_EMPTY_VARIABLE_TENSOR_TABLE, 48, "Empty variable-tensor table."); // 1343242288
GE_ERRORNO_GRAPH(GE_GRAPH_VARIABLE_ALREADY_EXIST, 49, "Variable already exist."); // 1343242289
GE_ERRORNO_GRAPH(GE_GRAPH_VARIABLE_DOES_NOT_EXIST, 50, "Variable does not exist."); // 1343242290
GE_ERRORNO_GRAPH(GE_GRAPH_OPTIONS_INVALID, 51, "Client session options is invalid."); // 1343242291
GE_ERRORNO_GRAPH(GE_GRAPH_NO_OUTPUT_DESC_INFO, 52, "No output desc info."); // 1343242292
GE_ERRORNO_GRAPH(GE_GRAPH_OUTPUT_DESCINFO_TENSOR_NUM_MISMATCH, 53,
"Number of output descinfo and tensor mismatch."); // 1343242293
GE_ERRORNO_GRAPH(GE_GRAPH_FILENAMEPREFIX_INVALID, 54, "Graph Save Model fileNamePrefix is invalid."); // 1343242294
GE_ERRORNO_GRAPH(GE_GRAPH_NOT_BUILT, 55, "Graph is not built before SaveModel."); // 1343242295
GE_ERRORNO_GRAPH(GE_GRAPH_SAVEMODEL_FAILED, 56, "Graph SaveModel failed."); // 1343242296
GE_ERRORNO_GRAPH(GE_GRAPH_MEMORY_ALLOC_FAILED, 57, "Failed allocating memory for model file header."); // 1343242297
GE_ERRORNO_GRAPH(GE_GRAPH_NODE_SEARCHER_REMOVE_GRAPH_FAILED, 58, "Failed remove graph in node seacher."); // 1343242298
GE_ERRORNO_GRAPH(GE_GRAPH_NODE_SEARCHER_ADD_GRAPH_FAILED, 59, "Failed add graph in node seacher."); // 1343242299
GE_ERRORNO_GRAPH(GE_GRAPH_NODE_SEARCHER_GET_GRAPH_REBUILD_FAILED, 60,
"Failed add graph in node seacher."); // 1343242300
GE_ERRORNO_GRAPH(GE_GRAPH_NODE_SEARCHER_SET_GRAPH_FINISH_REBUILD_GRAPH_FAILED, 61,
"Failed set graph finish rebuild in node searcher."); // 1343242301
GE_ERRORNO_GRAPH(GE_GRAPH_VARIABLE_OP_PASS_FAILED, 62, "Failed to run variable pass."); // 1343242302

// Optimize errocode
GE_ERRORNO_GRAPH(TO_BE_DELETED, 63, "The node of the graph to be deleted."); // 1343242303
GE_ERRORNO_GRAPH(NOT_CHANGED, 64, "The node of the graph no changed."); // 1343242304

// Engine_manager module error code definition
GE_ERRORNO_ENGINE(GE_ENG_INIT_FAILED, 0, "Failed to initialize engine."); // 1343246336
GE_ERRORNO_ENGINE(GE_ENG_FINALIZE_FAILED, 1, "Engine finalize failed."); // 1343246337
GE_ERRORNO_ENGINE(GE_ENG_MEMTYPE_ERROR, 2, "Memory type HBM is necessary when engine is in device"); // 1343246338

// Ops module error code definition
GE_ERRORNO_OPS(GE_OPS_KERNEL_STORE_INIT_FAILED, 0, "Failed to initialize OpsKernelInfoStore."); // 1343250432
GE_ERRORNO_OPS(GE_OPS_GRAPH_OPTIMIZER_INIT_FAILED, 1, "Failed to initialize GraphOptimizer."); // 1343250433
GE_ERRORNO_OPS(GE_OPS_KERNEL_INFO_NOT_EXIST, 2, "OpsKernelInfo not exist."); // 1343250434
GE_ERRORNO_OPS(GE_OPS_KERNEL_STORE_NOT_EXIST, 3, "OpsKernelInfoStore not exist."); // 1343250435
GE_ERRORNO_OPS(GE_OPS_CALC_RUNNING_PARAM_FAILED, 4, "Failed to CalcOpRunningParam."); // 1343250436
GE_ERRORNO_OPS(GE_OPS_GENERATE_TASK_FAILED, 5, "Failed to GenerateTask."); // 1343250437
GE_ERRORNO_OPS(GE_OPS_OPTIMIZE_ORIGINAL_GRAPH_FAILED, 6, "Failed to OptimizeOriginalGraph."); // 1343250438
GE_ERRORNO_OPS(GE_OPS_OPTIMIZE_FUSED_GRAPH_FAILED, 7, "Failed to OptimizeFusedGraph."); // 1343250439
GE_ERRORNO_OPS(GE_OPS_ENGINE_IS_NOT_REGISTERED, 8, "Engine is not registered."); // 1343250440
GE_ERRORNO_OPS(GE_OPS_GET_NO_VALID_SO, 9,
"There is no valid so about OpsKernelInfoStore or GraphOptimizer."); // 1343250441
GE_ERRORNO_OPS(GE_OPS_GET_OPTIMIZE_BY_ENGINE_FAILED, 10, "Failed to get graphOptimizer by name."); // 1343250442
GE_ERRORNO_OPS(GE_OPS_GET_OPTIMIZE_BY_PRIORITY_FAILED, 11, "Failed to get graphOptimizer by priority."); // 1343250443
GE_ERRORNO_OPS(GE_OPS_LOAD_GE_OPTIMIZER_FAILED, 12, "Failed to load ge graphOptimizer."); // 1343250444

// Runtime module error code definition
GE_ERRORNO_RUNTIME(GE_RTI_DEVICE_ID_INVALID, 1, "device id is invalid");
GE_ERRORNO_RUNTIME(GE_RTI_DEVICE_NOT_READY, 2, "set device failed, device not ready");
GE_ERRORNO_RUNTIME(GE_RTI_MEMALLOC_FAILED, 3, "malloc memory failed");
GE_ERRORNO_RUNTIME(GE_RTI_MODEL_NOT_LOADED, 4, "model has not been loaded");
GE_ERRORNO_RUNTIME(GE_RTI_THREAD_POOL_IS_NULL, 5, "model excute failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_CCE_CREATE_HANDLE_FAILED, 6, "cce create handle failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_CCE_SET_STREAM_FAILED, 7, "cce set stream failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_CREATE_RTMODEL_FAILED, 8, "call runtime create rtModel failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_CREATE_STREAM_FAILED, 9, "call runtime create stream failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_BIND_STREAM_FAILED, 10, "call runtime bind stream to model failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_CREATE_LABLE_FAILED, 11, "call runtime create lable failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MODEL_LOAD_COMPLETE_FAILED, 12, "call runtime model load complete failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MODEL_GET_TASK_ID_FAILED, 14, "call runtime get task id failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_KERNEL_LAUNCH_FAILED, 13, "call runtime kernel launch failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_KERNEL_LAUNCHEX_FAILED, 15, "call runtime kernel launchex failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_KERNEL_FUSION_START_FAILED, 16, "call runtime kernel fusion start failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_KERNEL_FUSION_END_FAILED, 17, "call runtime kernel fusion end failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_LABEL_SET_FAILED, 18, "call runtime lable set failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_LABLE_GOTO_FAILED, 19, "call runtime lable goto failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_LABLE_SWITCH_FAILED, 20, "call runtime lable switch failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MEM_ALLOC_MANAGED_FAILED, 21, "call runtime mem alloc managed failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MEM_FREE_MANAGED_FAILED, 22, "call runtime mem free managed failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_FREE_FAILED, 23, "call runtime free failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_STREAM_SYNC_FAILED, 24, "call runtime sync stream failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MODEL_EXCUTE_FAILED, 25, "call runtime model excute failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MEM_ASYNC_FAILED, 26, "call runtime mem async failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MEM_ALLOC_HOST_FAILED, 27, "call runtime alloc host memory failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MEM_FREE_HOST_FAILED, 28, "call runtime free host memory failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MEM_ALLOC_DEVICE_FAILED, 29, "call runtime alloc device memory failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_MEM_FREE_DEVICE_FAILED, 30, "call runtime free device memory failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_FLUSH_CACHE_FAILED, 31, "call runtime flush cache failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_UNBIND_STREAM_FAILED, 32, "unbind rtstream from rtmodel failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_DESTORY_STREAM_FAILED, 33, "destory stream failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_DESTORY_LABEL_FAILED, 34, "destory label failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_DESTORY_MODEL_FAILED, 35, "destory model failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_CCE_TRANS_TENSOR_FAILED, 36, "call cce transfer tensor descriptor failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_CCE_TRANS_FILTER_FAILED, 37, "call cce transfer filter descriptor failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_CCE_UPDATE_KERNEL_ARGS_FAILED, 38, "call cce update kernel args failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_CCE_DESTORY_HANDLE_FAILED, 39, "destory handle failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_CREATE_EVENT_FAILED, 40, "call rutime create event failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_EVENT_RECORD_FAILED, 41, "call rutime event record failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_STREAM_WAIT_EVENT_FAILED, 42, "call rutime stream wait event failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_HCCL_BROADCAST_FAILED, 43, "call hccl hcom broadcast failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_HCCL_ALL_GATHER_FAILED, 44, "call hccl hcom all gather failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_HCCL_ALL_REDUCE_FAILED, 45, "call hccl hcom all reduce failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_RUNTIME_DESTORY_EVENT_FAILED, 46, "destory rt event failed");
GE_ERRORNO_RUNTIME(GE_RTI_CALL_HCCL_REDUCE_SCATTER_FAILED, 47, "call hccl hcom reduce scatter failed");

// Executor module error code definition
GE_ERRORNO_EXECUTOR(GE_EXEC_NOT_INIT, 1, "GE Executor is not yet initialized.");

// Generator module error code definition
GE_ERRORNO_GENERATOR(GE_GENERATOR_GRAPH_MANAGER_INIT_FAILED, 1, "Graph manager initialize failed.");
GE_ERRORNO_GENERATOR(GE_GENERATOR_GRAPH_MANAGER_ADD_GRAPH_FAILED, 2, "Graph manager add graph failed.");
GE_ERRORNO_GENERATOR(GE_GENERATOR_GRAPH_MANAGER_BUILD_GRAPH_FAILED, 3, "Graph manager build graph failed.");
GE_ERRORNO_GENERATOR(GE_GENERATOR_GRAPH_MANAGER_FINALIZE_FAILED, 4, "Graph manager finalize failed.");
GE_ERRORNO_GENERATOR(GE_GENERATOR_GRAPH_MANAGER_SAVE_MODEL_FAILED, 5, "Graph manager save model failed.");
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_GE_INNER_ERROR_CODES_H_

+ 153
- 0
inc/framework/common/ge_types.h View File

@@ -0,0 +1,153 @@
/**
* 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 INC_FRAMEWORK_COMMON_GE_TYPES_H_
#define INC_FRAMEWORK_COMMON_GE_TYPES_H_

#include <stdint.h>

#include <string>
#include <vector>

#include "common/fmk_error_codes.h"
#include "ge/ge_api_error_codes.h"

using std::string;

namespace ge {
enum RuntimeType { HOST = 0, DEVICE = 1 };

enum PerfLevel { GEN_TASK_WITH_FUSION = -1, GEN_TASK_WITHOUT_L2FUSION = 3, GEN_TASK_WITHOUT_FUSION = 4 };

enum FrameworkType {
FMK_TYPE_C = 0,
FMK_TYPE_MINDSPORE = 1,
FMK_TYPE_T = 3,
FMK_TYPE_A_NN,
FMK_TYPE_RESERVED,
};

const char *const GE_ENGINE_ATTR_MEM_TYPE_HBM = "HBM";

// Data cache, including data address and length
struct DataBuffer {
public:
void *data; // Data address
uint32_t length; // Data length
bool isDataSupportMemShare = false;
DataBuffer(void *dataIn, uint32_t len, bool isSupportMemShare)
: data(dataIn), length(len), isDataSupportMemShare(isSupportMemShare) {}

DataBuffer() : data(nullptr), length(0), isDataSupportMemShare(false) {}
};

///
/// @ingroup domi_ome
/// @brief External inputdata
///
struct InputData {
uint32_t index; // Index of input data
uint32_t timestamp; // Data creation time
uint32_t timeout; // Processing timeout
uint32_t model_id; // Model ID required for data processing
uint64_t request_id = 0; // Request ID
std::vector<DataBuffer> blobs; // Actual input data, currently only supports one input
};

// The definition of output result structure
struct OutputData {
uint32_t index; // Index of input data
uint32_t model_id; // The model ID corresponding to the processing result

/// Output data cache, arranged in sequence of output operators.
/// If the operator has multiple outputs,
/// the data buffer order of the operator is the same as that defined in the
/// offline model
std::vector<DataBuffer> blobs;
};

// The definition of command data structure
struct Command {
std::string cmd_type; // Command type
std::vector<std::string> cmd_params; // Command params
};

// The definition of I/O shape description
struct ShapeDescription {
int64_t num = 0;
int64_t channel = 0;
int64_t height = 0;
int64_t width = 0;
std::vector<int64_t> dims;
};

// Definition of input and output description information
struct InputOutputDescInfo {
std::string name;
uint32_t size;
uint32_t data_type;
ShapeDescription shape_info;
};

// The structure of offline Modeldata
struct ModelData {
void *model_data = nullptr; // Model binary data start addr
uint32_t model_len = 0; // Model binary data length
int32_t priority = 0; // Model priority
std::string key; // Key path for encrypt model, Empty for unencrypt
};

// The definition of Model information
struct ModelInfo {
uint32_t version = 0;
std::string name;
bool is_encrypt = 0; // 0:unencrypt, 1:encrypt
std::vector<ShapeDescription> input_desc;
std::vector<ShapeDescription> output_desc;
uint8_t reserved[3] = {0}; // 3-byte reserved field
};

// Asynchronous callback interface, implemented by the caller
class ModelListener {
public:
virtual ~ModelListener() {}
///
/// @brief Asynchronous callback interface
/// @param [in] model_id Model ID of the callback
/// @param [in] data_index Index of the input_data
/// @param [in] resultCode Execution results
///
virtual Status OnComputeDone(uint32_t model_id, uint32_t data_index, uint32_t result_code) = 0;
};

// OMM configuration item
struct Options {
int64_t session_id;
int32_t device_id;
int64_t job_id;
bool isUseHcom;
bool deployMode;
bool isAICPUMode;
bool enable_atomic;
string podName;
int64_t rankId;
string rankTableFile;
int32_t ge_hccl_flag = 0;
int32_t physical_device_id;
};
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_GE_TYPES_H_

+ 76
- 0
inc/framework/common/gflags_util.h View File

@@ -0,0 +1,76 @@
/**
* 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 INC_FRAMEWORK_COMMON_GFLAGS_UTIL_H_
#define INC_FRAMEWORK_COMMON_GFLAGS_UTIL_H_

#include <gflags/gflags.h>
#include <string>

namespace ge {
class GflagsUtils {
public:
///
/// @brief Determines whether the parameter is true
/// @param name name parameter name
/// @return true or false
///
static bool IsSetCommandTrue(const char *name) {
std::string out;
return gflags::GetCommandLineOption(name, &out) && out == "true";
}

///
/// @brief Determines whether the parameter is empty
/// @param name name parameter name
/// @return true if empty otherwise false
///
static bool IsSetCommandNotEmpty(const char *name) {
std::string out;
return gflags::GetCommandLineOption(name, &out) && !out.empty();
}

///
/// @brief Determines whether the parameter is not default
/// @param flag_name name parameter name
/// @return true if not default otherwise false
///
static bool IsCommandLineNotDefault(const char *flag_name) {
google::CommandLineFlagInfo info;
return GetCommandLineFlagInfo(flag_name, &info) && !info.is_default;
}

///
/// @brief Modify gflags to print help information
/// @param flags_h Pass in the self-defined help parameter, it is recommended to be FLAGS_h
/// @return void
///
static void ChangeHelpFlags(bool flags_h) {
if (flags_h || IsSetCommandTrue("help") || IsSetCommandTrue("helpfull") || IsSetCommandNotEmpty("helpon") ||
IsSetCommandNotEmpty("helpmatch") || IsSetCommandTrue("helppackage") || IsSetCommandTrue("helpxml")) {
gflags::SetCommandLineOption("help", "false");
gflags::SetCommandLineOption("helpfull", "false");
gflags::SetCommandLineOption("helpon", "");
gflags::SetCommandLineOption("helpmatch", "");
gflags::SetCommandLineOption("helppackage", "false");
gflags::SetCommandLineOption("helpxml", "false");
gflags::SetCommandLineOption("helpshort", "true");
}
}
};
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_GFLAGS_UTIL_H_

+ 67
- 0
inc/framework/common/helper/model_helper.h View File

@@ -0,0 +1,67 @@
/**
* 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 INC_FRAMEWORK_COMMON_HELPER_MODEL_HELPER_H_
#define INC_FRAMEWORK_COMMON_HELPER_MODEL_HELPER_H_

#include <memory>
#include <string>

#include "common/fmk_types.h"
#include "common/helper/om_file_helper.h"
#include "common/types.h"
#include "graph/model.h"
#include "model/ge_model.h"

namespace ge {
class ModelHelper {
public:
ModelHelper() = default;
~ModelHelper();

Status SaveToOmModel(const GeModelPtr &ge_model, const SaveParam &save_param, const std::string &output_file);
Status SaveOriginalGraphToOmModel(const ge::Graph &graph, const std::string &output_file);
Status LoadModel(const ge::ModelData &model_data);

ModelFileHeader *GetFileHeader() { return file_header_; }

GeModelPtr GetGeModel();

static Status TransModelToGeModel(const ModelPtr &model, GeModelPtr &ge_model);
static Status TransGeModelToModel(const GeModelPtr &geModelPtr, ModelPtr &modelPtr);

private:
bool is_assign_model_ = false;
ModelFileHeader *file_header_ = nullptr;
// Encrypted model need delete temp model and unencrypted model need not delete model
uint8_t *model_addr_tmp_ = nullptr;
uint32_t model_len_tmp_ = 0;
GeModelPtr model_;

ModelHelper(const ModelHelper &);
ModelHelper &operator=(const ModelHelper &);
Status GenerateGeModel(OmFileLoadHelper &om_load_helper);
Status LoadModelData(OmFileLoadHelper &om_load_helper);
void SetModelToGeModel(ge::Model &model);
Status LoadWeights(OmFileLoadHelper &om_load_helper);
Status LoadTask(OmFileLoadHelper &om_load_helper);
Status LoadTBEKernelStore(OmFileLoadHelper &om_load_helper);
Status ReleaseLocalModelData() noexcept;
Status SaveModelPartition(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, ModelPartitionType type,
const uint8_t *data, size_t size);
};
} // namespace ge
#endif // INC_FRAMEWORK_COMMON_HELPER_MODEL_HELPER_H_

+ 91
- 0
inc/framework/common/helper/om_file_helper.h View File

@@ -0,0 +1,91 @@
/**
* 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 INC_FRAMEWORK_COMMON_HELPER_OM_FILE_HELPER_H_
#define INC_FRAMEWORK_COMMON_HELPER_OM_FILE_HELPER_H_

#include <string>
#include <vector>

#include "framework/common/fmk_types.h"
#include "framework/common/ge_types.h"
#include "framework/common/types.h"

using std::string;
using std::vector;

namespace ge {
struct ModelPartition {
ModelPartitionType type;
uint8_t *data = 0;
uint32_t size = 0;
};

struct OmFileContext {
vector<ModelPartition> partition_datas_;
vector<char> partition_table_;
uint32_t model_data_len_;
};

struct SaveParam {
int32_t encode_mode;
std::string ek_file;
std::string cert_file;
std::string hw_key_file;
std::string pri_key_file;
std::string model_name;
};

class OmFileLoadHelper {
public:
Status Init(const ge::ModelData &model);

Status Init(uint8_t *model_data, const uint32_t model_data_size);

Status GetModelPartition(ModelPartitionType type, ModelPartition &partition);

private:
Status CheckModelValid(const ge::ModelData &model) const;

Status LoadModelPartitionTable(uint8_t *model_data, const uint32_t model_data_size);

bool is_inited_{false};

public:
OmFileContext context_;
};

class OmFileSaveHelper {
public:
ModelFileHeader &GetModelFileHeader() { return model_header_; }

uint32_t GetModelDataSize() const { return context_.model_data_len_; }

ModelPartitionTable *GetPartitionTable();

Status AddPartition(ModelPartition &partition);

const vector<ModelPartition> &GetModelPartitions() const;

Status SaveModel(const SaveParam &save_param, const char *target_file);

Status SaveModelToFile(const char *output_file);

ModelFileHeader model_header_;
OmFileContext context_;
};
} // namespace ge
#endif // INC_FRAMEWORK_COMMON_HELPER_OM_FILE_HELPER_H_

+ 120
- 0
inc/framework/common/l2_cache_optimize.h View File

@@ -0,0 +1,120 @@
/**
* 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 INC_FRAMEWORK_COMMON_L2_CACHE_OPTIMIZE_H_
#define INC_FRAMEWORK_COMMON_L2_CACHE_OPTIMIZE_H_

#include <stdint.h>

#include <algorithm>
#include <functional>
#include <string>
#include <vector>

#include "common/types.h"
#include "common/util.h"
#include "graph/compute_graph.h"

namespace ge {
// Size of RC memory alignment, 2M
const size_t ALIGN_SIZE = 2097152;
const uint32_t RC_VALUE_DEFAULT = 1;
const uint32_t RC_VALUE_MAC = 32;

// RC data type classification
enum RCType {
RC_DEFAULT, // Such as temporary workspace memory of operator, variable (including global and local variable)
RC_HCOM, // Output of gradient aggregation, RC value should be set to 0
RC_L2LOSS, // Parameter of L2 loss operator, RC value should be set to 0
RC_INPUTOUTPUT, // Input and output tensor of operator, RC value is returned by FE calculation
RC_WEIGHTS, // The weight, fp16, RC value used by FP/BP operator should be set to 1 or the actual access numbers
RC_DW, // The gradient data DW and RC value output by BP operator
// should be set to 1 or the actual access numbers
RC_ARGS // Args of FlowTable, actual access numbers
};

enum MemType { INPUT_TENSOR, OUTPUT_TENSOR, WEIGHT, WORKSPACE };

// Memory usage information < node, type, number >
struct NodeInfo {
string nodeName;
MemType memType;
size_t index;
};

// Memory block RC value
struct RCMemoryBlock {
RCType type; // RC type
size_t blockSize; // memory block size
size_t headOffset; // Start offset from base address
size_t tailOffset; // End offset from base address
uint32_t rcCount; // RC value
NodeInfo nodeInfo; // Input and output indexes of node objects to which RC belongs
};

// L2Cache optimizer
class L2CacheOptimize {
public:
explicit L2CacheOptimize(ge::ComputeGraphPtr &graph);
~L2CacheOptimize();

// Collect the information L2Cache Memory optimization
Status Gath();

private:
ge::ComputeGraphPtr graph_;

// Save RC block information list
vector<RCMemoryBlock> weightRCs;
vector<RCMemoryBlock> opRCs;

// Extract RC information generated by FE from compiled graph
void RetirveRCinfo();

// Take the maximum common divisor of RC values for the duplicate address
void Merge(vector<RCMemoryBlock> &blocks);

// The RC information is aligned with the 2m address
void Align(vector<RCMemoryBlock> &blocks);

// Weight of l2loss operator, output of gradient aggregation output, RC value set to 0
void HandleOutputZeroRC(RCType type, ge::NodePtr node, vector<int64_t> &outputList, vector<RCMemoryBlock> &blocks);

// Processing operator input Tensor's RC
void HandOPInput(ge::NodePtr node, vector<int64_t> &inputList, vector<RCMemoryBlock> &blocks);

// Processing operator output Tensor's RC
void HandOPoutput(ge::NodePtr node, vector<int64_t> &outputList, vector<RCMemoryBlock> &blocks);

// maximum common divisor
uint32_t Measure(uint32_t x, uint32_t y) const {
if (x == 0 || y == 0) return RC_VALUE_DEFAULT;
uint32_t z = y;
while (x % y != 0) {
z = x % y;
x = y;
y = z;
}
return z;
}

bool Contain(const RCMemoryBlock &l_block, const RCMemoryBlock &r_block);
bool Cross(const RCMemoryBlock &l_block, const RCMemoryBlock &r_block);
bool Connect(const RCMemoryBlock &l_block, const RCMemoryBlock &r_block);
};
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_L2_CACHE_OPTIMIZE_H_

+ 161
- 0
inc/framework/common/op/attr_value_util.h View File

@@ -0,0 +1,161 @@
/**
* 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 INC_FRAMEWORK_COMMON_OP_ATTR_VALUE_UTIL_H_
#define INC_FRAMEWORK_COMMON_OP_ATTR_VALUE_UTIL_H_

#include <google/protobuf/map.h>
#include <string>
#include <unordered_map>

#include "common/types.h"
#include "graph/debug/ge_attr_define.h"
#include "proto/om.pb.h"

using domi::AttrDef;
using domi::OpDef;
using domi::AttrDef_ListValue;
using domi::ModelDef;
using domi::NamedAttrs;

namespace ge {
using AttrDefMap = ::google::protobuf::Map<::std::string, ::domi::AttrDef>;
using AttrDefPair = ::google::protobuf::MapPair<std::string, domi::AttrDef>;

void AddOpAttr(const std::string &key, AttrDef &attr, OpDef *opdef);
// DEFINE_ADD_ATTR_VALUE
void AddOpAttr(const std::string &key, const std::string &value, AttrDefMap *attrs);
void AddOpAttr(const std::string &key, const char *value, AttrDefMap *attrs);
void AddOpAttr(const char *key, const char *value, AttrDefMap *attrs);
void AddOpAttr(const std::string &key, const uint32_t value, AttrDefMap *attrs);
void AddOpAttr(const std::string &key, const int32_t value, AttrDefMap *attrs);
void AddOpAttr(const std::string &key, const int64_t value, AttrDefMap *attrs);
void AddOpAttr(const std::string &key, const float value, AttrDefMap *attrs);
void AddOpAttr(const std::string &key, const double value, AttrDefMap *attrs);
void AddOpAttr(const std::string &key, const bool value, AttrDefMap *attrs);

void AddOpAttr(const std::string &key, const AttrDef_ListValue &value, AttrDefMap *attrs);

// DEFINE_ADD_ATTR_VALUE
void AddOpAttr(const std::string &key, const std::string &value, OpDef *opdef);
void AddOpAttr(const std::string &key, const char *value, OpDef *opdef);
void AddOpAttr(const char *key, const char *value, OpDef *opdef);
void AddOpAttr(const std::string &key, const uint32_t value, OpDef *opdef);
void AddOpAttr(const std::string &key, const int32_t value, OpDef *opdef);
void AddOpAttr(const std::string &key, const int64_t value, OpDef *opdef);
void AddOpAttr(const std::string &key, const float value, OpDef *opdef);
void AddOpAttr(const std::string &key, const double value, OpDef *opdef);
void AddOpAttr(const std::string &key, const bool value, OpDef *opdef);

void AddOpAttr(const std::string &key, const AttrDef_ListValue &value, OpDef *opdef);

void AddOpBytesAttr(const std::string &key, const void *value, size_t size, OpDef *opdef);

// DEFINE_ADD_ATTR_VALUE_LIST
void AddOpAttrList(const std::string &key, const double value, AttrDefMap *attrs);
void AddOpAttrList(const std::string &key, const float value, AttrDefMap *attrs);
void AddOpAttrList(const std::string &key, const uint32_t value, AttrDefMap *attrs);
void AddOpAttrList(const std::string &key, const int32_t value, AttrDefMap *attrs);
void AddOpAttrList(const std::string &key, const std::string value, AttrDefMap *attrs);
void AddOpAttrList(const std::string &key, const double value, OpDef *opdef);
void AddOpAttrList(const std::string &key, const float value, OpDef *opdef);
void AddOpAttrList(const std::string &key, const uint32_t value, OpDef *opdef);
void AddOpAttrList(const std::string &key, const int32_t value, OpDef *opdef);
void AddOpAttrList(const std::string &key, const bool value, OpDef *opdef);
void AddOpAttrList(const std::string &key, const int64_t value, OpDef *opdef);

void AddOpAttrList(const std::string &key, const std::string &value, OpDef *opdef);

bool GetOpAttr(const std::string &key, std::string *value, const OpDef *opdef);
bool GetOpAttr(const std::string &key, int32_t *value, const OpDef *opdef);
bool GetOpAttr(const std::string &key, int64_t *value, const OpDef *opdef);
bool GetOpAttr(const std::string &key, uint32_t *value, const OpDef *opdef);
bool GetOpAttr(const std::string &key, float *value, const OpDef *opdef);
bool GetOpAttr(const std::string &key, double *value, const OpDef *opdef);
bool GetOpAttr(const std::string &key, bool *value, const OpDef *opdef);
bool GetOpAttr(const std::string &key, AttrDef_ListValue *value, const OpDef *opdef);

uint32_t GetOpAttrListSize(const std::string &key, std::string value, const OpDef *opdef);
uint32_t GetOpAttrListSize(const std::string &key, int32_t value, const OpDef *opdef);
uint32_t GetOpAttrListSize(const std::string &key, int64_t value, const OpDef *opdef);
uint32_t GetOpAttrListSize(const std::string &key, uint32_t value, const OpDef *opdef);
uint32_t GetOpAttrListSize(const std::string &key, float value, const OpDef *opdef);
uint32_t GetOpAttrListSize(const std::string &key, double value, const OpDef *opdef);
uint32_t GetOpAttrListSize(const std::string &key, bool value, const OpDef *opdef);

bool GetBytesAttr(const std::string &key, std::string *value, const OpDef *opdef);
bool GetBytesAttr(const std::string &key, std::string *value, const ModelDef *model_def);

void AddModelAttr(const std::string &key, const std::string &value, ModelDef *model_def);
void AddModelAttr(const std::string &key, const char *value, ModelDef *model_def);
void AddModelAttr(const char *key, const char *value, ModelDef *model_def);
void AddModelAttr(const std::string &key, const uint32_t value, ModelDef *model_def);
void AddModelAttr(const std::string &key, const int32_t value, ModelDef *model_def);
void AddModelAttr(const std::string &key, const int64_t value, ModelDef *model_def);
void AddModelAttr(const std::string &key, const float value, ModelDef *model_def);
void AddModelAttr(const std::string &key, const double value, ModelDef *model_def);
void AddModelAttr(const std::string &key, const bool value, ModelDef *model_def);
void AddModelAttr(const std::string &key, const void *value, size_t size, ModelDef *model_def);
void AddModelAttr(const std::string &key, const AttrDef_ListValue &value, ModelDef *model_def);

void AddModelAttrList(const std::string &key, const double value, ModelDef *model_def);
void AddModelAttrList(const std::string &key, const float value, ModelDef *model_def);
void AddModelAttrList(const std::string &key, const uint32_t value, ModelDef *model_def);
void AddModelAttrList(const std::string &key, const int32_t value, ModelDef *model_def);
void AddModelAttrList(const std::string &key, const std::string &value, ModelDef *model_def);

bool GetModelAttr(const std::string &key, std::string *value, const ModelDef *model_def);
bool GetModelAttr(const std::string &key, int32_t *value, const ModelDef *model_def);
bool GetModelAttr(const std::string &key, int64_t *value, const ModelDef *model_def);
bool GetModelAttr(const std::string &key, uint32_t *value, const ModelDef *model_def);
bool GetModelAttr(const std::string &key, float *value, const ModelDef *model_def);
bool GetModelAttr(const std::string &key, double *value, const ModelDef *model_def);
bool GetModelAttr(const std::string &key, bool *value, const ModelDef *model_def);
bool GetModelAttr(const std::string &key, AttrDef_ListValue *value, const ModelDef *model_def);

bool HasOpAttr(const OpDef *opdef, const std::string &attr_name);

void SetAttrDef(const std::string &value, AttrDef *out);
void SetAttrDef(const char *value, AttrDef *out);
void SetAttrDef(const uint32_t value, AttrDef *out);
void SetAttrDef(const int32_t value, AttrDef *out);
void SetAttrDef(const float value, AttrDef *out);
void SetAttrDef(const double value, AttrDef *out);
void SetAttrDef(const bool value, AttrDef *out);
void SetAttrList(const std::string &value, AttrDef *out);
void SetAttrList(const bool value, AttrDef *out);
void SetAttrList(const float value, AttrDef *out);
void SetAttrList(const double value, AttrDef *out);
void SetAttrList(const uint32_t value, AttrDef *out);

bool GetAttrDefValue(const std::string &key, std::string *value, const AttrDefMap &attr);
bool GetAttrDefValue(const std::string &key, int32_t *value, const AttrDefMap &attr);
bool GetAttrDefValue(const std::string &key, int64_t *value, const AttrDefMap &attr);
bool GetAttrDefValue(const std::string &key, uint32_t *value, const AttrDefMap &attr);
bool GetAttrDefValue(const std::string &key, float *value, const AttrDefMap &attr);
bool GetAttrDefValue(const std::string &key, double *value, const AttrDefMap &attr);
bool GetAttrDefValue(const std::string &key, bool *value, const AttrDefMap &attr);
bool GetAttrDefValue(const std::string &key, AttrDef_ListValue *value, const AttrDefMap &attr);
bool GetAttrDefValue(const std::string &key, NamedAttrs *&value, AttrDefMap *attr);
bool GetAttrDefValue(const std::string &key, const NamedAttrs *&value, const AttrDefMap &attr);

bool GetAttrDefListValue(const std::string &key, int idx, int32_t *value, const AttrDefMap &attr);
bool GetAttrDefListValue(const std::string &key, int idx, uint32_t *value, const AttrDefMap &attr);
bool GetAttrDefListValue(const std::string &key, int idx, float *value, const AttrDefMap &attr);
bool GetAttrDefListValue(const std::string &key, int idx, double *value, const AttrDefMap &attr);
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_OP_ATTR_VALUE_UTIL_H_

+ 280
- 0
inc/framework/common/op/ge_op_utils.h View File

@@ -0,0 +1,280 @@
/**
* 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 INC_FRAMEWORK_COMMON_OP_GE_OP_UTILS_H_
#define INC_FRAMEWORK_COMMON_OP_GE_OP_UTILS_H_

#include <cce/dnn.h>

#include <memory>
#include <vector>

#include "common/op/attr_value_util.h"
#include "common/types.h"
#include "common/util.h"
#include "graph/attr_value.h"
#include "graph/ge_tensor.h"
#include "graph/node.h"
#include "graph/op_desc.h"
#include "proto/insert_op.pb.h"

namespace ge {
using namespace cce;
using domi::Status;

// Add Sub Mul
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t ADD_INPUT_NUM;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t SUB_INPUT_NUM;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t MUL_INPUT_NUM;

// Permute
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const int32_t PERMUTE_ORDER_NUM;

// Ssd PriroBox
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const double SSD_PRIORBOX_ASPECT_RATIO_VALUE;

FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t STRIDEDSLICE_INPUT_NUM;

// Switch
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t SWITCH_INPUT_NUM;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t SWITCH_OUTPUT_NUM;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t SWITCH_FALSE_OUTPUT;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t SWITCH_TRUE_OUTPUT;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t SWITCH_DATA_INPUT;
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const uint32_t SWITCH_PRED_INPUT;

class OpUtils {
public:
///
/// @ingroup domi_ome
/// @brief Check whether check_value is in [min_enum_value, max_enum_value]
/// @return true Within
/// @return false out of range
//
static inline bool CheckEnumValid(int32_t check_value, int32_t min_enum_value, int32_t max_enum_value) {
return check_value < min_enum_value ? false : (check_value >= max_enum_value ? false : true);
}
///
/// @ingroup domi_omg
/// @brief Convert the dimension of array according to different format
/// @param [in] src_format src_shape format
/// @param [in] src Dimension array to be converted
/// @param [in] dst_format Target format after conversion
/// @param [out] dst Dimension array after conversion
/// @return SUCCESS success
/// @return FAILED fail
///
static bool ConvertDim(ccTensorFormat_t src_format, const std::vector<int64_t> &src, ccTensorFormat_t dst_format,
std::vector<int64_t> &dst);
///
/// @ingroup domi_omg
/// @brief Determine whether to manually calculate the tensor size based on the values of format and dim
/// @param [in] format, Format information of the tensor
/// @param [in] real_dim_cnt, Tensor dim
/// @return true Manually calculate the size based on dim and datatype
/// @return false skip
///
static bool IsComputDimsSize(const int32_t format, const uint32_t real_dim_cnt);
///
/// @ingroup domi_ome
/// @brief Initialize the tensor description, which is used for input and output.
/// @param [in] model_tensor Tensor information defined by the offline model
/// @param [out] cc_tensor Tensor definition used by CC
/// @return SUCCESS success
/// @return FAILED fail
///
static Status InitTensorDescriptor(const ge::GeTensorDesc &model_tensor, ccTensorDescriptor_t &cc_tensor);
///
/// @ingroup domi_ome
/// @brief Initialize the tensor description, which is used for input and output.
/// @param [in] model_tensor Tensor information defined by the offline model
/// @param [in] dst_data_type data_type of the target cc_tensor
/// @param [out] cc_tensor Tensor definition used by CC
/// @return SUCCESS success
/// @return FAILED fail
///
static Status InitTensorDescriptor(const ge::GeTensorDesc &model_tensor, int32_t dst_data_type,
ccTensorDescriptor_t &cc_tensor);
///
/// @ingroup domi_ome
/// @brief Initialize the tensor description for bias.
/// @param [in] model_tensor Tensor information defined by the offline model
/// @param [out] cc_tensor Tensor definition used by CC
/// @return SUCCESS success
/// @return FAILED fail
///
///
static Status InitTensorDescriptor(const ge::GeTensor &model_tensor, ccTensorDescriptor_t &cc_tensor);
///
/// @ingroup domi_ome
/// @brief Initialize the tensor description for bias.
/// @param [in] model_tensor Tensor information defined by the offline model
/// @param [in] dst_data_type data_type of the target cc_tensor
/// @param [out] cc_tensor Tensor definition used by CC
/// @return SUCCESS success
/// @return FAILED fail
///
static Status InitTensorDescriptor(const ge::GeTensor &model_tensor, int32_t dst_data_type,
ccTensorDescriptor_t &cc_tensor);

static Status InitTensorDescriptor(int32_t format, int32_t data_type, const std::vector<int64_t> &dim,
ccTensorDescriptor_t &cc_tensor, uint32_t real_dim_cnt = 4);
///
/// @ingroup domi_ome
/// @brief Destroys a tensor
/// @param [inout] cc_tensor Tensor definition used by CC
///
static void DestroyTensorDescriptor(ccTensorDescriptor_t &cc_tensor) noexcept;

///
/// @ingroup domi_ome
/// @brief Destroys a tensor
/// @param [inout] cc_filter cc_filter Definition of the filter used by CC
///
static void DestroyFilterDescriptor(ccFilterDescriptor_t &cc_filter);

///
/// @ingroup domi_ome
/// @brief Initializing Filter Description
/// @param [in] model_filter Filter information defined in the offline model
/// @param [out] cc_filter Definition of the filter used by CC
/// @return SUCCESS success
/// @return FAILED fail
///
static Status InitFilterDescriptor(const ge::GeTensor &model_filter, ccFilterDescriptor_t &cc_filter);

///
/// @brief Extract AIPP parameters from AttrDefMap and splice them
/// @param [in] aipp_attr attr of operator
/// @param [out] aipp_params aipp parameters
/// @return enum of tagCCAippInputFormat
///
static Status ConvertAippParams(const GeAttrValue::NamedAttrs &aipp_attr, domi::AippOpParams *aipp_params);
static Status TransferDim(const std::vector<int64_t> &dim, std::vector<int64_t> &dim_vector);
static void SliceData(std::vector<char *> &input, int64_t chunk_size, std::vector<char *> &output, int64_t begin,
int64_t out_dim, int64_t stride);
static Status SetOutputSliceData(void *data, int64_t data_size, int32_t data_type, std::vector<int64_t> &input_dims,
std::vector<int64_t> &begin, std::vector<int64_t> &output_dims, ge::GeTensor *output,
std::vector<int64_t> &stride);

///
/// @ingroup domi_omg
/// @brief Convert the convolution‘s weight data from [h, w, c, k] to [k, c, h, w]
/// @param [in] input Weight data in HWCK format
/// @param [in] H value of H dimension
/// @param [in] W value of W dimension
/// @param [in] C value of C dimension
/// @param [in] K value of K dimension
/// @param [out] output Data pointer after conversion. The format is KCHW.
///
static void TransDataHWCK2KCHW(const void *input, int64_t H, int64_t W, int64_t C, int64_t K, void **output);
///
/// @ingroup domi_omg
/// @brief Converts the convolution‘s weight data from [k, c, h, w] to [h, w, c, k].
/// @param [in] input Weight data in HWCK format
/// @param [in] K value of K dimension
/// @param [in] C value of C dimension
/// @param [in] H value of H dimension
/// @param [in] W value of W dimension
/// @param [out] output Data pointer after conversion. The format is HWCK
///
static void TransDataKCHW2HWCK(const void *input, int64_t K, int64_t C, int64_t H, int64_t W, void *output);
///
/// @ingroup domi_omg
/// @brief Initialize the input and output description of the data node which is applied to filter weight in the
/// training network
/// @param [in] model_tensor input and output tensor information
/// @param [out] cc_tensor Tensor in CCE format after conversion
////
static Status InitFilterTensorDescriptor(const ge::GeTensorDesc &model_tensor, ccFilterDescriptor_t &cc_tensor);

static void SetTensorDescriptorAllOffsetQuantizeInfo(const GeTensorDesc &tensor, ccTensorDescriptor_t cc_tensor);
static vector<ConstGeTensorPtr> GetWeights(const ge::Node &node);
static vector<ConstGeTensorPtr> GetWeights(ge::ConstNodePtr node);
static vector<GeTensorPtr> MutableWeights(const ge::Node &node);
static vector<GeTensorPtr> MutableWeights(const ge::NodePtr node);
static Status SetWeights(ge::Node &node, const vector<ge::GeTensorPtr> &weights);
static Status SetWeights(ge::NodePtr node, const vector<ge::GeTensorPtr> &weights);
static Status GetShapeDataFromConstTensor(const ConstGeTensorPtr &tensor, DataType type, std::vector<int64_t> &dims);

private:
friend class CceTensorDescriptor;
static uint32_t GetRealDimCnt(const GeTensorDesc &tensor_desc);
};

class CceTensorDescriptor;

using CceTensorDescriptorPtr = std::shared_ptr<CceTensorDescriptor>;

class CceTensorDescriptor {
public:
explicit CceTensorDescriptor(ccTensorDescriptor_t cc_tensor);

CceTensorDescriptor(const CceTensorDescriptor &) = delete;
CceTensorDescriptor &operator=(const CceTensorDescriptor &) = delete;

~CceTensorDescriptor();

ccTensorDescriptor_t GetPtr() { return cc_tensor_; }

///
/// @brief Initializes the tensor based on shape information.
/// @param[in] format data permutation format
/// @param[in] data_type Data Type
/// @param[in] dim dim information
/// @return return code
///
Status InitTensor(int32_t format, int32_t data_type, const std::vector<int64_t> &dims);

Status InitTensor(int32_t format, int32_t data_type, const ge::GeShape &shape);

///
/// @brief get format of tensor
/// @param[out] format format of the tensor
/// @return return code
///
Status GetFormat(ccTensorFormat_t *format);

///
/// @brief Obtains the size of the tensor.
/// @param[out] size size of Tensor
/// @return return code
///
Status GetTensorSizeInBytes(uint32_t *size);

///
/// @brief transform tensor between 4d(NCHW) and 5d(NC1HWC0)
/// @param [in] xDesc descriptor of input tensor
/// @param [in] x point to input data in host memory
/// @param [in] dataTypeTransmode mode of data type transform
/// @param [in] yDesc descriptor of output tensor
/// @param [in|out] y point to output data in host memory
/// @param [in] ySizeInBytes size of outputData
/// @return return code
///
static Status TransTensor(const ccTensorDescriptor_t xDesc, const void *x, const CceTensorDescriptorPtr &yDesc,
void *y, uint32_t ySizeInBytes);

///
/// @brief CceTensorDescriptor Static Constructor
/// @return CceTensorDescriptor smart pointer
///
static CceTensorDescriptorPtr Create();

ccTensorDescriptor_t cc_tensor_ = nullptr;
};
} // namespace ge
#endif // INC_FRAMEWORK_COMMON_OP_GE_OP_UTILS_H_

+ 425
- 0
inc/framework/common/op/op_parser_util.h View File

@@ -0,0 +1,425 @@
/**
* 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 INC_FRAMEWORK_COMMON_OP_OP_PARSER_UTIL_H_
#define INC_FRAMEWORK_COMMON_OP_OP_PARSER_UTIL_H_

#include <cce/dnn.h>
#include <limits.h>
#include <math.h>
#include <stdint.h>

namespace domi {
// General
const float DEFAULT_ALPHA_VALUE = 1.0;
const float DEFAULT_BETA_VALUE = 0.0;
const uint32_t NORMAL_INPUT_NUM = 1;
const uint32_t NORMAL_OUTPUT_NUM = 1;
const uint32_t NORMAL_WORKSPACE_NUM = 0;
const int32_t NORMAL_1D_DIM_NUM = 1;
const int32_t NORMAL_SCALE_DIM_NUM = 0;
const int NORMAL_TENSOR_FORMAT = static_cast<const int>(cce::CC_TENSOR_NC1HWC0);
const int NORMAL_TENSOR_SIZE = 4;
const int NORMAL_DEVICE_DATA_TYPE = static_cast<const int>(cce::CC_DATA_HALF);
const int DEFAULT_POOLING_MODE = static_cast<const int>(cce::CC_POOLING_MAX);
const uint32_t DEFAULT_REAL_DIM_CNT = 4;

// Const
const uint32_t CONST_OP_INPUT_NUM = 0;
const uint32_t CONST_OP_NORMAL_WEIGHT_SIZE = 1;

// MatMul
const uint32_t MATMUL_INPUT_NUM = 2;

// ActivationGrad
const int32_t ACTIVATIONGRAD_INPUT_NUM = 2;

// FusedBatchNorm
const int32_t FUSED_BATCH_NORM_WORKSPACE_NUM = 1;
const int32_t FUSED_BATCH_NORM_INPUT_NUM = 5;
const int32_t FUSED_BATCH_NORM_OUTPUT_NUM = 5;
// FusedBatchNormGrad
const int32_t FUSEDBATCHNORMGRAD_WORKSPACE_NUM = 1;
const int32_t FUSEDBATCHNORMGRAD_INPUT_NUM = 5;
const int32_t FUSEDBATCHNORMGRAD_OUTPUT_NUM = 3;

// Conv
const uint32_t CONVOLUTION_WORKSPACE_NUM = 1;
const uint32_t CONVOLUTION_PAD_SIZE = 4;
const uint32_t CONVOLUTION_STRIDE_SIZE = 2;
const uint32_t CONVOLUTION_DILATION_SIZE = 2;
const int32_t CONVOLUTION_ADJ_SIZE = 2;
const int32_t CONVOLUTION_TARGET_SHAPE_SIZE = 2;

// ConvGradFilter
const uint32_t CONVGRADFILTER_WORKSPACE_NUM = 1;
const uint32_t CONVGRADFILTER_INPUT_NUM = 3;

// Pooling
const uint32_t POOLING_WINDOW_SIZE = 2;
const uint32_t POOLING_STRIDE_SIZE = 2;
const uint32_t POOLING_PAD_SIZE = 4;

// Add Sub Mul
const uint32_t ADD_INPUT_NUM = 2;
const uint32_t SUB_INPUT_NUM = 2;
const uint32_t MUL_INPUT_NUM = 2;
const uint32_t DIV_INPUT_NUM = 2;
const uint32_t ADD_WORKSPACE_NUM = 1;
const uint32_t SUB_WORKSPACE_NUM = 1;
const uint32_t MUL_WORKSPACE_NUM = 1;
const uint32_t DIV_WORKSPACE_NUM = 1;

const int32_t DEFAULT_AXIS_VALUE = -1;

const int32_t RESHAPE_AXIS_DEFAULT_VALUE = 0;
const int32_t RESHAPE_NUM_AXES_DEFAULT_VALUE = -1;
const uint32_t RESHAPE_WORKSPACE_NUM = 1;

const uint32_t FLATTEN_WORKSPACE_NUM = 1;

const int32_t CONCAT_MIN_INPUT_SIZE = 1;
const int32_t CONCAT_DEFAULT_AXIS = 1;
const uint32_t CONCAT_WORKSPACE_NUM = 1;

// The value for LRN parameters
const uint32_t LRN_DEFAULT_NORM_REGION = 0;
const float LRN_DEFAULT_K = 1.0;
const uint32_t LRN_DEFAULT_LOCAL_SIZE = 5;
const float LRN_DEFAULT_ALPHA = 1.0;
const float LRN_DEFAULT_BETA = 0.75;

///
/// @ingroup domi_common
/// @brief default value of roipooling
///
const uint32_t ROIPOOLING_DEFAULT_POOLED_H = 0;
const uint32_t ROIPOOLING_DEFAULT_POOLED_W = 0;
const float ROIPOOLING_DEFAULT_SPATIAL_SCALE = 1;
const int32_t ROIPOOLING_DEFAULT_SAMPLING_RATIO = -1;

// DetectionOutput
const int32_t DETECTIONOUTPUT_INPUT_SIZE = 3;
const int32_t DETECTIONOUTPUT_OUTPUT_SIZE = 2;
const int32_t DETECTIONOUTPUT_WORKSPACE_NUM = 1;
const int DETECTIONOUTPUT_CLASS_NUM = 20;
const int DETECTIONOUTPUT_NUM_CLASSES_DEFAULT_VALUE = 21;
const float DETECTIONOUTPUT_NMS_THRESHOLD_DEFAULT_VALUE = 0.3;
const float DETECTIONOUTPUT_CONFIDENCE_THRESHOLD_DEFAULT_VALUE = 0.8;

// Proposal
const int32_t PROPOSAL_INPUT_SIZE = 3;
const int32_t PROPOSAL_OUTPUT_MAX_SIZE = 2;
const int32_t PROPOSAL_WORKSPACE_NUM = 1;
const float PROPOSAL_BASE_SIZE_DEFAULT_VALUE = 16;
const float PROPOSAL_RATIO_DIM_0_DEFAULT_VALUE = 0.5;
const float PROPOSAL_RATIO_DIM_1_DEFAULT_VALUE = 1;
const float PROPOSAL_RATIO_DIM_2_DEFAULT_VALUE = 2;
const float PROPOSAL_SCALE_DIM_0_DEFAULT_VALUE = 8;
const float PROPOSAL_SCALE_DIM_1_DEFAULT_VALUE = 16;
const float PROPOSAL_SCALE_DIM_2_DEFAULT_VALUE = 32;
const float PROPOSAL_MIN_SIZE_DEFAULT_VALUE = 16;
const int PROPOSAL_PRE_NMS_TOPN_DEFAULT_VALUE = 6000;
const int PROPOSAL_POST_NMS_TOPN_DEFAULT_VALUE = 304;
const float PROPOSAL_NMS_THRESH_DEFAULT_VALUE = 0.7;
const float PROPOSAL_FILTER_THRESH_DEFAULT_VALUE = 0;

// TVM OP
const uint32_t DEFAULT_KERNEL_BLOCK_DIM = 1;

// Softmax
const int32_t SOFTMAX_WORKSPACE_NUM = 1;

// SoftmaxCrossEntropy
const int32_t SOFTMAXCROSSENTROPY_INPUT_NUM = 2;
const int32_t SOFTMAXCROSSENTROPY_OUTPUT_NUM = 2;

// Permute
const int32_t PERMUTE_INPUT_NUM = 1;
const int32_t PERMUTE_OUTPUT_NUM = 1;
const int32_t PERMUTE_WORKSPACE_NUM = 1;
const int32_t PERMUTE_ORDER_NUM = 4;

// Ssd normalize
const int SSD_NORMALIZE_INPUT_SIZE = 1;
const float SSD_NORMALIZE_EPS_DEFAULT_VALUE = 2e-7;

// SsdPriroBox
const int32_t SSD_PRIOR_BOX_WORKSPACE_NUM = 1;
const int32_t SSD_PRIOR_BOX_INPUT_NUM = 2;
const bool SSD_PRIOR_BOX_FLIP_VALUE = true;
const bool SSD_PRIOR_BOX_CLIP_VALUE = false;
const double SSD_PRIOR_BOX_ASPECT_OFFSET_VALUE = 0.5;
const double SSD_PRIORBOX_VARIANCE_VALUE = 0.1;
const double SSD_PRIORBOX_VARIANCE_SIZE_ONE = 1;
const double SSD_PRIORBOX_VARIANCE_SIZE_FOUR = 4;
const double SSD_PRIORBOX_ASPECT_RATIO_VALUE = 1.0;
const int SSD_PRIOR_BOX_CODETYPE_CORNER_VALUE = 1;
const int SSD_PRIOR_BOX_CODETYPE_CENTER_SIZE_VALUE = 2;
const int SSD_PRIOR_BOX_CODETYPE_CORNER_SIZE_VALUE = 3;

// Ssd DetectionOutput
const int32_t SSD_DETECTIONOUTPUT_INPUT_SIZE = 3;
const int32_t SSD_DETECTIONOUTPUT_INPUT_SIZE_AFTER_FUSION = 2;
const int32_t SSD_DETECTIONOUTPUT_OUTPUT_SIZE = 2;
const int32_t SSD_DETECTIONOUTPUT_OUTPUT_SIZE_AFTER_FUSION = 3;
const int32_t SSD_DETECTIONOUTPUT_WORKSPACE_NUM = 1;
const int32_t SSD_DETECTIONOUTPUT_WORKSPACE_NUM_AFTER_FUSION = 0;
const bool SSD_DETECTIONOUTPUT_SHARED_LOCATION_DEFAULT_VALUE = true;
const int32_t SSD_DETECTIONOUTPUT_BACKGROUND_LABEL_ID_DEFAULT_VALUE = 0;
const float SSD_DETECTIONOUTPUT_NMS_THRESHOLD_DEFAULT_VALUE = 0.3;
const int32_t SSD_DETECTIONOUTPUT_TOP_K_DEFAULT_VALUE = 200;
const float SSD_DETECTIONOUTPUT_ETA_DEFAULT_VALUE = 1.0;
const int SSD_DETECTIONOUTPUT_CODE_TYPE_DEFAULT_VALUE = static_cast<const int>(cce::CC_BOX_CENTER_SIZE);
const int32_t SSD_DETECTIONOUTPUT_KEEP_TOP_K_DEFAULT_VALUE = 200;
const bool SSD_DETECTIONOUTPUT_VARIANCE_ENCODED_IN_TARGET_DEFAULT_VALUE = false;
const float SSD_DETECTIONOUTPUT_CONFIDENCE_THRESHOLD_DEFAULT_VALUE = 0.1;

// Refinedet DetectionOutput
const int32_t REFINEDET_DETECTIONOUTPUT_INPUT_SIZE = 5;
const int32_t REFINEDET_DETECTIONOUTPUT_INPUT_SIZE_AFTER_FUSION = 2;
const int32_t REFINEDET_DETECTIONOUTPUT_OUTPUT_SIZE = 2;
const int32_t REFINEDET_DETECTIONOUTPUT_OUTPUT_SIZE_AFTER_FUSION = 3;
const int32_t REFINEDET_DETECTIONOUTPUT_WORKSPACE_NUM = 1;
const bool REFINEDET_DETECTIONOUTPUT_SHARED_LOCATION_DEFAULT_VALUE = true;
const int32_t REFINEDET_DETECTIONOUTPUT_BACKGROUND_LABEL_ID_DEFAULT_VALUE = 0;
const float REFINEDET_DETECTIONOUTPUT_NMS_THRESHOLD_DEFAULT_VALUE = 0.3;
const int32_t REFINEDET_DETECTIONOUTPUT_TOP_K_DEFAULT_VALUE = 200;
const float REFINEDET_DETECTIONOUTPUT_ETA_DEFAULT_VALUE = 1.0;
const bool REFINEDET_DETECTIONOUTPUT_VARIANCE_ENCODED_IN_TARGET_DEFAULT_VALUE = false;
const int REFINEDET_DETECTIONOUTPUT_CODE_TYPE_DEFAULT_VALUE = static_cast<const int>(cce::CC_BOX_CENTER_SIZE);
const int32_t REFINEDET_DETECTIONOUTPUT_KEEP_TOP_K_DEFAULT_VALUE = 200;
const float REFINEDET_DETECTIONOUTPUT_CONFIDENCE_THRESHOLD_DEFAULT_VALUE = 0.1;
const float REFINEDET_DETECTIONOUTPUT_OBJECTNESS_SCORE_DEFAULT_VALUE = 0;

// Channel axpy
const int32_t CHANNEL_AXPY_INPUT_NUM = 3;
const int32_t CHANNEL_AXPY_INPUT_DIM_SIZE = 4;
const int32_t CHANNEL_AXPY_WORKSPACE_NUM = 1;

// Psroi pooling
const int PSROI_POOLING_INPUT_COUNT = 2;
const int PSROI_POOLING_WORKSPACE_NUM = 1;

// MaxPoolWithArgmax
const uint32_t MAX_POOL_WITH_ARGMAX_OUTPUT_NUM = 2;
const uint32_t MAX_POOL_GRAD_WITH_ARGMAX_INPUT_NUM = 3;

// AvgPoolGrad
const uint32_t AVG_POOL_GRAD_INPUT_NUM = 2;

// ROIAlign
const int32_t ROIALIGN_INPUT_SIZE = 2;
const int32_t ROIALIGN_WORKSPACE_NUM = 1;
const int32_t ROIALIGN_DEFAULT_POOLED_H = 1;
const int32_t ROIALIGN_DEFAULT_POOLED_W = 1;

// Correlation
const uint32_t CORRELATION_INPUT_NUM = 2;
const int CORRELATION_WORKSPACE_NUM = 1;

// Detectionpostprocess
const int32_t POSTPROCESS_INPUT_SIZE = 4;
const int32_t POSTPROCESS_OUTPUT_SIZE = 2;
const int32_t POSTPROCESS_WORKSPACE_NUM = 1;
const uint32_t POSTPROCESS_CLS_NUM_DEFAULT_VALUE = 12;
const uint32_t POSTPROCESS_POST_NMS_TOPN_DEFAULT_VALUE = 100;
const float POSTPROCESS_NMS_THRESH_DEFAULT_VALUE = 0.3;
const float POSTPROCESS_CONF_THRESH_DEFAULT_VALUE = 0.5;
const float POSTPROCESS_BBOX_REG_WEIGHT_DIM_DEFAULT_VALUE = 1.0;
const int32_t POSTPROCESS_BBOX_REG_WEIGHT_SIZE_DEFAULT_VALUE = 4;

// Split
const int32_t SPLIT_INPUT_NUM = 2;
const int32_t SPLIT_DEFAULT_AXIS_VALUE = 1;
const int32_t SPLIT_MIN_OUTPUT_SIZE = 1;

const uint32_t STRIDEDSLICE_INPUT_NUM = 4;
// Slice
const int32_t SLICE_INPUT_NUM = 3;
const int32_t SLICE_WEIGHT_NUM = 2;

// GatherNd
const int32_t GATHERND_INPUT_NUM = 2;
// ArgMax
const int32_t ARGMAX_INPUT_NUM = 2;
const int32_t ARGMAX_REAL_INPUT_NUM = 1;

// HighWay
const int32_t HIGHWAY_INPUT_NUM = 4;
const int32_t HIGHWAY_WORKSPACE_NUM = 1;
// RealDiv
const int32_t REALDIV_INPUT_NUM = 2;

// Range
const int32_t RANGE_INPUT_NUM = 3;
const int32_t RANGE_OUTPUT_NUM = 1;
const int32_t RANGE_INPUT_DIM_SIZE = 0;

// Pad
const int32_t PAD_WEIGHT_NUM = 1;
const int32_t PAD_DIM_SIZE = 2;
const int32_t PAD_DIM0 = 4;
const int32_t PAD_DIM1 = 2;
const int32_t PAD_WEIGHT_WITH_CONSTANT_NUM = 2;
const int32_t PAD_CONSTATNT_DEFAULT_VALUE = 0;
const int32_t PAD_PADDINGS_SIZE = 8;

// Tile
const int32_t TILE_WEIGHT_NUM = 1;
const int32_t TILE_MULTIPLES_DIM_SIZE = 1;

// DecodeBbox
const int32_t DECODE_BBOX_INPUT_NUM = 2;

// GenerateRpnProposals
const int32_t GENERATE_RPN_PROPOSAL_INPUT_SIZE = 2;
const int32_t GENERATE_RPN_PROPOSAL_OUTPUT_SIZE = 3;

// Decode_BBox
const int32_t DECODE_BBOX_INPUT_SIZE = 2;
const int32_t DEFAULT_DECODE_CLIP_VALUE = 0;

// FastRcnnPredictions
const int32_t FASTRCNN_PREDICTIONS_INPUT_SIZE = 2;
const int32_t FASTRCNN_PREDICTIONS_OUTPUT_SIZE = 4;

const int32_t CLIP_BOXES_INPUT_NUM = 1;
const int32_t CLIP_BOXES_WEIGHT_SIZE = 1;
const int32_t CLIP_BOXES_WEIGHT_ITEM_SIZE = 2;
const int32_t CLIP_BOXES_OUTPUT_NUM = 1;

const int32_t FLOORDIV_INPUT_NUM = 2;
// Mean
const int32_t MEAN_WEIGHT_SIZE = 1;
const int32_t MEAN_WEIGHT_DIM_SIZE = 1;
const int32_t MEAN_WEIGHT_DIM = 2;
const int32_t MEAN_FIRST_AXIS = 2;
const int32_t MEAN_SECOND_AXIS = 3;
const int32_t MEAN_STRIDE_PLACE_HOLD = 1;
// Switch
const uint32_t SWITCH_INPUT_NUM = 2;
const uint32_t SWITCH_OUTPUT_NUM = 2;
// Merge
const uint32_t MERGE_INPUT_NUM = 2;
// Greater
const uint32_t GREATER_OUTPUT_NUM = 1;
const uint32_t GREATER_INPUT_NUM = 0;
const uint32_t GREATER_WEIGHT_NUM = 2;

// Yolo region
const uint32_t YOLO_REGION_OUTPUT_NUM = 3;
const uint32_t YOLO_REGION_WORKSPACE_NUM = 1;
const uint32_t YOLO_REGION_COORDS = 4;
const uint32_t YOLO_REGION_CLASSES = 20;
const uint32_t YOLO_REGION_BOXES = 1;
const bool YOLO_REGION_BACKGROUND = false;
const bool YOLO_REGION_SOFTMAX = false;
const bool YOLO_REGION_SOFTMAX_TREE = false;

// Yolo detectionoutput
const uint32_t YOLO_DETECTIONOUTPUT_INPUT_SIZE = 4;
const uint32_t YOLO_DETECTIONOUTPUT_OUTPUT_SIZE = 2;
const uint32_t YOLO_DETECTION_OUTPUT_WORKSPACE_NUM = 1;
const uint32_t YOLO_DETECTION_OUTPUT_CLASSES = 20;
const uint32_t YOLO_DETECTION_OUTPUT_BOXES_V2 = 5;
const uint32_t YOLO_DETECTION_OUTPUT_BOXES_V3 = 3;
const bool YOLO_DETECTION_OUTPUT_RELATIVE = true;
const float YOLO_DETECTION_OUTPUT_OBJECTNESS_THRESHOLD = 0.5;
const float YOLO_DETECTION_OUTPUT_CLASS_THRESHOLD = 0.5;
const uint32_t YOLO_DETECTION_OUTPUT_POST_TOP_K = UINT_MAX;
const float YOLO_DETECTION_OUTPUT_NMS_THRESHOLD = 0;
const float YOLO_DETECTION_OUTPUT_IOU_THRESHOLD_DECAY = 1.0;
const float YOLO_DETECTION_OUTPUT_COOR_SCALE_FACTOR = 1.0;

// Reorg
const int32_t REORG_DEFAULT_STRIDE = 2;
const uint32_t REORG_INPUT_COUNT = 1;
// Reshape
const int32_t RESHAPE_INPUT_NUM = 2;
// Maximum
const int32_t MAXIMUM_INPUT_NUM = 2;

// Spatialtf
const int32_t SPATIALTF_WORKSPACE_NUM = 1;

const int32_t REVERSE_DEFAULT_AXIS = 1;
// Crop
const int32_t CROP_AXIS = 2;
const int32_t CROP_INPUT_NUM = 2;

// ConvGradInput
const uint32_t CONVGRADINPUT_WORKSPACE_NUM = 1;
const uint32_t CONVGRADINPUT_INPUT_NUM = 3;

// RNN
const uint32_t RNN_WORKSPACE_NUM = 1;

// Cropandresize
const int32_t CROPANDRESIZE_WEIGHT_NUM = 1;
const int32_t CROPANDRESIZE_CROP_DIM_SIZE = 1;
const int32_t CROP_DIM0 = 2;

// Attention decoder weight index
const uint32_t ATTENTION_DECODER_WEIGHT_ATTENW0 = 0;
const uint32_t ATTENTION_DECODER_WEIGHT_ATTENTION0_KERNEL = 1;
const uint32_t ATTENTION_DECODER_WEIGHT_ATTNOUTPUTPROJECTION_KERNEL = 2;
const uint32_t ATTENTION_DECODER_WEIGHT_ATTENTION_DECODER_KERNEL = 3;
const uint32_t ATTENTION_DECODER_WEIGHT_CELL0_GATES_KERNEL = 4;
const uint32_t ATTENTION_DECODER_WEIGHT_CELL0_CANDIDATE_KERNEL = 5;
const uint32_t ATTENTION_DECODER_WEIGHT_CELL1_GATES_KERNEL = 6;
const uint32_t ATTENTION_DECODER_WEIGHT_CELL1_CANDIDATE_KERNEL = 7;
const uint32_t ATTENTION_DECODER_WEIGHT_ATTENTION0_BIAS = 8;
const uint32_t ATTENTION_DECODER_WEIGHT_ATTNOUTPUTPROJECTION_BIAS = 9;
const uint32_t ATTENTION_DECODER_WEIGHT_ATTENTION_DECODER_BIAS = 10;
const uint32_t ATTENTION_DECODER_WEIGHT_CELL0_GATES_BIAS = 11;
const uint32_t ATTENTION_DECODER_WEIGHT_CELL0_CANDIDATE_BIAS = 12;
const uint32_t ATTENTION_DECODER_WEIGHT_CELL1_GATES_BIAS = 13;
const uint32_t ATTENTION_DECODER_WEIGHT_CELL1_CANDIDATE_BIAS = 14;
const uint32_t ATTENTION_DECODER_WEIGHT_EMBEDDING = 15;
const uint32_t ATTENTION_DECODER_WEIGHT_ATTENVA = 16;
const uint32_t ATTENTION_DECODER_WEIGHT_DECODER_INITIAL = 17;

// Attention decoder weight size
const uint32_t ATTENTION_DECODER_WEIGHT_SIZE = 18;
const uint32_t ATTENTION_DECODER_INPUT_SIZE = 2;
const uint32_t ATTENTION_DECODER_WORKSPACE_NUM = 1;
const uint32_t ATTENTION_DECODER_INPUT_DECODER_INPUTS = 0;
const uint32_t ATTENTION_DECODER_INPUT_DECODER_INITIAL_HIDDEN = 1;

const int ATTENTION_DECODER_ALGO_NORMAL = 0;
const int ATTENTION_DECODER_SYMBOLS = 10000;
const int ATTENTION_DECODER_EMBEDDING_SIZE = 128;
const int ATTENTION_DECODER_ATTENTION_NUM_HIDDEN = 256;
const int ATTENTION_DECODER_DECODER_NUM_HIDDEN = 128;
const int ATTENTION_DECODER_DECODER_NUM_LAYERS = 2;
const int ATTENTION_DECODER_RNN_UNBIDIRECTIONAL = 0;
const int ATTENTION_DECODER_SEQLEN_VALUE = 57;
const int ATTENTION_DECODER_GRU = 3;

// Logicaland
const int32_t LOGICAL_AND_INPUT_NUM = 2;
const int32_t EQUAL_INPUT_NUM = 2;

static const int32_t OP_WEIGHT_MEM_BASE_OFFSET = 512;

// MultiShape
const uint32_t MULTI_SHAPE_INPUT_NUM = 2;

// Shufflechannel
const uint32_t SHUFFLECHANNEL_DEFAULT_GROUP = 1;
} // namespace domi
#endif // INC_FRAMEWORK_COMMON_OP_OP_PARSER_UTIL_H_

+ 62
- 0
inc/framework/common/op_types.h View File

@@ -0,0 +1,62 @@
/**
* 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 INC_FRAMEWORK_COMMON_OP_TYPES_H_
#define INC_FRAMEWORK_COMMON_OP_TYPES_H_

#include <set>
#include <string>

namespace ge {
class OpTypeContainer {
public:
static OpTypeContainer *Instance() {
static OpTypeContainer instance;
return &instance;
}
~OpTypeContainer() = default;

void Register(const std::string &op_type) { op_type_list_.insert(op_type); }

bool IsExisting(const std::string &op_type) {
auto iter_find = op_type_list_.find(op_type);
return iter_find != op_type_list_.end();
}

protected:
OpTypeContainer() {}

private:
std::set<std::string> op_type_list_;
};

class OpTypeRegistrar {
public:
explicit OpTypeRegistrar(const std::string &op_type) { OpTypeContainer::Instance()->Register(op_type); }
~OpTypeRegistrar() {}
};

#define REGISTER_OPTYPE_DECLARE(var_name, str_name) \
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY extern const char *var_name;

#define REGISTER_OPTYPE_DEFINE(var_name, str_name) \
const char *var_name = str_name; \
const OpTypeRegistrar g_##var_name##_reg(str_name);

#define IS_OPTYPE_EXISTING(str_name) (OpTypeContainer::Instance()->IsExisting(str_name))
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_OP_TYPES_H_

+ 60
- 0
inc/framework/common/scope_guard.h View File

@@ -0,0 +1,60 @@
/**
* 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 INC_FRAMEWORK_COMMON_SCOPE_GUARD_H_
#define INC_FRAMEWORK_COMMON_SCOPE_GUARD_H_

#include <functional>
#include <iostream>

/// Usage:
/// Acquire Resource 1
/// MAKE_GUARD([&] { Release Resource 1 })
/// Acquire Resource 2
/// MAKE_GUARD([&] { Release Resource 2 })
#define GE_MAKE_GUARD(var, callback) ge::ScopeGuard make_guard_##var(callback)
#define GE_DISMISS_GUARD(var) make_guard_##var.Dismiss()

namespace ge {
class ScopeGuard {
public:
// Noncopyable
ScopeGuard(ScopeGuard const &) = delete;
ScopeGuard &operator=(ScopeGuard const &) = delete;

explicit ScopeGuard(const std::function<void()> &on_exit_scope) : on_exit_scope_(on_exit_scope), dismissed_(false) {}

~ScopeGuard() {
if (!dismissed_) {
if (on_exit_scope_ != nullptr) {
try {
on_exit_scope_();
} catch (std::bad_function_call &e) {
} catch (...) {
}
}
}
}

void Dismiss() { dismissed_ = true; }

private:
std::function<void()> on_exit_scope_;
bool dismissed_;
};
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_SCOPE_GUARD_H_

+ 156
- 0
inc/framework/common/string_util.h View File

@@ -0,0 +1,156 @@
/**
* 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 INC_FRAMEWORK_COMMON_STRING_UTIL_H_
#define INC_FRAMEWORK_COMMON_STRING_UTIL_H_

#include <securec.h>

#include <algorithm>
#include <functional>
#include <sstream>
#include <string>
#include <vector>

namespace ge {
class StringUtils {
public:
static std::string &Ltrim(std::string &s) {
#if __cplusplus >= 201103L
(void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); }));
#else
(void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
#endif
return s;
}

static std::string &Rtrim(std::string &s) {
#if __cplusplus >= 201103L
(void)s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int c) { return !std::isspace(c); }));
#else
(void)s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
#endif
return s;
}

///
/// @ingroup domi_common
/// @brief delete spaces at the beginning and end of a string
/// @param [in] string to be trimmed
/// @return string after trim
///
static std::string &Trim(std::string &s) { return Ltrim(Rtrim(s)); }

///
/// @ingroup domi_common
/// @brief string splitting
/// @param [in] str string to be trimmed
/// @param [in] delim separator
/// @return string array after segmentation
///
static std::vector<std::string> Split(const std::string &str, char delim) {
std::vector<std::string> elems;

if (str.empty()) {
elems.emplace_back("");
return elems;
}

std::stringstream ss(str);
std::string item;

while (getline(ss, item, delim)) {
elems.push_back(item);
}

auto str_size = str.size();
if (str_size > 0 && str[str_size - 1] == delim) {
elems.emplace_back("");
}

return elems;
}
///
/// @ingroup domi_common
/// @brief obtain the file name
/// @param [in] s path name
/// @return file name
///
static std::string GetFileName(std::string &s) {
if (s.empty()) {
return "";
}
std::vector<std::string> files = StringUtils::Split(s, '/');

return files.empty() ? "" : files[files.size() - 1];
}
///
/// @ingroup domi_common
/// @brief full replacement
/// @link
/// @param [in] str str string to be replaced
/// @param [in] old_value old Characters Before Replacement
/// @param [in] new_value new Characters Before Replacement
/// @return string after replacement
///
static std::string ReplaceAll(std::string str, const std::string &old_value, const std::string &new_value) {
std::string::size_type cur_pos = 0;
std::string::size_type old_length = old_value.length();
std::string::size_type new_length = new_value.length();
// cycle replace
for (; cur_pos != std::string::npos; cur_pos += new_length) {
if ((cur_pos = str.find(old_value, cur_pos)) != std::string::npos) {
(void)str.replace(cur_pos, old_length, new_value);
} else {
break;
}
}
return str;
}

///
/// @ingroup domi_common
/// @brief checks whether a character string starts with a character string (prefix)
/// @link
/// @param [in] str string to be compared
/// @param [in] str_x prefix
/// @return if the value is a prefix, true is returned. Otherwise, false is returned
///
static bool StartWith(const std::string &str, const std::string str_x) {
return ((str.size() >= str_x.size()) && (str.compare(0, str_x.size(), str_x) == 0));
}

///
/// @ingroup domi_common
/// @brief format string
/// @link
/// @param [in] format specifies the character string format
/// @param [in] ... format Filling Content
/// @return formatted string
///
static std::string FormatString(const char *format, ...) {
const uint32_t MAX_BUFFER_LEN = 1024; // the stack memory plint check result must be less than 1024
va_list args;
va_start(args, format);
char buffer[MAX_BUFFER_LEN] = {0};
int32_t ret = vsnprintf_s(buffer, MAX_BUFFER_LEN, MAX_BUFFER_LEN - 1, format, args);
va_end(args);
return ret > 0 ? buffer : "";
}
};
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_STRING_UTIL_H_

+ 1048
- 0
inc/framework/common/types.h
File diff suppressed because it is too large
View File


+ 378
- 0
inc/framework/common/util.h View File

@@ -0,0 +1,378 @@
/**
* 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 INC_FRAMEWORK_COMMON_UTIL_H_
#define INC_FRAMEWORK_COMMON_UTIL_H_

#include <google/protobuf/text_format.h>
#include <limits.h>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>

#include "framework/common/debug/ge_log.h"
#include "framework/common/debug/log.h"
#include "framework/common/scope_guard.h"
#include "framework/common/ge_inner_error_codes.h"
#include "mmpa/mmpa_api.h"

#define CHECK_FALSE_EXEC(expr, exec_expr, ...) \
{ \
bool b = (expr); \
if (!b) { \
exec_expr; \
} \
};

// new ge marco
// Encapsulate common resource releases
#define GE_MAKE_GUARD_RTMEM(var) \
GE_MAKE_GUARD(var, [&] { \
if (var) GE_CHK_RT(rtFreeHost(var)); \
});

#define GE_MAKE_GUARD_RTSTREAM(var) \
GE_MAKE_GUARD(var, [&] { \
if (var) GE_CHK_RT(rtStreamDestroy(var)); \
});

#define GE_MAKE_GUARD_RTEVENT(var) \
GE_MAKE_GUARD(var, [&] { \
if (var) GE_CHK_RT(rtEventDestroy(var)); \
});

#define GE_MAKE_GUARD_TENSOR(var) \
GE_MAKE_GUARD(var, [&] { \
if (var) GE_CHK_CCE(ccDestroyTensorDescriptor(&var)); \
});

#define GE_MAKE_GUARD_FILTER_DESC(var) \
GE_MAKE_GUARD(var, [&] { \
if (var) GE_CHK_CCE(ccDestroyFilterDescriptor(&var)); \
});

#define GE_RETURN_WITH_LOG_IF_ERROR(expr, ...) \
do { \
const ::ge::Status _status = (expr); \
if (_status) { \
GELOGE(ge::FAILED, __VA_ARGS__); \
return _status; \
} \
} while (0)

// Check if the parameter is false. If yes, return FAILED and record the error log
#define GE_RETURN_WITH_LOG_IF_FALSE(condition, ...) \
do { \
bool _condition = (condition); \
if (!_condition) { \
GELOGE(ge::FAILED, __VA_ARGS__); \
return ge::FAILED; \
} \
} while (0)

// Check if the parameter is null. If yes, return PARAM_INVALID and record the error
#define GE_CHECK_NOTNULL(val) \
do { \
if (val == nullptr) { \
GELOGE(ge::PARAM_INVALID, "param[#val] must not be null."); \
return ge::PARAM_INVALID; \
} \
} while (0)

// Check if the parameter is null. If yes, return PARAM_INVALID and record the error
#define GE_CHECK_NOTNULL_JUST_RETURN(val) \
do { \
if (val == nullptr) { \
GELOGE(ge::PARAM_INVALID, "param[#val] must not be null."); \
return; \
} \
} while (0)

// Check whether the parameter is null. If so, execute the exec_expr expression and record the error log
#define GE_CHECK_NOTNULL_EXEC(val, exec_expr) \
do { \
if (val == nullptr) { \
GELOGE(ge::PARAM_INVALID, "param[#val] must not be null."); \
exec_expr; \
} \
} while (0)

// Check whether the parameter is null. If yes, return directly and record the error log
#define GE_RT_VOID_CHECK_NOTNULL(val) \
do { \
if (val == nullptr) { \
GELOGE(ge::PARAM_INVALID, "param[#val] must not be null."); \
return; \
} \
} while (0)

// Check if the parameter is null. If yes, return false and record the error log
#define GE_RT_FALSE_CHECK_NOTNULL(val) \
do { \
if (val == nullptr) { \
GELOGE(ge::FAILED, "param[#val] must not be null."); \
return false; \
} \
} while (0)

// Check if the parameter is out of bounds
#define GE_CHECK_SIZE(size) \
do { \
if (size == 0) { \
GELOGE(ge::PARAM_INVALID, "param[#size] is out of range"); \
return ge::PARAM_INVALID; \
} \
} while (0)

// Macros that define the size variable
#define GE_DEFINE_BYTE_SIZE(_var_name, _expr, _sizeof) \
uint32_t _var_name; \
do { \
uint32_t _expr_size = (_expr); \
uint32_t _sizeof_size = (_sizeof); \
if (_expr_size > (0xffffffff) / _sizeof_size) { \
GELOGE(ge::PARAM_INVALID, "byte_size: [#_var_name] is out of range"); \
return ge::PARAM_INVALID; \
} \
_var_name = _sizeof_size * _expr_size; \
} while (0);

// Check if the container is empty
#define GE_CHECK_VECTOR_NOT_EMPTY(vector) \
do { \
if (vector.empty()) { \
GELOGE(ge::FAILED, "param[#vector] is empty !"); \
return ge::FAILED; \
} \
} while (0)

// Check if the value on the left is greater than or equal to the value on the right
#define GE_CHECK_GE(lhs, rhs) \
do { \
if (lhs < rhs) { \
GELOGE(ge::PARAM_INVALID, "param[#lhs] is less than[#rhs]"); \
return ge::PARAM_INVALID; \
} \
} while (0)

// Check if the value on the left is less than or equal to the value on the right
#define GE_CHECK_LE(lhs, rhs) \
do { \
if (lhs > rhs) { \
GELOGE(ge::PARAM_INVALID, "param[#lhs] is greater than[#rhs]"); \
return ge::PARAM_INVALID; \
} \
} while (0)

#define GE_DELETE_NEW_SINGLE(var) \
{ \
if (var != nullptr) { \
delete var; \
var = nullptr; \
} \
};

#define GE_DELETE_NEW_ARRAY(var) \
{ \
if (var != nullptr) { \
delete[] var; \
var = nullptr; \
} \
};

///
/// @ingroup domi_common
/// @brief version of om.proto file
///
static constexpr int32_t OM_PROTO_VERSION = 2;

// Finding an Integer Ceiling Value Without Precision Loss
#define CEIL(N, n) (((N) + (n)-1) / (n))

namespace ge {
using google::protobuf::Message;

///
/// @ingroup domi_common
/// @brief Maximum file path length
///
const int32_t DOMI_MAX_PATH_LEN = 256;

///
/// @ingroup domi_common
/// @brief proto file in bianary format
/// @param [in] file path of proto file
/// @param [out] proto memory for storing the proto file
/// @return true success
/// @return false fail
///
bool ReadProtoFromBinaryFile(const char *file, Message *proto);

///
/// @ingroup domi_common
/// @brief Reads the proto structure from an array.
/// @param [in] data proto data to be read
/// @param [in] size proto data size
/// @param [out] proto Memory for storing the proto file
/// @return true success
/// @return false fail
///
bool ReadProtoFromArray(const void *data, int size, Message *proto);

///
/// @ingroup domi_proto
/// @brief Reads the proto file in the text format.
/// @param [in] file path of proto file
/// @param [out] message Memory for storing the proto file
/// @return true success
/// @return false fail
///
bool ReadProtoFromText(const char *file, google::protobuf::Message *message);

bool ReadProtoFromMem(const char *data, int size, google::protobuf::Message *message);

///
/// @ingroup: domi_common
/// @brief: get length of file
/// @param [in] input_file: path of file
/// @return long: File length. If the file length fails to be obtained, the value -1 is returned.
///
extern long GetFileLength(const std::string &input_file);

///
/// @ingroup domi_common
/// @brief Reads all data from a binary file.
/// @param [in] file_name path of file
/// @param [out] buffer Output memory address, which needs to be released by the caller.
/// @param [out] length Output memory size
/// @return false fail
/// @return true success
///
bool ReadBytesFromBinaryFile(const char *file_name, char **buffer, int &length);

bool ReadBytesFromBinaryFile(const char *file_name, std::vector<char> &buffer);

///
/// @ingroup domi_common
/// @brief Recursively Creating a Directory
/// @param [in] directory_path Path, which can be a multi-level directory.
/// @return 0 success
/// @return -1 fail
///
extern int CreateDirectory(const std::string &directory_path);

///
/// @ingroup domi_common
/// @brief Obtains the current time string.
/// @return Time character string in the format : %Y%m%d%H%M%S, eg: 20171011083555
///
std::string CurrentTimeInStr();

///
/// @ingroup domi_common
/// @brief onverts Vector of a number to a string.
/// @param [in] v Vector of a number
/// @return string
///
template <typename T>
std::string ToString(std::vector<T> &v) {
std::stringstream ss;
ss << "[";
for (T x : v) {
ss << x;
ss << ", ";
}
std::string strRet =
ss.str().substr(0, ss.str().length() - 2); // Delete the two extra characters at the end of the line.
strRet += "]";
return strRet;
}

///
/// @ingroup domi_common
/// @brief Converts RepeatedField to String.
/// @param [in] rpd_field RepeatedField
/// @return string
///
template <typename T>
std::string ToString(const google::protobuf::RepeatedField<T> &rpd_field) {
std::stringstream ss;
ss << "[";
for (T x : rpd_field) {
ss << x;
ss << ", ";
}
std::string strRet =
ss.str().substr(0, ss.str().length() - 2); // Delete the two extra characters at the end of the line.
strRet += "]";
return strRet;
}

///
/// @ingroup domi_common
/// @brief Obtains the absolute time (timestamp) of the current system.
/// @return Timestamp, in microseconds (US)
///
///
uint64_t GetCurrentTimestap();

///
/// @ingroup domi_common
/// @brief Check whether the product of two int64 numbers exceeds the int64 range.
/// @param [in] a
/// @param [in] b
/// @return false: true: The result is within the normal int64 range.
///
bool CheckInt64MulOverflow(int64_t a, int64_t b);

///
/// @ingroup domi_common
/// @brief Absolute path for obtaining files.
/// @param [in] path of input file
/// @param [out] Absolute path of a file. If the absolute path cannot be obtained, an empty string is returned
///
std::string RealPath(const char *path);

///
/// @ingroup domi_common
/// @brief Check whether the specified input file path is valid.
/// 1. The specified path cannot be empty.
/// 2. The path can be converted to an absolute path.
/// 3. The file path exists and is readable.
/// @param [in] file_path path of input file
/// @param [out] result
///
bool CheckInputPathValid(const std::string &file_path);

///
/// @ingroup domi_common
/// @brief Checks whether the specified output file path is valid.
/// @param [in] file_path path of output file
/// @param [out] result
///
bool CheckOutputPathValid(const std::string &file_path);

///
/// @ingroup domi_common
/// @brief Check whether the file path meets the whitelist verification requirements.
/// @param [in] filePath file path
/// @param [out] result
///
bool ValidateStr(const std::string &filePath, const std::string &mode);
} // namespace ge

#endif // INC_FRAMEWORK_COMMON_UTIL_H_

+ 66
- 0
inc/framework/dlog/log.h View File

@@ -0,0 +1,66 @@
/**
* 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 INC_FRAMEWORK_DLOG_LOG_H_
#define INC_FRAMEWORK_DLOG_LOG_H_

#include <string>
#if !defined(__ANDROID__) && !defined(ANDROID)
#include "toolchain/slog.h"
#else
#include<android/log.h>
#endif

#ifdef _MSC_VER
#define FUNC_NAME __FUNCTION__
#else
#define FUNC_NAME __PRETTY_FUNCTION__
#endif

#if !defined(__ANDROID__) && !defined(ANDROID)
#define DAV_LOGI(MOD_NAME, fmt, ...) \
dlog_info(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
#define DAV_LOGW(MOD_NAME, fmt, ...) \
dlog_warn(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
#define DAV_LOGE(MOD_NAME, fmt, ...) \
dlog_error(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
#define DAV_LOGD(MOD_NAME, fmt, ...) \
dlog_debug(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
#define DAV_EVENT(MOD_NAME, fmt, ...) \
dlog_event(static_cast<int>(GE), "%s:" #fmt, __FUNCTION__, ##__VA_ARGS__)
#else
#define DAV_LOGI(MOD_NAME, fmt, ...) \
__android_log_print(ANDROID_LOG_INFO, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define DAV_LOGW(MOD_NAME, fmt, ...) \
__android_log_print(ANDROID_LOG_WARN, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define DAV_LOGE(MOD_NAME, fmt, ...) \
__android_log_print(ANDROID_LOG_ERROR, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define DAV_LOGD(MOD_NAME, fmt, ...) \
__android_log_print(ANDROID_LOG_DEBUG, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#define DAV_EVENT(MOD_NAME, fmt, ...) \
__android_log_print(ANDROID_LOG_DEBUG, MOD_NAME, "%s %s(%d)::" #fmt, __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__)
#endif

#define DLOG_DECLARE(level) \
void Log_##level(const char *mod_name, const char *func, const char *file, int line, const char *format, ...)

namespace ge {
DLOG_DECLARE(INFO);
DLOG_DECLARE(WARNING);
DLOG_DECLARE(ERROR);
} // namespace ge

#endif // INC_FRAMEWORK_DLOG_LOG_H_

+ 55
- 0
inc/framework/engine/dnnengine.h View File

@@ -0,0 +1,55 @@
/**
* 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 INC_FRAMEWORK_ENGINE_DNNENGINE_H_
#define INC_FRAMEWORK_ENGINE_DNNENGINE_H_

#include <map>
#include <string>
#include <vector>

#include "common/ge_inner_error_codes.h"
#include "common/ge_types.h"
#include "graph/types.h"

namespace ge {
enum PriorityEnum {
COST_0 = 0,
COST_1,
COST_2,
COST_9 = 9,
};

struct DNNEngineAttribute {
std::string engine_name;
std::vector<std::string> mem_type;
uint32_t compute_cost;
enum RuntimeType runtime_type; // HOST, DEVICE
// set this attribute if the inputformat of engine must be specific, otherwise set FORMAT_RESERVED
Format engine_input_format;
Format engine_output_format;
};

class DNNEngine {
public:
virtual ~DNNEngine() = default;
virtual Status Initialize(const std::map<std::string, std::string> &options) = 0;
virtual Status Finalize() = 0;
virtual void GetAttributes(DNNEngineAttribute &attr) const = 0;
};
} // namespace ge

#endif // INC_FRAMEWORK_ENGINE_DNNENGINE_H_

+ 166
- 0
inc/framework/executor/ge_executor.h View File

@@ -0,0 +1,166 @@
/**
* 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 INC_FRAMEWORK_EXECUTOR_GE_EXECUTOR_H_
#define INC_FRAMEWORK_EXECUTOR_GE_EXECUTOR_H_

#include <memory>
#include <string>
#include <vector>

#include "common/ge_inner_error_codes.h"
#include "common/ge_types.h"
#include "common/types.h"
#include "graph/tensor.h"
#include "runtime/base.h"

namespace ge {
class ModelListenerAdapter;

class SingleOp;

struct RunModelData {
uint32_t index; // Data index
uint32_t model_id; // Model id
std::vector<DataBuffer> blobs; // All input/output data buffer
uint32_t timestamp; // Data creation time
uint32_t timeout; // Processing timeout
uint64_t request_id = 0; // Request ID
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeExecutor {
public:
GeExecutor();
~GeExecutor() = default;
ge::Status Initialize();

// Load model
ge::Status LoadModelOffline(uint32_t &model_id, const std::string &path, const std::string &key, int32_t priority,
std::shared_ptr<ge::ModelListener> listener);

ge::Status UnloadModel(uint32_t model_id);

ge::Status RunModel(const ge::RunModelData &input_data, ge::RunModelData &output_data);

// Get input and output descriptor
ge::Status GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc,
std::vector<ge::TensorDesc> &output_desc);

ge::Status GetModelDescInfoForZeroCopy(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc,
std::vector<ge::TensorDesc> &output_desc);

ge::Status LoadModel(uint32_t &model_id, const ge::ModelData &model_data,
std::shared_ptr<ge::ModelListener> listener);

ge::Status CommandHandle(const ge::Command &command);

///
/// @ingroup ge
/// @brief Query model memory consuming interface
/// @param [in] model_id Offline model ID
/// @param [out] max_size Memory size
/// @return SUCCESS
/// @return FAILED
///
ge::Status GetMaxUsedMemory(uint32_t model_id, uint32_t &max_size);

///
/// @ingroup ge
/// @brief Load data from model file to memory
/// @param [in] const std::string &path: Offline model file path
/// @param [out] ModelData &model_data: Offline model memory data
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status LoadDataFromFile(const std::string &path, ge::ModelData &model_data);

///
/// @ingroup ge
/// @brief Load model from offline model memory data
/// @param [in] ModelData &model_data: Offline model data
/// @param [in] void *dev_ptr: Input/Output memory address
/// @param [in] size_t mem_size: Input/Output memory length
/// @param [in] void *weight_ptr: Weight memory address
/// @param [in] size_t weight_size: Weight memory length
/// @param [out] uint32_t &model_id: Corresponding identification after model loading
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status LoadModelFromData(uint32_t &model_id, const ge::ModelData &model_data, void *dev_ptr, size_t mem_size,
void *weight_ptr, size_t weight_size);

///
/// @ingroup ge
/// @brief Load task list from ModelData with queue.
/// @param [out] model_id: model id allocate from manager.
/// @param [in] model_data: Model data load from offline model.
/// @param [in] input_queue_ids: input queue ids create from user.
/// @param [in] output_queue_ids: input queue ids create from user.
/// @return: 0 for success / others for fail
///
ge::Status LoadModelWithQ(uint32_t &model_id, const ge::ModelData &model_data,
const std::vector<uint32_t> &input_queue_ids,
const std::vector<uint32_t> &output_queue_ids);

///
/// @ingroup ge
/// @brief Synchronous execution of offline model(Do not create thread)
/// @param [in] uint32_t model_id: Model ID to execute
/// @param [in] void* stream: stream to execute
/// @param [in] bool async_mode: is asynchronize mode.
/// @param [in] const domi::InputData *input_data: Model input data
/// @param [out] domi::OutputData *output_data: Model output data
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status ExecModel(uint32_t model_id, void *stream, const ge::RunModelData &input_data,
ge::RunModelData &output_data, bool async_mode = false);

///
/// @ingroup ge
/// @brief Get weight memory size from model file
/// @param [in] const std::string &path: Offline model file path
/// @param [out] size_t &mem_size Execution memory size
/// @param [out] size_t &weight_size Weight memory space size
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status GetMemAndWeightSize(const std::string &path, size_t &mem_size, size_t &weight_size);

///
/// @ingroup ge
/// @brief Get weight memory size from model file
/// @param [in] const void *model_data Offline model buffer
/// @param [in] size_t model_size Offline model buffer length
/// @param [out] size_t &mem_size Execution memory size
/// @param [out] size_t &weight_size Weight memory space size
/// @return SUCCESS handle successfully / others handle failed
///
ge::Status GetMemAndWeightSize(const void *model_data, size_t model_size, size_t &mem_size, size_t &weight_size);

static ge::Status LoadSingleOp(const std::string &model_name, const ge::ModelData &model_data, void *stream,
SingleOp **single_op);

static ge::Status ExecuteAsync(SingleOp *executor, const std::vector<DataBuffer> &inputs,
std::vector<DataBuffer> &outputs);

static ge::Status ReleaseSingleOpResource(void *stream);

private:
static bool is_init_;
std::vector<std::shared_ptr<ModelListenerAdapter>> listener_adapters_;
};

ge::Status ModelInfoParser(const ge::ModelData &model, ge::ModelInfo &model_info);
} // namespace ge

#endif // INC_FRAMEWORK_EXECUTOR_GE_EXECUTOR_H_

+ 113
- 0
inc/framework/ge_runtime/davinci_model.h View File

@@ -0,0 +1,113 @@
/**
* 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 INC_FRAMEWORK_GE_RUNTIME_DAVINCI_MODEL_H_
#define INC_FRAMEWORK_GE_RUNTIME_DAVINCI_MODEL_H_

#include <memory>
#include <vector>

#include "ge_runtime/op_info.h"
#include "ge_runtime/task_info.h"

namespace ge {
namespace model_runner {
class DavinciModel {
public:
DavinciModel(const std::vector<std::shared_ptr<TaskInfo>> &task_info_list,
const std::vector<std::shared_ptr<OpInfo>> &data_info_list,
const std::vector<std::shared_ptr<OpInfo>> &output_info_list,
const std::vector<std::shared_ptr<OpInfo>> &constant_info_list,
const std::vector<model_runner::OpInfoPtr> &variable_info_list,
const std::vector<uint32_t> &wait_active_stream_list,
const std::vector<uint32_t> &force_copy_stream_list, uint64_t mem_size = 0, uint64_t weight_size = 0,
uint64_t var_size = 0, uintptr_t logic_mem_base = 0, uintptr_t logic_weight_base = 0,
uintptr_t logic_var_base = 0, uint32_t stream_num = 0, uint32_t batch_num = 0, uint32_t event_num = 0,
int32_t priority = 0)
: task_info_list_(task_info_list),
data_info_list_(data_info_list),
output_info_list_(output_info_list),
constant_info_list_(constant_info_list),
variable_info_list_(variable_info_list),
wait_active_stream_list_(wait_active_stream_list),
force_copy_stream_list_(force_copy_stream_list),
mem_size_(mem_size),
weight_size_(weight_size),
var_size_(var_size),
logic_mem_base_(logic_mem_base),
logic_weight_base_(logic_weight_base),
logic_var_base_(logic_var_base),
stream_num_(stream_num),
batch_num_(batch_num),
event_num_(event_num),
priority_(priority) {}
~DavinciModel() {}

uint64_t GetMemSize() const { return mem_size_; }
uint64_t GetWeightSize() const { return weight_size_; }
uint64_t GetVarSize() const { return var_size_; }

uintptr_t GetLogicMemBase() const { return logic_mem_base_; }
uintptr_t GetLogicWeightBase() const { return logic_weight_base_; }
uintptr_t GetLogicVarBase() const { return logic_var_base_; }

uint32_t GetStreamNum() const { return stream_num_; }
uint32_t GetBatchNum() const { return batch_num_; }
uint32_t GetEventNum() const { return event_num_; }

const std::vector<uint32_t> &GetWaitActiveStreams() const { return wait_active_stream_list_; }
const std::vector<uint32_t> &GetForceCopyStreams() const { return force_copy_stream_list_; }

int32_t GetPriority() const { return priority_; }

const std::vector<std::shared_ptr<TaskInfo>> &GetTaskInfoList() const { return task_info_list_; }
const std::vector<std::shared_ptr<OpInfo>> &GetDataInfoList() const { return data_info_list_; }
const std::vector<std::shared_ptr<OpInfo>> &GetOutputInfoList() const { return output_info_list_; }
const std::vector<std::shared_ptr<OpInfo>> &GetConstantInfoList() const { return output_info_list_; }
const std::vector<model_runner::OpInfoPtr> &GetVariableInfoList() const { return variable_info_list_; }

private:
std::vector<std::shared_ptr<TaskInfo>> task_info_list_;
std::vector<std::shared_ptr<OpInfo>> data_info_list_;
std::vector<std::shared_ptr<OpInfo>> output_info_list_;
std::vector<std::shared_ptr<OpInfo>> constant_info_list_;
std::vector<model_runner::OpInfoPtr> variable_info_list_;

std::vector<uint32_t> wait_active_stream_list_;
std::vector<uint32_t> force_copy_stream_list_;

uint64_t mem_size_;
uint64_t weight_size_;
uint64_t var_size_;

uintptr_t logic_mem_base_;
uintptr_t logic_weight_base_;
uintptr_t logic_var_base_;

uint32_t stream_num_;
uint32_t batch_num_;
uint32_t event_num_;

int32_t priority_;

// Disable to copy constructor and assignment operator
DavinciModel &operator=(const DavinciModel &) = delete;
DavinciModel(const DavinciModel &) = delete;
};
} // namespace model_runner
} // namespace ge

#endif // INC_FRAMEWORK_GE_RUNTIME_DAVINCI_MODEL_H_

+ 58
- 0
inc/framework/ge_runtime/model_runner.h View File

@@ -0,0 +1,58 @@
/**
* 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 INC_FRAMEWORK_GE_RUNTIME_MODEL_RUNNER_H_
#define INC_FRAMEWORK_GE_RUNTIME_MODEL_RUNNER_H_

#include <memory>
#include <unordered_map>
#include <vector>

#include "common/ge_inner_error_codes.h"
#include "common/ge_types.h"
#include "ge_runtime/davinci_model.h"

namespace ge {
namespace model_runner {
class RuntimeModel;

class ModelRunner {
public:
static ModelRunner &Instance();

bool LoadDavinciModel(uint32_t device_id, uint64_t session_id, uint32_t model_id,
std::shared_ptr<DavinciModel> davinci_model, std::shared_ptr<ModelListener> listener);

const std::vector<uint32_t> &GetTaskIdList(uint32_t model_id) const;

bool UnloadModel(uint32_t model_id);

bool RunModel(uint32_t model_id, const InputData &input_data, OutputData *output_data);

bool GetInputOutputDescInfo(uint32_t model_id, bool zero_copy, std::vector<InputOutputDescInfo> *input_desc,
std::vector<InputOutputDescInfo> *output_desc, std::vector<uint32_t> *input_format,
std::vector<uint32_t> *output_format);

private:
ModelRunner() = default;
~ModelRunner() = default;

std::unordered_map<uint32_t, std::shared_ptr<RuntimeModel>> runtime_models_;
};
} // namespace model_runner
} // namespace ge

#endif // INC_FRAMEWORK_GE_RUNTIME_MODEL_RUNNER_H_

+ 72
- 0
inc/framework/ge_runtime/op_info.h View File

@@ -0,0 +1,72 @@
/**
* 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 INC_FRAMEWORK_GE_RUNTIME_OP_INFO_H_
#define INC_FRAMEWORK_GE_RUNTIME_OP_INFO_H_

#include <memory>
#include <string>
#include <vector>

namespace ge {
namespace model_runner {
struct TensorInfo {
int64_t GetShapeSize() const {
int64_t res = 1;
if (dims.empty()) {
return 0;
}
for (auto dim : dims) {
res *= dim;
}
return res;
}

int64_t GetDim(uint32_t index) {
if (index >= dims.size()) {
return 0;
}
return dims[index];
}

std::vector<int64_t> dims;
uint32_t datatype;
uint32_t format;
uint32_t real_dim_cnt;
uint32_t size;
bool is_output;
};

struct OpInfo {
uint32_t index;
std::string name;
std::string type;
bool var_is_broadcast;
std::vector<uintptr_t> input_addrs;
std::vector<uintptr_t> output_addrs;
std::vector<TensorInfo> input_tensors;
std::vector<TensorInfo> output_tensors;
std::vector<TensorInfo> weight_tensors;
std::vector<std::string> src_name;
std::vector<int64_t> src_index;
std::string weight_data;
};

using TensorInfoPtr = std::shared_ptr<TensorInfo>;
using OpInfoPtr = std::shared_ptr<OpInfo>;
} // namespace model_runner
} // namespace ge
#endif // INC_FRAMEWORK_GE_RUNTIME_OP_INFO_H_

+ 394
- 0
inc/framework/ge_runtime/task_info.h View File

@@ -0,0 +1,394 @@
/**
* 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 INC_FRAMEWORK_GE_RUNTIME_TASK_INFO_H_
#define INC_FRAMEWORK_GE_RUNTIME_TASK_INFO_H_

#include <stdint.h>
#include <functional>
#include <memory>
#include <string>
#include <vector>

#include "cce/taskdown_api.h"

namespace ge {
namespace model_runner {
enum TaskInfoType {
kCce = 0,
kTbe,
kAiCpu,
kLabelSet,
kLabelSwitch,
kLabelGoto,
kEventRecord,
kEventWait,
kFusionStart,
kFusionEnd,
kHccl,
kProfilerTrace,
kMemcpyAsync,
kStreamSwitch,
kStreamActive,
// Insert new task type here
kReserved = 23
};

class TaskInfo {
public:
virtual ~TaskInfo() {}
uint32_t stream_id() const { return stream_id_; }
TaskInfoType type() const { return type_; }

protected:
TaskInfo(uint32_t stream_id, TaskInfoType type) : stream_id_(stream_id), type_(type) {}

private:
uint32_t stream_id_;
TaskInfoType type_;
};

class CceTaskInfo : public TaskInfo {
public:
CceTaskInfo(uint32_t stream_id, const cce::ccOpContext &ctx, const std::string &stub_func, uint32_t block_dim,
const std::vector<uint8_t> &args, uint32_t args_size, const std::vector<uint8_t> &sm_desc,
const std::vector<uint8_t> &flow_table, const std::vector<uint8_t> &args_offset, bool is_flowtable)
: TaskInfo(stream_id, TaskInfoType::kCce),
ctx_(ctx),
stub_func_(stub_func),
block_dim_(block_dim),
args_(args),
args_size_(args_size),
sm_desc_(sm_desc),
flow_table_(flow_table),
args_offset_(args_offset),
is_flowtable_(is_flowtable) {}
~CceTaskInfo() override {}

cce::ccOpContext cc_context() const { return ctx_; }
std::string stub_func() const { return stub_func_; }
uint32_t block_dim() const { return block_dim_; }
const std::vector<uint8_t> &args() const { return args_; }
uint32_t args_size() const { return args_size_; }
const std::vector<uint8_t> &sm_desc() const { return sm_desc_; }
const std::vector<uint8_t> &flow_table() const { return flow_table_; }
const std::vector<uint8_t> &args_offset() const { return args_offset_; }
bool is_flowtable() const { return is_flowtable_; }

private:
cce::ccOpContext ctx_;
std::string stub_func_;
uint32_t block_dim_;
std::vector<uint8_t> args_;
uint32_t args_size_;
std::vector<uint8_t> sm_desc_;
std::vector<uint8_t> flow_table_;
std::vector<uint8_t> args_offset_;
bool is_flowtable_;
};

class TbeTaskInfo : public TaskInfo {
public:
TbeTaskInfo(uint32_t stream_id, const std::string &stub_func, uint32_t block_dim, const std::vector<uint8_t> &args,
uint32_t args_size, const std::vector<uint8_t> &sm_desc, void *binary, uint32_t binary_size,
const std::vector<uint8_t> &meta_data, const std::vector<void *> &input_data_addrs,
const std::vector<void *> &output_data_addrs, const std::vector<void *> &workspace_addrs)
: TaskInfo(stream_id, TaskInfoType::kTbe),
stub_func_(stub_func),
block_dim_(block_dim),
args_(args),
args_size_(args_size),
sm_desc_(sm_desc),
binary_(binary),
binary_size_(binary_size),
meta_data_(meta_data),
input_data_addrs_(input_data_addrs),
output_data_addrs_(output_data_addrs),
workspace_addrs_(workspace_addrs) {}
~TbeTaskInfo() override {}

const std::string &stub_func() const { return stub_func_; }
uint32_t block_dim() const { return block_dim_; }
const std::vector<uint8_t> &args() const { return args_; }
uint32_t args_size() const { return args_size_; }
const std::vector<uint8_t> &sm_desc() const { return sm_desc_; }
void *binary() const { return binary_; }
uint32_t binary_size() const { return binary_size_; }
const std::vector<uint8_t> &meta_data() const { return meta_data_; }
const std::vector<void *> &input_data_addrs() const { return input_data_addrs_; }
const std::vector<void *> &output_data_addrs() const { return output_data_addrs_; }
const std::vector<void *> &workspace_addrs() const { return workspace_addrs_; }

void SetBinary(void *binary, uint32_t binary_size) {
binary_ = binary;
binary_size_ = binary_size;
}

private:
std::string stub_func_;
uint32_t block_dim_;
std::vector<uint8_t> args_;
uint32_t args_size_;
std::vector<uint8_t> sm_desc_;
void *binary_;
uint32_t binary_size_;
std::vector<uint8_t> meta_data_;
std::vector<void *> input_data_addrs_;
std::vector<void *> output_data_addrs_;
std::vector<void *> workspace_addrs_;
};

class AicpuTaskInfo : public TaskInfo {
public:
AicpuTaskInfo(uint32_t stream_id, const string &so_name, const std::string &kernel_name, const std::string &node_def,
const std::vector<void *> &input_data_addrs, const std::vector<void *> &output_data_addrs)
: TaskInfo(stream_id, TaskInfoType::kAiCpu),
so_name_(so_name),
kernel_name_(kernel_name),
node_def_(node_def),
input_data_addrs_(input_data_addrs),
output_data_addrs_(output_data_addrs) {}
~AicpuTaskInfo() override {}

const std::string &so_name() const { return so_name_; }
const std::string &kernel_name() const { return kernel_name_; }
const std::string &node_def() const { return node_def_; }
const std::vector<void *> &input_data_addrs() const { return input_data_addrs_; }
const std::vector<void *> &output_data_addrs() const { return output_data_addrs_; }

private:
std::string so_name_;
std::string kernel_name_;
std::string node_def_;
std::vector<void *> input_data_addrs_;
std::vector<void *> output_data_addrs_;
};

class LabelTaskInfo : public TaskInfo {
public:
uint32_t label_id() const { return label_id_; }

protected:
LabelTaskInfo(uint32_t stream_id, TaskInfoType type, uint32_t label_id)
: TaskInfo(stream_id, type), label_id_(label_id) {}
virtual ~LabelTaskInfo() override {}

uint32_t label_id_;
};

class LabelSetTaskInfo : public LabelTaskInfo {
public:
LabelSetTaskInfo(uint32_t stream_id, uint32_t label_id)
: LabelTaskInfo(stream_id, TaskInfoType::kLabelSet, label_id) {}
~LabelSetTaskInfo() override {}
};

class LabelSwitchTaskInfo : public LabelTaskInfo {
public:
LabelSwitchTaskInfo(uint32_t stream_id, uint32_t label_id)
: LabelTaskInfo(stream_id, TaskInfoType::kLabelSwitch, label_id) {}
~LabelSwitchTaskInfo() override {}
};

class LabelGotoTaskInfo : public LabelTaskInfo {
public:
LabelGotoTaskInfo(uint32_t stream_id, uint32_t label_id)
: LabelTaskInfo(stream_id, TaskInfoType::kLabelGoto, label_id) {}
~LabelGotoTaskInfo() override {}
};

class EventTaskInfo : public TaskInfo {
public:
uint32_t event_id() const { return event_id_; }

protected:
EventTaskInfo(uint32_t stream_id, TaskInfoType type, uint32_t event_id)
: TaskInfo(stream_id, type), event_id_(event_id) {}
virtual ~EventTaskInfo() override {}

uint32_t event_id_;
};

class EventRecordTaskInfo : public EventTaskInfo {
public:
EventRecordTaskInfo(uint32_t stream_id, uint32_t event_id)
: EventTaskInfo(stream_id, TaskInfoType::kEventRecord, event_id) {}
~EventRecordTaskInfo() override {}
};

class EventWaitTaskInfo : public EventTaskInfo {
public:
EventWaitTaskInfo(uint32_t stream_id, uint32_t event_id)
: EventTaskInfo(stream_id, TaskInfoType::kEventWait, event_id) {}
~EventWaitTaskInfo() override {}
};

class FusionStartTaskInfo : public TaskInfo {
public:
explicit FusionStartTaskInfo(uint32_t stream_id) : TaskInfo(stream_id, TaskInfoType::kFusionStart) {}
~FusionStartTaskInfo() override {}
};

class FusionEndTaskInfo : public TaskInfo {
public:
explicit FusionEndTaskInfo(uint32_t stream_id) : TaskInfo(stream_id, TaskInfoType::kFusionEnd) {}
~FusionEndTaskInfo() override {}
};

class HcclTaskInfo : public TaskInfo {
public:
HcclTaskInfo(uint32_t stream_id, const std::string hccl_type, void *input_data_addr, void *output_data_addr,
void *workspace_addr, int64_t workspace_size, int64_t hccl_stream_num,
const std::vector<uint8_t> &private_def, void *ops_kernel_store, int32_t count, int64_t root_id,
int64_t op_type, int64_t data_type, std::function<bool(void *, void *)> hcom_bind_model,
std::function<bool(void *)> hcom_unbind_model,
std::function<bool(std::shared_ptr<HcclTaskInfo>, void *)> hcom_distribute_task)
: TaskInfo(stream_id, TaskInfoType::kHccl),
hccl_type_(hccl_type),
input_data_addr_(input_data_addr),
output_data_addr_(output_data_addr),
workspace_addr_(workspace_addr),
workspace_size_(workspace_size),
hccl_stream_num_(hccl_stream_num),
private_def_(private_def),
ops_kernel_store_(ops_kernel_store),
count_(count),
root_id_(root_id),
op_type_(op_type),
data_type_(data_type),
hcom_bind_model_(hcom_bind_model),
hcom_unbind_model_(hcom_unbind_model),
hcom_distribute_task_(hcom_distribute_task) {}
~HcclTaskInfo() override {}

const std::string &hccl_type() const { return hccl_type_; }
void *input_data_addr() const { return input_data_addr_; }
void *output_data_addr() const { return output_data_addr_; }
void *workspace_addr() const { return workspace_addr_; }
int64_t workspace_size() const { return workspace_size_; }
int64_t hccl_stream_num() const { return hccl_stream_num_; }
const std::vector<uint8_t> &private_def() const { return private_def_; }
void *ops_kernel_store() const { return ops_kernel_store_; }
int32_t count() const { return count_; }
int64_t root_id() const { return root_id_; }
int64_t op_type() const { return op_type_; }
int64_t data_type() const { return data_type_; }
std::function<bool(void *, void *)> hcom_bind_model() const { return hcom_bind_model_; }
std::function<bool(void *)> hcom_unbind_model() const { return hcom_unbind_model_; }
std::function<bool(std::shared_ptr<HcclTaskInfo>, void *)> hcom_distribute_task() const {
return hcom_distribute_task_;
}

private:
std::string hccl_type_;
void *input_data_addr_;
void *output_data_addr_;
void *workspace_addr_;
int64_t workspace_size_;
int64_t hccl_stream_num_;
std::vector<uint8_t> private_def_;
void *ops_kernel_store_;
int32_t count_;
int64_t root_id_;
int64_t op_type_;
int64_t data_type_;
std::function<bool(void *, void *)> hcom_bind_model_;
std::function<bool(void *)> hcom_unbind_model_;
std::function<bool(std::shared_ptr<HcclTaskInfo>, void *)> hcom_distribute_task_;
};

class ProfilerTraceTaskInfo : public TaskInfo {
public:
ProfilerTraceTaskInfo(uint32_t stream_id, uint64_t log_id, bool notify, uint32_t flat)
: TaskInfo(stream_id, TaskInfoType::kProfilerTrace), log_id_(log_id), notify_(notify), flat_(flat) {}
~ProfilerTraceTaskInfo() override {}

uint64_t log_id() const { return log_id_; }
bool notify() const { return notify_; }
uint32_t flat() const { return flat_; }

private:
uint64_t log_id_;
bool notify_;
uint32_t flat_;
};

class MemcpyAsyncTaskInfo : public TaskInfo {
public:
MemcpyAsyncTaskInfo(uint32_t stream_id, void *dst, uint64_t dst_max, void *src, uint64_t count, uint32_t kind)
: TaskInfo(stream_id, TaskInfoType::kMemcpyAsync),
dst_(dst),
dst_max_(dst_max),
src_(src),
count_(count),
kind_(kind) {}
~MemcpyAsyncTaskInfo() override {}

void *dst() const { return dst_; }
uint64_t dst_max() const { return dst_max_; }
void *src() const { return src_; }
uint64_t count() const { return count_; }
uint32_t kind() const { return kind_; }

private:
void *dst_;
uint64_t dst_max_;
void *src_;
uint64_t count_;
int32_t kind_;
};

class StreamSwitchTaskInfo : public TaskInfo {
public:
StreamSwitchTaskInfo(uint32_t stream_id, int64_t true_stream_id, void *input_addr, void *value_addr, int64_t cond,
int64_t data_type)
: TaskInfo(stream_id, TaskInfoType::kStreamSwitch),
true_stream_id_(true_stream_id),
input_addr_(input_addr),
value_addr_(value_addr),
cond_(cond),
data_type_(data_type) {}
~StreamSwitchTaskInfo() override {}

int64_t true_stream_id() const { return true_stream_id_; }
void *input_addr() const { return input_addr_; }
void *value_addr() const { return value_addr_; }
int64_t cond() const { return cond_; }
int64_t data_type() const { return data_type_; }

private:
int64_t true_stream_id_;
void *input_addr_;
void *value_addr_;
int64_t cond_;
int64_t data_type_;
};

class StreamActiveTaskInfo : public TaskInfo {
public:
StreamActiveTaskInfo(uint32_t stream_id, uint32_t active_stream_id)
: TaskInfo(stream_id, TaskInfoType::kStreamActive), active_stream_id_(active_stream_id) {}
~StreamActiveTaskInfo() override {}

uint32_t active_stream_id() const { return active_stream_id_; }

private:
uint32_t active_stream_id_;
};
} // namespace model_runner
} // namespace ge

#endif // INC_FRAMEWORK_GE_RUNTIME_TASK_INFO_H_

+ 67
- 0
inc/framework/generator/ge_generator.h View File

@@ -0,0 +1,67 @@
/**
* 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 INC_FRAMEWORK_GENERATOR_GE_GENERATOR_H_
#define INC_FRAMEWORK_GENERATOR_GE_GENERATOR_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "common/ge_inner_error_codes.h"
#include "graph/ge_tensor.h"
#include "graph/graph.h"
#include "graph/op_desc.h"

namespace ge {
class GeGenerator {
public:
GeGenerator() = default;

~GeGenerator() = default;

GeGenerator(const GeGenerator &) = delete;

GeGenerator &operator=(const GeGenerator &) = delete;

Status Initialize(const std::map<std::string, std::string> &options);

Status Finalize();

Status GenerateOfflineModel(const Graph &graph, const std::string &file_name_prefix,
const std::vector<GeTensor> &inputs = std::vector<GeTensor>());

///
/// @ingroup ge
/// @brief: Build single OP in Model.
/// @param [in] op_desc: the OP description.
/// @param [in] inputs: input tensors.
/// @param [in] outputs: output tensors.
/// @param [in] model_file_name: name of model file.
/// @return SUCCESS or FAILED
///
Status BuildSingleOpModel(OpDescPtr &op_desc, const std::vector<GeTensor> &inputs,
const std::vector<GeTensor> &outputs, const std::string &model_file_name);

private:
class Impl;

std::shared_ptr<Impl> impl_;
};
} // namespace ge

#endif // INC_FRAMEWORK_GENERATOR_GE_GENERATOR_H_

+ 172
- 0
inc/framework/generator/generator_api.h View File

@@ -0,0 +1,172 @@
/**
* 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 INC_FRAMEWORK_GENERATOR_GENERATOR_API_H_
#define INC_FRAMEWORK_GENERATOR_GENERATOR_API_H_

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef uint32_t Status_t;

typedef void *OpAttr_t;
typedef void *OpTensor_t;

///
/// @ingroup ge
/// @brief Generate offline model for the op.
/// @param [in] op_type: type name of the op.
/// @param [in] in_tensor: input description array (created by OpTensorCreate).
/// @param [in] in_num: number of in_tensor.
/// @param [in] out_tensor: output description array (created by OpTensorCreate).
/// @param [in] out_num: number of out_tensor.
/// @param [in] attr: the attributes of the op (created by OpAttrCreate).
/// @param [in] om_file: file name for the om to save.
/// @return 0 for success / others for fail
///
extern Status_t OpTaskGernerator(const char *op_type, const OpTensor_t *in_tensor, int in_num,
const OpTensor_t *out_tensor, int out_num, const OpAttr_t attr, const char *om_file);

///
/// @ingroup ge
/// @brief Create Tensor Description.
/// @param [in] format: tensor format of the data.
/// @param [in] datatype: tensor type of the data.
/// @param [in] shape: tensor shape array.
/// @param [in] num: number of shape.
/// @return OpTensor_t for success / nullptr for failure
///
extern OpTensor_t OpTensorCreate(int format, int datatype, const int64_t *shape, int num);

///
/// @ingroup ge
/// @brief Destroy Tensor Description.
/// @param [in] OpTensor_t tensor: created by OpTensorCreate.
/// @param [out] none
/// @return 0 for success / others for failure.
///
extern Status_t OpTensorDestroy(OpTensor_t tensor);

///
/// @ingroup ge
/// @brief Create an attribute holder.
/// @param [in] none
/// @param [out] none
/// @return OpAttr_t for success / nullptr for failure.
///
extern OpAttr_t OpAttrCreate();

///
/// @ingroup ge
/// @brief Destroy Attribute holder.
/// @param [in] OpAttr_t attr: created by OpAttrCreate.
/// @param [out] none
/// @return 0 for success / others for failure.
///
extern Status_t OpAttrDestroy(OpAttr_t attr);

///
/// @ingroup ge
/// @brief Set a boolean attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attributed value.
/// @return 0 for success / others for failure.
///
extern Status_t SetAttrBool(OpAttr_t attr, const char *name, bool value);

///
/// @ingroup ge
/// @brief Set an integer attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value.
/// @return 0 for success / others for failure.
///
extern Status_t SetAttrInt(OpAttr_t attr, const char *name, int64_t value);

///
/// @ingroup ge
/// @brief Set a float attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value.
/// @return 0 for success / others for failure.
///
extern Status_t SetAttrFloat(OpAttr_t attr, const char *name, float value);

///
/// @ingroup ge
/// @brief Set a string attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value (can`t be nullptr, end with '\0').
/// @return 0 for success / others for failure.
///
extern Status_t SetAttrString(OpAttr_t attr, const char *name, const char *value);

///
/// @ingroup ge
/// @brief Set a boolean array attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value array.
/// @param [in] num: number of value array.
/// @return 0 for success / others for failure.
///
extern Status_t SetAttrBoolList(OpAttr_t attr, const char *name, const bool *value, int num);

///
/// @ingroup ge
/// @brief Set an integer array attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value array.
/// @param [in] num: number of value array.
/// @return 0 for success / others for failure.
///
extern Status_t SetAttrIntList(OpAttr_t attr, const char *name, const int64_t *value, int num);

///
/// @ingroup ge
/// @brief Set a float array attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value array.
/// @param [in] num: number of value array.
/// @return 0 for success / others for failure.
///
extern Status_t SetAttrFloatList(OpAttr_t attr, const char *name, const float *value, int num);

///
/// @ingroup ge
/// @brief Set a string array attribute to the attribute holder.
/// @param [in] attr: attribute holder (created by OpAttrCreate).
/// @param [in] name: attribute name (can`t be nullptr, end with '\0').
/// @param [in] value: attribute value array (each value can`t be nullptr, end with '\0').
/// @param [in] num: number of value array.
/// @return 0 for success / others for failure.
///
extern Status_t SetAttrStringList(OpAttr_t attr, const char *name, const char **value, int num);

#ifdef __cplusplus
}
#endif

#endif // INC_FRAMEWORK_GENERATOR_GENERATOR_API_H_

+ 42
- 0
inc/framework/memory/memory_assigner.h View File

@@ -0,0 +1,42 @@
/**
* 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 INC_FRAMEWORK_MEMORY_MEMORY_ASSIGNER_H_
#define INC_FRAMEWORK_MEMORY_MEMORY_ASSIGNER_H_

#include <utility>

#include "common/ge_inner_error_codes.h"
#include "graph/node.h"

namespace ge {
const int64_t kMemAlignSize = 512;
class MemoryAssigner {
public:
explicit MemoryAssigner(ge::ComputeGraphPtr compute_graph) : compute_graph_(std::move(compute_graph)) {}
virtual ~MemoryAssigner() = default;

MemoryAssigner(const MemoryAssigner &) = delete;

MemoryAssigner &operator=(const MemoryAssigner &) = delete;

Status AssignMemory(bool is_loop_graph, size_t &mem_offset);

private:
ge::ComputeGraphPtr compute_graph_;
};
} // namespace ge
#endif // INC_FRAMEWORK_MEMORY_MEMORY_ASSIGNER_H_

+ 130
- 0
inc/framework/omg/omg_inner_types.h View File

@@ -0,0 +1,130 @@
/**
* 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 INC_FRAMEWORK_OMG_OMG_INNER_TYPES_H_
#define INC_FRAMEWORK_OMG_OMG_INNER_TYPES_H_

#include <functional>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include "framework/common/fmk_error_codes.h"
#include "framework/common/types.h"
#include "register/register_fmk_types.h"

using domi::DOMI_TENSOR_ND;
using domi::DOMI_TENSOR_RESERVED;
using domi::domiTensorFormat_t;
using domi::FMK_TYPE_RESERVED;
using domi::FrameworkType;
using std::map;
using std::string;
using std::unordered_map;
using std::vector;

namespace ge {
///
/// @ingroup domi_omg
/// @brief run model
///
enum RunMode {
kGeOmModel = 0, // generate offline model file
kModelToJson = 1, // convert to JSON file
kOnlyPreCheck = 3, // only for pre-check
kPbtxtToJson = 5 // pbtxt to json
};

///
/// @ingroup domi_omg
/// @brief high-precision mode
///
enum HighPrecisionMode {
// the FP16 high-precision function is disabled in common mode
kHighPrecisonDefault = 0,

// high-precision mode, in which FP16 high-precision mode (Convolution/FullConnect/AvgPooling are involved) is enable
kHighPrecisionFP16 = 1
};

///
/// @ingroup domi_omg
/// @brief description buffer data
///
struct OMGBufferData {
void *data;
uint32_t length;
};

struct OmgContext {
OmgContext() { format = DOMI_TENSOR_ND; }
domiTensorFormat_t format;

// format of the input specified by the command line
std::unordered_map<std::string, domiTensorFormat_t> input_nodes_format_map;
std::vector<domiTensorFormat_t> output_formats;

// user-designate input dims
std::vector<std::pair<std::string, std::vector<int64_t>>> user_input_dims;
// global input dims
std::unordered_map<std::string, std::vector<int64_t>> input_dims;

// resolve the mapping between operators with the same name and corresponding network. format e.g.
// Detectionoutput:SsdDetectiontOutput
std::map<std::string, std::string> op_conf_map;
// save the output node of the network. key = operator name, value = index, index indicates the output index of the
// operator
std::map<std::string, std::vector<int32_t>> out_nodes_map;
// user-designate out nodes (this is used for determing the orders)
std::vector<std::pair<std::string, int32_t>> user_out_nodes;
// path for the aicpu custom operator so_file
std::vector<std::string> aicpu_op_run_paths;
// ddk version
std::string ddk_version;
// preferential format used by the entire network
domiTensorFormat_t net_format = DOMI_TENSOR_RESERVED;
domi::FrameworkType type = domi::FMK_TYPE_RESERVED;
RunMode run_mode = kOnlyPreCheck;
bool train_flag = false;
// whether to use FP16 high precision
int32_t fp16_high_precision = kHighPrecisonDefault;

std::string output_type;

// Save the name of the entire network: Some special operators are used to determine a network. Some operators in the
// network require special processing based on the specific network.
// e.g:faster-rcnn, the FirstStageProcessor module is determined as the Faster-R-CNN network based on the scope
// fusion. Then, the conv+reshape operators in the FirstStageBoxPredictor/BoxEncodingPredictor scope are combined. The
// convolution kernel rearrangement reshape operator needs to be deleted for the convolution kernel.
std::string net_name;
// whether to enable dynamic batch
bool enable_l2dynamic = false;
};
} // namespace ge

namespace domi {
///
/// @ingroup domi_omg
/// @brief get OMG context
/// @return OmgContext context
///
ge::OmgContext &GetContext();
} // namespace domi

#endif // INC_FRAMEWORK_OMG_OMG_INNER_TYPES_H_

+ 22
- 0
inc/framework/omg/omg_types.h View File

@@ -0,0 +1,22 @@
/**
* 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 INC_FRAMEWORK_OMG_OMG_TYPES_H_
#define INC_FRAMEWORK_OMG_OMG_TYPES_H_

#include "register/register_fmk_types.h"

#endif // INC_FRAMEWORK_OMG_OMG_TYPES_H_

+ 53
- 0
inc/framework/omg/version.h View File

@@ -0,0 +1,53 @@
/**
* 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 INC_FRAMEWORK_OMG_VERSION_H_
#define INC_FRAMEWORK_OMG_VERSION_H_

#include <memory>
#include <set>
#include <string>
#include <vector>

#include "common/debug/log.h"
#include "common/string_util.h"
#include "framework/common/debug/ge_log.h"

namespace ge {
class PlatformVersionManager {
public:
PlatformVersionManager() = delete;
~PlatformVersionManager() = delete;
static Status GetPlatformVersion(std::string &ver) {
#if defined PLATFORM_PHOENIX
ver = "3.51.z";
#elif defined PLATFORM_ORLANDO
ver = "3.31.z";
#elif defined PLATFORM_MINI
ver = "1.11.z";
#elif defined PLATFORM_CLOUD
ver = "1.61.z";
#endif
std::vector<std::string> version_splits = StringUtils::Split(ver, '.');
GE_IF_BOOL_EXEC(version_splits.size() < 3, GELOGW("Read platform version error!"); return FAILED;);

GELOGI("Read current platform version: %s.", ver.c_str());
return SUCCESS;
}
}; // class PlatformManager
} // namespace ge

#endif // INC_FRAMEWORK_OMG_VERSION_H_

+ 278
- 0
inc/graph/anchor.h View File

@@ -0,0 +1,278 @@
/**
* 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 INC_GRAPH_ANCHOR_H_
#define INC_GRAPH_ANCHOR_H_

#include <memory>
#include <string>
#include <vector>

#include "graph/ge_error_codes.h"
#include "graph/range_vistor.h"
#include "graph/types.h"

namespace ge {
enum AnchorStatus { ANCHOR_SUSPEND = 0, ANCHOR_CONST = 1, ANCHOR_DATA = 2, ANCHOR_RESERVED = 3 };
using std::string;
using std::vector;

class Node;

using NodePtr = std::shared_ptr<Node>;

class Edge;

using EdgePtr = std::shared_ptr<Edge>;

class Anchor;

using AnchorPtr = std::shared_ptr<Anchor>;

class DataAnchor;

using DataAnchorPtr = std::shared_ptr<DataAnchor>;

class InDataAnchor;

using InDataAnchorPtr = std::shared_ptr<InDataAnchor>;

class OutDataAnchor;

using OutDataAnchorPtr = std::shared_ptr<OutDataAnchor>;

class ControlAnchor;

using ControlAnchorPtr = std::shared_ptr<ControlAnchor>;

class InControlAnchor;

using InControlAnchorPtr = std::shared_ptr<InControlAnchor>;

class OutControlAnchor;

using OutControlAnchorPtr = std::shared_ptr<OutControlAnchor>;

using ConstAnchor = const Anchor;

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Anchor : public std::enable_shared_from_this<Anchor> {
friend class AnchorUtils;

public:
using TYPE = const char *;
template <class T>
using Vistor = RangeVistor<T, std::shared_ptr<ConstAnchor>>;

Anchor(const NodePtr &ownerNode, int idx);

virtual ~Anchor() = default;

protected:
// Whether the two anchors are equal
virtual bool Equal(AnchorPtr anchor) const = 0;
virtual bool IsTypeOf(TYPE type) const;

public:
// Get all peer anchors connected to current anchor
Vistor<AnchorPtr> GetPeerAnchors() const;
// Get the first peer anchor
AnchorPtr GetFirstPeerAnchor() const;

// Get the node which is the owner of the anchor
NodePtr GetOwnerNode() const;

// Remove all links with the anchor
void UnlinkAll() noexcept;

// Remove link with the given anchor
graphStatus Unlink(const AnchorPtr &peer);

// Replace the peeranchor with the new peeranchor
graphStatus ReplacePeer(const AnchorPtr &oldPeer, const AnchorPtr &firstPeer, const AnchorPtr &secondPeer);

// Judge if the anchor is linked with the given anchor
bool IsLinkedWith(const AnchorPtr &peer);

// Get the anchor index of the node
int GetIdx() const;

// Set the anchor index of the node
void SetIdx(int index);

protected:
// All peer anchors connected to current anchor
vector<std::weak_ptr<Anchor>> peer_anchors_;
// The owner nodes of the anchor
std::weak_ptr<Node> owner_node_;
// The index of current anchor
int idx_;
template <class T>
static Anchor::TYPE TypeOf() {
static_assert(std::is_base_of<Anchor, T>::value, "T must be a Anchor!");
return __PRETTY_FUNCTION__;
}

public:
template <class T>
static std::shared_ptr<T> DynamicAnchorCast(AnchorPtr anchorPtr) {
static_assert(std::is_base_of<Anchor, T>::value, "T must be a Anchor!");
if (anchorPtr == nullptr || !anchorPtr->IsTypeOf<T>()) {
return nullptr;
}
return std::static_pointer_cast<T>(anchorPtr);
}

template <typename T>
bool IsTypeOf() {
return IsTypeOf(TypeOf<T>());
}
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY DataAnchor : public Anchor {
friend class AnchorUtils;

public:
explicit DataAnchor(const NodePtr &ownerNode, int idx);

virtual ~DataAnchor() = default;

protected:
bool IsTypeOf(TYPE type) const override;

private:
Format format_{FORMAT_ND};
AnchorStatus status_{ANCHOR_SUSPEND};
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InDataAnchor : public DataAnchor {
friend class OutDataAnchor;

friend class OutControlAnchor;

public:
explicit InDataAnchor(const NodePtr &ownerNode, int idx);

virtual ~InDataAnchor() = default;

// Get source out data anchor
OutDataAnchorPtr GetPeerOutAnchor() const;

// Build connection from OutDataAnchor to InDataAnchor
graphStatus LinkFrom(const OutDataAnchorPtr &src);

protected:
bool Equal(AnchorPtr anchor) const override;
bool IsTypeOf(TYPE type) const override;
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OutDataAnchor : public DataAnchor {
friend class InDataAnchor;

friend class AnchorUtils;

public:
template <class T>
using Vistor = RangeVistor<T, std::shared_ptr<ConstAnchor>>;

explicit OutDataAnchor(const NodePtr &ownerNode, int idx);

virtual ~OutDataAnchor() = default;
// Get dst in data anchor(one or more)
Vistor<InDataAnchorPtr> GetPeerInDataAnchors() const;
uint32_t GetPeerInDataNodesSize() const;

// Get dst in control anchor(one or more)
Vistor<InControlAnchorPtr> GetPeerInControlAnchors() const;

// Build connection from OutDataAnchor to InDataAnchor
graphStatus LinkTo(const InDataAnchorPtr &dest);

// Build connection from OutDataAnchor to InControlAnchor
graphStatus LinkTo(const InControlAnchorPtr &dest);

protected:
bool Equal(AnchorPtr anchor) const override;
bool IsTypeOf(TYPE type) const override;
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY ControlAnchor : public Anchor {
public:
explicit ControlAnchor(const NodePtr &ownerNode);

explicit ControlAnchor(const NodePtr &ownerNode, int idx);

virtual ~ControlAnchor() = default;

protected:
bool IsTypeOf(TYPE type) const override;
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InControlAnchor : public ControlAnchor {
friend class OutControlAnchor;

friend class OutDataAnchor;

public:
explicit InControlAnchor(const NodePtr &ownerNode);

explicit InControlAnchor(const NodePtr &ownerNode, int idx);

virtual ~InControlAnchor() = default;

// Get source out control anchors
Vistor<OutControlAnchorPtr> GetPeerOutControlAnchors() const;
bool IsPeerOutAnchorsEmpty() const { return peer_anchors_.empty(); }

// Get source out data anchors
Vistor<OutDataAnchorPtr> GetPeerOutDataAnchors() const;

// Build connection from OutControlAnchor to InControlAnchor
graphStatus LinkFrom(const OutControlAnchorPtr &src);

protected:
bool Equal(AnchorPtr anchor) const override;
bool IsTypeOf(TYPE type) const override;
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OutControlAnchor : public ControlAnchor {
friend class InControlAnchor;

public:
template <class T>
using Vistor = RangeVistor<T, std::shared_ptr<ConstAnchor>>;

explicit OutControlAnchor(const NodePtr &ownerNode);

explicit OutControlAnchor(const NodePtr &ownerNode, int idx);

virtual ~OutControlAnchor() = default;

// Get dst in control anchor(one or more)
Vistor<InControlAnchorPtr> GetPeerInControlAnchors() const;
// Get dst data anchor in control anchor(one or more)
Vistor<InDataAnchorPtr> GetPeerInDataAnchors() const;

// Build connection from OutControlAnchor to InControlAnchor
graphStatus LinkTo(const InControlAnchorPtr &dest);
// Build connection from OutDataAnchor to InDataAnchor
graphStatus LinkTo(const InDataAnchorPtr &dest);

protected:
bool Equal(AnchorPtr anchor) const override;
bool IsTypeOf(TYPE type) const override;
};
} // namespace ge
#endif // INC_GRAPH_ANCHOR_H_

+ 190
- 0
inc/graph/attr_value_serializable.h View File

@@ -0,0 +1,190 @@
/**
* 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 INC_GRAPH_ATTR_VALUE_SERIALIZABLE_H_
#define INC_GRAPH_ATTR_VALUE_SERIALIZABLE_H_

#include <string>
#include <vector>

#include "graph/ge_attr_value.h"

namespace ge {
class GeAttrValue;
class _GeSerializable {
public:
template <typename T>
struct ge_serializable_int64_t_support_type {
using DT = typename std::remove_cv<T>::type;
static const bool value = std::is_same<DT, uint64_t>::value // by cast
|| std::is_same<DT, int32_t>::value || std::is_same<DT, uint32_t>::value ||
std::is_same<DT, int16_t>::value || std::is_same<DT, uint16_t>::value ||
std::is_same<DT, int8_t>::value || std::is_same<DT, uint8_t>::value;
};

template <typename T, typename T::__ge_serializable = 0>
static GeAttrValue SaveItemAsAttrValue(const T &t) {
return GeAttrValue::CreateFrom(t);
}

template <typename T, typename T::__ge_serializable = 0>
static GeAttrValue SaveItemAsAttrValue(const vector<T> &t) {
return GeAttrValue::CreateFrom(t);
}

template <typename T, GeAttrValue::enable_if_type_valid_t<T> = 0, typename DT = typename std::remove_cv<T>::type>
static GeAttrValue SaveItemAsAttrValue(const T &t) {
return GeAttrValue::CreateFrom<DT>(t);
}
// int64_t support type
template <typename T, typename std::enable_if<ge_serializable_int64_t_support_type<T>::value, int>::type = 0>
static GeAttrValue SaveItemAsAttrValue(const T &t) {
return GeAttrValue::CreateFrom<GeAttrValue::INT>(t);
}
// vector int64_t support type
template <typename T, typename std::enable_if<ge_serializable_int64_t_support_type<T>::value, int>::type = 0>
static GeAttrValue SaveItemAsAttrValue(const vector<T> &t) {
return GeAttrValue::CreateFrom<GeAttrValue::LIST_INT>(t);
}

template <typename T, typename T::__ge_serializable = 0>
static graphStatus LoadItemFromAttrValue(T &t, GeAttrValue &attrVal) {
return attrVal.GetValue(t);
}

template <typename T, typename T::__ge_serializable = 0>
static graphStatus LoadItemFromAttrValue(vector<T> &t, GeAttrValue &attrVal) {
return attrVal.GetValue(t);
}

template <typename T, GeAttrValue::enable_if_type_valid_t<T> = 0, typename DT = typename std::remove_cv<T>::type>
static graphStatus LoadItemFromAttrValue(T &t, GeAttrValue &attrVal) {
return attrVal.GetValue<DT>(t);
}

template <typename T, typename std::enable_if<ge_serializable_int64_t_support_type<T>::value, int>::type = 0>
static graphStatus LoadItemFromAttrValue(T &t, GeAttrValue &attrVal) {
return attrVal.GetValue<GeAttrValue::INT>(t);
}

template <typename T, typename std::enable_if<ge_serializable_int64_t_support_type<T>::value, int>::type = 0>
static graphStatus LoadItemFromAttrValue(vector<T> &t, GeAttrValue &attrVal) {
return attrVal.GetValue<GeAttrValue::LIST_INT>(t);
}

template <class T, class... Args>
static void SaveItem(GeAttrValue::NamedAttrs &namedAttrs, string itemName, T &item, Args &... args) {
GeAttrValue itemVal = SaveItemAsAttrValue(item);
(void)namedAttrs.SetAttr(itemName, itemVal);
SaveItem(namedAttrs, args...);
}

static void SaveItem(GeAttrValue::NamedAttrs &namedAttrs __attribute__((__unused__))) {}

template <class T, class... Args>
static graphStatus LoadItem(GeAttrValue::NamedAttrs &namedAttrs, string itemName, T &item, Args &... args) {
auto itemVal = namedAttrs.GetItem(itemName);
auto status = LoadItemFromAttrValue(item, itemVal);
if (status != GRAPH_SUCCESS) {
return status;
}
return LoadItem(namedAttrs, args...);
}

static graphStatus LoadItem(GeAttrValue::NamedAttrs &namedAttrs __attribute__((__unused__))) { return GRAPH_SUCCESS; }
};


#define _GE_FI(a) #a, a
#define _GE_MAP_FIELDS1(a1) _GE_FI(a1)
#define _GE_MAP_FIELDS2(a1, a2) _GE_FI(a1), _GE_FI(a2)
#define _GE_MAP_FIELDS3(a1, a2, a3) _GE_FI(a1), _GE_FI(a2), _GE_FI(a3)
#define _GE_MAP_FIELDS4(a1, a2, a3, a4) _GE_FI(a1), _GE_FI(a2), _GE_FI(a3), _GE_FI(a4)
#define _GE_MAP_FIELDS5(a1, a2, a3, a4, a5) _GE_FI(a1), _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5)
#define _GE_MAP_FIELDS6(a1, a2, a3, a4, a5, a6) _GE_FI(a1), _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6)
#define _GE_MAP_FIELDS7(a1, a2, a3, a4, a5, a6, a7) \
_GE_FI(a1) \
, _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6), _GE_FI(a7)
#define _GE_MAP_FIELDS8(a1, a2, a3, a4, a5, a6, a7, a8) \
_GE_FI(a1) \
, _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6), _GE_FI(a7), _GE_FI(a8)
#define _GE_MAP_FIELDS9(a1, a2, a3, a4, a5, a6, a7, a8, a9) \
_GE_FI(a1) \
, _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6), _GE_FI(a7), _GE_FI(a8), _GE_FI(a9)
#define _GE_MAP_FIELDS10(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
_GE_FI(a1) \
, _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6), _GE_FI(a7), _GE_FI(a8), _GE_FI(a9), _GE_FI(a10)
#define _GE_MAP_FIELDS11(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
_GE_FI(a1) \
, _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6), _GE_FI(a7), _GE_FI(a8), _GE_FI(a9), _GE_FI(a10), \
_GE_FI(a11)
#define _GE_MAP_FIELDS12(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) \
_GE_FI(a1) \
, _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6), _GE_FI(a7), _GE_FI(a8), _GE_FI(a9), _GE_FI(a10), \
_GE_FI(a11), _GE_FI(a12)
#define _GE_MAP_FIELDS13(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) \
_GE_FI(a1) \
, _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6), _GE_FI(a7), _GE_FI(a8), _GE_FI(a9), _GE_FI(a10), \
_GE_FI(a11), _GE_FI(a12), _GE_FI(a13)
#define _GE_MAP_FIELDS14(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) \
_GE_FI(a1) \
, _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6), _GE_FI(a7), _GE_FI(a8), _GE_FI(a9), _GE_FI(a10), \
_GE_FI(a11), _GE_FI(a12), _GE_FI(a13), _GE_FI(a14)
#define _GE_MAP_FIELDS15(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) \
_GE_FI(a1) \
, _GE_FI(a2), _GE_FI(a3), _GE_FI(a4), _GE_FI(a5), _GE_FI(a6), _GE_FI(a7), _GE_FI(a8), _GE_FI(a9), _GE_FI(a10), \
_GE_FI(a11), _GE_FI(a12), _GE_FI(a13), _GE_FI(a14), _GE_FI(a15)

#define _GE_PRIVATE_ARGS_GLUE(x, y) x y

#define _GE_PRIVATE_MACRO_VAR_ARGS_IMPL_COUNT(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, N, \
...) \
N
#define _GE_PRIVATE_MACRO_VAR_ARGS_IMPL(args) _GE_PRIVATE_MACRO_VAR_ARGS_IMPL_COUNT args
#define _GE_COUNT_MACRO_VAR_ARGS(...) \
_GE_PRIVATE_MACRO_VAR_ARGS_IMPL((__VA_ARGS__, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))

#define _GE_PRIVATE_MACRO_CHOOSE_HELPER2(M, count) M##count
#define _GE_PRIVATE_MACRO_CHOOSE_HELPER1(M, count) _GE_PRIVATE_MACRO_CHOOSE_HELPER2(M, count)
#define _GE_PRIVATE_MACRO_CHOOSE_HELPER(M, count) _GE_PRIVATE_MACRO_CHOOSE_HELPER1(M, count)

#define _GE_INVOKE_VAR_MACRO(...) \
_GE_PRIVATE_ARGS_GLUE(_GE_PRIVATE_MACRO_CHOOSE_HELPER(_GE_MAP_FIELDS, _GE_COUNT_MACRO_VAR_ARGS(__VA_ARGS__)), \
(__VA_ARGS__))

#define GE_SERIALIZABLE(...) \
public: \
friend class ge::GeAttrValue; \
using __ge_serializable = int; \
\
private: \
ge::graphStatus Save(GeAttrValue &ar) const { \
GeAttrValue::NamedAttrs named_attrs; \
_GeSerializable::SaveItem(named_attrs, _GE_INVOKE_VAR_MACRO(__VA_ARGS__)); \
return ar.SetValue<GeAttrValue::NamedAttrs>(named_attrs); \
} \
ge::graphStatus Load(const GeAttrValue &ar) { \
GeAttrValue::NamedAttrs named_attrs; \
ge::graphStatus status = ar.GetValue<GeAttrValue::NamedAttrs>(named_attrs); \
if (status != GRAPH_SUCCESS) { \
return status; \
} \
return _GeSerializable::LoadItem(named_attrs, _GE_INVOKE_VAR_MACRO(__VA_ARGS__)); \
}

// end NamedAttrs Helper: GE_SERIALIZABLE
} // namespace ge
#endif // INC_GRAPH_ATTR_VALUE_SERIALIZABLE_H_

+ 83
- 0
inc/graph/buffer.h View File

@@ -0,0 +1,83 @@
/**
* 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 INC_GRAPH_BUFFER_H_
#define INC_GRAPH_BUFFER_H_

#include <memory>
#include <string>
#include <vector>

#include "detail/attributes_holder.h"
#include "graph/types.h"

namespace ge {
#ifdef HOST_VISIBILITY
#define GE_FUNC_HOST_VISIBILITY __attribute__((visibility("default")))
#else
#define GE_FUNC_HOST_VISIBILITY
#endif
#ifdef DEV_VISIBILITY
#define GE_FUNC_DEV_VISIBILITY __attribute__((visibility("default")))
#else
#define GE_FUNC_DEV_VISIBILITY
#endif

using std::shared_ptr;

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Buffer {
public:
Buffer();
Buffer(const Buffer &other);

explicit Buffer(std::size_t bufferSize, std::uint8_t defualtVal = 0);

~Buffer() = default;

Buffer &operator=(const Buffer &other);

static Buffer CopyFrom(const std::uint8_t *data, std::size_t bufferSize);

const std::uint8_t *GetData() const;
std::uint8_t *GetData();
std::size_t GetSize() const;
void ClearBuffer();

// For compatibility
inline const std::uint8_t *data() const { return GetData(); }
inline std::uint8_t *data() { return GetData(); }
inline std::size_t size() const { return GetSize(); }
inline void clear() { return ClearBuffer(); }
uint8_t operator[](size_t index) const {
if (buffer_ != nullptr && index < buffer_->size()) {
return (uint8_t)(*buffer_)[index];
}
return 0xff;
}

private:
GeIrProtoHelper<proto::AttrDef> data_;
std::string *buffer_ = nullptr;

// Create buffer from protobuf obj
Buffer(const ProtoMsgOwner &protoOnwer, proto::AttrDef *buffer);
Buffer(const ProtoMsgOwner &protoOnwer, std::string *buffer);

friend class GeAttrValueImp;
friend class GeTensor;
};
} // namespace ge
#endif // INC_GRAPH_BUFFER_H_

+ 242
- 0
inc/graph/compute_graph.h View File

@@ -0,0 +1,242 @@
/**
* 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 INC_GRAPH_COMPUTE_GRAPH_H_
#define INC_GRAPH_COMPUTE_GRAPH_H_

#include <deque>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "detail/attributes_holder.h"
#include "graph/anchor.h"
#include "graph/node.h"
#include "graph/op_desc.h"
#include "graph/range_vistor.h"

namespace ge {
class Node;
using NodePtr = std::shared_ptr<Node>;
class Edge;
using EdgePtr = std::shared_ptr<Edge>;

class InDataAnchor;
using InDataAnchorPtr = std::shared_ptr<InDataAnchor>;

class OutDataAnchor;
using OutDataAnchorPtr = std::shared_ptr<OutDataAnchor>;

class ControlAnchor;
using ControlAnchorPtr = std::shared_ptr<ControlAnchor>;
class InControlAnchor;
using InControlAnchorPtr = std::shared_ptr<InControlAnchor>;
class OutControlAnchor;
using OutControlAnchorPtr = std::shared_ptr<OutControlAnchor>;
class GeAttrValue;
using AttrValuePtr = std::shared_ptr<GeAttrValue>;
using ConstComputeGraph = const ComputeGraph;

class OperatorImpl;
using OperatorImplPtr = std::shared_ptr<OperatorImpl>;

class ComputeGraph : public std::enable_shared_from_this<ComputeGraph>, public AttrHolder {
friend class GraphUtils;

public:
template <class T>
using Vistor = RangeVistor<T, std::shared_ptr<ConstComputeGraph>>;

explicit ComputeGraph(const std::string &name);
virtual ~ComputeGraph();

std::string GetName() const;
void SetName(const std::string &name);

using AttrHolder::DelAttr;
using AttrHolder::GetAttr;
using AttrHolder::HasAttr;
using AttrHolder::SetAttr;

size_t GetAllNodesSize() const;
Vistor<NodePtr> GetAllNodes() const;
size_t GetDirectNodesSize() const;
Vistor<NodePtr> GetDirectNode() const;
Vistor<NodePtr> GetInputNodes() const;
Vistor<NodePtr> GetOutputNodes() const;

NodePtr FindNode(const std::string &name) const;
// Add node
NodePtr AddNode(NodePtr node);
NodePtr AddNode(OpDescPtr op);
NodePtr AddNodeFront(NodePtr node);
NodePtr AddNodeFront(const OpDescPtr &op);
NodePtr AddInputNode(NodePtr node);
NodePtr AddOutputNode(NodePtr node);

graphStatus RemoveNode(const NodePtr &node);
graphStatus RemoveInputNode(const NodePtr &node);
graphStatus RemoveOutputNode(const NodePtr &node);
graphStatus RemoveConstInput(const NodePtr &node);

std::shared_ptr<ComputeGraph> AddSubGraph(std::shared_ptr<ComputeGraph> sub_graph);
graphStatus RemoveSubGraph(const std::shared_ptr<ComputeGraph> &sub_graph);

graphStatus TopologicalSorting();
bool IsValid() const;
void Dump() const;

graphStatus IsolateNode(const NodePtr &node);
graphStatus Verify();
graphStatus InferShape();
graphStatus InferOriginFormat();
graphStatus InferShapeInNeed();
graphStatus InsertEventNodes();
bool operator==(const ComputeGraph &r_compute_graph) const;

const std::map<std::vector<std::string>, std::vector<std::string>> &GetShareParamLayer() const {
return params_share_map_;
}

void SetShareParamLayer(const std::map<std::vector<std::string>, std::vector<std::string>> params_share_map) {
params_share_map_ = params_share_map;
}

void SetInputsOrder(const std::vector<std::string> &inputs_order) { inputs_order_ = inputs_order; }

void SetGraphOutNodes(std::map<std::string, std::vector<int32_t>> out_nodes_map) { out_nodes_map_ = out_nodes_map; }

void AppendGraphOutNodes(std::map<std::string, std::vector<int32_t>> out_nodes_map) {
for (auto &item : out_nodes_map) {
(void)out_nodes_map_.emplace(item.first, item.second);
}
}

const std::map<std::string, std::vector<int32_t>> &GetGraphOutNodes() const { return out_nodes_map_; }

void SetOrigGraph(ComputeGraphPtr orig_graph) { origGraph_ = orig_graph; }

ComputeGraphPtr GetOrigGraph(void) { return origGraph_; }
void SetOutputSize(uint32_t size) { output_size_ = size; }
uint32_t GetOutputSize() const { return output_size_; }
void SetInputSize(uint32_t size) { input_size_ = size; }
uint32_t GetInputSize() const { return input_size_; }

///
/// Set iteration needed.
/// If set is true, it means this graph need run iteration some
/// times(according variant "npu_runconfig/iterations_per_loop").
/// @param need_iteration is need iteration
///
void SetNeedIteration(bool need_iteration) { need_iteration_ = need_iteration; }

void SetUserDefOutput(const std::string &output_name);

const std::string GetOutput();

///
/// Get need_iteration.
/// @return is need iteration
///
bool GetNeedIteration() const { return need_iteration_; }

void SetGraphOpName(const std::map<uint32_t, std::string> &op_name_map) { op_name_map_ = op_name_map; }
const std::map<uint32_t, std::string> &GetGraphOpName() const { return op_name_map_; }

const std::map<OperatorImplPtr, NodePtr> &GetAllNodesInfo() const;

void SetAllNodesInfo(const std::map<OperatorImplPtr, NodePtr> &nodes) { all_nodes_infos_ = nodes; }

void SetGraphOutNodesInfo(std::vector<std::pair<NodePtr, int32_t>> &out_nodes_info) {
output_nodes_info_ = out_nodes_info;
}

void AppendGraphOutNodesInfo(std::vector<std::pair<NodePtr, int32_t>> &out_nodes_info) {
output_nodes_info_.insert(output_nodes_info_.end(), out_nodes_info.begin(), out_nodes_info.end());
}

const std::vector<std::pair<NodePtr, int32_t>> &GetGraphOutNodesInfo() const { return output_nodes_info_; }

void SetGraphTargetNodesInfo(const std::vector<NodePtr> &target_nodes_info) {
target_nodes_info_ = target_nodes_info;
}
const std::vector<NodePtr> &GetGraphTargetNodesInfo() const { return target_nodes_info_; }

void SetSessionID(uint64_t session_id) { session_id_ = session_id; }
uint64_t GetSessionID() const { return session_id_; }

void SetGraphID(uint32_t graph_id) { graph_id_ = graph_id; }
uint32_t GetGraphID() const { return graph_id_; }

void SaveDataFormat(ge::Format data_format) { data_format_ = data_format; }
ge::Format GetDataFormat() const { return data_format_; }
bool IsSummaryGraph() const { return is_summary_graph_; }
void SetSummaryFlag(bool is_summary_graph) { is_summary_graph_ = is_summary_graph; }
// Graph Before BFE
ComputeGraphPtr origGraph_;

protected:
ProtoAttrMapHelper MutableAttrMap() override;
ConstProtoAttrMapHelper GetAttrMap() const override;

private:
graphStatus DFSTopologicalSorting(std::vector<NodePtr> &node_vec, std::map<NodePtr, uint32_t> &map_in_edge_num,
std::vector<NodePtr> &stack);
graphStatus BFSTopologicalSorting(std::vector<NodePtr> &node_vec, std::map<NodePtr, uint32_t> &map_in_edge_num,
std::deque<NodePtr> &stack);
graphStatus CollectBreadthOutNode(const NodePtr &node, std::map<NodePtr, uint32_t> &map_in_edge_num,
std::map<string, NodePtr> &breadth_node_map);
graphStatus SortNodes(std::vector<NodePtr> &stack, std::map<NodePtr, uint32_t> &mapInEdgeNum);
size_t GetInEdgeSize(const NodePtr &node);
size_t GetOutEdgeSize(const NodePtr &node);
graphStatus RemoveExtraOutEdge(const NodePtr &node);
bool GraphMembersAreEqual(const ComputeGraph &r_graph) const;
bool GraphAttrsAreEqual(const ComputeGraph &r_graph) const;
bool VectorInputNodePtrIsEqual(const std::vector<NodePtr> &r_node_ptr_vector,
const std::vector<NodePtr> &l_node_ptr_vector) const;

ProtoAttrMapHelper attrs_;

friend class ModelSerializeImp;
friend class GraphDebugImp;
friend class OnnxUtils;
std::vector<NodePtr> nodes_;
std::vector<NodePtr> input_nodes_;
std::vector<std::shared_ptr<ComputeGraph>> sub_graph_;
std::string name_;
bool is_valid_flag_;
bool is_summary_graph_ = false;
// Indicates whether it is need iteration
bool need_iteration_ = false;
std::map<std::vector<std::string>, std::vector<std::string>> params_share_map_;
std::map<std::string, std::vector<int32_t>> out_nodes_map_;
// TaskIdx -> op_name Map
std::map<uint32_t, std::string> op_name_map_;
std::vector<std::string> inputs_order_;
uint32_t output_size_ = 1;
uint32_t input_size_ = 1;
std::map<OperatorImplPtr, NodePtr> all_nodes_infos_;
std::vector<std::pair<NodePtr, int32_t>> output_nodes_info_;
std::vector<NodePtr> target_nodes_info_;
uint64_t session_id_ = 0;
uint32_t graph_id_ = 0;
ge::Format data_format_ = ge::FORMAT_ND;
};
} // namespace ge

#endif // INC_GRAPH_COMPUTE_GRAPH_H_

+ 778
- 0
inc/graph/debug/ge_attr_define.h View File

@@ -0,0 +1,778 @@
/**
* 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 INC_GRAPH_DEBUG_GE_ATTR_DEFINE_H_
#define INC_GRAPH_DEBUG_GE_ATTR_DEFINE_H_

#include <string>

#include "graph/types.h"

namespace ge {
#ifdef HOST_VISIBILITY
#define GE_FUNC_HOST_VISIBILITY __attribute__((visibility("default")))
#else
#define GE_FUNC_HOST_VISIBILITY
#endif
#ifdef DEV_VISIBILITY
#define GE_FUNC_DEV_VISIBILITY __attribute__((visibility("default")))
#else
#define GE_FUNC_DEV_VISIBILITY
#endif
// Public attribute
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_NAME;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_TYPE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_WORKSPACE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_WEIGHT_NAME;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_IS_QUANTIZE_FACTOR;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_ALPHA;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_BETA;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_PADMODE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_PADMODES;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_MODE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FILTER;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_BIAS;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_BIAS_TERM;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_PAD;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_PADS;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_PAD_SIZE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_PAD_MODE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_SCALE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_WINDOWS;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_GLOBAL_POOLING;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_CEIL_MODE;

// GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string
// ATTR_NAME_WEIGHTS;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_RELUMODE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_STRIDE_SIZE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_RELU_FLAG;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_ALGO;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FORMAT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FILTER_FORMAT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_LRN_K;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_LRN_NORM_REGION;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_LRN_LOCAL_SIZE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_LRN_ALPHA;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_LRN_BETA;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_AXIS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_BROADCAST;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OUTPUT_NUM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_TIDX;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_TPADDINGS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_IMG_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_IMG_W;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NET_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NET_W;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_TMULTIPLES;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_MULTIPLES;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_T;

extern GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY const std::string ATTR_NAME_N;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_TSHAPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_NAN_OPT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_AIPP;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_INPUT_FORMAT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OUTPUT_FORMAT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FRAMEWORK_NODE_DEF;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FRAMEWORK_OP_DEF;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FRAMEWORK_FWK_TYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FRAMEWORK_FUNC_DEF;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FRAMEWORK_ORIGINAL_TYPE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_INPUT_TENSOR_DESC;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OUTPUT_TENSOR_DESC;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_INFERRED_FORMAT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_PRED_PERMUTE_DELETED;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_IGNORE_PRED_FORMAT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_WEIGHTS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_WEIGHTS_DATA;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_BROACAST_REAL_DIM_CNT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DIM_ALIGN;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_SESSION_GRAPH_ID;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_BATCH_NUM;


GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_AUTOMIC_ADD_START;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_AUTOMIC_ADD_MEM_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_STREAM_LABEL;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_STREAM_CYCLE_EVENT_FLAG;

// to be deleted
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_TO_BE_DELETED;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PERMUTE_RESHAPE_FUSION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PERMUTE_RESHAPE_FUSION_CONV_PROPOSAL;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PERMUTE_RESHAPE_FUSION_CONV_DECODEBBOX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PERMUTE_RESHAPE_FUSION_BOX_TYPE_NUM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_MBOX_LOC_FUSION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_MBOX_CONF_FUSION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_MBOX_OCR_FUSION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_MBOX_FUSION_BOX_TYPE_NUM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_RESHAPE_SLICE_CONCAT_FUSION;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIORBOX_CONCAT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REFINEDET_MBOX_LOC_FUSION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REFINEDET_RESHAPE_SLICE_CONCAT_FUSION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REFINEDET_MBOX_CONF_FUSION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REFINEDET_MBOX_FUSION_BOX_TYPE_NUM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REFINEDET_PRIOR_BOX_ATTR_VARIANCE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REFINEDET_PRIOR_BOX_ATTR_VARIANCE_NUM;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string NEED_INFER;

// _Arg
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_INDEX;
// _RetVal
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RETVAL_ATTR_NAME_INDEX;
// Data
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DATA_ATTR_NAME_DATA_TYPE;

// Send
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SEND_ATTR_EVENT_ID;

// Recv
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RECV_ATTR_EVENT_ID;

// Convolution
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_COEF;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_STRIDE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_STRIDES;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DILATION;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DILATIONS;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_MODE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_ALGO;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_GROUP;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_PAD_MODE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_PAD;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_STRIDE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_DILATION;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_NUM_OUTPUT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_KERNEL;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_FILTER;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_BIAS;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_RELU_FLAG;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_ADJ;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_TARGET_SHAPE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_BEFORE_PAD;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_ATTR_NAME_HAS_BIAS;

// Pooling
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_NAN_OPT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_PAD_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_GLOBAL_POOLING;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_WINDOW;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_PAD;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_STRIDE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_CEIL_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_DATA_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_BEFORE_PAD;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POOLING_ATTR_NAME_ALGO;

// Eltwise
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ELTWISE_ATTR_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ELTWISE_ATTR_COEFF;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ELTWISE_ATTR_WEIGHT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ELTWISE_ATTR_RELU_FLAG;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ELTWISE_ATTR_ALPHA;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ELTWISE_ATTR_BETA;

// BatchNorm
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string BATCHNORM_ATTR_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string BATCHNORM_ATTR_EPSILON;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string BATCHNORM_ATTR_USE_GLOBAL_STATS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string BATCHNORM_ATTR_MOVING_AVERAGE_FRACTION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string BATCHNORM_ATTR_ESTIMATED_MEAN;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string BATCHNORM_ATTR_ESTIMATED_VARIANCE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string BATCHNORM_ATTR_SCALE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string BATCHNORM_ATTR_BIAS;

// Scale
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SCALE_ATTR_SCALE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SCALE_ATTR_BIAS;

// FullConnection
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FULL_CONNECTION_ATTR_FILTER;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FULL_CONNECTION_ATTR_BIAS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FULL_CONNECTION_ATTR_NUM_OUTPUT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FULL_CONNECTION_ATTR_RELU_FLAG;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FULL_ATTR_NAME_ALGO;

// SoftmaxOpParams
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SOFTMAX_ATTR_ALGO;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SOFTMAX_ATTR_MODE;

// SparseSoftmaxCrossEntropy
extern GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY const std::string SPARSE_SOFTMAX_CROSS_ENTROPY_ATTR_MODE;
extern GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY const std::string SPARSE_SOFTMAX_CROSS_ENTROPY_IS_GRAD;
// Attr labelSmoothing
extern GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY const std::string SOFTMAX_CROSS_ENTROPY_LABELSMOOTHING;

// ApplyMomentum
extern GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY const std::string APPLYMENTUM_ATTR_IS_GRAPH_FUSION;

// Activation
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ACTIVATION_ATTR_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ACTIVATION_ATTR_COEF;

// Concat
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONCAT_ATTR_NAME_AXIS;

// Const
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONST_ATTR_NAME_DATA_TRANSTYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONST_ATTR_NAME_OUTPUT_FORMAT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONST_ATTR_NAME_OUTPUT_TYPE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEPTH_SPACE_ATTR_BLOCK_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string L2_NORMALIZE_ATTR_EPS;

// Roipooling
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIPOOLING_ATTR_NAME_POOLED_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIPOOLING_ATTR_NAME_POOLED_W;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIPOOLING_ATTR_NAME_SPATIAL_SCALE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIPOOLING_ATTR_NAME_RIO_POOLING_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIPOOLING_ATTR_NAME_POOLING_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIPOOLING_ATTR_NAME_SAMPLING_RATIO;

// DetectionOutput
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_NUM_CLASSES;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_NMS_THRESHOLD;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_TOP_K;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_CONFIDENCE_THRESHOLD;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_IMG_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_IMG_W;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_BATCH_SIZE;
// Ssd DetectionOutput
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_ETA;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_SHARED_LOCATION;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_BACKGROUND_LABEL_ID;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_CODE_TYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_VARIANCE_ENCODED_IN_TARGET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_KEEP_TOP_K;

// Refinedet DetectionOutput
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_OBJECTNESS_SCORE;

// Yolo DetectionOutput
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_ClASSES;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_BIASES;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_RELATIVE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_OBJECTNESS_THRESHOLD;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_CLASS_THRESHOLD;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_POST_TOP_K;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_IOU_THRESHOLD_DECAY;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_COOR_SCALE_FACTOR;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DETECTIONOUTPUT_ATTR_YOLO_VERSION;

// DetectionPostprocess
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POSTPROCESS_ATTR_NAME_CLS_NUM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POSTPROCESS_ATTR_NAME_CONF_THRESH;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POSTPROCESS_ATTR_NAME_NMS_THRESH;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POSTPROCESS_ATTR_POST_NMS_TOPN;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POSTPROCESS_ATTR_NAME_BBOX_REG_WEIGHT;

// Spatialtransfrom
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SPTIALTF_ATTR_NAME_OUTPUT_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SPTIALTF_ATTR_NAME_OUTPUT_W;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SPTIALTF_ATTR_NAME_BORDER_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SPTIALTF_ATTR_NAME_AFFINE_TRANSFORM;

// Proposal
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_NAME_FEAT_STRIDE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_NAME_BASE_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_NAME_MIN_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_NAME_RATIO;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_NAME_SCALE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_NAME_PRE_NMS_TOPN;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_NAME_POST_NMS_TOPN;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_NAME_NMS_THRESH;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_NAME_TOP_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_IMG_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PROPOSAL_ATTR_IMG_W;
// Softmax
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SOFTMAX_ATTR_AXIS;

// Permute
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PERMUTE_ATTR_ORDER;

// SSD Normalize
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSDNORMALIZE_ATTR_ACCROSS_SPATIAL;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSDNORMALIZE_ATTR_CHANNEL_SHARED;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSDNORMALIZE_ATTR_EPS;

// Flatten
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FLATTEN_ATTR_AXIS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FLATTEN_ATTR_END_AXIS;

// SsdPRIORBOX
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_FLIP;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_CLIP;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_IMG_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_IMG_W;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_STEP_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_STEP_W;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_MIN_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_MAX_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_MIN_SIZE_NUM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_MAX_SIZE_NUM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_ASPECT_RATIO;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_ASPECT_RATIO_NUM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_VARIANCE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SSD_PRIOR_BOX_ATTR_VARIANCE_NUM;

// PRelu
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PRELU_ATTR_CHANNEL_SHARED;

// Psroi pooling
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PSROIPOOLING_ATTR_SPATIAL_SCALE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PSROIPOOLING_ATTR_OUTPUT_DIM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PSROIPOOLING_ATTR_GROUP_SIZE;

// Power
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POWER_ATTR_NAME_POWER;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POWER_ATTR_NAME_SCALE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string POWER_ATTR_NAME_SHIFT;

// Pack
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PACK_ATTR_NAME_NUM;

// Unpack
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string UNPACK_ATTR_NAME_NUM;
// Gathernd
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string GATHERND_ATTR_NAME_TINDICES;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string GATHERND_ATTR_NAME_TPARAMS;

// Argmax
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ARGMAX_ATTR_NAME_TOPK;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ARGMAX_ATTR_NAME_OUTMAX;

// Relu
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_NEGATIVE_SLOPE;

// FreeSpaceExtract
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FREESPACEEXTRACT_ATTR_NAME_ORG_HEIGHT;

// Split
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SPLIT_ATTR_NAME_SLICE_POINT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SPLIT_ATTR_NAME_SIZE_SPLIT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SPLIT_ATTR_NAME_NUM_SPLIT;

// Tvm
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string TVM_ATTR_NAME_MAGIC;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string TVM_ATTR_NAME_BLOCKDIM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string TVM_ATTR_NAME_METADATA;

// Squeeze
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SQUEEZE_ATTR_AXIS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SQUEEZE_ATTR_DIMS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SQUEEZE_OP_NAME;

// Stride slice
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string STRIDE_SLICE_ATTR_BEGIN_MASK;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string STRIDE_SLICE_ATTR_END_MASK;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string STRIDE_SLICE_ATTR_ELLIPSIS_MASK;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string STRIDE_SLICE_ATTR_NEW_AXIS_MASK;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string STRIDE_SLICE_ATTR_SHRINK_AXIS_MASK;

// Slice
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SLICE_ATTR_NAME_BEGINS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SLICE_ATTR_NAME_SIZES;

// Roialign
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIALIGN_ATTR_SPATIAL_SCALE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIALIGN_ATTR_SAMPLING_RATIO;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIALIGN_ATTR_NAME_POOLED_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ROIALIGN_ATTR_NAME_POOLED_W;

// Generate_rpn_proposal
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string GENERATE_RPN_PROPOSAL_ATTR_PRE_NMS_TOPK;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string GENERATE_RPN_PROPOSAL_ATTR_POST_NMS_TOPK;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string GENERATE_RPN_PROPOSAL_ATTR_RPN_MINI_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string
GENERATE_RPN_PROPOSAL_ATTR_RPN_PROPOSAL_NMS_THRESH;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string
GENERATE_RPN_PROPOSAL_ATTR_RPN_PROPOSAL_FILTER_THRESH;
// Decode_bbox
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DECODE_BBOX_ATTR_DECODECLIP;

// Cast
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CAST_ATTR_DSTT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CAST_ATTR_SRCT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CAST_ATTR_DST_TYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CAST_ATTR_TRUNCATE;

// Fastrcnnn predications
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FASTRCNN_PREDICTIONS_ATTR_TOPK;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FASTRCNN_PREDICTIONS_ATTR_SCORE_THRESHOLD;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FASTRCNN_PREDICTIONS_ATTR_NMS_THRESHOLD;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FASTRCNN_PREDICTIONS_ATTR_NUM_CLASSES;

// REORG
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REORG_ATTR_STRIDE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REORG_ATTR_REVERSE;

// MERGE
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string MERGE_DEAD_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string MERGE_PRENODE_FLAG;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string TO_BE_OUTPUT;

// ENTER
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ENTER_ATTR_FRAME_NAME;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ENTER_ATTR_CONSTANT_FLAG;

// Concatv2
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONCAT_V2_ATTR_TIDX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONCAT_V2_ATTR_N;
// SUM
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SUM_ATTR_TIDX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SUM_ATTR_AXIS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SUM_ATTR_KEEP_DIMS;

// ResizeBilinear
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_ALIGN_CORNERS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_HEIGHT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_WIDTH;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_ZOOM_FACTOR;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_SHRINK_FACTOR;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_PAD_BEGIN;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_PAD_END;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_ALPHA;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESIZE_BILINEAR_ATTR_BETA;

// MatMul
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string MATMUL_TRANSPOSE_X;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string MATMUL_TRANSPOSE_W;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string MATMUL_HAS_BIAS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string MATMUL_ATTR_IS_TRAINING;

// Flatten
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FLATTEN_START_AXIS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FLATTEN_END_AXIS;

// Reshape
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESHAPE_ATTR_AXIS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESHAPE_ATTR_NUM_AXES;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESHAPE_ATTR_FORMAT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESHAPE_ATTR_SHAPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESHAPE_ATTR_ALPHA;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RESHAPE_ATTR_BETA;

// Frameoworkop
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string T_IN_DATATYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string T_OUT_DATATYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OUT_N;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OUT_C;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OUT_H;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OUT_W;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_PAD_DEPTH_CONV;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_PAD_CONV;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_BEFORE_PAD;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ANN_MEAN_KEEPDIMS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PAD_ATTR_PADDINGDS;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PAD_ATTR_CONSTANT_VALUE;

// ConvGradFilter
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_GRAD_FILTER_OUTPUT_SHAPE;
// ConvGradInput
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CONV_GRAD_INPUT_OUTPUT_SHAPE;

// Rnn
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RNN_MODE_STATIC;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string MUTI_RNN;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CELL_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string CNN_RNN;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string LSTM_CELL;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string GRU_CELL;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RNN_HT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RNN_XT_HT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string RNN_BATCH_SIZE;

// Upsample
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string UPSAMPLE_ATTR_NAME_SCALE;

// Filler
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FILLER_TYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FILLER_VALUE;

// Shufflechannel
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SHUFFLE_CHANNEL_GROUP;

// TopKV2
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string TOPKV2_ATTR_K;

// Calibaration
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string STRIDE_H_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string STRIDE_W_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PAD_TOP_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PAD_BOTTOM_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PAD_RIGHT_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string PAD_LEFT_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_ALGO_ATTR;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string SCALE_TYPE_ATTR;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_SCALE_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_SCALE_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_SCALE_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_OFFSET_DATA_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_OFFSET_DATA_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_OFFSET_WEIGHT_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_OFFSET_WEIGHT_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_OFFSET_PAD_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string QUANTIZE_OFFSET_PAD_OFFSET;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEQUANTIZE_SCALE_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEQUANTIZE_SCALE_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEQUANTIZE_SCALE_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEQUANTIZE_OFFSET_DATA_TYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEQUANTIZE_OFFSET_DATA_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEQUANTIZE_OFFSET_WEIGHT_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEQUANTIZE_OFFSET_WEIGHT_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEQUANTIZE_OFFSET_PAD_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DEQUANTIZE_OFFSET_PAD_OFFSET;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REQUANTIZE_SCALE_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REQUANTIZE_SCALE_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REQUANTIZE_SCALE_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REQUANTIZE_OFFSET_DATA_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REQUANTIZE_OFFSET_DATA_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REQUANTIZE_OFFSET_WEIGHT_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REQUANTIZE_OFFSET_WEIGHT_OFFSET;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REQUANTIZE_OFFSET_PAD_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REQUANTIZE_OFFSET_PAD_OFFSET;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_IS_CONST;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_GROUP;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DILATION_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_EPSILON;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_POOLING_MODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_CLASS_NUM;
// Model
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_TARGET_TYPE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_STREAM_NUM;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_EVENT_NUM;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_MEMORY_SIZE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_WEIGHT_SIZE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_TASK_GEN_BASE_ADDR;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_TASK_GEN_WEIGHT_ADDR;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_TASK_GEN_VAR_ADDR;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_VAR_SIZE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_MODEL_TASK_INDEX_OP_NAME;

// Public attribute
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_IMPLY_TYPE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_BYTE_SIZE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FUSION_INFERENCE_ID;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FUSION_OPDEF;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_IO_OP;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_FUSION_SCOPE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OPATTR;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_RELUFLAG;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_SEQLEN_INDEX;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_X_INDEX;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_CONT_INDEX;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_XSTATIC_INDEX;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string TARGET_TYPE_MINI;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string TARGET_TYPE_TINY;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string TARGET_TYPE_LITE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_CONTINUOUS_INPUT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_CONTINUOUS_OUTPUT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_REFERENCE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_ATOMIC_INDEX;

// Used for mark the active label list to find stream of activated node
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_ACTIVE_LABEL_LIST;

// Multi batch
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_PRED_VALUE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_BATCH_NUM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_BATCH_LABEL;

// Control flow
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_STREAM_SWITCH_COND;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_TRUE_BRANCH_STREAM;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_ACTIVE_STREAM_LIST;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_SWITCHN_PRED_VALUE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_SWITCH_BRANCH_NODE_LABEL;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_SWITCH_TRUE_BRANCH_FLAG;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_SWITCH_DATA_TYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_ORIG_NODE_NAME;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_CYCLIC_DEPENDENCE_FLAG;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_NEXT_ITERATION;

// Used for mark the active node is for loop, type:bool
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_IS_LOOP_ACTIVE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_MEMORY_TYPE_INPUT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_MEMORY_TYPE_OUTPUT;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_MEMORY_TYPE_WORKSPACE;

// Atomic addr clean attrs
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATOMIC_ATTR_INPUT_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATOMIC_ATTR_OUTPUT_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATOMIC_ATTR_IS_FUSION_NODE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATOMIC_ATTR_IS_ATOMIC_NODE;

GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string EXT_ATTR_ATOMIC_WORKSPACE_INFO;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string EXT_ATTR_ATOMIC_WORKSPACE_OFFSET;
// Used for find variable session_id
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string MODEL_ATTR_SESSION_ID;

// Source/dst format for Op FormatTransfer
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FORMAT_TRANSFER_SRC_FORMAT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string FORMAT_TRANSFER_DST_FORMAT;

// For compile op by ge call
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NEED_COMPILE;

// For mutil-batch
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_INSERT_BY_MBATCH;

// For inserted op
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_INSERTED_BY_GE;

// For data dump
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DATA_DUMP_IS_MULTIOP;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DATA_DUMP_SUB_SPLITER_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DATA_DUMP_GROUP_OP_NAME;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DATA_DUMP_ORIGIN_NAME;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DATA_DUMP_ORIGIN_OUTPUT_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DATA_DUMP_ORIGIN_FORMAT;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_DATA_DUMP_ORIGIN_DATA_TYPE;

// Varible
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REF_VAR_SRC_VAR_NAME;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string VAR_ATTR_SRC_VAR_NAME;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string REF_VAR_PRE_PEER_OUT_INDEX;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string VAR_ATTR_VAR_IS_BROADCAST;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string VAR_ATTR_VAR_IS_RESTORE;

// HCOM
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string HCOM_ATTR_ROOT_RANK;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string HCOM_ATTR_REDUCE_TYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string HCOM_ATTR_RANK_SIZE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string HCOM_ATTR_SHAPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string HCOM_ATTR_DATA_TYPE;


GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_INPUT_DATATYPE;
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string ATTR_NAME_OUTPUT_DATATYPE;

// Dynamic stitch
GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY extern const std::string DYNAMIC_STITCH_ATTR_NAME_NUM;
} // namespace ge

#endif // INC_GRAPH_DEBUG_GE_ATTR_DEFINE_H_

+ 198
- 0
inc/graph/def_types.h View File

@@ -0,0 +1,198 @@
/**
* 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 INC_GRAPH_DEF_TYPES_H_
#define INC_GRAPH_DEF_TYPES_H_

#include <atomic>
#include <memory>
#include <vector>

#include "graph/attr_value_serializable.h"
#include "graph/buffer.h"

namespace ge {
#define DEF_TYPE_DEC(type, name) \
inline void set_##name(const type &value) { name = value; } \
type *mutable_##name() { return &name; }

#define DEF_TYPE_HAS_DEC(type, name) \
inline void set_##name(const type &value) { name = value; } \
\
private: \
bool has_mutable_##name{false}; \
\
public: \
bool has_##name() const { return (has_mutable_##name) || QuantizeFactorHasData(name); } \
type *mutable_##name() { \
has_mutable_##name = true; \
return &name; \
}

#define DEF_TYPE_VEC_DEC(type, name) \
inline int name##_size() const { return name.size(); } \
inline void clear_##name() { name.clear(); } \
inline void set_##name(int index, type value) { name[index] = value; } \
inline void add_##name(type value) { name.push_back(value); } \
inline std::vector<type> *mutable_##name() { return &name; }

#define DEF_TYPE_BYTES_DEC(name) \
inline void clear_##name() { name.ClearBuffer(); } \
inline void set_##name(const void *value, size_t size) { \
name = Buffer::CopyFrom((const uint8_t *)(value), size); } \
inline Buffer *mutable_##name() { return &name; }

struct CompressInfo {
public:
CompressInfo() {}
CompressInfo(int32_t blockRow, int32_t blockCol, int32_t fractalK, int32_t fractalN, int32_t lastFractalK,
int32_t lastFractalN, int32_t cubeSize, int32_t loadDir) {
blockrow = blockRow;
blockcol = blockCol;
fractalk = fractalK;
fractaln = fractalN;
lastfractalk = lastFractalK;
lastfractaln = lastFractalN;
cubesize = cubeSize;
loaddir = loadDir;
}

int32_t blockrow{0}; // Block row
int32_t blockcol{0}; // Block col
int32_t fractalk{0}; // Fractal K
int32_t fractaln{0}; // Fractal N
int32_t lastfractalk{0}; // K of last fractal
int32_t lastfractaln{0}; // N of last fractal
int32_t cubesize{0}; // Cube's length
int32_t loaddir{0}; // Data load directtiono 0:col load 1:row load
DEF_TYPE_DEC(int32_t, blockrow);
DEF_TYPE_DEC(int32_t, blockcol);
DEF_TYPE_DEC(int32_t, fractalk);
DEF_TYPE_DEC(int32_t, fractaln);
DEF_TYPE_DEC(int32_t, lastfractalk);
DEF_TYPE_DEC(int32_t, lastfractaln);
DEF_TYPE_DEC(int32_t, cubesize);
DEF_TYPE_DEC(int32_t, loaddir);

GE_SERIALIZABLE(blockrow, blockcol, fractalk, fractaln, lastfractalk, lastfractaln, cubesize, loaddir);
};

enum QuantizeScaleType { VECTOR_SCALE = 0, SCALAR_SCALE = 1 };
enum QuantizeScaleMode { NORMAL_MODE = 0, SQRT_MODE = 1 };
enum QuantizeAlgorithm {
NON_OFFSET_ALGO = 0,
HALF_OFFSET_ALGO = 1,
ALL_OFFSET_ALGO = 2,
};
struct QuantizeFactor {
public:
// QuantizeScaleMode scale_mode;
uint32_t scale_mode{0};
Buffer scale_value;
int64_t scale_offset{0};
Buffer offset_data_value;
int64_t offset_data_offset{0};
Buffer offset_weight_value;
int64_t offset_weight_offset{0};
Buffer offset_pad_value;
int64_t offset_pad_offset{0};

DEF_TYPE_DEC(uint32_t, scale_mode);
DEF_TYPE_BYTES_DEC(scale_value);

DEF_TYPE_DEC(int64_t, scale_offset);
DEF_TYPE_BYTES_DEC(offset_data_value);
DEF_TYPE_DEC(int64_t, offset_data_offset);

DEF_TYPE_BYTES_DEC(offset_weight_value);
DEF_TYPE_DEC(int64_t, offset_weight_offset);
DEF_TYPE_BYTES_DEC(offset_pad_value);
DEF_TYPE_DEC(int64_t, offset_pad_offset);

GE_SERIALIZABLE(scale_mode, scale_value, scale_offset, offset_data_value, offset_data_offset, offset_weight_value,
offset_weight_offset, offset_pad_value, offset_pad_offset)
};

static inline bool QuantizeFactorHasData(const QuantizeFactor &factor) {
return factor.scale_value.GetSize() > 0 || factor.offset_data_value.GetSize() > 0 ||
factor.offset_weight_value.GetSize() > 0 || factor.offset_pad_value.GetSize() > 0;
}

struct AllOffsetQuantizeInfo {
public:
AllOffsetQuantizeInfo() {}
AllOffsetQuantizeInfo(float s, int32_t o) : scale(s), offset(o) {}
float scale{0};
int32_t offset{0};

DEF_TYPE_DEC(float, scale);
DEF_TYPE_DEC(int32_t, offset);

GE_SERIALIZABLE(scale, offset)
};

struct QuantizeCalcFactor {
public:
Buffer offsetw;
int64_t offsetw_offset{0};
Buffer offsetd;
int64_t offsetd_offset{0};
Buffer scalereq;
int64_t scaledreq_offset{0};
Buffer offsetdnext;
int64_t offsetdnext_offset{0};

DEF_TYPE_BYTES_DEC(offsetw);
DEF_TYPE_DEC(int64_t, offsetw_offset);
DEF_TYPE_BYTES_DEC(offsetd);
DEF_TYPE_DEC(int64_t, offsetd_offset);
DEF_TYPE_BYTES_DEC(scalereq);
DEF_TYPE_DEC(int64_t, scaledreq_offset);
DEF_TYPE_BYTES_DEC(offsetdnext);
DEF_TYPE_DEC(int64_t, offsetdnext_offset);

GE_SERIALIZABLE(offsetw, offsetw_offset, offsetd, offsetd_offset, scalereq, scaledreq_offset, offsetdnext,
offsetdnext_offset);
};

static inline bool QuantizeFactorHasData(const QuantizeCalcFactor &factor) {
return factor.offsetw.GetSize() > 0 || factor.offsetd.GetSize() > 0 || factor.scalereq.GetSize() > 0 ||
factor.offsetdnext.GetSize() > 0;
}

struct QuantizeFactorParams {
uint32_t quantize_algo{0};
uint32_t scale_type{0};
QuantizeFactor quantize_param;
QuantizeFactor dequantize_param;
QuantizeFactor requantize_param;
QuantizeCalcFactor quantizecalc_param;
DEF_TYPE_DEC(uint32_t, quantize_algo);
DEF_TYPE_DEC(uint32_t, scale_type);
DEF_TYPE_HAS_DEC(QuantizeFactor, quantize_param);
DEF_TYPE_HAS_DEC(QuantizeFactor, dequantize_param);
DEF_TYPE_HAS_DEC(QuantizeFactor, requantize_param);
DEF_TYPE_HAS_DEC(QuantizeCalcFactor, quantizecalc_param);

GE_SERIALIZABLE(quantize_algo, scale_type, quantize_param, dequantize_param, requantize_param, quantizecalc_param,
has_mutable_quantize_param, has_mutable_dequantize_param, has_mutable_requantize_param,
has_mutable_quantizecalc_param);
};

#undef DEF_TYPE_DEC
} // namespace ge

#endif // INC_GRAPH_DEF_TYPES_H_

+ 118
- 0
inc/graph/detail/any_map.h View File

@@ -0,0 +1,118 @@
/**
* 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 INC_GRAPH_DETAIL_ANY_MAP_H_
#define INC_GRAPH_DETAIL_ANY_MAP_H_

#include <map>
#include <memory>
#include <string>
#include <utility>

namespace ge {
using std::shared_ptr;
using std::string;

class TypeID {
public:
template <class T>
static TypeID Of() {
return TypeID(__PRETTY_FUNCTION__);
}

~TypeID() = default;

bool operator==(const TypeID &__arg) const { return type_ == __arg.type_; }

private:
explicit TypeID(string type) : type_(std::move(type)) {}

string type_;
};

class AnyMap {
public:
template <class DT>
bool Set(const string &name, const DT &val);

template <class T>
bool Get(const string &name, T &retValue) const;

bool Has(const string &name) const { return anyValues_.find(name) != anyValues_.end(); }

private:
class Placeholder {
public:
virtual ~Placeholder() = default;

virtual const TypeID &GetTypeInfo() const = 0;
};

template <typename VT>
class Holder : public Placeholder {
public:
explicit Holder(const VT &value) : value_(value) {}

~Holder() override = default;

const TypeID &GetTypeInfo() const override {
static const TypeID typeId = TypeID::Of<VT>();
return typeId;
}

const VT value_;
};

std::map<string, shared_ptr<Placeholder>> anyValues_;
};

template <class DT>
bool AnyMap::Set(const string &name, const DT &val) {
auto it = anyValues_.find(name);

std::shared_ptr<Holder<DT>> tmp;
try {
tmp = std::make_shared<Holder<DT>>(val);
} catch (std::bad_alloc &e) {
tmp = nullptr;
} catch (...) {
tmp = nullptr;
}

if (it == anyValues_.end()) {
(void)anyValues_.emplace(name, tmp);
} else {
if (it->second && it->second->GetTypeInfo() == TypeID::Of<DT>()) {
it->second = tmp;
} else {
return false;
}
}
return true;
}

template <class T>
bool AnyMap::Get(const string &name, T &retValue) const {
auto it = anyValues_.find(name);
if (it != anyValues_.end() && it->second && it->second->GetTypeInfo() == TypeID::Of<T>()) {
auto retPtr = std::static_pointer_cast<Holder<T>>(it->second);
retValue = retPtr->value_;
return true;
}
return false;
}
} // namespace ge
#endif // INC_GRAPH_DETAIL_ANY_MAP_H_

+ 154
- 0
inc/graph/detail/attributes_holder.h View File

@@ -0,0 +1,154 @@
/**
* 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 INC_GRAPH_DETAIL_ATTRIBUTES_HOLDER_H_
#define INC_GRAPH_DETAIL_ATTRIBUTES_HOLDER_H_

#include <map>
#include <memory>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>

#include "graph/detail/any_map.h"
#include "graph/ge_error_codes.h"
#include "graph/types.h"

namespace google {
namespace protobuf {
class Message;
template <typename Key, typename T>
class Map;
} // namespace protobuf
} // namespace google

namespace ge {
using std::string;
class GeAttrValue;

namespace proto {
class AttrDef;
class TensorDef;
class TensorDescriptor;
class ShapeDef;
class NamedAttrs;
class ModelDef;
class OpDef;
class GraphDef;
} // namespace proto

using ProtoAttrMap = ::google::protobuf::Map<::std::string, ::ge::proto::AttrDef>;
using ProtoMsgOwner = std::shared_ptr<::google::protobuf::Message>;

template <class ProtoType>
class GeIrProtoHelper {
public:
GeIrProtoHelper(const ProtoMsgOwner &protoOwner, ProtoType *protoMsg)
: protoOwner_(protoOwner), protoMsg_(protoMsg) {}

GeIrProtoHelper() {
protoOwner_ = std::shared_ptr<::google::protobuf::Message>(nullptr);
protoMsg_ = nullptr;
}
virtual ~GeIrProtoHelper() = default;

template <typename T>
GeIrProtoHelper(const GeIrProtoHelper<T> &other) {
protoOwner_ = other.protoOwner_;
protoMsg_ = other.protoMsg_;
}
template <typename T>
GeIrProtoHelper &operator=(const GeIrProtoHelper<T> &other) {
protoOwner_ = other.protoOnwer_;
protoMsg_ = other.protoMsg_;
return *this;
}
void InitDefault();
template <typename T>
bool operator==(const GeIrProtoHelper<T> &other) const {
return protoOwner_ == other.protoOwner_ && protoMsg_ == other.protoMsg_;
}

inline const ProtoMsgOwner &GetProtoOwner() const { return protoOwner_; }
inline ProtoType *GetProtoMsg() const { return protoMsg_; }
void CopyValueFrom(const GeIrProtoHelper<const ProtoType> &other) {
if (other.protoMsg_ != nullptr && protoMsg_ != nullptr) {
*protoMsg_ = *other.protoMsg_;
}
}
void MoveValueFrom(GeIrProtoHelper<ProtoType> &&other) {
if (other.protoMsg_ != nullptr && protoMsg_ != nullptr) {
*protoMsg_ = std::move(*other.protoMsg_);
}
}

// protoMsg_ is part of protoOwner_ and they have the same runtime
ProtoMsgOwner protoOwner_ = nullptr;
ProtoType *protoMsg_ = nullptr;
friend class GeIrProtoHelper<typename std::conditional<
std::is_const<ProtoType>::value, typename std::remove_const<ProtoType>::type, const ProtoType>::type>;
};

using ProtoAttrMapHelper = GeIrProtoHelper<ProtoAttrMap>;
using ConstProtoAttrMapHelper = GeIrProtoHelper<const ProtoAttrMap>;

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AttrHolder {
public:
AttrHolder() = default;
virtual ~AttrHolder() = default;

graphStatus SetAttr(const string &name, const GeAttrValue &value);

graphStatus GetAttr(const string &name, GeAttrValue &value) const;

bool HasAttr(const string &name) const;

graphStatus DelAttr(const string &name);

void CopyAttrsFrom(const AttrHolder &holder);

template <class T>
bool SetExtAttr(const string &name, const T &value) {
return extAttrs_.Set(name, value);
}
template <class T>
T TryGetExtAttr(const string &name, T defaultValue) const {
T ret(defaultValue);
(void)extAttrs_.Get(name, ret);
return ret;
}

protected:
graphStatus AddRequiredAttr(const std::string &name);
const std::unordered_set<string> GetAllAttrNames() const;
const std::map<string, GeAttrValue> GetAllAttrs() const;

virtual ProtoAttrMapHelper MutableAttrMap() = 0;
virtual ConstProtoAttrMapHelper GetAttrMap() const = 0;

friend class ModelSerializeImp;
friend class AttrUtils;
friend class AttrUtilsHelper;

std::vector<string> requiredAttrs_;

private:
AnyMap extAttrs_;
};
} // namespace ge

#endif // INC_GRAPH_DETAIL_ATTRIBUTES_HOLDER_H_

+ 90
- 0
inc/graph/detail/model_serialize_imp.h View File

@@ -0,0 +1,90 @@
/**
* 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 INC_GRAPH_DETAIL_MODEL_SERIALIZE_IMP_H_
#define INC_GRAPH_DETAIL_MODEL_SERIALIZE_IMP_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "graph/anchor.h"
#include "graph/model.h"
#include "detail/attributes_holder.h"
#include "graph/ge_tensor.h"
#include "graph/graph.h"
#include "graph/node.h"

namespace ge {
using ComputeGraphPtr = std::shared_ptr<ComputeGraph>;

struct NodeNameGraphReq {
string node_name;
int32_t index;
ComputeGraphPtr graph;
};

struct NodeNameNodeReq {
string src_node_name;
int32_t src_out_index;
NodePtr dst_node;
int32_t dst_in_index;
string dst_node_name;
};

class ModelSerializeImp {
public:
bool SerializeModel(const Model &model, proto::ModelDef *modeProto);

bool SerializeGraph(const ConstComputeGraphPtr &graph, proto::GraphDef *graphProto);

bool SerializeEdge(const NodePtr &node, proto::OpDef *opDefProto);

bool SerializeOpDesc(const ConstOpDescPtr &node, proto::OpDef *opDefProto);

bool SerializeNode(const NodePtr &node, proto::OpDef *opDefProto);

bool SerializeTensor(const ConstGeTensorPtr &tensor, proto::TensorDef *tensorProto);

bool UnserializeModel(Model &model, proto::ModelDef &modeProto);

bool UnserializeGraphWithoutEdge(ComputeGraphPtr &graph, proto::GraphDef &graphProto);

bool UnserializeGraph(ComputeGraphPtr &graph, proto::GraphDef &graphProto);

bool HandleNodeNameRef();

bool UnserializeOpDesc(OpDescPtr &opDesc, proto::OpDef &opDefProto);

bool UnserializeNode(ComputeGraphPtr &graph, proto::OpDef &opDefProto);

bool UnserializeTensor(GeTensorPtr &tensor, proto::TensorDef &tensorProto);

bool ParseNodeIndex(const string &node_index, string &nodeName, int32_t &index);

void SetProtobufOwner(const ProtoMsgOwner &bufferProtobufOnwer) { protobuf_owner_ = bufferProtobufOnwer; }

private:
std::vector<NodeNameGraphReq> graph_input_node_names_;
std::vector<NodeNameGraphReq> graph_output_node_names_;
std::vector<NodeNameNodeReq> node_input_node_names_;
std::map<string, NodePtr> node_map_;
ProtoMsgOwner protobuf_owner_;
};
} // namespace ge

#endif // INC_GRAPH_DETAIL_MODEL_SERIALIZE_IMP_H_

+ 342
- 0
inc/graph/ge_attr_value.h View File

@@ -0,0 +1,342 @@
/**
* 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 INC_GRAPH_GE_ATTR_VALUE_H_
#define INC_GRAPH_GE_ATTR_VALUE_H_

#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "graph/buffer.h"
#include "detail/attributes_holder.h"
#include "graph/ge_error_codes.h"
#include "graph/ge_tensor.h"

using std::map;
using std::string;
using std::vector;

namespace ge {
class GeTensor;

using GeTensorPtr = std::shared_ptr<GeTensor>;
using ConstGeTensorPtr = std::shared_ptr<const GeTensor>;

class ComputeGraph;
using ComputeGraphPtr = std::shared_ptr<ComputeGraph>;
using ConstComputeGraphPtr = std::shared_ptr<const ComputeGraph>;

class GeTensorDesc;

class GeAttrValueImp;

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeAttrValue {
public:
class NamedAttrs : public AttrHolder {
public:
NamedAttrs();
virtual ~NamedAttrs() = default;
void SetName(const std::string &name);
string GetName() const;
GeAttrValue GetItem(const string &key) const;

protected:
ProtoAttrMapHelper MutableAttrMap() override;
ConstProtoAttrMapHelper GetAttrMap() const override;

private:
// Create namedAttrs from protobuf obj
NamedAttrs(const ProtoMsgOwner &owner, proto::NamedAttrs *protoMsg);
GeIrProtoHelper<proto::NamedAttrs> named_attrs_;
friend class GeAttrValueImp;
};

using INT = int64_t;
using FLOAT = float;
using BOOL = bool;
using STR = std::string;
using TENSOR = GeTensorPtr;
using TENSOR_DESC = GeTensorDesc;
using GRAPH = ComputeGraphPtr;
using BYTES = Buffer;
using NAMED_ATTRS = NamedAttrs;
using DATA_TYPE = ge::DataType;

using LIST_INT = vector<INT>;
using LIST_FLOAT = vector<FLOAT>;
using LIST_BOOL = vector<BOOL>;
using LIST_STR = vector<STR>;
using LIST_TENSOR = vector<TENSOR>;
using LIST_TENSOR_DESC = vector<TENSOR_DESC>;
using LIST_GRAPH = vector<GRAPH>;
using LIST_BYTES = vector<BYTES>;
using LIST_NAMED_ATTRS = vector<NAMED_ATTRS>;
using LIST_LIST_INT = vector<vector<int64_t>>;
using LIST_DATA_TYPE = vector<ge::DataType>;

enum ValueType {
VT_NONE = 0,
VT_STRING,
VT_FLOAT,
VT_BOOL,
VT_INT,
VT_TENSOR_DESC,
VT_TENSOR,
VT_BYTES,
VT_GRAPH,
VT_NAMED_ATTRS,
VT_LIST_LIST_INT,
VT_DATA_TYPE,

VT_LIST_BASE = 1000,
VT_LIST_STRING = VT_LIST_BASE + VT_STRING,
VT_LIST_FLOAT = VT_LIST_BASE + VT_FLOAT,
VT_LIST_BOOL = VT_LIST_BASE + VT_BOOL,
VT_LIST_INT = VT_LIST_BASE + VT_INT,
VT_LIST_TENSOR_DESC = VT_LIST_BASE + VT_TENSOR_DESC,
VT_LIST_TENSOR = VT_LIST_BASE + VT_TENSOR,
VT_LIST_BYTES = VT_LIST_BASE + VT_BYTES,
VT_LIST_GRAPH = VT_LIST_BASE + VT_GRAPH,
VT_LIST_NAMED_ATTRS = VT_LIST_BASE + VT_NAMED_ATTRS,
VT_LIST_DATA_TYPE = VT_LIST_BASE + VT_DATA_TYPE,
};

template <class T>
struct IsAttrTypeEnable {
using DT = typename std::remove_cv<T>::type;

static bool const VALUE = std::is_same<INT, DT>::value || std::is_same<FLOAT, DT>::value ||
std::is_same<BOOL, DT>::value || std::is_same<STR, DT>::value ||
std::is_same<GRAPH, DT>::value || std::is_same<TENSOR, DT>::value ||
std::is_same<TENSOR_DESC, DT>::value || std::is_same<BYTES, DT>::value ||
std::is_same<NAMED_ATTRS, DT>::value || std::is_same<DATA_TYPE, DT>::value;

// Not has list type of NamedAttrs
static bool const LIST_VALUE = std::is_same<LIST_INT, DT>::value || std::is_same<LIST_FLOAT, DT>::value ||
std::is_same<LIST_BOOL, DT>::value || std::is_same<LIST_STR, DT>::value ||
std::is_same<LIST_GRAPH, DT>::value || std::is_same<LIST_TENSOR, DT>::value ||
std::is_same<LIST_TENSOR_DESC, DT>::value || std::is_same<LIST_BYTES, DT>::value ||
std::is_same<LIST_NAMED_ATTRS, DT>::value ||
std::is_same<LIST_LIST_INT, DT>::value || std::is_same<LIST_DATA_TYPE, DT>::value;
};

template <typename vector_type>
// To cols
using enable_if_vector_type_valid_t = typename std::enable_if<IsAttrTypeEnable<vector_type>::LIST_VALUE,
int>::type;

template <typename one_type>
using enable_if_one_type_valid_t = typename std::enable_if<IsAttrTypeEnable<one_type>::VALUE, int>::type;

template <typename val_type>
using enable_if_type_valid_t =
typename std::enable_if<IsAttrTypeEnable<val_type>::VALUE || IsAttrTypeEnable<val_type>::LIST_VALUE, int>::type;

template <typename seriliable_type>
using enable_if_seriliable_type_valid_t = typename seriliable_type::__ge_serializable;

GeAttrValue();
~GeAttrValue() = default;
// SetValue, Set initializer_list
template <typename T, typename DT, enable_if_vector_type_valid_t<T> = 0>
graphStatus SetValue(std::initializer_list<DT> &&val) {
T vectorVal;
for (auto &item : val) {
vectorVal.push_back(item);
}
return SetValue(vectorVal);
}

// SetValue, Set vector
template <typename T, typename DT, enable_if_vector_type_valid_t<T> = 0>
graphStatus SetValue(const std::vector<DT> &val) {
T vectorVal;
for (auto item : val) {
vectorVal.push_back(item);
}
return SetValue(vectorVal);
}

// SetValue, not list type
template <typename T, typename DT, enable_if_one_type_valid_t<T> = 0>
graphStatus SetValue(DT &&val) {
return SetValue(T(std::forward<DT>(val)));
}

// GE_SERIALIZABLE
template <typename T, enable_if_seriliable_type_valid_t<T> = 0>
graphStatus SetValue(const T &t) {
return t.Save(*this);
}

template <typename T, enable_if_seriliable_type_valid_t<T> = 0>
graphStatus SetValue(const vector<T> &t) {
vector<NamedAttrs> attrs;
for (auto &item : t) {
GeAttrValue val;
item.Save(val);
NamedAttrs attrsItem;
(void)val.GetValue<NamedAttrs>(attrsItem);
attrs.push_back(attrsItem);
}
return SetValue(attrs);
}

// GetValue, list value
template <typename T, typename DT, enable_if_vector_type_valid_t<T> = 0,
typename std::enable_if<!std::is_same<DT, GeTensorPtr>::value, int>::type = 0>
graphStatus GetValue(std::vector<DT> &val) const {
T valGet;
val.clear();
auto status = GetValue(valGet);
if (status != GRAPH_SUCCESS) {
return status;
}
for (auto item : valGet) {
val.push_back(item);
}
return GRAPH_SUCCESS;
}

// GetValue, not list type
template <typename T, typename DT, enable_if_one_type_valid_t<T> = 0,
typename std::enable_if<!std::is_same<DT, GeTensorPtr>::value, int>::type = 0>
graphStatus GetValue(DT &val) const {
T valGet;
auto status = GetValue(valGet);
if (status != GRAPH_SUCCESS) {
return status;
}
val = DT(valGet);
return GRAPH_SUCCESS;
}

// GE_SERIALIZABLE
template <typename T, enable_if_seriliable_type_valid_t<T> = 0>
graphStatus GetValue(T &t) {
return t.Load(*this);
}

template <typename T, enable_if_seriliable_type_valid_t<T> = 0>
graphStatus GetValue(vector<T> &t) {
graphStatus status;
t.clear();
vector<NamedAttrs> attrs;
status = this->GetValue(attrs);
if (status != GRAPH_SUCCESS) {
return status;
}
for (auto &attr : attrs) {
T item;
GeAttrValue val;
(void)val.SetValue(attr);
status = item.Load(val);
if (status != GRAPH_SUCCESS) {
return status;
}
t.push_back(item);
}
return GRAPH_SUCCESS;
}

template <typename T, typename DT, enable_if_type_valid_t<T> = 0>
static GeAttrValue CreateFrom(DT &&val) {
GeAttrValue valRet;
(void)valRet.SetValue<T>(std::forward<DT>(val));
return valRet;
}

template <typename T, typename DT, enable_if_vector_type_valid_t<T> = 0>
static GeAttrValue CreateFrom(std::initializer_list<DT> &&val) {
GeAttrValue valRet;
(void)valRet.SetValue<T>(std::move(val));
return valRet;
}

template <typename T, enable_if_seriliable_type_valid_t<T> = 0>
static GeAttrValue CreateFrom(const T &val) {
GeAttrValue valRet;
(void)valRet.SetValue(val);
return valRet;
}

template <typename T, enable_if_seriliable_type_valid_t<T> = 0>
static GeAttrValue CreateFrom(const vector<T> &val) {
GeAttrValue valRet;
(void)valRet.SetValue(val);
return valRet;
}

ValueType GetValueType() const;

bool IsEmpty() const;

GeAttrValue Copy() const;

// For map key
bool operator==(const GeAttrValue &other) const { return value_ == other.value_; }

graphStatus MutableTensor(GeTensorPtr &tensor);
graphStatus MutableListTensor(vector<GeTensorPtr> &list_tensor);

private:
#define VALUE_SET_GET_DEC(DT) \
graphStatus SetValue(const DT &val); \
graphStatus GetValue(DT &val) const;
VALUE_SET_GET_DEC(GeAttrValue::STR)
VALUE_SET_GET_DEC(GeAttrValue::INT)
VALUE_SET_GET_DEC(GeAttrValue::FLOAT)
VALUE_SET_GET_DEC(GeAttrValue::BOOL)
VALUE_SET_GET_DEC(GeTensorDesc)
VALUE_SET_GET_DEC(GeAttrValue::TENSOR)
VALUE_SET_GET_DEC(GeAttrValue::GRAPH)
VALUE_SET_GET_DEC(BYTES)
VALUE_SET_GET_DEC(NamedAttrs)
VALUE_SET_GET_DEC(ge::DataType)
VALUE_SET_GET_DEC(vector<GeAttrValue::STR>)
VALUE_SET_GET_DEC(vector<GeAttrValue::INT>)
VALUE_SET_GET_DEC(vector<GeAttrValue::FLOAT>)
VALUE_SET_GET_DEC(vector<GeAttrValue::BOOL>)
VALUE_SET_GET_DEC(vector<GeTensorDesc>)
VALUE_SET_GET_DEC(vector<GeAttrValue::TENSOR>)
VALUE_SET_GET_DEC(vector<GeAttrValue::GRAPH>)
VALUE_SET_GET_DEC(vector<GeAttrValue::BYTES>)
VALUE_SET_GET_DEC(vector<NamedAttrs>)
VALUE_SET_GET_DEC(vector<vector<int64_t>>)
VALUE_SET_GET_DEC(vector<ge::DataType>)
#undef VALUE_SET_GET_DEC

GeIrProtoHelper<proto::AttrDef> value_;
GeAttrValue(const ProtoMsgOwner &proto_owner, ge::proto::AttrDef *val);

friend class AttrHolder;
friend class ModelSerializeImp;
friend class OnnxUtils;
};

class AttrValueImpl {
public:
AttrValueImpl() = default;
~AttrValueImpl() = default;

GeAttrValue geAttrValue_;
};
} // namespace ge
#endif // INC_GRAPH_GE_ATTR_VALUE_H_

+ 45
- 0
inc/graph/ge_context.h View File

@@ -0,0 +1,45 @@
/**
* 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 INC_GRAPH_GE_CONTEXT_H_
#define INC_GRAPH_GE_CONTEXT_H_

#include <string>

#include "graph/ge_error_codes.h"

namespace ge {
class GEContext {
public:
graphStatus GetOption(const std::string &key, std::string &option);
uint64_t SessionId();
uint32_t DeviceId();
uint64_t JobId();
void Init();
void SetCtxDeviceId(uint32_t device_id);

private:
uint64_t session_id_ = 0;
uint32_t device_id_ = 0;
uint64_t job_id_ = 0;
};

/// Get context
/// @return
GEContext &GetContext();
} // namespace ge

#endif // INC_GRAPH_GE_CONTEXT_H_

+ 26
- 0
inc/graph/ge_global_options.h View File

@@ -0,0 +1,26 @@
/**
* 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 INC_GRAPH_GE_GLOBAL_OPTIONS_H_
#define INC_GRAPH_GE_GLOBAL_OPTIONS_H_

#include <map>
#include <string>

namespace ge {
std::map<std::string, std::string> &GetMutableGlobalOptions();
}
#endif // INC_GRAPH_GE_GLOBAL_OPTIONS_H_

+ 44
- 0
inc/graph/ge_local_context.h View File

@@ -0,0 +1,44 @@
/**
* 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 INC_GRAPH_GE_LOCAL_CONTEXT_H_
#define INC_GRAPH_GE_LOCAL_CONTEXT_H_

#include <map>
#include <string>
#include <vector>

#include "graph/ge_error_codes.h"

using std::string;
using std::map;

namespace ge {
class GEThreadLocalContext {
public:
graphStatus GetOption(const string &key, string &option);
void SetGlobalOption(map<std::string, string> options_map);
void SetSessionOption(map<std::string, string> options_map);

private:
map<string, string> session_options_;
map<string, string> global_options_;
};

GEThreadLocalContext &GetThreadLocalContext();
} // namespace ge

#endif // INC_GRAPH_GE_LOCAL_CONTEXT_H_

+ 171
- 0
inc/graph/ge_tensor.h View File

@@ -0,0 +1,171 @@
/**
* 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 INC_GRAPH_GE_TENSOR_H_
#define INC_GRAPH_GE_TENSOR_H_

#include <atomic>
#include <memory>
#include <string>
#include <vector>

#include "detail/attributes_holder.h"
#include "graph/buffer.h"
#include "graph/ge_error_codes.h"
#include "graph/types.h"

namespace ge {
class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeShape {
public:
GeShape();
~GeShape() = default;
explicit GeShape(std::vector<int64_t> s);

size_t GetDimNum() const;
// If the idx is invalid, return 0
int64_t GetDim(size_t idx) const;
graphStatus SetDim(size_t idx, int64_t value);
std::vector<int64_t> GetDims() const;

int64_t GetShapeSize() const;
std::string ToString() const;

GeShape(const GeShape &other);
GeShape(GeShape &&other);
GeShape &operator=(const GeShape &other);
GeShape &operator=(GeShape &&other);

private:
GeIrProtoHelper<proto::ShapeDef> shape_def_;
friend class GeTensorDesc;
// Create geshape from proto obj
GeShape(const ProtoMsgOwner &protoOnwer, proto::ShapeDef *protoMsg);

void RefTo(const GeShape &shape) { shape_def_ = shape.shape_def_; }
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeTensorDesc : public AttrHolder {
friend class TensorUtils;
friend class GeAttrValue;
friend class ModelSerialize;

public:
GeTensorDesc();
explicit GeTensorDesc(GeShape shape, Format format = FORMAT_ND, DataType dt = DT_FLOAT);
GeTensorDesc(const GeTensorDesc &desc);
GeTensorDesc(GeTensorDesc &&desc);

~GeTensorDesc() = default;
bool operator==(const GeTensorDesc &r_ge_tensor_desc) const;

void Update(GeShape shape, Format format = FORMAT_ND, DataType dt = DT_FLOAT);

GeShape GetShape() const;
GeShape &MutableShape();
void SetShape(GeShape shape);

GeShape GetOriginShape() const;
void SetOriginShape(const GeShape &originShape);

Format GetFormat() const;
void SetFormat(Format format);

Format GetOriginFormat() const;
void SetOriginFormat(Format originFormat);

DataType GetDataType() const;
void SetDataType(DataType dt);

void SetOriginDataType(DataType originDataType);
DataType GetOriginDataType() const;

GeTensorDesc Clone() const;
GeTensorDesc &operator=(const GeTensorDesc &desc);
GeTensorDesc &operator=(GeTensorDesc &&desc);

graphStatus IsValid() const;

protected:
ProtoAttrMapHelper MutableAttrMap() override;
ConstProtoAttrMapHelper GetAttrMap() const override;

private:
bool GeTensorDescAttrsAreEqual(const GeTensorDesc &r_ge_tensor_desc) const;
using AttrHolder::DelAttr;
using AttrHolder::GetAllAttrs;
using AttrHolder::GetAttr;
using AttrHolder::HasAttr;
using AttrHolder::SetAttr;

void Init();

// Create getensordesc from proto obj
GeTensorDesc(const ProtoMsgOwner &protoOnwer, proto::TensorDescriptor *protoMsg);
friend class GeTensor;
friend class GeAttrValueImp;
friend class ModelSerializeImp;
friend class OnnxUtils;

GeIrProtoHelper<proto::TensorDescriptor> tensor_descriptor_;
// Reference from tensorDescriptor_, do not direct use
mutable GeShape __shape_;

void RefTo(const GeTensorDesc &tensorDesc) { tensor_descriptor_ = tensorDesc.tensor_descriptor_; }
GeShape &ShapeReference() const;
};

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeTensor {
public:
GeTensor();
explicit GeTensor(const GeTensorDesc &tensorDesc);
explicit GeTensor(const GeTensorDesc &tensorDesc, const std::vector<uint8_t> &data);
explicit GeTensor(const GeTensorDesc &tensorDesc, const Buffer &data);
explicit GeTensor(const GeTensorDesc &tensorDesc, const uint8_t *data, size_t size);
explicit GeTensor(GeTensorDesc &&tensorDesc, std::vector<uint8_t> &&data);
~GeTensor() = default;

GeTensorDesc GetTensorDesc() const;
GeTensorDesc &MutableTensorDesc();
void SetTensorDesc(const GeTensorDesc &tensorDesc);

const Buffer GetData() const;
Buffer MutableData();
graphStatus SetData(std::vector<uint8_t> &&data);
graphStatus SetData(const std::vector<uint8_t> &data);
graphStatus SetData(const Buffer &data);
graphStatus SetData(const uint8_t *data, size_t size);

GeTensor Clone() const;

// Share value
GeTensor(const GeTensor &other);
// Share value
GeTensor &operator=(const GeTensor &other);

private:
friend class GeAttrValueImp;
friend class ModelSerializeImp;
friend class OnnxUtils;
// Create getensor from proto obj
GeTensor(const ProtoMsgOwner &protoOnwer, proto::TensorDef *protoMsg);
GeIrProtoHelper<proto::TensorDef> tensor_def_;
// Reference from tensorDef_, cab not use it directly
mutable GeTensorDesc __desc_;
GeTensorDesc &DescReference() const;
};
} // namespace ge

#endif // INC_GRAPH_GE_TENSOR_H_

+ 134
- 0
inc/graph/graph_util.h View File

@@ -0,0 +1,134 @@
/**
* 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 INC_GRAPH_GRAPH_UTIL_H_
#define INC_GRAPH_GRAPH_UTIL_H_

#include <string>

#include "proto/om.pb.h"

namespace ge {
using AttrDefMap = ::google::protobuf::Map<::std::string, ::domi::AttrDef>;
bool HasOpAttr(const OpDef *opdef, std::string attr_name);
bool GetOpAttr(const std::string &key, int32_t *value, const OpDef *opdef);

static const char OP_TYPE_DATA[] = "Data";
static const char OP_TYPE_INPUT[] = "Input";
static const char ATTR_KEY_INPUT_FORMAT[] = "input_format";
static const char ATTR_KEY_OUTPUT_FORMAT[] = "output_format";
static const char OP_TYPE_ANN_DATA[] = "AnnData";
} // namespace ge

#if !defined(__ANDROID__) && !defined(ANDROID)
#include "toolchain/slog.h"
const char levelStr[4][8] = {"ERROR", "WARN", "INFO", "DEBUG"};
#else
#include <syslog.h>
#include <utils/Log.h>
const char levelStr[8][8] = {"EMERG", "ALERT", "CRIT", "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG"};
#endif

#ifdef _MSC_VER
#define FUNC_NAME __FUNCTION__
#else
#define FUNC_NAME __PRETTY_FUNCTION__
#endif

#if !defined(__ANDROID__) && !defined(ANDROID)
#define D_GRAPH_LOGI(MOD_NAME, fmt, ...) \
dlog_info(FMK, "%s:%s:%d:" #fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
#define D_GRAPH_LOGW(MOD_NAME, fmt, ...) \
dlog_warn(FMK, "%s:%s:%d:" #fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
#define D_GRAPH_LOGE(MOD_NAME, fmt, ...) \
dlog_error(FMK, "%s:%s:%d:" #fmt, __FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__)
#else
#define D_GRAPH_LOG(level, format, ...) \
do { \
{ \
fprintf(stdout, "[%s] [%s] [%s] [%s] [%s:%d] " format "\n", "", "GRAPH", levelStr[level], __FUNCTION__, \
__FILE__, __LINE__, ##__VA_ARGS__); \
syslog(level, "%s %s:%d] [%s] %s " format "\n", "", __FILE__, __LINE__, "OPTIMIZER", __FUNCTION__, \
##__VA_ARGS__); \
} \
} while (0)
#define D_GRAPH_LOGI(MOD_NAME, fmt, ...) D_GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
#define D_GRAPH_LOGW(MOD_NAME, fmt, ...) D_GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
#define D_GRAPH_LOGE(MOD_NAME, fmt, ...) D_GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
#endif

#if !defined(__ANDROID__) && !defined(ANDROID)
#define GRAPH_LOGI(...) D_GRAPH_LOGI(GRAPH_MOD_NAME, __VA_ARGS__)
#define GRAPH_LOGW(...) D_GRAPH_LOGW(GRAPH_MOD_NAME, __VA_ARGS__)
#define GRAPH_LOGE(...) D_GRAPH_LOGE(GRAPH_MOD_NAME, __VA_ARGS__)
#else

#define GRAPH_LOG(level, format, ...) \
do { \
{ \
fprintf(stdout, "[%s] [%s] [%s] [%s] [%s:%d] " format "\n", "", "GRAPH", levelStr[level], __FUNCTION__, \
__FILE__, __LINE__, ##__VA_ARGS__); \
syslog(level, "%s %s:%d] [%s] %s " format "\n", "", __FILE__, __LINE__, "OPTIMIZER", __FUNCTION__, \
##__VA_ARGS__); \
} \
} while (0)
#define GRAPH_LOGI(fmt, ...) GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
#define GRAPH_LOGW(fmt, ...) GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
#define GRAPH_LOGE(fmt, ...) GRAPH_LOG(ANDROID_LOG_INFO, #fmt, ##__VA_ARGS__)
#endif

#define GRAPH_CHK_STATUS_RET_NOLOG(expr) \
do { \
const domi::graphStatus _status = (expr); \
if (_status != domi::GRAPH_SUCCESS) { \
return _status; \
} \
} while (0)

#define GRAPH_CHK_BOOL_RET_STATUS(expr, _status, ...) \
do { \
bool b = (expr); \
if (!b) { \
GRAPH_LOGE(__VA_ARGS__); \
return _status; \
} \
} while (0)

#define GRAPH_CHK_BOOL_EXEC_NOLOG(expr, exec_expr) \
{ \
bool b = (expr); \
if (!b) { \
exec_expr; \
} \
};

#define GRAPH_IF_BOOL_EXEC(expr, exec_expr) \
{ \
if (expr) { \
exec_expr; \
} \
}

#define GRAPH_RETURN_WITH_LOG_IF_ERROR(expr, ...) \
do { \
const ::domi::graphStatus _status = (expr); \
if (_status) { \
GRAPH_LOGE(__VA_ARGS__); \
return _status; \
} \
} while (0)

#endif // INC_GRAPH_GRAPH_UTIL_H_

+ 95
- 0
inc/graph/model.h View File

@@ -0,0 +1,95 @@
/**
* 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 INC_GRAPH_MODEL_H_
#define INC_GRAPH_MODEL_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "detail/attributes_holder.h"
#include "graph/ge_attr_value.h"
#include "graph/graph.h"

namespace ge {
using std::map;
using std::string;
using std::vector;

class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Model : public AttrHolder {
public:
Model();

~Model() = default;

Model(const string &name, const string &custom_version);

string GetName() const;
void SetName(const string &name);

uint32_t GetVersion() const;

void SetVersion(uint32_t version) { version_ = version; }

std::string GetPlatformVersion() const;

void SetPlatformVersion(string version) { platform_version_ = version; }

Graph GetGraph() const;

void SetGraph(const Graph &graph);

void SetAttr(const ProtoAttrMapHelper &attrs);

using AttrHolder::GetAllAttrNames;
using AttrHolder::GetAllAttrs;
using AttrHolder::GetAttr;
using AttrHolder::HasAttr;
using AttrHolder::SetAttr;

graphStatus Save(Buffer &buffer) const;

graphStatus SaveToFile(const string &file_name) const;
// Model will be rewritten
static graphStatus Load(const uint8_t *data, size_t len, Model &model);
graphStatus Load(ge::proto::ModelDef &model_def);
graphStatus LoadFromFile(const string &file_name);

bool IsValid() const;

protected:
ConstProtoAttrMapHelper GetAttrMap() const override;
ProtoAttrMapHelper MutableAttrMap() override;

private:
void Init();
ProtoAttrMapHelper attrs_;
friend class ModelSerializeImp;
friend class GraphDebugImp;
friend class OnnxUtils;
friend class ModelHelper;
friend class ModelBuilder;
string name_;
uint32_t version_;
std::string platform_version_{""};
Graph graph_;
};
} // namespace ge
using ModelPtr = std::shared_ptr<ge::Model>;

#endif // INC_GRAPH_MODEL_H_

+ 54
- 0
inc/graph/model_serialize.h View File

@@ -0,0 +1,54 @@
/**
* 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 INC_GRAPH_MODEL_SERIALIZE_H_
#define INC_GRAPH_MODEL_SERIALIZE_H_

#include <map>
#include <string>

#include "graph/buffer.h"
#include "graph/compute_graph.h"
#include "graph/model.h"

namespace ge {
class ModelSerialize {
public:
Buffer SerializeModel(const Model &model);

Model UnserializeModel(const uint8_t *data, size_t len);
Model UnserializeModel(ge::proto::ModelDef &model_def);

Buffer SerializeGraph(const ComputeGraphPtr &graph);

ComputeGraphPtr UnserializeGraph(const uint8_t *data, size_t len);

Buffer SerializeOpDesc(const ConstOpDescPtr &opDesc);
OpDescPtr UnserializeOpDesc(const uint8_t *data, size_t len);

size_t GetSerializeModelSize(const Model &model);

private:
static std::map<std::string, GeAttrValue> &MutableTensorDescAttrMap(GeTensorDesc &tensorDesc);

static const std::map<std::string, GeAttrValue> &GetTensorDescAttrMap(const GeTensorDesc &tensorDesc);

friend class ModelSerializeImp;
friend class GraphDebugImp;
};
} // namespace ge

#endif // INC_GRAPH_MODEL_SERIALIZE_H_

+ 208
- 0
inc/graph/node.h View File

@@ -0,0 +1,208 @@
/**
* 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 INC_GRAPH_NODE_H_
#define INC_GRAPH_NODE_H_

#include <map>
#include <memory>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>

#include "graph/ge_attr_value.h"
#include "graph/op_desc.h"
#include "graph/range_vistor.h"
#include "utils/attr_utils.h"

namespace ge {
class ComputeGraph;

using ComputeGraphPtr = std::shared_ptr<ComputeGraph>;

class Node;

using NodePtr = std::shared_ptr<Node>;
using ConstNodePtr = std::shared_ptr<const Node>;
using NodeRef = std::weak_ptr<Node>;

class Anchor;

using AnchorPtr = std::shared_ptr<Anchor>;

class InDataAnchor;

using InDataAnchorPtr = std::shared_ptr<InDataAnchor>;

class OutDataAnchor;

using OutDataAnchorPtr = std::shared_ptr<OutDataAnchor>;

class ControlAnchor;

using ControlAnchorPtr = std::shared_ptr<ControlAnchor>;

class InControlAnchor;

using InControlAnchorPtr = std::shared_ptr<InControlAnchor>;

class OutControlAnchor;

using OutControlAnchorPtr = std::shared_ptr<OutControlAnchor>;

using OpDescPtr = std::shared_ptr<OpDesc>;

using ConstNode = const Node;

typedef std::vector<std::multimap<std::string, ge::AnchorPtr>> kFusionDataFlowVec_t;

// Node is a component of ComputeGraph
class Node : public std::enable_shared_from_this<Node> {
friend class ComputeGraph;
friend class ModelSerializeImp;

public:
template <class T>
using Vistor = RangeVistor<T, std::shared_ptr<ConstNode>>;
~Node();
Node(const Node &) = delete;
Node &operator=(const Node &) = delete;
bool operator==(const Node &r_node) const;

protected:
Node() = default;
Node(const OpDescPtr &op, const ComputeGraphPtr &ownerGraph);

public:
graphStatus Init();

std::string GetName() const;
std::string GetType() const;

ComputeGraphPtr GetOwnerComputeGraph() const;
graphStatus SetOwnerComputeGraph(const ComputeGraphPtr &graph);

Vistor<InDataAnchorPtr> GetAllInDataAnchors() const;
Vistor<OutDataAnchorPtr> GetAllOutDataAnchors() const;
uint32_t GetAllInDataAnchorsSize() const;
uint32_t GetAllOutDataAnchorsSize() const;
Vistor<AnchorPtr> GetAllOutAnchors() const;
Vistor<AnchorPtr> GetAllInAnchors() const;
InDataAnchorPtr GetInDataAnchor(int idx) const;
OutDataAnchorPtr GetOutDataAnchor(int idx) const;
InControlAnchorPtr GetInControlAnchor() const;
OutControlAnchorPtr GetOutControlAnchor() const;
Vistor<NodePtr> GetInNodes() const;
Vistor<NodePtr> GetOutNodes() const;
AnchorPtr GetInAnchor(int idx) const;
AnchorPtr GetOutAnchor(int idx) const;

bool IsAllInNodesSeen(std::unordered_set<Node *> &nodes_seen) const;

// All inData nodes
Vistor<NodePtr> GetInDataNodes() const;
// All inControl nodes
Vistor<NodePtr> GetInControlNodes() const;
// GetInAllNodes = InDataNodes + InControlNodes
Vistor<NodePtr> GetInAllNodes() const;

// All outData nodes
Vistor<NodePtr> GetOutDataNodes() const;
uint32_t GetOutDataNodesSize() const;
// All outControl nodes
Vistor<NodePtr> GetOutControlNodes() const;
// GetOutAllNodes = OutDataNodes + InControlNodes
Vistor<NodePtr> GetOutAllNodes() const;

// Get all indata nodes and its outanchor
Vistor<std::pair<NodePtr, OutDataAnchorPtr>> GetInDataNodesAndAnchors() const;

// Get all outdata nodes and its inanchor
Vistor<std::pair<NodePtr, InDataAnchorPtr>> GetOutDataNodesAndAnchors() const;

graphStatus InferShapeAndType() const;
graphStatus Verify() const;

graphStatus InferOriginFormat() const;

OpDescPtr GetOpDesc() const;

graphStatus UpdateOpDesc(const OpDescPtr &op);

graphStatus AddLinkFrom(const NodePtr &input_node);

graphStatus AddLinkFrom(const uint32_t &index, NodePtr input_node);

graphStatus AddLinkFrom(const string &name, NodePtr input_node);

graphStatus AddLinkFromForParse(const NodePtr &input_node);

void AddSendEventId(uint32_t event_id) { send_event_id_list_.push_back(event_id); }

void AddRecvEventId(uint32_t event_id) { recv_event_id_list_.push_back(event_id); }

const std::vector<uint32_t> &GetSendEventIdList() const { return send_event_id_list_; }

const std::vector<uint32_t> &GetRecvEventIdList() const { return recv_event_id_list_; }
void GetFusionInputFlowList(kFusionDataFlowVec_t &fusion_input_list) {
fusion_input_list = fusion_input_dataflow_list_;
}

void GetFusionOutputFlowList(kFusionDataFlowVec_t &fusion_output_list) {
fusion_output_list = fusion_output_dataflow_list_;
}

void SetFusionInputFlowList(kFusionDataFlowVec_t &fusion_input_list) {
fusion_input_dataflow_list_ = fusion_input_list;
}

void SetFusionOutputFlowList(kFusionDataFlowVec_t &fusion_output_list) {
fusion_output_dataflow_list_ = fusion_output_list;
}

void SetOrigNode(const NodePtr &orignode) { orig_node_ = orignode; }

NodePtr GetOrigNode(void) { return orig_node_; }

private:
bool NodeMembersAreEqual(const Node &r_node) const;
bool NodeAttrsAreEqual(const Node &r_node) const;
bool NodeInConnectsAreEqual(const Node &r_node) const;
bool NodeOutConnectsAreEqual(const Node &r_node) const;
bool NodeAnchorIsEqual(const AnchorPtr &l_anchor, const AnchorPtr &r_anchor, size_t i) const;
OpDescPtr op_;
std::weak_ptr<ComputeGraph> owner_graph_;
vector<InDataAnchorPtr> in_data_anchors_;
vector<OutDataAnchorPtr> out_data_anchors_;
InControlAnchorPtr in_control_anchor_;
OutControlAnchorPtr out_control_anchor_;
map<string, GeAttrValue> attrs_;
bool has_init_{false};
bool anchor_status_updated_{false};
std::vector<uint32_t> send_event_id_list_;
std::vector<uint32_t> recv_event_id_list_;

kFusionDataFlowVec_t fusion_input_dataflow_list_;
kFusionDataFlowVec_t fusion_output_dataflow_list_;

NodePtr orig_node_;
friend class NodeUtils;
friend class OnnxUtils;
};
} // namespace ge

#endif // INC_GRAPH_NODE_H_

+ 256
- 0
inc/graph/op_desc.h View File

@@ -0,0 +1,256 @@
/**
* 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 INC_GRAPH_OP_DESC_H_
#define INC_GRAPH_OP_DESC_H_

#include <functional>
#include <map>
#include <memory>
#include <string>
#include <unordered_set>
#include <vector>

#include "detail/attributes_holder.h"
#include "graph/range_vistor.h"

#define DYNAMIN_INPUT_NAME(name, index) (((name)) + std::to_string((index)))
#define DYNAMIN_OUTPUT_NAME(name, index) (((name)) + std::to_string((index)))
namespace ge {
using std::map;
using std::pair;
using std::shared_ptr;
using std::string;
using std::vector;

class Operator;
class GeTensorDesc;

using GeTensorDescPtr = shared_ptr<GeTensorDesc>;
using ConstGeTensorDescPtr = shared_ptr<const GeTensorDesc>;

class OpDesc;

using OpDescPtr = shared_ptr<OpDesc>;
using ConstOpDescPtr = shared_ptr<const OpDesc>;

class GeAttrValue;

using ConstOpDesc = const OpDesc;

class OpDesc : public std::enable_shared_from_this<OpDesc>, public AttrHolder {
public:
template <class T>
using Vistor = RangeVistor<T, shared_ptr<ConstOpDesc>>;

friend class GraphBuilderImpl;

friend class OperatorImpl;

OpDesc(const string &name, const string &type);

OpDesc();

~OpDesc();

bool operator==(const OpDesc &r_op_desc) const;

string GetName() const;

void SetName(const string &name);

string GetType() const;

void SetType(const string &type);

graphStatus AddInputDesc(const GeTensorDesc &input_desc);

graphStatus AddInputDesc(const string &name, const GeTensorDesc &input_desc);

graphStatus AddInputDesc(uint32_t index, const ge::GeTensorDesc &input_desc);

graphStatus AddInputDescForward(const string &name, const unsigned int num);

graphStatus AddOutputDescForward(const string &name, const unsigned int num);

graphStatus AddOptionalInputDesc(const string &name, const GeTensorDesc &input_desc);

graphStatus UpdateInputDesc(uint32_t index, const GeTensorDesc &tensor_desc);

graphStatus UpdateInputDesc(const string &name, const GeTensorDesc &tensor_desc);

bool InputIsSet(const string &name) const;

GeTensorDesc GetInputDesc(uint32_t index) const;

GeTensorDesc GetInputDesc(const string &name) const;

Vistor<string> GetAllInputNames() const;

GeTensorDescPtr MutableInputDesc(uint32_t index) const;

Vistor<GeTensorDesc> GetAllInputsDesc() const;

Vistor<GeTensorDescPtr> GetAllInputsDescPtr() const;

size_t GetInputsSize() const;

graphStatus AddOutputDesc(const GeTensorDesc &output_desc);

graphStatus AddOutputDesc(const string &name, const GeTensorDesc &output_desc);

graphStatus UpdateOutputDesc(uint32_t index, const GeTensorDesc &tensor_desc);

graphStatus UpdateOutputDesc(const string &name, const GeTensorDesc &tensor_desc);

GeTensorDesc GetOutputDesc(uint32_t index) const;

GeTensorDesc GetOutputDesc(const string &name) const;

GeTensorDescPtr MutableOutputDesc(uint32_t index) const;

Vistor<GeTensorDesc> GetAllOutputsDesc() const;

Vistor<GeTensorDescPtr> GetAllOutputsDescPtr() const;

size_t GetOutputsSize() const;

ConstGeTensorDescPtr GetOutputDescPtr(uint32_t index) const;

ConstGeTensorDescPtr GetInputDescPtr(uint32_t index) const;

graphStatus AddDynamicInputDesc(const string &name, const unsigned int num, bool isPushBack = true);

graphStatus AddDynamicOutputDesc(const string &name, const unsigned int num, bool isPushBack = true);

bool IsOptionalInput(const string &name) const;

bool IsOptionalInput(uint32_t index) const;

std::map<string, uint32_t> GetAllInputName();

std::map<string, uint32_t> GetAllOutputName();

bool UpdateInputName(std::map<string, uint32_t> inputNameIdx);

bool UpdateOutputName(std::map<string, uint32_t> outputNameIdx);

void AddInferFunc(const std::function<graphStatus(Operator &)> &func);

std::function<graphStatus(Operator &)> GetInferFunc() const;

graphStatus InferShapeAndType();

void AddInferFormatFunc(const std::function<graphStatus(Operator &)> &func);

std::function<graphStatus(Operator &)> GetInferFormatFunc() const;

graphStatus DefaultInferFormat();

std::function<graphStatus(Operator &)> GetVerifyFunc() const;

void AddVerifierFunc(const std::function<graphStatus(Operator &)> &func);

graphStatus CallInferFormatFunc(Operator &op);

graphStatus OpVerify();

graphStatus CommonVerify() const;

using AttrHolder::AddRequiredAttr;
using AttrHolder::DelAttr;
using AttrHolder::GetAllAttrNames;
using AttrHolder::GetAllAttrs;
using AttrHolder::GetAttr;
using AttrHolder::HasAttr;
using AttrHolder::SetAttr;

void SetId(int64_t id);
int64_t GetId() const;
void SetStreamId(int64_t stream_id);
int64_t GetStreamId() const;
void SetInputName(const vector<string> &input_name);
vector<string> GetInputName() const;
void SetSrcName(const vector<string> &src_name);
vector<string> GetSrcName() const;
void SetSrcIndex(const vector<int64_t> &src_index);
vector<int64_t> GetSrcIndex() const;
void SetInputOffset(const vector<int64_t> &input);
vector<int64_t> GetInputOffset() const;
void SetOutputOffset(const vector<int64_t> &input);
vector<int64_t> GetOutputOffset() const;
void SetDstName(const vector<string> &dst_name);
vector<string> GetDstName() const;
void SetDstIndex(const vector<int64_t> &dst_index);
vector<int64_t> GetDstIndex() const;
void SetWorkspace(const vector<int64_t> &workspace);
vector<int64_t> GetWorkspace() const;
void SetWorkspaceBytes(const vector<int64_t> &workspace_bytes);
vector<int64_t> GetWorkspaceBytes() const;
void SetIsInputConst(const vector<bool> &is_input_const);
vector<bool> GetIsInputConst() const;

string GetInputNameByIndex(uint32_t index) const;

int GetInputIndexByName(const string &name) const;

string GetOutputNameByIndex(uint32_t index) const;

int GetOutputIndexByName(const string &name) const;

graphStatus RestoreInputNameIdx(const string &name, const int &index);

graphStatus RestoreOutputNameIdx(const string &name, const int &index);

graphStatus CallInferFunc(Operator &op);

void SetOpKernelLibName(const std::string &name);

std::string GetOpKernelLibName() const;

void SetOpEngineName(const std::string &name);

std::string GetOpEngineName() const;

protected:
ProtoAttrMapHelper MutableAttrMap() override;
ConstProtoAttrMapHelper GetAttrMap() const override;

private:
OpDesc(const ProtoMsgOwner &proto_msg_owner, ge::proto::OpDef *op_def);
bool OpDescMembersAreEqual(const OpDesc &r_op_desc) const;
bool OpDescAttrsAreEqual(const OpDesc &r_op_desc) const;
bool OpDescGenTensorDescsAreEqual(const OpDesc &r_op_desc) const;

GeIrProtoHelper<ge::proto::OpDef> op_def_;
vector<GeTensorDescPtr> inputs_desc_{};
map<string, uint32_t> input_name_idx_{};
std::unordered_set<string> optional_input_names_{};
vector<GeTensorDescPtr> outputs_desc_{};
map<string, uint32_t> output_name_idx_{};
std::function<graphStatus(Operator &)> infer_func_ = nullptr;
std::function<graphStatus(Operator &)> infer_format_func_ = nullptr;
std::function<graphStatus(Operator &)> verifier_func_ = nullptr;
string op_kernel_lib_name_;
string engine_name_;
friend class OpDescUtils;
friend class ModelSerializeImp;
friend class AttrUtils;
friend class GeAttrValueImp;
friend class OnnxUtils;
};
} // namespace ge
#endif // INC_GRAPH_OP_DESC_H_

+ 47
- 0
inc/graph/op_kernel_bin.h View File

@@ -0,0 +1,47 @@
/**
* 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 INC_GRAPH_OP_KERNEL_BIN_H_
#define INC_GRAPH_OP_KERNEL_BIN_H_

#include <memory>
#include <string>
#include <utility>
#include <vector>

namespace ge {
class OpKernelBin {
public:
OpKernelBin(std::string name, std::vector<char> &&data) : name_(std::move(name)), data_(std::move(data)) {}

~OpKernelBin() = default;

const std::string &GetName() const { return name_; }
const uint8_t *GetBinData() const { return (const uint8_t *)data_.data(); }
size_t GetBinDataSize() const { return data_.size(); }
OpKernelBin(const OpKernelBin &) = delete;
const OpKernelBin &operator=(const OpKernelBin &) = delete;

private:
std::string name_;
std::vector<char> data_;
};

using OpKernelBinPtr = std::shared_ptr<OpKernelBin>;
const char *const OP_EXTATTR_NAME_TBE_KERNEL = "tbeKernel";
} // namespace ge

#endif // INC_GRAPH_OP_KERNEL_BIN_H_

+ 58
- 0
inc/graph/operator_factory_impl.h View File

@@ -0,0 +1,58 @@
/**
* 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 INC_GRAPH_OPERATOR_FACTORY_IMPL_H_
#define INC_GRAPH_OPERATOR_FACTORY_IMPL_H_

#include <map>
#include <memory>
#include <string>
#include <vector>

#include "graph/operator_factory.h"

namespace ge {
class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OperatorFactoryImpl {
public:
static Operator CreateOperator(const std::string &operator_name, const std::string &operator_type);

static graphStatus GetOpsTypeList(std::vector<std::string> &all_ops);

static bool IsExistOp(const string &operator_type);

static InferShapeFunc GetInferShapeFunc(const std::string &operator_type);

static InferFormatFunc GetInferFormatFunc(const std::string &operator_type);

static VerifyFunc GetVerifyFunc(const std::string &operator_type);

static graphStatus RegisterOperatorCreator(const std::string &operator_type, OpCreator const &op_creator);

static graphStatus RegisterInferShapeFunc(const std::string &operator_type, InferShapeFunc const infer_shape_func);

static graphStatus RegisterInferFormatFunc(const std::string &operator_type, InferFormatFunc const infer_format_func);

static graphStatus RegisterVerifyFunc(const std::string &operator_type, VerifyFunc const verify_func);

private:
static shared_ptr<std::map<string, OpCreator>> operator_creators_;
static shared_ptr<std::map<string, InferShapeFunc>> operator_infershape_funcs_;
static shared_ptr<std::map<string, InferFormatFunc>> operator_inferformat_funcs_;
static shared_ptr<std::map<string, VerifyFunc>> operator_verify_funcs_;
};
} // namespace ge

#endif // INC_GRAPH_OPERATOR_FACTORY_IMPL_H_

+ 44
- 0
inc/graph/opsproto_manager.h View File

@@ -0,0 +1,44 @@
/**
* 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 INC_GRAPH_OPSPROTO_MANAGER_H_
#define INC_GRAPH_OPSPROTO_MANAGER_H_

#include <dirent.h>
#include <dlfcn.h>
#include <string.h>
#include <map>
#include <string>
#include <vector>

namespace ge {
class OpsProtoManager {
public:
static OpsProtoManager *Instance();

bool Initialize(const std::map<std::string, std::string> &options);

void Finalize();

void LoadOpsProtoPluginSo(std::string &path);

private:
std::string pluginPath_;
std::vector<void *> handles_;
};
} // namespace ge

#endif // INC_GRAPH_OPSPROTO_MANAGER_H_

+ 53
- 0
inc/graph/range_vistor.h View File

@@ -0,0 +1,53 @@
/**
* 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 INC_GRAPH_RANGE_VISTOR_H_
#define INC_GRAPH_RANGE_VISTOR_H_

#include <vector>

template <class E, class O>
class RangeVistor {
public:
using Iterator = typename std::vector<E>::iterator;
using ConstIterator = typename std::vector<E>::const_iterator;

RangeVistor(O owner, const std::vector<E> &vs) : owner_(owner), elements_(vs) {}

~RangeVistor() {}

Iterator begin() { return elements_.begin(); }

Iterator end() { return elements_.end(); }

ConstIterator begin() const { return elements_.begin(); }

ConstIterator end() const { return elements_.end(); }

std::size_t size() const { return elements_.size(); }

bool empty() const { return elements_.empty(); }

E &at(std::size_t index) { return elements_.at(index); }

const E &at(std::size_t index) const { return elements_.at(index); }

private:
O owner_;
std::vector<E> elements_;
};

#endif // INC_GRAPH_RANGE_VISTOR_H_

+ 37
- 0
inc/graph/shape_refiner.h View File

@@ -0,0 +1,37 @@
/**
* 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 INC_GRAPH_SHAPE_REFINER_H_
#define INC_GRAPH_SHAPE_REFINER_H_

#include <string>

#include "external/graph/inference_context.h"
#include "external/graph/ge_error_codes.h"
#include "graph/node.h"

namespace ge {
// ShapeRefiner performs shape inference for compute graphs
class ShapeRefiner {
public:
static graphStatus InferShapeAndType(const ConstNodePtr &node, Operator &op);
static graphStatus InferShapeAndType(const NodePtr &node);

private:
static void PrintInOutTensorShape(const ge::NodePtr &node, const std::string &phase);
};
} // namespace ge
#endif // INC_GRAPH_SHAPE_REFINER_H_

+ 45
- 0
inc/graph/utils/anchor_utils.h View File

@@ -0,0 +1,45 @@
/**
* 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 INC_GRAPH_UTILS_ANCHOR_UTILS_H_
#define INC_GRAPH_UTILS_ANCHOR_UTILS_H_

#include "graph/anchor.h"
#include "graph/node.h"

namespace ge {
class AnchorUtils {
public:
// Get anchor format
static Format GetFormat(const DataAnchorPtr &dataAnchor);

// Set anchor format
static graphStatus SetFormat(const DataAnchorPtr &dataAnchor, Format dataFormat);

// Get anchor status
static AnchorStatus GetStatus(const DataAnchorPtr &dataAnchor);

// Set anchor status
static graphStatus SetStatus(const DataAnchorPtr &dataAnchor, AnchorStatus anchorStatus);

static bool HasControlEdge(const AnchorPtr &anchor);

static bool IsControlEdge(const AnchorPtr &src, const AnchorPtr &dst);

static int GetIdx(const AnchorPtr &anchor);
};
} // namespace ge
#endif // INC_GRAPH_UTILS_ANCHOR_UTILS_H_

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save