@@ -16,8 +16,11 @@ endif() | |||
if(DEFINED ENV{D_PKG_SERVER}) | |||
set(GE_PB_PKG $ENV{D_PKG_SERVER}) | |||
message("Download packages from PKG server") | |||
endif() | |||
message("Download packages from DPKG server") | |||
elseif(DEFINED ENV{MSLIBS_SERVER}) | |||
set(GE_PB_PKG "http://$ENV{MSLIBS_SERVER}:8081") | |||
message("Download packages from MSPKG server") | |||
endif () | |||
set(ASCEND_DRIVER_DIR ${ASCEND_DIR}/driver/lib64) | |||
set(ASCEND_DRIVER_COMMON_DIR ${ASCEND_DIR}/driver/lib64/common) | |||
@@ -37,7 +40,7 @@ set(ATLAS_MS_RUNTIME_PATH ${ATLAS_RUNTIME_DIR} ${ATLAS_ACL_DIR} ${ATLAS_ATC_DIR} | |||
option(ENABLE_OPEN_SRC "Enable graphengine compile in opensource." FALSE) | |||
if (ENABLE_OPEN_SRC) | |||
set(HI_PYTHON python3.7) | |||
set(HI_PYTHON python3) | |||
include(cmake/external_libs/protobuf_shared.cmake) | |||
include(cmake/external_libs/protobuf_static.cmake) | |||
@@ -71,7 +74,7 @@ if (ENABLE_OPEN_SRC) | |||
set(STATIC_ACL_LIB ${GE_LIB_PATH}) | |||
find_module(slog libslog.so ${GE_LIB_PATH}) | |||
find_module(static_mmpa libmmpa.a ${GE_LIB_PATH}) | |||
find_module(msprof libmsprof.so ${GE_LIB_PATH}) | |||
find_module(msprofiler libmsprofiler.a ${GE_LIB_PATH}) | |||
find_module(hccl libhccl.so ${GE_LIB_PATH}) | |||
find_module(adump_server libadump_server.a ${GE_LIB_PATH}) | |||
find_module(runtime libruntime.so ${GE_LIB_PATH}) | |||
@@ -80,20 +83,19 @@ if (ENABLE_OPEN_SRC) | |||
find_module(error_manager liberror_manager.so ${GE_LIB_PATH}) | |||
find_module(ascend_hal_stub libascend_hal.so ${GE_LIB_PATH}) | |||
find_module(error_manager_static liberror_manager.a ${GE_LIB_PATH}) | |||
find_module(msprofiler libmsprofiler.a ${GE_LIB_PATH}) | |||
find_module(msprofiler_fwk libmsprofiler_fwk.a ${GE_LIB_PATH}) | |||
#find_module(ascendcl_static libascendcl.a ${GE_LIB_PATH}) | |||
else() | |||
find_module(slog libslog.so ${ASCEND_ATC_DIR} ${ASCEND_DRIVER_COMMON_DIR}) | |||
find_module(static_mmpa libmmpa.a ${ASCEND_ATC_DIR} ${ASCEND_RUNTIME_DIR}) | |||
find_module(error_manager liberror_manager.so ${ASCEND_ATC_DIR} ${ASCEND_RUNTIME_DIR}) | |||
if(PLATFORM STREQUAL "train") | |||
find_module(msprof libmsprof.so ${ASCEND_DRIVER_COMMON_DIR}) | |||
find_module(hccl libhccl.so ${ASCEND_RUNTIME_DIR}) | |||
find_module(adump_server libadump_server.a ${ASCEND_RUNTIME_DIR}) | |||
find_module(runtime libruntime.so ${ASCEND_RUNTIME_DIR}) | |||
find_module(resource libresource.so ${ASCEND_RUNTIME_DIR}) | |||
find_module(error_manager liberror_manager.so ${ASCEND_RUNTIME_DIR}) | |||
find_module(msprofiler libmsprofiler.a ${ASCEND_RUNTIME_DIR}) | |||
find_module(msprofiler_fwk libmsprofiler_fwk.a ${ASCEND_RUNTIME_DIR}) | |||
find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}/driver) | |||
if(PRODUCT STREQUAL "flr3") | |||
message(FATAL_ERROR "This platform is not supported in train mode, build terminated") | |||
@@ -106,20 +108,17 @@ if (ENABLE_OPEN_SRC) | |||
find_module(error_manager liberror_manager.so ${ASCEND_ATC_DIR}) | |||
find_module(error_manager_static liberror_manager.a ${ASCEND_ACL_DIR}) | |||
find_module(msprofiler libmsprofiler.a ${ASCEND_ACL_DIR}) | |||
#find_module(ascendcl_static libascendcl.a ${ASCEND_ACL_DIR}) | |||
#find_module(ascendcl_static libascendcl.a ${ASCEND_ACL_DIR}) | |||
if(PRODUCT STREQUAL "flr3") | |||
find_module(msprof libmsprof.so ${ASCEND_DRIVER_SHARE_DIR}) | |||
elseif(PRODUCT STREQUAL "flr1") | |||
find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}/driver) | |||
find_module(msprof libmsprof.so ${ASCEND_DRIVER_COMMON_DIR}) | |||
elseif(PRODUCT STREQUAL "flr2") | |||
# flr2 ascend_hal_stub limsprof ? | |||
else() | |||
find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}) | |||
find_module(msprof libmsprof.so ${ASCEND_DRIVER_DIR}) | |||
endif() | |||
elseif(PLATFORM STREQUAL "all") | |||
find_module(msprof libmsprof.so ${ASCEND_DRIVER_COMMON_DIR}) | |||
find_module(msprofiler libmsprofiler.a ${ASCEND_DRIVER_COMMON_DIR}) | |||
find_module(hccl libhccl.so ${ASCEND_RUNTIME_DIR}) | |||
find_module(adump_server libadump_server.a ${ASCEND_ACL_DIR}) | |||
find_module(runtime libruntime.so ${ASCEND_ACL_DIR}) | |||
@@ -127,14 +126,14 @@ if (ENABLE_OPEN_SRC) | |||
find_module(resource libresource.so ${ASCEND_ATC_DIR}) | |||
find_module(error_manager liberror_manager.so ${ASCEND_ATC_DIR}) | |||
find_module(error_manager_static liberror_manager.a ${ASCEND_ACL_DIR}) | |||
find_module(msprofiler libmsprofiler.a ${ASCEND_ACL_DIR}) | |||
find_module(msprofiler_fwk libmsprofiler_fwk.a ${ASCEND_ACL_DIR}) | |||
find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}/driver) | |||
#find_module(ascendcl_static libascendcl.a ${ASCEND_ACL_DIR}) | |||
else() | |||
message(STATUS "PLATFORM param is invalid, should be train or inference, you choose nothing!") | |||
message(STATUS "PLATFORM param is invalid, should be train or inference, you choose nothing!") | |||
endif() | |||
if (ENABLE_GE_COV OR ENABLE_GE_UT) | |||
if (ENABLE_GE_COV OR ENABLE_GE_UT) | |||
add_subdirectory(tests) | |||
endif() | |||
@@ -158,7 +157,7 @@ elseif (ENABLE_D OR ENABLE_ACL) | |||
include(cmake/intf_pub_linux.cmake) | |||
# common libraries | |||
find_module(slog libslog.so ${ASCEND_MS_DRIVER_PATH}) | |||
find_module(slog libalog.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
find_module(error_manager liberror_manager.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
find_module(static_mmpa libmmpa.a ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
@@ -178,7 +177,7 @@ elseif(ENABLE_MS_TESTCASES) | |||
include(cmake/intf_pub_linux.cmake) | |||
# common libraries | |||
find_module(slog libslog.so ${ASCEND_MS_DRIVER_PATH}) | |||
find_module(slog libalog.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
find_module(error_manager liberror_manager.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
find_module(static_mmpa libmmpa.a ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
@@ -1,5 +1,35 @@ | |||
# Release 1.0.0 | |||
### Major Features and Improvements | |||
* Dynamic dims input is supported in online inference scenarios. | |||
* Dynamic ranking is supported in the GetNext scenario. | |||
* Dynamic shape is supported in offline inference scenarios. | |||
* Dynamic AIPP is supported in the dynamic multi-batch scenario. | |||
* Dynamic shape is supported for single operator in inference scenarios. | |||
* Supporting Profiling Training Trace in the Dynamic Shape Scenario. | |||
### New Features | |||
#### C++ API | |||
* Session::AddGraphWithCopy(uint32_t graphId, const Graph& graph) added ([#230](https://gitee.com/mindspore/graphengine/pulls/230)) | |||
* Session::AddGraphWithCopy(uint32_t graphId, const Graph& graph, const std::map<AscendString, AscendString>& options) added([#230](https://gitee.com/mindspore/graphengine/pulls/230)) | |||
### Bug fixes | |||
* Fix aicpu custom cpukernelluanch operation scene, the problem of stream resources cannot be released normally. | |||
* Fix the problem of network performance degradation caused by adding too many trandata operators in special scenes of graph optimization | |||
* Code review to fix the problem of program dead loop after partial integer flip | |||
* Fix the problem that some scenes of dynamic shape cannot dump the reducesum operator | |||
* Fix the problem of large loop expansion during network composition, resulting in insufficient memory and training failure | |||
* Fix the problem of dump AICPU operator fails. | |||
## Thanks to our Contributors | |||
Thanks goes to these wonderful people: wuweikang,wangcong,weiyang,yanghaorang,xutianchun,shibeiji,zhouchao, tanghuikang, zhoulili, liujunzhu, zhengyuanhua, taoxiangdong, zhaoxinxin, chuxing, wangtao, zhaozhixuan, wangwenhua Contributions of any kind are welcome! | |||
Contributions of any kind are welcome! | |||
# Release 1.0.0 | |||
## Major Features and Improvements | |||
* Automatically dump the input and output of the abnormal operator when the network execution is abnormal; | |||
* Realize dynamic multi-batch based on GotoLabel; | |||
@@ -458,3 +458,76 @@ Copyright (c) Facebook Inc. and Microsoft Corporation. | |||
License: MIT License | |||
Please see above. | |||
Software: caffe 1.0 | |||
License: BSD 2-Clause License | |||
Open Source Software Licensed Under the BSD 2-Clause License | |||
GraphEngine uses source code files from caffe so as to support model format conversion from caffe model to GraphEngine model. | |||
Please see below for the full list of source code files from caffe that are used by GraphEngine. | |||
The below software in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
---------------------------------------------------------------------------------------- | |||
1. caffe.proto master | |||
All contributions by the University of California: | |||
Copyright (c) 2014-2017 The Regents of the University of California (Regents) | |||
All rights reserved. | |||
Terms of the BSD 2-Clause License: | |||
-------------------------------------------------------------------- | |||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | |||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. | |||
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. | |||
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: tensorflow 1.15.0 | |||
License: Apache-2.0 License | |||
Open Source Software Licensed Under the Apache-2.0 License | |||
GraphEngine uses source code files from tensorflow so as to support model format conversion from tensorflow model to GraphEngine model. | |||
Please see below for the full list of source code files from tensorflow that are used by GraphEngine. | |||
The below software in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
---------------------------------------------------------------------------------------- | |||
1. attr_value.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
2. function.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
3. graph.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
4. node_def.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
5. op_def.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
6. resource_handle.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
7. tensor.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
8. tensor_shape.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
9. types.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
10. versions.proto master | |||
Copyright 2015 The TensorFlow Authors. All Rights Reserved. | |||
Terms of the Apache-2.0 License: | |||
Please see above. |
@@ -23,7 +23,7 @@ export BUILD_PATH="${BASEPATH}/build/" | |||
usage() | |||
{ | |||
echo "Usage:" | |||
echo "sh build.sh [-j[n]] [-h] [-v] [-s] [-t] [-u] [-c] [-S on|off]" | |||
echo "sh build.sh [-j[n]] [-h] [-v] [-s] [-t] [-u] [-c] [-S on|off] [-M]" | |||
echo "" | |||
echo "Options:" | |||
echo " -h Print usage" | |||
@@ -35,6 +35,7 @@ usage() | |||
echo " -p Build inference or train" | |||
echo " -v Display build command" | |||
echo " -S Enable enable download cmake compile dependency from gitee , default off" | |||
echo " -M build MindSpore mode" | |||
echo "to be continued ..." | |||
} | |||
@@ -62,8 +63,9 @@ checkopts() | |||
PLATFORM="" | |||
PRODUCT="normal" | |||
ENABLE_GITEE="off" | |||
MINDSPORE_MODE="off" | |||
# Process the options | |||
while getopts 'ustchj:p:g:vS:' opt | |||
while getopts 'ustchj:p:g:vS:M' opt | |||
do | |||
OPTARG=$(echo ${OPTARG} | tr '[A-Z]' '[a-z]') | |||
case "${opt}" in | |||
@@ -104,6 +106,9 @@ checkopts() | |||
ENABLE_GITEE="$OPTARG" | |||
echo "enable download from gitee" | |||
;; | |||
M) | |||
MINDSPORE_MODE="on" | |||
;; | |||
*) | |||
echo "Undefined option: ${opt}" | |||
usage | |||
@@ -113,8 +118,8 @@ checkopts() | |||
} | |||
checkopts "$@" | |||
git submodule update --init metadef | |||
git submodule update --init parser | |||
#git submodule update --init metadef | |||
#git submodule update --init parser | |||
mk_dir() { | |||
local create_dir="$1" # the target to make | |||
@@ -150,7 +155,13 @@ build_graphengine() | |||
if [[ "X$ENABLE_GITEE" = "Xon" ]]; then | |||
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_GITEE=ON" | |||
fi | |||
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPEN_SRC=True -DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH} -DPLATFORM=${PLATFORM} -DPRODUCT=${PRODUCT}" | |||
if [[ "X$MINDSPORE_MODE" = "Xoff" ]]; then | |||
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_OPEN_SRC=True -DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH} -DPLATFORM=${PLATFORM} -DPRODUCT=${PRODUCT}" | |||
else | |||
CMAKE_ARGS="${CMAKE_ARGS} -DENABLE_D=ON -DCMAKE_INSTALL_PREFIX=${OUTPUT_PATH}" | |||
fi | |||
echo "${CMAKE_ARGS}" | |||
cmake ${CMAKE_ARGS} .. | |||
if [ $? -ne 0 ] | |||
@@ -169,6 +180,9 @@ build_graphengine() | |||
elif [ "X$ENABLE_GE_UT" = "Xon" ] | |||
then | |||
TARGET="ut_libgraph ut_libge_multiparts_utest ut_libge_others_utest ut_libge_kernel_utest ut_libge_distinct_load_utest" | |||
elif [ "X$MINDSPORE_MODE" = "Xon" ] | |||
then | |||
TARGET="ge_common graph" | |||
elif [ "x${PLATFORM}" = "xall" ] | |||
then | |||
# build all the target | |||
@@ -314,7 +328,13 @@ generate_package() | |||
fi | |||
} | |||
if [[ "X$ENABLE_GE_UT" = "Xoff" ]]; then | |||
if [[ "X$ENABLE_GE_UT" = "Xoff" && "X$MINDSPORE_MODE" = "Xoff" ]]; then | |||
generate_package | |||
echo "---------------- GraphEngine package archive generated ----------------" | |||
elif [ "X$MINDSPORE_MODE" = "Xon" ] | |||
then | |||
cd "${OUTPUT_PATH}" | |||
find ./ -name graphengine_lib.tar -exec rm {} \; | |||
tar -cf graphengine_lib.tar lib | |||
fi | |||
echo "---------------- GraphEngine package archive generated ----------------" | |||
@@ -23,6 +23,7 @@ ExternalProject_Add(gflags_build | |||
URL ${REQ_URL} | |||
#URL /home/txd/workspace/linux_cmake/pkg/protobuf-3.8.0.tar.gz | |||
#SOURCE_DIR ${GE_CODE_DIR}/../../third_party/gflags/src/gflags-2.2.2 | |||
TLS_VERIFY OFF | |||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_CXX_FLAGS=${gflags_CXXFLAGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/gflags <SOURCE_DIR> | |||
BUILD_COMMAND $(MAKE) | |||
INSTALL_COMMAND $(MAKE) install | |||
@@ -10,11 +10,14 @@ if ((${CMAKE_INSTALL_PREFIX} STREQUAL /usr/local) OR | |||
message(STATUS "No install prefix selected, default to ${CMAKE_INSTALL_PREFIX}.") | |||
endif() | |||
if (ENABLE_GITEE) | |||
set(REQ_URL "https://gitee.com/mirrors/googletest/repository/archive/release-1.8.0.tar.gz") | |||
if (GE_PB_PKG) | |||
set(REQ_URL "${GE_PB_PKG}/libs/ge_gtest/release-1.8.1.tar.gz") | |||
set(MD5 "") | |||
elseif (ENABLE_GITEE) | |||
set(REQ_URL "https://gitee.com/mirrors/googletest/repository/archive/release-1.8.1.tar.gz") | |||
set(MD5 "") | |||
else() | |||
set(REQ_URL "https://github.com/google/googletest/archive/release-1.8.0.tar.gz") | |||
set(REQ_URL "https://github.com/google/googletest/archive/release-1.8.1.tar.gz") | |||
set(MD5 "") | |||
endif () | |||
@@ -22,8 +25,9 @@ set (gtest_CXXFLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 -D_FORTIFY_SOURCE=2 -O2 -fstack- | |||
set (gtest_CFLAGS "-D_GLIBCXX_USE_CXX11_ABI=0 -D_FORTIFY_SOURCE=2 -O2 -fstack-protector-all -Wl,-z,relro,-z,now,-z,noexecstack") | |||
ExternalProject_Add(gtest_build | |||
URL ${REQ_URL} | |||
TLS_VERIFY OFF | |||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_CXX_FLAGS=${gtest_CXXFLAGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/gtest <SOURCE_DIR> | |||
-DBUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_MACOSX_RPATH=TRUE -Dgtest_disable_pthreads=ON | |||
-DBUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_MACOSX_RPATH=TRUE -Dgtest_disable_pthreads=ON | |||
BUILD_COMMAND $(MAKE) | |||
INSTALL_COMMAND $(MAKE) install | |||
EXCLUDE_FROM_ALL TRUE | |||
@@ -5,10 +5,14 @@ endif() | |||
include(ExternalProject) | |||
set(JSON_SRC_DIR ${CMAKE_BINARY_DIR}/opensrc/json/include) | |||
if (ENABLE_GITEE) | |||
set(REQ_URL "https://gitee.com/mirrors/JSON-for-Modern-CPP/repository/archive/v3.6.1.zip") | |||
set(MD5 "5bda78ce308e6cfcf614dcf1d5ff27a7") | |||
set(JSON_INCLUDE_DIR "${JSON_SRC_DIR}/include") | |||
if (GE_PB_PKG) | |||
set(REQ_URL "${GE_PB_PKG}/libs/ge_nlohmann_json/include.zip") | |||
set(MD5 "0dc903888211db3a0f170304cd9f3a89") | |||
set(JSON_INCLUDE_DIR ${JSON_SRC_DIR}) | |||
#elseif (ENABLE_GITEE) | |||
# set(REQ_URL "https://gitee.com/mirrors/JSON-for-Modern-CPP/repository/archive/v3.6.1.zip") | |||
# set(MD5 "5bda78ce308e6cfcf614dcf1d5ff27a7") | |||
#set(JSON_INCLUDE_DIR "${JSON_SRC_DIR}/include") | |||
else() | |||
set(REQ_URL "https://github.com/nlohmann/json/releases/download/v3.6.1/include.zip") | |||
set(MD5 "0dc903888211db3a0f170304cd9f3a89") | |||
@@ -18,6 +22,7 @@ ExternalProject_Add(json_build | |||
URL ${REQ_URL} | |||
#URL /home/txd/workspace/cloud_code/pkg/include.zip | |||
SOURCE_DIR ${JSON_SRC_DIR} | |||
TLS_VERIFY OFF | |||
CONFIGURE_COMMAND "" | |||
BUILD_COMMAND "" | |||
INSTALL_COMMAND "" | |||
@@ -6,7 +6,10 @@ set(ONNX_PROTO_DIR ${CMAKE_BINARY_DIR}/onnx) | |||
set(ONNX_PROTO_FILE ${ONNX_PROTO_DIR}/onnx.proto) | |||
file(MAKE_DIRECTORY ${ONNX_PROTO_DIR}) | |||
if (ENABLE_GITEE) | |||
if (GE_PB_PKG) | |||
set(REQ_URL "${GE_PB_PKG}/libs/onnx/onnx-1.6.0.tar.gz") | |||
set(MD5 "512f2779d6215d4a36f366b6b9acdf1e") | |||
elseif (ENABLE_GITEE) | |||
set(REQ_URL "https://gitee.com/mirrors/ONNX/repository/archive/v1.6.0.tar.gz") | |||
set(MD5 "1bdbcecdd68ea8392630467646776e02") | |||
else() | |||
@@ -19,6 +22,7 @@ ExternalProject_Add(onnx | |||
#URL /home/txd/workspace/cloud_code/pkg/onnx-1.6.0.tar.gz | |||
#URL_HASH SHA256=3b88c3fe521151651a0403c4d131cb2e0311bd28b753ef692020a432a81ce345 | |||
#SOURCE_DIR ${ONNX_SRC_DIR} | |||
TLS_VERIFY OFF | |||
CONFIGURE_COMMAND "" | |||
BUILD_COMMAND "" | |||
#INSTALL_COMMAND "" | |||
@@ -26,6 +26,7 @@ set(protobuf_CXXFLAGS "-Wno-maybe-uninitialized -Wno-unused-parameter -fPIC -fst | |||
set(protobuf_LDFLAGS "-Wl,-z,relro,-z,now,-z,noexecstack") | |||
ExternalProject_Add(protobuf_build | |||
URL ${REQ_URL} | |||
TLS_VERIFY OFF | |||
CONFIGURE_COMMAND ${CMAKE_COMMAND} | |||
-Dprotobuf_WITH_ZLIB=OFF | |||
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR} | |||
@@ -27,6 +27,7 @@ ExternalProject_Add(protobuf_static_build | |||
URL ${REQ_URL} | |||
#URL /home/txd/workspace/linux_cmake/pkg/protobuf-3.8.0.tar.gz | |||
#SOURCE_DIR ${METADEF_DIR}/../../third_party/protobuf/src/protobuf-3.8.0 | |||
TLS_VERIFY OFF | |||
CONFIGURE_COMMAND ${CMAKE_COMMAND} | |||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} | |||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} | |||
@@ -30,6 +30,7 @@ ExternalProject_Add(protoc_build | |||
URL ${REQ_URL} | |||
#URL /home/txd/workspace/linux_cmake/pkg/protobuf-3.8.0.tar.gz | |||
#SOURCE_DIR ${GE_CODE_DIR}/../third_party/protobuf/src/protobuf-3.8.0 | |||
TLS_VERIFY OFF | |||
CONFIGURE_COMMAND ${CMAKE_COMMAND} -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_CXX_FLAGS=${protobuf_CXXFLAGS} -DCMAKE_CXX_LDFLAGS=${protobuf_LDFLAGS} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}/protoc <SOURCE_DIR>/cmake | |||
BUILD_COMMAND $(MAKE) | |||
INSTALL_COMMAND $(MAKE) install | |||
@@ -10,11 +10,20 @@ if ((${CMAKE_INSTALL_PREFIX} STREQUAL /usr/local) OR | |||
message(STATUS "No install prefix selected, default to ${CMAKE_INSTALL_PREFIX}.") | |||
endif() | |||
if (GE_PB_PKG) | |||
set(REQ_URL "${GE_PB_PKG}/libs/securec/v1.1.10.tar.gz") | |||
set(MD5 "") | |||
else() | |||
set(REQ_URL "https://gitee.com/openeuler/libboundscheck/repository/archive/v1.1.10.tar.gz") | |||
set(MD5 "") | |||
endif () | |||
ExternalProject_Add(c_sec_build | |||
URL https://gitee.com/openeuler/libboundscheck/repository/archive/v1.1.10.tar.gz | |||
#URL /home/txd/workspace/linux_cmake/pkg/protobuf-3.8.0.tar.gz | |||
URL ${REQ_URL} | |||
#URL https://gitee.com/openeuler/libboundscheck/repository/archive/v1.1.10.tar.gz | |||
#SOURCE_DIR ${GE_CODE_DIR}/../libc_sec | |||
PATCH_COMMAND patch -p1 < ${GE_CODE_DIR}/metadef/third_party/patch/securec/0001-add-securec-cmake-script.patch | |||
TLS_VERIFY OFF | |||
CONFIGURE_COMMAND ${CMAKE_COMMAND} | |||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} | |||
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} | |||
@@ -4,7 +4,7 @@ endif() | |||
add_library(intf_pub INTERFACE) | |||
target_compile_options(intf_pub INTERFACE | |||
target_compile_options(intf_pub INTERFACE | |||
-Wall | |||
-fPIC | |||
$<IF:$<STREQUAL:${CMAKE_SYSTEM_NAME},centos>,-fstack-protector-all,-fstack-protector-strong> | |||
@@ -16,6 +16,7 @@ target_compile_definitions(intf_pub INTERFACE | |||
$<$<CONFIG:Debug>:CFG_BUILD_DEBUG> | |||
WIN64=1 | |||
LINUX=0 | |||
LOG_CPP | |||
) | |||
target_link_options(intf_pub INTERFACE | |||
-Wl,-z,relro | |||
@@ -60,6 +60,8 @@ set(TRAIN_SRC_LIST | |||
"common/dump/dump_manager.cc" | |||
"common/dump/dump_properties.cc" | |||
"common/dump/dump_op.cc" | |||
"common/profiling/ge_profiling.cc" | |||
"common/profiling/ge_runner_profiling.cc" | |||
"engine_manager/dnnengine_manager.cc" | |||
"ge_local_engine/engine/host_cpu_engine.cc" | |||
"generator/ge_generator.cc" | |||
@@ -142,6 +144,7 @@ set(TRAIN_SRC_LIST | |||
"graph/passes/atomic_addr_clean_pass.cc" | |||
"graph/passes/mark_same_addr_pass.cc" | |||
"graph/passes/mark_graph_unknown_status_pass.cc" | |||
"graph/passes/dynamic_single_op_reset_shape_pass.cc" | |||
"graph/passes/mark_agnostic_pass.cc" | |||
"graph/partition/dynamic_shape_partition.cc" | |||
"graph/partition/stage_partition.cc" | |||
@@ -154,6 +157,8 @@ set(TRAIN_SRC_LIST | |||
"graph/passes/compile_nodes_pass.cc" | |||
"graph/passes/constant_folding_pass.cc" | |||
"graph/passes/constant_fuse_same_pass.cc" | |||
"graph/passes/remove_same_const_pass.cc" | |||
"graph/passes/useless_control_out_remove_pass.cc" | |||
"graph/passes/control_trigger_pass.cc" | |||
"graph/passes/dimension_adjust_pass.cc" | |||
"graph/passes/dimension_compute_pass.cc" | |||
@@ -201,6 +206,7 @@ set(TRAIN_SRC_LIST | |||
"host_kernels/sub_kernel.cc" | |||
"host_kernels/transdata_kernel.cc" | |||
"host_kernels/unpack_kernel.cc" | |||
"host_kernels/reformat_kernel.cc" | |||
"graph/passes/folding_pass.cc" | |||
"graph/passes/get_original_format_pass.cc" | |||
"graph/passes/guarantee_const_pass.cc" | |||
@@ -331,7 +337,6 @@ set(TRAIN_SRC_LIST | |||
"hybrid/hybrid_davinci_model.cc" | |||
"executor/ge_executor.cc" | |||
"client/ge_api.cc" | |||
"client/ge_prof.cc" | |||
"analyzer/analyzer.cc" | |||
"ir_build/ge_ir_build.cc" | |||
"ir_build/atc_ir_common.cc" | |||
@@ -432,6 +437,7 @@ set(INFER_SRC_LIST | |||
"graph/passes/atomic_addr_clean_pass.cc" | |||
"graph/passes/mark_same_addr_pass.cc" | |||
"graph/passes/mark_graph_unknown_status_pass.cc" | |||
"graph/passes/dynamic_single_op_reset_shape_pass.cc" | |||
"graph/passes/mark_agnostic_pass.cc" | |||
"graph/common/omg_util.cc" | |||
"graph/common/bcast.cc" | |||
@@ -487,6 +493,7 @@ set(INFER_SRC_LIST | |||
"host_kernels/slice_d_kernel.cc" | |||
"host_kernels/dynamic_stitch_kernel.cc" | |||
"host_kernels/identity_kernel.cc" | |||
"host_kernels/reformat_kernel.cc" | |||
"graph/passes/stop_gradient_pass.cc" | |||
"graph/passes/prevent_gradient_pass.cc" | |||
"graph/passes/identity_pass.cc" | |||
@@ -517,6 +524,8 @@ set(INFER_SRC_LIST | |||
"graph/passes/assign_pass.cc" | |||
"graph/passes/addn_pass.cc" | |||
"graph/passes/common_subexpression_elimination_pass.cc" | |||
"graph/passes/remove_same_const_pass.cc" | |||
"graph/passes/useless_control_out_remove_pass.cc" | |||
"graph/passes/transop_symmetry_elimination_pass.cc" | |||
"graph/passes/save_pass.cc" | |||
"graph/passes/switch_dead_branch_elimination.cc" | |||
@@ -611,6 +620,7 @@ target_compile_definitions(ge_runner PRIVATE | |||
FMK_SUPPORT_DUMP | |||
DAVINCI_CLOUD | |||
google=ascend_private | |||
$<$<STREQUAL:${ENABLE_OPEN_SRC},True>:ONLY_COMPILE_OPEN_SRC> | |||
) | |||
target_compile_options(ge_runner PRIVATE | |||
@@ -643,12 +653,14 @@ target_include_directories(ge_runner PRIVATE | |||
${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain | |||
) | |||
target_link_libraries(ge_runner | |||
target_link_libraries(ge_runner PRIVATE | |||
$<BUILD_INTERFACE:intf_pub> | |||
ge_memory | |||
adump_server | |||
msprofiler | |||
static_mmpa | |||
-Wl,--whole-archive | |||
msprofiler_fwk | |||
-Wl,--no-whole-archive | |||
-Wl,--no-as-needed | |||
graph | |||
ge_common | |||
@@ -656,7 +668,6 @@ target_link_libraries(ge_runner | |||
register | |||
c_sec | |||
slog | |||
msprof | |||
runtime | |||
resource | |||
error_manager | |||
@@ -677,6 +688,7 @@ target_compile_definitions(ge_compiler PRIVATE | |||
FMK_HOST_INFER | |||
COMPILE_OMG_PACKAGE | |||
google=ascend_private | |||
$<$<STREQUAL:${ENABLE_OPEN_SRC},True>:ONLY_COMPILE_OPEN_SRC> | |||
) | |||
target_compile_options(ge_compiler PRIVATE | |||
@@ -709,7 +721,7 @@ target_include_directories(ge_compiler PRIVATE | |||
${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain | |||
) | |||
target_link_libraries(ge_compiler | |||
target_link_libraries(ge_compiler PRIVATE | |||
$<BUILD_INTERFACE:intf_pub> | |||
ge_memory | |||
static_mmpa | |||
@@ -763,7 +775,14 @@ target_link_options(opensrc_ascendcl PRIVATE | |||
-Wl,--allow-multiple-definition | |||
-Wl,-z,muldefs | |||
-Wl,-Bsymbolic | |||
-Wl,--exclude-libs,ALL | |||
-Wl,--exclude-libs,libascend_protobuf.a | |||
-Wl,--exclude-libs,libge_executor.a | |||
-Wl,--exclude-libs,libge_common.a | |||
-Wl,--exclude-libs,libgraph.a | |||
-Wl,--exclude-libs,libmmpa.a | |||
-Wl,--exclude-libs,libregister.a | |||
-Wl,--exclude-libs,liberror_manager.a | |||
-Wl,--exclude-libs,libadump_server.a | |||
) | |||
target_link_libraries(opensrc_ascendcl PRIVATE | |||
-Wl,--whole-archive | |||
@@ -781,7 +800,6 @@ target_link_libraries(opensrc_ascendcl PRIVATE | |||
c_sec | |||
runtime | |||
slog | |||
msprof | |||
ascend_hal_stub | |||
-Wl,--as-needed | |||
-lrt | |||
@@ -797,12 +815,10 @@ set_target_properties(opensrc_ascendcl PROPERTIES | |||
add_custom_command( | |||
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/stub_ge_ir_build.cc | |||
${CMAKE_CURRENT_BINARY_DIR}/stub_ge_api.cc | |||
${CMAKE_CURRENT_BINARY_DIR}/stub_ge_prof.cc | |||
COMMAND echo "Generating stub files." | |||
&& ${HI_PYTHON} ${CMAKE_CURRENT_LIST_DIR}/stub/gen_stubapi.py ${GE_CODE_DIR}/inc/external ${CMAKE_CURRENT_BINARY_DIR} | |||
&& mv ge_ir_build.cc stub_ge_ir_build.cc | |||
&& mv ge_api.cc stub_ge_api.cc | |||
&& mv ge_prof.cc stub_ge_prof.cc | |||
&& echo "Generating stub files end." | |||
#WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |||
#DEPENDS stub/gen_stubapi.py ${TOP_DIR}/inc/external ${CMAKE_CURRENT_BINARY_DIR} | |||
@@ -811,7 +827,6 @@ add_custom_command( | |||
add_custom_target(ge_stub | |||
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/stub_ge_ir_build.cc | |||
${CMAKE_CURRENT_BINARY_DIR}/stub_ge_api.cc | |||
${CMAKE_CURRENT_BINARY_DIR}/stub_ge_prof.cc | |||
) | |||
################################################################## | |||
@@ -853,7 +868,6 @@ target_include_directories(atc_stub_ge_compiler PRIVATE | |||
############ stub/libge_runner.so ############ | |||
add_library(fwk_stub_ge_runner SHARED | |||
stub_ge_api.cc | |||
stub_ge_prof.cc | |||
stub_ge_ir_build.cc | |||
) | |||
@@ -32,6 +32,9 @@ | |||
#include "graph/common/ge_call_wrapper.h" | |||
#include "register/op_registry.h" | |||
#include "common/ge/tbe_plugin_manager.h" | |||
#ifndef ONLY_COMPILE_OPEN_SRC | |||
#include "toolchain/plog.h" | |||
#endif | |||
using domi::OpRegistry; | |||
using std::map; | |||
@@ -129,12 +132,17 @@ Status GEInitializeImpl(const std::map<string, string> &options) { | |||
// Initialize GE, prepare for execution, call GELib::Initialize | |||
Status GEInitialize(const std::map<string, string> &options) { | |||
#ifndef ONLY_COMPILE_OPEN_SRC | |||
if (DlogReportInitialize() != SUCCESS) { | |||
GELOGW("Dlog report device log initialize failed."); | |||
} | |||
#endif | |||
return GEInitializeImpl(options); | |||
} | |||
Status GEInitialize(const std::map<AscendString, AscendString> &options) { | |||
std::map<std::string, std::string> str_options; | |||
for (auto & option : options) { | |||
for (auto &option : options) { | |||
if (option.first.GetString() == nullptr || option.second.GetString() == nullptr) { | |||
GELOGE(FAILED, "GEInitialize options is nullptr."); | |||
return FAILED; | |||
@@ -143,6 +151,11 @@ Status GEInitialize(const std::map<AscendString, AscendString> &options) { | |||
std::string val = option.second.GetString(); | |||
str_options[key] = val; | |||
} | |||
#ifndef ONLY_COMPILE_OPEN_SRC | |||
if (DlogReportInitialize() != SUCCESS) { | |||
GELOGW("Dlog report device log initialize failed."); | |||
} | |||
#endif | |||
return GEInitializeImpl(str_options); | |||
} | |||
@@ -187,6 +200,12 @@ Status GEFinalize() { | |||
// to avoid memory fragment, use malloc_trim to back free stack to system | |||
malloc_trim(0); | |||
#ifndef ONLY_COMPILE_OPEN_SRC | |||
if (DlogReportFinalize() != SUCCESS) { | |||
GELOGW("Dlog report device log finalize failed."); | |||
} | |||
#endif | |||
GELOGT(TRACE_STOP, "GEFinalize finished"); | |||
return ret; | |||
} | |||
@@ -1,369 +0,0 @@ | |||
/** | |||
* Copyright 2020 Huawei Technologies Co., Ltd | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
#include "ge/ge_prof.h" | |||
#include "ge/ge_api.h" | |||
#include "init/gelib.h" | |||
#include "common/debug/log.h" | |||
#include "framework/common/debug/ge_log.h" | |||
#include "common/profiling/profiling_manager.h" | |||
#include "graph/load/graph_loader.h" | |||
#include "toolchain/prof_acl_api.h" | |||
using std::map; | |||
using std::string; | |||
using std::vector; | |||
namespace { | |||
const uint32_t kMaxDeviceNum = 64; | |||
const uint32_t kDeviceListIndex = 3; | |||
const std::string kProfilingInit = "prof_init"; | |||
const std::string kProfilingFinalize = "prof_finalize"; | |||
const std::string kProfilingStart = "prof_start"; | |||
const std::string kProfilingStop = "prof_stop"; | |||
const std::string kDeviceNums = "devNums"; | |||
const std::string kDeviceIdList = "devIdList"; | |||
const std::string kAicoreMetrics = "aicoreMetrics"; | |||
const std::map<ge::ProfilingAicoreMetrics, std::string> kProfAicoreMetricsToString = { | |||
{ge::kAicoreArithmaticThroughput, "AICORE_ARITHMATIC_THROUGHPUT"}, | |||
{ge::kAicorePipeline, "AICORE_PIPELINE"}, | |||
{ge::kAicoreSynchronization, "AICORE_SYNCHRONIZATION"}, | |||
{ge::kAicoreMemory, "AICORE_MEMORY"}, | |||
{ge::kAicoreInternalMemory, "AICORE_INTERNAL_MEMORY"}, | |||
{ge::kAicoreStall, "AICORE_STALL"}}; | |||
} // namespace | |||
static bool g_graph_prof_init_ = false; | |||
static std::mutex g_prof_mutex_; | |||
namespace ge { | |||
struct aclgrphProfConfig { | |||
ProfConfig config; | |||
}; | |||
Status aclgrphProfInit(const char *profiler_path, uint32_t length) { | |||
GELOGT(TRACE_INIT, "Graph prof init start"); | |||
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "Ge client is not initialized."); | |||
return FAILED; | |||
} | |||
std::lock_guard<std::mutex> lock(g_prof_mutex_); | |||
if (g_graph_prof_init_) { | |||
GELOGW("Multi graph profiling initializations."); | |||
return GE_PROF_MULTI_INIT; | |||
} | |||
Status ret = CheckPath(profiler_path, length); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Profiling config path is invalid."); | |||
return ret; | |||
} | |||
// if command mode is set, just return | |||
if (ProfilingManager::Instance().ProfilingOn()) { | |||
GELOGW("Graph prof init failed, cause profiling command pattern is running."); | |||
return GE_PROF_MODE_CONFLICT; | |||
} | |||
ret = ProfInit(profiler_path); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "ProfInit init fail"); | |||
return ret; | |||
} | |||
GraphLoader graph_loader; | |||
Command command; | |||
command.cmd_params.clear(); | |||
command.cmd_type = kProfilingInit; | |||
command.module_index = PROF_MODEL_LOAD; | |||
ret = graph_loader.CommandHandle(command); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Handle profiling command %s failed, config = %s", kProfilingInit.c_str(), profiler_path); | |||
return ret; | |||
} | |||
if (!g_graph_prof_init_) { | |||
g_graph_prof_init_ = true; | |||
GELOGI("Profiling init successfully."); | |||
} | |||
GELOGI("Successfully execute GraphProfInit."); | |||
return SUCCESS; | |||
} | |||
Status aclgrphProfFinalize() { | |||
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "Ge client is not initialized."); | |||
return FAILED; | |||
} | |||
std::lock_guard<std::mutex> lock(g_prof_mutex_); | |||
// if command mode is set, just return | |||
if (ProfilingManager::Instance().ProfilingOn()) { | |||
GELOGW("Graph prof finalize failed, cause profiling command pattern is running."); | |||
return GE_PROF_MODE_CONFLICT; | |||
} | |||
if (!g_graph_prof_init_) { | |||
GELOGE(GE_PROF_NOT_INIT, "Graph not profiling initialize."); | |||
return GE_PROF_NOT_INIT; | |||
} | |||
GraphLoader graph_loader; | |||
Command command; | |||
command.cmd_params.clear(); | |||
command.cmd_type = kProfilingFinalize; | |||
Status ret = graph_loader.CommandHandle(command); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Handle profiling command %s failed.", kProfilingFinalize.c_str()); | |||
return ret; | |||
} | |||
ret = ProfFinalize(); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Finalize profiling failed, result = %d", ret); | |||
} | |||
if (ret == SUCCESS) { | |||
g_graph_prof_init_ = false; | |||
GELOGI("Successfully execute GraphProfFinalize."); | |||
} | |||
return ret; | |||
} | |||
bool TransProfConfigToParam(const aclgrphProfConfig *profiler_config, vector<string> &prof_config_params) { | |||
prof_config_params.clear(); | |||
prof_config_params.emplace_back(kDeviceNums); | |||
prof_config_params.emplace_back(std::to_string(profiler_config->config.devNums)); | |||
prof_config_params.emplace_back(kDeviceIdList); | |||
std::string devID = ""; | |||
if (profiler_config->config.devNums == 0) { | |||
GELOGW("The device num is invalid."); | |||
return false; | |||
} | |||
for (uint32_t i = 0; i < profiler_config->config.devNums; i++) { | |||
devID.append(std::to_string(profiler_config->config.devIdList[i])); | |||
if (i != profiler_config->config.devNums - 1) { | |||
devID.append(","); | |||
} | |||
} | |||
prof_config_params.push_back(devID); | |||
prof_config_params.push_back(kAicoreMetrics); | |||
auto iter = | |||
kProfAicoreMetricsToString.find(static_cast<ProfilingAicoreMetrics>(profiler_config->config.aicoreMetrics)); | |||
if (iter == kProfAicoreMetricsToString.end()) { | |||
GELOGW("The prof aicore metrics is invalid."); | |||
return false; | |||
} | |||
prof_config_params.push_back(iter->second); | |||
return true; | |||
} | |||
bool isProfConfigValid(const uint32_t *deviceid_list, uint32_t device_nums) { | |||
if (deviceid_list == nullptr) { | |||
GELOGE(PARAM_INVALID, "deviceIdList is nullptr"); | |||
return false; | |||
} | |||
if (device_nums == 0 || device_nums > kMaxDeviceNum) { | |||
GELOGE(PARAM_INVALID, "The device nums is invalid."); | |||
return false; | |||
} | |||
// real device num | |||
int32_t dev_count = 0; | |||
rtError_t rt_err = rtGetDeviceCount(&dev_count); | |||
if (rt_err != RT_ERROR_NONE) { | |||
GELOGE(INTERNAL_ERROR, "Get the Device count fail."); | |||
return false; | |||
} | |||
if (device_nums > static_cast<uint32_t>(dev_count)) { | |||
GELOGE(PARAM_INVALID, "Device num(%u) is not in range 1 ~ %d.", device_nums, dev_count); | |||
return false; | |||
} | |||
std::unordered_set<uint32_t> record; | |||
for (size_t i = 0; i < device_nums; ++i) { | |||
uint32_t dev_id = deviceid_list[i]; | |||
if (dev_id >= static_cast<uint32_t>(dev_count)) { | |||
GELOGE(PARAM_INVALID, "Device id %u is not in range 0 ~ %d(exclude %d)", dev_id, dev_count, dev_count); | |||
return false; | |||
} | |||
if (record.count(dev_id) > 0) { | |||
GELOGE(PARAM_INVALID, "Device id %u is duplicatedly set", dev_id); | |||
return false; | |||
} | |||
record.insert(dev_id); | |||
} | |||
return true; | |||
} | |||
aclgrphProfConfig *aclgrphProfCreateConfig(uint32_t *deviceid_list, uint32_t device_nums, | |||
ProfilingAicoreMetrics aicore_metrics, ProfAicoreEvents *aicore_events, | |||
uint64_t data_type_config) { | |||
if (!isProfConfigValid(deviceid_list, device_nums)) { | |||
return nullptr; | |||
} | |||
aclgrphProfConfig *config = new (std::nothrow) aclgrphProfConfig(); | |||
if (config == nullptr) { | |||
GELOGE(INTERNAL_ERROR, "new aclgrphProfConfig fail"); | |||
return nullptr; | |||
} | |||
config->config.devNums = device_nums; | |||
if (memcpy_s(config->config.devIdList, sizeof(config->config.devIdList), deviceid_list, | |||
device_nums * sizeof(uint32_t)) != EOK) { | |||
GELOGE(INTERNAL_ERROR, "copy devID failed. size = %u", device_nums); | |||
delete config; | |||
return nullptr; | |||
} | |||
config->config.aicoreMetrics = static_cast<ProfAicoreMetrics>(aicore_metrics); | |||
config->config.dataTypeConfig = data_type_config; | |||
GELOGI("Successfully create prof config."); | |||
return config; | |||
} | |||
Status aclgrphProfDestroyConfig(aclgrphProfConfig *profiler_config) { | |||
if (profiler_config == nullptr) { | |||
GELOGE(PARAM_INVALID, "destroy profilerConfig failed, profilerConfig must not be nullptr"); | |||
return PARAM_INVALID; | |||
} | |||
delete profiler_config; | |||
GELOGI("Successfully destroy prof config."); | |||
return SUCCESS; | |||
} | |||
Status aclgrphProfStart(aclgrphProfConfig *profiler_config) { | |||
if (profiler_config == nullptr) { | |||
GELOGE(PARAM_INVALID, "aclgrphProfConfig is invalid."); | |||
return FAILED; | |||
} | |||
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "Ge client is not initialized."); | |||
return FAILED; | |||
} | |||
std::lock_guard<std::mutex> lock(g_prof_mutex_); | |||
// if command mode is set, just return | |||
if (ProfilingManager::Instance().ProfilingOn()) { | |||
GELOGW("Graph prof finalize failed, cause profiling command pattern is running."); | |||
return GE_PROF_MODE_CONFLICT; | |||
} | |||
if (!g_graph_prof_init_) { | |||
GELOGE(GE_PROF_NOT_INIT, "Graph not profiling initialize."); | |||
return GE_PROF_NOT_INIT; | |||
} | |||
Status ret = ProfStartProfiling(&profiler_config->config); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Start profiling failed, prof result = %d", ret); | |||
return FAILED; | |||
} | |||
std::vector<string> prof_params; | |||
if (!TransProfConfigToParam(profiler_config, prof_params)) { | |||
GELOGE(PARAM_INVALID, "Transfer profilerConfig to string vector failed"); | |||
return PARAM_INVALID; | |||
} | |||
GraphLoader graph_loader; | |||
Command command; | |||
command.cmd_params.clear(); | |||
command.cmd_type = kProfilingStart; | |||
command.cmd_params = prof_params; | |||
command.module_index = profiler_config->config.dataTypeConfig; | |||
GELOGI("Profiling will start, device nums:%s , deviceID:[%s], data type config: 0x%llx", prof_params[0].c_str(), | |||
prof_params[kDeviceListIndex].c_str(), command.module_index); | |||
ret = graph_loader.CommandHandle(command); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Handle profiling command failed"); | |||
return FAILED; | |||
} | |||
GELOGI("Successfully execute GraphProfStartProfiling."); | |||
return SUCCESS; | |||
} | |||
Status aclgrphProfStop(aclgrphProfConfig *profiler_config) { | |||
if (profiler_config == nullptr) { | |||
GELOGE(PARAM_INVALID, "aclgrphProfConfig is invalid."); | |||
return FAILED; | |||
} | |||
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance(); | |||
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) { | |||
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "Ge client is not initialized."); | |||
return FAILED; | |||
} | |||
std::lock_guard<std::mutex> lock(g_prof_mutex_); | |||
// if command mode is set, just return | |||
if (ProfilingManager::Instance().ProfilingOn()) { | |||
GELOGW("Graph prof finalize failed, cause profiling command pattern is running."); | |||
return GE_PROF_MODE_CONFLICT; | |||
} | |||
if (!g_graph_prof_init_) { | |||
GELOGE(GE_PROF_NOT_INIT, "Graph not profiling initialize."); | |||
return GE_PROF_NOT_INIT; | |||
} | |||
for (uint32_t i = 0; i < profiler_config->config.devNums; i++) { | |||
uint64_t data_type_config; | |||
Status status = ProfGetDataTypeConfig(profiler_config->config.devIdList[i], data_type_config); | |||
if (status != SUCCESS) { | |||
GELOGE(status, "Prof get data type config failed, prof result = %d", status); | |||
return status; | |||
} | |||
if (data_type_config != profiler_config->config.dataTypeConfig) { | |||
GELOGE(FAILED, "data type config verify failed"); | |||
return FAILED; | |||
} | |||
} | |||
std::vector<string> prof_params; | |||
if (!TransProfConfigToParam(profiler_config, prof_params)) { | |||
GELOGE(PARAM_INVALID, "Transfer profilerConfig to string vector failed"); | |||
return PARAM_INVALID; | |||
} | |||
GraphLoader graph_loader; | |||
Command command; | |||
command.cmd_params.clear(); | |||
command.cmd_type = kProfilingStop; | |||
command.cmd_params = prof_params; | |||
command.module_index = profiler_config->config.dataTypeConfig; | |||
GELOGI("Profiling will stop, device nums:%s , deviceID:[%s], data type config: 0x%llx", prof_params[0].c_str(), | |||
prof_params[kDeviceListIndex].c_str(), command.module_index); | |||
Status ret = graph_loader.CommandHandle(command); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Handle profiling command failed"); | |||
return FAILED; | |||
} | |||
ret = ProfStopProfiling(&profiler_config->config); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Stop profiling failed, prof result = %d", ret); | |||
return ret; | |||
} | |||
GELOGI("Successfully execute GraphProfStopProfiling."); | |||
return SUCCESS; | |||
} | |||
} // namespace ge |
@@ -4,7 +4,6 @@ LOCAL_PATH := $(call my-dir) | |||
COMMON_LOCAL_SRC_FILES := \ | |||
proto/ge_api.proto \ | |||
ge_api.cc \ | |||
ge_prof.cc \ | |||
COMMON_LOCAL_C_INCLUDES := \ | |||
@@ -69,9 +68,9 @@ LOCAL_SHARED_LIBRARIES := \ | |||
libgraph \ | |||
libregister \ | |||
libge_compiler \ | |||
libge_common \ | |||
libmsprof | |||
libge_common | |||
LOCAL_STATIC_LIBRARIES += libmsprofiler_fwk \ | |||
LOCAL_LDFLAGS := -lrt -ldl | |||
@@ -104,8 +103,10 @@ LOCAL_SHARED_LIBRARIES := \ | |||
libregister \ | |||
libruntime \ | |||
libge_compiler \ | |||
libge_common \ | |||
libmsprof | |||
libge_common | |||
LOCAL_STATIC_LIBRARIES += libmsprofiler_fwk \ | |||
LOCAL_LDFLAGS := -lrt -ldl | |||
@@ -24,6 +24,7 @@ set(SRC_LIST | |||
"helper/om_file_helper.cc" | |||
"helper/model_helper.cc" | |||
"../model/ge_model.cc" | |||
"../model/ge_root_model.cc" | |||
"auth/file_saver.cc" | |||
"fp16_t.cc" | |||
"math/fp16_math.cc" | |||
@@ -129,6 +130,7 @@ target_compile_definitions(ge_common_static PRIVATE | |||
google=ascend_private | |||
$<IF:$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>,OS_TYPE=WIN,OS_TYPE=0> | |||
$<$<STREQUAL:${TARGET_SYSTEM_NAME},Windows>:SECUREC_USING_STD_SECURE_LIB=0 NOMINMAX> | |||
LOG_CPP | |||
) | |||
target_compile_options(ge_common_static PRIVATE | |||
@@ -177,12 +179,14 @@ target_compile_definitions(ge_common PRIVATE | |||
FMK_SUPPORT_DUMP | |||
OS_CENTOS | |||
google=ascend_private | |||
LOG_CPP | |||
) | |||
target_compile_options(ge_common PRIVATE | |||
-fvisibility=hidden | |||
-O2 | |||
-Werror | |||
-Wno-deprecated-declarations | |||
) | |||
target_include_directories(ge_common PRIVATE | |||
@@ -54,8 +54,8 @@ Status FileSaver::OpenFile(int32_t &fd, const std::string &file_path) { | |||
Status FileSaver::WriteData(const void *data, uint32_t size, int32_t fd) { | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(size == 0 || data == nullptr, return PARAM_INVALID); | |||
mmSsize_t write_count; | |||
uint32_t size_2g = ((uint32_t) 0x1 << 31); | |||
uint32_t size_1g = ((uint32_t) 0x1 << 30); | |||
uint32_t size_2g = 2147483648; // 0x1 << 31 | |||
uint32_t size_1g = 1073741824; // 0x1 << 30 | |||
// Write data | |||
if (size > size_2g) { | |||
auto seek = reinterpret_cast<uint8_t *>(const_cast<void *>(data)); | |||
@@ -258,6 +258,65 @@ FileSaver::SaveToFile(const string &file_path, ModelFileHeader &file_header, Mod | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status | |||
FileSaver::SaveToFile(const string &file_path, ModelFileHeader &file_header, | |||
vector<ModelPartitionTable *> &model_partition_tables, | |||
const vector<vector<ModelPartition>> &all_partition_datas) { | |||
file_header.is_encrypt = ModelEncryptType::UNENCRYPTED; | |||
const Status ret = SaveWithFileHeader(file_path, file_header, model_partition_tables, all_partition_datas); | |||
GE_CHK_BOOL_RET_STATUS(ret == SUCCESS, FAILED, "save file failed, file_path:%s, file header len:%u.", | |||
file_path.c_str(), file_header.length); | |||
return SUCCESS; | |||
} | |||
Status FileSaver::SaveWithFileHeader(const std::string &file_path, const ModelFileHeader &file_header, | |||
vector<ModelPartitionTable *> &model_partition_tables, | |||
const vector<vector<ModelPartition>> &all_partition_datas) { | |||
GE_CHK_BOOL_EXEC(model_partition_tables.size() == all_partition_datas.size(), | |||
return PARAM_INVALID, | |||
"model table size %zu does not match partition size %zu", | |||
model_partition_tables.size(), all_partition_datas.size()) | |||
for (size_t index = 0; index < model_partition_tables.size(); ++index) { | |||
auto &cur_partiton_data = all_partition_datas[index]; | |||
auto &cur_model_partition_table = *model_partition_tables[index]; | |||
GE_CHK_BOOL_RET_STATUS(!cur_partiton_data.empty() && cur_model_partition_table.num != 0 | |||
&& cur_model_partition_table.num == cur_partiton_data.size(), FAILED, | |||
"Invalid param:partition data size is (%u), model_partition_table.num is (%zu).", | |||
cur_model_partition_table.num, cur_partiton_data.size()); | |||
} | |||
// Open file | |||
int32_t fd = 0; | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(OpenFile(fd, file_path) != SUCCESS, return FAILED); | |||
Status ret = SUCCESS; | |||
do { | |||
// Write file header | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
WriteData(static_cast<const void *>(&file_header), sizeof(ModelFileHeader), fd) != SUCCESS, ret = FAILED; | |||
break); | |||
for (size_t index = 0; index < model_partition_tables.size(); ++index) { | |||
// Write model partition table | |||
auto &cur_tabel = *model_partition_tables[index]; | |||
uint32_t table_size = static_cast<uint32_t>(SIZE_OF_MODEL_PARTITION_TABLE(cur_tabel)); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
WriteData(static_cast<const void *>(&cur_tabel), table_size, fd) != SUCCESS, ret = FAILED; break); | |||
// Write partition data | |||
auto &cur_partition_datas = all_partition_datas[index]; | |||
for (const auto &partition_data : cur_partition_datas) { | |||
GELOGI("GC:size[%zu]", partition_data.size); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG( | |||
WriteData(static_cast<const void *>(partition_data.data), partition_data.size, fd) != SUCCESS, ret = FAILED; | |||
break); | |||
} | |||
} | |||
} while (0); | |||
// Close file | |||
GE_CHK_BOOL_RET_STATUS(mmClose(fd) == EN_OK, FAILED, "Close file failed."); | |||
return ret; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status FileSaver::SaveToFile(const string &file_path, const void *data, | |||
int len) { | |||
if (data == nullptr || len <= 0) { | |||
@@ -74,6 +74,10 @@ class FileSaver { | |||
ModelPartitionTable &model_partition_table, | |||
const std::vector<ModelPartition> &partition_datas); | |||
static Status SaveToFile(const string &file_path, ModelFileHeader &file_header, | |||
vector<ModelPartitionTable *> &model_partition_tables, | |||
const vector<vector<ModelPartition>> &all_partition_datas); | |||
static Status SaveToBuffWithFileHeader(const ModelFileHeader &file_header, | |||
ModelPartitionTable &model_partition_table, | |||
const std::vector<ModelPartition> &partitionDatas, | |||
@@ -108,6 +112,9 @@ class FileSaver { | |||
static Status SaveWithFileHeader(const std::string &file_path, const ModelFileHeader &file_header, | |||
ModelPartitionTable &model_partition_table, | |||
const std::vector<ModelPartition> &partition_datas); | |||
static Status SaveWithFileHeader(const std::string &file_path, const ModelFileHeader &file_header, | |||
vector<ModelPartitionTable *> &model_partition_tables, | |||
const vector<vector<ModelPartition>> &all_partition_datas); | |||
}; | |||
} // namespace ge | |||
#endif // GE_COMMON_AUTH_FILE_SAVER_H_ |
@@ -25,32 +25,38 @@ | |||
namespace ge { | |||
namespace { | |||
const char* kBase64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |||
"abcdefghijklmnopqrstuvwxyz" | |||
"0123456789+/"; | |||
const char *kBase64Chars = | |||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |||
"abcdefghijklmnopqrstuvwxyz" | |||
"0123456789+/"; | |||
const char kEqualSymbol = '='; | |||
const size_t kBase64CharsNum = 64; | |||
const size_t kThreeByteOneGroup = 3; | |||
const size_t kFourByteOneGroup = 4; | |||
} | |||
const size_t kThreeByteOneGroupIndex0 = 0; | |||
const size_t kThreeByteOneGroupIndex1 = 1; | |||
const size_t kThreeByteOneGroupIndex2 = 2; | |||
const size_t kFourByteOneGroupIndex0 = 0; | |||
const size_t kFourByteOneGroupIndex1 = 1; | |||
const size_t kFourByteOneGroupIndex2 = 2; | |||
const size_t kFourByteOneGroupIndex3 = 3; | |||
} // namespace | |||
namespace base64 { | |||
static inline bool IsBase64Char(const char &c) { | |||
return (isalnum(c) || (c == '+') || (c == '/')); | |||
} | |||
static inline bool IsBase64Char(const char &c) { return (isalnum(c) || (c == '+') || (c == '/')); } | |||
static std::string EncodeToBase64(const std::string &raw_data) { | |||
size_t encode_length = raw_data.size() / kThreeByteOneGroup * kFourByteOneGroup; | |||
encode_length += raw_data.size() % kThreeByteOneGroup == 0 ? 0 : kFourByteOneGroup; | |||
size_t raw_data_index = 0 ; | |||
size_t raw_data_index = 0; | |||
size_t encode_data_index = 0; | |||
std::string encode_data; | |||
encode_data.resize(encode_length); | |||
for (; raw_data_index + kThreeByteOneGroup <= raw_data.size(); raw_data_index += kThreeByteOneGroup) { | |||
auto char_1 = static_cast<uint8_t>(raw_data[raw_data_index]); | |||
auto char_2 = static_cast<uint8_t>(raw_data[raw_data_index + 1]); | |||
auto char_3 = static_cast<uint8_t>(raw_data[raw_data_index + 2]); | |||
auto char_2 = static_cast<uint8_t>(raw_data[raw_data_index + kThreeByteOneGroupIndex1]); | |||
auto char_3 = static_cast<uint8_t>(raw_data[raw_data_index + kThreeByteOneGroupIndex2]); | |||
encode_data[encode_data_index++] = kBase64Chars[char_1 >> 2u]; | |||
encode_data[encode_data_index++] = kBase64Chars[((char_1 << 4u) & 0x30) | (char_2 >> 4u)]; | |||
encode_data[encode_data_index++] = kBase64Chars[((char_2 << 2u) & 0x3c) | (char_3 >> 6u)]; | |||
@@ -80,8 +86,7 @@ static std::string EncodeToBase64(const std::string &raw_data) { | |||
#pragma GCC diagnostic ignored "-Wunused-function" | |||
static Status DecodeFromBase64(const std::string &base64_data, std::string &decode_data) { | |||
if (base64_data.size() % kFourByteOneGroup != 0) { | |||
GELOGE(PARAM_INVALID, "base64 data size must can be divided by 4, but given data size is %zu", | |||
base64_data.size()); | |||
GELOGE(PARAM_INVALID, "base64 data size must can be divided by 4, but given data size is %zu", base64_data.size()); | |||
return PARAM_INVALID; | |||
} | |||
decode_data.clear(); | |||
@@ -92,10 +97,10 @@ static Status DecodeFromBase64(const std::string &base64_data, std::string &deco | |||
return static_cast<uint8_t>(std::distance(kBase64Chars, char_pos)) & 0xff; | |||
}; | |||
for (std::size_t input_data_index = 0; input_data_index < base64_data_len; input_data_index += 4) { | |||
for (std::size_t input_data_index = 0; input_data_index < base64_data_len; input_data_index += kFourByteOneGroup) { | |||
for (size_t i = 0; i < kFourByteOneGroup; ++i) { | |||
if (base64_data[input_data_index + i] == kEqualSymbol && | |||
input_data_index >= base64_data_len - 4 && i > 1) { | |||
input_data_index >= base64_data_len - kFourByteOneGroup && i > 1) { | |||
byte_4[i] = kBase64CharsNum; | |||
} else if (IsBase64Char(base64_data[input_data_index + i])) { | |||
byte_4[i] = FindCharInBase64Chars(base64_data[input_data_index + i]); | |||
@@ -104,19 +109,23 @@ static Status DecodeFromBase64(const std::string &base64_data, std::string &deco | |||
return PARAM_INVALID; | |||
} | |||
} | |||
decode_data += static_cast<char>((byte_4[0] << 2u) + ((byte_4[1] & 0x30) >> 4u)); | |||
if (byte_4[2] >= kBase64CharsNum){ | |||
decode_data += | |||
static_cast<char>((byte_4[kFourByteOneGroupIndex0] << 2u) + ((byte_4[kFourByteOneGroupIndex1] & 0x30) >> 4u)); | |||
if (byte_4[kFourByteOneGroupIndex2] >= kBase64CharsNum) { | |||
break; | |||
} else if (byte_4[3] >= kBase64CharsNum) { | |||
decode_data += static_cast<char>(((byte_4[1] & 0x0f) << 4u) + ((byte_4[2] & 0x3c) >> 2u)); | |||
} else if (byte_4[kFourByteOneGroupIndex3] >= kBase64CharsNum) { | |||
decode_data += static_cast<char>(((byte_4[kFourByteOneGroupIndex1] & 0x0f) << 4u) + | |||
((byte_4[kFourByteOneGroupIndex2] & 0x3c) >> 2u)); | |||
break; | |||
} | |||
decode_data += static_cast<char>(((byte_4[1] & 0x0f) << 4u) + ((byte_4[2] & 0x3c) >> 2u)); | |||
decode_data += static_cast<char>(((byte_4[2] & 0x03) << 6u) + byte_4[3]); | |||
decode_data += static_cast<char>(((byte_4[kFourByteOneGroupIndex1] & 0x0f) << 4u) + | |||
((byte_4[kFourByteOneGroupIndex2] & 0x3c) >> 2u)); | |||
decode_data += | |||
static_cast<char>(((byte_4[kFourByteOneGroupIndex2] & 0x03) << 6u) + byte_4[kFourByteOneGroupIndex3]); | |||
} | |||
return SUCCESS; | |||
} | |||
#pragma GCC diagnostic pop | |||
} | |||
} // namespace base64 | |||
} // namespace ge | |||
#endif // GE_COMMON_BASE64_H_ |
@@ -139,7 +139,8 @@ int MemoryDumper::OpenFile(const char *filename) { | |||
GE_IF_BOOL_EXEC( | |||
-1 != path_split_pos, string prefix_path = std::string(filename).substr(0, path_split_pos); | |||
string last_path = std::string(filename).substr(path_split_pos, strlen(filename) - 1); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(prefix_path.length() >= MMPA_MAX_PATH, return kInvalidFd, "Prefix path is too long!"); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(prefix_path.length() >= MMPA_MAX_PATH, | |||
return kInvalidFd, "Prefix path is too long!"); | |||
GE_CHK_BOOL_TRUE_EXEC_WITH_LOG(mmRealPath(prefix_path.c_str(), tmp_path, MMPA_MAX_PATH) != EN_OK, return kInvalidFd, | |||
"Dir %s does not exit.", prefix_path.c_str()); | |||
real_path = std::string(tmp_path) + last_path;) | |||
@@ -23,12 +23,30 @@ | |||
#include "common/formats/utils/formats_trans_utils.h" | |||
#include "framework/common/debug/ge_log.h" | |||
#include "framework/common/debug/log.h" | |||
#include "framework/common/types.h" | |||
#include "graph/utils/type_utils.h" | |||
namespace ge { | |||
namespace formats { | |||
namespace { | |||
const int kDimSize4D = 4; | |||
const size_t kSingleDim = 1; | |||
const size_t kNdDimIndexN = 0; | |||
const size_t kNdDimIndexH = 1; | |||
const size_t kNdDimIndexW = 2; | |||
const size_t kDimDValueBNdFNz = 2; // dim d-value between Nd and FractalZz | |||
const size_t kNdDimCountBackwardsW = 1; | |||
const size_t kNdDimCountBackwardsWH = 2; | |||
const size_t kFNzDimCountBackwardsW0 = 1; | |||
const size_t kFNzDimCountBackwardsW0H0 = 2; | |||
const size_t kFNzDimCountBackwardsW0H0H1 = 3; | |||
const size_t kFNzDimCountBackwardsW0H0H1W1 = 4; | |||
bool IsDataTypeSupport(DataType data_type) { return GetSizeByDataType(data_type) > 0; } | |||
using ShapeVector = std::vector<int64_t>; | |||
@@ -60,14 +78,14 @@ Status TransShapeToFracNz(const ShapeVector &src_shape, DataType data_type, Shap | |||
auto w0 = GetCubeSizeByDataType(data_type); | |||
int64_t h0 = kCubeSize; | |||
switch (src_shape.size()) { | |||
case 1: | |||
dst_shape.push_back(Ceil(src_shape[0], w0)); | |||
dst_shape.push_back(1); | |||
case kSingleDim: | |||
dst_shape.push_back(Ceil(src_shape[kNdDimIndexN], w0)); | |||
dst_shape.push_back(DIM_DEFAULT_VALUE); | |||
dst_shape.push_back(h0); | |||
dst_shape.push_back(w0); | |||
hw_shape.push_back(1); | |||
hw_shape.push_back(1); | |||
hw_shape.push_back(src_shape[0]); | |||
hw_shape.push_back(DIM_DEFAULT_VALUE); | |||
hw_shape.push_back(DIM_DEFAULT_VALUE); | |||
hw_shape.push_back(src_shape[kNdDimIndexN]); | |||
if (!IsShapeValid(dst_shape)) { | |||
GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
return PARAM_INVALID; | |||
@@ -76,17 +94,17 @@ Status TransShapeToFracNz(const ShapeVector &src_shape, DataType data_type, Shap | |||
default: | |||
auto size = src_shape.size(); | |||
int64_t times = 1; | |||
for (size_t i = 0; i != size - 2; i++) { | |||
for (size_t i = 0; i != size - kDimDValueBNdFNz; i++) { | |||
dst_shape.push_back(src_shape[i]); | |||
times *= src_shape[i]; | |||
} | |||
dst_shape.push_back(Ceil(src_shape[size - 1], w0)); | |||
dst_shape.push_back(Ceil(src_shape[size - 2], h0)); | |||
dst_shape.push_back(Ceil(src_shape[size - kNdDimCountBackwardsW], w0)); | |||
dst_shape.push_back(Ceil(src_shape[size - kNdDimCountBackwardsWH], h0)); | |||
dst_shape.push_back(h0); | |||
dst_shape.push_back(w0); | |||
hw_shape.push_back(times); | |||
hw_shape.push_back(src_shape[size - 2]); | |||
hw_shape.push_back(src_shape[size - 1]); | |||
hw_shape.push_back(src_shape[size - kNdDimCountBackwardsWH]); | |||
hw_shape.push_back(src_shape[size - kNdDimCountBackwardsW]); | |||
if (!IsShapeValid(dst_shape)) { | |||
GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
return PARAM_INVALID; | |||
@@ -128,16 +146,16 @@ Status TransFormatFromNdToFracNz(const TransArgs &args, TransResult &result, con | |||
} | |||
// src&dst_shape can be written as times*H*W & times*W1*H1*H0*W0, respectively. dst_shape_size >= kDimNum4D | |||
auto times = hw_shape.at(0); | |||
auto h = hw_shape.at(1); | |||
auto w = hw_shape.at(2); | |||
auto times = hw_shape.at(kNdDimIndexN); | |||
auto h = hw_shape.at(kNdDimIndexH); | |||
auto w = hw_shape.at(kNdDimIndexW); | |||
auto hw = h * w; | |||
auto shape_size = args.dst_shape.size(); | |||
auto w1 = args.dst_shape[shape_size - 4]; | |||
auto h1 = args.dst_shape[shape_size - 3]; | |||
auto h0 = args.dst_shape[shape_size - 2]; | |||
auto w0 = args.dst_shape[shape_size - 1]; | |||
auto w1 = args.dst_shape[shape_size - kFNzDimCountBackwardsW0H0H1W1]; | |||
auto h1 = args.dst_shape[shape_size - kFNzDimCountBackwardsW0H0H1]; | |||
auto h0 = args.dst_shape[shape_size - kFNzDimCountBackwardsW0H0]; | |||
auto w0 = args.dst_shape[shape_size - kFNzDimCountBackwardsW0]; | |||
auto h1h0 = h1 * h0; | |||
auto h1h0w0 = h1h0 * w0; | |||
auto w1h1h0w0 = w1 * h1h0w0; | |||
@@ -198,16 +216,16 @@ Status TransFormatFromFracNzToNd(const TransArgs &args, TransResult &result, con | |||
return OUT_OF_MEMORY; | |||
} | |||
auto times = dst_hw_shape.at(0); | |||
auto h = dst_hw_shape.at(1); | |||
auto w = dst_hw_shape.at(2); | |||
auto times = dst_hw_shape.at(kNdDimIndexN); | |||
auto h = dst_hw_shape.at(kNdDimIndexH); | |||
auto w = dst_hw_shape.at(kNdDimIndexW); | |||
auto hw = h * w; | |||
auto shape_size = args.src_shape.size(); | |||
auto w1 = args.src_shape[shape_size - 4]; | |||
auto h1 = args.src_shape[shape_size - 3]; | |||
auto h0 = args.src_shape[shape_size - 2]; | |||
auto w0 = args.src_shape[shape_size - 1]; | |||
auto w1 = args.src_shape[shape_size - kFNzDimCountBackwardsW0H0H1W1]; | |||
auto h1 = args.src_shape[shape_size - kFNzDimCountBackwardsW0H0H1]; | |||
auto h0 = args.src_shape[shape_size - kFNzDimCountBackwardsW0H0]; | |||
auto w0 = args.src_shape[shape_size - kFNzDimCountBackwardsW0]; | |||
auto h1h0 = h1 * h0; | |||
auto h1h0w0 = h1h0 * w0; | |||
auto w1h1h0w0 = w1 * h1h0w0; | |||
@@ -23,12 +23,29 @@ | |||
#include "common/formats/utils/formats_trans_utils.h" | |||
#include "framework/common/debug/ge_log.h" | |||
#include "framework/common/debug/log.h" | |||
#include "framework/common/types.h" | |||
#include "graph/utils/type_utils.h" | |||
namespace ge { | |||
namespace formats { | |||
namespace { | |||
const int kDimSize4D = 4; | |||
const size_t kSingleDim = 1; | |||
const size_t kNdDimIndexN = 0; | |||
const size_t kNdDimIndexH = 1; | |||
const size_t kNdDimIndexW = 2; | |||
const size_t kDimDValueBNdFZz = 2; // dim d-value between Nd and FractalZz | |||
const size_t kNdDimCountBackwardsW = 1; | |||
const size_t kNdDimCountBackwardsWH = 2; | |||
const size_t kFZzDimCountBackwardsW0 = 1; | |||
const size_t kFZzDimCountBackwardsW0H0 = 2; | |||
const size_t kFZzDimCountBackwardsW0H0W1 = 3; | |||
const size_t kFZzDimCountBackwardsW0H0W1H1 = 4; | |||
bool IsDataTypeSupport(DataType d_type) { return GetSizeByDataType(d_type) > 0; } | |||
using ShapeVector = std::vector<int64_t>; | |||
@@ -40,8 +57,8 @@ bool CheckShape(Format format, const ShapeVector &shape) { | |||
case FORMAT_NHWC: | |||
return CheckShapeValid(shape, kDimSize4D); | |||
default: | |||
std::string error = "Trans format between " + FmtToStr(TypeUtils::FormatToSerialString(format)) + | |||
" and FORMAT_FRACTAL_ZZ is not supported."; | |||
std::string error = "Trans format between " + FmtToStr(TypeUtils::FormatToSerialString(format)) + | |||
" and FORMAT_FRACTAL_ZZ is not supported."; | |||
GE_ERRORLOG_AND_ERRORMSG(PARAM_INVALID, error.c_str()); | |||
return false; | |||
} | |||
@@ -60,14 +77,14 @@ Status TransShapeToFracZz(const ShapeVector &src_shape, DataType data_type, Shap | |||
auto w0 = GetCubeSizeByDataType(data_type); | |||
auto h0 = GetCubeSizeByDataType(data_type); | |||
switch (src_shape.size()) { | |||
case 1: | |||
dst_shape.push_back(1); | |||
dst_shape.push_back(Ceil(src_shape[0], w0)); | |||
case kSingleDim: | |||
dst_shape.push_back(DIM_DEFAULT_VALUE); | |||
dst_shape.push_back(Ceil(src_shape[kNdDimIndexN], w0)); | |||
dst_shape.push_back(h0); | |||
dst_shape.push_back(w0); | |||
hw_shape.push_back(1); | |||
hw_shape.push_back(1); | |||
hw_shape.push_back(src_shape[0]); | |||
hw_shape.push_back(DIM_DEFAULT_VALUE); | |||
hw_shape.push_back(DIM_DEFAULT_VALUE); | |||
hw_shape.push_back(src_shape[kNdDimIndexN]); | |||
if (!IsShapeValid(dst_shape)) { | |||
GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
return PARAM_INVALID; | |||
@@ -76,17 +93,17 @@ Status TransShapeToFracZz(const ShapeVector &src_shape, DataType data_type, Shap | |||
default: | |||
auto size = src_shape.size(); | |||
int64_t times = 1; | |||
for (size_t i = 0; i != size - 2; i++) { | |||
for (size_t i = 0; i != size - kDimDValueBNdFZz; i++) { | |||
dst_shape.push_back(src_shape[i]); | |||
times *= src_shape[i]; | |||
} | |||
dst_shape.push_back(Ceil(src_shape[size - 2], h0)); | |||
dst_shape.push_back(Ceil(src_shape[size - 1], w0)); | |||
dst_shape.push_back(Ceil(src_shape[size - kNdDimCountBackwardsWH], h0)); | |||
dst_shape.push_back(Ceil(src_shape[size - kNdDimCountBackwardsW], w0)); | |||
dst_shape.push_back(h0); | |||
dst_shape.push_back(w0); | |||
hw_shape.push_back(times); | |||
hw_shape.push_back(src_shape[size - 2]); | |||
hw_shape.push_back(src_shape[size - 1]); | |||
hw_shape.push_back(src_shape[size - kNdDimCountBackwardsWH]); | |||
hw_shape.push_back(src_shape[size - kNdDimCountBackwardsW]); | |||
if (!IsShapeValid(dst_shape)) { | |||
GELOGE(PARAM_INVALID, "Failed to check dst shape %s", ShapeToString(dst_shape).c_str()); | |||
return PARAM_INVALID; | |||
@@ -127,16 +144,16 @@ Status TransFormatFromNdToFracZz(const TransArgs &args, TransResult &result, con | |||
return OUT_OF_MEMORY; | |||
} | |||
// The src&dst_shape can be written as times*H*W & times*H1*W1*H0*W0, respectively. dst_shape_size >= kDimNum4D | |||
auto times = hw_shape.at(0); | |||
auto h = hw_shape.at(1); | |||
auto w = hw_shape.at(2); | |||
auto times = hw_shape.at(kNdDimIndexN); | |||
auto h = hw_shape.at(kNdDimIndexH); | |||
auto w = hw_shape.at(kNdDimIndexW); | |||
auto hw = h * w; | |||
auto shape_size = args.dst_shape.size(); | |||
auto h1 = args.dst_shape[shape_size - 4]; | |||
auto w1 = args.dst_shape[shape_size - 3]; | |||
auto h0 = args.dst_shape[shape_size - 2]; | |||
auto w0 = args.dst_shape[shape_size - 1]; | |||
auto h1 = args.dst_shape[shape_size - kFZzDimCountBackwardsW0H0W1H1]; | |||
auto w1 = args.dst_shape[shape_size - kFZzDimCountBackwardsW0H0W1]; | |||
auto h0 = args.dst_shape[shape_size - kFZzDimCountBackwardsW0H0]; | |||
auto w0 = args.dst_shape[shape_size - kFZzDimCountBackwardsW0]; | |||
auto h0w0 = h0 * w0; | |||
auto w1h0w0 = w1 * h0w0; | |||
auto h1w1h0w0 = h1 * w1h0w0; | |||
@@ -155,8 +172,8 @@ Status TransFormatFromNdToFracZz(const TransArgs &args, TransResult &result, con | |||
auto src_offset = (src_h_head + w1_idx * w0) * size; | |||
auto dst_offset = (h0_head + w1_idx * h0w0) * size; | |||
auto protected_size = dst_size - dst_offset < static_cast<int64_t>(SECUREC_MEM_MAX_LEN) | |||
? dst_size - dst_offset | |||
: static_cast<int64_t>(SECUREC_MEM_MAX_LEN); | |||
? dst_size - dst_offset | |||
: static_cast<int64_t>(SECUREC_MEM_MAX_LEN); | |||
auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
static_cast<size_t>(size * w0)); | |||
if (ret != EOK) { | |||
@@ -171,8 +188,8 @@ Status TransFormatFromNdToFracZz(const TransArgs &args, TransResult &result, con | |||
auto src_offset = (src_h_head + src_w_idx) * size; | |||
auto dst_offset = (w0_head + w0_idx) * size; | |||
auto protected_size = dst_size - dst_offset < static_cast<int64_t>(SECUREC_MEM_MAX_LEN) | |||
? dst_size - dst_offset | |||
: static_cast<int64_t>(SECUREC_MEM_MAX_LEN); | |||
? dst_size - dst_offset | |||
: static_cast<int64_t>(SECUREC_MEM_MAX_LEN); | |||
auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
static_cast<size_t>(size)); | |||
if (ret != EOK) { | |||
@@ -205,16 +222,16 @@ Status TransFormatFromFracZzToNd(const TransArgs &args, TransResult &result, con | |||
} | |||
// The src&dst_shape can be written as times*H*W & times*H1*W1*H0*W0, respectively. dst_shape_size >= kDimNum4D | |||
auto times = dst_hw_shape.at(0); | |||
auto h = dst_hw_shape.at(1); | |||
auto w = dst_hw_shape.at(2); | |||
auto times = dst_hw_shape.at(kNdDimIndexN); | |||
auto h = dst_hw_shape.at(kNdDimIndexH); | |||
auto w = dst_hw_shape.at(kNdDimIndexW); | |||
auto hw = h * w; | |||
auto shape_size = args.src_shape.size(); | |||
auto h1 = args.src_shape[shape_size - 4]; | |||
auto w1 = args.src_shape[shape_size - 3]; | |||
auto h0 = args.src_shape[shape_size - 2]; | |||
auto w0 = args.src_shape[shape_size - 1]; | |||
auto h1 = args.src_shape[shape_size - kFZzDimCountBackwardsW0H0W1H1]; | |||
auto w1 = args.src_shape[shape_size - kFZzDimCountBackwardsW0H0W1]; | |||
auto h0 = args.src_shape[shape_size - kFZzDimCountBackwardsW0H0]; | |||
auto w0 = args.src_shape[shape_size - kFZzDimCountBackwardsW0]; | |||
auto h0w0 = h0 * w0; | |||
auto w1h0w0 = w1 * h0w0; | |||
auto h1w1h0w0 = h1 * w1h0w0; | |||
@@ -233,8 +250,8 @@ Status TransFormatFromFracZzToNd(const TransArgs &args, TransResult &result, con | |||
auto src_offset = (h0_head + w1_idx * h0w0) * size; | |||
auto dst_offset = (dst_h_head + w1_idx * w0) * size; | |||
auto protected_size = dst_size - dst_offset < static_cast<int64_t>(SECUREC_MEM_MAX_LEN) | |||
? dst_size - dst_offset | |||
: static_cast<int64_t>(SECUREC_MEM_MAX_LEN); | |||
? dst_size - dst_offset | |||
: static_cast<int64_t>(SECUREC_MEM_MAX_LEN); | |||
auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
static_cast<size_t>(size * w0)); | |||
if (ret != EOK) { | |||
@@ -249,8 +266,8 @@ Status TransFormatFromFracZzToNd(const TransArgs &args, TransResult &result, con | |||
auto dst_w_idx = w1_head + w0_idx; | |||
auto dst_offset = (dst_h_head + dst_w_idx) * size; | |||
auto protected_size = dst_size - dst_offset < static_cast<int64_t>(SECUREC_MEM_MAX_LEN) | |||
? dst_size - dst_offset | |||
: static_cast<int64_t>(SECUREC_MEM_MAX_LEN); | |||
? dst_size - dst_offset | |||
: static_cast<int64_t>(SECUREC_MEM_MAX_LEN); | |||
auto ret = memcpy_s(dst.get() + dst_offset, static_cast<size_t>(protected_size), args.data + src_offset, | |||
static_cast<size_t>(size)); | |||
if (ret != EOK) { | |||
@@ -35,7 +35,6 @@ | |||
* Padding to (N, ceil(Z/16)*16) | |||
* Last Step: View the (N, ceil(Z/16)*16) as 4D (N/16, 16, C/16, 16) and transpose to (C/16, N/16, 16, 16) | |||
*/ | |||
namespace ge { | |||
namespace formats { | |||
namespace { | |||
@@ -19,6 +19,7 @@ | |||
#include <securec.h> | |||
#include <memory> | |||
#include "common/formats/utils/formats_definitions.h" | |||
#include "common/formats/utils/formats_trans_utils.h" | |||
#include "framework/common/debug/ge_log.h" | |||
#include "framework/common/debug/log.h" | |||
@@ -29,21 +30,21 @@ namespace formats { | |||
namespace { | |||
std::map<Format, std::map<Format, std::vector<int64_t>>> perm_args{ | |||
{FORMAT_NCHW, | |||
{{FORMAT_NHWC, std::vector<int64_t>({0, 2, 3, 1})}, | |||
{FORMAT_HWCN, std::vector<int64_t>({2, 3, 1, 0})}, | |||
{FORMAT_CHWN, std::vector<int64_t>({1, 2, 3, 0})}}}, | |||
{{FORMAT_NHWC, std::vector<int64_t>({kNchwN, kNchwH, kNchwW, kNchwC})}, | |||
{FORMAT_HWCN, std::vector<int64_t>({kNchwH, kNchwW, kNchwC, kNchwN})}, | |||
{FORMAT_CHWN, std::vector<int64_t>({kNchwC, kNchwH, kNchwW, kNchwN})}}}, | |||
{FORMAT_NHWC, | |||
{{FORMAT_NCHW, std::vector<int64_t>({0, 3, 1, 2})}, | |||
{FORMAT_CHWN, std::vector<int64_t>({3, 1, 2, 0})}, | |||
{FORMAT_HWCN, std::vector<int64_t>({1, 2, 3, 0})}}}, | |||
{{FORMAT_NCHW, std::vector<int64_t>({kNhwcN, kNhwcC, kNhwcH, kNhwcW})}, | |||
{FORMAT_CHWN, std::vector<int64_t>({kNhwcC, kNhwcH, kNhwcW, kNhwcN})}, | |||
{FORMAT_HWCN, std::vector<int64_t>({kNhwcH, kNhwcW, kNhwcC, kNhwcN})}}}, | |||
{FORMAT_HWCN, | |||
{{FORMAT_NCHW, std::vector<int64_t>({3, 2, 0, 1})}, | |||
{FORMAT_NHWC, std::vector<int64_t>({3, 0, 1, 2})}, | |||
{FORMAT_CHWN, std::vector<int64_t>({2, 0, 1, 3})}}}, | |||
{{FORMAT_NCHW, std::vector<int64_t>({kHwcnN, kHwcnC, kHwcnH, kHwcnW})}, | |||
{FORMAT_NHWC, std::vector<int64_t>({kHwcnN, kHwcnH, kHwcnW, kHwcnC})}, | |||
{FORMAT_CHWN, std::vector<int64_t>({kHwcnC, kHwcnH, kHwcnW, kHwcnN})}}}, | |||
{FORMAT_CHWN, | |||
{{FORMAT_NCHW, std::vector<int64_t>({3, 0, 1, 2})}, | |||
{FORMAT_NHWC, std::vector<int64_t>({3, 1, 2, 0})}, | |||
{FORMAT_HWCN, std::vector<int64_t>({1, 2, 0, 3})}}}, | |||
{{FORMAT_NCHW, std::vector<int64_t>({kChwnN, kChwnC, kChwnH, kChwnW})}, | |||
{FORMAT_NHWC, std::vector<int64_t>({kChwnN, kChwnH, kChwnW, kChwnC})}, | |||
{FORMAT_HWCN, std::vector<int64_t>({kChwnH, kChwnW, kChwnC, kChwnN})}}}, | |||
}; | |||
bool IsShapeArgValid(const std::vector<int64_t> &src_shape, const std::vector<int64_t> &perm_arg) { | |||
@@ -23,6 +23,7 @@ static const int kCubeSize = 16; | |||
static const int kNiSize = 16; | |||
static const int64_t kShapeItemNumMAX = 1024UL * 1024UL * 1024UL * 1024UL; | |||
enum NchwDimIndex { | |||
kNchwN, | |||
kNchwC, | |||
@@ -47,6 +48,14 @@ enum HwcnDimIndex { | |||
kHwcnDimsNum | |||
}; | |||
enum ChwnDimIndex { | |||
kChwnC, | |||
kChwnH, | |||
kChwnW, | |||
kChwnN, | |||
kChwnDimsNum | |||
}; | |||
enum Nc1hwc0DimIndex { | |||
kNc1hwc0N, | |||
kNc1hwc0C1, | |||
@@ -123,7 +123,10 @@ Status PluginManager::LoadSo(const string &path, const vector<string> &func_chec | |||
if (handle == nullptr) { | |||
const char *error = mmDlerror(); | |||
GE_IF_BOOL_EXEC(error == nullptr, error = ""); | |||
GELOGE(GE_PLGMGR_PATH_INVALID, "Failed to dlopen %s!", error); | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19012", {"function", "reason"}, | |||
{"mmDlopen", "shared library path is " + FmtToStr(file_path_dlopen) + ". Errormessage" + FmtToStr(error)}); | |||
GELOGE(GE_PLGMGR_PATH_INVALID, "Failed to dlopen the shared library path[%s]. Errormessage[%s]!", | |||
file_path_dlopen.c_str(), error); | |||
continue; | |||
} | |||
@@ -132,6 +135,9 @@ Status PluginManager::LoadSo(const string &path, const vector<string> &func_chec | |||
for (const auto &func_name : func_check_list) { | |||
auto real_fn = (void (*)())mmDlsym(handle, const_cast<char *>(func_name.c_str())); | |||
if (real_fn == nullptr) { | |||
ErrorManager::GetInstance().ATCReportErrMessage("E19012", {"function", "reason"}, | |||
{"mmDlsym", FmtToStr(func_name) + " is skipped since function" + | |||
FmtToStr(func_name) + " is not existed!"}); | |||
GELOGE(GE_PLGMGR_PATH_INVALID, "%s is skipped since function %s is not existed!", func_name.c_str(), | |||
func_name.c_str()); | |||
is_valid = false; | |||
@@ -37,6 +37,8 @@ | |||
#include "graph/utils/type_utils.h" | |||
namespace ge { | |||
const int kBaseInt = 10; | |||
std::map<string, string> TBEPluginManager::options_ = {}; | |||
// Get Singleton Instance | |||
@@ -155,7 +157,7 @@ void TBEPluginManager::GetCustomOpPath(std::string &customop_path) { | |||
domi::FrameworkType type = domi::TENSORFLOW; | |||
auto it = options_.find(FRAMEWORK_TYPE); | |||
if (it != options_.end()) { | |||
type = static_cast<domi::FrameworkType>(std::strtol(it->second.c_str(), nullptr, 10)); | |||
type = static_cast<domi::FrameworkType>(std::strtol(it->second.c_str(), nullptr, kBaseInt)); | |||
} | |||
fmk_type = ge::TypeUtils::FmkTypeToSerialString(type); | |||
GELOGI("Framework type is %s.", fmk_type.c_str()); | |||
@@ -179,12 +181,19 @@ void TBEPluginManager::GetCustomOpPath(std::string &customop_path) { | |||
void TBEPluginManager::LoadCustomOpLib() { | |||
LoadPluginSo(options_); | |||
std::string fmk_type = std::to_string(domi::TENSORFLOW); | |||
auto it = options_.find(ge::FRAMEWORK_TYPE); | |||
if (it != options_.end()) { | |||
fmk_type = it->second; | |||
} | |||
std::vector<OpRegistrationData> registration_datas = domi::OpRegistry::Instance()->registrationDatas; | |||
GELOGI("The size of registration_datas is: %zu", registration_datas.size()); | |||
for (OpRegistrationData reg_data : registration_datas) { | |||
GELOGD("Begin to register optype: %s, imply_type: %s", reg_data.GetOmOptype().c_str(), | |||
TypeUtils::ImplyTypeToSerialString(reg_data.GetImplyType()).c_str()); | |||
domi::OpRegistry::Instance()->Register(reg_data); | |||
if (std::to_string(reg_data.GetFrameworkType()) == fmk_type) { | |||
GELOGD("Begin to register optype: %s, imply_type: %s", reg_data.GetOmOptype().c_str(), | |||
TypeUtils::ImplyTypeToSerialString(reg_data.GetImplyType()).c_str()); | |||
domi::OpRegistry::Instance()->Register(reg_data); | |||
} | |||
} | |||
} | |||
@@ -7,6 +7,7 @@ GE_COMMON_LOCAL_SRC_FILES := \ | |||
helper/om_file_helper.cc \ | |||
helper/model_helper.cc \ | |||
../model/ge_model.cc \ | |||
../model/ge_root_model.cc \ | |||
auth/file_saver.cc \ | |||
fp16_t.cc \ | |||
math/fp16_math.cc \ | |||
@@ -32,6 +32,7 @@ using domi::ModelTaskDef; | |||
namespace { | |||
const int64_t kOriginalOmPartitionNum = 1; | |||
const uint32_t kStatiOmFileModelNum = 1; | |||
} | |||
@@ -39,7 +40,7 @@ namespace ge { | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelHelper::~ModelHelper() { (void)ReleaseLocalModelData(); } | |||
Status ModelHelper::SaveModelPartition(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, ModelPartitionType type, | |||
const uint8_t *data, size_t size) { | |||
const uint8_t *data, size_t size, size_t model_index) { | |||
if (size < 1 || size > UINT32_MAX) { | |||
GELOGE(PARAM_INVALID, "Add model partition failed, partition size %zu invalid", size); | |||
if (size > UINT32_MAX) { | |||
@@ -68,25 +69,16 @@ Status ModelHelper::SaveModelPartition(std::shared_ptr<OmFileSaveHelper> &om_fil | |||
partition_model.data = const_cast<uint8_t *>(data); | |||
partition_model.size = static_cast<uint32_t>(size); | |||
partition_model.type = type; | |||
if (om_file_save_helper->AddPartition(partition_model) != SUCCESS) { | |||
if (om_file_save_helper->AddPartition(partition_model, model_index) != SUCCESS) { | |||
GELOGE(PARAM_INVALID, "Add model partition failed, partition size %zu", size); | |||
return PARAM_INVALID; | |||
} | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmModel(const GeModelPtr &ge_model, | |||
const SaveParam &save_param, | |||
const std::string &output_file, | |||
ModelBufferData& model) { | |||
if (output_file.empty()) { | |||
GELOGE(FAILED, "GraphBuilder SaveModel received invalid file name prefix"); | |||
return FAILED; | |||
} | |||
GE_IF_BOOL_EXEC(ge_model == nullptr, GELOGE(FAILED, "Ge_model is nullptr"); return FAILED); | |||
std::shared_ptr<OmFileSaveHelper> om_file_save_helper = ge::MakeShared<OmFileSaveHelper>(); | |||
GE_CHECK_NOTNULL(om_file_save_helper); | |||
Status ModelHelper::SaveModelDef(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, | |||
const GeModelPtr &ge_model, ge::Buffer &model_buffer, size_t model_index) { | |||
ModelPtr model_tmp = ge::MakeShared<ge::Model>(ge_model->GetName(), ge_model->GetPlatformVersion()); | |||
if (model_tmp == nullptr) { | |||
GELOGE(FAILED, "Create Model %s Ptr failed", ge_model->GetName().c_str()); | |||
@@ -96,16 +88,21 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod | |||
model_tmp->SetVersion(ge_model->GetVersion()); | |||
model_tmp->SetAttr(ge_model->MutableAttrMap()); | |||
ge::Buffer model_buffer; | |||
(void)model_tmp->Save(model_buffer); | |||
GELOGD("MODEL_DEF size is %zu", model_buffer.GetSize()); | |||
if (model_buffer.GetSize() > 0) { | |||
if (SaveModelPartition(om_file_save_helper, ModelPartitionType::MODEL_DEF, model_buffer.GetData(), | |||
model_buffer.GetSize()) != SUCCESS) { | |||
model_buffer.GetSize(), model_index) != SUCCESS) { | |||
GELOGE(PARAM_INVALID, "Add model graph partition failed"); | |||
return PARAM_INVALID; | |||
} | |||
} | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::SaveModelWeights(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, | |||
const GeModelPtr &ge_model, size_t model_index) { | |||
auto ge_model_weight = ge_model->GetWeight(); | |||
GELOGD("WEIGHTS_DATA size is %zu, %p", ge_model_weight.GetSize(), ge_model_weight.GetData()); | |||
// weight is not necessary | |||
@@ -113,31 +110,43 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod | |||
GE_CHK_STATUS_RET(SaveModelPartition(om_file_save_helper, | |||
ModelPartitionType::WEIGHTS_DATA, | |||
ge_model_weight.GetData(), | |||
ge_model_weight.GetSize()), "Add weight partition failed"); | |||
ge_model_weight.GetSize(), model_index), "Add weight partition failed"); | |||
} | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::SaveModelTbeKernel(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, | |||
const GeModelPtr &ge_model, size_t model_index) { | |||
TBEKernelStore tbe_kernel_store = ge_model->GetTBEKernelStore(); | |||
GELOGD("TBE_KERNELS size is %zu", tbe_kernel_store.DataSize()); | |||
if (tbe_kernel_store.DataSize() > 0) { | |||
GE_CHK_STATUS_RET(SaveModelPartition(om_file_save_helper, | |||
ModelPartitionType::TBE_KERNELS, | |||
tbe_kernel_store.Data(), | |||
tbe_kernel_store.DataSize()), "Add tbe kernel partition failed"); | |||
GE_CHK_STATUS_RET( | |||
SaveModelPartition(om_file_save_helper, ModelPartitionType::TBE_KERNELS, | |||
ge_model->GetTBEKernelStore().Data(), ge_model->GetTBEKernelStore().DataSize(), | |||
model_index), "Add tbe kernel partition failed"); | |||
} | |||
// no need to check value, DATA->NetOutput | |||
(void)tbe_kernel_store.Load(tbe_kernel_store.Data(), tbe_kernel_store.DataSize()); | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::SaveModelCustAICPU(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, | |||
const GeModelPtr &ge_model, size_t model_index) { | |||
CustAICPUKernelStore cust_aicpu_kernel_store = ge_model->GetCustAICPUKernelStore(); | |||
GELOGD("cust aicpu kernels size is %zu", cust_aicpu_kernel_store.DataSize()); | |||
if (cust_aicpu_kernel_store.DataSize() > 0) { | |||
GE_CHK_STATUS_RET(SaveModelPartition(om_file_save_helper, | |||
ModelPartitionType::CUST_AICPU_KERNELS, | |||
cust_aicpu_kernel_store.Data(), | |||
cust_aicpu_kernel_store.DataSize()), | |||
ge_model->GetCustAICPUKernelStore().Data(), | |||
cust_aicpu_kernel_store.DataSize(), model_index), | |||
"Add cust aicpu kernel partition failed"); | |||
} | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::SaveModelTaskDef(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, | |||
const GeModelPtr &ge_model, ge::Buffer &task_buffer, size_t model_index) { | |||
std::shared_ptr<ModelTaskDef> model_task_def = ge_model->GetModelTaskDefPtr(); | |||
if (model_task_def == nullptr) { | |||
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Create model task def ptr failed"); | |||
@@ -146,9 +155,9 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod | |||
size_t partition_task_size = model_task_def->ByteSizeLong(); | |||
GE_IF_BOOL_EXEC(partition_task_size == 0 || partition_task_size > INT_MAX, | |||
GELOGE(FAILED, "Model_def's byte size (%zu) is invalid!", partition_task_size); | |||
return FAILED); | |||
return FAILED); | |||
ge::Buffer task_buffer(partition_task_size); | |||
task_buffer = ge::Buffer(partition_task_size); | |||
if (task_buffer.GetSize() == 0) { | |||
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "Alloc model task def buffer failed"); | |||
return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
@@ -159,21 +168,28 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod | |||
GELOGD("TASK_INFO size is %zu", partition_task_size); | |||
if (SaveModelPartition(om_file_save_helper, ModelPartitionType::TASK_INFO, task_buffer.GetData(), | |||
partition_task_size) != SUCCESS) { | |||
partition_task_size, model_index) != SUCCESS) { | |||
GELOGE(PARAM_INVALID, "Add model task def partition failed"); | |||
return PARAM_INVALID; | |||
} | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::SaveModelHeader(std::shared_ptr<OmFileSaveHelper> &om_file_save_helper, | |||
const GeModelPtr &ge_model, size_t model_num) { | |||
// Save target/version to model_header | |||
ModelFileHeader &model_header = om_file_save_helper->GetModelFileHeader(); | |||
model_header.platform_type = ge_model->GetPlatformType(); | |||
model_header.om_ir_version = ge_model->GetVersion(); | |||
model_header.model_num = model_num; | |||
std::string platform_version = ge_model->GetPlatformVersion(); | |||
errno_t err; | |||
err = memcpy_s(model_header.platform_version, PLATFORM_VERSION_LEN, platform_version.c_str(), | |||
platform_version.size() + 1); | |||
if (err != EOK) { | |||
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "ModelHelper SaveModel failed while allocating memory for platform_version."); | |||
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, | |||
"ModelHelper SaveModel failed while allocating memory for platform_version."); | |||
return ACL_ERROR_GE_MEMORY_ALLOCATION; | |||
} | |||
string version = reinterpret_cast<char *>(model_header.platform_version); | |||
@@ -188,8 +204,142 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmMod | |||
} | |||
string model_name = reinterpret_cast<char *>(model_header.name); | |||
GELOGD("Model name save:%s", model_name.c_str()); | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::SaveAllModelPartiton(std::shared_ptr<OmFileSaveHelper>& om_file_save_helper, | |||
const GeModelPtr &ge_model, ge::Buffer &model_buffer, | |||
ge::Buffer &task_buffer, size_t model_index) { | |||
if (SaveModelDef(om_file_save_helper, ge_model, model_buffer, model_index) != SUCCESS) { | |||
GELOGE(FAILED, "save model def failed"); | |||
return FAILED; | |||
} | |||
if (SaveModelWeights(om_file_save_helper, ge_model, model_index) != SUCCESS) { | |||
GELOGE(FAILED, "save model weights failed"); | |||
return FAILED; | |||
} | |||
if (SaveModelTbeKernel(om_file_save_helper, ge_model, model_index) != SUCCESS) { | |||
GELOGE(FAILED, "save model tbe kernel failed"); | |||
return FAILED; | |||
} | |||
if (SaveModelCustAICPU(om_file_save_helper, ge_model, model_index) != SUCCESS) { | |||
GELOGE(FAILED, "save model cust ai cpu failed"); | |||
return FAILED; | |||
} | |||
if (SaveModelTaskDef(om_file_save_helper, ge_model, task_buffer, model_index) != SUCCESS) { | |||
GELOGE(FAILED, "save task def failed"); | |||
return FAILED; | |||
} | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmModel(const GeModelPtr &ge_model, | |||
const SaveParam &save_param, | |||
const std::string &output_file, | |||
ModelBufferData& model) { | |||
if (output_file.empty()) { | |||
GELOGE(FAILED, "GraphBuilder SaveModel received invalid file name prefix"); | |||
return FAILED; | |||
} | |||
Status ret = om_file_save_helper->SaveModel(save_param, output_file.c_str(), model, is_offline_); | |||
GE_IF_BOOL_EXEC(ge_model == nullptr, GELOGE(FAILED, "Ge_model is nullptr"); return FAILED); | |||
std::shared_ptr<OmFileSaveHelper> om_file_save_helper = ge::MakeShared<OmFileSaveHelper>(); | |||
GE_CHECK_NOTNULL(om_file_save_helper); | |||
ge::Buffer model_buffer; | |||
ge::Buffer task_buffer; | |||
auto ret = SaveAllModelPartiton(om_file_save_helper, ge_model, model_buffer, task_buffer); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "save all model partition failed"); | |||
return ret; | |||
} | |||
ret = SaveModelHeader(om_file_save_helper, ge_model); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "save model header failed"); | |||
return ret; | |||
} | |||
ret = om_file_save_helper->SaveModel(save_param, output_file.c_str(), model, is_offline_); | |||
if (ret != SUCCESS) { | |||
GELOGE(FAILED, "OmFileSaveHelper SaveModel return fail."); | |||
return ret; | |||
} | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::SaveToOmRootModel( | |||
const GeRootModelPtr &ge_root_model, | |||
const SaveParam &save_param, | |||
const std::string &output_file, | |||
ModelBufferData& model, | |||
bool is_unknown_shape) { | |||
GE_CHECK_NOTNULL(ge_root_model); | |||
GE_IF_BOOL_EXEC(ge_root_model == nullptr, GELOGE(FAILED, "Ge_root_model is nullptr"); return FAILED); | |||
auto &name_to_ge_model = ge_root_model->GetSubgraphInstanceNameToModel(); | |||
GE_IF_BOOL_EXEC(name_to_ge_model.empty(), GELOGE(FAILED, "Ge_root_model has no sub model"); return FAILED); | |||
GE_IF_BOOL_EXEC(output_file.empty(), | |||
GELOGE(FAILED, "GraphBuilder SaveModel received invalid file name prefix"); | |||
return FAILED); | |||
if (!is_unknown_shape) { | |||
auto &model_root = name_to_ge_model.begin()->second; | |||
return SaveToOmModel(model_root, save_param, output_file, model); | |||
} | |||
std::shared_ptr<OmFileSaveHelper> om_file_save_helper = ge::MakeShared<OmFileSaveHelper>(); | |||
GE_CHECK_NOTNULL(om_file_save_helper); | |||
auto &first_ge_model = name_to_ge_model.at(ge_root_model->GetRootGraph()->GetName()); | |||
// ge root model must be the first to be loaded | |||
vector<string> model_names{ge_root_model->GetRootGraph()->GetName()}; | |||
for (auto &item : name_to_ge_model) { | |||
if (item.first != model_names.front()) { | |||
model_names.emplace_back(item.first); | |||
} | |||
} | |||
vector<ge::Buffer> model_buffers(model_names.size()); | |||
vector<ge::Buffer> task_buffers(model_names.size()); | |||
size_t cur_index = 0; | |||
if (model_names.size() > 1) { | |||
GELOGD("only save first model MODEL_DEF"); | |||
if (SaveModelDef(om_file_save_helper, first_ge_model, model_buffers[cur_index], cur_index) != SUCCESS) { | |||
GELOGE(FAILED, "save model def failed"); | |||
return FAILED; | |||
} | |||
++cur_index; | |||
} | |||
for (; cur_index < model_names.size(); ++cur_index) { | |||
auto model_name = model_names[cur_index]; | |||
GELOGD("cur model %s index is %zu", model_name.c_str(), cur_index); | |||
const GeModelPtr &ge_model = name_to_ge_model.at(model_name); | |||
auto ret = SaveAllModelPartiton(om_file_save_helper, ge_model, model_buffers[cur_index], | |||
task_buffers[cur_index], cur_index); | |||
if (ret != SUCCESS) { | |||
GELOGE(INTERNAL_ERROR, "Save model %s failed", model_name.c_str()); | |||
return INTERNAL_ERROR; | |||
} | |||
} | |||
auto ret = SaveModelHeader(om_file_save_helper, first_ge_model, model_names.size()); | |||
if (ret != SUCCESS) { | |||
GELOGE(INTERNAL_ERROR, "Save model %s header failed", first_ge_model->GetName().c_str()); | |||
return INTERNAL_ERROR; | |||
} | |||
ret = om_file_save_helper->SaveRootModel(save_param, output_file.c_str(), model, is_offline_); | |||
if (ret != SUCCESS) { | |||
GELOGE(FAILED, "OmFileSaveHelper SaveModel return fail."); | |||
return FAILED; | |||
@@ -288,7 +438,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadModel(c | |||
} | |||
file_header_ = reinterpret_cast<ModelFileHeader *>(model_data.model_data); | |||
OmFileLoadHelper om_load_helper; | |||
status = om_load_helper.Init(model_addr_tmp_, model_len_tmp_); | |||
if (status != SUCCESS) { | |||
@@ -310,7 +459,61 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadModel(c | |||
GELOGE(status, "GenerateGeModel failed"); | |||
return status; | |||
} | |||
GELOGD("in ModelHelper::LoadModel, is_assign_model_ is setted to true!"); | |||
is_assign_model_ = true; | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadRootModel(const ge::ModelData &model_data) { | |||
if (model_data.model_data == nullptr || model_data.model_len == 0) { | |||
GELOGE(GE_EXEC_MODEL_DATA_SIZE_INVALID, "Model_data is nullptr, or model_data_size is 0"); | |||
return GE_EXEC_MODEL_DATA_SIZE_INVALID; | |||
} | |||
if (is_assign_model_) { | |||
GELOGE(GE_EXEC_LOAD_MODEL_REPEATED, "Model helper has already loaded!"); | |||
return GE_EXEC_LOAD_MODEL_REPEATED; | |||
} | |||
if (ReleaseLocalModelData() != SUCCESS) { | |||
GELOGE(INTERNAL_ERROR, "ReleaseLocalModelData failed."); | |||
return INTERNAL_ERROR; | |||
} | |||
Status status = ge::DavinciModelParser::ParseModelContent(model_data, model_addr_tmp_, model_len_tmp_); | |||
if (status != SUCCESS) { | |||
GELOGE(status, "Parse model content failed!"); | |||
return status; | |||
} | |||
file_header_ = reinterpret_cast<ModelFileHeader *>(model_data.model_data); | |||
//model verison 1.0 file header does not have model_num member | |||
is_unknown_shape_model_ = file_header_->version >= ge::MODEL_VERSION && | |||
file_header_->model_num > kStatiOmFileModelNum; | |||
GELOGD("cur om model is ge root model or no %d, model version %zu", is_unknown_shape_model_, file_header_->version); | |||
OmFileLoadHelper om_load_helper; | |||
if (is_unknown_shape_model_) { | |||
auto model_num = file_header_->model_num; | |||
status = om_load_helper.Init(model_addr_tmp_, model_len_tmp_, model_num); | |||
} else { | |||
status = om_load_helper.Init(model_addr_tmp_, model_len_tmp_); | |||
} | |||
if (status != SUCCESS) { | |||
GELOGE(status, "Om_load_helper init failed"); | |||
model_addr_tmp_ = nullptr; | |||
return status; | |||
} | |||
// Encrypt model need to del temp model/no encrypt model don't need to del model | |||
model_addr_tmp_ = nullptr; | |||
status = GenerateGeRootModel(om_load_helper); | |||
if (status != SUCCESS) { | |||
GELOGE(status, "GenerateGeRootModel failed"); | |||
return status; | |||
} | |||
GELOGD("in ModelHelper::LoadRootModel, is_assign_model_ is setted to true!"); | |||
is_assign_model_ = true; | |||
return SUCCESS; | |||
} | |||
@@ -341,6 +544,61 @@ Status ModelHelper::GenerateGeModel(OmFileLoadHelper &om_load_helper) { | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::GenerateGeRootModel(OmFileLoadHelper &om_load_helper) { | |||
GELOGD("Begin to generate ge root model"); | |||
root_model_ = ge::MakeShared<ge::GeRootModel>(); | |||
GE_CHECK_NOTNULL(root_model_); | |||
if (!is_unknown_shape_model_) { | |||
if (GenerateGeModel(om_load_helper) != SUCCESS) { | |||
GELOGE(FAILED, "GenerateGeModel failed"); | |||
return FAILED; | |||
} | |||
GE_CHECK_NOTNULL(model_); | |||
root_model_->SetRootGraph(GraphUtils::GetComputeGraph(model_->GetGraph())); | |||
return SUCCESS; | |||
} | |||
bool is_first_model = true; | |||
for (size_t mode_index = 0; mode_index < file_header_->model_num; ++mode_index) { | |||
GeModelPtr cur_model = ge::MakeShared<ge::GeModel>(); | |||
Status ret = LoadModelData(om_load_helper, cur_model, mode_index); | |||
if (ret != SUCCESS) { | |||
return GE_EXEC_LOAD_MODEL_PARTITION_FAILED; | |||
} | |||
if (is_first_model) { | |||
is_first_model = false; | |||
root_model_->SetRootGraph(GraphUtils::GetComputeGraph(cur_model->GetGraph())); | |||
root_model_->SetModelId(cur_model->GetModelId()); | |||
model_ = cur_model; | |||
continue; | |||
} | |||
ret = LoadWeights(om_load_helper, cur_model, mode_index); | |||
if (ret != SUCCESS) { | |||
return GE_EXEC_LOAD_WEIGHT_PARTITION_FAILED; | |||
} | |||
ret = LoadTBEKernelStore(om_load_helper, cur_model, mode_index); | |||
if (ret != SUCCESS) { | |||
return GE_EXEC_LOAD_KERNEL_PARTITION_FAILED; | |||
} | |||
ret = LoadCustAICPUKernelStore(om_load_helper, cur_model, mode_index); | |||
if (ret != SUCCESS) { | |||
return GE_EXEC_LOAD_KERNEL_PARTITION_FAILED; | |||
} | |||
ret = LoadTask(om_load_helper, cur_model, mode_index); | |||
if (ret != SUCCESS) { | |||
return GE_EXEC_LOAD_TASK_PARTITION_FAILED; | |||
} | |||
root_model_->SetSubgraphInstanceNameToModel(cur_model->GetName(), cur_model); | |||
} | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::LoadModelData(OmFileLoadHelper &om_load_helper) { | |||
ModelPartition partition_model_def; | |||
// no need to check value, DATA->NetOutput | |||
@@ -366,6 +624,28 @@ void ModelHelper::SetModelToGeModel(ge::Model &model) { | |||
model_->SetAttr(model.MutableAttrMap()); | |||
} | |||
Status ModelHelper::LoadModelData(OmFileLoadHelper &om_load_helper, GeModelPtr &cur_model, size_t mode_index) { | |||
ModelPartition partition_model_def; | |||
// no need to check value, DATA->NetOutput | |||
om_load_helper.GetModelPartition(ModelPartitionType::MODEL_DEF, partition_model_def, mode_index); | |||
GELOGD("Model_def partition addr:%p,size:%u", partition_model_def.data, partition_model_def.size); | |||
ge::Model model; | |||
if (ge::Model::Load(partition_model_def.data, partition_model_def.size, model) != SUCCESS) { | |||
GELOGE(INTERNAL_ERROR, "Load model failed."); | |||
return INTERNAL_ERROR; | |||
} | |||
cur_model->SetGraph(model.GetGraph()); | |||
cur_model->SetName(model.GetName()); | |||
cur_model->SetVersion(model.GetVersion()); | |||
cur_model->SetPlatformVersion(model.GetPlatformVersion()); | |||
cur_model->SetAttr(model.MutableAttrMap()); | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::LoadWeights(OmFileLoadHelper &om_load_helper) { | |||
ModelPartition partition; | |||
if (om_load_helper.GetModelPartition(ModelPartitionType::WEIGHTS_DATA, partition) != SUCCESS) { | |||
@@ -379,6 +659,19 @@ Status ModelHelper::LoadWeights(OmFileLoadHelper &om_load_helper) { | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::LoadWeights(OmFileLoadHelper &om_load_helper, GeModelPtr &cur_model, size_t mode_index) { | |||
ModelPartition partition; | |||
if (om_load_helper.GetModelPartition(ModelPartitionType::WEIGHTS_DATA, partition, mode_index) != SUCCESS) { | |||
GELOGE(FAILED, "Get weight model partition failed."); | |||
return FAILED; | |||
} | |||
ge::Buffer weight = ge::Buffer::CopyFrom(partition.data, partition.size); | |||
cur_model->SetWeight(weight); | |||
GELOGD("GetWeight size:%u", partition.size); | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadTask(OmFileLoadHelper &om_load_helper) { | |||
ModelPartition task_partition; | |||
if (om_load_helper.GetModelPartition(ModelPartitionType::TASK_INFO, task_partition) != SUCCESS) { | |||
@@ -398,6 +691,27 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadTask(Om | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ModelHelper::LoadTask(OmFileLoadHelper &om_load_helper, | |||
GeModelPtr &cur_model, | |||
size_t mode_index) { | |||
ModelPartition task_partition; | |||
if (om_load_helper.GetModelPartition(ModelPartitionType::TASK_INFO, task_partition, mode_index) != SUCCESS) { | |||
GELOGE(FAILED, "Get task model partition failed."); | |||
return FAILED; | |||
} | |||
std::shared_ptr<ModelTaskDef> task = ge::MakeShared<ModelTaskDef>(); | |||
GE_CHECK_NOTNULL(task); | |||
if (task_partition.size != 0) { | |||
if (!ReadProtoFromArray(task_partition.data, task_partition.size, task.get())) { | |||
GELOGE(INTERNAL_ERROR, "ReadProtoFromArray failed."); | |||
return INTERNAL_ERROR; | |||
} | |||
GELOGD("TASK_INFO op_size:%zu, stream_num:%u", task->op().size(), task->stream_num()); | |||
} | |||
cur_model->SetModelTaskDef(task); | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::LoadTBEKernelStore(OmFileLoadHelper &om_load_helper) { | |||
// Load tbe kernels | |||
ModelPartition partition_kernel_def; | |||
@@ -414,6 +728,23 @@ Status ModelHelper::LoadTBEKernelStore(OmFileLoadHelper &om_load_helper) { | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::LoadTBEKernelStore(OmFileLoadHelper &om_load_helper, GeModelPtr &cur_model, size_t mode_index) { | |||
// Load tbe kernels | |||
ModelPartition partition_kernel_def; | |||
TBEKernelStore kernel_store; | |||
if (om_load_helper.GetModelPartition(ModelPartitionType::TBE_KERNELS, partition_kernel_def, mode_index) == | |||
SUCCESS) { | |||
GELOGD("Kernels partition size:%u", partition_kernel_def.size); | |||
if (kernel_store.Load(partition_kernel_def.data, partition_kernel_def.size)) { | |||
GELOGD("Load tbe kernels success"); | |||
} else { | |||
GELOGW("Load tbe kernels failed"); | |||
} | |||
} | |||
cur_model->SetTBEKernelStore(kernel_store); | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::LoadCustAICPUKernelStore(OmFileLoadHelper &om_load_helper) { | |||
// Load cust aicpu kernels | |||
ModelPartition partition_kernel_def; | |||
@@ -421,19 +752,39 @@ Status ModelHelper::LoadCustAICPUKernelStore(OmFileLoadHelper &om_load_helper) { | |||
if (om_load_helper.GetModelPartition(ModelPartitionType::CUST_AICPU_KERNELS, partition_kernel_def) == SUCCESS) { | |||
GELOGD("Kernels partition size:%u", partition_kernel_def.size); | |||
if (kernel_store.Load(partition_kernel_def.data, partition_kernel_def.size)) { | |||
GELOGI("Load cust aicpu kernels success"); | |||
GELOGD("Load cust aicpu kernels success"); | |||
} else { | |||
GELOGW("Load cust aicpu kernels failed"); | |||
} | |||
} | |||
model_->SetCustAICPUKernelStore(kernel_store); | |||
return SUCCESS; | |||
} | |||
Status ModelHelper::LoadCustAICPUKernelStore(OmFileLoadHelper &om_load_helper, | |||
GeModelPtr &cur_model, size_t mode_index) { | |||
// Load cust aicpu kernels | |||
ModelPartition partition_kernel_def; | |||
CustAICPUKernelStore kernel_store; | |||
if (om_load_helper.GetModelPartition(ModelPartitionType::CUST_AICPU_KERNELS, partition_kernel_def, mode_index) | |||
== SUCCESS) { | |||
GELOGD("Kernels partition size:%u", partition_kernel_def.size); | |||
if (kernel_store.Load(partition_kernel_def.data, partition_kernel_def.size)) { | |||
GELOGD("Load cust aicpu kernels success"); | |||
} else { | |||
GELOGW("Load cust aicpu kernels failed"); | |||
} | |||
} | |||
cur_model->SetCustAICPUKernelStore(kernel_store); | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY GeModelPtr ModelHelper::GetGeModel() { | |||
if (model_ != nullptr) { | |||
return model_; | |||
} | |||
GELOGI("Model has not been loaded!"); | |||
GELOGD("Model has not been loaded!"); | |||
std::shared_ptr<ge::GeModel> out_model = ge::MakeShared<ge::GeModel>(); | |||
if (out_model == nullptr) { | |||
return nullptr; | |||
@@ -441,6 +792,20 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY GeModelPtr ModelHelper::GetGeMo | |||
return out_model; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY GeRootModelPtr ModelHelper::GetGeRootModel() { | |||
if (root_model_ != nullptr) { | |||
return root_model_; | |||
} | |||
GELOGD("Model has not been loaded!"); | |||
std::shared_ptr<ge::GeRootModel> out_model = ge::MakeShared<ge::GeRootModel>(); | |||
if (out_model == nullptr) { | |||
return nullptr; | |||
} | |||
return out_model; | |||
} | |||
Status ModelHelper::ReleaseLocalModelData() noexcept { | |||
Status result = SUCCESS; | |||
if (model_addr_tmp_ != nullptr) { | |||
@@ -52,6 +52,17 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status OmFileLoadHelper::Init(u | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status OmFileLoadHelper::Init(uint8_t *model_data, | |||
uint32_t model_data_size, | |||
uint32_t model_num) { | |||
Status status = LoadModelPartitionTable(model_data, model_data_size, model_num); | |||
if (status != SUCCESS) { | |||
return status; | |||
} | |||
is_inited_ = true; | |||
return SUCCESS; | |||
} | |||
// Use both | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status OmFileLoadHelper::GetModelPartition(ModelPartitionType type, | |||
ModelPartition &partition) { | |||
@@ -79,6 +90,37 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status OmFileLoadHelper::GetMod | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status OmFileLoadHelper::GetModelPartition(ModelPartitionType type, | |||
ModelPartition &partition, | |||
size_t model_index) { | |||
if (!is_inited_) { | |||
GELOGE(PARAM_INVALID, "OmFileLoadHelper has not been initialized!"); | |||
return PARAM_INVALID; | |||
} | |||
if (model_index >= model_contexts_.size()) { | |||
GELOGE(PARAM_INVALID, "cur index : %zu, model_contexts size:%zu", model_index, model_contexts_.size()); | |||
return PARAM_INVALID; | |||
} | |||
auto &cur_ctx = model_contexts_[model_index]; | |||
bool found = false; | |||
for (ModelPartition &part : cur_ctx.partition_datas_) { | |||
if (part.type == type) { | |||
partition = part; | |||
found = true; | |||
break; | |||
} | |||
} | |||
if (!found) { | |||
if (type != ModelPartitionType::TBE_KERNELS && type != ModelPartitionType::WEIGHTS_DATA && | |||
type != ModelPartitionType::CUST_AICPU_KERNELS) { | |||
GELOGE(FAILED, "GetModelPartition:type:%d is not in partition_datas!", static_cast<int>(type)); | |||
return FAILED; | |||
} | |||
} | |||
return SUCCESS; | |||
} | |||
Status OmFileLoadHelper::CheckModelValid(const ge::ModelData &model) const { | |||
// Parameter validity check | |||
if (model.model_data == nullptr) { | |||
@@ -138,7 +180,8 @@ Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, const uint | |||
context_.partition_datas_.push_back(partition); | |||
if (partition.size > model_data_size || mem_offset > model_data_size - partition.size) { | |||
GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, "The partition size %zu is greater than the model data size %u.", | |||
GELOGE(ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID, | |||
"The partition size %zu is greater than the model data size %u.", | |||
partition.size + mem_offset, model_data_size); | |||
return ACL_ERROR_GE_EXEC_MODEL_DATA_SIZE_INVALID; | |||
} | |||
@@ -148,6 +191,61 @@ Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, const uint | |||
return SUCCESS; | |||
} | |||
Status OmFileLoadHelper::LoadModelPartitionTable(uint8_t *model_data, uint32_t model_data_size, uint32_t model_num) { | |||
if (model_data == nullptr) { | |||
GELOGE(PARAM_INVALID, "Param model_data must not be null!"); | |||
return PARAM_INVALID; | |||
} | |||
uint32_t cur_offset = 0; | |||
for (uint32_t index = 0; index < model_num; ++index) { | |||
// Init partition table | |||
auto partition_table = reinterpret_cast<ModelPartitionTable *>(model_data + cur_offset); | |||
size_t partition_table_size = SIZE_OF_MODEL_PARTITION_TABLE(*partition_table); | |||
cur_offset += partition_table_size; | |||
GELOGD("Cur model index %zu: ModelPartitionTable num :%u, " | |||
"ModelFileHeader length :%zu, ModelPartitionTable length :%zu", | |||
index, partition_table->num, sizeof(ModelFileHeader), partition_table_size); | |||
if (model_data_size <= cur_offset) { | |||
GELOGE(GE_EXEC_MODEL_DATA_SIZE_INVALID, "invalid model data, partition_table->num:%u, model data size %u", | |||
partition_table->num, model_data_size); | |||
return GE_EXEC_MODEL_DATA_SIZE_INVALID; | |||
} | |||
for (uint32_t i = 0; i < partition_table->num; i++) { | |||
ModelPartition partition; | |||
partition.size = partition_table->partition[i].mem_size; | |||
partition.data = model_data + cur_offset; | |||
partition.type = partition_table->partition[i].type; | |||
if (index >= model_contexts_.size()) { | |||
if (index != model_contexts_.size()) { | |||
GELOGE(FAILED, "cur index is %zu make model_contexts_ overflow", index); | |||
return FAILED; | |||
} | |||
OmFileContext tmp_ctx; | |||
tmp_ctx.partition_datas_.push_back(partition); | |||
model_contexts_.push_back(tmp_ctx); | |||
} else { | |||
model_contexts_[index].partition_datas_.push_back(partition); | |||
} | |||
if (partition.size > model_data_size || cur_offset > model_data_size - partition.size) { | |||
GELOGE(GE_EXEC_MODEL_DATA_SIZE_INVALID, "The partition size %zu is greater than the model data size %u.", | |||
partition.size + cur_offset, model_data_size); | |||
return GE_EXEC_MODEL_DATA_SIZE_INVALID; | |||
} | |||
cur_offset += partition.size; | |||
GELOGD("Partition, type:%d, size:%u, model_index:%zu", static_cast<int>(partition.type), partition.size, index); | |||
} | |||
} | |||
if (cur_offset != model_data_size) { | |||
GELOGE(FAILED, "do not get the complete model, read end offset:%zu, all size:%zu", cur_offset, model_data_size); | |||
return FAILED; | |||
} | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY const std::vector<ModelPartition> | |||
&OmFileSaveHelper::GetModelPartitions() const { | |||
return context_.partition_datas_; | |||
@@ -172,6 +270,28 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelPartitionTable *OmFileSave | |||
return partition_table; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelPartitionTable *OmFileSaveHelper::GetPartitionTable( | |||
size_t cur_ctx_index) { | |||
auto &cur_ctx = model_contexts_[cur_ctx_index]; | |||
auto partition_size = static_cast<uint32_t>(cur_ctx.partition_datas_.size()); | |||
// Build ModelPartitionTable, flex array | |||
cur_ctx.partition_table_.clear(); | |||
cur_ctx.partition_table_.resize(sizeof(ModelPartitionTable) + sizeof(ModelPartitionMemInfo) * partition_size, 0); | |||
auto partition_table = reinterpret_cast<ModelPartitionTable *>(cur_ctx.partition_table_.data()); | |||
partition_table->num = partition_size; | |||
uint32_t mem_offset = 0; | |||
for (uint32_t i = 0; i < partition_size; i++) { | |||
ModelPartition partition = cur_ctx.partition_datas_[i]; | |||
partition_table->partition[i] = {partition.type, mem_offset, partition.size}; | |||
mem_offset += partition.size; | |||
GELOGD("Partition, type:%d, size:%u", static_cast<int>(partition.type), partition.size); | |||
} | |||
return partition_table; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status OmFileSaveHelper::AddPartition(ModelPartition &partition) { | |||
if (ge::CheckUint32AddOverflow(context_.model_data_len_, partition.size) != SUCCESS) { | |||
GELOGE(FAILED, "UINT32 %u and %u addition can result in overflow!", context_.model_data_len_, partition.size); | |||
@@ -182,6 +302,27 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status OmFileSaveHelper::AddPar | |||
return SUCCESS; | |||
} | |||
Status OmFileSaveHelper::AddPartition(ModelPartition &partition, size_t cur_index) { | |||
if (ge::CheckUint32AddOverflow(context_.model_data_len_, partition.size) != SUCCESS) { | |||
GELOGE(FAILED, "UINT32 %u and %u addition can result in overflow!", context_.model_data_len_, partition.size); | |||
return FAILED; | |||
} | |||
if (cur_index >= model_contexts_.size()) { | |||
if (cur_index != model_contexts_.size()) { | |||
GELOGE(FAILED, "cur index is %zu make model_contexts_ overflow", cur_index); | |||
return FAILED; | |||
} | |||
OmFileContext tmp_ctx; | |||
tmp_ctx.model_data_len_ += partition.size; | |||
tmp_ctx.partition_datas_.push_back(partition); | |||
model_contexts_.push_back(tmp_ctx); | |||
} else { | |||
model_contexts_[cur_index].model_data_len_ += partition.size; | |||
model_contexts_[cur_index].partition_datas_.push_back(partition); | |||
} | |||
return SUCCESS; | |||
} | |||
Status OmFileSaveHelper::SaveModel(const SaveParam &save_param, const char *output_file, ModelBufferData &model, | |||
bool is_offline) { | |||
(void)save_param.cert_file; | |||
@@ -198,6 +339,10 @@ Status OmFileSaveHelper::SaveModel(const SaveParam &save_param, const char *outp | |||
Status OmFileSaveHelper::SaveModelToFile(const char *output_file, ModelBufferData &model, bool is_offline) { | |||
#if !defined(NONSUPPORT_SAVE_TO_FILE) | |||
if (context_.partition_datas_.empty()) { | |||
GE_CHK_BOOL_EXEC(!model_contexts_.empty(), return FAILED, "mode contexts empty"); | |||
context_ = model_contexts_.front(); | |||
} | |||
uint32_t model_data_len = context_.model_data_len_; | |||
if (model_data_len == 0) { | |||
GELOGE(domi::PARAM_INVALID, "Model data len error! should not be 0"); | |||
@@ -231,4 +376,53 @@ Status OmFileSaveHelper::SaveModelToFile(const char *output_file, ModelBufferDat | |||
return SUCCESS; | |||
#endif | |||
} | |||
Status OmFileSaveHelper::SaveRootModel(const SaveParam &save_param, const char *output_file, | |||
ModelBufferData &model, bool is_offline) { | |||
(void)save_param.cert_file; | |||
(void)save_param.ek_file; | |||
(void)save_param.encode_mode; | |||
(void)save_param.hw_key_file; | |||
(void)save_param.pri_key_file; | |||
#if !defined(NONSUPPORT_SAVE_TO_FILE) | |||
vector<ModelPartitionTable *> model_partition_tabels; | |||
vector<vector<ModelPartition>> all_model_partitions; | |||
for (size_t ctx_index = 0; ctx_index < model_contexts_.size(); ++ctx_index) { | |||
auto &cur_ctx = model_contexts_[ctx_index]; | |||
uint32_t cur_model_data_len = cur_ctx.model_data_len_; | |||
if (cur_model_data_len == 0) { | |||
GELOGE(domi::PARAM_INVALID, "Model data len error! should not be 0"); | |||
return domi::PARAM_INVALID; | |||
} | |||
auto tmp_table = GetPartitionTable(ctx_index); | |||
if (tmp_table == nullptr) { | |||
GELOGE(ge::GE_GRAPH_SAVE_FAILED, "SaveModelToFile execute failed: partition_table is NULL."); | |||
return ge::GE_GRAPH_SAVE_FAILED; | |||
} | |||
uint32_t size_of_table = SIZE_OF_MODEL_PARTITION_TABLE(*tmp_table); | |||
FMK_UINT32_ADDCHECK(size_of_table, cur_model_data_len) | |||
FMK_UINT32_ADDCHECK(size_of_table + cur_model_data_len, model_header_.length) | |||
model_header_.length += size_of_table + cur_model_data_len; | |||
model_partition_tabels.push_back(tmp_table); | |||
all_model_partitions.push_back(cur_ctx.partition_datas_); | |||
GELOGD("sizeof(ModelPartitionTable):%u, cur_model_data_len:%u, cur_context_index:%zu", | |||
size_of_table, cur_model_data_len, ctx_index); | |||
} | |||
Status ret; | |||
if (is_offline) { | |||
ret = FileSaver::SaveToFile(output_file, model_header_, model_partition_tabels, all_model_partitions); | |||
} else { | |||
GELOGW("do not support save ge root model to buff now"); | |||
return FAILED; | |||
} | |||
if (ret == SUCCESS) { | |||
GELOGD("Save model success without encrypt."); | |||
} | |||
return ret; | |||
#else | |||
return SUCCESS; | |||
#endif | |||
} | |||
} // namespace ge |
@@ -357,7 +357,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void OpUtils::TransDataHWCK2KCH | |||
const char *w_data = (const char *)input; | |||
int64_t count = h * w * c * k; | |||
GE_IF_BOOL_EXEC(count <= 0, GELOGW("Count value must be greater than 0, but count = %ld", count); return ); | |||
GE_IF_BOOL_EXEC(count <= 0, GELOGW("Count value must be greater than 0, but count = %ld", count); return); | |||
float *buf = new (std::nothrow) float[count](); | |||
GE_RT_VOID_CHECK_NOTNULL(buf); | |||
float *src_buff = nullptr; | |||
@@ -0,0 +1,198 @@ | |||
/** | |||
* Copyright 2020 Huawei Technologies Co., Ltd | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
#include "common/profiling/ge_profiling.h" | |||
#include "runtime/base.h" | |||
#include "common/profiling/profiling_manager.h" | |||
#include "framework/common/debug/ge_log.h" | |||
#include "framework/common/debug/log.h" | |||
#include "graph/load/graph_loader.h" | |||
#include "init/gelib.h" | |||
#include "framework/common/ge_inner_error_codes.h" | |||
namespace { | |||
const uint32_t kDeviceListIndex = 3; | |||
const std::string kDeviceNums = "devNums"; | |||
const std::string kDeviceIdList = "devIdList"; | |||
const std::string kProfilingInit = "prof_init"; | |||
const std::string kProfilingFinalize = "prof_finalize"; | |||
const std::string kProfilingStart = "prof_start"; | |||
const std::string kProfilingStop = "prof_stop"; | |||
const std::string kProfModelSubscribe = "prof_model_subscribe"; | |||
const std::string kProfModelUnsubscribe = "prof_model_cancel_subscribe"; | |||
const std::string kRtSetDeviceRegName = "profiling"; | |||
const std::map<ProfCommandHandleType, std::string> kProfCommandTypeMap = { | |||
{kProfCommandhandleInit, kProfilingInit}, | |||
{kProfCommandhandleStart, kProfilingStart}, | |||
{kProfCommandhandleStop, kProfilingStop}, | |||
{kProfCommandhandleFinalize, kProfilingFinalize}, | |||
{kProfCommandhandleModelSubscribe, kProfModelSubscribe}, | |||
{kProfCommandhandleModelUnsubscribe, kProfModelUnsubscribe}}; | |||
} // namespace | |||
bool TransProfConfigToParam(const ProfCommandHandleData &profCommand, vector<string> &prof_config_params) { | |||
prof_config_params.clear(); | |||
prof_config_params.emplace_back(kDeviceNums); | |||
prof_config_params.emplace_back(std::to_string(profCommand.devNums)); | |||
prof_config_params.emplace_back(kDeviceIdList); | |||
std::string devID = ""; | |||
if (profCommand.devNums == 0) { | |||
GELOGW("The device num is invalid."); | |||
return false; | |||
} | |||
for (uint32_t i = 0; i < profCommand.devNums; i++) { | |||
devID.append(std::to_string(profCommand.devIdList[i])); | |||
if (i != profCommand.devNums - 1) { | |||
devID.append(","); | |||
} | |||
} | |||
prof_config_params.push_back(devID); | |||
return true; | |||
} | |||
bool isProfConfigValid(const uint32_t *deviceid_list, uint32_t device_nums) { | |||
if (deviceid_list == nullptr) { | |||
GELOGE(ge::PARAM_INVALID, "deviceIdList is nullptr"); | |||
return false; | |||
} | |||
if (device_nums == 0 || device_nums > MAX_DEV_NUM) { | |||
GELOGE(ge::PARAM_INVALID, "The device nums: %u is invalid.", device_nums); | |||
return false; | |||
} | |||
// real device num | |||
int32_t dev_count = 0; | |||
rtError_t rt_err = rtGetDeviceCount(&dev_count); | |||
if (rt_err != RT_ERROR_NONE) { | |||
GELOGE(ge::INTERNAL_ERROR, "Get the Device count fail."); | |||
return false; | |||
} | |||
if (device_nums > static_cast<uint32_t>(dev_count)) { | |||
GELOGE(ge::PARAM_INVALID, "Device num(%u) is not in range 1 ~ %d.", device_nums, dev_count); | |||
return false; | |||
} | |||
std::unordered_set<uint32_t> record; | |||
for (size_t i = 0; i < device_nums; ++i) { | |||
uint32_t dev_id = deviceid_list[i]; | |||
if (dev_id >= static_cast<uint32_t>(dev_count)) { | |||
GELOGE(ge::PARAM_INVALID, "Device id %u is not in range 0 ~ %d(exclude %d)", dev_id, dev_count, dev_count); | |||
return false; | |||
} | |||
if (record.count(dev_id) > 0) { | |||
GELOGE(ge::PARAM_INVALID, "Device id %u is duplicatedly set", dev_id); | |||
return false; | |||
} | |||
record.insert(dev_id); | |||
} | |||
return true; | |||
} | |||
ge::Status RegProfCtrlCallback(MsprofCtrlCallback func) { | |||
if (func == nullptr) { | |||
GELOGE(ge::PARAM_INVALID, "Msprof ctrl callback is nullptr."); | |||
return ge::PARAM_INVALID; | |||
} | |||
if (ge::ProfilingManager::Instance().GetMsprofCallback().msprofCtrlCallback != nullptr) { | |||
GELOGW("Msprof ctrl callback is exist, just ignore it."); | |||
} else { | |||
ge::ProfilingManager::Instance().SetMsprofCtrlCallback(func); | |||
} | |||
return ge::SUCCESS; | |||
} | |||
ge::Status RegProfSetDeviceCallback(MsprofSetDeviceCallback func) { | |||
if (func == nullptr) { | |||
GELOGE(ge::PARAM_INVALID, "MsprofSetDeviceCallback callback is nullptr."); | |||
return ge::PARAM_INVALID; | |||
} | |||
// Pass MsprofSetDeviceCallback to runtime | |||
ge::Status rt_ret = rtRegDeviceStateCallback(kRtSetDeviceRegName.c_str(), static_cast<rtDeviceStateCallback>(func)); | |||
if (rt_ret != ge::SUCCESS) { | |||
GELOGE(rt_ret, "Pass MsprofSetDeviceCallback to runtime failed!"); | |||
return rt_ret; | |||
} | |||
return ge::SUCCESS; | |||
} | |||
ge::Status RegProfReporterCallback(MsprofReporterCallback func) { | |||
if (func == nullptr) { | |||
GELOGE(ge::PARAM_INVALID, "MsprofReporterCallback callback is nullptr."); | |||
return ge::PARAM_INVALID; | |||
} | |||
if (ge::ProfilingManager::Instance().GetMsprofCallback().msprofReporterCallback != nullptr) { | |||
GELOGW("Msprof reporter callback is exist, just ignore it."); | |||
} else { | |||
GELOGI("GE register Msprof reporter callback."); | |||
ge::ProfilingManager::Instance().SetMsprofReporterCallback(func); | |||
// Pass MsprofReporterCallback to runtime | |||
ge::Status rt_ret = rtSetMsprofReporterCallback(func); | |||
if (rt_ret != ge::SUCCESS) { | |||
GELOGE(rt_ret, "Pass MsprofReporterCallback to runtime failed!!"); | |||
return rt_ret; | |||
} | |||
// Pass MsprofReporterCallback to hccl | |||
} | |||
return ge::SUCCESS; | |||
} | |||
ge::Status ProfCommandHandle(ProfCommandHandleType type, void *data, uint32_t len) { | |||
if (type != kProfCommandhandleFinalize) { | |||
GE_CHECK_NOTNULL(data); | |||
} | |||
ProfCommandHandleData *prof_config_param = reinterpret_cast<ProfCommandHandleData *>(data); | |||
auto iter = kProfCommandTypeMap.find(type); | |||
if (iter == kProfCommandTypeMap.end()) { | |||
GELOGW("The prof comand type is invalid."); | |||
return ge::PARAM_INVALID; | |||
} | |||
std::vector<string> prof_params; | |||
if (type == kProfCommandhandleStart || type == kProfCommandhandleStop) { | |||
if (!isProfConfigValid(prof_config_param->devIdList, prof_config_param->devNums)) { | |||
return ge::FAILED; | |||
} | |||
if (!TransProfConfigToParam(*prof_config_param, prof_params)) { | |||
GELOGE(ge::PARAM_INVALID, "Transfer profilerConfig to string vector failed"); | |||
return ge::PARAM_INVALID; | |||
} | |||
} | |||
ge::GraphLoader graph_loader; | |||
ge::Command command; | |||
command.cmd_params.clear(); | |||
command.cmd_type = iter->second; | |||
command.cmd_params = prof_params; | |||
if (type != kProfCommandhandleFinalize) { | |||
command.module_index = prof_config_param->profSwitch; | |||
} | |||
GELOGI("GE commandhandle execute, Command Type: %s, data type config: 0x%llx", iter->second.c_str(), | |||
command.module_index); | |||
if (type == kProfCommandhandleStart || type == kProfCommandhandleStop) { | |||
GELOGI("Profiling device nums:%s , deviceID:[%s]", prof_params[0].c_str(), prof_params[kDeviceListIndex].c_str()); | |||
} | |||
ge::Status ret = graph_loader.CommandHandle(command); | |||
if (ret != ge::SUCCESS) { | |||
GELOGE(ret, "Handle profiling command failed"); | |||
return ge::FAILED; | |||
} | |||
GELOGI("Successfully execute profiling command type: %d, command 0x%llx.", type, command.module_index); | |||
return ge::SUCCESS; | |||
} | |||
@@ -0,0 +1,26 @@ | |||
/** | |||
* Copyright 2020 Huawei Technologies Co., Ltd | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
#include "common/profiling/ge_runner_profiling.h" | |||
#include "init/gelib.h" | |||
bool IsInitialize() { | |||
std::shared_ptr<ge::GELib> instance_ptr = ge::GELib::GetInstance(); | |||
if (instance_ptr == nullptr || instance_ptr->InitFlag() == false) { | |||
return false; | |||
} | |||
return true; | |||
} |
@@ -24,16 +24,9 @@ | |||
#include "graph/load/new_model_manager/davinci_model.h" | |||
namespace { | |||
const char *const kJobID = "jobID"; | |||
const char *const kDeviceID = "deviceID"; | |||
const char *const kStartCfg = "startCfg"; | |||
const char *const kFeatures = "features"; | |||
const char *const kConf = "conf"; | |||
const char *const kEvents = "events"; | |||
const char *const kAiCoreEvents = "ai_core_events"; | |||
const char *const kName = "name"; | |||
const char *const kTraceID = "traceId"; | |||
const char *const kProfDir = "resultPath"; | |||
const char *const kTrainingTrace = "training_trace"; | |||
const char *const kFpPoint = "fp_point"; | |||
const char *const kBpPoint = "bp_point"; | |||
const size_t kReportMaxLen = 2048; | |||
const int32_t kMaxDeviceNum = 256; | |||
const std::string kConfigNumsdev = "devNums"; | |||
@@ -45,7 +38,11 @@ const std::string kProfModelUnsubscribe = "prof_model_cancel_subscribe"; | |||
} // namespace | |||
namespace ge { | |||
ProfilingManager::ProfilingManager() : subscribe_count_(0) {} | |||
ProfilingManager::ProfilingManager() | |||
: is_load_profiling_(false), is_execute_profiling_(false), is_training_trace_(false), subscribe_count_(0) { | |||
prof_cb_.msprofCtrlCallback = nullptr; | |||
prof_cb_.msprofReporterCallback = nullptr; | |||
} | |||
ProfilingManager::~ProfilingManager() {} | |||
@@ -58,44 +55,29 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::In | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
vector<int32_t>().swap(device_id_); | |||
subscribe_count_ = 0; | |||
job_id_ = options.job_id; | |||
GELOGI("ProfilingManager::Init job_id:%s", job_id_.c_str()); | |||
GELOGI("ProfilingManager::Init job_id:%s", options.job_id.c_str()); | |||
Status ret; | |||
if (!recv_profiling_config_.empty()) { | |||
GELOGI("Profiling json config from acl:%s", recv_profiling_config_.c_str()); | |||
ret = InitFromAclCfg(recv_profiling_config_); | |||
} else { | |||
ret = InitFromOptions(options); | |||
if (ret == SUCCESS && is_load_profiling_) { | |||
device_id_.push_back(options.device_id); | |||
} | |||
} | |||
struct MsprofGeOptions prof_conf = {{ 0 }}; | |||
Status ret = InitFromOptions(options, prof_conf); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Failed to init profiling."); | |||
return ret; | |||
} | |||
if (is_load_profiling_) { | |||
// register Framework to profiling | |||
int result = Msprof::Engine::Init(GE_PROFILING_MODULE, &engine_); | |||
if (result != 0) { | |||
GELOGE(FAILED, "Register profiling engine failed."); | |||
return FAILED; | |||
if (is_execute_profiling_) { | |||
if (prof_cb_.msprofCtrlCallback == nullptr) { | |||
GELOGE(ge::PARAM_INVALID, "MsprofCtrlCallback callback is nullptr."); | |||
return ge::PARAM_INVALID; | |||
} | |||
// profiling startup first time | |||
GELOGI("Begin to init profiling, device num %zu", device_id_.size()); | |||
for (size_t i = 0; i < device_id_.size(); ++i) { | |||
ret = StartProfiling(0, device_id_[i]); | |||
if (ret != SUCCESS) { | |||
GELOGW("Profiling start failed on device %d.", device_id_[i]); | |||
continue; | |||
} | |||
GELOGI("Profiling init succ on device %d.", device_id_[i]); | |||
int32_t cb_ret = prof_cb_.msprofCtrlCallback( | |||
static_cast<uint32_t>(MsprofCtrlCallbackType::MSPROF_CTRL_INIT_GE_OPTIONS), | |||
static_cast<void *>(&prof_conf), sizeof(MsprofGeOptions)); | |||
if (cb_ret != 0) { | |||
GELOGE(FAILED, "Call msprofCtrlCallback failed, type:%u, return:%d", | |||
static_cast<uint32_t>(MsprofCtrlCallbackType::MSPROF_CTRL_INIT_GE_OPTIONS), cb_ret); | |||
return FAILED; | |||
} | |||
GELOGI("Profiling init success"); | |||
} else { | |||
GELOGI("The profiling is off, skip the initialization"); | |||
} | |||
@@ -103,288 +85,120 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::In | |||
return SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::InitFromAclCfg( | |||
const std::string &config) { | |||
ge::Status ProfilingManager::InitFromOptions(const Options &options, MsprofGeOptions &prof_conf) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
try { | |||
is_load_profiling_ = false; | |||
is_execute_profiling_ = false; | |||
profiling_opts_.clear(); | |||
op_trace_conf_.clear(); | |||
Json start_prof_conf = Json::parse(config); | |||
Json &prof_conf = start_prof_conf[kStartCfg][0]; | |||
job_id_ = prof_conf[kJobID]; | |||
auto iter = prof_conf.find(kProfDir); | |||
if (iter != prof_conf.end()) { | |||
prof_dir_ = prof_conf[kProfDir]; | |||
} | |||
Json &device_id = prof_conf[kDeviceID]; | |||
if (device_id.size() != 0) { | |||
vector<int32_t>().swap(device_id_); | |||
bool is_all = false; | |||
for (size_t i = 0; i < device_id.size(); i++) { | |||
std::string device_id_str = device_id[i].get<std::string>(); | |||
if (device_id_str == "all") { | |||
is_all = true; | |||
break; | |||
} | |||
device_id_.push_back(std::stoi(device_id_str)); | |||
} | |||
if (is_all) { | |||
int32_t count = 0; | |||
rtError_t rt_err = rtGetDeviceCount(&count); | |||
if (rt_err != RT_ERROR_NONE) { | |||
GELOGE(FAILED, "Call rtGetDeviceCount to get device failed."); | |||
} | |||
// enable profiling by env | |||
char env_profiling_mode[MMPA_MAX_PATH] = { 0x00 }; | |||
is_execute_profiling_ = false; | |||
vector<int32_t>().swap(device_id_); | |||
for (int32_t i = 0; i < count; ++i) { | |||
device_id_.push_back(i); | |||
} | |||
} | |||
if (options.profiling_mode == "1" && !options.profiling_options.empty()) { | |||
// enable profiling by ge option | |||
if (strncpy_s(prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX, options.profiling_options.c_str(), | |||
MSPROF_OPTIONS_DEF_LEN_MAX - 1) != EOK) { | |||
GELOGE(INTERNAL_ERROR, "copy profiling_options failed."); | |||
return INTERNAL_ERROR; | |||
} | |||
Json &features = prof_conf[kFeatures]; | |||
if (ParseFeaturesFromAclCfg(features) != SUCCESS) { | |||
GELOGE(FAILED, "Parse feature from acl cfg failed."); | |||
return FAILED; | |||
is_execute_profiling_ = true; | |||
GELOGI("The profiling in options is %s, %s. origin option: %s", options.profiling_mode.c_str(), prof_conf.options, | |||
options.profiling_options.c_str()); | |||
} else { | |||
(void)mmGetEnv("PROFILING_MODE", env_profiling_mode, MMPA_MAX_PATH); | |||
(void)mmGetEnv("PROFILING_OPTIONS", prof_conf.options, MSPROF_OPTIONS_DEF_LEN_MAX); | |||
// The env is invalid | |||
if ((strcmp("true", env_profiling_mode) != 0) || (strcmp(prof_conf.options, "\0") == 0)) { | |||
return SUCCESS; | |||
} | |||
is_load_profiling_ = true; | |||
// enable profiling by env | |||
is_execute_profiling_ = true; | |||
} catch (...) { | |||
GELOGE(FAILED, "Json conf is not invalid !"); | |||
return ge::PARAM_INVALID; | |||
GELOGI("The profiling in env is %s, %s", env_profiling_mode, prof_conf.options); | |||
} | |||
#endif | |||
return ge::SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::ParseFeaturesFromAclCfg( | |||
const Json &features) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
try { | |||
for (size_t i = 0; i < features.size(); ++i) { | |||
const Json &feature = features[i]; | |||
if ((feature.find(kName) == feature.end()) || feature[kName].is_null()) { | |||
continue; | |||
} | |||
const std::string &name = feature[kName]; | |||
if (name == "op_trace") { | |||
const Json &conf = feature[kConf]; | |||
const Json &events = conf[0][kEvents]; | |||
const std::string &ai_core_events = events[0][kAiCoreEvents]; | |||
GELOGI("Op trace config from acl ai_core_events:%s", ai_core_events.c_str()); | |||
is_op_trace_ = true; | |||
ProfMgrConf prof_mgr_conf; | |||
int result = ProfMgrGetConf(ai_core_events, &prof_mgr_conf); | |||
if (result != 0) { | |||
GELOGE(FAILED, "ProfMgrGetConf failed."); | |||
return FAILED; | |||
} | |||
op_trace_conf_ = prof_mgr_conf.conf; | |||
op_trace_iter_num_ = static_cast<int32_t>(op_trace_conf_.size()); | |||
GELOGI("Op trace profiling iter num %d,", op_trace_iter_num_); | |||
} else if (name == "task_trace") { | |||
is_op_trace_ = false; | |||
if (feature.find(kConf) != feature.end()) { | |||
const Json &conf = feature[kConf]; | |||
std::stringstream task_trace_conf; | |||
task_trace_conf << conf; | |||
task_trace_conf_ = task_trace_conf.str(); | |||
} | |||
GELOGI("Task trace config from acl"); | |||
} else if (name == "system_trace") { | |||
is_op_trace_ = false; | |||
const Json &conf = feature[kConf]; | |||
std::stringstream system_trace_conf; | |||
system_trace_conf << conf; | |||
system_trace_conf_ = system_trace_conf.str(); | |||
GELOGI("System trace config from acl"); | |||
} | |||
profiling_opts_.push_back(name); | |||
} | |||
} catch (...) { | |||
GELOGE(ge::PARAM_INVALID, "Json conf feature is not invalid !"); | |||
return ge::PARAM_INVALID; | |||
if (!is_execute_profiling_) { | |||
return SUCCESS; | |||
} | |||
#endif | |||
return ge::SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::InitFromOptions(const Options &options) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
// enable profiling support two ways: env and front end | |||
char profiling_mode_temp[MMPA_MAX_PATH] = { 0x00 }; | |||
char prof_options_temp[MMPA_MAX_PATH] = { 0x00 }; | |||
(void)mmGetEnv("PROFILING_MODE", profiling_mode_temp, MMPA_MAX_PATH); | |||
(void)mmGetEnv("PROFILING_OPTIONS", prof_options_temp, MMPA_MAX_PATH ); | |||
const char *profiling_mode = profiling_mode_temp; | |||
const char *prof_options = prof_options_temp; | |||
if ((profiling_mode == nullptr) || (strcmp("true", profiling_mode) != 0) || (prof_options == nullptr)) { | |||
is_load_profiling_ = false; | |||
is_execute_profiling_ = false; | |||
} else { | |||
std::string prof_options_str = std::string(prof_options); | |||
profiling_opts_ = StringUtils::Split(prof_options_str, ':'); | |||
is_load_profiling_ = true; | |||
is_execute_profiling_ = true; | |||
GELOGI("The profiling in env is %s, %s", profiling_mode, prof_options); | |||
// Parse json str for bp fp | |||
Status ret = ParseOptions(prof_conf.options); | |||
if (ret != ge::SUCCESS) { | |||
GELOGE(ge::PARAM_INVALID, "Parse training trace param failed."); | |||
return ge::PARAM_INVALID; | |||
} | |||
if (!is_load_profiling_) { | |||
const std::string enable_profiling = "1"; | |||
if (options.profiling_mode != enable_profiling || options.profiling_options.empty()) { | |||
is_load_profiling_ = false; | |||
is_execute_profiling_ = false; | |||
return SUCCESS; | |||
} else { | |||
profiling_opts_ = StringUtils::Split(options.profiling_options, ':'); | |||
is_load_profiling_ = true; | |||
is_execute_profiling_ = true; | |||
GELOGI("The profiling in options is %s, %s", options.profiling_mode.c_str(), options.profiling_options.c_str()); | |||
} | |||
} | |||
// features:'training_trace', 'task_trace' or 'op_trace' etc | |||
if (!profiling_opts_.empty()) { | |||
if (profiling_opts_[0] == "op_trace") { | |||
is_op_trace_ = true; | |||
// op trace get conf | |||
ProfMgrConf prof_mgr_conf; | |||
int result = ProfMgrGetConf("", &prof_mgr_conf); | |||
if (result != 0) { | |||
GELOGE(FAILED, "ProfMgrGetConf failed."); | |||
return FAILED; | |||
} | |||
op_trace_conf_ = prof_mgr_conf.conf; | |||
op_trace_iter_num_ = static_cast<int32_t>(op_trace_conf_.size()); | |||
GELOGI("op trace profiling iter num %d,", op_trace_iter_num_); | |||
} else { | |||
is_op_trace_ = false; | |||
op_trace_iter_num_ = 1; | |||
} | |||
if (strncpy_s(prof_conf.jobId, MSPROF_OPTIONS_DEF_LEN_MAX, options.job_id.c_str(), | |||
MSPROF_OPTIONS_DEF_LEN_MAX - 1) != EOK) { | |||
GELOGE(INTERNAL_ERROR, "copy job_id failed."); | |||
return INTERNAL_ERROR; | |||
} | |||
GELOGI("Job id: %s, original job id: %s.", prof_conf.jobId, options.job_id.c_str()); | |||
#endif | |||
return ge::SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ge::Status ProfilingManager::StartProfiling(int32_t iter_num, | |||
int32_t device_id) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
if (!profiling_opts_.empty()) { | |||
GELOGI("Start profiling index is %d", iter_num); | |||
// current one docker only use one device | |||
Json p_device; | |||
try { | |||
// profiling need physical_device_id | |||
p_device[kDeviceID] = std::to_string(device_id); | |||
p_device[kJobID] = job_id_; | |||
p_device[kTraceID] = std::to_string(GetContext().TraceId()); | |||
if (!prof_dir_.empty()) { | |||
p_device[kProfDir] = prof_dir_; | |||
GELOGI("Prof dir: %s.", prof_dir_.c_str()); | |||
} | |||
Json features; | |||
if (is_op_trace_) { | |||
Json f; | |||
f[kName] = "op_trace"; | |||
Json conf; | |||
if (op_trace_conf_.size() <= static_cast<size_t>(iter_num)) { | |||
GELOGE(FAILED, "Op trace iter num is invalid!"); | |||
return FAILED; | |||
} | |||
Json events; | |||
events[0] = nlohmann::json::parse(op_trace_conf_[iter_num]); | |||
conf[0][kEvents] = events; | |||
f[kConf] = conf; | |||
features[0] = f; | |||
if (iter_num == 0) { | |||
is_load_ = true; | |||
} | |||
} else { | |||
for (std::vector<std::string>::size_type i = 0; i < profiling_opts_.size(); i++) { | |||
Json f; | |||
if (profiling_opts_[i] == "system_trace") { | |||
f[kConf] = nlohmann::json::parse(system_trace_conf_); | |||
} else if (profiling_opts_[i] == "task_trace") { | |||
if (!task_trace_conf_.empty()) { | |||
f[kConf] = nlohmann::json::parse(task_trace_conf_); | |||
} | |||
} | |||
f[kName] = profiling_opts_[i]; | |||
features[i] = f; | |||
} | |||
is_load_ = true; | |||
} | |||
p_device[kFeatures] = features; | |||
// only one device, but sProfMgrStartUp API require for device list | |||
Json devices; | |||
devices[0] = p_device; | |||
Json start_cfg; | |||
start_cfg[kStartCfg] = devices; | |||
// convert json to string | |||
std::stringstream ss; | |||
ss << start_cfg; | |||
send_profiling_config_ = ss.str(); | |||
GELOGI("Profiling config %s\n", send_profiling_config_.c_str()); | |||
} catch (...) { | |||
GELOGE(FAILED, "Op trace json conf is not invalid !"); | |||
return FAILED; | |||
ge::Status ProfilingManager::ParseOptions(const std::string &options) { | |||
if (options.empty()) { | |||
GELOGE(ge::PARAM_INVALID, "Profiling options is empty."); | |||
return ge::PARAM_INVALID; | |||
} | |||
try { | |||
Json prof_options = Json::parse(options); | |||
if (options.find(kTrainingTrace) == std::string::npos) { | |||
return ge::SUCCESS; | |||
} | |||
// runtime startup for profiling | |||
uint64_t module = GetProfilingModule(); | |||
int32_t device_num = 1; | |||
uint32_t device_id_rt = static_cast<uint32_t>(device_id); | |||
GE_CHK_RT_RET(rtProfilerStart(module, device_num, &device_id_rt)); | |||
// call profiling startup API | |||
ProfMgrCfg prof_cfg = {send_profiling_config_}; | |||
void *prof_handle = ProfMgrStartUp(&prof_cfg); | |||
if (prof_handle == nullptr) { | |||
GELOGW("ProfMgrStartUp failed on device %d ", device_id); | |||
return FAILED; | |||
const std::string training_trace = prof_options[kTrainingTrace]; | |||
if (training_trace.empty()) { | |||
GELOGI("Training trace will not take effect."); | |||
return ge::SUCCESS; | |||
} | |||
GELOGI("GE profiling training trace:%s", training_trace.c_str()); | |||
if (training_trace != "on") { | |||
GELOGE(ge::PARAM_INVALID, "Training trace param:%s is invalid.", training_trace.c_str()); | |||
return ge::PARAM_INVALID; | |||
} | |||
fp_point_ = prof_options[kFpPoint]; | |||
bp_point_ = prof_options[kBpPoint]; | |||
if (!fp_point_.empty() && !bp_point_.empty()) { | |||
GELOGI("Training trace bp fp is set, bp_point:%s, fp_point:%s.", bp_point_.c_str(), fp_point_.c_str()); | |||
} | |||
GELOGD("StartProfiling, prof_handle: %p", prof_handle); | |||
prof_handle_vec_.push_back(prof_handle); | |||
is_training_trace_ = true; | |||
} catch (...) { | |||
GELOGE(FAILED, "Json prof_conf options is invalid."); | |||
return ge::PARAM_INVALID; | |||
} | |||
#endif | |||
return SUCCESS; | |||
return ge::SUCCESS; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::StopProfiling() { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
Msprof::Engine::Reporter *reporter = PluginImpl::GetPluginReporter(); | |||
if (reporter != nullptr) { | |||
int ret = reporter->Flush(); | |||
GELOGI("Report data end, ret is %d", ret); | |||
} | |||
uint64_t module = GetProfilingModule(); | |||
// The following if case will not be executed in normal case, inc case of ProfStopProfiling is abnormal | |||
int32_t device_num = static_cast<int32_t>(device_id_.size()); | |||
auto device_id_ptr = std::unique_ptr<uint32_t[]>(new (std::nothrow) uint32_t[device_num]); | |||
if (device_id_ptr == nullptr) { | |||
GELOGE(FAILED, "Stop profiling: device id ptr is null."); | |||
return; | |||
} | |||
for (int32_t i = 0; i < device_num; i++) { | |||
device_id_ptr[i] = static_cast<uint32_t>(device_id_[i]); | |||
if (device_num != 0) { | |||
auto device_id_ptr = std::unique_ptr<uint32_t[]>(new (std::nothrow) uint32_t[device_num]); | |||
if (device_id_ptr == nullptr) { | |||
GELOGE(FAILED, "Stop profiling: device id ptr is null."); | |||
return; | |||
} | |||
for (int32_t i = 0; i < device_num; i++) { | |||
device_id_ptr[i] = static_cast<uint32_t>(device_id_[i]); | |||
} | |||
rtError_t rt_ret = rtProfilerStop(module, device_num, device_id_ptr.get()); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGW("Call rtProfilerStop failed, ret:%d", rt_ret); | |||
} | |||
} | |||
rtError_t rt_ret = rtProfilerStop(module, device_num, device_id_ptr.get()); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGW("Call rtProfilerStop failed, ret:%d", rt_ret); | |||
// stop profiling | |||
if (prof_cb_.msprofCtrlCallback == nullptr) { | |||
GELOGE(ge::PARAM_INVALID, "MsprofCtrlCallback callback is nullptr."); | |||
return; | |||
} | |||
for (size_t i = 0; i < prof_handle_vec_.size(); ++i) { | |||
int result = ProfMgrStop(prof_handle_vec_[i]); | |||
if (result != 0) { | |||
GELOGW("ProfMgr stop return fail:%d, handle:%p", result, prof_handle_vec_[i]); | |||
} | |||
int32_t cb_ret = prof_cb_.msprofCtrlCallback(static_cast<uint32_t>(MsprofCtrlCallbackType::MSPROF_CTRL_FINALIZE), | |||
nullptr, 0); | |||
if (cb_ret != 0) { | |||
GELOGW("call msprofCtrlCallback failed, type:%u, return:%d", | |||
static_cast<uint32_t>(MsprofCtrlCallbackType::MSPROF_CTRL_FINALIZE), cb_ret); | |||
return; | |||
} | |||
vector<void *>().swap(prof_handle_vec_); | |||
is_load_ = false; | |||
recv_profiling_config_ = ""; | |||
GELOGI("Stop Profiling success."); | |||
#endif | |||
} | |||
@@ -392,12 +206,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::StopProf | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ProfilingTaskDescInfo( | |||
uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, const int32_t &device_id) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
Msprof::Engine::Reporter *reporter = PluginImpl::GetPluginReporter(); | |||
if (reporter == nullptr) { | |||
GELOGI("Profiling report is nullptr!"); | |||
return; | |||
} | |||
std::string data; | |||
for (const auto &task : task_desc_info) { | |||
std::string model_name = task.model_name; | |||
@@ -412,7 +220,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::Profilin | |||
.append(std::to_string(stream_id)).append(" ") | |||
.append(std::to_string(model_id)).append("\n")); | |||
Msprof::Engine::ReporterData reporter_data{}; | |||
ReporterData reporter_data{}; | |||
reporter_data.deviceId = device_id; | |||
reporter_data.data = (unsigned char *)data.c_str(); | |||
reporter_data.dataLen = data.size(); | |||
@@ -422,9 +230,9 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::Profilin | |||
return; | |||
} | |||
ret = reporter->Report(&reporter_data); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Reporter data of task_desc_info fail!"); | |||
int32_t cb_ret = CallMsprofReport(reporter_data); | |||
if (cb_ret != 0) { | |||
GELOGE(cb_ret, "Reporter data of task_desc_info failed, ret:%d", cb_ret); | |||
return; | |||
} | |||
} | |||
@@ -436,9 +244,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::Profilin | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ProfilingGraphDescInfo( | |||
uint32_t model_id, const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info, const int32_t &device_id) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
Msprof::Engine::Reporter *reporter = PluginImpl::GetPluginReporter(); | |||
GE_IF_BOOL_EXEC(reporter == nullptr, GELOGI("Profiling report is nullptr!"); return;); | |||
std::string data; | |||
for (const auto &graph : compute_graph_desc_info) { | |||
data.append("model_name:") | |||
@@ -493,64 +298,52 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::Profilin | |||
} | |||
data.append(" model_id:").append(std::to_string(model_id)); | |||
data.append("\n"); | |||
Msprof::Engine::ReporterData reporter_data{}; | |||
Report(device_id, data, *reporter, reporter_data); | |||
GraphDescReport(device_id, data); | |||
data.clear(); | |||
} | |||
#endif | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::Report( | |||
const int32_t &device_id, const string &data, Msprof::Engine::Reporter &reporter, | |||
Msprof::Engine::ReporterData &reporter_data) { | |||
void ProfilingManager::GraphDescReport(const int32_t &device_id, const string &data) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
ReporterData reporter_data{}; | |||
int ret = -1; | |||
int32_t cb_ret = -1; | |||
size_t index = data.size() / kReportMaxLen; | |||
if (index >= 1) { | |||
reporter_data.deviceId = device_id; | |||
int ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "graph_desc_info", sizeof("graph_desc_info")); | |||
ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "graph_desc_info", sizeof("graph_desc_info")); | |||
GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag of graph_desc_info memcpy error!"); return;); | |||
for (size_t i = 0; i < index; ++i) { | |||
reporter_data.data = (unsigned char *)data.c_str() + kReportMaxLen * i; | |||
reporter_data.dataLen = kReportMaxLen; | |||
ret = reporter.Report(&reporter_data); | |||
GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(ret, "Reporter data of graph_desc_info fail!"); return;); | |||
cb_ret = CallMsprofReport(reporter_data); | |||
GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data of graph_desc_info failed, ret:%d", cb_ret); return;); | |||
} | |||
reporter_data.dataLen = data.size() - kReportMaxLen * index; | |||
if (reporter_data.dataLen != 0) { | |||
reporter_data.data = (unsigned char *)data.c_str() + kReportMaxLen * index; | |||
ret = reporter.Report(&reporter_data); | |||
GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(ret, "Reporter data of graph_desc_info fail!"); return;); | |||
cb_ret = CallMsprofReport(reporter_data); | |||
GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data of graph_desc_info failed, ret:%d", cb_ret); return;); | |||
} | |||
} else { | |||
reporter_data.deviceId = device_id; | |||
reporter_data.data = (unsigned char *)data.c_str(); | |||
reporter_data.dataLen = data.size(); | |||
int ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "graph_desc_info", sizeof("graph_desc_info")); | |||
ret = memcpy_s(reporter_data.tag, MSPROF_ENGINE_MAX_TAG_LEN + 1, "graph_desc_info", sizeof("graph_desc_info")); | |||
GE_IF_BOOL_EXEC(ret != EOK, GELOGE(ret, "Report data tag of graph_desc_info memcpy error!"); return;); | |||
ret = reporter.Report(&reporter_data); | |||
GE_IF_BOOL_EXEC(ret != SUCCESS, GELOGE(ret, "Reporter data of graph_desc_info fail!"); return;); | |||
} | |||
#endif | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::PluginUnInit(const std::string &module) const { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
int ret = Msprof::Engine::UnInit(module); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "profiling plugin uninit failed, ret:%d", ret); | |||
cb_ret = CallMsprofReport(reporter_data); | |||
GE_IF_BOOL_EXEC(cb_ret != 0, GELOGE(cb_ret, "Reporter data of graph_desc_info failed, ret:%d", cb_ret); return;); | |||
} | |||
#endif | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportProfilingData( | |||
uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, | |||
const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info, | |||
bool check_device) { | |||
const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
int32_t logic_device_id = 0; | |||
rtError_t rt_ret = rtGetDevice(&logic_device_id); | |||
@@ -559,13 +352,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportPr | |||
return; | |||
} | |||
GELOGD("current logic_device_id:%d", logic_device_id); | |||
if (check_device) { | |||
auto ret = std::find(device_id_.begin(), device_id_.end(), logic_device_id); | |||
if (ret == device_id_.end()) { | |||
GELOGE(FAILED, "get valid phy_device_id failed, profiling report failed."); | |||
return; | |||
} | |||
} | |||
GELOGD("start ProfilingTaskDescInfo."); | |||
ProfilingTaskDescInfo(model_id, task_desc_info, logic_device_id); | |||
GELOGD("start ProfilingGraphDescInfo."); | |||
@@ -574,11 +360,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::ReportPr | |||
#endif | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::SetProfilingConfig( | |||
const std::string &profiling_cfg) { | |||
recv_profiling_config_ = profiling_cfg; | |||
} | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY uint64_t ProfilingManager::GetProfilingModule() { | |||
uint64_t module = PROF_MODEL_EXECUTE_MASK | | |||
PROF_RUNTIME_API_MASK | | |||
@@ -594,9 +375,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY uint64_t ProfilingManager::GetP | |||
return module; | |||
} | |||
void ProfilingManager::UpdateSubscribeDeviceModuleMap(std::string prof_type, | |||
uint32_t device_id, | |||
uint64_t module) { | |||
void ProfilingManager::UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
if (prof_type == kProfModelSubscribe) { | |||
if (subs_dev_module_.find(device_id) != subs_dev_module_.end()) { | |||
@@ -608,9 +387,13 @@ void ProfilingManager::UpdateSubscribeDeviceModuleMap(std::string prof_type, | |||
subs_dev_module_[device_id] = dev_info; | |||
} | |||
} else if (prof_type == kProfModelUnsubscribe) { | |||
if (subs_dev_module_.find(device_id) != subs_dev_module_.end()) { | |||
if (subs_dev_module_[device_id].subscribe_count > 0) { | |||
subs_dev_module_[device_id].subscribe_count--; | |||
auto iter = subs_dev_module_.find(device_id); | |||
if (iter != subs_dev_module_.end()) { | |||
if (iter->second.subscribe_count > 0) { | |||
iter->second.subscribe_count--; | |||
} | |||
if (iter->second.subscribe_count == 0) { | |||
subs_dev_module_.erase(iter); | |||
} | |||
} | |||
} else { | |||
@@ -626,10 +409,11 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfMo | |||
uint64_t model_load_mask = module & PROF_MODEL_LOAD_MASK; | |||
if ((subscribe_count_ == 0) && (model_load_mask == PROF_MODEL_LOAD_MASK)) { | |||
// register framework to profiling | |||
int32_t result = Msprof::Engine::Init(GE_PROFILING_MODULE, &engine_); | |||
if (result != SUCCESS) { | |||
GELOGE(FAILED, "Register profiling engine failed."); | |||
return FAILED; | |||
// register Framework to profiling | |||
int32_t cb_ret = PluginInit(); | |||
if (cb_ret != 0) { | |||
GELOGE(cb_ret, "profiling plugin init failed, ret:%d", cb_ret); | |||
return cb_ret; | |||
} | |||
GELOGI("Prof subscribe: model load profiling on."); | |||
} | |||
@@ -647,7 +431,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfMo | |||
UpdateSubscribeDeviceModuleMap(kProfModelSubscribe, device[0], module); | |||
// Report profiling data | |||
Status p_ret = davinci_model->ReportProfilingData(false); | |||
Status p_ret = davinci_model->ReportProfilingData(); | |||
if (p_ret != SUCCESS) { | |||
GELOGE(p_ret, "Report profiling data failed."); | |||
return p_ret; | |||
@@ -672,6 +456,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfMo | |||
auto iter = subs_dev_module_.find(device[0]); | |||
if (iter != subs_dev_module_.end()) { | |||
if (subs_dev_module_[device[0]].subscribe_count == 1) { | |||
// The same device_id, only stop at last time | |||
rtError_t rt_ret = rtProfilerStop(subs_dev_module_[device[0]].module, dev_num, device); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGE(FAILED, "Runtime profiler stop failed."); | |||
@@ -679,15 +464,15 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfMo | |||
} | |||
} | |||
UpdateSubscribeDeviceModuleMap(kProfModelUnsubscribe, device[0], subs_dev_module_[device[0]].module); | |||
} else { | |||
GELOGE(FAILED, "The device_id:%u has not been subscribed, do not need to cancel.", device[0]); | |||
return FAILED; | |||
} | |||
subscribe_count_--; | |||
if (subscribe_count_ == 0) { | |||
int32_t ret = Msprof::Engine::UnInit(GE_PROFILING_MODULE); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Profiling plugin uninit failed, ret:%d", ret); | |||
return ret; | |||
} | |||
// profiling plugin uninit at last subscription | |||
PluginUnInit(); | |||
} | |||
#endif | |||
return SUCCESS; | |||
@@ -700,11 +485,12 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfIn | |||
if (model_load_mask == PROF_MODEL_LOAD_MASK) { | |||
// register Framework to profiling | |||
int32_t result = Msprof::Engine::Init(GE_PROFILING_MODULE, &engine_); | |||
if (result != SUCCESS) { | |||
GELOGE(FAILED, "Register profiling engine failed."); | |||
return FAILED; | |||
int32_t cb_ret = PluginInit(); | |||
if (cb_ret != 0) { | |||
GELOGE(cb_ret, "profiling plugin init failed, ret:%d", cb_ret); | |||
return cb_ret; | |||
} | |||
int32_t device_num = -1; | |||
rtError_t rt_ret = rtProfilerStart(model_load_mask, device_num, nullptr); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
@@ -719,7 +505,6 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfIn | |||
if (training_trace_mask == PROF_TRAINING_TRACE_MASK) { | |||
is_training_trace_ = true; | |||
} | |||
is_acl_api_mode_ = true; | |||
GELOGI("Prof init success."); | |||
#endif | |||
return SUCCESS; | |||
@@ -730,19 +515,17 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfFi | |||
std::lock_guard<std::mutex> lock(mutex_); | |||
is_load_profiling_ = false; | |||
is_training_trace_ = false; | |||
is_acl_api_mode_ = false; | |||
is_execute_profiling_ = false; | |||
// profiling plugin uninit | |||
PluginUnInit(); | |||
int32_t ret = Msprof::Engine::UnInit(GE_PROFILING_MODULE); | |||
if (ret != SUCCESS) { | |||
GELOGE(ret, "Profiling plugin uninit failed, ret:%d", ret); | |||
} | |||
int32_t dev_num = -1; | |||
rtError_t rt_ret = rtProfilerStop(PROF_MODEL_LOAD_MASK, dev_num, nullptr); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGE(FAILED, "Runtime profiler stop failed."); | |||
return FAILED; | |||
} | |||
for (auto device_id_module : device_id_module_map_) { | |||
if (device_id_module.second != 0) { | |||
uint32_t device_id = static_cast<uint32_t>(device_id_module.first); | |||
@@ -792,6 +575,7 @@ Status ProfilingManager::ProfParseDeviceId(const std::map<std::string, std::stri | |||
return FAILED; | |||
} catch (std::out_of_range &) { | |||
GELOGE(FAILED, "Device id: %s is out of range.", decvice_id[i].c_str()); | |||
return FAILED; | |||
} catch (...) { | |||
GELOGE(FAILED, "Device id: %s cannot change to int.", decvice_id[i].c_str()); | |||
return FAILED; | |||
@@ -818,6 +602,7 @@ Status ProfilingManager::ProfParseParam(const std::map<std::string, std::string> | |||
return FAILED; | |||
} catch (std::out_of_range &) { | |||
GELOGE(FAILED, "Device num: %s is out of range.", iter->second.c_str()); | |||
return FAILED; | |||
} catch (...) { | |||
GELOGE(FAILED, "Device num: %s cannot change to int.", iter->second.c_str()); | |||
return FAILED; | |||
@@ -844,6 +629,10 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfSt | |||
uint64_t module, const std::map<std::string, std::string> &config_para) { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
std::lock_guard<std::mutex> lock(mutex_); | |||
uint64_t training_trace_mask = module & PROF_TRAINING_TRACE_MASK; | |||
if (training_trace_mask == PROF_TRAINING_TRACE_MASK) { | |||
is_training_trace_ = true; | |||
} | |||
int32_t device_num = 0; | |||
vector<int32_t> device_list; | |||
if (ProfParseParam(config_para, device_num, device_list) != SUCCESS) { | |||
@@ -859,7 +648,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfSt | |||
for (int32_t i = 0; i < device_num; i++) { | |||
device_id_ptr[i] = static_cast<uint32_t>(device_list[i]); | |||
} | |||
GELOGD("Runtime config param: 0x%llx, device num: %d.", module, device_num); | |||
GELOGI("Runtime config param: 0x%llx, device num: %d.", module, device_num); | |||
rtError_t rt_ret = rtProfilerStart(module, device_num, device_id_ptr.get()); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
@@ -878,7 +667,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfSt | |||
GELOGW("Prof start: load model module is invalid."); | |||
} | |||
UpdateDeviceIdModuleMap(kProfStart, module, device_list); | |||
GELOGD("Prof start profiling success."); | |||
GELOGI("Prof start profiling success."); | |||
#endif | |||
return SUCCESS; | |||
} | |||
@@ -901,7 +690,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfSt | |||
for (int32_t i = 0; i < device_num; i++) { | |||
device_id_ptr[i] = static_cast<uint32_t>(device_list[i]); | |||
} | |||
GELOGD("Prof stop: runtime config param: 0x%llx, device num: %d", module, device_num); | |||
GELOGI("Prof stop: runtime config param: 0x%llx, device num: %d", module, device_num); | |||
rtError_t rt_ret = rtProfilerStop(module, device_num, device_id_ptr.get()); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGE(FAILED, "Prof stop: runtime profiler config proc failed."); | |||
@@ -921,7 +710,7 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::ProfSt | |||
GELOGW("Prof stop: load model module is invalid."); | |||
} | |||
UpdateDeviceIdModuleMap(kProfStop, module, device_list); | |||
GELOGD("Prof stop profiling success."); | |||
GELOGI("Prof stop profiling success."); | |||
#endif | |||
return SUCCESS; | |||
} | |||
@@ -963,47 +752,103 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY bool ProfilingManager::Profilin | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGE(rt_ret, "Runtime get logic_device_id failed, current logic_device_id:%d", logic_device_id); | |||
} | |||
GELOGD("Current logic_device_id:%d", logic_device_id); | |||
GELOGI("Current logic_device_id:%d", logic_device_id); | |||
bool execute_model_prof_on = false; | |||
auto iter = std::find(device_id_.begin(), device_id_.end(), logic_device_id); | |||
if (iter != device_id_.end()) { | |||
execute_model_prof_on = true; | |||
} | |||
GELOGD("Flag is_execute_profiling: %d, execute_model_prof_on: %d", is_execute_profiling_, execute_model_prof_on); | |||
return is_execute_profiling_ || execute_model_prof_on; | |||
GELOGI("Flag is_execute_profiling: %d, execute_model_prof_on: %d", is_execute_profiling_, execute_model_prof_on); | |||
return execute_model_prof_on; | |||
} | |||
/** | |||
* @brief Profiling PluginImpl | |||
*/ | |||
// PluginImpl static variable init | |||
Msprof::Engine::Reporter *PluginImpl::reporter_ = nullptr; | |||
PluginImpl::PluginImpl(const std::string &module) : module_(module) { GELOGI("Create PluginImpl\n"); } | |||
int PluginImpl::Init(const Msprof::Engine::Reporter *reporter) { | |||
GELOGI("PluginImpl init"); | |||
reporter_ = const_cast<Msprof::Engine::Reporter *>(reporter); | |||
return 0; | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::PluginInit() const { | |||
if (prof_cb_.msprofReporterCallback == nullptr) { | |||
GELOGE(ge::PARAM_INVALID, "MsprofReporterCallback callback is nullptr."); | |||
return ge::PARAM_INVALID; | |||
} | |||
return prof_cb_.msprofReporterCallback( | |||
static_cast<uint32_t>(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK), | |||
static_cast<uint32_t>(MsprofReporterCallbackType::MSPROF_REPORTER_INIT), | |||
nullptr, 0); | |||
} | |||
int PluginImpl::UnInit() { | |||
GELOGI("PluginImpl Uninit"); | |||
reporter_ = nullptr; | |||
return 0; | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::PluginUnInit() const { | |||
#ifdef DAVINCI_SUPPORT_PROFILING | |||
if (prof_cb_.msprofReporterCallback == nullptr) { | |||
GELOGE(ge::PARAM_INVALID, "MsprofReporterCallback callback is nullptr."); | |||
return; | |||
} | |||
int32_t cb_ret = prof_cb_.msprofReporterCallback( | |||
static_cast<uint32_t>(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK), | |||
static_cast<uint32_t>(MsprofReporterCallbackType::MSPROF_REPORTER_UNINIT), | |||
nullptr, 0); | |||
if (cb_ret != 0) { | |||
GELOGW("profiling plugin uninit failed, ret:%d", cb_ret); | |||
} | |||
#endif | |||
} | |||
Msprof::Engine::PluginIntf *ProfilingEngineImpl::CreatePlugin() { | |||
GELOGI(" Create Plugin"); | |||
return new (std::nothrow) PluginImpl(GE_PROFILING_MODULE); | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY Status ProfilingManager::CallMsprofReport( | |||
ReporterData &reporter_data) const { | |||
if (prof_cb_.msprofReporterCallback == nullptr) { | |||
GELOGE(ge::PARAM_INVALID, "MsprofReporterCallback callback is nullptr."); | |||
return ge::PARAM_INVALID; | |||
} | |||
return prof_cb_.msprofReporterCallback( | |||
static_cast<uint32_t>(MsprofReporterModuleId::MSPROF_MODULE_FRAMEWORK), | |||
static_cast<uint32_t>(MsprofReporterCallbackType::MSPROF_REPORTER_REPORT), | |||
static_cast<void *>(&reporter_data), sizeof(ReporterData)); | |||
} | |||
int ProfilingEngineImpl::ReleasePlugin(Msprof::Engine::PluginIntf *plugin) { | |||
if (plugin != nullptr) { | |||
delete plugin; | |||
plugin = nullptr; | |||
FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void ProfilingManager::GetFpBpPoint( | |||
std::string &fp_point, std::string &bp_point) { | |||
// Env or options mode, fp_point_/bp_point_ have initiliazed on profiling init | |||
if (!fp_point_.empty() && !bp_point_.empty()) { | |||
fp_point = fp_point_; | |||
bp_point = bp_point_; | |||
GELOGI("Bp Fp have been initialized in env or options. bp_point: %s, fp_point: %s", bp_point.c_str(), | |||
fp_point.c_str()); | |||
return; | |||
} | |||
// ProfApi mode and training trace is set | |||
// Parse options first | |||
char env_profiling_options[MSPROF_OPTIONS_DEF_LEN_MAX] = { 0x00 }; | |||
bool is_profiling_valid = false; | |||
std::string profiling_options; | |||
if (ge::GetContext().GetOption(OPTION_EXEC_PROFILING_OPTIONS, profiling_options) == SUCCESS && | |||
!profiling_options.empty()) { | |||
is_profiling_valid = true; | |||
} else { | |||
INT32 ret = mmGetEnv("PROFILING_OPTIONS", env_profiling_options, MSPROF_OPTIONS_DEF_LEN_MAX); | |||
if (ret != EN_OK) { | |||
GELOGI("PROFILING_OPTIONS env is not exist."); | |||
return; | |||
} | |||
GELOGI("Parse env PROFILING_OPTIONS:%s.", env_profiling_options); | |||
profiling_options = env_profiling_options; | |||
is_profiling_valid = true; | |||
} | |||
if (is_profiling_valid) { | |||
try { | |||
Json prof_options = Json::parse(profiling_options); | |||
fp_point_ = prof_options[kFpPoint]; | |||
bp_point_ = prof_options[kBpPoint]; | |||
fp_point = fp_point_; | |||
bp_point = bp_point_; | |||
if (!fp_point_.empty() && !bp_point_.empty()) { | |||
GELOGI("Training trace bp fp is set, bp_point:%s, fp_point:%s.", bp_point_.c_str(), fp_point_.c_str()); | |||
} | |||
} catch (...) { | |||
GELOGW("Json prof options is invalid."); | |||
return; | |||
} | |||
} | |||
return 0; | |||
return; | |||
} | |||
} // namespace ge |
@@ -26,9 +26,7 @@ | |||
#include "framework/common/ge_inner_error_codes.h" | |||
#include "framework/common/ge_types.h" | |||
#include "external/register/register_types.h" | |||
#include "toolchain/prof_engine.h" | |||
#include "toolchain/prof_mgr_core.h" | |||
#include "toolchain/prof_acl_api.h" | |||
#include "toolchain/prof_callback.h" | |||
using std::map; | |||
using std::string; | |||
@@ -37,35 +35,33 @@ using Json = nlohmann::json; | |||
namespace { | |||
const std::string GE_PROFILING_MODULE = "Framework"; | |||
// DataTypeConfig MASK | |||
const uint64_t PROF_ACL_API_MASK = 0x0001; | |||
const uint64_t PROF_TASK_TIME_MASK = 0x0002; | |||
const uint64_t PROF_AICORE_METRICS_MASK = 0x0004; | |||
const uint64_t PROF_AICPU_TRACE_MASK = 0x0008; | |||
const uint64_t PROF_MODEL_EXECUTE_MASK = 0x0010; | |||
const uint64_t PROF_RUNTIME_API_MASK = 0x0020; | |||
const uint64_t PROF_RUNTIME_TRACE_MASK = 0x0040; | |||
const uint64_t PROF_SCHEDULE_TIMELINE_MASK = 0x0080; | |||
const uint64_t PROF_SCHEDULE_TRACE_MASK = 0x0100; | |||
const uint64_t PROF_AIVECTORCORE_METRICS_MASK = 0x0200; | |||
const uint64_t PROF_SUBTASK_TIME_MASK = 0x0400; | |||
const uint64_t PROF_TRAINING_TRACE_MASK = 0x0800; | |||
const uint64_t PROF_HCCL_TRACE_MASK = 0x1000; | |||
const uint64_t PROF_DATA_PROCESS_MASK = 0x2000; | |||
const uint64_t PROF_MODEL_LOAD_MASK = 0x8000000000000000; | |||
} // namespace | |||
namespace ge { | |||
struct DeviceSubsInfo { | |||
uint64_t module; | |||
uint32_t subscribe_count; | |||
}; | |||
// register Plugin | |||
class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY PluginImpl : public Msprof::Engine::PluginIntf { | |||
public: | |||
explicit PluginImpl(const std::string &module); | |||
~PluginImpl() {} | |||
int Init(const Msprof::Engine::Reporter *reporter); | |||
int UnInit(); | |||
static Msprof::Engine::Reporter *GetPluginReporter() { return reporter_; } | |||
private: | |||
static Msprof::Engine::Reporter *reporter_; | |||
std::string module_; | |||
}; | |||
// register Engine | |||
class ProfilingEngineImpl : public Msprof::Engine::EngineIntf { | |||
public: | |||
ProfilingEngineImpl() {} | |||
~ProfilingEngineImpl() {} | |||
Msprof::Engine::PluginIntf *CreatePlugin(); | |||
int ReleasePlugin(Msprof::Engine::PluginIntf *plugin); | |||
struct MsprofCallback { | |||
MsprofCtrlCallback msprofCtrlCallback; | |||
MsprofReporterCallback msprofReporterCallback; | |||
}; | |||
class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager { | |||
@@ -73,68 +69,55 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ProfilingManager { | |||
ProfilingManager(); | |||
virtual ~ProfilingManager(); | |||
static ProfilingManager &Instance(); | |||
ge::Status Init(const Options &options); | |||
ge::Status InitFromOptions(const Options &options); | |||
ge::Status InitFromAclCfg(const std::string &config); | |||
ge::Status StartProfiling(int32_t iter, int32_t device_id); | |||
void UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module); | |||
ge::Status ProfModelSubscribe(uint64_t module, void *model); | |||
ge::Status ProfModelUnsubscribe(void *model); | |||
ge::Status ProfInit(uint64_t module); | |||
ge::Status ProfFinalize(); | |||
ge::Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | |||
ge::Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | |||
Status Init(const Options &options); | |||
Status ProfInit(uint64_t module); | |||
Status ProfFinalize(); | |||
Status ProfStartProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | |||
Status ProfStopProfiling(uint64_t module, const std::map<std::string, std::string> &config_para); | |||
Status ProfModelSubscribe(uint64_t module, void *model); | |||
Status ProfModelUnsubscribe(void *model); | |||
void StopProfiling(); | |||
bool ProfilingOpTraceOn() const { return is_op_trace_; } | |||
bool ProfilingLoadFlag() const { return is_load_; } | |||
bool ProfilingTrainingTraceOn() const { return is_training_trace_; } | |||
bool ProfilingModelLoadOn() const { return is_load_profiling_; } | |||
bool ProfilingModelExecuteOn() const; | |||
bool ProfilingOn() const { return is_load_profiling_ && is_execute_profiling_; } // only used by command pattern | |||
bool IsAclApiMode() const { return is_acl_api_mode_; } | |||
int32_t GetOpTraceIterNum() const { return op_trace_iter_num_; } | |||
// is_execute_profiling_ only used by ge option and env | |||
bool ProfilingOn() const { return is_load_profiling_ && is_execute_profiling_; } | |||
void ReportProfilingData(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, | |||
const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info, | |||
bool check_device); | |||
void Report(const int32_t &device_id, const string &data, Msprof::Engine::Reporter &reporter, | |||
Msprof::Engine::ReporterData &reporter_data); | |||
const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info); | |||
void ProfilingTaskDescInfo(uint32_t model_id, const std::vector<TaskDescInfo> &task_desc_info, | |||
const int32_t &device_id); | |||
void ProfilingGraphDescInfo(uint32_t model_id, const std::vector<ComputeGraphDescInfo> &compute_graph_desc_info, | |||
const int32_t &device_id); | |||
void SetProfilingConfig(const string &profiling_cfg); | |||
vector<int32_t> GetProfilingDeviceId() const { return device_id_; } | |||
void PluginUnInit(const std::string &module) const; | |||
Status PluginInit() const; | |||
void PluginUnInit() const; | |||
Status CallMsprofReport(ReporterData &reporter_data) const; | |||
struct MsprofCallback &GetMsprofCallback() { return prof_cb_; } | |||
void SetMsprofCtrlCallback(MsprofCtrlCallback func) { prof_cb_.msprofCtrlCallback = func; } | |||
void SetMsprofReporterCallback(MsprofReporterCallback func) { prof_cb_.msprofReporterCallback = func; } | |||
void GetFpBpPoint(std::string &fp_point, std::string &bp_point); | |||
private: | |||
ge::Status ParseFeaturesFromAclCfg(const Json &feature); | |||
ge::Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num, | |||
vector<int32_t> &device_list); | |||
ge::Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para, | |||
Status InitFromOptions(const Options &options, MsprofGeOptions &prof_conf); | |||
Status ParseOptions(const std::string &options); | |||
Status ProfParseParam(const std::map<std::string, std::string> &config_para, int32_t &device_num, | |||
vector<int32_t> &device_list); | |||
Status ProfParseDeviceId(const std::map<std::string, std::string> &config_para, | |||
vector<int32_t> &device_list); | |||
uint64_t GetProfilingModule(); | |||
void GraphDescReport(const int32_t &device_id, const string &data); | |||
void UpdateDeviceIdModuleMap(string prof_type, uint64_t module, const vector<int32_t> &device_list); | |||
bool is_load_profiling_ = false; | |||
bool is_execute_profiling_ = false; | |||
bool is_op_trace_ = false; | |||
bool is_load_ = false; | |||
bool is_training_trace_ = false; | |||
bool is_acl_api_mode_ = false; | |||
int32_t op_trace_iter_num_ = 0; | |||
string job_id_; | |||
string prof_dir_; | |||
void UpdateSubscribeDeviceModuleMap(std::string prof_type, uint32_t device_id, uint64_t module); | |||
bool is_load_profiling_; | |||
bool is_execute_profiling_; | |||
bool is_training_trace_; | |||
vector<int32_t> device_id_; | |||
vector<string> op_trace_conf_; | |||
vector<string> profiling_opts_; | |||
vector<void *> prof_handle_vec_; | |||
string recv_profiling_config_; | |||
string send_profiling_config_; | |||
string system_trace_conf_; | |||
string task_trace_conf_; | |||
const ProfilingEngineImpl engine_; | |||
map<int32_t, uint64_t> device_id_module_map_; // key: device_id, value: profiling on module | |||
map<uint32_t, DeviceSubsInfo> subs_dev_module_; // key: device_id, value: profiling on module | |||
uint32_t subscribe_count_; | |||
std::mutex mutex_; | |||
MsprofCallback prof_cb_; | |||
std::string fp_point_; | |||
std::string bp_point_; | |||
}; | |||
} // namespace ge | |||
#endif // GE_COMMON_PROFILING_PROFILING_MANAGER_H_ |
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
// Protocol buffer representing the shape of tensors. | |||
syntax = "proto3"; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||
@@ -1,3 +1,11 @@ | |||
/** | |||
* This file is part of Open Source Software TensorFlow, version 1.15.0 https://github.com/tensorflow/tensorflow | |||
* | |||
* This file is included by GraphEngine so as to support model format conversion from tensorflow model to GraphEngine model. | |||
* This file in this distribution may have been modified by Huawei Technologies Co., Ltd ("Huawei Modifications"). | |||
* All Huawei Modifications are Copyright 2019-2020 Huawei Technologies Co., Ltd. | |||
*/ | |||
syntax = "proto3"; | |||
package domi.tensorflow; | |||