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
2 changes: 1 addition & 1 deletion xllm-kernel/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2026 The xLLM Authors. Licensed under Apache-2.0.
recursive-include csrc *.cpp *.h
recursive-include csrc/ascendc CMakeLists.txt *.cmake *.txt *.hpp *.inc
recursive-include csrc/ascendc CMakeLists.txt *.cmake *.txt *.hpp *.inc *.json
recursive-include third_party/catlass/include *.h *.hpp
include third_party/catlass/LICENSE
recursive-include third_party/pto-isa/include *.h *.hpp *.inc
Expand Down
36 changes: 35 additions & 1 deletion xllm-kernel/csrc/ascendc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ set(mega_prefill_host "${CMAKE_CURRENT_SOURCE_DIR}/mega_gdn_prefill_op/op_host")
set(mega_decode_host "${CMAKE_CURRENT_SOURCE_DIR}/mega_gdn_decode/op_host")
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")
set(scatter "${CMAKE_CURRENT_SOURCE_DIR}/scatter_nd_update_v2")
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 @@ -63,6 +66,8 @@ list(APPEND op_definitions
"${mega_prefill_host}/mega_gdn_prefill_op_def.cpp"
"${mega_decode_host}/mega_gdn_decode_def.cpp"
"${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"
)
if("ascend910b" IN_LIST ASCEND_COMPUTE_UNIT OR "ascend910_93" IN_LIST ASCEND_COMPUTE_UNIT)
list(APPEND op_definitions
Expand Down Expand Up @@ -146,10 +151,16 @@ npu_op_library(cust_opapi ACLNN
"${ASCEND_AUTOGEN_PATH}/aclnn_xllm_kernel_mega_gdn_decode.cpp"
"${ASCEND_AUTOGEN_PATH}/aclnn_xllm_kernel_mega_gdn_mtp_decode.cpp"
${mega_varlen_api}
"${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"
"${scatter}/op_host/op_api/aclnn_scatter_nd_update_v2.cpp"
"${scatter}/op_host/op_api/scatter_nd_update_v2.cpp"
${a2_aclnn_sources}
)
target_include_directories(cust_opapi PRIVATE
"${ASCEND_CANN_PACKAGE_PATH}/include/aclnn"
"${ASCEND_CANN_PACKAGE_PATH}/pkg_inc/aicpu"
"${ASCEND_AUTOGEN_PATH}"
)
target_link_libraries(cust_opapi PRIVATE
Expand All @@ -159,7 +170,10 @@ target_link_libraries(cust_opapi PRIVATE

set(generated_proto "${ASCEND_AUTOGEN_PATH}/op_proto.cc")
file(GLOB generated_fallback CONFIGURE_DEPENDS "${ASCEND_AUTOGEN_PATH}/fallback_*.cpp")
npu_op_library(cust_op_proto GRAPH ${generated_proto})
npu_op_library(cust_op_proto GRAPH
${generated_proto}
"${qli_metadata}/op_graph/quant_lightning_indexer_metadata_proto.cpp"
)
npu_op_library(cust_optiling TILING
${op_definitions}
"${gamma_host}/gamma_add_rms_norm_infershape.cpp"
Expand Down Expand Up @@ -199,6 +213,11 @@ npu_op_library(cust_optiling TILING
"${mega_mtp_host}/mega_gdn_mtp_decode_tiling.cpp"
"${mega_mtp_host}/mega_gdn_mtp_decode_proto.cpp"
${mega_varlen_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"
"${scatter}/op_host/scatter_nd_update_infershape.cpp"
"${scatter}/op_host/scatter_nd_update_v2_tiling.cpp"
${a2_tiling_sources}
${generated_fallback}
)
Expand All @@ -208,6 +227,7 @@ foreach(target cust_optiling cust_op_proto)
endforeach()
target_include_directories(cust_optiling PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}"
"${qli}/op_host"
"${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 @@ -333,5 +353,19 @@ if(a2_aclnn_sources)
npu_op_kernel_options(ascendc_kernels XllmKernelMlaPreprocessV2
OPTIONS --cce-auto-sync=off -Wno-deprecated-declarations -Werror)
endif()
npu_op_kernel_sources(ascendc_kernels OP_TYPE XllmKernelQuantLightningIndexer
KERNEL_DIR quant_lightning_indexer/op_kernel KERNEL_FILE xllm_kernel_quant_lightning_indexer.cpp)
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")
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
OPTIONS --cce-auto-sync=on -Wno-deprecated-declarations -Wno-error)

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

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

npu_op_package_add(${vendor} LIBRARY cust_opapi cust_op_proto cust_optiling ascendc_kernels)
7 changes: 7 additions & 0 deletions xllm-kernel/csrc/ascendc/quant_lightning_indexer/SOURCE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
QuantLightningIndexer CANN implementation

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

Packaged under a private CANN operator type and ACLNN entry points.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
 * Copyright (c) 2025 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under
the terms and conditions of  * CANN Open Software License Agreement Version 2.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.  */

/*!
* \file ops_err.h
* \brief
*/

#ifndef Xllm_COMMON_OPS_ERR_H
#define Xllm_COMMON_OPS_ERR_H

#include "log/log.h"

#ifndef XLLM_OP_MODULE_ID
#if defined(OP)
#define XLLM_OP_MODULE_ID OP
#else
// CANN 9.1 中 OP_MODULE_ID 为 log.h 内 constexpr,9.0
// 中不存在;统一回退固定模块 ID 63(仅影响日志过滤,不影响功能)
#define XLLM_OP_MODULE_ID 63
#endif
#endif

#define OPS_INNER_ERR_STUB(ERR_CODE_STR, OPS_DESC, FMT, ...) \
do { \
OpLogSub(XLLM_OP_MODULE_ID, DLOG_ERROR, OPS_DESC, FMT, ##__VA_ARGS__); \
REPORT_INNER_ERR_MSG(ERR_CODE_STR, FMT, ##__VA_ARGS__); \
} while (0)

/* 基础报错 */
#define OPS_REPORT_VECTOR_INNER_ERR(OPS_DESC, ...) \
OPS_INNER_ERR_STUB("E89999", OPS_DESC, __VA_ARGS__)
#define OPS_REPORT_CUBE_INNER_ERR(OPS_DESC, ...) \
OPS_INNER_ERR_STUB("E69999", OPS_DESC, __VA_ARGS__)

#endif // Xllm_COMMON_OPS_ERR_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/**
 * Copyright (c) 2026 Huawei Technologies Co., Ltd.
 * This program is free software, you can redistribute it and/or modify it under
the terms and conditions of  * CANN Open Software License Agreement Version 2.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.  */

/*!
* \file quant_lightning_indexer_def.cpp
* \brief
*/

#include "register/op_def_registry.h"

namespace ops {
class XllmKernelQuantLightningIndexer : public OpDef {
public:
explicit XllmKernelQuantLightningIndexer(const char* name) : OpDef(name) {
this->Input("query")
.ParamType(REQUIRED)
.DataType({ge::DT_INT8})
.Format({ge::FORMAT_ND})
.AutoContiguous();
this->Input("key")
.ParamType(REQUIRED)
.DataType({ge::DT_INT8})
.Format({ge::FORMAT_ND})
.IgnoreContiguous();
this->Input("weights")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16})
.Format({ge::FORMAT_ND})
.AutoContiguous();
this->Input("query_dequant_scale")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16})
.Format({ge::FORMAT_ND})
.AutoContiguous();
this->Input("key_dequant_scale")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT16})
.Format({ge::FORMAT_ND})
.IgnoreContiguous();
this->Input("actual_seq_lengths_query")
.ParamType(OPTIONAL)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND})
.AutoContiguous();
this->Input("actual_seq_lengths_key")
.ParamType(OPTIONAL)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND})
.AutoContiguous();
this->Input("block_table")
.ParamType(OPTIONAL)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND})
.AutoContiguous();
this->Input("metadata")
.ParamType(OPTIONAL)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND})
.AutoContiguous();
this->Output("sparse_indices")
.ParamType(REQUIRED)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND});
this->Output("sparse_values")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT})
.Format({ge::FORMAT_ND});
this->Attr("query_quant_mode")
.AttrType(REQUIRED)
.Int(0); // 0: 默认值,per-token-head
this->Attr("key_quant_mode")
.AttrType(REQUIRED)
.Int(0); // 0: 默认值,per-token-head
this->Attr("layout_query").AttrType(OPTIONAL).String("BSND");
this->Attr("layout_key").AttrType(OPTIONAL).String("BSND");
this->Attr("sparse_count")
.AttrType(OPTIONAL)
.Int(2048); // 2048: 默认值,筛选前2048
this->Attr("sparse_mode")
.AttrType(OPTIONAL)
.Int(3); // 3: 默认值,只计算下三角
this->Attr("pre_tokens")
.AttrType(OPTIONAL)
.Int(
9223372036854775807); // 9223372036854775807: 默认值,int64的最大值
this->Attr("next_tokens")
.AttrType(OPTIONAL)
.Int(
9223372036854775807); // 9223372036854775807: 默认值,int64的最大值
this->Attr("cmp_ratio").AttrType(OPTIONAL).Int(1); // 1: 压缩率
this->Attr("return_values")
.AttrType(OPTIONAL)
.Bool(false); // 是否返回sparse_values
this->Attr("stride").AttrType(OPTIONAL).Int(1); // stride参数
this->Attr("scale_stride").AttrType(OPTIONAL).Int(1); // scaleStride参数
OpAICoreConfig aicore_config;
aicore_config.DynamicCompileStaticFlag(true)
.DynamicFormatFlag(true)
.DynamicRankSupportFlag(true)
.DynamicShapeSupportFlag(true)
.NeedCheckSupportFlag(false)
.PrecisionReduceFlag(true);
this->AICore().AddConfig("ascend910b", aicore_config);
this->AICore().AddConfig("ascend910_93", aicore_config);

