From 306bbe0e654402cbae9b0f770f25e8298d4fe3b2 Mon Sep 17 00:00:00 2001 From: yanghaoran Date: Wed, 9 Dec 2020 15:00:38 +0800 Subject: [PATCH] Synchronize latest Ascend software suite 09 Dec 2020, with refactored GraphEngine --- CMakeLists.txt | 2 +- build.sh | 3 ++ cmake/dependency_graphenginev2.cmake | 39 +++++++++++++++++++ cmake/mind_expression.cmake | 5 ++- cmake/package.cmake | 12 +++--- graphengine | 2 +- .../ascend/executor/ai_core_dynamic_kernel.cc | 13 +++---- .../ascend/executor/ai_core_dynamic_kernel.h | 2 + .../executor/tiling/op_tiling_calculater.cc | 8 ++-- .../executor/tiling/op_tiling_calculater.h | 3 +- .../ccsrc/runtime/hccl_adapter/hccl_adapter.h | 2 +- .../transformer/test_transformer.py | 6 +-- tests/ut/cpp/runtest.sh | 6 ++- .../stub/dynamic_shape/dynamic_shape_stub.cc | 7 ++-- 14 files changed, 76 insertions(+), 34 deletions(-) create mode 100644 cmake/dependency_graphenginev2.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 30d22e4ead4..2b4a85b3baf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,7 @@ set(MS_CCSRC_PATH ${CMAKE_SOURCE_DIR}/mindspore/ccsrc) set(MS_CCSRC_BUILD_PATH ${BUILD_PATH}/mindspore/mindspore/ccsrc) if (ENABLE_D OR ENABLE_ACL OR ENABLE_TESTCASES) - include(${CMAKE_SOURCE_DIR}/cmake/dependency_graphengine.cmake) + include(${CMAKE_SOURCE_DIR}/cmake/dependency_graphenginev2.cmake) endif () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") diff --git a/build.sh b/build.sh index 67b4d3301a8..f3a1b2fef93 100755 --- a/build.sh +++ b/build.sh @@ -398,6 +398,9 @@ parse_device echo "---------------- MindSpore: build start ----------------" mkdir -pv "${BUILD_PATH}/package/mindspore/lib" git submodule update --init graphengine +cd "${BASEPATH}/graphengine" +git submodule update --init metadef +cd "${BASEPATH}" if [[ "X$ENABLE_AKG" = "Xon" ]] && [[ "X$ENABLE_D" = "Xon" || "X$ENABLE_GPU" = "Xon" ]]; then git submodule update --init --recursive akg fi diff --git a/cmake/dependency_graphenginev2.cmake b/cmake/dependency_graphenginev2.cmake new file mode 100644 index 00000000000..3d003e7f8e6 --- /dev/null +++ b/cmake/dependency_graphenginev2.cmake @@ -0,0 +1,39 @@ +message(STATUS "Compiling GraphEngine") +set(GE_SOURCE_DIR ${CMAKE_SOURCE_DIR}/graphengine) + +message(STATUS "[ME] build_path: ${BUILD_PATH}") + +function(find_submodule_lib module name path) + find_library(${module}_LIBRARY_DIR NAMES ${name} NAMES_PER_DIR PATHS ${path} + PATH_SUFFIXES lib + ) + if ("${${module}_LIBRARY_DIR}" STREQUAL "${module}_LIBRARY_DIR-NOTFOUND") + message(FATAL_ERROR "${name} not found in any of following paths: ${path}") + endif() + add_library(${module} SHARED IMPORTED) + set_target_properties(${module} PROPERTIES + IMPORTED_LOCATION ${${module}_LIBRARY_DIR} + ) +endfunction() + +if (ENABLE_D OR ENABLE_ACL OR ENABLE_TESTCASES) + set(_ge_tmp_CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) + set(_ge_tmp_ENABLE_GITEE ${ENABLE_GITEE}) + set(ENABLE_GITEE ON) + set(CMAKE_INSTALL_PREFIX ${BUILD_PATH}/graphengine) + + if (ENABLE_TESTCASES) + # use slog, error manager, mmpa in non ascend mode, e.g. tests + set(GE_PREBUILD_PATH ${GE_SOURCE_DIR}/third_party/prebuild/${CMAKE_HOST_SYSTEM_PROCESSOR}) + set(ENABLE_MS_TESTCASES TRUE) + find_submodule_lib(slog libslog.so ${GE_PREBUILD_PATH}) + find_submodule_lib(error_manager liberror_manager.so ${GE_PREBUILD_PATH}) + find_submodule_lib(static_mmpa libmmpa.a ${GE_PREBUILD_PATH}) + endif() + + add_subdirectory(${GE_SOURCE_DIR}) + set(CMAKE_INSTALL_PREFIX ${_ge_tmp_CMAKE_INSTALL_PREFIX}) + set(ENABLE_GITEE ${_ge_tmp_ENABLE_GITEE}) +else() + message(FATAL_ERROR "No compile option defined for GraphEngine, exiting") +endif() diff --git a/cmake/mind_expression.cmake b/cmake/mind_expression.cmake index 0a18e56f38e..a396833f50d 100644 --- a/cmake/mind_expression.cmake +++ b/cmake/mind_expression.cmake @@ -61,9 +61,10 @@ if (ENABLE_GE) link_directories(${CMAKE_SOURCE_DIR}/third_party/ge/lib) elseif(ENABLE_D OR ENABLE_ACL OR ENABLE_TESTCASES) include_directories(${CMAKE_SOURCE_DIR}/graphengine/inc) - include_directories(${CMAKE_SOURCE_DIR}/graphengine/inc/ops) include_directories(${CMAKE_SOURCE_DIR}/graphengine/inc/external) - include_directories(${CMAKE_SOURCE_DIR}/graphengine/inc/external/graph) + include_directories(${CMAKE_SOURCE_DIR}/graphengine/metadef/inc) + include_directories(${CMAKE_SOURCE_DIR}/graphengine/metadef/inc/external) + include_directories(${CMAKE_SOURCE_DIR}/graphengine/metadef/inc/external/graph) endif() if (ENABLE_GE OR ENABLE_D OR ENABLE_ACL OR ENABLE_TESTCASES) diff --git a/cmake/package.cmake b/cmake/package.cmake index 0d309b3aafe..0960bdcfb97 100644 --- a/cmake/package.cmake +++ b/cmake/package.cmake @@ -210,7 +210,7 @@ if (NOT ENABLE_GE) set(ASCEND_DRIVER_PATH ${ASCEND_PATH}/driver/lib64/common) install( - FILES ${CMAKE_SOURCE_DIR}/build/graphengine/libc_sec.so + FILES ${CMAKE_SOURCE_DIR}/build/graphengine/c_sec/lib/libc_sec.so DESTINATION ${INSTALL_LIB_DIR} COMPONENT mindspore ) @@ -223,9 +223,9 @@ if (NOT ENABLE_GE) ) install( FILES - ${CMAKE_BINARY_DIR}/graphengine/src/common/graph/libgraph.so - ${CMAKE_BINARY_DIR}/graphengine/src/ge/common/libge_common.so - ${CMAKE_BINARY_DIR}/graphengine/src/ge/ge_runtime/libge_runtime.so + ${CMAKE_BINARY_DIR}/graphengine/metadef/graph/libgraph.so + ${CMAKE_BINARY_DIR}/graphengine/ge/common/libge_common.so + ${CMAKE_BINARY_DIR}/graphengine/ge/ge_runtime/libge_runtime.so DESTINATION ${INSTALL_LIB_DIR} COMPONENT mindspore ) @@ -233,8 +233,8 @@ if (NOT ENABLE_GE) elseif (ENABLE_TESTCASES) install( FILES - ${CMAKE_BINARY_DIR}/graphengine/src/common/graph/libgraph.so - ${CMAKE_SOURCE_DIR}/build/graphengine/libc_sec.so + ${CMAKE_BINARY_DIR}/graphengine/metadef/graph/libgraph.so + ${CMAKE_SOURCE_DIR}/build/graphengine/c_sec/lib/libc_sec.so ${LIBEVENT_LIB_LIST} DESTINATION ${INSTALL_LIB_DIR} COMPONENT mindspore diff --git a/graphengine b/graphengine index ce23341ee2c..20a0326976d 160000 --- a/graphengine +++ b/graphengine @@ -1 +1 @@ -Subproject commit ce23341ee2c7e48b39f227b293d1aa7f54effd34 +Subproject commit 20a0326976db65ca01f43ae4ccdd85677faaeb5e diff --git a/mindspore/ccsrc/runtime/device/ascend/executor/ai_core_dynamic_kernel.cc b/mindspore/ccsrc/runtime/device/ascend/executor/ai_core_dynamic_kernel.cc index 4de335f0200..1eac30f9100 100644 --- a/mindspore/ccsrc/runtime/device/ascend/executor/ai_core_dynamic_kernel.cc +++ b/mindspore/ccsrc/runtime/device/ascend/executor/ai_core_dynamic_kernel.cc @@ -74,17 +74,14 @@ void AiCoreDynamicKernel::ParseCompileJson() { std::replace(compile_info_attr.begin(), compile_info_attr.end(), '\'', '\"'); compile_info_attr = ReplaceInvalidJsonStr(compile_info_attr); MS_LOG(INFO) << "Get compile_info:" << compile_info_attr; - - try { - compile_info_json_ = std::make_shared(nlohmann::json::parse(compile_info_attr)); - } catch (nlohmann::json::parse_error &e) { - MS_LOG(EXCEPTION) << "parse json failed, error:" << e.what(); - } + op_compile_info_.str = compile_info_attr; + op_compile_info_.key = ""; if (AnfAlgo::HasNodeAttr(kAttrFusionType, cnode_ptr_)) { auto fusion_type = AnfAlgo::GetNodeAttr(cnode_ptr_, kAttrFusionType); MS_LOG(INFO) << "Get fusion_type:" << fusion_type; (*compile_info_json_)["_pattern"] = fusion_type; + op_compile_info_.key = std::hash{}(fusion_type); } } @@ -132,8 +129,8 @@ void AiCoreDynamicKernel::ComputeTiling() { MS_LOG(INFO) << "Start compute tiling of:" << cnode_ptr_->fullname_with_scope(); optiling::OpRunInfo op_run_info; - OpTilingCalculater::GetInstance().CalculateTiling(NOT_NULL(cnode_ptr_), NOT_NULL(compile_info_json_), - depend_tensor_map_, NOT_NULL(&op_run_info)); + OpTilingCalculater::GetInstance().CalculateTiling(NOT_NULL(cnode_ptr_), op_compile_info_, depend_tensor_map_, + NOT_NULL(&op_run_info)); block_dim_ = op_run_info.block_dim; workspaces_size_ = op_run_info.workspaces; tiling_data_ = op_run_info.tiling_data.str(); diff --git a/mindspore/ccsrc/runtime/device/ascend/executor/ai_core_dynamic_kernel.h b/mindspore/ccsrc/runtime/device/ascend/executor/ai_core_dynamic_kernel.h index 218ecccb506..67826060426 100644 --- a/mindspore/ccsrc/runtime/device/ascend/executor/ai_core_dynamic_kernel.h +++ b/mindspore/ccsrc/runtime/device/ascend/executor/ai_core_dynamic_kernel.h @@ -24,6 +24,7 @@ #include "nlohmann/json.hpp" #include "ir/tensor.h" #include "runtime/device/device_address.h" +#include "register/op_tiling.h" #include "mindspore/ccsrc/runtime/device/executor/dynamic_kernel.h" namespace mindspore { @@ -60,6 +61,7 @@ class AiCoreDynamicKernel : public DynamicKernel { std::vector workspaces_size_; std::vector workspace_addr_; std::shared_ptr compile_info_json_; + optiling::OpCompileInfo op_compile_info_{}; void ComputeTiling(); bool CopyTilingToDevice(); diff --git a/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.cc b/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.cc index e0bd51ac1b6..88afa8c4f6e 100644 --- a/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.cc +++ b/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.cc @@ -25,6 +25,7 @@ #include "runtime/device/ascend/ge_types_convert.h" #include "utils/utils.h" #include "external/graph/tensor.h" +#include "external/register/op_tiling_registry.h" namespace mindspore { namespace device { @@ -136,7 +137,7 @@ void FeedTeOpConstTensor(const NotNull &cnode, const std::mapsecond; } -void OpTilingCalculater::CalculateTiling(const NotNull &cnode, - const NotNull> &compile_info_json, +void OpTilingCalculater::CalculateTiling(const NotNull &cnode, const optiling::OpCompileInfo &op_compile_info, const std::map &depend_tensor_map, NotNull op_run_info) { optiling::TeOpParas op_param; @@ -181,7 +181,7 @@ void OpTilingCalculater::CalculateTiling(const NotNull &cnode, MS_LOG(INFO) << "Get tiling func:" << iter->first; if (iter != tiling_func_map_.end()) { - bool ret = (iter->second)(op_type, op_param, *compile_info_json.get(), *op_run_info); + bool ret = (iter->second)(op_param, op_compile_info, *op_run_info); if (!ret) { MS_LOG(EXCEPTION) << "Calculate tiling failed"; } diff --git a/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.h b/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.h index 0331ae37574..066d21dd051 100644 --- a/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.h +++ b/mindspore/ccsrc/runtime/device/ascend/executor/tiling/op_tiling_calculater.h @@ -37,8 +37,7 @@ class OpTilingCalculater { } void Init(); - void CalculateTiling(const NotNull &cnode, - const NotNull> &compile_info_json, + void CalculateTiling(const NotNull &cnode, const optiling::OpCompileInfo &op_compile_info, const std::map &depend_tensor_map, NotNull op_run_info); diff --git a/mindspore/ccsrc/runtime/hccl_adapter/hccl_adapter.h b/mindspore/ccsrc/runtime/hccl_adapter/hccl_adapter.h index e5ba2beedb2..cd82fbcc0ad 100644 --- a/mindspore/ccsrc/runtime/hccl_adapter/hccl_adapter.h +++ b/mindspore/ccsrc/runtime/hccl_adapter/hccl_adapter.h @@ -21,7 +21,7 @@ #include #include #include "mindspore/core/ir/anf.h" -#include "external/hccl/hccl_types.h" +#include "hccl/hccl_types.h" #define MS_API __attribute__((visibility("default"))) diff --git a/tests/st/model_zoo_tests/transformer/test_transformer.py b/tests/st/model_zoo_tests/transformer/test_transformer.py index 7ce6abe89d2..11001f92e38 100644 --- a/tests/st/model_zoo_tests/transformer/test_transformer.py +++ b/tests/st/model_zoo_tests/transformer/test_transformer.py @@ -164,10 +164,10 @@ def test_transformer(): # assertion occurs while the loss value, overflow state or loss_scale value is wrong loss_value = np.array(callback.loss_list) - assert np.allclose(loss_value[0], 11.241624, 0, 0.000005) + assert np.allclose(loss_value[0], 11.241604, 0, 0.000005) - expect_loss_value = [11.241624, 11.243232, 11.217465, 11.204196, 11.2138195, - 11.215386, 11.19053, 11.150403, 11.191858, 11.160057] + expect_loss_value = [11.241604, 11.243231, 11.217458, 11.204156, 11.213805, + 11.215374, 11.19065, 11.150393, 11.191824, 11.160044] print("loss value: {}".format(loss_value)) assert np.allclose(loss_value[0:10], expect_loss_value, 0, 0.0005) diff --git a/tests/ut/cpp/runtest.sh b/tests/ut/cpp/runtest.sh index db720e0deae..97d28daf642 100755 --- a/tests/ut/cpp/runtest.sh +++ b/tests/ut/cpp/runtest.sh @@ -15,7 +15,7 @@ # ============================================================================ set -e -BASEPATH=$(cd $(dirname $0); pwd) +BASEPATH=$(cd "$(dirname "$0")"; pwd) PROJECT_PATH=${BASEPATH}/../../.. if [ $BUILD_PATH ];then echo "BUILD_PATH = $BUILD_PATH" @@ -26,7 +26,9 @@ fi cd ${BUILD_PATH}/mindspore/tests/ut/cpp -export LD_LIBRARY_PATH=${BUILD_PATH}/mindspore/googletest/googlemock/gtest:${PROJECT_PATH}/mindspore:${PROJECT_PATH}/mindspore/lib:$LD_LIBRARY_PATH +export LD_LIBRARY_PATH=${BUILD_PATH}/mindspore/googletest/googlemock/gtest:${PROJECT_PATH}/mindspore:\ +${PROJECT_PATH}/mindspore/lib:${PROJECT_PATH}/graphengine/third_party/prebuild/x86_64:\ +${PROJECT_PATH}/graphengine/third_party/prebuild/aarch64:${LD_LIBRARY_PATH} export PYTHONPATH=${PROJECT_PATH}/tests/ut/cpp/python_input:$PYTHONPATH:${PROJECT_PATH} export GLOG_v=2 export GC_COLLECT_IN_CELL=1 diff --git a/tests/ut/cpp/stub/dynamic_shape/dynamic_shape_stub.cc b/tests/ut/cpp/stub/dynamic_shape/dynamic_shape_stub.cc index 5560abd0a6e..19f869baaf4 100644 --- a/tests/ut/cpp/stub/dynamic_shape/dynamic_shape_stub.cc +++ b/tests/ut/cpp/stub/dynamic_shape/dynamic_shape_stub.cc @@ -53,10 +53,9 @@ bool HcclExecutorManager::Initialize() { return true; } bool HcclExecutorManager::Finalize() { return true; } void OpTilingCalculater::Init() {} -void OpTilingCalculater::CalculateTiling(const NotNull &cnode, - const NotNull> &compile_info_json, - const std::map &depend_tensor_map, - NotNull op_run_info) {} +void OpTilingCalculater::CalculateTiling(const NotNull &cnode, const optiling::OpCompileInfo &op_compile_info, + const std::map &depend_tensor_map, + NotNull op_run_info) {} } // namespace ascend } // namespace device } // namespace mindspore