OpenCVFindCANN.cmake 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ocv_check_environment_variables(CANN_INSTALL_DIR)
  2. if("cann${CANN_INSTALL_DIR}" STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME})
  3. set(CANN_INSTALL_DIR $ENV{ASCEND_TOOLKIT_HOME})
  4. message(STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME=$ENV{ASCEND_TOOLKIT_HOME}")
  5. endif()
  6. if(CANN_INSTALL_DIR)
  7. # Supported platforms: x86-64, arm64
  8. if(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
  9. elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
  10. else()
  11. set(HAVE_CANN OFF)
  12. message(STATUS "CANN: CANN toolkit supports x86-64 and arm64 but not ${CMAKE_SYSTEM_PROCESSOR}. Turning off HAVE_CANN")
  13. return()
  14. endif()
  15. # Supported OS: linux (because of we need fork() to build models in child process)
  16. # done via checks in cann.cpp
  17. # FIXME: remove the check if a better model building solution is found
  18. # include
  19. set(incs_cann "${CANN_INSTALL_DIR}/include")
  20. list(APPEND incs_cann "${CANN_INSTALL_DIR}/opp")
  21. # libs
  22. # * libascendcl.so
  23. set(lib_ascendcl "${CANN_INSTALL_DIR}/acllib/lib64")
  24. find_library(found_lib_ascendcl NAMES ascendcl PATHS ${lib_ascendcl} NO_DEFAULT_PATH)
  25. if(found_lib_ascendcl)
  26. set(lib_ascendcl ${found_lib_ascendcl})
  27. message(STATUS "CANN: libascendcl.so is found at ${lib_ascendcl}")
  28. else()
  29. message(STATUS "CANN: Missing libascendcl.so. Turning off HAVE_CANN")
  30. set(HAVE_CANN OFF)
  31. return()
  32. endif()
  33. # * libgraph.so
  34. set(lib_graph "${CANN_INSTALL_DIR}/compiler/lib64")
  35. find_library(found_lib_graph NAMES graph PATHS ${lib_graph} NO_DEFAULT_PATH)
  36. if(found_lib_graph)
  37. set(lib_graph ${found_lib_graph})
  38. message(STATUS "CANN: libgraph.so is found at ${lib_graph}")
  39. else()
  40. message(STATUS "CANN: Missing libgraph.so. Turning off HAVE_CANN")
  41. set(HAVE_CANN OFF)
  42. return()
  43. endif()
  44. # * libge_compiler.so
  45. set(lib_ge_compiler "${CANN_INSTALL_DIR}/compiler/lib64")
  46. find_library(found_lib_ge_compiler NAMES ge_compiler PATHS ${lib_ge_compiler} NO_DEFAULT_PATH)
  47. if(found_lib_ge_compiler)
  48. set(lib_ge_compiler ${found_lib_ge_compiler})
  49. message(STATUS "CANN: libge_compiler.so is found at ${lib_ge_compiler}")
  50. else()
  51. message(STATUS "CANN: Missing libge_compiler.so. Turning off HAVE_CANN")
  52. set(HAVE_CANN OFF)
  53. return()
  54. endif()
  55. # * libopsproto.so
  56. set(lib_opsproto "${CANN_INSTALL_DIR}/opp/op_proto/built-in")
  57. find_library(found_lib_opsproto NAMES opsproto PATHS ${lib_opsproto} NO_DEFAULT_PATH)
  58. if(found_lib_opsproto)
  59. set(lib_opsproto ${found_lib_opsproto})
  60. message(STATUS "CANN: libopsproto.so is found at ${lib_opsproto}")
  61. else()
  62. message(STATUS "CANN: Missing libopsproto.so. Turning off HAVE_CANN")
  63. set(HAVE_CANN OFF)
  64. return()
  65. endif()
  66. set(libs_cann "")
  67. list(APPEND libs_cann ${lib_ascendcl})
  68. list(APPEND libs_cann ${lib_opsproto})
  69. list(APPEND libs_cann ${lib_graph})
  70. list(APPEND libs_cann ${lib_ge_compiler})
  71. try_compile(VALID_ASCENDCL
  72. "${OpenCV_BINARY_DIR}"
  73. "${OpenCV_SOURCE_DIR}/cmake/checks/cann.cpp"
  74. CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${incs_cann}"
  75. "-DLINK_LIBRARIES:STRING=${libs_cann}"
  76. OUTPUT_VARIABLE ASCEND_TRY_OUT)
  77. if(NOT ${VALID_ASCENDCL})
  78. message(WARNING "Cannot use CANN")
  79. set(HAVE_CANN OFF)
  80. return()
  81. endif()
  82. set(HAVE_CANN ON)
  83. endif()
  84. if(HAVE_CANN)
  85. set(CANN_INCLUDE_DIRS ${incs_cann})
  86. set(CANN_LIBRARIES ${libs_cann})
  87. ocv_add_external_target(cann "${CANN_INCLUDE_DIRS}" "${CANN_LIBRARIES}" "HAVE_CANN")
  88. ocv_warnings_disable(CMAKE_C_FLAGS -Wignored-qualifiers)
  89. ocv_warnings_disable(CMAKE_CXX_FLAGS -Wignored-qualifiers)
  90. endif()
  91. MARK_AS_ADVANCED(
  92. incs_cann
  93. libs_cann
  94. lib_ascendcl
  95. lib_graph
  96. lib_ge_compiler
  97. )