Skip to content
Merged
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
154 changes: 0 additions & 154 deletions tests/python/test_sparse_attention_dispatch.py

This file was deleted.

40 changes: 39 additions & 1 deletion xllm-kernel/csrc/ascendc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ set(mega_varlen_host "${CMAKE_CURRENT_SOURCE_DIR}/mega_gdn_mtp_decode_varlen/op_
set(qli "${CMAKE_CURRENT_SOURCE_DIR}/quant_lightning_indexer")
set(qli_metadata "${CMAKE_CURRENT_SOURCE_DIR}/quant_lightning_indexer_metadata")
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)
foreach(component IN LISTS sparse_attention_components)
set(host "${CMAKE_CURRENT_SOURCE_DIR}/${component}/op_host")
list(APPEND sparse_attention_definitions "${host}/${component}_def.cpp")
list(APPEND sparse_attention_tiling "${host}/${component}_tiling.cpp")
endforeach()
set(pto_include "${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/pto-isa/include")
if(NOT EXISTS "${pto_include}/pto/pto-inst.hpp")
message(FATAL_ERROR "MegaChunkGdn needs PTO headers. "
Expand All @@ -68,6 +75,7 @@ list(APPEND op_definitions
"${mega_mtp_host}/mega_gdn_mtp_decode_def.cpp"
"${qli}/op_host/quant_lightning_indexer_def.cpp"
"${scatter}/op_host/scatter_nd_update_v2_def.cpp"
${sparse_attention_definitions}
)
if("ascend910b" IN_LIST ASCEND_COMPUTE_UNIT OR "ascend910_93" IN_LIST ASCEND_COMPUTE_UNIT)
list(APPEND op_definitions
Expand Down Expand Up @@ -128,6 +136,9 @@ npu_op_code_gen(
PACKAGE ${vendor}
OUT_DIR "${ASCEND_AUTOGEN_PATH}"
)
foreach(component IN LISTS sparse_attention_components)
list(APPEND sparse_attention_api "${ASCEND_AUTOGEN_PATH}/aclnn_xllm_kernel_${component}.cpp")
endforeach()
npu_op_library(cust_opapi ACLNN
"${gamma_host}/op_api/aclnn_gamma_add_rms_norm.cpp"
"${gamma_host}/op_api/gamma_add_rms_norm.cpp"
Expand Down Expand Up @@ -156,6 +167,9 @@ npu_op_library(cust_opapi ACLNN
"${qli_metadata}/op_api/l0_quant_lightning_indexer_metadata.cpp"
"${scatter}/op_host/op_api/aclnn_scatter_nd_update_v2.cpp"
"${scatter}/op_host/op_api/scatter_nd_update_v2.cpp"
${sparse_attention_api}
"${sas_metadata}/op_api/aclnn_sparse_attn_sharedkv_metadata.cpp"
"${sas_metadata}/op_api/l0_sparse_attn_sharedkv_metadata.cpp"
${a2_aclnn_sources}
)
target_include_directories(cust_opapi PRIVATE
Expand All @@ -173,6 +187,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"
"${sas_metadata}/op_graph/sparse_attn_sharedkv_metadata_proto.cpp"
)
npu_op_library(cust_optiling TILING
${op_definitions}
Expand Down Expand Up @@ -218,6 +233,11 @@ npu_op_library(cust_optiling TILING
"${qli_metadata}/op_host/quant_lightning_indexer_metadata_infershape.cpp"
"${scatter}/op_host/scatter_nd_update_infershape.cpp"
"${scatter}/op_host/scatter_nd_update_v2_tiling.cpp"
${sparse_attention_tiling}
"${CMAKE_CURRENT_SOURCE_DIR}/compressor/op_host/compressor_proto.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/sparse_attn_sharedkv/op_host/sparse_attn_sharedkv_proto.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/sparse_flash_attention_lse/op_host/sparse_flash_attention_lse_infershape.cpp"
"${sas_metadata}/op_host/sparse_attn_sharedkv_metadata_infershape.cpp"
${a2_tiling_sources}
${generated_fallback}
)
Expand All @@ -228,6 +248,7 @@ endforeach()
target_include_directories(cust_optiling PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${qli}/op_host"
"${ASCEND_CANN_PACKAGE_PATH}/pkg_inc"
"${ASCEND_CANN_PACKAGE_PATH}/include/op_common/op_host"
)
target_link_libraries(cust_optiling PRIVATE "${ASCEND_CANN_PACKAGE_PATH}/lib64/libascendalog.so")
Expand Down Expand Up @@ -364,8 +385,25 @@ npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelScatterNdUpdateV2
npu_op_kernel_options(ascendc_kernels XllmKernelScatterNdUpdateV2
OPTIONS --cce-auto-sync=on -Wno-deprecated-declarations -Wno-error)

npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelCompressor
KERNEL_DIR compressor/op_kernel KERNEL_FILE xllm_kernel_compressor.cpp)
npu_op_kernel_options(ascendc_kernels XllmKernelCompressor
OPTIONS --cce-auto-sync=off -Wno-deprecated-declarations -Wno-error
-mllvm -cce-aicore-hoist-movemask=false --op_relocatable_kernel_binary=true
"-I${CMAKE_CURRENT_SOURCE_DIR}" "-I${CMAKE_CURRENT_SOURCE_DIR}/compressor/op_kernel")
npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelSparseAttnSharedkv
KERNEL_DIR sparse_attn_sharedkv/op_kernel KERNEL_FILE xllm_kernel_sparse_attn_sharedkv.cpp)
npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelSparseFlashAttentionLse
KERNEL_DIR sparse_flash_attention_lse/op_kernel KERNEL_FILE xllm_kernel_sparse_flash_attention_lse.cpp)
foreach(op_type XllmKernelSparseAttnSharedkv XllmKernelSparseFlashAttentionLse)
npu_op_kernel_options(ascendc_kernels ${op_type}
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}")
endforeach()

npu_op_kernel_library(ascendc_kernels SRC_BASE "${CMAKE_CURRENT_SOURCE_DIR}" TILING_LIBRARY cust_optiling)

include("${qli_metadata}/aicpu.cmake")
include("${CMAKE_CURRENT_SOURCE_DIR}/aicpu.cmake")

npu_op_package_add(${vendor} LIBRARY cust_opapi cust_op_proto cust_optiling ascendc_kernels)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright 2026 The xLLM Authors. Licensed under Apache-2.0.

set(aicpu "${CMAKE_CURRENT_LIST_DIR}/op_kernel_aicpu")
set(cann "${ASCEND_CANN_PACKAGE_PATH}")
find_program(aicpu_cxx NAMES aarch64-target-linux-gnu-g++
HINTS "${cann}/toolkit/toolchain/hcc/bin" "${cann}/toolchain/hcc/bin"
Expand All @@ -9,30 +8,45 @@ 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(qli_aicpu_library "${CMAKE_CURRENT_BINARY_DIR}/libxllm_kernel_aicpu.so")
set(aicpu_library "${CMAKE_CURRENT_BINARY_DIR}/libxllm_kernel_aicpu.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(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")
set(config "${directory}/${component}_aicpu.json")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${config}")
file(READ "${config}" component_json)
string(JSON operator MEMBER "${component_json}" 0)
string(JSON definition GET "${component_json}" "${operator}")
string(JSON aicpu_json SET "${aicpu_json}" "${operator}" "${definition}")
endforeach()
file(GENERATE OUTPUT "${aicpu_config}" CONTENT "${aicpu_json}\n")

add_custom_command(
OUTPUT "${qli_aicpu_library}"
OUTPUT "${aicpu_library}"
COMMAND "${aicpu_cxx}" -std=c++17 -O2 -shared -fPIC -fvisibility=hidden
-fvisibility-inlines-hidden -fstack-protector-all
-Dgoogle=ascend_private -DDISABLE_COMPILE_V1 -D_FORTIFY_SOURCE=2 -D_GLIBCXX_USE_CXX11_ABI=1
"-I${CMAKE_CURRENT_SOURCE_DIR}"
"-I${cann}/include" "-I${cann}/include/aicpu" "-I${cann}/pkg_inc" "-I${cann}/pkg_inc/base"
"-I${cann}/pkg_inc/aicpu_common/context/common" "-I${cann}/pkg_inc/aicpu_common/context/cpu_proto"
"-I${cann}/pkg_inc/aicpu_common/context/utils"
"${aicpu}/quant_lightning_indexer_metadata_aicpu.cpp"
${aicpu_sources}
-Wl,--whole-archive "${aicpu_context}" "${aicpu_protobuf}" -Wl,--no-whole-archive
-Wl,-Bsymbolic -Wl,--exclude-libs=libbase_ascend_protobuf.a
-o "${qli_aicpu_library}"
-o "${aicpu_library}"
DEPENDS
"${aicpu}/quant_lightning_indexer_metadata_aicpu.cpp"
"${aicpu}/quant_lightning_indexer_metadata_aicpu.h"
"${aicpu}/cpu_context_util.h"
${aicpu_sources}
${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 "${qli_aicpu_library}")
add_custom_target(xllm_kernel_aicpu ALL DEPENDS "${aicpu_library}")
set(cpu_destination "packages/vendors/${vendor}/op_impl/cpu")
install(FILES "${qli_aicpu_library}" DESTINATION "${cpu_destination}/aicpu_kernel/impl")
install(FILES "${aicpu}/quant_lightning_indexer_metadata_aicpu.json"
DESTINATION "${cpu_destination}/config" RENAME cust_aicpu_kernel.json)
install(FILES "${aicpu_library}" DESTINATION "${cpu_destination}/aicpu_kernel/impl")
install(FILES "${aicpu_config}" DESTINATION "${cpu_destination}/config")
7 changes: 7 additions & 0 deletions xllm-kernel/csrc/ascendc/compressor/SOURCE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Compressor CANN implementation

Source: https://gitcode.com/xLLM-AI/xllm_ops
Revision: 8bd2b014c38fec33ecf14dd33e05e8ad792ec5c8
Directory: xllm_ops/attention/compressor

Packaged under a private CANN operator type and ACLNN entry points.
Loading
Loading