-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[BugFix]Added the store_kv_block_metadata ascendC operator #11865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,9 +62,9 @@ class StoreKVBlockBase { | |
| AscendC::LocalTensor<T> tokenLocal; | ||
| AscendC::GlobalTensor<T> keyInputGt; | ||
| AscendC::GlobalTensor<T> keyCacheInputGt; | ||
| AscendC::GlobalTensor<uint32_t> groupLenGt; | ||
| AscendC::GlobalTensor<uint32_t> groupKeyIdxGt; | ||
| AscendC::GlobalTensor<uint32_t> groupKeyCacheIdxGt; | ||
| AscendC::GlobalTensor<int32_t> groupLenGt; | ||
| AscendC::GlobalTensor<int32_t> groupKeyIdxGt; | ||
| AscendC::GlobalTensor<int32_t> groupKeyCacheIdxGt; | ||
| AscendC::TBuf<AscendC::TPosition::VECCALC> tokenBuf; | ||
| __aicore__ inline StoreKVBlockBase() {} | ||
|
|
||
|
|
@@ -84,7 +84,6 @@ class StoreKVBlockBase { | |
| numCache = tilingData->numCache; | ||
| groupInfoLen = tilingData->groupInfoLen; | ||
|
|
||
|
|
||
| coreId = AscendC::GetBlockIdx(); | ||
| coreTail = tilingData->coreTail; | ||
| blockNum = AscendC::GetBlockNum(); | ||
|
|
@@ -101,21 +100,21 @@ class StoreKVBlockBase { | |
|
|
||
| keyInputGt.SetGlobalBuffer(reinterpret_cast<__gm__ T*>(keyIn)); | ||
| keyCacheInputGt.SetGlobalBuffer(reinterpret_cast<__gm__ T*>(keyCacheIn)); | ||
| groupLenGt.SetGlobalBuffer(reinterpret_cast<__gm__ uint32_t*>(groupLen)); | ||
| groupKeyIdxGt.SetGlobalBuffer(reinterpret_cast<__gm__ uint32_t*>(groupKeyIdx)); | ||
| groupKeyCacheIdxGt.SetGlobalBuffer(reinterpret_cast<__gm__ uint32_t*>(groupKeyCacheIdx)); | ||
| groupLenGt.SetGlobalBuffer(reinterpret_cast<__gm__ int32_t*>(groupLen)); | ||
| groupKeyIdxGt.SetGlobalBuffer(reinterpret_cast<__gm__ int32_t*>(groupKeyIdx)); | ||
| groupKeyCacheIdxGt.SetGlobalBuffer(reinterpret_cast<__gm__ int32_t*>(groupKeyCacheIdx)); | ||
|
|
||
| pipeThis->InitBuffer(tokenBuf, blockTableSize*tokenByteSize); | ||
| tokenLocal = tokenBuf.Get<T>(); | ||
|
|
||
| AscendC::DataCopyExtParams copyParams{1, 0, 0, 0, 0}; // todo: full block length | ||
| AscendC::DataCopyPadExtParams<T> padParams{false, 0, 0, 0}; | ||
| for (uint32_t i = 0; i < corePerNum; i++) { | ||
| uint32_t idx = (coreId+i*blockNum); | ||
| for (int32_t i = 0; i < corePerNum; i++) { | ||
| int32_t idx = (coreId+i*blockNum); | ||
|
|
||
| // if( groupLenGt.GetValue(idx)<= 0 || groupKeyIdxGt.GetValue(idx)<0 || groupKeyCacheIdxGt.GetValue(idx)<0){ | ||
| // continue; | ||
| // } | ||
| if( groupLenGt.GetValue(idx)<= 0 || groupKeyIdxGt.GetValue(idx)<0 || groupKeyCacheIdxGt.GetValue(idx)<0){ | ||
| continue; | ||
| } | ||
|
Comment on lines
+115
to
+117
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Ascend C, |
||
|
|
||
| copyParams.blockLen = groupLenGt.GetValue(idx)*tokenByteSize; // in bytes | ||
| DataCopyPad(tokenLocal, keyInputGt[ groupKeyIdxGt.GetValue(idx)*tokenSize], copyParams, padParams); // note: offset order | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| # --------------------------------------------------------------------------------------------------------- | ||
| # 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 should 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. | ||
| # --------------------------------------------------------------------------------------------------------- | ||
| add_modules_sources_aicpu(OPTYPE store_kv_block ACLNNTYPE aclnn) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /** | ||
| * 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 should 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 aclnn_store_kv_block_metadata.cpp | ||
| * \brief AClnn interface for StoreKvBlockMetadata operator | ||
| */ | ||
|
|
||
| #include "aclnn_store_kv_block_metadata.h" | ||
| #include "l0_store_kv_block_metadata.h" | ||
| #include "aclnn_kernels/contiguous.h" | ||
| #include "aclnn_kernels/reshape.h" | ||
| #include "aclnn/aclnn_base.h" | ||
| #include "aclnn_kernels/common/op_error_check.h" | ||
| #include "opdev/common_types.h" | ||
| #include "opdev/data_type_utils.h" | ||
| #include "opdev/format_utils.h" | ||
| #include "opdev/op_dfx.h" | ||
| #include "opdev/op_executor.h" | ||
| #include "opdev/op_log.h" | ||
| #include "opdev/tensor_view_utils.h" | ||
| #include "opdev/make_op_executor.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| aclnnStatus aclnnStoreKvBlockMetadataGetWorkspaceSize( | ||
| const aclTensor *slotMapping, | ||
| const aclTensor *groupLen, | ||
| const aclTensor *groupKeyIdx, | ||
| const aclTensor *groupKeyCacheIdx, | ||
| int64_t blockSize, | ||
| uint64_t *workspaceSize, | ||
| aclOpExecutor **executor) | ||
| { | ||
| L2_DFX_PHASE_1(aclnnStoreKvBlockMetadata, | ||
| DFX_IN(slotMapping, blockSize), | ||
| DFX_OUT(groupLen, groupKeyIdx, groupKeyCacheIdx)); | ||
|
|
||
| auto uniqueExecutor = CREATE_EXECUTOR(); | ||
| CHECK_RET(uniqueExecutor.get() != nullptr, ACLNN_ERR_INNER_CREATE_EXECUTOR); | ||
|
|
||
| // basic parameter checks | ||
| CHECK_RET(slotMapping != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| CHECK_RET(groupLen != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| CHECK_RET(groupKeyIdx != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| CHECK_RET(groupKeyCacheIdx != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
| CHECK_RET(blockSize > 0, ACLNN_ERR_PARAM_INVALID); | ||
|
|
||
| auto slotMappingContiguous = l0op::Contiguous(slotMapping, uniqueExecutor.get()); | ||
| CHECK_RET(slotMappingContiguous != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
|
|
||
| auto ret = l0op::StoreKvBlockMetadata(slotMappingContiguous, groupLen, groupKeyIdx, groupKeyCacheIdx,blockSize, | ||
| uniqueExecutor.get()); | ||
| CHECK_RET(ret != nullptr, ACLNN_ERR_INNER_NULLPTR); | ||
|
|
||
| *workspaceSize = 0; | ||
| uniqueExecutor.ReleaseTo(executor); | ||
| return ACLNN_SUCCESS; | ||
| } | ||
|
|
||
| __attribute__((visibility("default"))) aclnnStatus aclnnStoreKvBlockMetadata(void *workspace, uint64_t workspaceSize, | ||
| aclOpExecutor *executor, aclrtStream stream) | ||
| { | ||
| L2_DFX_PHASE_2(aclnnStoreKvBlockMetadata); | ||
| return CommonOpExecutorRun(workspace, workspaceSize, executor, stream); | ||
| } | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * 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 should 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. | ||
| */ | ||
|
|
||
| #ifndef ACLNN_STORE_KV_BLOCK_METADATA_H | ||
| #define ACLNN_STORE_KV_BLOCK_METADATA_H | ||
|
|
||
| #include "aclnn/aclnn_base.h" | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| __attribute__((visibility("default"))) aclnnStatus aclnnStoreKvBlockMetadataGetWorkspaceSize( | ||
| const aclTensor *slotMapping, | ||
| const aclTensor *groupLen, | ||
| const aclTensor *groupKeyIdx, | ||
| const aclTensor *groupKeyCacheIdx, | ||
| int64_t blockSize, | ||
| uint64_t *workspaceSize, | ||
| aclOpExecutor **executor); | ||
|
|
||
| __attribute__((visibility("default"))) aclnnStatus aclnnStoreKvBlockMetadata(void *workspace, uint64_t workspaceSize, | ||
| aclOpExecutor *executor, aclrtStream stream); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
|
|
||
| #endif // ACLNN_STORE_KV_BLOCK_METADATA_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
params.coreNumis used here, butcoreNumis not a member of theStoreKVBlockParamsstruct. This will cause a compilation failure. Please use the correct local variable or platform API to retrieve the core count.