diff --git a/cmake/OpenCVFindCANN.cmake b/cmake/OpenCVFindCANN.cmake index b0b8e35c6b..e1cd054a37 100644 --- a/cmake/OpenCVFindCANN.cmake +++ b/cmake/OpenCVFindCANN.cmake @@ -5,13 +5,24 @@ if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}") endif() +if(EXISTS "${CANN_INSTALL_DIR}/opp/op_proto/built-in/inc") + set(CANN_VERSION_BELOW_6_3_ALPHA002 "YES" ) + add_definitions(-DCANN_VERSION_BELOW_6_3_ALPHA002="YES") +endif() + if(CANN_INSTALL_DIR) + # Supported system: UNIX + if(NOT UNIX) + set(HAVE_CANN OFF) + message(WARNING "CANN: CANN toolkit supports unix but not ${CMAKE_SYSTEM_NAME}. Turning off HAVE_CANN") + return() + endif() # Supported platforms: x86-64, arm64 if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64") else() set(HAVE_CANN OFF) - message(STATUS "CANN: CANN toolkit supports x86-64 and arm64 but not ${CMAKE_SYSTEM_PROCESSOR}. Turning off HAVE_CANN") + message(WARNING "CANN: CANN toolkit supports x86-64 and arm64 but not ${CMAKE_SYSTEM_PROCESSOR}. Turning off HAVE_CANN") return() endif() @@ -31,7 +42,7 @@ if(CANN_INSTALL_DIR) set(lib_ascendcl ${found_lib_ascendcl}) message(STATUS "CANN: libascendcl.so is found at ${lib_ascendcl}") else() - message(STATUS "CANN: Missing libascendcl.so. Turning off HAVE_CANN") + message(WARNING "CANN: Missing libascendcl.so. Turning off HAVE_CANN") set(HAVE_CANN OFF) return() endif() @@ -42,7 +53,7 @@ if(CANN_INSTALL_DIR) set(lib_graph ${found_lib_graph}) message(STATUS "CANN: libgraph.so is found at ${lib_graph}") else() - message(STATUS "CANN: Missing libgraph.so. Turning off HAVE_CANN") + message(WARNING "CANN: Missing libgraph.so. Turning off HAVE_CANN") set(HAVE_CANN OFF) return() endif() @@ -53,29 +64,49 @@ if(CANN_INSTALL_DIR) set(lib_ge_compiler ${found_lib_ge_compiler}) message(STATUS "CANN: libge_compiler.so is found at ${lib_ge_compiler}") else() - message(STATUS "CANN: Missing libge_compiler.so. Turning off HAVE_CANN") + message(WARNING "CANN: Missing libge_compiler.so. Turning off HAVE_CANN") set(HAVE_CANN OFF) return() endif() # * libopsproto.so - set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in") + if (CANN_VERSION_BELOW_6_3_ALPHA002) + set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in/") + else() + if(EXISTS "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux") + set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto/lib/linux/${CMAKE_HOST_SYSTEM_PROCESSOR}") + else() + set(lib_opsproto "${CANN_INSTALL_DIR}/opp/built-in/op_proto") + endif() + endif() find_library(found_lib_opsproto NAMES opsproto PATHS ${lib_opsproto} NO_DEFAULT_PATH) if(found_lib_opsproto) set(lib_opsproto ${found_lib_opsproto}) message(STATUS "CANN: libopsproto.so is found at ${lib_opsproto}") else() - message(STATUS "CANN: Missing libopsproto.so. Turning off HAVE_CANN") + message(WARNING "CANN: Missing libopsproto.so can't found at ${lib_opsproto}. Turning off HAVE_CANN") set(HAVE_CANN OFF) return() endif() - set(libs_cann "") list(APPEND libs_cann ${lib_ascendcl}) list(APPEND libs_cann ${lib_opsproto}) list(APPEND libs_cann ${lib_graph}) list(APPEND libs_cann ${lib_ge_compiler}) + # * lib_graph_base.so + if(NOT CANN_VERSION_BELOW_6_3_ALPHA002) + set(lib_graph_base "${CANN_INSTALL_DIR}/compiler/lib64") + find_library(found_libgraph_base NAMES graph_base PATHS ${lib_graph_base} NO_DEFAULT_PATH) + if(found_libgraph_base) + set(lib_graph_base ${found_libgraph_base}) + message(STATUS "CANN: lib_graph_base.so is found at ${lib_graph_base}") + list(APPEND libs_cann ${lib_graph_base}) + else() + message(STATUS "CANN: Missing lib_graph_base.so. It is only required after cann version 6.3.RC1.alpha002") + endif() + endif() + try_compile(VALID_ASCENDCL "${OpenCV_BINARY_DIR}" "${OpenCV_SOURCE_DIR}/cmake/checks/cann.cpp" diff --git a/modules/dnn/src/net_cann.cpp b/modules/dnn/src/net_cann.cpp index a3eb52200f..103c7c8dd2 100644 --- a/modules/dnn/src/net_cann.cpp +++ b/modules/dnn/src/net_cann.cpp @@ -304,9 +304,9 @@ std::shared_ptr compileCannGraph(std::shared_ptr bool ok; if ((child=fork()) == 0) { - // initialize engine + // initialize engine Ascend310/Ascend310P3/Ascend910B/Ascend310B std::map options = { - {ge::AscendString(ge::ir_option::SOC_VERSION), ge::AscendString("Ascend310")}, + {ge::AscendString(ge::ir_option::SOC_VERSION), ge::AscendString(aclrtGetSocName())}, }; ACL_CHECK_GRAPH_RET(ge::aclgrphBuildInitialize(options)); diff --git a/modules/dnn/src/op_cann.hpp b/modules/dnn/src/op_cann.hpp index c60c311b7f..1d15eab6a3 100644 --- a/modules/dnn/src/op_cann.hpp +++ b/modules/dnn/src/op_cann.hpp @@ -10,7 +10,11 @@ #include "graph/graph.h" // ge::Graph; ge::Operator from operator.h #include "graph/ge_error_codes.h" // GRAPH_SUCCESS, ... -#include "op_proto/built-in/inc/all_ops.h" // ge::Conv2D, ... +#ifdef CANN_VERSION_BELOW_6_3_ALPHA002 + #include "op_proto/built-in/inc/all_ops.h" // ge::Conv2D, ... +#else + #include "built-in/op_proto/inc/all_ops.h" // ge::Conv2D, ... +#endif #include "graph/tensor.h" // ge::Shape, ge::Tensor, ge::TensorDesc #include "graph/types.h" // DT_FLOAT, ... ; FORMAT_NCHW, ...