[Kernel] add custom op GmmSwigluQuantWeightNzTensorList (#3804)
### What this PR does / why we need it? This PR introduces support for adding custom CANN `aclnn` ops to `vllm-ascend`, allowing users to define and use their own custom operators. Key changes include: - Building and installing custom ops into the `vllm-ascend`-specified directory - Binding the `aclnn` op interface to the `torch.ops._C_ascend` module - Enabling invocation of these ops within `vllm-ascend` This PR includes a sample custom op: `aclnnGroupedMatmulSwigluQuantWeightNzTensorList`, which is adapted from the CANN operator [`aclnnGroupedMatmulSwigluQuantWeightNZ`](https://www.hiascend.com/document/detail/zh/canncommercial/83RC1/API/aolapi/context/aclnnGroupedMatmulSwigluQuantWeightNZ.md). Its input parameters `weight` and `weight_scale` now accept `list[torch.Tensor]` (i.e., `at::TensorList`). ### Does this PR introduce _any_ user-facing change? No. - vLLM version: v0.11.2 --------- Signed-off-by: QianChenxi <chenxi.qian.cq@outlook.com>
This commit is contained in:
235
csrc/cmake/config.cmake
Normal file
235
csrc/cmake/config.cmake
Normal file
@@ -0,0 +1,235 @@
|
||||
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
# This file is a part of the CANN Open Software.
|
||||
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# ======================================================================================================================
|
||||
|
||||
########################################################################################################################
|
||||
# Environment Check
|
||||
########################################################################################################################
|
||||
|
||||
# Python3
|
||||
find_package(Python3)
|
||||
if ((NOT Python3_FOUND) OR (${Python3_EXECUTABLE} STREQUAL ""))
|
||||
message(FATAL_ERROR "Can't find python3.")
|
||||
endif ()
|
||||
set(HI_PYTHON "${Python3_EXECUTABLE}" CACHE STRING "python executor")
|
||||
|
||||
# Get the base CANN path
|
||||
if (CUSTOM_ASCEND_CANN_PACKAGE_PATH)
|
||||
set(ASCEND_CANN_PACKAGE_PATH ${CUSTOM_ASCEND_CANN_PACKAGE_PATH})
|
||||
elseif (DEFINED ENV{ASCEND_HOME_PATH})
|
||||
set(ASCEND_CANN_PACKAGE_PATH $ENV{ASCEND_HOME_PATH})
|
||||
elseif (DEFINED ENV{ASCEND_OPP_PATH})
|
||||
get_filename_component(ASCEND_CANN_PACKAGE_PATH "$ENV{ASCEND_OPP_PATH}/.." ABSOLUTE)
|
||||
else()
|
||||
set(ASCEND_CANN_PACKAGE_PATH "/usr/local/Ascend/latest")
|
||||
endif ()
|
||||
message(STATUS "ASCEND_CANN_PACKAGE_PATH=${ASCEND_CANN_PACKAGE_PATH}")
|
||||
|
||||
########################################################################################################################
|
||||
# Common Configuration
|
||||
########################################################################################################################
|
||||
|
||||
# Switches
|
||||
option(PREPARE_BUILD "Prepare build." OFF)
|
||||
option(ENABLE_OPS_HOST "Build ops host." ON)
|
||||
option(ENABLE_OPS_KERNEL "Build ops kernel." ON)
|
||||
if (TESTS_EXAMPLE_OPS_TEST OR TESTS_UT_OPS_TEST)
|
||||
set(ENABLE_OPS_KERNEL OFF)
|
||||
endif ()
|
||||
set(OP_DEBUG_CONFIG "false" CACHE STRING "op debug config")
|
||||
|
||||
# Path configuration
|
||||
# Source tree related paths
|
||||
get_filename_component(OPS_ADV_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
|
||||
get_filename_component(OPS_ADV_CMAKE_DIR "${OPS_ADV_DIR}/cmake" REALPATH)
|
||||
get_filename_component(OPS_ADV_UTILS_KERNEL_INC "${OPS_ADV_DIR}/utils/inc/kernel" REALPATH)
|
||||
|
||||
|
||||
# Build tree related paths
|
||||
set(ASCEND_IMPL_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/impl CACHE STRING "ascend impl output directories")
|
||||
set(ASCEND_BINARY_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/binary CACHE STRING "ascend binary output directories")
|
||||
set(ASCEND_AUTOGEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/autogen CACHE STRING "Auto generate file directories")
|
||||
set(ASCEND_CUSTOM_OPTIONS ${ASCEND_AUTOGEN_DIR}/custom_compile_options.ini)
|
||||
set(ASCEND_CUSTOM_TILING_KEYS ${ASCEND_AUTOGEN_DIR}/custom_tiling_keys.ini)
|
||||
set(ASCEND_CUSTOM_OPC_OPTIONS ${ASCEND_AUTOGEN_DIR}/custom_opc_options.ini)
|
||||
set(OP_BUILD_TOOL ${ASCEND_CANN_PACKAGE_PATH}/tools/opbuild/op_build CACHE STRING "op_build tool")
|
||||
file(MAKE_DIRECTORY ${ASCEND_AUTOGEN_DIR})
|
||||
file(REMOVE ${ASCEND_CUSTOM_OPTIONS})
|
||||
file(TOUCH ${ASCEND_CUSTOM_OPTIONS})
|
||||
file(REMOVE ${ASCEND_CUSTOM_TILING_KEYS})
|
||||
file(TOUCH ${ASCEND_CUSTOM_TILING_KEYS})
|
||||
file(REMOVE ${ASCEND_CUSTOM_OPC_OPTIONS})
|
||||
file(TOUCH ${ASCEND_CUSTOM_OPC_OPTIONS})
|
||||
if (BUILD_OPEN_PROJECT)
|
||||
if(EXISTS ${ASCEND_CANN_PACKAGE_PATH}/tools/ascend_project/cmake)
|
||||
set(ASCEND_PROJECT_DIR ${ASCEND_CANN_PACKAGE_PATH}/tools/ascend_project)
|
||||
else()
|
||||
set(ASCEND_PROJECT_DIR ${ASCEND_CANN_PACKAGE_PATH}/tools/op_project_templates/ascendc/customize)
|
||||
endif()
|
||||
set(ASCEND_CMAKE_DIR ${ASCEND_PROJECT_DIR}/cmake CACHE STRING "ascend project cmake")
|
||||
set(IMPL_INSTALL_DIR packages/vendors/${VENDOR_NAME}/op_impl/ai_core/tbe/${VENDOR_NAME}_impl)
|
||||
set(IMPL_DYNAMIC_INSTALL_DIR packages/vendors/${VENDOR_NAME}/op_impl/ai_core/tbe/${VENDOR_NAME}_impl/dynamic)
|
||||
set(ACLNN_INC_INSTALL_DIR packages/vendors/${VENDOR_NAME}/op_api/include)
|
||||
else()
|
||||
set(ASCEND_CMAKE_DIR ${TOP_DIR}/asl/ops/cann/ops/built-in/ascendc/samples/customize/cmake CACHE STRING "ascend project cmake")
|
||||
set(IMPL_INSTALL_DIR lib/ascendc/impl)
|
||||
set(IMPL_DYNAMIC_INSTALL_DIR lib/ascendc/impl/dynamic)
|
||||
set(ACLNN_INC_INSTALL_DIR lib/include)
|
||||
set(OPS_STATIC_TYPES infer train)
|
||||
set(OPS_STATIC_SCRIPT ${TOP_DIR}/asl/ops/cann/ops/built-in/kernel/binary_script/build_opp_kernel_static.py)
|
||||
endif ()
|
||||
set(ASCENDC_CMAKE_UTIL_DIR ${ASCEND_CMAKE_DIR}/util)
|
||||
set(CUSTOM_DIR ${CMAKE_BINARY_DIR}/custom)
|
||||
set(TILING_CUSTOM_DIR ${CUSTOM_DIR}/op_impl/ai_core/tbe/op_tiling)
|
||||
set(TILING_CUSTOM_FILE ${TILING_CUSTOM_DIR}/liboptiling.so)
|
||||
|
||||
# Temporary adaptation for ascendc changes, to be removed after switching to the new version of ascendc
|
||||
if(EXISTS ${ASCENDC_CMAKE_UTIL_DIR}/ascendc_gen_options.py)
|
||||
set(ADD_OPS_COMPILE_OPTION_V2 ON)
|
||||
else()
|
||||
set(ADD_OPS_COMPILE_OPTION_V2 OFF)
|
||||
endif()
|
||||
|
||||
########################################################################################################################
|
||||
# CMake Options, Default Parameters Setting
|
||||
# Configure CMake options and default parameters according to the CMake build process
|
||||
# CMake build process: 1) Configuration phase; 2) Build phase; 3) Installation phase;
|
||||
########################################################################################################################
|
||||
if (BUILD_OPEN_PROJECT)
|
||||
# Build phase
|
||||
# Build type
|
||||
# The Generator in CMake is a tool used to generate native build systems. Generally divided into two types:
|
||||
# 1. Single-configuration generator:
|
||||
# In the configuration phase, only one build type is allowed to be specified through the variable CMAKE_BUILD_TYPE;
|
||||
# In the build phase, the build type cannot be changed, and only the build type specified through the variable CMAKE_BUILD_TYPE in the configuration phase can be used;
|
||||
# Common generators of this type include: Ninja, Unix Makefiles
|
||||
# 2. Multi-configuration generator:
|
||||
# In the configuration phase, only the list of build types available in the build phase is specified through the variable CMAKE_CONFIGURATION_TYPES;
|
||||
# In the build phase, the specific build type of the build phase is specified through the "--config" parameter;
|
||||
# Common generators of this type include: Xcode, Visual Studio
|
||||
# Therefore:
|
||||
# 1. In the single-configuration generator scenario, if the build type (CMAKE_BUILD_TYPE) is not specified, the default is Debug;
|
||||
# 2. In the multi-configuration generator scenario, if the build types available in the build phase (CMAKE_CONFIGURATION_TYPES) are not specified,
|
||||
# it is defaulted to the full set of build types allowed by CMake [Debug;Release;MinSizeRel;RelWithDebInfo]
|
||||
get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
if (GENERATOR_IS_MULTI_CONFIG)
|
||||
if (NOT CMAKE_CONFIGURATION_TYPES)
|
||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" CACHE STRING "Configuration Build type" FORCE)
|
||||
endif ()
|
||||
else ()
|
||||
if (NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Build type(default Debug)" FORCE)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Build phase
|
||||
# Executable runtime library file search path RPATH
|
||||
# Do not skip RPATH in UTest and Example scenarios
|
||||
if (TESTS_UT_OPS_TEST OR TESTS_EXAMPLE_OPS_TEST)
|
||||
set(CMAKE_SKIP_RPATH FALSE)
|
||||
else ()
|
||||
set(CMAKE_SKIP_RPATH TRUE)
|
||||
endif ()
|
||||
|
||||
# Build phase
|
||||
# CCACHE configuration
|
||||
if (ENABLE_CCACHE)
|
||||
if (CUSTOM_CCACHE)
|
||||
set(CCACHE_PROGRAM ${CUSTOM_CCACHE})
|
||||
else()
|
||||
find_program(CCACHE_PROGRAM ccache)
|
||||
endif ()
|
||||
if (CCACHE_PROGRAM)
|
||||
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE PATH "C cache Compiler")
|
||||
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM} CACHE PATH "CXX cache Compiler")
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
# Installation phase
|
||||
# Installation path
|
||||
# When CMAKE_INSTALL_PREFIX is not explicitly set (i.e., CMAKE_INSTALL_PREFIX takes the default value),
|
||||
# correct its value to be level with the build tree root directory CMAKE_CURRENT_BINARY_DIR
|
||||
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
|
||||
get_filename_component(_Install_Path_Prefix "${CMAKE_CURRENT_BINARY_DIR}/../output" REALPATH)
|
||||
set(CMAKE_INSTALL_PREFIX "${_Install_Path_Prefix}" CACHE STRING "Install path" FORCE)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
########################################################################################################################
|
||||
# Public Compilation Parameters
|
||||
########################################################################################################################
|
||||
list(TRANSFORM ASCEND_COMPUTE_UNIT TOLOWER)
|
||||
if (BUILD_OPEN_PROJECT)
|
||||
message(STATUS "ENABLE_CCACHE=${ENABLE_CCACHE}, CUSTOM_CCACHE=${CUSTOM_CCACHE}")
|
||||
message(STATUS "CCACHE_PROGRAM=${CCACHE_PROGRAM}")
|
||||
message(STATUS "ASCEND_COMPUTE_UNIT=${ASCEND_COMPUTE_UNIT}")
|
||||
message(STATUS "ASCEND_OP_NAME=${ASCEND_OP_NAME}")
|
||||
message(STATUS "TILING_KEY=${TILING_KEY}")
|
||||
message(STATUS "TESTS_UT_OPS_TEST=${TESTS_UT_OPS_TEST}")
|
||||
message(STATUS "TESTS_EXAMPLE_OPS_TEST=${TESTS_EXAMPLE_OPS_TEST}")
|
||||
endif ()
|
||||
|
||||
########################################################################################################################
|
||||
# Preprocessing
|
||||
########################################################################################################################
|
||||
if (BUILD_OPEN_PROJECT)
|
||||
if (NOT PREPARE_BUILD AND ENABLE_OPS_KERNEL)
|
||||
if (TILING_KEY)
|
||||
string(REPLACE ";" "::" EP_TILING_KEY "${TILING_KEY}")
|
||||
else()
|
||||
set(EP_TILING_KEY FALSE)
|
||||
endif ()
|
||||
|
||||
if (OPS_COMPILE_OPTIONS)
|
||||
string(REPLACE ";" "::" EP_OPS_COMPILE_OPTIONS "${OPS_COMPILE_OPTIONS}")
|
||||
else()
|
||||
set(EP_OPS_COMPILE_OPTIONS FALSE)
|
||||
endif ()
|
||||
|
||||
string(REPLACE ";" "::" EP_ASCEND_COMPUTE_UNIT "${ASCEND_COMPUTE_UNIT}")
|
||||
|
||||
execute_process(COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/prepare.sh
|
||||
-s ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
-b ${CMAKE_CURRENT_BINARY_DIR}/prepare_build
|
||||
-p ${ASCEND_CANN_PACKAGE_PATH}
|
||||
--autogen-dir ${ASCEND_AUTOGEN_DIR}
|
||||
--build-open-project ${BUILD_OPEN_PROJECT}
|
||||
--binary-out-dir ${ASCEND_BINARY_OUT_DIR}
|
||||
--impl-out-dir ${ASCEND_IMPL_OUT_DIR}
|
||||
--op-build-tool ${OP_BUILD_TOOL}
|
||||
--ascend-cmake-dir ${ASCEND_CMAKE_DIR}
|
||||
--tiling-key ${EP_TILING_KEY}
|
||||
--ops-compile-options ${EP_OPS_COMPILE_OPTIONS}
|
||||
--check-compatible ${CHECK_COMPATIBLE}
|
||||
--ascend-compute_unit ${EP_ASCEND_COMPUTE_UNIT}
|
||||
--op_debug_config ${OP_DEBUG_CONFIG}
|
||||
--ascend-op-name "${ASCEND_OP_NAME}"
|
||||
RESULT_VARIABLE result
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
OUTPUT_VARIABLE PREPARE_BUILD_OUTPUT_VARIABLE)
|
||||
if (result)
|
||||
message(FATAL_ERROR "Error: ops prepare build failed.")
|
||||
endif ()
|
||||
|
||||
file(REMOVE ${ASCEND_CUSTOM_OPTIONS})
|
||||
file(TOUCH ${ASCEND_CUSTOM_OPTIONS})
|
||||
file(REMOVE ${ASCEND_CUSTOM_TILING_KEYS})
|
||||
file(TOUCH ${ASCEND_CUSTOM_TILING_KEYS})
|
||||
file(REMOVE ${ASCEND_CUSTOM_OPC_OPTIONS})
|
||||
file(TOUCH ${ASCEND_CUSTOM_OPC_OPTIONS})
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
########################################################################################################################
|
||||
# Other Configuration
|
||||
########################################################################################################################
|
||||
if (BUILD_OPEN_PROJECT)
|
||||
if (TESTS_UT_OPS_TEST)
|
||||
include(${OPS_ADV_CMAKE_DIR}/config_utest.cmake)
|
||||
endif ()
|
||||
endif ()
|
||||
609
csrc/cmake/func.cmake
Normal file
609
csrc/cmake/func.cmake
Normal file
@@ -0,0 +1,609 @@
|
||||
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
# This file is a part of the CANN Open Software.
|
||||
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# ======================================================================================================================
|
||||
|
||||
function(add_target_source)
|
||||
cmake_parse_arguments(ADD "" "BASE_TARGET;SRC_DIR" "TARGET_NAME" ${ARGN})
|
||||
|
||||
get_target_property(all_srcs ${ADD_BASE_TARGET} SOURCES)
|
||||
set(add_srcs)
|
||||
foreach(_src ${all_srcs})
|
||||
string(REGEX MATCH "^${ADD_SRC_DIR}" is_match "${_src}")
|
||||
if (is_match)
|
||||
list(APPEND add_srcs ${_src})
|
||||
endif ()
|
||||
endforeach()
|
||||
|
||||
get_target_property(all_includes ${ADD_BASE_TARGET} INCLUDE_DIRECTORIES)
|
||||
set(add_includes)
|
||||
foreach(_include ${all_includes})
|
||||
string(REGEX MATCH "^${ADD_SRC_DIR}" is_match "${_include}")
|
||||
if (is_match)
|
||||
list(APPEND add_includes ${_include})
|
||||
endif ()
|
||||
endforeach()
|
||||
|
||||
foreach(_target_name ${ADD_TARGET_NAME})
|
||||
target_sources(${_target_name} PRIVATE
|
||||
${add_srcs}
|
||||
)
|
||||
|
||||
target_include_directories(${_target_name} PRIVATE
|
||||
${add_includes}
|
||||
)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(op_add_subdirectory OP_LIST OP_DIR_LIST)
|
||||
set(_OP_LIST)
|
||||
set(_OP_DIR_LIST)
|
||||
|
||||
file(GLOB OP_HOST_CMAKE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/**/op_host/CMakeLists.txt")
|
||||
|
||||
foreach(OP_CMAKE_FILE ${OP_HOST_CMAKE_FILES})
|
||||
get_filename_component(OP_HOST_DIR "${OP_CMAKE_FILE}" DIRECTORY)
|
||||
get_filename_component(OP_DIR "${OP_HOST_DIR}" DIRECTORY)
|
||||
get_filename_component(OP_NAME "${OP_DIR}" NAME)
|
||||
|
||||
if (NOT BUILD_OPEN_PROJECT)
|
||||
if (EXISTS ${TOP_DIR}/asl/ops/cann/ops/built-in/tbe/impl/ascendc/${OP_NAME})
|
||||
continue()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (DEFINED ASCEND_OP_NAME AND NOT "${ASCEND_OP_NAME}" STREQUAL "")
|
||||
if (NOT "${ASCEND_OP_NAME}" STREQUAL "all" AND NOT "${ASCEND_OP_NAME}" STREQUAL "ALL")
|
||||
if (NOT ${OP_NAME} IN_LIST ASCEND_OP_NAME)
|
||||
continue()
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
list(APPEND _OP_LIST ${OP_NAME})
|
||||
list(APPEND _OP_DIR_LIST ${OP_DIR})
|
||||
endforeach()
|
||||
|
||||
list(REMOVE_DUPLICATES _OP_LIST)
|
||||
list(REMOVE_DUPLICATES _OP_DIR_LIST)
|
||||
list(SORT _OP_LIST)
|
||||
list(SORT _OP_DIR_LIST)
|
||||
set(${OP_LIST} ${_OP_LIST} PARENT_SCOPE)
|
||||
set(${OP_DIR_LIST} ${_OP_DIR_LIST} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(op_add_depend_directory)
|
||||
cmake_parse_arguments(DEP "" "OP_DIR_LIST" "OP_LIST" ${ARGN})
|
||||
set(_OP_DEPEND_DIR_LIST)
|
||||
foreach(op_name ${DEP_OP_LIST})
|
||||
if (DEFINED ${op_name}_depends)
|
||||
foreach(depend_info ${${op_name}_depends})
|
||||
if (NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${depend_info}/op_host/CMakeLists.txt)
|
||||
continue()
|
||||
endif ()
|
||||
|
||||
get_filename_component(_depend_op_name "${depend_info}" NAME)
|
||||
if (NOT BUILD_OPEN_PROJECT)
|
||||
if (EXISTS ${TOP_DIR}/asl/ops/cann/ops/built-in/tbe/impl/ascendc/${_depend_op_name})
|
||||
continue()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (NOT ${_depend_op_name} IN_LIST DEP_OP_LIST)
|
||||
list(APPEND _OP_DEPEND_DIR_LIST ${CMAKE_CURRENT_SOURCE_DIR}/${depend_info})
|
||||
endif ()
|
||||
endforeach()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
list(SORT _OP_DEPEND_DIR_LIST)
|
||||
set(${DEP_OP_DIR_LIST} ${_OP_DEPEND_DIR_LIST} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(add_compile_cmd_target)
|
||||
cmake_parse_arguments(CMD "" "COMPUTE_UNIT" "" ${ARGN})
|
||||
|
||||
if(ADD_OPS_COMPILE_OPTION_V2)
|
||||
set(OP_DEBUG_CONFIG_OPTION --opc-config-file ${ASCEND_CUSTOM_OPC_OPTIONS})
|
||||
else()
|
||||
if(OP_DEBUG_CONFIG)
|
||||
set(OP_DEBUG_CONFIG_OPTION --op-debug-config ${OP_DEBUG_CONFIG})
|
||||
endif()
|
||||
set(OP_TILING_KEY_OPTION --tiling-keys ${ASCEND_CUSTOM_TILING_KEYS})
|
||||
endif()
|
||||
|
||||
set(_OUT_DIR ${ASCEND_BINARY_OUT_DIR}/${CMD_COMPUTE_UNIT})
|
||||
set(GEN_OUT_DIR ${_OUT_DIR}/gen)
|
||||
set(COMPILE_CMD_TARGET generate_compile_cmd_${CMD_COMPUTE_UNIT})
|
||||
add_custom_target(${COMPILE_CMD_TARGET} ALL
|
||||
COMMAND mkdir -p ${GEN_OUT_DIR}
|
||||
COMMAND ${HI_PYTHON} ${ASCENDC_CMAKE_UTIL_DIR}/ascendc_bin_param_build.py
|
||||
${base_aclnn_binary_dir}/aic-${CMD_COMPUTE_UNIT}-ops-info.ini
|
||||
${GEN_OUT_DIR}
|
||||
${CMD_COMPUTE_UNIT}
|
||||
${OP_TILING_KEY_OPTION}
|
||||
${OP_DEBUG_CONFIG_OPTION}
|
||||
COMMAND ${HI_PYTHON} ${ASCENDC_CMAKE_UTIL_DIR}/ascendc_bin_param_build.py
|
||||
${base_aclnn_binary_dir}/inner/aic-${CMD_COMPUTE_UNIT}-ops-info.ini
|
||||
${GEN_OUT_DIR}
|
||||
${CMD_COMPUTE_UNIT}
|
||||
${OP_TILING_KEY_OPTION}
|
||||
${OP_DEBUG_CONFIG_OPTION}
|
||||
COMMAND ${HI_PYTHON} ${ASCENDC_CMAKE_UTIL_DIR}/ascendc_bin_param_build.py
|
||||
${base_aclnn_binary_dir}/exc/aic-${CMD_COMPUTE_UNIT}-ops-info.ini
|
||||
${GEN_OUT_DIR}
|
||||
${CMD_COMPUTE_UNIT}
|
||||
${OP_TILING_KEY_OPTION}
|
||||
${OP_DEBUG_CONFIG_OPTION}
|
||||
)
|
||||
|
||||
add_dependencies(${COMPILE_CMD_TARGET} opbuild_gen_default opbuild_gen_inner opbuild_gen_exc)
|
||||
add_dependencies(generate_compile_cmd ${COMPILE_CMD_TARGET})
|
||||
endfunction()
|
||||
|
||||
function(add_ops_info_target)
|
||||
cmake_parse_arguments(OPINFO "" "COMPUTE_UNIT" "" ${ARGN})
|
||||
|
||||
set(OPS_INFO_TARGET generate_ops_info_${OPINFO_COMPUTE_UNIT})
|
||||
set(OPS_INFO_JSON ${ASCEND_AUTOGEN_DIR}/aic-${OPINFO_COMPUTE_UNIT}-ops-info.json)
|
||||
set(CUSTOM_OPS_INFO_DIR ${CUSTOM_DIR}/op_impl/ai_core/tbe/config/${OPINFO_COMPUTE_UNIT})
|
||||
|
||||
set(OPS_INFO_INI ${base_aclnn_binary_dir}/aic-${OPINFO_COMPUTE_UNIT}-ops-info.ini)
|
||||
set(OPS_INFO_INNER_INI ${base_aclnn_binary_dir}/inner/aic-${OPINFO_COMPUTE_UNIT}-ops-info.ini)
|
||||
set(OPS_INFO_EXCLUDE_INI ${base_aclnn_binary_dir}/exc/aic-${OPINFO_COMPUTE_UNIT}-ops-info.ini)
|
||||
|
||||
add_custom_command(OUTPUT ${OPS_INFO_JSON}
|
||||
COMMAND ${HI_PYTHON} ${ASCENDC_CMAKE_UTIL_DIR}/parse_ini_to_json.py
|
||||
${OPS_INFO_INI}
|
||||
${OPS_INFO_INNER_INI}
|
||||
${OPS_INFO_EXCLUDE_INI}
|
||||
${OPS_INFO_JSON}
|
||||
COMMAND mkdir -p ${CUSTOM_OPS_INFO_DIR}
|
||||
COMMAND cp -f ${OPS_INFO_JSON} ${CUSTOM_OPS_INFO_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(${OPS_INFO_TARGET} ALL
|
||||
DEPENDS ${OPS_INFO_JSON}
|
||||
)
|
||||
|
||||
add_dependencies(${OPS_INFO_TARGET} opbuild_gen_default opbuild_gen_inner opbuild_gen_exc)
|
||||
add_dependencies(generate_ops_info ${OPS_INFO_TARGET})
|
||||
|
||||
install(FILES ${OPS_INFO_JSON}
|
||||
DESTINATION packages/vendors/${VENDOR_NAME}/op_impl/ai_core/tbe/config/${OPINFO_COMPUTE_UNIT} OPTIONAL
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(add_ops_compile_options)
|
||||
cmake_parse_arguments(OP_COMPILE "" "OP_NAME" "COMPUTE_UNIT;OPTIONS" ${ARGN})
|
||||
|
||||
if(NOT OP_COMPILE_OPTIONS)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(ADD_OPS_COMPILE_OPTION_V2)
|
||||
execute_process(COMMAND ${HI_PYTHON} ${ASCENDC_CMAKE_UTIL_DIR}/ascendc_gen_options.py
|
||||
${ASCEND_CUSTOM_OPTIONS} ${OP_COMPILE_OP_NAME}
|
||||
${OP_COMPILE_COMPUTE_UNIT} ${OP_COMPILE_OPTIONS}
|
||||
RESULT_VARIABLE EXEC_RESULT
|
||||
OUTPUT_VARIABLE EXEC_INFO
|
||||
ERROR_VARIABLE EXEC_ERROR)
|
||||
if (EXEC_RESULT)
|
||||
message("add ops compile options info: ${EXEC_INFO}")
|
||||
message("add ops compile options error: ${EXEC_ERROR}")
|
||||
message(FATAL_ERROR "Error: add ops compile options failed!")
|
||||
endif ()
|
||||
else()
|
||||
file(APPEND ${ASCEND_CUSTOM_OPTIONS}
|
||||
"${OP_COMPILE_OP_NAME},${OP_COMPILE_COMPUTE_UNIT},${OP_COMPILE_OPTIONS}\n"
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(add_ops_tiling_keys)
|
||||
cmake_parse_arguments(OP_COMPILE "" "OP_NAME" "COMPUTE_UNIT;TILING_KEYS" ${ARGN})
|
||||
|
||||
if(NOT OP_COMPILE_TILING_KEYS)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(ADD_OPS_COMPILE_OPTION_V2)
|
||||
list(JOIN OP_COMPILE_TILING_KEYS "," STRING_TILING_KEYS)
|
||||
add_ops_compile_options(
|
||||
OP_NAME ${OP_COMPILE_OP_NAME}
|
||||
OPTIONS --tiling_key=${STRING_TILING_KEYS}
|
||||
)
|
||||
else()
|
||||
file(APPEND ${ASCEND_CUSTOM_TILING_KEYS}
|
||||
"${OP_COMPILE_OP_NAME},${OP_COMPILE_COMPUTE_UNIT},${OP_COMPILE_TILING_KEYS}\n"
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(add_opc_config)
|
||||
cmake_parse_arguments(OP_COMPILE "" "OP_NAME" "COMPUTE_UNIT;CONFIG" ${ARGN})
|
||||
|
||||
if(NOT ADD_OPS_COMPILE_OPTION_V2)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT OP_COMPILE_CONFIG)
|
||||
return()
|
||||
endif()
|
||||
|
||||
string(REPLACE "," ";" OP_COMPILE_CONFIG_LIST "${OP_COMPILE_CONFIG}")
|
||||
|
||||
set(_OPC_CONFIG)
|
||||
|
||||
foreach(_option ${OP_COMPILE_CONFIG_LIST})
|
||||
if("${_option}" STREQUAL "ccec_g")
|
||||
list(APPEND _OPC_CONFIG "-g")
|
||||
elseif("${_option}" STREQUAL "ccec_O0")
|
||||
list(APPEND _OPC_CONFIG "-O0")
|
||||
elseif("${_option}" STREQUAL "oom")
|
||||
list(APPEND _OPC_CONFIG "--oom")
|
||||
elseif("${_option}" STREQUAL "dump_cce")
|
||||
list(APPEND _OPC_CONFIG "--save-temp-files")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(_OPC_CONFIG)
|
||||
add_ops_compile_options(
|
||||
OP_NAME ${OP_COMPILE_OP_NAME}
|
||||
OPTIONS ${_OPC_CONFIG}
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(add_ops_src_copy)
|
||||
cmake_parse_arguments(SRC_COPY "" "TARGET_NAME;SRC;DST;BE_RELIED;COMPUTE_UNIT" "" ${ARGN})
|
||||
|
||||
set(OPS_UTILS_INC_KERNEL_TARGET ops_utils_inc_kernel_${SRC_COPY_COMPUTE_UNIT})
|
||||
if (EXISTS ${OPS_ADV_UTILS_KERNEL_INC})
|
||||
if (NOT TARGET ${OPS_UTILS_INC_KERNEL_TARGET})
|
||||
get_filename_component(_ROOT_OPS_SRC_DIR "${SRC_COPY_DST}" DIRECTORY)
|
||||
set(OPS_UTILS_INC_KERNEL_DIR ${_ROOT_OPS_SRC_DIR}/ascendc/common)
|
||||
add_custom_command(OUTPUT ${OPS_UTILS_INC_KERNEL_DIR}
|
||||
COMMAND mkdir -p ${OPS_UTILS_INC_KERNEL_DIR}
|
||||
COMMAND cp -rf ${OPS_ADV_UTILS_KERNEL_INC}/*.* ${OPS_UTILS_INC_KERNEL_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(${OPS_UTILS_INC_KERNEL_TARGET}
|
||||
DEPENDS ${OPS_UTILS_INC_KERNEL_DIR}
|
||||
)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
if (NOT TARGET ${SRC_COPY_TARGET_NAME})
|
||||
set(_BUILD_FLAG ${SRC_COPY_DST}/${SRC_COPY_TARGET_NAME}.done)
|
||||
add_custom_command(OUTPUT ${_BUILD_FLAG}
|
||||
COMMAND mkdir -p ${SRC_COPY_DST}
|
||||
COMMAND cp -rf ${SRC_COPY_SRC}/op_kernel/*.* ${SRC_COPY_DST}
|
||||
COMMAND touch ${_BUILD_FLAG}
|
||||
)
|
||||
|
||||
add_custom_target(${SRC_COPY_TARGET_NAME}
|
||||
DEPENDS ${_BUILD_FLAG}
|
||||
)
|
||||
endif ()
|
||||
|
||||
if (TARGET ${OPS_UTILS_INC_KERNEL_TARGET})
|
||||
add_dependencies(${SRC_COPY_TARGET_NAME} ${OPS_UTILS_INC_KERNEL_TARGET})
|
||||
endif ()
|
||||
|
||||
if (DEFINED SRC_COPY_BE_RELIED)
|
||||
add_dependencies(${SRC_COPY_BE_RELIED} ${SRC_COPY_TARGET_NAME})
|
||||
endif ()
|
||||
|
||||
endfunction()
|
||||
|
||||
function(add_bin_compile_target)
|
||||
cmake_parse_arguments(BINARY "" "COMPUTE_UNIT" "OP_INFO" ${ARGN})
|
||||
|
||||
set(_INSTALL_DIR packages/vendors/${VENDOR_NAME}/op_impl/ai_core/tbe/kernel)
|
||||
set(_OUT_DIR ${ASCEND_BINARY_OUT_DIR}/${BINARY_COMPUTE_UNIT})
|
||||
|
||||
set(BIN_OUT_DIR ${_OUT_DIR}/bin)
|
||||
set(GEN_OUT_DIR ${_OUT_DIR}/gen)
|
||||
set(SRC_OUT_DIR ${_OUT_DIR}/src)
|
||||
file(MAKE_DIRECTORY ${BIN_OUT_DIR})
|
||||
|
||||
foreach(_op_info ${BINARY_OP_INFO})
|
||||
get_filename_component(_op_name "${_op_info}" NAME)
|
||||
set(${_op_name}_dir ${_op_info})
|
||||
endforeach()
|
||||
|
||||
set(_ops_target_list)
|
||||
set(compile_scripts)
|
||||
file(GLOB scripts_list ${GEN_OUT_DIR}/*.sh)
|
||||
list(APPEND compile_scripts ${scripts_list})
|
||||
|
||||
foreach(bin_script ${compile_scripts})
|
||||
get_filename_component(bin_file ${bin_script} NAME_WE)
|
||||
string(REPLACE "-" ";" bin_sep ${bin_file})
|
||||
list(GET bin_sep 0 op_type)
|
||||
list(GET bin_sep 1 op_file)
|
||||
list(GET bin_sep 2 op_index)
|
||||
|
||||
if (NOT DEFINED ${op_file}_dir)
|
||||
continue()
|
||||
endif ()
|
||||
|
||||
if (NOT TARGET ${op_file})
|
||||
add_custom_target(${op_file})
|
||||
add_dependencies(ops_kernel ${op_file})
|
||||
endif ()
|
||||
|
||||
set(OP_TARGET_NAME ${op_file}_${BINARY_COMPUTE_UNIT})
|
||||
|
||||
if (NOT TARGET ${OP_TARGET_NAME})
|
||||
add_custom_target(${OP_TARGET_NAME})
|
||||
add_dependencies(${op_file} ${OP_TARGET_NAME})
|
||||
list(APPEND _ops_target_list ${OP_TARGET_NAME})
|
||||
|
||||
set(OP_SRC_OUT_DIR ${SRC_OUT_DIR}/${op_file})
|
||||
set(OP_BIN_OUT_DIR ${BIN_OUT_DIR}/${op_file})
|
||||
file(MAKE_DIRECTORY ${OP_SRC_OUT_DIR})
|
||||
|
||||
add_ops_src_copy(
|
||||
TARGET_NAME
|
||||
${OP_TARGET_NAME}_src_copy
|
||||
SRC
|
||||
${${op_file}_dir}
|
||||
DST
|
||||
${OP_SRC_OUT_DIR}
|
||||
COMPUTE_UNIT
|
||||
${BINARY_COMPUTE_UNIT}
|
||||
)
|
||||
|
||||
if (DEFINED ${op_file}_depends)
|
||||
foreach(depend_info ${${op_file}_depends})
|
||||
get_filename_component(_depend_op_name "${depend_info}" NAME)
|
||||
set(_depend_op_target ${_depend_op_name}_${BINARY_COMPUTE_UNIT}_src_copy)
|
||||
add_ops_src_copy(
|
||||
TARGET_NAME
|
||||
${_depend_op_target}
|
||||
SRC
|
||||
${CMAKE_SOURCE_DIR}/${depend_info}
|
||||
DST
|
||||
${SRC_OUT_DIR}/${_depend_op_name}
|
||||
COMPUTE_UNIT
|
||||
${BINARY_COMPUTE_UNIT}
|
||||
BE_RELIED
|
||||
${OP_TARGET_NAME}_src_copy
|
||||
)
|
||||
endforeach()
|
||||
endif ()
|
||||
|
||||
set(DYNAMIC_PY_FILE ${OP_SRC_OUT_DIR}/${op_type}.py)
|
||||
add_custom_command(OUTPUT ${DYNAMIC_PY_FILE}
|
||||
COMMAND cp -rf ${ASCEND_IMPL_OUT_DIR}/dynamic/${op_file}.py ${DYNAMIC_PY_FILE}
|
||||
)
|
||||
|
||||
add_custom_target(${OP_TARGET_NAME}_py_copy
|
||||
DEPENDS ${DYNAMIC_PY_FILE}
|
||||
)
|
||||
|
||||
add_custom_command(OUTPUT ${OP_BIN_OUT_DIR}
|
||||
COMMAND mkdir -p ${OP_BIN_OUT_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(${OP_TARGET_NAME}_mkdir
|
||||
DEPENDS ${OP_BIN_OUT_DIR}
|
||||
)
|
||||
|
||||
install(DIRECTORY ${OP_BIN_OUT_DIR}
|
||||
DESTINATION ${_INSTALL_DIR}/${BINARY_COMPUTE_UNIT} OPTIONAL
|
||||
)
|
||||
|
||||
install(FILES ${BIN_OUT_DIR}/${op_file}.json
|
||||
DESTINATION ${_INSTALL_DIR}/config/${BINARY_COMPUTE_UNIT} OPTIONAL
|
||||
)
|
||||
endif ()
|
||||
|
||||
set(_group "1-0")
|
||||
if (DEFINED ASCEND_OP_NAME AND NOT "${ASCEND_OP_NAME}" STREQUAL "")
|
||||
if (NOT "${ASCEND_OP_NAME}" STREQUAL "all" AND NOT "${ASCEND_OP_NAME}" STREQUAL "ALL")
|
||||
if (${op_file} IN_LIST ASCEND_OP_NAME)
|
||||
list(LENGTH ASCEND_OP_NAME _len)
|
||||
list(FIND ASCEND_OP_NAME ${op_file} _index)
|
||||
math(EXPR _next_index "${_index} + 1")
|
||||
if (${_next_index} LESS ${_len})
|
||||
list(GET ASCEND_OP_NAME ${_next_index} _group_str)
|
||||
set(_regex "^[0-9]+-[0-9]+$")
|
||||
string(REGEX MATCH "${_regex}" match "${_group_str}")
|
||||
if (match)
|
||||
set(_group ${_group_str})
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
string(REPLACE "-" ";" _group_sep ${_group})
|
||||
|
||||
list(GET _group_sep 1 start_index)
|
||||
set(end_index ${op_index})
|
||||
list(GET _group_sep 0 step)
|
||||
|
||||
set(_compile_flag false)
|
||||
if (${start_index} LESS ${end_index})
|
||||
foreach(i RANGE ${start_index} ${end_index} ${step})
|
||||
if (${i} EQUAL ${end_index})
|
||||
set(_compile_flag true)
|
||||
break()
|
||||
endif ()
|
||||
endforeach()
|
||||
elseif (${start_index} EQUAL ${end_index})
|
||||
set(_compile_flag true)
|
||||
else()
|
||||
set(_compile_flag false)
|
||||
endif ()
|
||||
|
||||
if (_compile_flag)
|
||||
set(_BUILD_COMMAND)
|
||||
set(_BUILD_FLAG ${GEN_OUT_DIR}/${OP_TARGET_NAME}_${op_index}.done)
|
||||
if (ENABLE_OPS_HOST)
|
||||
list(APPEND _BUILD_COMMAND export ASCEND_CUSTOM_OPP_PATH=${CUSTOM_DIR} &&)
|
||||
endif ()
|
||||
list(APPEND _BUILD_COMMAND export HI_PYTHON="python3" &&)
|
||||
list(APPEND _BUILD_COMMAND export TILINGKEY_PAR_COMPILE=1 &&)
|
||||
list(APPEND _BUILD_COMMAND export BIN_FILENAME_HASHED=1 &&)
|
||||
list(APPEND _BUILD_COMMAND bash ${bin_script} ${OP_SRC_OUT_DIR}/${op_type}.py ${OP_BIN_OUT_DIR})
|
||||
if(CMAKE_GENERATOR MATCHES "Unix Makefiles")
|
||||
list(APPEND _BUILD_COMMAND && echo $(MAKE))
|
||||
endif()
|
||||
|
||||
add_custom_command(OUTPUT ${_BUILD_FLAG}
|
||||
COMMAND ${_BUILD_COMMAND}
|
||||
COMMAND touch ${_BUILD_FLAG}
|
||||
WORKING_DIRECTORY ${GEN_OUT_DIR}
|
||||
)
|
||||
|
||||
add_custom_target(${OP_TARGET_NAME}_${op_index}
|
||||
DEPENDS ${_BUILD_FLAG}
|
||||
)
|
||||
|
||||
if (ENABLE_OPS_HOST)
|
||||
add_dependencies(${OP_TARGET_NAME}_${op_index} optiling generate_ops_info)
|
||||
endif ()
|
||||
add_dependencies(${OP_TARGET_NAME}_${op_index} ${OP_TARGET_NAME}_src_copy ${OP_TARGET_NAME}_py_copy ${OP_TARGET_NAME}_mkdir)
|
||||
add_dependencies(${OP_TARGET_NAME} ${OP_TARGET_NAME}_${op_index})
|
||||
endif ()
|
||||
endforeach()
|
||||
|
||||
if (_ops_target_list)
|
||||
set(OPS_CONFIG_TARGET ops_config_${BINARY_COMPUTE_UNIT})
|
||||
set(BINARY_INFO_CONFIG_FILE ${BIN_OUT_DIR}/binary_info_config.json)
|
||||
|
||||
add_custom_command(OUTPUT ${BINARY_INFO_CONFIG_FILE}
|
||||
COMMAND ${HI_PYTHON} ${ASCENDC_CMAKE_UTIL_DIR}/ascendc_ops_config.py -p ${BIN_OUT_DIR} -s ${BINARY_COMPUTE_UNIT}
|
||||
)
|
||||
|
||||
add_custom_target(${OPS_CONFIG_TARGET}
|
||||
DEPENDS ${BINARY_INFO_CONFIG_FILE}
|
||||
)
|
||||
|
||||
add_dependencies(ops_config ${OPS_CONFIG_TARGET})
|
||||
|
||||
foreach(_op_target ${_ops_target_list})
|
||||
add_dependencies(${OPS_CONFIG_TARGET} ${_op_target})
|
||||
endforeach()
|
||||
|
||||
install(FILES ${BINARY_INFO_CONFIG_FILE}
|
||||
DESTINATION ${_INSTALL_DIR}/config/${BINARY_COMPUTE_UNIT} OPTIONAL
|
||||
)
|
||||
endif ()
|
||||
endfunction()
|
||||
|
||||
function(redefine_file_macro)
|
||||
cmake_parse_arguments(_FILE "" "" "TARGET_NAME" ${ARGN})
|
||||
|
||||
foreach(_target_name ${_FILE_TARGET_NAME})
|
||||
target_compile_options(${_target_name} PRIVATE
|
||||
-Wno-builtin-macro-redefined
|
||||
)
|
||||
|
||||
get_target_property(_srcs ${_target_name} SOURCES)
|
||||
|
||||
foreach(_src ${_srcs})
|
||||
get_filename_component(_src_name "${_src}" NAME)
|
||||
set_source_files_properties(${_src}
|
||||
PROPERTIES COMPILE_DEFINITIONS __FILE__="${_src_name}"
|
||||
)
|
||||
endforeach()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(add_static_ops)
|
||||
cmake_parse_arguments(STATIC "" "SRC_DIR" "ACLNN_SRC;ACLNN_INNER_SRC" ${ARGN})
|
||||
set(prepare_ops_adv_static_target prepare_ops_adv_static)
|
||||
set(static_src_temp_dir ${CMAKE_CURRENT_BINARY_DIR}/static_src_temp_dir)
|
||||
set(modified_files)
|
||||
foreach(ops_type ${OPS_STATIC_TYPES})
|
||||
get_target_property(all_srcs aclnn_ops_${ops_type} SOURCES)
|
||||
set(add_srcs)
|
||||
set(generate_aclnn_srcs)
|
||||
foreach(_src ${all_srcs})
|
||||
string(REGEX MATCH "^${STATIC_SRC_DIR}" is_match "${_src}")
|
||||
if (is_match)
|
||||
list(APPEND add_srcs ${_src})
|
||||
endif ()
|
||||
endforeach()
|
||||
|
||||
foreach(_src ${add_srcs})
|
||||
get_filename_component(name_without_ext ${_src} NAME_WE)
|
||||
string(REGEX REPLACE "^aclnn_" "" _op_name ${name_without_ext})
|
||||
|
||||
foreach(_aclnn_src ${STATIC_ACLNN_SRC})
|
||||
get_filename_component(aclnn_name ${_aclnn_src} NAME_WE)
|
||||
if("aclnn_${_op_name}" STREQUAL "${aclnn_name}")
|
||||
list(APPEND generate_aclnn_srcs ${_aclnn_src})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(_aclnn_inner_src ${STATIC_ACLNN_INNER_SRC})
|
||||
get_filename_component(aclnn_inner_name ${_aclnn_inner_src} NAME_WE)
|
||||
if("aclnnInner_${_op_name}" STREQUAL "${aclnn_inner_name}")
|
||||
list(APPEND generate_aclnn_srcs ${_aclnn_inner_src})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
if(add_srcs)
|
||||
list(TRANSFORM add_srcs REPLACE "${STATIC_SRC_DIR}" "${static_src_temp_dir}" OUTPUT_VARIABLE add_static_srcs)
|
||||
list(APPEND modified_files ${add_static_srcs})
|
||||
set(aclnn_ops_static_target aclnn_ops_${ops_type}_static)
|
||||
set_source_files_properties(${add_static_srcs}
|
||||
TARGET_DIRECTORY ${aclnn_ops_static_target}
|
||||
PROPERTIES GENERATED TRUE
|
||||
)
|
||||
|
||||
target_sources(${aclnn_ops_static_target} PRIVATE
|
||||
${add_static_srcs}
|
||||
)
|
||||
add_dependencies(${aclnn_ops_static_target} ${prepare_ops_adv_static_target})
|
||||
endif()
|
||||
|
||||
if(generate_aclnn_srcs)
|
||||
list(REMOVE_DUPLICATES generate_aclnn_srcs)
|
||||
set(aclnn_op_target acl_op_${ops_type}_builtin)
|
||||
set_source_files_properties(${generate_aclnn_srcs}
|
||||
TARGET_DIRECTORY ${aclnn_op_target}
|
||||
PROPERTIES GENERATED TRUE
|
||||
)
|
||||
|
||||
target_sources(${aclnn_op_target} PRIVATE
|
||||
${generate_aclnn_srcs}
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT TARGET ${prepare_ops_adv_static_target})
|
||||
list(REMOVE_DUPLICATES modified_files)
|
||||
add_custom_command(OUTPUT ${static_src_temp_dir}
|
||||
COMMAND mkdir -p ${static_src_temp_dir}
|
||||
COMMAND cp -rf ${STATIC_SRC_DIR}/src ${static_src_temp_dir}
|
||||
COMMAND ${HI_PYTHON} -B ${OPS_STATIC_SCRIPT} InsertIni -p ${static_src_temp_dir} -f ${modified_files}
|
||||
)
|
||||
|
||||
add_custom_target(${prepare_ops_adv_static_target}
|
||||
DEPENDS ${static_src_temp_dir}
|
||||
)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if (BUILD_OPEN_PROJECT)
|
||||
if (TESTS_UT_OPS_TEST)
|
||||
include(${OPS_ADV_CMAKE_DIR}/func_utest.cmake)
|
||||
endif ()
|
||||
if (TESTS_EXAMPLE_OPS_TEST)
|
||||
include(${OPS_ADV_CMAKE_DIR}/func_examples.cmake)
|
||||
endif ()
|
||||
endif ()
|
||||
12
csrc/cmake/intf.cmake
Normal file
12
csrc/cmake/intf.cmake
Normal file
@@ -0,0 +1,12 @@
|
||||
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
# This file is a part of the CANN Open Software.
|
||||
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# ======================================================================================================================
|
||||
|
||||
if (BUILD_OPEN_PROJECT)
|
||||
include(${OPS_ADV_CMAKE_DIR}/intf_pub.cmake)
|
||||
endif ()
|
||||
75
csrc/cmake/intf_pub.cmake
Normal file
75
csrc/cmake/intf_pub.cmake
Normal file
@@ -0,0 +1,75 @@
|
||||
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
# This file is a part of the CANN Open Software.
|
||||
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# ======================================================================================================================
|
||||
|
||||
# Custom package scenario, public compilation configuration for Host side targets
|
||||
# Note: To ensure compatibility with the built-in package compilation process, the intf_pub name cannot be changed
|
||||
add_library(intf_pub INTERFACE)
|
||||
target_include_directories(intf_pub
|
||||
INTERFACE
|
||||
${ASCEND_CANN_PACKAGE_PATH}/include
|
||||
${ASCEND_CANN_PACKAGE_PATH}/include/external
|
||||
${ASCEND_CANN_PACKAGE_PATH}/include/experiment/platform
|
||||
${ASCEND_CANN_PACKAGE_PATH}/include/experiment/runtime
|
||||
${ASCEND_CANN_PACKAGE_PATH}/include/experiment/msprof
|
||||
)
|
||||
target_link_directories(intf_pub
|
||||
INTERFACE
|
||||
${ASCEND_CANN_PACKAGE_PATH}/lib64
|
||||
)
|
||||
target_compile_options(intf_pub
|
||||
INTERFACE
|
||||
-fPIC
|
||||
-O2
|
||||
-Wall -Wundef -Wcast-qual -Wpointer-arith -Wdate-time
|
||||
-Wfloat-equal -Wformat=2 -Wshadow
|
||||
-Wsign-compare -Wunused-macros -Wvla -Wdisabled-optimization -Wempty-body -Wignored-qualifiers
|
||||
-Wimplicit-fallthrough=3 -Wtype-limits -Wshift-negative-value -Wswitch-default
|
||||
-Wframe-larger-than=32768 -Woverloaded-virtual
|
||||
-Wnon-virtual-dtor -Wshift-overflow=2 -Wshift-count-overflow
|
||||
-Wwrite-strings -Wmissing-format-attribute -Wformat-nonliteral
|
||||
-Wdelete-non-virtual-dtor -Wduplicated-cond
|
||||
-Wtrampolines -Wsized-deallocation -Wlogical-op -Wsuggest-attribute=format
|
||||
-Wduplicated-branches
|
||||
-Wmissing-include-dirs -Wformat-signedness
|
||||
-Wreturn-local-addr -Wextra
|
||||
-Wredundant-decls -Wfloat-conversion
|
||||
-Wno-write-strings -Wall -Wno-dangling-else -Wno-comment -Wno-conversion-null -Wno-return-type
|
||||
-Wno-unknown-pragmas -Wno-sign-compare
|
||||
-Wno-error=undef
|
||||
-Wno-error=comment
|
||||
-Wno-error=conversion-null
|
||||
-Wno-error=dangling-else
|
||||
-Wno-error=return-type
|
||||
-Wno-error=shadow
|
||||
-Wno-error=sign-compare
|
||||
-Wno-error=unknown-pragmas
|
||||
-Wno-error=unused-parameter
|
||||
-Wno-error=cast-qual
|
||||
-Wno-error=format=
|
||||
-Wno-error=maybe-uninitialized
|
||||
-Wno-error=missing-field-initializers
|
||||
-Wno-error=redundant-decls
|
||||
-Wno-error=unused-variable
|
||||
$<$<COMPILE_LANGUAGE:C>:-Wnested-externs>
|
||||
$<$<CONFIG:Debug>:-g>
|
||||
$<IF:$<VERSION_GREATER:${CMAKE_C_COMPILER_VERSION},4.8.5>,-fstack-protector-strong,-fstack-protector-all>
|
||||
)
|
||||
target_compile_definitions(intf_pub
|
||||
INTERFACE
|
||||
$<$<COMPILE_LANGUAGE:CXX>:_GLIBCXX_USE_CXX11_ABI=0>
|
||||
$<$<CONFIG:Release>:_FORTIFY_SOURCE=2>
|
||||
)
|
||||
target_link_options(intf_pub
|
||||
INTERFACE
|
||||
$<$<STREQUAL:$<TARGET_PROPERTY:TYPE>,EXECUTABLE>:-pie>
|
||||
$<$<CONFIG:Release>:-s>
|
||||
-Wl,-z,relro
|
||||
-Wl,-z,now
|
||||
-Wl,-z,noexecstack
|
||||
)
|
||||
113
csrc/cmake/modules/Findalog.cmake
Normal file
113
csrc/cmake/modules/Findalog.cmake
Normal file
@@ -0,0 +1,113 @@
|
||||
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
||||
# This file is a part of the CANN Open Software.
|
||||
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# ======================================================================================================================
|
||||
|
||||
if (alog_FOUND)
|
||||
message(STATUS "Package alog has been found.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
set(_cmake_targets_defined "")
|
||||
set(_cmake_targets_not_defined "")
|
||||
set(_cmake_expected_targets "")
|
||||
foreach(_cmake_expected_target IN ITEMS slog alog alog_headers)
|
||||
list(APPEND _cmake_expected_targets "${_cmake_expected_target}")
|
||||
if(TARGET "${_cmake_expected_target}")
|
||||
list(APPEND _cmake_targets_defined "${_cmake_expected_target}")
|
||||
else()
|
||||
list(APPEND _cmake_targets_not_defined "${_cmake_expected_target}")
|
||||
endif()
|
||||
endforeach()
|
||||
unset(_cmake_expected_target)
|
||||
|
||||
if(_cmake_targets_defined STREQUAL _cmake_expected_targets)
|
||||
unset(_cmake_targets_defined)
|
||||
unset(_cmake_targets_not_defined)
|
||||
unset(_cmake_expected_targets)
|
||||
unset(CMAKE_IMPORT_FILE_VERSION)
|
||||
cmake_policy(POP)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT _cmake_targets_defined STREQUAL "")
|
||||
string(REPLACE ";" ", " _cmake_targets_defined_text "${_cmake_targets_defined}")
|
||||
string(REPLACE ";" ", " _cmake_targets_not_defined_text "${_cmake_targets_not_defined}")
|
||||
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_cmake_targets_defined_text}\nTargets not yet defined: ${_cmake_targets_not_defined_text}\n")
|
||||
endif()
|
||||
unset(_cmake_targets_defined)
|
||||
unset(_cmake_targets_not_defined)
|
||||
unset(_cmake_expected_targets)
|
||||
|
||||
find_path(_INCLUDE_DIR
|
||||
NAMES base/alog_pub.h
|
||||
NO_CMAKE_SYSTEM_PATH
|
||||
NO_CMAKE_FIND_ROOT_PATH)
|
||||
|
||||
find_library(slog_SHARED_LIBRARY
|
||||
NAMES libascendalog.so
|
||||
PATH_SUFFIXES lib64
|
||||
NO_CMAKE_SYSTEM_PATH
|
||||
NO_CMAKE_FIND_ROOT_PATH)
|
||||
|
||||
find_library(alog_SHARED_LIBRARY
|
||||
NAMES libascendalog.so
|
||||
PATH_SUFFIXES lib64
|
||||
NO_CMAKE_SYSTEM_PATH
|
||||
NO_CMAKE_FIND_ROOT_PATH)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(alog
|
||||
FOUND_VAR
|
||||
alog_FOUND
|
||||
REQUIRED_VARS
|
||||
_INCLUDE_DIR
|
||||
slog_SHARED_LIBRARY
|
||||
alog_SHARED_LIBRARY
|
||||
)
|
||||
|
||||
if(alog_FOUND)
|
||||
set(alog_INCLUDE_DIR "${_INCLUDE_DIR}")
|
||||
include(CMakePrintHelpers)
|
||||
message(STATUS "Variables in alog module:")
|
||||
cmake_print_variables(alog_INCLUDE_DIR)
|
||||
cmake_print_variables(slog_SHARED_LIBRARY)
|
||||
cmake_print_variables(alog_SHARED_LIBRARY)
|
||||
|
||||
add_library(slog SHARED IMPORTED)
|
||||
set_target_properties(slog PROPERTIES
|
||||
INTERFACE_COMPILE_DEFINITIONS "LOG_CPP;PROCESS_LOG"
|
||||
INTERFACE_LINK_LIBRARIES "alog_headers"
|
||||
IMPORTED_LOCATION "${slog_SHARED_LIBRARY}"
|
||||
)
|
||||
|
||||
add_library(alog SHARED IMPORTED)
|
||||
set_target_properties(alog PROPERTIES
|
||||
INTERFACE_COMPILE_DEFINITIONS "LOG_CPP;PROCESS_LOG"
|
||||
INTERFACE_LINK_LIBRARIES "alog_headers"
|
||||
IMPORTED_LOCATION "${alog_SHARED_LIBRARY}"
|
||||
)
|
||||
|
||||
add_library(alog_headers INTERFACE IMPORTED)
|
||||
set_target_properties(alog_headers PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${alog_INCLUDE_DIR}"
|
||||
)
|
||||
|
||||
include(CMakePrintHelpers)
|
||||
cmake_print_properties(TARGETS slog
|
||||
PROPERTIES INTERFACE_COMPILE_DEFINITIONS INTERFACE_LINK_LIBRARIES IMPORTED_LOCATION
|
||||
)
|
||||
cmake_print_properties(TARGETS alog
|
||||
PROPERTIES INTERFACE_COMPILE_DEFINITIONS INTERFACE_LINK_LIBRARIES IMPORTED_LOCATION
|
||||
)
|
||||
cmake_print_properties(TARGETS alog_headers
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
)
|
||||
endif()
|
||||
|
||||
# Cleanup temporary variables.
|
||||
set(_INCLUDE_DIR)
|
||||
130
csrc/cmake/scripts/prepare.sh
Normal file
130
csrc/cmake/scripts/prepare.sh
Normal file
@@ -0,0 +1,130 @@
|
||||
#!/bin/bash
|
||||
# Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
||||
# This file is a part of the CANN Open Software.
|
||||
# Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
|
||||
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
||||
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
||||
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See LICENSE in the root of the software repository for the full text of the License.
|
||||
# ======================================================================================================================
|
||||
|
||||
CPU_NUM=$(($(cat /proc/cpuinfo | grep "^processor" | wc -l)*2))
|
||||
JOB_NUM="-j${CPU_NUM}"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-s)
|
||||
PATH_TO_SOURCE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-b)
|
||||
PATH_TO_BUILD="$2"
|
||||
shift 2
|
||||
;;
|
||||
-p)
|
||||
ASCEND_CANN_PACKAGE_PATH="$2"
|
||||
shift 2
|
||||
;;
|
||||
--autogen-dir)
|
||||
ASCEND_AUTOGEN_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
--build-open-project)
|
||||
BUILD_OPEN_PROJECT="$2"
|
||||
shift 2
|
||||
;;
|
||||
--binary-out-dir)
|
||||
ASCEND_BINARY_OUT_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
--impl-out-dir)
|
||||
ASCEND_IMPL_OUT_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
--op-build-tool)
|
||||
OP_BUILD_TOOL="$2"
|
||||
shift 2
|
||||
;;
|
||||
--ascend-cmake-dir)
|
||||
ASCEND_CMAKE_DIR="$2"
|
||||
shift 2
|
||||
;;
|
||||
--tiling-key)
|
||||
TILING_KEY="$2"
|
||||
shift 2
|
||||
;;
|
||||
--ops-compile-options)
|
||||
OPS_COMPILE_OPTIONS="$2"
|
||||
shift 2
|
||||
;;
|
||||
--check-compatible)
|
||||
CHECK_COMPATIBLE="$2"
|
||||
shift 2
|
||||
;;
|
||||
--ascend-compute_unit)
|
||||
ASCEND_COMPUTE_UNIT="$2"
|
||||
shift 2
|
||||
;;
|
||||
--ascend-op-name)
|
||||
ASCEND_OP_NAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
--op_debug_config)
|
||||
OP_DEBUG_CONFIG="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
function clean() {
|
||||
if [ -n "${PATH_TO_BUILD}" ];then
|
||||
rm -rf ${PATH_TO_BUILD}
|
||||
mkdir -p ${PATH_TO_BUILD}
|
||||
fi
|
||||
}
|
||||
|
||||
function convert_string() {
|
||||
local _input=$1
|
||||
_output=$(echo $_input | sed 's/::/;/g')
|
||||
echo "${_output}"
|
||||
}
|
||||
|
||||
function set_env() {
|
||||
CONVERT_TILING_KEY="$(convert_string ${TILING_KEY})"
|
||||
|
||||
CONVERT_OPS_COMPILE_OPTIONS="$(convert_string ${OPS_COMPILE_OPTIONS})"
|
||||
|
||||
CONVERT_ASCEND_COMPUTE_UNIT="$(convert_string ${ASCEND_COMPUTE_UNIT})"
|
||||
}
|
||||
|
||||
function build() {
|
||||
cd ${PATH_TO_BUILD}
|
||||
cmake ${PATH_TO_SOURCE} \
|
||||
-DBUILD_OPEN_PROJECT=${BUILD_OPEN_PROJECT} \
|
||||
-DPREPARE_BUILD=ON \
|
||||
-DCUSTOM_ASCEND_CANN_PACKAGE_PATH=${ASCEND_CANN_PACKAGE_PATH} \
|
||||
-DASCEND_AUTOGEN_DIR=${ASCEND_AUTOGEN_DIR} \
|
||||
-DASCEND_BINARY_OUT_DIR=${ASCEND_BINARY_OUT_DIR} \
|
||||
-DASCEND_IMPL_OUT_DIR=${ASCEND_IMPL_OUT_DIR} \
|
||||
-DOP_BUILD_TOOL=${OP_BUILD_TOOL} \
|
||||
-DASCEND_CMAKE_DIR=${ASCEND_CMAKE_DIR} \
|
||||
-DCHECK_COMPATIBLE=${CHECK_COMPATIBLE} \
|
||||
-DTILING_KEY="${CONVERT_TILING_KEY}" \
|
||||
-DOPS_COMPILE_OPTIONS="${CONVERT_OPS_COMPILE_OPTIONS}" \
|
||||
-DASCEND_COMPUTE_UNIT=${CONVERT_ASCEND_COMPUTE_UNIT} \
|
||||
-DOP_DEBUG_CONFIG=${OP_DEBUG_CONFIG} \
|
||||
-DASCEND_OP_NAME=${ASCEND_OP_NAME}
|
||||
|
||||
make ${JOB_NUM} prepare_build
|
||||
}
|
||||
|
||||
function main() {
|
||||
clean
|
||||
set_env
|
||||
build
|
||||
}
|
||||
|
||||
main
|
||||
Reference in New Issue
Block a user