char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
224145325
char/aliceai-t5-moe
1if ( "cann ${ CANN_INSTALL_DIR } " STREQUAL "cann" AND DEFINED ENV{ASCEND_TOOLKIT_HOME}) 2set ( CANN_INSTALL_DIR $ ENV { ASCEND_TOOLKIT_HOME }) 3message ( STATUS "CANN: updated CANN_INSTALL_DIR from ASCEND_TOOLKIT_HOME= $ ENV { ASCEND_TOOLKIT_HOME } " ) 4endif () 5 6# Auto-detech Soc type and Soc version, if detect failed, will abort build 7set ( SOC_VERSION "" ) 8function ( detect_ascend_soc_type SOC_VERSION ) 9execute_process ( 10COMMAND bash -c "npu-smi info|awk -F' ' 'NF > 0 && NR==7 {print $ 3}'" 11OUTPUT_VARIABLE npu_info 12RESULT_VARIABLE npu_result 13OUTPUT_STRIP_TRAILING_WHITESPACE 14) 15if ( " ${ npu_info } " STREQUAL "" OR ${ npu_result }) 16message ( FATAL_ERROR "Auto-detech ascend soc type failed, please specify manually or check ascend device working normally." ) 17endif () 18set ( $ { SOC_VERSION } "Ascend ${ npu_info } " PARENT_SCOPE ) 19endfunction () 20 21if ( NOT SOC_TYPE) 22detect_ascend_soc_type ( SOC_VERSION ) 23set ( SOC_TYPE " ${ SOC_VERSION } " ) 24message ( STATUS "CANN: SOC_VERSION auto-detected is: ${ SOC_VERSION } " ) 25endif () 26 27string ( TOLOWER ${ SOC_TYPE } SOC_VERSION ) # SOC_VERSION need lower 28 29# Construct Soc specify compile option: ASCEND_#Soc_Major_SN. Such as ASCEND_910B, ASCEND_310P. 30string ( REGEX MATCH "[0-9]+[a-zA-Z]" SOC_TYPE_MAJOR_SN " ${ SOC_VERSION } " ) 31set ( SOC_TYPE_COMPILE_OPTION "ASCEND_ ${ SOC_TYPE_MAJOR_SN } " ) 32string ( TOUPPER ${ SOC_TYPE_COMPILE_OPTION } SOC_TYPE_COMPILE_OPTION ) 33message ( STATUS "CANN: SOC_VERSION = ${ SOC_VERSION } " ) 34option ( USE_ACL_GRAPH "Enable CANN graph execution (ACL graph mode)" OFF ) 35 36if ( USE_ACL_GRAPHAND ( SOC_TYPE_MAJOR_SNSTREQUAL "310P" OR SOC_TYPE_COMPILE_OPTIONSTREQUAL "ASCEND_310P" )) 37message ( FATAL_ERROR 38"CANN Graph (ACL graph mode) is not supported on 310P devices. " 39"Please build with -DUSE_ACL_GRAPH=OFF or use a supported SOC." ) 40endif () 41 42if ( CANN_INSTALL_DIR) 43# Only Support Linux. 44if ( NOT UNIX) 45message ( FATAL_ERROR "CANN: CANN toolkit supports unix but not ${ CMAKE_SYSTEM_NAME } " ) 46endif () 47 48# Supported platforms: x86-64, arm64 49if ( CMAKE_SYSTEM_PROCESSORSTREQUAL "aarch64" ) 50elseif ( CMAKE_SYSTEM_PROCESSORSTREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSORSTREQUAL "amd64" ) 51else () 52message ( FATAL_ERROR "CANN: CANN toolkit supports x86-64 and arm64 but not ${ CMAKE_SYSTEM_PROCESSOR } " ) 53endif () 54 55# Set header and libs 56set ( CANN_INCLUDE_DIRS 57${ CANN_INSTALL_DIR } /include 58${ CANN_INSTALL_DIR } /include/aclnn 59${ CANN_INSTALL_DIR } /acllib/include 60) 61 62list ( APPEND CANN_LIBRARIES 63ascendcl 64nnopbase 65opapi 66acl_op_compiler 67) 68 69file ( GLOB GGML_SOURCES_CANN "*.cpp" ) 70 71ggml_add_backend_library ( ggml-cann ${ GGML_SOURCES_CANN }) 72target_link_libraries ( ggml-cann PRIVATE ${ CANN_LIBRARIES }) 73target_include_directories ( ggml-cann PRIVATE ${ CANN_INCLUDE_DIRS }) 74target_link_directories ( ggml-cann PRIVATE ${ CANN_INSTALL_DIR } /lib64 ) 75 76target_compile_definitions ( ggml-cann PRIVATE "-D ${ SOC_TYPE_COMPILE_OPTION } " ) 77 78if ( USE_ACL_GRAPH) 79target_compile_definitions ( ggml-cann PRIVATE USE_ACL_GRAPH ) 80message ( STATUS "CANN: USE_ACL_GRAPH is enabled." ) 81else () 82message ( STATUS "CANN: USE_ACL_GRAPH is disabled." ) 83endif () 84 85message ( STATUS "CANN: CANN_INCLUDE_DIRS = ${ CANN_INCLUDE_DIRS } " ) 86message ( STATUS "CANN: CANN_LIBRARIES = ${ CANN_LIBRARIES } " ) 87else () 88message ( FATAL_ERROR "CANN: Can't find CANN_INSTALL_DIR, did you forget to source set_var.sh?" ) 89endif ()