From: @hugo1 Reviewed-by: @sheng-nan,@wqtshg Signed-off-by: @wqtshgtags/v1.3.0
| @@ -39,7 +39,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) | |||
| if (ENABLE_GE_COV OR ENABLE_GE_UT OR ENABLE_GE_ST) | |||
| set(HI_PYTHON python3) | |||
| include(cmake/external_libs/protobuf_shared.cmake) | |||
| @@ -51,118 +51,132 @@ if (ENABLE_OPEN_SRC) | |||
| include(cmake/external_libs/json.cmake) | |||
| include(cmake/FindModule.cmake) | |||
| include(cmake/intf_pub_linux.cmake) | |||
| # if D_LINK_PATH is set in environment variables, search libraries in given path | |||
| if(DEFINED ENV{D_LINK_PATH}) | |||
| # D_LINK_PATH is set | |||
| set(GE_LIB_PATH $ENV{D_LINK_PATH}) | |||
| set(GE_SYS_ARCH "") | |||
| if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64") | |||
| # x86 ubuntu | |||
| set(GE_SYS_ARCH "x86_64") | |||
| elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") | |||
| # arm euleros | |||
| set(GE_SYS_ARCH "aarch64") | |||
| add_subdirectory(tests) | |||
| else () | |||
| if (ENABLE_OPEN_SRC) | |||
| set(HI_PYTHON python3) | |||
| include(cmake/external_libs/protobuf_shared.cmake) | |||
| include(cmake/external_libs/protobuf_static.cmake) | |||
| include(cmake/external_libs/protoc.cmake) | |||
| include(cmake/external_libs/gflags.cmake) | |||
| include(cmake/external_libs/gtest.cmake) | |||
| include(cmake/external_libs/securec.cmake) | |||
| include(cmake/external_libs/json.cmake) | |||
| include(cmake/FindModule.cmake) | |||
| include(cmake/intf_pub_linux.cmake) | |||
| # if D_LINK_PATH is set in environment variables, search libraries in given path | |||
| if(DEFINED ENV{D_LINK_PATH}) | |||
| # D_LINK_PATH is set | |||
| set(GE_LIB_PATH $ENV{D_LINK_PATH}) | |||
| set(GE_SYS_ARCH "") | |||
| if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64") | |||
| # x86 ubuntu | |||
| set(GE_SYS_ARCH "x86_64") | |||
| elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") | |||
| # arm euleros | |||
| set(GE_SYS_ARCH "aarch64") | |||
| else() | |||
| message(FATAL_ERROR "Running on a unsupported architecture: ${SYSTEM_TYPE}, build terminated") | |||
| endif() | |||
| set(GE_LIB_PATH ${GE_LIB_PATH}/${GE_SYS_ARCH}) | |||
| set(STATIC_ACL_LIB ${GE_LIB_PATH}) | |||
| find_module(slog libalog.so ${GE_LIB_PATH}) | |||
| find_module(static_mmpa libmmpa.a ${GE_LIB_PATH}) | |||
| find_module(msprofiler_ext 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}) | |||
| find_module(runtime_compile libruntime_compile.so ${GE_LIB_PATH}) | |||
| find_module(resource libresource.so ${GE_LIB_PATH}) | |||
| find_module(ascend_hal_stub libascend_hal.so ${GE_LIB_PATH}) | |||
| find_module(msprofiler_fwk_ext libmsprofiler_fwk.a ${GE_LIB_PATH}) | |||
| #find_module(ascendcl_static libascendcl.a ${GE_LIB_PATH}) | |||
| else() | |||
| message(FATAL_ERROR "Running on a unsupported architecture: ${SYSTEM_TYPE}, build terminated") | |||
| endif() | |||
| set(GE_LIB_PATH ${GE_LIB_PATH}/${GE_SYS_ARCH}) | |||
| set(STATIC_ACL_LIB ${GE_LIB_PATH}) | |||
| find_module(slog libalog.so ${GE_LIB_PATH}) | |||
| find_module(static_mmpa libmmpa.a ${GE_LIB_PATH}) | |||
| find_module(msprofiler_ext 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}) | |||
| find_module(runtime_compile libruntime_compile.so ${GE_LIB_PATH}) | |||
| find_module(resource libresource.so ${GE_LIB_PATH}) | |||
| find_module(ascend_hal_stub libascend_hal.so ${GE_LIB_PATH}) | |||
| find_module(msprofiler_fwk_ext libmsprofiler_fwk.a ${GE_LIB_PATH}) | |||
| #find_module(ascendcl_static libascendcl.a ${GE_LIB_PATH}) | |||
| elseif(ENABLE_GE_COV OR ENABLE_GE_UT) | |||
| add_subdirectory(tests) | |||
| else() | |||
| find_module(slog libalog.so ${ASCEND_ATC_DIR}) | |||
| find_module(static_mmpa libmmpa.a ${ASCEND_ATC_DIR}) | |||
| if(PLATFORM STREQUAL "train") | |||
| find_module(slog libalog.so ${ASCEND_ATC_DIR}) | |||
| find_module(static_mmpa libmmpa.a ${ASCEND_ATC_DIR}) | |||
| if(PLATFORM STREQUAL "train") | |||
| find_module(adump_server libadump_server.a ${ASCEND_RUNTIME_DIR}) | |||
| find_module(runtime libruntime.so ${ASCEND_RUNTIME_DIR}) | |||
| find_module(msprofiler_fwk_ext 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") | |||
| endif() | |||
| elseif(PLATFORM STREQUAL "inference") | |||
| find_module(adump_server libadump_server.a ${ASCEND_ACL_DIR}) | |||
| find_module(runtime libruntime.so ${ASCEND_ACL_DIR}) | |||
| find_module(runtime_compile libruntime_compile.so ${ASCEND_ATC_DIR}) | |||
| find_module(msprofiler_ext libmsprofiler.a ${ASCEND_ACL_DIR}) | |||
| if(PRODUCT STREQUAL "flr3") | |||
| elseif(PRODUCT STREQUAL "flr1") | |||
| find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}/driver) | |||
| elseif(PRODUCT STREQUAL "flr2") | |||
| # flr2 ascend_hal_stub limsprof ? | |||
| else() | |||
| find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}) | |||
| endif() | |||
| elseif(PLATFORM STREQUAL "all") | |||
| find_module(adump_server libadump_server.a ${ASCEND_RUNTIME_DIR}) | |||
| find_module(runtime libruntime.so ${ASCEND_RUNTIME_DIR}) | |||
| find_module(msprofiler_fwk_ext 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") | |||
| endif() | |||
| elseif(PLATFORM STREQUAL "inference") | |||
| find_module(adump_server libadump_server.a ${ASCEND_ACL_DIR}) | |||
| find_module(runtime libruntime.so ${ASCEND_ACL_DIR}) | |||
| find_module(runtime_compile libruntime_compile.so ${ASCEND_ATC_DIR}) | |||
| find_module(msprofiler_fwk_ext libmsprofiler_fwk.a ${ASCEND_RUNTIME_DIR}) | |||
| find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}) | |||
| find_module(runtime_compile libruntime_compile.so ${ASCEND_ATC_DIR}) | |||
| find_module(msprofiler_ext libmsprofiler.a ${ASCEND_ACL_DIR}) | |||
| if(PRODUCT STREQUAL "flr3") | |||
| elseif(PRODUCT STREQUAL "flr1") | |||
| find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}/driver) | |||
| elseif(PRODUCT STREQUAL "flr2") | |||
| # flr2 ascend_hal_stub limsprof ? | |||
| else() | |||
| find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}) | |||
| message(STATUS "PLATFORM param is invalid, should be train or inference, you choose nothing!") | |||
| endif() | |||
| elseif(PLATFORM STREQUAL "all") | |||
| find_module(adump_server libadump_server.a ${ASCEND_RUNTIME_DIR}) | |||
| find_module(runtime libruntime.so ${ASCEND_RUNTIME_DIR}) | |||
| find_module(msprofiler_fwk_ext libmsprofiler_fwk.a ${ASCEND_RUNTIME_DIR}) | |||
| find_module(ascend_hal_stub libascend_hal.so ${ASCEND_DRIVER_DIR}) | |||
| find_module(runtime_compile libruntime_compile.so ${ASCEND_ATC_DIR}) | |||
| find_module(msprofiler_ext libmsprofiler.a ${ASCEND_ACL_DIR}) | |||
| else() | |||
| message(STATUS "PLATFORM param is invalid, should be train or inference, you choose nothing!") | |||
| endif() | |||
| endif() | |||
| set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef) | |||
| set(PARSER_DIR ${CMAKE_CURRENT_LIST_DIR}/parser) | |||
| set(GE_DEPEND_DIR ${CMAKE_CURRENT_LIST_DIR}/..) | |||
| add_subdirectory(metadef) | |||
| add_subdirectory(parser) | |||
| #add_subdirectory(metadef/graph) | |||
| #add_subdirectory(metadef/register) | |||
| elseif (ENABLE_D OR ENABLE_ACL) | |||
| # compiling with MindSpore | |||
| include(cmake/external_libs/protobuf_static.cmake) | |||
| include(cmake/external_libs/protoc.cmake) | |||
| include(cmake/external_libs/securec.cmake) | |||
| include(cmake/external_libs/json.cmake) | |||
| include(cmake/FindModule.cmake) | |||
| include(cmake/intf_pub_linux.cmake) | |||
| # common libraries | |||
| find_module(slog libalog.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(static_mmpa libmmpa.a ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| if (ENABLE_D) | |||
| # training | |||
| find_module(runtime libruntime.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(register libregister.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| endif () | |||
| set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef) | |||
| add_subdirectory(metadef) | |||
| elseif(ENABLE_MS_TESTCASES) | |||
| include(cmake/external_libs/protobuf_static.cmake) | |||
| include(cmake/external_libs/protoc.cmake) | |||
| include(cmake/external_libs/securec.cmake) | |||
| include(cmake/FindModule.cmake) | |||
| include(cmake/intf_pub_linux.cmake) | |||
| # common libraries | |||
| find_module(slog libalog.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(static_mmpa libmmpa.a ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef) | |||
| set(PARSER_DIR ${CMAKE_CURRENT_LIST_DIR}/parser) | |||
| set(GE_DEPEND_DIR ${CMAKE_CURRENT_LIST_DIR}/..) | |||
| add_subdirectory(metadef) | |||
| add_subdirectory(parser) | |||
| #add_subdirectory(metadef/graph) | |||
| #add_subdirectory(metadef/register) | |||
| elseif (ENABLE_D OR ENABLE_ACL) | |||
| # compiling with MindSpore | |||
| include(cmake/external_libs/protobuf_static.cmake) | |||
| include(cmake/external_libs/protoc.cmake) | |||
| include(cmake/external_libs/securec.cmake) | |||
| include(cmake/external_libs/json.cmake) | |||
| include(cmake/FindModule.cmake) | |||
| include(cmake/intf_pub_linux.cmake) | |||
| # common libraries | |||
| find_module(slog libalog.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(static_mmpa libmmpa.a ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| if (ENABLE_D) | |||
| # training | |||
| find_module(runtime libruntime.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(register libregister.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| endif () | |||
| set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef) | |||
| add_subdirectory(metadef) | |||
| elseif(ENABLE_MS_TESTCASES) | |||
| include(cmake/external_libs/protobuf_static.cmake) | |||
| include(cmake/external_libs/protoc.cmake) | |||
| include(cmake/external_libs/securec.cmake) | |||
| include(cmake/FindModule.cmake) | |||
| include(cmake/intf_pub_linux.cmake) | |||
| # common libraries | |||
| find_module(slog libalog.so ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| find_module(static_mmpa libmmpa.a ${ASCEND_MS_RUNTIME_PATH} ${ATLAS_MS_RUNTIME_PATH}) | |||
| set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef) | |||
| add_subdirectory(metadef) | |||
| else() | |||
| set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/../metadef) | |||
| set(PARSER_DIR ${CMAKE_CURRENT_LIST_DIR}/../parser) | |||
| set(GE_DEPEND_DIR ${CMAKE_CURRENT_LIST_DIR}/..) | |||
| endif() | |||
| set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/metadef) | |||
| add_subdirectory(metadef) | |||
| else() | |||
| set(METADEF_DIR ${CMAKE_CURRENT_LIST_DIR}/../metadef) | |||
| set(PARSER_DIR ${CMAKE_CURRENT_LIST_DIR}/../parser) | |||
| set(GE_DEPEND_DIR ${CMAKE_CURRENT_LIST_DIR}/..) | |||
| endif() | |||
| add_subdirectory(ge) | |||
| add_subdirectory(ge) | |||
| endif () | |||
| @@ -177,6 +177,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$ENABLE_GE_ST" = "Xon" ] | |||
| then | |||
| TARGET="graph_engine_test" | |||
| elif [ "X$MINDSPORE_MODE" = "Xon" ] | |||
| then | |||
| TARGET="ge_common graph" | |||
| @@ -234,6 +237,29 @@ if [[ "X$ENABLE_GE_UT" = "Xon" || "X$ENABLE_GE_COV" = "Xon" ]]; then | |||
| genhtml coverage.info | |||
| fi | |||
| if [[ "X$ENABLE_GE_ST" = "Xon" ]]; then | |||
| #prepare engine & opskernel so | |||
| mkdir -p ${OUTPUT_PATH}/plugin/nnengine | |||
| mkdir -p ${OUTPUT_PATH}/plugin/nnengine/ge_config | |||
| mkdir -p ${OUTPUT_PATH}/plugin/opskernel | |||
| cp ${BUILD_PATH}/tests/st/libnnengine.so ${OUTPUT_PATH}/plugin/nnengine | |||
| cp ${BUILD_PATH}/engine_conf.json ${OUTPUT_PATH}/plugin/nnengine/ge_config | |||
| cp ${BUILD_PATH}/tests/st/libhost_cpu_engine.so ${OUTPUT_PATH}/plugin/opskernel | |||
| cp ${BUILD_PATH}/tests/st/libge_local_engine.so ${OUTPUT_PATH}/plugin/opskernel | |||
| cp ${BUILD_PATH}/tests/st/framework/libfe.so ${OUTPUT_PATH}/plugin/opskernel | |||
| #prepare st execution bin | |||
| cp ${BUILD_PATH}/tests/st/testcase/graph_engine_test ${OUTPUT_PATH} | |||
| #execute st testcase | |||
| RUN_TEST_CASE=${OUTPUT_PATH}/graph_engine_test && ${RUN_TEST_CASE} | |||
| if [[ "$?" -ne 0 ]]; then | |||
| echo "!!! ST FAILED, PLEASE CHECK YOUR CHANGES !!!" | |||
| echo -e "\033[31m${RUN_TEST_CASE}\033[0m" | |||
| exit 1; | |||
| fi | |||
| # remove plugin | |||
| rm -rf ${OUTPUT_PATH}/plugin | |||
| fi | |||
| # generate output package in tar form, including ut/st libraries/executables | |||
| generate_package() | |||
| { | |||
| @@ -337,7 +363,7 @@ generate_package() | |||
| fi | |||
| } | |||
| if [[ "X$ENABLE_GE_UT" = "Xoff" && "X$MINDSPORE_MODE" = "Xoff" ]]; then | |||
| if [[ "X$ENABLE_GE_UT" = "Xoff" && "X$ENABLE_GE_ST" = "Xoff" && "X$MINDSPORE_MODE" = "Xoff" ]]; then | |||
| generate_package | |||
| elif [ "X$MINDSPORE_MODE" = "Xon" ] | |||
| then | |||
| @@ -25,6 +25,7 @@ | |||
| #include "framework/common/op/op_parser_util.h" | |||
| #include "graph/types.h" | |||
| #include "task/task_factory.h" | |||
| #include "ge/common/math/math_util.h" | |||
| namespace ge { | |||
| namespace model_runner { | |||
| @@ -500,7 +501,7 @@ bool RuntimeModel::InitConstantInfo(std::shared_ptr<DavinciModel> &davinci_model | |||
| } | |||
| uint64_t *buff = reinterpret_cast<uint64_t *>(const_cast<char *>(constant->weight_data.data())); | |||
| uint32_t head_len = kOffsetUnit * kStringHeadElems; | |||
| if (ge::CheckInt64Uint32MulOverflow(elem_num, head_len) != SUCCESS) { | |||
| if (CheckInt64Uint32MulOverflow(elem_num, head_len) != SUCCESS) { | |||
| GELOGE(FAILED, "Shape size is invalid"); | |||
| return false; | |||
| } | |||
| @@ -83,7 +83,7 @@ bool AicpuTask::Distribute() { | |||
| return false; | |||
| } | |||
| GELOGI("ext info size:", ext_size); | |||
| GELOGI("ext info size: %u", ext_size); | |||
| aicpu_param_head.extInfoLength = ext_size; | |||
| aicpu_param_head.extInfoAddr = reinterpret_cast<uintptr_t>(ext_info_); | |||
| } | |||
| @@ -130,7 +130,7 @@ bool HcclTask::SetSecondaryStream() { | |||
| Status ret; | |||
| std::lock_guard<std::mutex> lock(model_stream_mapping_mutex_); | |||
| if (model_stream_mapping_.find(rt_model_handle_) == model_stream_mapping_.end()) { | |||
| GELOGI("Need to create map for rt_model_handle_:%p with new mainstream %ld.", rt_model_handle_, master_stream_id); | |||
| GELOGI("Need to create map for rt_model_handle_:%p with new mainstream %u.", rt_model_handle_, master_stream_id); | |||
| ret = CreateStream(hccl_secondary_stream_num, master_stream_id); | |||
| if (!ret) { | |||
| GELOGE(RT_FAILED, "Create hccl stream failed."); | |||
| @@ -189,7 +189,7 @@ bool HcclTask::SetSecondaryStream() { | |||
| } | |||
| GELOGI("Initialize hccl secondary stream success, hccl_secondary_stream_num =%ld", hccl_secondary_stream_num); | |||
| } else { | |||
| GELOGI("Need to create secondary stream for %s with new mainstream %ld.", task_info_->op_name().c_str(), | |||
| GELOGI("Need to create secondary stream for %s with new mainstream %u.", task_info_->op_name().c_str(), | |||
| master_stream_id); | |||
| ret = CreateStream(hccl_secondary_stream_num, master_stream_id); | |||
| if (!ret) { | |||
| @@ -72,7 +72,7 @@ bool LabelGotoTask::Distribute() { | |||
| return false; | |||
| } | |||
| rt_ret = rtLabelListCpy(label_list.data(), label_list.size(), label_info_, label_info_size); | |||
| rt_ret = rtLabelListCpy((void**)label_list.data(), label_list.size(), label_info_, label_info_size); | |||
| if (rt_ret != RT_ERROR_NONE) { | |||
| GELOGE(RT_FAILED, "Call rt api failed, ret: %#x", rt_ret); | |||
| return false; | |||
| @@ -69,7 +69,7 @@ bool LabelSwitchTask::Distribute() { | |||
| return false; | |||
| } | |||
| label_list[i] = all_label_resource_[label_index]; | |||
| GELOGI("Case %zu: label id %zu.", i, label_index); | |||
| GELOGI("Case %zu: label id %zu.", i, (size_t)label_index); | |||
| } | |||
| uint32_t label_info_size = sizeof(rtLabelDevInfo) * task_info_->label_size(); | |||
| @@ -0,0 +1,6 @@ | |||
| project(graphengine_st) | |||
| include(cmake/graphengine.cmake) | |||
| add_subdirectory(framework) | |||
| add_subdirectory(testcase) | |||
| @@ -0,0 +1,276 @@ | |||
| # ---- Test coverage ---- | |||
| if (ENABLE_GE_COV) | |||
| set(COVERAGE_COMPILER_FLAGS "-g --coverage -fprofile-arcs -fPIC -O0 -ftest-coverage") | |||
| set(CMAKE_CXX_FLAGS "${COVERAGE_COMPILER_FLAGS}") | |||
| endif() | |||
| # ----metadef Proto generate ---- | |||
| set(PROTO_LIST | |||
| "${GE_CODE_DIR}/metadef/proto/om.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/ge_ir.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/insert_op.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/task.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/dump_task.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/fwk_adapter.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/op_mapping.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/ge_api.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/optimizer_priority.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/onnx/ge_onnx.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/attr_value.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/function.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/graph.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/node_def.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/op_def.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/resource_handle.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/tensor.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/tensor_shape.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/types.proto" | |||
| "${GE_CODE_DIR}/metadef/proto/tensorflow/versions.proto" | |||
| ) | |||
| protobuf_generate(ge PROTO_SRCS PROTO_HDRS ${PROTO_LIST}) | |||
| # ---- File glob by group ---- | |||
| file(GLOB_RECURSE METADEF_SRCS CONFIGURE_DEPENDS | |||
| "${GE_CODE_DIR}/metadef/graph/*.cc" | |||
| "${GE_CODE_DIR}/metadef/register/*.cc" | |||
| "${GE_CODE_DIR}/metadef/register/*.cpp" | |||
| "${GE_CODE_DIR}/metadef/ops/*.cc" | |||
| "${GE_CODE_DIR}/metadef/third_party/transformer/src/*.cc" | |||
| ) | |||
| file(GLOB_RECURSE METADEF_REGISTER_SRCS CONFIGURE_DEPENDS | |||
| "${GE_CODE_DIR}/metadef/register/*.cc" | |||
| "${GE_CODE_DIR}/metadef/register/*.cpp" | |||
| ) | |||
| file(GLOB_RECURSE PARSER_SRCS CONFIGURE_DEPENDS | |||
| "${GE_CODE_DIR}/parser/parser/common/*.cc" | |||
| ) | |||
| file(GLOB_RECURSE LOCAL_ENGINE_SRC CONFIGURE_DEPENDS | |||
| "${GE_CODE_DIR}/ge/ge_local_engine/*.cc" | |||
| ) | |||
| list(REMOVE_ITEM LOCAL_ENGINE_SRC | |||
| "${GE_CODE_DIR}/ge/ge_local_engine/engine/host_cpu_engine.cc") | |||
| file(GLOB_RECURSE HOST_ENGINE_SRC CONFIGURE_DEPENDS | |||
| "${GE_CODE_DIR}/ge/host_cpu_engine/*.cc" | |||
| ) | |||
| file(GLOB_RECURSE NN_ENGINE_SRC CONFIGURE_DEPENDS | |||
| "${GE_CODE_DIR}/ge/plugin/*.cc" | |||
| ) | |||
| file(GLOB_RECURSE OFFLINE_SRC CONFIGURE_DEPENDS | |||
| "${GE_CODE_DIR}/ge/offline/*.cc" | |||
| ) | |||
| file(GLOB_RECURSE GE_SRCS CONFIGURE_DEPENDS | |||
| "${GE_CODE_DIR}/ge/*.cc" | |||
| ) | |||
| file(GLOB_RECURSE GE_SUB_ENGINE_SRCS CONFIGURE_DEPENDS | |||
| "${GE_CODE_DIR}/ge/ge_local_engine/engine/host_cpu_engine.cc" | |||
| ) | |||
| list(REMOVE_ITEM GE_SRCS ${LOCAL_ENGINE_SRC} ${HOST_ENGINE_SRC} ${NN_ENGINE_SRC} ${OFFLINE_SRC}) | |||
| list(APPEND GE_SRCS ${GE_SUB_ENGINE_SRCS}) | |||
| list(APPEND INCLUDE_DIRECTORIES | |||
| "${CMAKE_CURRENT_SOURCE_DIR}" | |||
| "${GE_CODE_DIR}" | |||
| "${GE_CODE_DIR}/inc" | |||
| "${GE_CODE_DIR}/metadef/inc" | |||
| "${GE_CODE_DIR}/ge" | |||
| "${GE_CODE_DIR}/ge/inc" | |||
| "${GE_CODE_DIR}/ge/ir_build" | |||
| "${GE_CODE_DIR}/metadef" | |||
| "${GE_CODE_DIR}/metadef/graph" | |||
| "${GE_CODE_DIR}/inc/external" | |||
| "${GE_CODE_DIR}/inc/framework/common" | |||
| "${GE_CODE_DIR}/metadef/inc/external" | |||
| "${GE_CODE_DIR}/metadef/inc/external/graph" | |||
| "${GE_CODE_DIR}/metadef/inc/graph" | |||
| "${GE_CODE_DIR}/inc/framework" | |||
| "${GE_CODE_DIR}/metadef/inc/common" | |||
| "${GE_CODE_DIR}/metadef/third_party" | |||
| "${GE_CODE_DIR}/metadef/third_party/transformer/inc" | |||
| "${GE_CODE_DIR}/parser" | |||
| "${GE_CODE_DIR}/parser/parser" | |||
| "${GE_CODE_DIR}/third_party/fwkacllib/inc" | |||
| "${GE_CODE_DIR}/third_party/fwkacllib/inc/cce" | |||
| "${GE_CODE_DIR}/third_party/fwkacllib/inc/ops" | |||
| "${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain" | |||
| "${GE_CODE_DIR}/tests/ut/ge" | |||
| "${GE_CODE_DIR}/tests/ut/common" | |||
| "${CMAKE_BINARY_DIR}" | |||
| "${CMAKE_BINARY_DIR}/proto/ge" | |||
| "${CMAKE_BINARY_DIR}/proto/ge/proto" | |||
| ) | |||
| list(APPEND STUB_LIBS | |||
| c_sec | |||
| slog_stub | |||
| cce_ge_stub | |||
| runtime_stub | |||
| profiler_stub | |||
| hccl_stub | |||
| error_manager_stub | |||
| ascend_protobuf | |||
| json | |||
| ) | |||
| # ---- Target : metadef graph ---- | |||
| add_library(metadef_graph SHARED ${METADEF_SRCS} ${PROTO_SRCS}) | |||
| target_include_directories(metadef_graph | |||
| PUBLIC | |||
| "${INCLUDE_DIRECTORIES}" | |||
| ) | |||
| target_compile_definitions(metadef_graph PRIVATE | |||
| google=ascend_private | |||
| FMK_SUPPORT_DUMP | |||
| ) | |||
| target_compile_options(metadef_graph PRIVATE | |||
| -g --coverage -fprofile-arcs -ftest-coverage | |||
| -Werror=format | |||
| ) | |||
| target_link_libraries(metadef_graph PUBLIC | |||
| $<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} | |||
| mmpa -L${GE_CODE_DIR}/third_party/prebuild/x86_64 -lrt -ldl -lpthread -lgcov | |||
| ) | |||
| set_target_properties(metadef_graph PROPERTIES CXX_STANDARD 11) | |||
| # ---- Target : Local engine ---- | |||
| add_library(ge_local_engine SHARED ${LOCAL_ENGINE_SRC} ${METADEF_REGISTER_SRCS}) | |||
| target_include_directories(ge_local_engine | |||
| PUBLIC | |||
| "${INCLUDE_DIRECTORIES}" | |||
| "${GE_CODE_DIR}/ge/ge_local_engine" | |||
| ) | |||
| target_compile_definitions(ge_local_engine PRIVATE | |||
| google=ascend_private | |||
| ) | |||
| target_compile_options(ge_local_engine PRIVATE | |||
| -g --coverage -fprofile-arcs -ftest-coverage | |||
| -Werror=format | |||
| ) | |||
| target_link_libraries(ge_local_engine PUBLIC | |||
| $<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} | |||
| metadef_graph | |||
| -lrt -ldl -lpthread -lgcov | |||
| ) | |||
| set_target_properties(ge_local_engine PROPERTIES CXX_STANDARD 11) | |||
| # ---- Target : Host engine ---- | |||
| add_library(host_cpu_engine SHARED ${HOST_ENGINE_SRC}) | |||
| target_include_directories(host_cpu_engine | |||
| PUBLIC | |||
| "${INCLUDE_DIRECTORIES}" | |||
| "${GE_CODE_DIR}/ge/host_cpu_engine" | |||
| ) | |||
| target_compile_definitions(host_cpu_engine PRIVATE | |||
| google=ascend_private | |||
| FMK_SUPPORT_DUMP | |||
| ) | |||
| target_compile_options(host_cpu_engine PRIVATE | |||
| -g --coverage -fprofile-arcs -ftest-coverage | |||
| -Werror=format | |||
| ) | |||
| target_link_libraries(host_cpu_engine PUBLIC | |||
| $<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} metadef_graph -lrt -ldl -lpthread -lgcov | |||
| ) | |||
| set_target_properties(host_cpu_engine PROPERTIES CXX_STANDARD 11) | |||
| # ---- Target : engine plugin---- | |||
| # | |||
| add_library(nnengine SHARED ${NN_ENGINE_SRC}) | |||
| target_include_directories(nnengine | |||
| PUBLIC | |||
| "${INCLUDE_DIRECTORIES}" | |||
| "${GE_CODE_DIR}/ge/plugin/engine" | |||
| ) | |||
| target_compile_definitions(nnengine PRIVATE | |||
| google=ascend_private | |||
| ) | |||
| target_compile_options(nnengine PRIVATE | |||
| -g --coverage -fprofile-arcs -ftest-coverage | |||
| -Werror=format | |||
| ) | |||
| target_link_libraries(nnengine PUBLIC | |||
| $<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} -lrt -ldl -lpthread -lgcov | |||
| ) | |||
| set_target_properties(nnengine PROPERTIES CXX_STANDARD 11) | |||
| # Targe: engine_conf | |||
| add_custom_target( | |||
| engine_conf.json ALL | |||
| DEPENDS ${CMAKE_BINARY_DIR}/engine_conf.json | |||
| ) | |||
| add_custom_command( | |||
| OUTPUT ${CMAKE_BINARY_DIR}/engine_conf.json | |||
| COMMAND cp ${GE_CODE_DIR}/ge/engine_manager/engine_conf.json ${CMAKE_BINARY_DIR}/ | |||
| ) | |||
| # Targe: optimizer priority | |||
| add_custom_target( | |||
| optimizer_priority.pbtxt ALL | |||
| DEPENDS ${CMAKE_BINARY_DIR}/optimizer_priority.pbtxt | |||
| ) | |||
| add_custom_command( | |||
| OUTPUT ${CMAKE_BINARY_DIR}/optimizer_priority.pbtxt | |||
| COMMAND cp ${GE_CODE_DIR}/ge/opskernel_manager/optimizer_priority.pbtxt ${CMAKE_BINARY_DIR}/ | |||
| ) | |||
| # ---- Target : Graph engine ---- | |||
| add_library(graphengine STATIC ${PARSER_SRCS} ${GE_SRCS}) | |||
| target_include_directories(graphengine | |||
| PUBLIC | |||
| "${INCLUDE_DIRECTORIES}" | |||
| "${GE_CODE_DIR}/ge/host_cpu_engine" | |||
| ) | |||
| target_compile_definitions(graphengine PRIVATE | |||
| google=ascend_private | |||
| FMK_SUPPORT_DUMP | |||
| ) | |||
| target_compile_options(graphengine PRIVATE | |||
| -g --coverage -fprofile-arcs -ftest-coverage | |||
| -Werror=format | |||
| ) | |||
| target_link_libraries(graphengine PUBLIC | |||
| $<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} | |||
| metadef_graph | |||
| -lrt -ldl -lpthread -lgcov | |||
| ) | |||
| set_target_properties(graphengine PROPERTIES CXX_STANDARD 11) | |||
| add_dependencies(graphengine host_cpu_engine ge_local_engine nnengine engine_conf.json optimizer_priority.pbtxt) | |||
| @@ -0,0 +1,77 @@ | |||
| list(APPEND INCLUDE_DIRECTORIES | |||
| "${CMAKE_CURRENT_SOURCE_DIR}" | |||
| "${GE_CODE_DIR}" | |||
| "${GE_CODE_DIR}/inc" | |||
| "${GE_CODE_DIR}/metadef/inc" | |||
| "${GE_CODE_DIR}/ge" | |||
| "${GE_CODE_DIR}/ge/inc" | |||
| "${GE_CODE_DIR}/ge/ir_build" | |||
| "${GE_CODE_DIR}/metadef" | |||
| "${GE_CODE_DIR}/metadef/graph" | |||
| "${GE_CODE_DIR}/inc/external" | |||
| "${GE_CODE_DIR}/inc/framework/common" | |||
| "${GE_CODE_DIR}/metadef/inc/external" | |||
| "${GE_CODE_DIR}/metadef/inc/external/graph" | |||
| "${GE_CODE_DIR}/metadef/inc/graph" | |||
| "${GE_CODE_DIR}/inc/framework" | |||
| "${GE_CODE_DIR}/metadef/inc/common" | |||
| "${GE_CODE_DIR}/metadef/third_party" | |||
| "${GE_CODE_DIR}/metadef/third_party/transformer/inc" | |||
| "${GE_CODE_DIR}/parser" | |||
| "${GE_CODE_DIR}/parser/parser" | |||
| "${GE_CODE_DIR}/third_party/fwkacllib/inc" | |||
| "${GE_CODE_DIR}/third_party/fwkacllib/inc/cce" | |||
| "${GE_CODE_DIR}/third_party/fwkacllib/inc/ops" | |||
| "${GE_CODE_DIR}/third_party/fwkacllib/inc/toolchain" | |||
| "${GE_CODE_DIR}/tests/ut/ge" | |||
| "${GE_CODE_DIR}/tests/ut/common" | |||
| "${CMAKE_BINARY_DIR}" | |||
| "${CMAKE_BINARY_DIR}/proto/ge" | |||
| "${CMAKE_BINARY_DIR}/proto/ge/proto" | |||
| ) | |||
| file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP" "*.c++") | |||
| #todo | |||
| file(GLOB_RECURSE STUB_ENGINE_SRC CONFIGURE_DEPENDS | |||
| "stub_engine/*.cc" | |||
| ) | |||
| # ---- Target : stub Host engine ---- | |||
| add_library(fe SHARED ${STUB_ENGINE_SRC}) | |||
| target_include_directories(fe | |||
| PUBLIC | |||
| ${INCLUDE_DIRECTORIES} | |||
| ${GE_CODE_DIR}/tests/st/framework | |||
| ${CMAKE_CURRENT_SOURCE_DIR} | |||
| ${CMAKE_CURRENT_SOURCE_DIR}/stub_engine | |||
| ) | |||
| target_compile_definitions(fe PRIVATE | |||
| google=ascend_private | |||
| FMK_SUPPORT_DUMP | |||
| ) | |||
| target_compile_options(fe PRIVATE | |||
| -g --coverage -fprofile-arcs -ftest-coverage | |||
| -Werror=format | |||
| ) | |||
| target_link_libraries(fe PUBLIC | |||
| $<BUILD_INTERFACE:intf_pub> ${STUB_LIBS} metadef_graph -lmmpa -L${GE_CODE_DIR}/third_party/prebuild/x86_64 -lrt -ldl -lpthread -lgcov | |||
| ) | |||
| set_target_properties(fe PROPERTIES CXX_STANDARD 11) | |||
| # ---- Target : framework ---- | |||
| list(REMOVE_ITEM SOURCES ${STUB_ENGINE_SRC}) | |||
| add_library(framework STATIC ${SOURCES}) | |||
| target_include_directories(framework | |||
| PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} | |||
| ) | |||
| set_target_properties(framework PROPERTIES CXX_STANDARD 11) | |||
| target_link_libraries(framework PUBLIC graphengine fe) | |||
| @@ -0,0 +1,17 @@ | |||
| /** | |||
| * Copyright 2021 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 "framework.h" | |||
| @@ -0,0 +1,22 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GRAPHENGINE_LLT_ST_FRAMEWORK_H_ | |||
| #define GRAPHENGINE_LLT_ST_FRAMEWORK_H_ | |||
| #include <string> | |||
| #include "common/ge_inner_error_codes.h" | |||
| #endif // GRAPHENGINE_LLT_ST_FRAMEWORK_H_ | |||
| @@ -0,0 +1,33 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GRAPHENGINE_ST_TYPES_H | |||
| #define GRAPHENGINE_ST_TYPES_H | |||
| #include <map> | |||
| namespace ge { | |||
| namespace st { | |||
| const std::string kAicoreLibName = "AiCoreLib"; | |||
| const std::string kVectorLibName = "VectorLib"; | |||
| const std::string kAicpuLibName = "AicpuLib"; | |||
| const std::string kAicpuAscendLibName = "AicpuAscendLib"; | |||
| const std::string kHcclLibName = "HcclLib"; | |||
| const std::string kRTSLibName = "RTSLib"; | |||
| const std::map<std::string, std::string> kStubEngine2KernelLib = { | |||
| {"AIcoreEngine", "AiCoreLib"}, {"VectorEngine", "VectorLib"}, | |||
| {"DNN_VM_AICPU", "AicpuLib"}, {"DNN_VM_AICPU_ASCEND", "AicpuAscendLib"}, | |||
| {"DNN_HCCL", "HcclLib"}, {"DNN_VM_RTS", "RTSLib"}}; | |||
| } // namespace st | |||
| } // namespace ge | |||
| #endif // GRAPHENGINE_ST_TYPES_H | |||
| @@ -0,0 +1,70 @@ | |||
| /** | |||
| * 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 "stub_engine.h" | |||
| #include <map> | |||
| #include <memory> | |||
| #include <string> | |||
| #include <securec.h> | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "common/ge/ge_util.h" | |||
| #include "inc/st_types.h" | |||
| namespace ge { | |||
| namespace st { | |||
| StubEngine &StubEngine::Instance() { | |||
| static StubEngine instance; | |||
| return instance; | |||
| } | |||
| Status StubEngine::Initialize(const std::map<string, string> &options) { | |||
| for (const auto engine_2_lib : kStubEngine2KernelLib) { | |||
| auto ops_kernel_store = MakeShared<StubOpsKernelInfoStore>(engine_2_lib.second); | |||
| if (ops_kernel_store == nullptr) { | |||
| return FAILED; | |||
| } | |||
| ops_kernel_store_map_.insert(make_pair(engine_2_lib.second, ops_kernel_store)); | |||
| } | |||
| return SUCCESS; | |||
| } | |||
| void StubEngine::GetOpsKernelInfoStores(std::map<std::string, OpsKernelInfoStorePtr> &ops_kernel_map) { | |||
| for (const auto name_2_ops_kernel_store : ops_kernel_store_map_) { | |||
| ops_kernel_map[name_2_ops_kernel_store.first] = name_2_ops_kernel_store.second; | |||
| } | |||
| } | |||
| void StubEngine::GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr> &) { | |||
| // no optimizer for host cpu engine | |||
| } | |||
| Status StubEngine::Finalize() { return SUCCESS; } | |||
| } // namespace st | |||
| } // namespace ge | |||
| ge::Status Initialize(const std::map<string, string> &options) { | |||
| return ge::st::StubEngine::Instance().Initialize(options); | |||
| } | |||
| void GetOpsKernelInfoStores(std::map<std::string, OpsKernelInfoStorePtr> &ops_kernel_map) { | |||
| ge::st::StubEngine::Instance().GetOpsKernelInfoStores(ops_kernel_map); | |||
| } | |||
| void GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr> &graph_optimizers) { | |||
| ge::st::StubEngine::Instance().GetGraphOptimizerObjs(graph_optimizers); | |||
| } | |||
| ge::Status Finalize() { return ge::st::StubEngine::Instance().Finalize(); } | |||
| @@ -0,0 +1,127 @@ | |||
| /** | |||
| * Copyright 2020 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GRAPH_ENGINE_LLT_STUB_ENGINE_H_ | |||
| #define GRAPH_ENGINE_LLT_STUB_ENGINE_H_ | |||
| #if defined(_MSC_VER) | |||
| #ifdef FUNC_VISIBILITY | |||
| #define GE_FUNC_VISIBILITY _declspec(dllexport) | |||
| #else | |||
| #define GE_FUNC_VISIBILITY | |||
| #endif | |||
| #else | |||
| #ifdef FUNC_VISIBILITY | |||
| #define GE_FUNC_VISIBILITY __attribute__((visibility("default"))) | |||
| #else | |||
| #define GE_FUNC_VISIBILITY | |||
| #endif | |||
| #endif | |||
| #include <map> | |||
| #include <memory> | |||
| #include <string> | |||
| #include "inc/st_types.h" | |||
| #include "common/opskernel/ops_kernel_info_store.h" | |||
| #include "common/optimizer/graph_optimizer.h" | |||
| #include "stub_engine/ops_kernel_store/stub_ops_kernel_store.h" | |||
| using OpsKernelInfoStorePtr = std::shared_ptr<ge::OpsKernelInfoStore>; | |||
| using StubOpsKernelInfoStorePtr = std::shared_ptr<ge::st::StubOpsKernelInfoStore>; | |||
| using GraphOptimizerPtr = std::shared_ptr<ge::GraphOptimizer>; | |||
| namespace ge { | |||
| namespace st { | |||
| /** | |||
| * host cpu engine. | |||
| * Used for the ops which executes on host. | |||
| */ | |||
| class GE_FUNC_VISIBILITY StubEngine { | |||
| public: | |||
| /** | |||
| * get StubEngine instance. | |||
| * @return StubEngine instance. | |||
| */ | |||
| static StubEngine &Instance(); | |||
| virtual ~StubEngine() = default; | |||
| /** | |||
| * When Ge start, GE will invoke this interface | |||
| * @return The status whether initialize successfully | |||
| */ | |||
| Status Initialize(const std::map<string, string> &options); | |||
| /** | |||
| * After the initialize, GE will invoke this interface | |||
| * to get the Ops kernel Store. | |||
| * @param ops_kernel_map The host cpu's ops kernel info | |||
| */ | |||
| void GetOpsKernelInfoStores(std::map<std::string, OpsKernelInfoStorePtr> &ops_kernel_map); | |||
| /** | |||
| * After the initialize, GE will invoke this interface | |||
| * to get the Graph Optimizer. | |||
| * @param graph_optimizers The host cpu's Graph Optimizer objs | |||
| */ | |||
| void GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr> &graph_optimizers); | |||
| /** | |||
| * When the graph finished, GE will invoke this interface | |||
| * @return The status whether initialize successfully | |||
| */ | |||
| Status Finalize(); | |||
| StubEngine(const StubEngine &StubEngine) = delete; | |||
| StubEngine(const StubEngine &&StubEngine) = delete; | |||
| StubEngine &operator=(const StubEngine &StubEngine) = delete; | |||
| StubEngine &operator=(StubEngine &&StubEngine) = delete; | |||
| private: | |||
| StubEngine() = default; | |||
| map<string, OpsKernelInfoStorePtr> ops_kernel_store_map_; | |||
| }; | |||
| } // namespace st | |||
| } // namespace ge | |||
| extern "C" { | |||
| /** | |||
| * When Ge start, GE will invoke this interface | |||
| * @return The status whether initialize successfully | |||
| */ | |||
| GE_FUNC_VISIBILITY ge::Status Initialize(const map<string, string> &options); | |||
| /** | |||
| * After the initialize, GE will invoke this interface to get the Ops kernel Store | |||
| * @param ops_kernel_map The host cpu's ops kernel info | |||
| */ | |||
| GE_FUNC_VISIBILITY void GetOpsKernelInfoStores(std::map<std::string, OpsKernelInfoStorePtr> &ops_kernel_map); | |||
| /** | |||
| * After the initialize, GE will invoke this interface to get the Graph Optimizer | |||
| * @param graph_optimizers The host cpu's Graph Optimizer objs | |||
| */ | |||
| GE_FUNC_VISIBILITY void GetGraphOptimizerObjs(std::map<std::string, GraphOptimizerPtr> &graph_optimizers); | |||
| /** | |||
| * When the graph finished, GE will invoke this interface | |||
| * @return The status whether initialize successfully | |||
| */ | |||
| GE_FUNC_VISIBILITY ge::Status Finalize(); | |||
| } | |||
| #endif // GRAPH_ENGINE_LLT_STUB_ENGINE_H_ | |||
| @@ -0,0 +1,42 @@ | |||
| /** | |||
| * Copyright 2021 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 "inc/st_types.h" | |||
| #include "stub_engine/ops_kernel_store/op/host_op.h" | |||
| #include "framework/common/util.h" | |||
| #include "stub_engine/ops_kernel_store/op/stub_op_factory.h" | |||
| namespace ge { | |||
| namespace st { | |||
| Status HostOp::Run() { | |||
| // no need to generate device task | |||
| return SUCCESS; | |||
| } | |||
| REGISTER_OP_CREATOR(Enter, RTSLib, HostOp); | |||
| REGISTER_OP_CREATOR(Merge, RTSLib, HostOp); | |||
| REGISTER_OP_CREATOR(Switch, RTSLib, HostOp); | |||
| REGISTER_OP_CREATOR(Less, AiCoreLib, HostOp); | |||
| REGISTER_OP_CREATOR(NextIteration, AiCoreLib, HostOp); | |||
| REGISTER_OP_CREATOR(LoopCond, RTSLib, HostOp); | |||
| REGISTER_OP_CREATOR(Exit, RTSLib, HostOp); | |||
| REGISTER_OP_CREATOR(StreamMerge, RTSLib, HostOp); | |||
| REGISTER_OP_CREATOR(StreamSwitch, RTSLib, HostOp); | |||
| REGISTER_OP_CREATOR(StreamActive, RTSLib, HostOp); | |||
| REGISTER_OP_CREATOR(Cast, AiCoreLib, HostOp); | |||
| REGISTER_OP_CREATOR(Transdata, AiCoreLib, HostOp); | |||
| } // namespace st | |||
| } // namespace ge | |||
| @@ -0,0 +1,36 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_HOST_OP_H_ | |||
| #define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_HOST_OP_H_ | |||
| #include "stub_engine/ops_kernel_store/op/op.h" | |||
| namespace ge { | |||
| namespace st { | |||
| class GE_FUNC_VISIBILITY HostOp : public Op { | |||
| public: | |||
| HostOp(const Node &node, RunContext &run_context) : Op(node, run_context) {} | |||
| ~HostOp() override = default; | |||
| HostOp &operator=(const HostOp &op) = delete; | |||
| HostOp(const HostOp &op) = delete; | |||
| Status Run() override; | |||
| }; | |||
| } // namespace st | |||
| } // namespace ge | |||
| #endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_HOST_OP_H_ | |||
| @@ -0,0 +1,45 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_H_ | |||
| #define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_H_ | |||
| #include <climits> | |||
| #include <string> | |||
| #include <vector> | |||
| #include "common/ge_inner_error_codes.h" | |||
| #include "common/opskernel/ops_kernel_info_types.h" | |||
| #include "graph/node.h" | |||
| namespace ge { | |||
| namespace st { | |||
| /** | |||
| * The base class for all op. | |||
| */ | |||
| class GE_FUNC_VISIBILITY Op { | |||
| public: | |||
| Op(const Node &node, RunContext &run_context) : run_context_(run_context), node_(node) {} | |||
| virtual ~Op() = default; | |||
| virtual Status Run() = 0; | |||
| protected: | |||
| const RunContext &run_context_; | |||
| const Node &node_; | |||
| }; | |||
| } // namespace st | |||
| } // namespace ge | |||
| #endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_H_ | |||
| @@ -0,0 +1,51 @@ | |||
| /** | |||
| * Copyright 2021 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 "stub_op_factory.h" | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "common/ge_inner_error_codes.h" | |||
| #include "graph/op_desc.h" | |||
| namespace ge { | |||
| namespace st { | |||
| OpFactory &OpFactory::Instance() { | |||
| static OpFactory instance; | |||
| return instance; | |||
| } | |||
| std::shared_ptr<Op> OpFactory::CreateOp(const Node &node, RunContext &run_context) { | |||
| auto iter = op_creator_map_.find(node.GetType()); | |||
| if (iter != op_creator_map_.end()) { | |||
| return iter->second(node, run_context); | |||
| } | |||
| GELOGE(FAILED, "Not supported OP, type = %s, name = %s", node.GetType().c_str(), node.GetName().c_str()); | |||
| return nullptr; | |||
| } | |||
| void OpFactory::RegisterCreator(const std::string &type, const std::string &kernel_lib, const OP_CREATOR_FUNC &func) { | |||
| if (func == nullptr) { | |||
| GELOGW("Func is NULL."); | |||
| return; | |||
| } | |||
| if (all_store_ops_.find(kernel_lib) != all_store_ops_.end()) { | |||
| all_store_ops_[kernel_lib].emplace_back(type); | |||
| } else { | |||
| all_store_ops_[kernel_lib] = {type}; | |||
| } | |||
| } | |||
| } // namespace st | |||
| } // namespace ge | |||
| @@ -0,0 +1,105 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_FACTORY_H_ | |||
| #define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_FACTORY_H_ | |||
| #include <functional> | |||
| #include <map> | |||
| #include <memory> | |||
| #include <string> | |||
| #include <vector> | |||
| #include "common/ge/ge_util.h" | |||
| #include "stub_engine/ops_kernel_store/op/op.h" | |||
| #include "inc/st_types.h" | |||
| namespace ge { | |||
| namespace st { | |||
| using OP_CREATOR_FUNC = std::function<std::shared_ptr<Op>(const Node &, RunContext &)>; | |||
| /** | |||
| * manage all the op, support create op. | |||
| */ | |||
| class GE_FUNC_VISIBILITY OpFactory { | |||
| public: | |||
| static OpFactory &Instance(); | |||
| /** | |||
| * @brief create Op. | |||
| * @param [in] node share ptr of node | |||
| * @param [in] run_context run context | |||
| * @return not nullptr success | |||
| * @return nullptr fail | |||
| */ | |||
| std::shared_ptr<Op> CreateOp(const Node &node, RunContext &run_context); | |||
| /** | |||
| * @brief Register Op create function. | |||
| * @param [in] type Op type | |||
| * @param [in] func Op create func | |||
| */ | |||
| void RegisterCreator(const std::string &type, const std::string &lib_name, const OP_CREATOR_FUNC &func); | |||
| const std::vector<std::string> &GetAllOps() const { return all_ops_; } | |||
| const std::vector<std::string> &GetAllOps(std::string lib_name) const { | |||
| auto iter = all_store_ops_.find(lib_name); | |||
| if(iter == all_store_ops_.end()){ | |||
| return all_ops_; | |||
| } | |||
| return iter->second; | |||
| } | |||
| bool CheckSupported(const std::string &type) { return op_creator_map_.find(type) != op_creator_map_.end(); } | |||
| OpFactory(const OpFactory &) = delete; | |||
| OpFactory &operator=(const OpFactory &) = delete; | |||
| OpFactory(OpFactory &&) = delete; | |||
| OpFactory &operator=(OpFactory &&) = delete; | |||
| private: | |||
| OpFactory() = default; | |||
| ~OpFactory() = default; | |||
| // the op creator function map | |||
| std::map<std::string, OP_CREATOR_FUNC> op_creator_map_; | |||
| std::map<std::string, std::map<std::string, OP_CREATOR_FUNC>> lib_op_creator_map_; | |||
| std::vector<std::string> all_ops_; | |||
| std::map<std::string, vector<std::string>> all_store_ops_; | |||
| }; | |||
| class GE_FUNC_VISIBILITY OpRegistrar { | |||
| public: | |||
| OpRegistrar(const std::string &type, const std::string &kernel_lib, const OP_CREATOR_FUNC &func) { | |||
| OpFactory::Instance().RegisterCreator(type, kernel_lib, func); | |||
| } | |||
| ~OpRegistrar() = default; | |||
| OpRegistrar(const OpRegistrar &) = delete; | |||
| OpRegistrar &operator=(const OpRegistrar &) = delete; | |||
| OpRegistrar(OpRegistrar &&) = delete; | |||
| OpRegistrar &operator=(OpRegistrar &&) = delete; | |||
| }; | |||
| #define REGISTER_OP_CREATOR(type, lib_name, clazz) \ | |||
| std::shared_ptr<Op> Creator_##type##Op(const Node &node, RunContext &run_context) { \ | |||
| return MakeShared<clazz>(node, run_context); \ | |||
| } \ | |||
| OpRegistrar g_##type##Op_creator(#type, #lib_name, Creator_##type##Op) | |||
| } // namespace st | |||
| } // namespace ge | |||
| #endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_OP_OP_FACTORY_H_ | |||
| @@ -0,0 +1,115 @@ | |||
| /** | |||
| * Copyright 2021 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 "stub_ops_kernel_builder.h" | |||
| #include <memory> | |||
| #include "common/ge_inner_error_codes.h" | |||
| #include "ge/ge_api_types.h" | |||
| #include "graph/utils/node_utils.h" | |||
| #include "graph/utils/tensor_utils.h" | |||
| #include "graph/utils/type_utils.h" | |||
| #include <securec.h> | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "host_cpu_engine/common/constant/constant.h" | |||
| #include "register/ops_kernel_builder_registry.h" | |||
| #include "inc/st_types.h" | |||
| namespace ge { | |||
| namespace st { | |||
| REGISTER_OPS_KERNEL_BUILDER(kAicoreLibName, StubOpsKernelBuilder); | |||
| REGISTER_OPS_KERNEL_BUILDER(kVectorLibName, StubOpsKernelBuilder); | |||
| REGISTER_OPS_KERNEL_BUILDER(kAicpuLibName, StubOpsKernelBuilder); | |||
| REGISTER_OPS_KERNEL_BUILDER(kAicpuAscendLibName, StubOpsKernelBuilder); | |||
| REGISTER_OPS_KERNEL_BUILDER(kHcclLibName, StubOpsKernelBuilder); | |||
| REGISTER_OPS_KERNEL_BUILDER(kRTSLibName, StubOpsKernelBuilder); | |||
| Status StubOpsKernelBuilder::Finalize() { return SUCCESS; } | |||
| Status StubOpsKernelBuilder::Initialize(const map<std::string, std::string> &options) { return SUCCESS; } | |||
| Status StubOpsKernelBuilder::CalcOpRunningParam(Node &ge_node) { | |||
| OpDescPtr op_desc = ge_node.GetOpDesc(); | |||
| if (op_desc == nullptr) { | |||
| GELOGE(FAILED, "[Get][OpDesc]CalcOpRunningParam failed, as op desc is null"); | |||
| REPORT_INNER_ERROR("E19999", "GetOpDesc failed."); | |||
| return FAILED; | |||
| } | |||
| bool is_shape_unknown = false; | |||
| if (NodeUtils::GetNodeUnknownShapeStatus(ge_node, is_shape_unknown) == GRAPH_SUCCESS) { | |||
| if (is_shape_unknown) { | |||
| GELOGI("op:%s is unknown shape, does not need to calc output size.", ge_node.GetName().c_str()); | |||
| return SUCCESS; | |||
| } | |||
| } | |||
| const string name = ge_node.GetName(); | |||
| const string type = ge_node.GetType(); | |||
| GELOGD("Calc op[%s:%s] running param, output size=%zu.", name.c_str(), type.c_str(), op_desc->GetOutputsSize()); | |||
| for (size_t i = 0; i < op_desc->GetOutputsSize(); ++i) { | |||
| GeTensorDesc output_tensor = op_desc->GetOutputDesc(static_cast<uint32_t>(i)); | |||
| Format format = output_tensor.GetFormat(); | |||
| DataType data_type = output_tensor.GetDataType(); | |||
| int64_t mem_size = 0; | |||
| // If mem size has been set, no need reset. | |||
| if ((TensorUtils::GetSize(output_tensor, mem_size) == GRAPH_SUCCESS) && (mem_size > 0)) { | |||
| GELOGD("Op[%s:%s] out[%zu] mem size has been set, no need calc again, format=%s, data_type=%s, mem_size=%ld.", | |||
| name.c_str(), type.c_str(), i, TypeUtils::FormatToSerialString(format).c_str(), | |||
| TypeUtils::DataTypeToSerialString(data_type).c_str(), mem_size); | |||
| continue; | |||
| } | |||
| int64_t output_mem_size = 0; | |||
| GeShape output_shape = output_tensor.GetShape(); | |||
| if ((TensorUtils::CalcTensorMemSize(output_shape, format, data_type, output_mem_size) != GRAPH_SUCCESS) || | |||
| (output_mem_size < 0)) { | |||
| GELOGE(FAILED, | |||
| "[Calc][TensorMemSize] fail for op[%s:%s] out[%zu] mem size, mem_size=%ld, format=%s, data_type=%s.", | |||
| name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(), | |||
| TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| REPORT_CALL_ERROR( | |||
| "E19999", "CalcTensorMemSize failed for op[%s:%s] out[%zu] mem size, mem_size=%ld, format=%s, data_type=%s.", | |||
| name.c_str(), type.c_str(), i, output_mem_size, TypeUtils::FormatToSerialString(format).c_str(), | |||
| TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| return FAILED; | |||
| } | |||
| GELOGI("Calc op[%s:%s] out[%zu] mem size is %ld, format=%s, data_type=%s.", name.c_str(), type.c_str(), i, | |||
| output_mem_size, TypeUtils::FormatToSerialString(format).c_str(), | |||
| TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| TensorUtils::SetSize(output_tensor, output_mem_size); | |||
| if (op_desc->UpdateOutputDesc(static_cast<uint32_t>(i), output_tensor) != GRAPH_SUCCESS) { | |||
| GELOGE(FAILED, "[Update][OutputDesc] fail for op[%s:%s] out[%zu] desc , format=%s, data_type=%s.", name.c_str(), | |||
| type.c_str(), i, TypeUtils::FormatToSerialString(format).c_str(), | |||
| TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| REPORT_CALL_ERROR("E19999", "UpdateOutputDesc failed for op[%s:%s] out[%zu] desc , format=%s, data_type=%s.", | |||
| name.c_str(), type.c_str(), i, TypeUtils::FormatToSerialString(format).c_str(), | |||
| TypeUtils::DataTypeToSerialString(data_type).c_str()); | |||
| return FAILED; | |||
| } | |||
| } | |||
| GELOGD("Calc op[%s:%s] running param success.", name.c_str(), type.c_str()); | |||
| return SUCCESS; | |||
| } | |||
| Status StubOpsKernelBuilder::GenerateTask(const Node &node, RunContext &context, vector<domi::TaskDef> &tasks) { | |||
| // no need to generate device task | |||
| return SUCCESS; | |||
| } | |||
| } // namespace st | |||
| } // namespace ge | |||
| @@ -0,0 +1,51 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_BUILDER_H_ | |||
| #define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_BUILDER_H_ | |||
| #if defined(_MSC_VER) | |||
| #ifdef FUNC_VISIBILITY | |||
| #define GE_FUNC_VISIBILITY _declspec(dllexport) | |||
| #else | |||
| #define GE_FUNC_VISIBILITY | |||
| #endif | |||
| #else | |||
| #ifdef FUNC_VISIBILITY | |||
| #define GE_FUNC_VISIBILITY __attribute__((visibility("default"))) | |||
| #else | |||
| #define GE_FUNC_VISIBILITY | |||
| #endif | |||
| #endif | |||
| #include "common/opskernel/ops_kernel_builder.h" | |||
| namespace ge { | |||
| namespace st { | |||
| class GE_FUNC_VISIBILITY StubOpsKernelBuilder : public OpsKernelBuilder { | |||
| public: | |||
| Status Initialize(const map<std::string, std::string> &options) override; | |||
| Status Finalize() override; | |||
| Status CalcOpRunningParam(Node &node) override; | |||
| Status GenerateTask(const Node &node, RunContext &context, std::vector<domi::TaskDef> &tasks) override; | |||
| }; | |||
| } // namespace st | |||
| } // namespace ge | |||
| #endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_BUILDER_H_ | |||
| @@ -0,0 +1,75 @@ | |||
| /** | |||
| * Copyright 2021 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 "stub_ops_kernel_store.h" | |||
| #include <memory> | |||
| #include "ge/ge_api_types.h" | |||
| #include "framework/common/debug/ge_log.h" | |||
| #include "graph/utils/node_utils.h" | |||
| #include "graph/utils/tensor_utils.h" | |||
| #include "graph/utils/type_utils.h" | |||
| #include "op/stub_op_factory.h" | |||
| namespace ge { | |||
| namespace st { | |||
| using domi::TaskDef; | |||
| using std::map; | |||
| using std::string; | |||
| using std::vector; | |||
| Status StubOpsKernelInfoStore::Initialize(const map<string, string> &options) { | |||
| GELOGI("StubOpsKernelInfoStore init start."); | |||
| string engine_name; | |||
| for (const auto &engine_2_lib : kStubEngine2KernelLib) { | |||
| if (engine_2_lib.second == store_name_) { | |||
| engine_name = engine_2_lib.first; | |||
| } | |||
| } | |||
| if (engine_name.empty()) { | |||
| return FAILED; | |||
| } | |||
| OpInfo default_op_info = {.engine = engine_name, | |||
| .opKernelLib = store_name_, | |||
| .computeCost = 0, | |||
| .flagPartial = false, | |||
| .flagAsync = false, | |||
| .isAtomic = false}; | |||
| // Init op_info_map_ | |||
| auto all_ops_in_store = OpFactory::Instance().GetAllOps(store_name_); | |||
| for (auto &op : all_ops_in_store) { | |||
| op_info_map_[op] = default_op_info; | |||
| } | |||
| GELOGI("StubOpsKernelInfoStore inited success. op num=%zu", op_info_map_.size()); | |||
| return SUCCESS; | |||
| } | |||
| Status StubOpsKernelInfoStore::Finalize() { | |||
| op_info_map_.clear(); | |||
| return SUCCESS; | |||
| } | |||
| void StubOpsKernelInfoStore::GetAllOpsKernelInfo(map<string, OpInfo> &infos) const { infos = op_info_map_; } | |||
| bool StubOpsKernelInfoStore::CheckSupported(const OpDescPtr &op_desc, std::string &) const { | |||
| if (op_desc == nullptr) { | |||
| return false; | |||
| } | |||
| return op_info_map_.count(op_desc->GetType()) > 0; | |||
| } | |||
| } // namespace st | |||
| } // namespace ge | |||
| @@ -0,0 +1,71 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_INFO_H_ | |||
| #define GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_INFO_H_ | |||
| #if defined(_MSC_VER) | |||
| #ifdef FUNC_VISIBILITY | |||
| #define GE_FUNC_VISIBILITY _declspec(dllexport) | |||
| #else | |||
| #define GE_FUNC_VISIBILITY | |||
| #endif | |||
| #else | |||
| #ifdef FUNC_VISIBILITY | |||
| #define GE_FUNC_VISIBILITY __attribute__((visibility("default"))) | |||
| #else | |||
| #define GE_FUNC_VISIBILITY | |||
| #endif | |||
| #endif | |||
| #include <map> | |||
| #include <string> | |||
| #include <vector> | |||
| #include "common/opskernel/ops_kernel_info_store.h" | |||
| namespace ge { | |||
| namespace st { | |||
| /*const vector<std::string> kStubOpKernelLibNameVec = { | |||
| "AiCoreLib", | |||
| "AicpuLib", | |||
| "HcclLib", | |||
| "RTSLib" | |||
| };*/ | |||
| class GE_FUNC_VISIBILITY StubOpsKernelInfoStore : public OpsKernelInfoStore { | |||
| public: | |||
| StubOpsKernelInfoStore(std::string store_name) : store_name_(store_name) {} | |||
| ~StubOpsKernelInfoStore() override = default; | |||
| Status Initialize(const std::map<std::string, std::string> &options) override; | |||
| Status Finalize() override; | |||
| bool CheckSupported(const OpDescPtr &op_desc, std::string &reason) const override; | |||
| void GetAllOpsKernelInfo(std::map<std::string, ge::OpInfo> &infos) const override; | |||
| std::string GetOpsKernelStoreName() const { return store_name_; } | |||
| StubOpsKernelInfoStore(const StubOpsKernelInfoStore &ops_kernel_store) = delete; | |||
| StubOpsKernelInfoStore(const StubOpsKernelInfoStore &&ops_kernel_store) = delete; | |||
| StubOpsKernelInfoStore &operator=(const StubOpsKernelInfoStore &ops_kernel_store) = delete; | |||
| StubOpsKernelInfoStore &operator=(StubOpsKernelInfoStore &&ops_kernel_store) = delete; | |||
| private: | |||
| // store op name and OpInfo key-value pair | |||
| std::map<std::string, ge::OpInfo> op_info_map_; | |||
| std::string store_name_; | |||
| }; | |||
| } // namespace st | |||
| } // namespace ge | |||
| #endif // GE_HOST_CPU_ENGINE_OPS_KERNEL_STORE_HOST_CPU_OPS_KERNEL_INFO_H_ | |||
| @@ -0,0 +1,17 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "graph_assertion.h" | |||
| @@ -0,0 +1,34 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GRAPHENGINE_LLT_ST_GRAPH_ASSERTION_H | |||
| #define GRAPHENGINE_LLT_ST_GRAPH_ASSERTION_H | |||
| /* | |||
| * Compare graph node size, node_attr | |||
| */ | |||
| #define ASSERT_GRAPH_EQUAL(g1,g2) \ | |||
| do { \ | |||
| } while (0) | |||
| #define ASSERT_GRAPH_CORRECT(g) \ | |||
| do { \ | |||
| } while (0) | |||
| #define ASSERT_GRAPH_SHAPE_CONTINOUS(g) \ | |||
| do { \ | |||
| } while (0) | |||
| #endif // GRAPHENGINE_LLT_ST_GRAPH_ASSERTION_H | |||
| @@ -0,0 +1,48 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #include "graph_builder_utils.h" | |||
| #include "inc/external/graph/operator.h" | |||
| #include "inc/external/graph/operator_factory.h" | |||
| #include "graph/utils/graph_utils.h" | |||
| namespace ge { | |||
| namespace st { | |||
| NodePtr ComputeGraphBuilder::AddNode(const std::string &name, const std::string &type, int in_cnt, int out_cnt, | |||
| Format format, DataType data_type, std::vector<int64_t> shape) { | |||
| auto tensor_desc = std::make_shared<GeTensorDesc>(); | |||
| tensor_desc->SetShape(GeShape(std::move(shape))); | |||
| tensor_desc->SetFormat(format); | |||
| tensor_desc->SetDataType(data_type); | |||
| auto op_desc = std::make_shared<OpDesc>(name, type); | |||
| for (int i = 0; i < in_cnt; ++i) { | |||
| op_desc->AddInputDesc(tensor_desc->Clone()); | |||
| } | |||
| for (int i = 0; i < out_cnt; ++i) { | |||
| op_desc->AddOutputDesc(tensor_desc->Clone()); | |||
| } | |||
| return graph_->AddNode(op_desc); | |||
| } | |||
| void ComputeGraphBuilder::AddDataEdge(NodePtr &src_node, int src_idx, NodePtr &dst_node, int dst_idx) { | |||
| GraphUtils::AddEdge(src_node->GetOutDataAnchor(src_idx), dst_node->GetInDataAnchor(dst_idx)); | |||
| } | |||
| void ComputeGraphBuilder::AddControlEdge(NodePtr &src_node, NodePtr &dst_node) { | |||
| GraphUtils::AddEdge(src_node->GetOutControlAnchor(), dst_node->GetInControlAnchor()); | |||
| } | |||
| } // namespace st | |||
| } // namespace ge | |||
| @@ -0,0 +1,53 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GRAPHENGINE_LLT_ST_GRAPH_BUILDER_H | |||
| #define GRAPHENGINE_LLT_ST_GRAPH_BUILDER_H | |||
| #include <string> | |||
| #include <vector> | |||
| #include "graph/compute_graph.h" | |||
| #include "graph/utils/graph_utils.h" | |||
| #include "graph/graph.h" | |||
| #include "graph/node.h" | |||
| namespace ge { | |||
| namespace st { | |||
| class ComputeGraphBuilder { | |||
| public: | |||
| explicit ComputeGraphBuilder(const std::string &name) { graph_ = std::make_shared<ComputeGraph>(name); } | |||
| NodePtr AddNode(const std::string &name, const std::string &type, int in_cnt, int out_cnt, | |||
| Format format = FORMAT_NCHW, DataType data_type = DT_FLOAT, | |||
| std::vector<int64_t> shape = {1, 1, 224, 224}); | |||
| void AddDataEdge(NodePtr &src_node, int src_idx, NodePtr &dst_node, int dst_idx); | |||
| void AddControlEdge(NodePtr &src_node, NodePtr &dst_node); | |||
| ComputeGraphPtr GetComputeGraph() { | |||
| graph_->TopologicalSorting(); | |||
| return graph_; | |||
| } | |||
| Graph GetGraph() { | |||
| graph_->TopologicalSorting(); | |||
| return GraphUtils::CreateGraphFromComputeGraph(graph_); | |||
| } | |||
| private: | |||
| ComputeGraphPtr graph_; | |||
| }; | |||
| } // namespace st | |||
| } // namespace ge | |||
| #endif // GRAPHENGINE_LLT_ST_GRAPH_BUILDER_H | |||
| @@ -0,0 +1,17 @@ | |||
| /** | |||
| * Copyright 2021 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 "tensor_builder_utils.h" | |||
| @@ -0,0 +1,22 @@ | |||
| /** | |||
| * Copyright 2021 Huawei Technologies Co., Ltd | |||
| * | |||
| * Licensed under the Apache License, Version 2.0 (the "License"); | |||
| * you may not use this file except in compliance with the License. | |||
| * You may obtain a copy of the License at | |||
| * | |||
| * http://www.apache.org/licenses/LICENSE-2.0 | |||
| * | |||
| * Unless required by applicable law or agreed to in writing, software | |||
| * distributed under the License is distributed on an "AS IS" BASIS, | |||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| * See the License for the specific language governing permissions and | |||
| * limitations under the License. | |||
| */ | |||
| #ifndef GRAPHENGINE_LLT_ST_TENSOR_BUILDER_UTILS_H | |||
| #define GRAPHENGINE_LLT_ST_TENSOR_BUILDER_UTILS_H | |||
| class tensor_builder_utils {}; | |||
| #endif // GRAPHENGINE_LLT_ST_TENSOR_BUILDER_UTILS_H | |||
| @@ -0,0 +1,15 @@ | |||
| file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cc" "*.CC" "*.cpp" "*.CPP" "*.c++") | |||
| add_executable(graph_engine_test ${SOURCES}) | |||
| target_include_directories(graph_engine_test | |||
| PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} | |||
| ) | |||
| set_target_properties(graph_engine_test PROPERTIES CXX_STANDARD 11) | |||
| target_link_libraries(graph_engine_test PRIVATE gtest gtest_main framework) | |||
| include(CTest) | |||
| enable_testing() | |||
| add_test(NAME test COMMAND graph_engine_test) | |||
| @@ -0,0 +1,192 @@ | |||
| /** | |||
| * Copyright 2021 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 <gtest/gtest.h> | |||
| #include <map> | |||
| #include "external/ge/ge_api.h" | |||
| #include "graph/debug/ge_attr_define.h" | |||
| #include "framework/common/types.h" | |||
| #include "framework.h" | |||
| #include "framework/utils/builder/graph_builder_utils.h" | |||
| #include "graph/operator_reg.h" | |||
| #include "graph/operator.h" | |||
| #define protected public | |||
| #define private public | |||
| #include "graph/utils/op_desc_utils.h" | |||
| #undef protected | |||
| #undef private | |||
| using namespace std; | |||
| using namespace ge; | |||
| namespace { | |||
| /** data a = 2; | |||
| * for(int i =0; i<5; ++i){ | |||
| * a=a * 2; | |||
| * } | |||
| * return a; | |||
| * ----------------------------------------------| | |||
| * | const(5) exit const(1) | | |||
| * | \ / \ | | |||
| * data(i)--Enter--merge--less--loopcond--switch-----add-----nextiteration | |||
| * \________________\___/ | |||
| * ------\------------------------| | |||
| * | \ const(2) | | |||
| * | \ \ | | |||
| * data(a)--Enter--merge--switch------mul-----nextiteration | |||
| * \ | |||
| * exit | |||
| * \ | |||
| * netoutput | |||
| * | |||
| **/ | |||
| Graph BuildV1ControlFlowGraph(){ | |||
| // build graph | |||
| st::ComputeGraphBuilder graphBuilder("g1"); | |||
| auto data_i = graphBuilder.AddNode("data_i",DATA,1,1); | |||
| auto enter_i = graphBuilder.AddNode("enter_i",ENTER,1,1); | |||
| ge::AttrUtils::SetStr(enter_i->GetOpDesc(), ENTER_ATTR_FRAME_NAME, "1"); | |||
| auto merge_i = graphBuilder.AddNode("merge_i",MERGE,2,1); | |||
| auto const_5 = graphBuilder.AddNode("const_5",CONSTANT,0,1); | |||
| auto less = graphBuilder.AddNode("less",LESS,2,1); | |||
| auto loopcond = graphBuilder.AddNode("loopcond",LOOPCOND,1,1,FORMAT_NCHW,DT_BOOL); | |||
| auto switch_i = graphBuilder.AddNode("switch_i",SWITCH,2,2); | |||
| auto exit_i = graphBuilder.AddNode("switch_i",EXIT,1,1); | |||
| auto const_1 = graphBuilder.AddNode("const_1",CONSTANT,0,1); | |||
| auto add = graphBuilder.AddNode("add",ADD,2,1); | |||
| auto next_iteration_i = graphBuilder.AddNode("next_iteration_i",NEXTITERATION,1,1); | |||
| auto data_a = graphBuilder.AddNode("data_a",DATA,1,1); | |||
| auto enter_a = graphBuilder.AddNode("enter_a",ENTER,1,1); | |||
| ge::AttrUtils::SetStr(enter_a->GetOpDesc(), ENTER_ATTR_FRAME_NAME, "1"); | |||
| auto merge_a = graphBuilder.AddNode("merge_a",MERGE,2,1); | |||
| auto switch_a = graphBuilder.AddNode("switch_a",SWITCH,2,2); | |||
| auto exit_a = graphBuilder.AddNode("exit_a",EXIT,1,1); | |||
| auto mul = graphBuilder.AddNode("mul",MUL,2,1); | |||
| auto const_2 = graphBuilder.AddNode("const_2",CONSTANT,0,1); | |||
| auto next_iteration_a = graphBuilder.AddNode("next_iteration_a",NEXTITERATION,1,1); | |||
| auto netoutput = graphBuilder.AddNode("netoutput",NETOUTPUT,2,2); | |||
| // i = i+1 | |||
| graphBuilder.AddDataEdge(data_i, 0, enter_i,0); | |||
| graphBuilder.AddDataEdge(enter_i, 0, merge_i,0); | |||
| graphBuilder.AddDataEdge(next_iteration_i, 0, merge_i,1); | |||
| graphBuilder.AddDataEdge(merge_i, 0, less,0); | |||
| graphBuilder.AddDataEdge(const_5, 0, less,1); | |||
| graphBuilder.AddDataEdge(less, 0, loopcond,0); | |||
| graphBuilder.AddDataEdge(loopcond, 0, switch_i,1); | |||
| graphBuilder.AddDataEdge(merge_i, 0, switch_i,0); | |||
| graphBuilder.AddDataEdge(switch_i, 0, exit_i,0); | |||
| graphBuilder.AddDataEdge(switch_i, 1, add,0); | |||
| graphBuilder.AddDataEdge(const_1, 0, add,1); | |||
| graphBuilder.AddDataEdge(add, 0, next_iteration_i,0); | |||
| graphBuilder.AddDataEdge(exit_i, 0, netoutput,1); | |||
| // a=a*2 | |||
| graphBuilder.AddDataEdge(data_a, 0, enter_a,0); | |||
| graphBuilder.AddDataEdge(enter_a, 0, merge_a,0); | |||
| graphBuilder.AddDataEdge(next_iteration_a, 0, merge_a,1); | |||
| graphBuilder.AddDataEdge(loopcond, 0, switch_a,1); | |||
| graphBuilder.AddDataEdge(merge_a, 0, switch_a,0); | |||
| graphBuilder.AddDataEdge(switch_a, 0, exit_a,0); | |||
| graphBuilder.AddDataEdge(switch_a, 1, mul,0); | |||
| graphBuilder.AddDataEdge(const_2, 0, mul,1); | |||
| graphBuilder.AddDataEdge(mul, 0, next_iteration_a,0); | |||
| graphBuilder.AddDataEdge(exit_a, 0, netoutput,0); | |||
| // set const weight | |||
| int64_t dims_size = 1; | |||
| vector<int64_t> data_vec = {5}; | |||
| for_each(data_vec.begin(), data_vec.end(), [&](int64_t &data) { dims_size *= data; }); | |||
| vector<int32_t> data_value_vec(dims_size, 1); | |||
| GeTensorDesc data_tensor_desc(GeShape(data_vec), FORMAT_NCHW, DT_INT32); | |||
| GeTensorPtr data_tensor = make_shared<GeTensor>(data_tensor_desc, (uint8_t *)data_value_vec.data(), | |||
| data_value_vec.size() * sizeof(int32_t)); | |||
| OpDescUtils::SetWeights(const_5->GetOpDesc(), data_tensor); | |||
| OpDescUtils::SetWeights(const_2->GetOpDesc(), data_tensor); | |||
| OpDescUtils::SetWeights(const_1->GetOpDesc(), data_tensor); | |||
| return graphBuilder.GetGraph(); | |||
| } | |||
| } | |||
| class FrameworkTest : public testing::Test { | |||
| protected: | |||
| void SetUp() { | |||
| // ge initialize | |||
| map<AscendString, AscendString> options; | |||
| auto ret = ge::GEInitialize(options); | |||
| EXPECT_EQ(ret, SUCCESS); | |||
| } | |||
| void TearDown() { | |||
| } | |||
| }; | |||
| /// data data | |||
| /// \ / | |||
| /// add | |||
| TEST_F(FrameworkTest, test_framework_add) { | |||
| // build graph | |||
| st::ComputeGraphBuilder graphBuilder("g1"); | |||
| auto data1 = graphBuilder.AddNode("data1",DATA,1,1); | |||
| auto data2 = graphBuilder.AddNode("data2",DATA,1,1); | |||
| auto add = graphBuilder.AddNode("add",ADD,2,1); | |||
| graphBuilder.AddDataEdge(data1, 0, add,0); | |||
| graphBuilder.AddDataEdge(data2, 0, add,1); | |||
| Graph graph = graphBuilder.GetGraph(); | |||
| // new session & add graph | |||
| map<AscendString, AscendString> options; | |||
| Session session(options); | |||
| auto ret = session.AddGraph(1, graph, options); | |||
| EXPECT_EQ(ret, SUCCESS); | |||
| // build input tensor | |||
| std::vector<InputTensorInfo> inputs; | |||
| // build_graph through session | |||
| ret = session.BuildGraph(1, inputs); | |||
| EXPECT_EQ(ret, SUCCESS); | |||
| } | |||
| /** data a = 2; | |||
| * for(int i =0; i<5; ++i){ | |||
| * a=a * 2; | |||
| * } | |||
| * return a; | |||
| * ----------------------------------------------| | |||
| * | const(5) exit const(1) | | |||
| * | \ / \ | | |||
| * data(i)--Enter--merge--less--loopcond--switch-----add-----nextiteration | |||
| * \________________\___/ | |||
| * ------\------------------------| | |||
| * | \ const(2) | | |||
| * | \ \ | | |||
| * data(a)--Enter--merge--switch------mul-----nextiteration | |||
| * \ | |||
| * exit | |||
| * \ | |||
| * netoutput | |||
| * | |||
| **/ | |||
| TEST_F(FrameworkTest, test_framework_v1_control_flow) { | |||
| // build graph | |||
| Graph graph = BuildV1ControlFlowGraph(); | |||
| // new session & add graph | |||
| map<AscendString, AscendString> options; | |||
| Session session(options); | |||
| auto ret = session.AddGraph(2, graph, options); | |||
| EXPECT_EQ(ret, SUCCESS); | |||
| // build input tensor | |||
| std::vector<InputTensorInfo> inputs; | |||
| // build_graph through session | |||
| ret = session.BuildGraph(2, inputs); | |||
| EXPECT_EQ(ret, SUCCESS); | |||
| // check result | |||
| } | |||