OpAICoreConfig aicore_config_95;
aicore_config_95.Input("query")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT8_E4M3FN})
.Format({ge::FORMAT_ND})
.AutoContiguous();
aicore_config_95.Input("key")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT8_E4M3FN})
.Format({ge::FORMAT_ND})
.AutoContiguous();
aicore_config_95.Input("weights")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT})
.Format({ge::FORMAT_ND})
.AutoContiguous();
aicore_config_95.Input("query_dequant_scale")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT})
.Format({ge::FORMAT_ND})
.AutoContiguous();
aicore_config_95.Input("key_dequant_scale")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT})
.Format({ge::FORMAT_ND})
.AutoContiguous();
aicore_config_95.Input("actual_seq_lengths_query")
.ParamType(OPTIONAL)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND})
.AutoContiguous();
aicore_config_95.Input("actual_seq_lengths_key")
.ParamType(OPTIONAL)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND})
.AutoContiguous();
aicore_config_95.Input("block_table")
.ParamType(OPTIONAL)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND})
.AutoContiguous();
aicore_config_95.Input("metadata")
.ParamType(OPTIONAL)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND})
.AutoContiguous();
aicore_config_95.Output("sparse_indices")
.ParamType(REQUIRED)
.DataType({ge::DT_INT32})
.Format({ge::FORMAT_ND});
aicore_config_95.Output("sparse_values")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT})
.Format({ge::FORMAT_ND});
aicore_config_95.DynamicCompileStaticFlag(true)
.DynamicFormatFlag(true)
.DynamicRankSupportFlag(true)
.DynamicShapeSupportFlag(true)
.NeedCheckSupportFlag(false)
.PrecisionReduceFlag(true)
.ExtendCfgInfo("aclnnSupport.value", "support_aclnn")
.ExtendCfgInfo("opFile.value", "xllm_kernel_quant_lightning_indexer")
.ExtendCfgInfo("jitCompile.flag", "static_false,dynamic_false");
this->AICore().AddConfig("ascend950", aicore_config_95);
}
};
OP_ADD(XllmKernelQuantLightningIndexer);
} // namespace ops
Loading
Loading