Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions xllm-kernel/csrc/ascendc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,43 @@ set(mega_mtp_host "${CMAKE_CURRENT_SOURCE_DIR}/mega_gdn_mtp_decode/op_host")
set(mega_varlen_host "${CMAKE_CURRENT_SOURCE_DIR}/mega_gdn_mtp_decode_varlen/op_host")
set(qli "${CMAKE_CURRENT_SOURCE_DIR}/quant_lightning_indexer")
set(qli_metadata "${CMAKE_CURRENT_SOURCE_DIR}/quant_lightning_indexer_metadata")
if("ascend910_93" IN_LIST ASCEND_COMPUTE_UNIT)
set(qli_v2 "${CMAKE_CURRENT_SOURCE_DIR}/quant_lightning_indexer_v2_va")
set(qli_v2_metadata "${CMAKE_CURRENT_SOURCE_DIR}/quant_lightning_indexer_v2_metadata_va")
set(qli_sparse_metadata "${CMAKE_CURRENT_SOURCE_DIR}/quant_sparse_lightning_indexer_metadata_va")
list(APPEND op_definitions "${qli_v2}/op_host/quant_lightning_indexer_v2_va_def.cpp")
set(qli_v2_api
"${ASCEND_AUTOGEN_PATH}/aclnn_xllm_kernel_quant_lightning_indexer_v3_va.cpp"
"${qli_v2}/op_host/op_api/aclnn_quant_lightning_indexer_v2_va.cpp"
"${qli_sparse_metadata}/op_host/op_api/aclnn_quant_sparse_lightning_indexer_metadata_va.cpp"
"${qli_sparse_metadata}/op_host/op_api/quant_sparse_lightning_indexer_metadata_va.cpp"
"${qli_v2_metadata}/op_host/op_api/aclnn_quant_lightning_indexer_v2_metadata_va.cpp"
"${qli_v2_metadata}/op_host/op_api/quant_lightning_indexer_v2_metadata_va.cpp"
)
set_property(SOURCE "${qli_v2_metadata}/op_host/op_api/aclnn_quant_lightning_indexer_v2_metadata_va.cpp"
"${qli_sparse_metadata}/op_host/op_api/aclnn_quant_sparse_lightning_indexer_metadata_va.cpp"
APPEND PROPERTY INCLUDE_DIRECTORIES "${ASCEND_CANN_PACKAGE_PATH}/pkg_inc/op_common")
set_property(SOURCE "${qli_v2_metadata}/op_host/op_api/aclnn_quant_lightning_indexer_v2_metadata_va.cpp"
"${qli_sparse_metadata}/op_host/op_api/aclnn_quant_sparse_lightning_indexer_metadata_va.cpp"
APPEND PROPERTY COMPILE_DEFINITIONS OP_LOG_LIBOPAPI_ONLY)
set(qli_v2_tiling
"${qli_v2}/op_host/quant_lightning_indexer_v2_va_infershape.cpp"
"${qli_v2}/op_host/quant_lightning_indexer_v2_va_tiling.cpp"
"${qli_sparse_metadata}/op_host/quant_sparse_lightning_indexer_metadata_va_infershape.cpp"
"${qli_v2_metadata}/op_host/quant_lightning_indexer_v2_metadata_va_infershape.cpp"
)
list(APPEND v41_metadata_graph_sources
"${qli_sparse_metadata}/op_graph/quant_sparse_lightning_indexer_metadata_va_proto.cpp"
"${qli_v2_metadata}/op_graph/quant_lightning_indexer_v2_metadata_va_proto.cpp")
list(APPEND v41_aicpu_components quant_lightning_indexer_v2_metadata_va quant_sparse_lightning_indexer_metadata_va)
list(APPEND v41_aicpu_headers "${qli_v2}/op_kernel/quant_lightning_indexer_v2_metadata_va.h")
install(FILES "${qli_sparse_metadata}/op_host/op_api/aclnn_quant_sparse_lightning_indexer_metadata_va.h"
DESTINATION "packages/vendors/${vendor}/op_api/include"
RENAME aclnn_xllm_kernel_quant_sparse_lightning_indexer_metadata_va.h)
install(FILES "${qli_v2_metadata}/op_host/op_api/aclnn_quant_lightning_indexer_v2_metadata_va.h"
DESTINATION "packages/vendors/${vendor}/op_api/include"
RENAME aclnn_xllm_kernel_quant_lightning_indexer_v2_metadata_va.h)
endif()
set(scatter "${CMAKE_CURRENT_SOURCE_DIR}/scatter_nd_update_v2")
set(sas_metadata "${CMAKE_CURRENT_SOURCE_DIR}/sparse_attn_sharedkv_metadata")
set(sparse_attention_components compressor sparse_attn_sharedkv sparse_flash_attention_lse)
Expand Down Expand Up @@ -111,6 +148,7 @@ if("ascend910b" IN_LIST ASCEND_COMPUTE_UNIT OR "ascend910_93" IN_LIST ASCEND_COM
endif()
# The two quantized projections have device implementations on the A2/A3 targets.
if("ascend910b" IN_LIST ASCEND_COMPUTE_UNIT OR "ascend910_93" IN_LIST ASCEND_COMPUTE_UNIT)
set(router_norm_host "${CMAKE_CURRENT_SOURCE_DIR}/rms_norm_cast_va/op_host")
set(quant_gemm_host "${CMAKE_CURRENT_SOURCE_DIR}/quant_matmul_nz_decode/op_host")
set(mla_host "${CMAKE_CURRENT_SOURCE_DIR}/mla_preprocess_v2/op_host")
set(catlass_include "${xllm_kernel_root}/third_party/catlass/include")
Expand All @@ -119,14 +157,18 @@ if("ascend910b" IN_LIST ASCEND_COMPUTE_UNIT OR "ascend910_93" IN_LIST ASCEND_COM
"In a Git checkout run git submodule update --init xllm-kernel/third_party/catlass.")
endif()
list(APPEND op_definitions
"${router_norm_host}/rms_norm_cast_va_def.cpp"
"${quant_gemm_host}/quant_matmul_nz_decode_def.cpp"
"${mla_host}/mla_preprocess_v2_def.cpp"
)
set(a2_aclnn_sources
"${ASCEND_AUTOGEN_PATH}/aclnn_xllm_kernel_rms_norm_cast_va.cpp"
"${ASCEND_AUTOGEN_PATH}/aclnn_xllm_kernel_quant_matmul_nz_decode.cpp"
"${ASCEND_AUTOGEN_PATH}/aclnn_xllm_kernel_mla_preprocess_v2.cpp"
)
set(a2_tiling_sources
"${router_norm_host}/rms_norm_cast_va_infershape.cpp"
"${router_norm_host}/rms_norm_cast_va_tiling.cpp"
"${quant_gemm_host}/quant_matmul_nz_decode_proto.cpp"
"${quant_gemm_host}/quant_matmul_nz_decode_tiling.cpp"
"${mla_host}/mla_preprocess_tiling.cpp"
Expand Down Expand Up @@ -197,6 +239,7 @@ npu_op_library(cust_opapi ACLNN
"${ASCEND_AUTOGEN_PATH}/aclnn_xllm_kernel_quant_lightning_indexer.cpp"
"${qli_metadata}/op_api/aclnn_quant_lightning_indexer_metadata.cpp"
"${qli_metadata}/op_api/l0_quant_lightning_indexer_metadata.cpp"
${qli_v2_api}
"${scatter}/op_host/op_api/aclnn_scatter_nd_update_v2.cpp"
"${scatter}/op_host/op_api/scatter_nd_update_v2.cpp"
${sparse_attention_api}
Expand All @@ -222,6 +265,7 @@ file(GLOB generated_fallback CONFIGURE_DEPENDS "${ASCEND_AUTOGEN_PATH}/fallback_
npu_op_library(cust_op_proto GRAPH
${generated_proto}
"${qli_metadata}/op_graph/quant_lightning_indexer_metadata_proto.cpp"
${v41_metadata_graph_sources}
"${sas_metadata}/op_graph/sparse_attn_sharedkv_metadata_proto.cpp"
)
npu_op_library(cust_optiling TILING
Expand Down Expand Up @@ -266,6 +310,7 @@ npu_op_library(cust_optiling TILING
"${qli}/op_host/quant_lightning_indexer_infershape.cpp"
"${qli}/op_host/quant_lightning_indexer_tiling.cpp"
"${qli_metadata}/op_host/quant_lightning_indexer_metadata_infershape.cpp"
${qli_v2_tiling}
"${scatter}/op_host/scatter_nd_update_infershape.cpp"
"${scatter}/op_host/scatter_nd_update_v2_tiling.cpp"
${sparse_attention_tiling}
Expand Down Expand Up @@ -405,6 +450,8 @@ if("ascend950" IN_LIST ASCEND_COMPUTE_UNIT)

endif()
if(a2_aclnn_sources)
npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelRmsNormCastVa
KERNEL_DIR rms_norm_cast_va/op_kernel KERNEL_FILE xllm_kernel_rms_norm_cast_va.cpp)
npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelQuantMatmulNzDecode
KERNEL_DIR quant_matmul_nz_decode/op_kernel KERNEL_FILE xllm_kernel_quant_matmul_nz_decode.cpp)
npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelMlaPreprocessV2
Expand All @@ -421,6 +468,14 @@ npu_op_kernel_options(ascendc_kernels XllmKernelQuantLightningIndexer
OPTIONS --cce-auto-sync=off -Wno-deprecated-declarations -Wno-error
-mllvm -cce-vf-remove-membar=false -mllvm -cce-aicore-hoist-movemask=false
"-I${CMAKE_CURRENT_SOURCE_DIR}" "-I${qli}/op_kernel")
if("ascend910_93" IN_LIST ASCEND_COMPUTE_UNIT)
npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelQuantLightningIndexerV3Va
KERNEL_DIR quant_lightning_indexer_v2_va/op_kernel KERNEL_FILE xllm_kernel_quant_lightning_indexer_v3_va.cpp)
npu_op_kernel_options(ascendc_kernels XllmKernelQuantLightningIndexerV3Va
OPTIONS --cce-auto-sync=off -Wno-deprecated-declarations -Werror
-mllvm -cce-vf-remove-membar=false -mllvm -cce-aicore-hoist-movemask=false
"-I${qli_v2}/op_kernel")
endif()
npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelScatterNdUpdateV2
KERNEL_DIR scatter_nd_update_v2/op_kernel KERNEL_FILE xllm_kernel_scatter_nd_update_v2.cpp)
npu_op_kernel_options(ascendc_kernels XllmKernelScatterNdUpdateV2
Expand Down Expand Up @@ -482,3 +537,10 @@ npu_op_kernel_library(ascendc_kernels SRC_BASE "${CMAKE_CURRENT_SOURCE_DIR}" TIL
include("${CMAKE_CURRENT_SOURCE_DIR}/aicpu.cmake")

npu_op_package_add(${vendor} LIBRARY cust_opapi cust_op_proto cust_optiling ascendc_kernels)

if(qli_v2)
# An incremental CANN build may still have the V2 header from before the V3 migration.
install(FILES "${qli_v2}/op_host/op_api/aclnn_quant_lightning_indexer_v2_va.h"
DESTINATION "packages/vendors/${vendor}/op_api/include"
RENAME aclnn_xllm_kernel_quant_lightning_indexer_v2_va.h)
endif()
9 changes: 6 additions & 3 deletions xllm-kernel/csrc/ascendc/aicpu.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ find_library(aicpu_context NAMES libaicpu_context.a
HINTS "${cann}/lib64" "${cann}/ops_base/lib64" NO_DEFAULT_PATH REQUIRED)
find_library(aicpu_protobuf NAMES libbase_ascend_protobuf.a
HINTS "${cann}/lib64" "${cann}/ops_base/lib64" NO_DEFAULT_PATH REQUIRED)
set(aicpu_library "${CMAKE_CURRENT_BINARY_DIR}/libxllm_kernel_aicpu.so")
# CANN 9 selects the custom AICPU library from the vendor suffix.
set(aicpu_library "${CMAKE_CURRENT_BINARY_DIR}/libmath_aicpu_kernels.so")
set(aicpu_config "${CMAKE_CURRENT_BINARY_DIR}/cust_aicpu_kernel.json")
set(aicpu_json "{}")
foreach(component quant_lightning_indexer_metadata sparse_attn_sharedkv_metadata)
set(aicpu_components quant_lightning_indexer_metadata sparse_attn_sharedkv_metadata ${v41_aicpu_components})
foreach(component IN LISTS aicpu_components)
set(directory "${CMAKE_CURRENT_LIST_DIR}/${component}/op_kernel_aicpu")
list(APPEND aicpu_sources "${directory}/${component}_aicpu.cpp")
list(APPEND aicpu_headers "${directory}/${component}_aicpu.h")
Expand Down Expand Up @@ -40,13 +42,14 @@ add_custom_command(
DEPENDS
${aicpu_sources}
${aicpu_headers}
${v41_aicpu_headers}
"${qli_metadata}/op_kernel_aicpu/cpu_context_util.h"
"${CMAKE_CURRENT_LIST_DIR}/sparse_attn_sharedkv/op_kernel/sparse_attn_sharedkv_metadata.h"
"${qli}/op_kernel/quant_lightning_indexer_metadata.h"
"${aicpu_context}" "${aicpu_protobuf}"
VERBATIM
)
add_custom_target(xllm_kernel_aicpu ALL DEPENDS "${aicpu_library}")
set(cpu_destination "packages/vendors/${vendor}/op_impl/cpu")
set(cpu_destination "packages/vendors/${vendor}_math/op_impl/cpu")
install(FILES "${aicpu_library}" DESTINATION "${cpu_destination}/aicpu_kernel/impl")
install(FILES "${aicpu_config}" DESTINATION "${cpu_destination}/config")
Original file line number Diff line number Diff line change
Expand Up @@ -871,17 +871,16 @@ __aicore__ inline void DequantSwigluQuantBase<TEMPLATE_DSQ_ARGS>::DynamicQuant(
for (uint32_t i = 0; i < proDimsx; ++i) {
ComputeReduceMax(tmpUbF32Gate[i * tl_->UbFactorDimy], tl_->UbFactorDimy);
}
// Calc quant: proDimsx * 64 -> proDimsx
// repeatTimes:proDimsx, dstRepStride:1(dtype), srcBlkStride:1,
// srcRepStride:tl_->UbFactorDimy / 64 * 8
WholeReduceMax(tmpUbF32Gate,
tmpUbF32Gate,
MASK_NUM_T32,
proDimsx,
1,
1,
tl_->UbFactorDimy / MASK_NUM_T32 * MASK_BLK_STRIDE,
ReduceOrder::ORDER_ONLY_VALUE);
// Use the actual row stride and keep the reduction within narrow rows.
WholeReduceMax(
tmpUbF32Gate,
tmpUbF32Gate,
tl_->UbFactorDimy < MASK_NUM_T32 ? tl_->UbFactorDimy : MASK_NUM_T32,
proDimsx,
1,
1,
tl_->UbFactorDimy / BLOCK_ELEM,
ReduceOrder::ORDER_ONLY_VALUE);
PipeBarrier<PIPE_V>();
// Calc quant: scaleOut / 127.0
Muls(scaleOut, tmpUbF32Gate, DYNAMIC_QUANT_FACTOR, proDimsx);
Expand Down
Loading
Loading