Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/CMakeLists.txt +20 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/README.md +99 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/docs/aclnnInterleaveRope.md +421 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/examples/aclnn_interleave_rope.h +58 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/examples/test_aclnn_interleave_rope.cpp +185 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/interleave_rope_collect.py +162 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/interleave_rope_test.py +220 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_graph/CMakeLists.txt +12 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_graph/fusion_pass/.gitkeep +0 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_graph/interleave_rope_proto.h +45 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/CMakeLists.txt +30 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/ascend910_93/interleave_rope_binary.json +99 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/ascend910_93/interleave_rope_simplified_key.ini +13 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/ascend910b/interleave_rope_binary.json +99 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/ascend910b/interleave_rope_simplified_key.ini +13 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/kirin9030/interleave_rope_binary.json +52 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/kirin9030/interleave_rope_simplified_key.ini +13 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/kirinx90/interleave_rope_binary.json +52 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/kirinx90/interleave_rope_simplified_key.ini +13 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/interleave_rope_def.cpp +93 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/interleave_rope_infershape.cpp +57 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/interleave_rope_tiling.cpp +359 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/interleave_rope_tiling.h +104 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/op_api/aclnn_interleave_rope.cpp +52 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/op_api/aclnn_interleave_rope.h +58 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/op_api/aclnn_rotary_position_embedding.h +58 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_kernel/interleave_rope.cpp +50 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_kernel/interleave_rope_b11d.h +204 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_kernel/interleave_rope_b1sd.h +205 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_kernel/interleave_rope_fixed_bnsd_b11d.h +188 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_kernel/interleave_rope_split_s.h +249 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/test_data/cases_manifest.json +139 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/CMakeLists.txt +17 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/CMakeLists.txt +17 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/CMakeLists.txt +21 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/op_api/CMakeLists.txt +15 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/op_api/test_aclnn_interleave_rope.cpp +48 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/test_interleave_rope_infershape.cpp +92 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/test_interleave_rope_tiling.cpp +220 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_kernel/CMakeLists.txt +31 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_kernel/test_interleave_rope.cpp +148 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_kernel/test_interleave_rope.h +61 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/CMakeLists.txt +19 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/README.md +302 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/docs/aclnnQkvRmsNormRopeCache.md +724 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/examples/test_aclnn_qkv_rms_norm_rope_cache.cpp +239 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/op_graph/CMakeLists.txt +11 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/op_graph/qkv_rms_norm_rope_cache_proto.h +121 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/op_host/CMakeLists.txt +28 -0
- datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/op_host/config/ascend910_93/qkv_rms_norm_rope_cache_binary.json +1949 -0
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/CMakeLists.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 2 |
+
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
# CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
message(STATUS "=== Debug: start ops.posembedding.interleave_rope.CMakeLists.txt ")
|
| 12 |
+
file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
|
| 13 |
+
if(NOT ENABLE_TEST AND NOT BENCHMARK)
|
| 14 |
+
list(REMOVE_ITEM CURRENT_DIRS tests)
|
| 15 |
+
endif()
|
| 16 |
+
foreach(SUB_DIR ${CURRENT_DIRS})
|
| 17 |
+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
|
| 18 |
+
add_subdirectory(${SUB_DIR})
|
| 19 |
+
endif()
|
| 20 |
+
endforeach()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# InterleaveRope
|
| 2 |
+
|
| 3 |
+
## 产品支持情况
|
| 4 |
+
|
| 5 |
+
|产品 | 是否支持 |
|
| 6 |
+
|:-------------------------|:----------:|
|
| 7 |
+
| <term>Ascend 950PR/Ascend 950DT</term> | × |
|
| 8 |
+
| <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ |
|
| 9 |
+
| <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | √ |
|
| 10 |
+
| <term>Kirin X90 处理器系列产品</term> | √ |
|
| 11 |
+
| <term>Kirin 9030 处理器系列产品</term> | √ |
|
| 12 |
+
|
| 13 |
+
## 功能说明
|
| 14 |
+
|
| 15 |
+
- 算子功能:针对单输入x进行旋转位置编码。
|
| 16 |
+
- 计算公式:
|
| 17 |
+
$$
|
| 18 |
+
q = \text{reshape}(x, [B, N, S, D//2, 2]) \cdot \text{transpose}(-1, -2) \cdot \text{reshape}([B, N, S, D])
|
| 19 |
+
$$
|
| 20 |
+
|
| 21 |
+
$$
|
| 22 |
+
q_{\text{embed}} = q \cdot \text{cos} + \text{RotateHalf}(q) \cdot \sin
|
| 23 |
+
$$
|
| 24 |
+
|
| 25 |
+
其中:RotateHalf(q)表示将q的D维后半部分元素移至前半部分并乘以 -1,后半部分用前半部分的值。
|
| 26 |
+
|
| 27 |
+
$$
|
| 28 |
+
\text{RotateHalf}(q)_{\text{i}} =
|
| 29 |
+
\begin{cases}
|
| 30 |
+
-q_{i+D//2} & \text{if } i < D//2 \\
|
| 31 |
+
q_{i-D//2} & \text{otherwise}
|
| 32 |
+
\end{cases}
|
| 33 |
+
$$
|
| 34 |
+
|
| 35 |
+
## 参数说明
|
| 36 |
+
|
| 37 |
+
<table style="undefined;table-layout: fixed; width: 1576px"><colgroup>
|
| 38 |
+
<col style="width: 170px">
|
| 39 |
+
<col style="width: 170px">
|
| 40 |
+
<col style="width: 312px">
|
| 41 |
+
<col style="width: 213px">
|
| 42 |
+
<col style="width: 100px">
|
| 43 |
+
</colgroup>
|
| 44 |
+
<thead>
|
| 45 |
+
<tr>
|
| 46 |
+
<th>参数名</th>
|
| 47 |
+
<th>输入/输出/属性</th>
|
| 48 |
+
<th>描述</th>
|
| 49 |
+
<th>数据类型</th>
|
| 50 |
+
<th>数据格式</th>
|
| 51 |
+
</tr></thead>
|
| 52 |
+
<tbody>
|
| 53 |
+
<tr>
|
| 54 |
+
<td>x</td>
|
| 55 |
+
<td>输入</td>
|
| 56 |
+
<td>表示待处理张量,对应公式中的x。</td>
|
| 57 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 58 |
+
<td>ND</td>
|
| 59 |
+
</tr>
|
| 60 |
+
<tr>
|
| 61 |
+
<td>cos</td>
|
| 62 |
+
<td>输入</td>
|
| 63 |
+
<td>表示RoPE旋转位置的余弦分量,对应公式中的cos。</td>
|
| 64 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 65 |
+
<td>ND</td>
|
| 66 |
+
</tr>
|
| 67 |
+
<tr>
|
| 68 |
+
<td>sin</td>
|
| 69 |
+
<td>输入</td>
|
| 70 |
+
<td>表示RoPE旋转位置的正弦分量,对应公式中的sin。</td>
|
| 71 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 72 |
+
<td>ND</td>
|
| 73 |
+
</tr>
|
| 74 |
+
<tr>
|
| 75 |
+
<td>y</td>
|
| 76 |
+
<td>输出</td>
|
| 77 |
+
<td>表示旋转编码后的结果,对应公式中的q_embed。</td>
|
| 78 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 79 |
+
<td>ND</td>
|
| 80 |
+
</tr>
|
| 81 |
+
</tbody>
|
| 82 |
+
</table>
|
| 83 |
+
|
| 84 |
+
- Kirin X90/Kirin 9030 处理器系列产品: 不支持BFLOAT16。
|
| 85 |
+
|
| 86 |
+
## 约束说明
|
| 87 |
+
|
| 88 |
+
* 该接口支持推理场景下使用。
|
| 89 |
+
* x,y要求为4 维张量,shape为(B,N,S,D)。
|
| 90 |
+
* cos,sin要求为4 维张量,shape为(B,N,S,D),S可以为1 或与x的S相同,数据类型、数据格式与x一致。
|
| 91 |
+
* 输入x、cos、sin的D维度必须等于64。
|
| 92 |
+
* cos、sin的N维度必须等于1。
|
| 93 |
+
* x、cos、sin、y都不支持非连续的Tensor。
|
| 94 |
+
|
| 95 |
+
## 调用说明
|
| 96 |
+
|
| 97 |
+
| 调用方式 | 调用样例 | 说明 |
|
| 98 |
+
|----------------|-----------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
|
| 99 |
+
| aclnn调用 | [test_aclnn_interleave_rope](./examples/test_aclnn_interleave_rope.cpp) | 通过[aclnnInterleaveRope](./docs/aclnnInterleaveRope.md)接口方式调用InterleaveRope算子。 |
|
datasets/ops_src/ops_transformer/test_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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# aclnnInterleaveRope
|
| 2 |
+
|
| 3 |
+
[📄 查看源码](https://gitcode.com/cann/ops-transformer/tree/master/posembedding/interleave_rope)
|
| 4 |
+
|
| 5 |
+
## 产品支持情况
|
| 6 |
+
|
| 7 |
+
| 产品 | 是否支持 |
|
| 8 |
+
| :----------------------------------------------------------- | :------: |
|
| 9 |
+
| <term>Ascend 950PR/Ascend 950DT</term> | √ |
|
| 10 |
+
| <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | × |
|
| 11 |
+
| <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | × |
|
| 12 |
+
| <term>Atlas 200I/500 A2 推理产品</term> | × |
|
| 13 |
+
| <term>Atlas 推理系列产品</term> | × |
|
| 14 |
+
| <term>Atlas 训练系列产品</term> | × |
|
| 15 |
+
|
| 16 |
+
## 功能说明
|
| 17 |
+
|
| 18 |
+
- 接口功能:针对单输入x进行旋转位置编码。
|
| 19 |
+
|
| 20 |
+
- 计算公式:
|
| 21 |
+
|
| 22 |
+
$$
|
| 23 |
+
q = \text{reshape}(x, [B, N, S, D//2, 2]) \cdot \text{transpose}(-1, -2) \cdot \text{reshape}([B, N, S, D])
|
| 24 |
+
$$
|
| 25 |
+
|
| 26 |
+
$$
|
| 27 |
+
q_{\text{embed}} = q \cdot \text{cos} + \text{RotateHalf}(q) \cdot \sin
|
| 28 |
+
$$
|
| 29 |
+
|
| 30 |
+
其中:RotateHalf(q)表示将q的D维后半部分元素移至前半部分并乘以 -1,后半部分用前半部分的值。
|
| 31 |
+
|
| 32 |
+
$$
|
| 33 |
+
\text{RotateHalf}(q)_{\text{i}} =
|
| 34 |
+
\begin{cases}
|
| 35 |
+
-q_{i+D//2} & \text{if } i < D//2 \\
|
| 36 |
+
q_{i-D//2} & \text{otherwise}
|
| 37 |
+
\end{cases}
|
| 38 |
+
$$
|
| 39 |
+
|
| 40 |
+
## 函数原型
|
| 41 |
+
|
| 42 |
+
该算子采用两段式接口,必须先调用"aclnnInterleaveRopeGetWorkspaceSize"接口获取入参并根据流程计算所需workspace大小,再调用"aclnnInterleaveRope"接口执行计算。
|
| 43 |
+
|
| 44 |
+
```c++
|
| 45 |
+
aclnnStatus aclnnInterleaveRopeGetWorkspaceSize(
|
| 46 |
+
const aclTensor *x,
|
| 47 |
+
const aclTensor *cos,
|
| 48 |
+
const aclTensor *sin,
|
| 49 |
+
aclTensor *out,
|
| 50 |
+
uint64_t *workspaceSize,
|
| 51 |
+
aclOpExecutor **executor)
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
```c++
|
| 55 |
+
aclnnStatus aclnnInterleaveRope(
|
| 56 |
+
void *workspace,
|
| 57 |
+
uint64_t workspaceSize,
|
| 58 |
+
aclOpExecutor *executor,
|
| 59 |
+
aclrtStream stream)
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## aclnnInterleaveRopeGetWorkspaceSize
|
| 63 |
+
|
| 64 |
+
- **参数说明**
|
| 65 |
+
|
| 66 |
+
<table style="undefined;table-layout: fixed; width: 1461px"><colgroup>
|
| 67 |
+
<col style="width: 162px">
|
| 68 |
+
<col style="width: 121px">
|
| 69 |
+
<col style="width: 332px">
|
| 70 |
+
<col style="width: 169px">
|
| 71 |
+
<col style="width: 275px">
|
| 72 |
+
<col style="width: 118px">
|
| 73 |
+
<col style="width: 138px">
|
| 74 |
+
<col style="width: 146px">
|
| 75 |
+
</colgroup>
|
| 76 |
+
<thead>
|
| 77 |
+
<tr>
|
| 78 |
+
<th>参数名</th>
|
| 79 |
+
<th>输入/输出</th>
|
| 80 |
+
<th>描述</th>
|
| 81 |
+
<th>使用说明</th>
|
| 82 |
+
<th>数据类型</th>
|
| 83 |
+
<th>数据格式</th>
|
| 84 |
+
<th>维度(shape)</th>
|
| 85 |
+
<th>非连续Tensor</th>
|
| 86 |
+
</tr>
|
| 87 |
+
</thead>
|
| 88 |
+
<tbody>
|
| 89 |
+
<tr>
|
| 90 |
+
<td>x</td>
|
| 91 |
+
<td>输入</td>
|
| 92 |
+
<td>device侧的aclTensor,待执行旋转位置编码的张量,对应公式中的x。</td>
|
| 93 |
+
<td>-</td>
|
| 94 |
+
<td>FLOAT32、FLOAT16、BFLOAT16</td>
|
| 95 |
+
<td>ND</td>
|
| 96 |
+
<td>4</td>
|
| 97 |
+
<td>√</td>
|
| 98 |
+
</tr>
|
| 99 |
+
<tr>
|
| 100 |
+
<td>cos</td>
|
| 101 |
+
<td>输入</td>
|
| 102 |
+
<td>device侧的aclTensor,位置编码张量,对应公式中的cos。</td>
|
| 103 |
+
<td>shape与x满足broadcast关系。</td>
|
| 104 |
+
<td>与x一致</td>
|
| 105 |
+
<td>ND</td>
|
| 106 |
+
<td>4</td>
|
| 107 |
+
<td>√</td>
|
| 108 |
+
</tr>
|
| 109 |
+
<tr>
|
| 110 |
+
<td>sin</td>
|
| 111 |
+
<td>输入</td>
|
| 112 |
+
<td>device侧的aclTensor,位置编码张量,对应公式中的sin。</td>
|
| 113 |
+
<td>shape与cos一致。</td>
|
| 114 |
+
<td>与x一致</td>
|
| 115 |
+
<td>ND</td>
|
| 116 |
+
<td>4</td>
|
| 117 |
+
<td>√</td>
|
| 118 |
+
</tr>
|
| 119 |
+
<tr>
|
| 120 |
+
<td>out</td>
|
| 121 |
+
<td>输出</td>
|
| 122 |
+
<td>device侧的aclTensor,旋转位置编码计算结果,对应公式中的y。</td>
|
| 123 |
+
<td>shape与x一致。</td>
|
| 124 |
+
<td>与x一致</td>
|
| 125 |
+
<td>ND</td>
|
| 126 |
+
<td>4</td>
|
| 127 |
+
<td>x</td>
|
| 128 |
+
</tr>
|
| 129 |
+
<tr>
|
| 130 |
+
<td>workspaceSize</td>
|
| 131 |
+
<td>输出</td>
|
| 132 |
+
<td>返回用户需要在npu device侧申请的workspace大小。</td>
|
| 133 |
+
<td>-</td>
|
| 134 |
+
<td>-</td>
|
| 135 |
+
<td>-</td>
|
| 136 |
+
<td>-</td>
|
| 137 |
+
<td>-</td>
|
| 138 |
+
</tr>
|
| 139 |
+
<tr>
|
| 140 |
+
<td>executor</td>
|
| 141 |
+
<td>输出</td>
|
| 142 |
+
<td>返回op执行器,包含算子计算流程。</td>
|
| 143 |
+
<td>-</td>
|
| 144 |
+
<td>-</td>
|
| 145 |
+
<td>-</td>
|
| 146 |
+
<td>-</td>
|
| 147 |
+
<td>-</td>
|
| 148 |
+
</tr>
|
| 149 |
+
</tbody>
|
| 150 |
+
</table>
|
| 151 |
+
|
| 152 |
+
- **返回值**
|
| 153 |
+
|
| 154 |
+
aclnnStatus:返回算子的执行状态码。
|
| 155 |
+
|
| 156 |
+
第一段接口完成入参校验,出现以下场景时报错:
|
| 157 |
+
|
| 158 |
+
<table style="undefined;table-layout: fixed; width: 1155px"><colgroup>
|
| 159 |
+
<col style="width: 288px">
|
| 160 |
+
<col style="width: 125px">
|
| 161 |
+
<col style="width: 742px">
|
| 162 |
+
</colgroup>
|
| 163 |
+
<thead>
|
| 164 |
+
<tr>
|
| 165 |
+
<th>返回码</th>
|
| 166 |
+
<th>错误码</th>
|
| 167 |
+
<th>描述</th>
|
| 168 |
+
</tr>
|
| 169 |
+
</thead>
|
| 170 |
+
<tbody>
|
| 171 |
+
<tr>
|
| 172 |
+
<td>ACLNN_ERR_PARAM_NULLPTR</td>
|
| 173 |
+
<td>161001</td>
|
| 174 |
+
<td>传入的x、cos、sin或out是空指��。</td>
|
| 175 |
+
</tr>
|
| 176 |
+
<tr>
|
| 177 |
+
<td>ACLNN_ERR_PARAM_INVALID</td>
|
| 178 |
+
<td>161002</td>
|
| 179 |
+
<td>传入的x、cos、sin、out的数据类型和格式不在支持的范围内。</td>
|
| 180 |
+
</tr>
|
| 181 |
+
<tr>
|
| 182 |
+
<td>ACLNN_ERR_INNER_TILING_ERROR</td>
|
| 183 |
+
<td>561002</td>
|
| 184 |
+
<td>传入的x、cos、sin、out的shape不匹配。</td>
|
| 185 |
+
</tr>
|
| 186 |
+
</tbody>
|
| 187 |
+
</table>
|
| 188 |
+
|
| 189 |
+
## aclnnInterleaveRope
|
| 190 |
+
|
| 191 |
+
- **参数说明**
|
| 192 |
+
|
| 193 |
+
<table style="undefined;table-layout: fixed; width: 1155px"><colgroup>
|
| 194 |
+
<col style="width: 173px">
|
| 195 |
+
<col style="width: 133px">
|
| 196 |
+
<col style="width: 849px">
|
| 197 |
+
</colgroup>
|
| 198 |
+
<thead>
|
| 199 |
+
<tr>
|
| 200 |
+
<th>参数名</th>
|
| 201 |
+
<th>输入/输出</th>
|
| 202 |
+
<th>描述</th>
|
| 203 |
+
</tr></thead>
|
| 204 |
+
<tbody>
|
| 205 |
+
<tr>
|
| 206 |
+
<td>workspace</td>
|
| 207 |
+
<td>输入</td>
|
| 208 |
+
<td>在Device侧申请的workspace内存地址。</td>
|
| 209 |
+
</tr>
|
| 210 |
+
<tr>
|
| 211 |
+
<td>workspaceSize</td>
|
| 212 |
+
<td>输入</td>
|
| 213 |
+
<td>在Device侧申请的workspace大小,由第一段接口aclnnInterleaveRopeGetWorkspaceSize获取。</td>
|
| 214 |
+
</tr>
|
| 215 |
+
<tr>
|
| 216 |
+
<td>executor</td>
|
| 217 |
+
<td>输入</td>
|
| 218 |
+
<td>op执行器,包含了算子计算流程。</td>
|
| 219 |
+
</tr>
|
| 220 |
+
<tr>
|
| 221 |
+
<td>stream</td>
|
| 222 |
+
<td>输入</td>
|
| 223 |
+
<td>指定执行任务的Stream流。</td>
|
| 224 |
+
</tr>
|
| 225 |
+
</tbody>
|
| 226 |
+
</table>
|
| 227 |
+
|
| 228 |
+
- **返回值**
|
| 229 |
+
|
| 230 |
+
aclnnStatus:返回算子的执行状态码。
|
| 231 |
+
|
| 232 |
+
## 约束说明
|
| 233 |
+
|
| 234 |
+
- 确定性计算:
|
| 235 |
+
- aclnnInterleaveRope默认确定性实现。
|
| 236 |
+
- 该接口支持推理场景下使用。
|
| 237 |
+
- x、cos、sin、out要求为4维张量,shape为(B,N,S,D)。
|
| 238 |
+
- cos、sin的S维度可以为1或与x的S维度相同,N维度必须等于1。
|
| 239 |
+
- 输入x、cos、sin的D维度必须等于64。
|
| 240 |
+
|
| 241 |
+
## 调用示例
|
| 242 |
+
|
| 243 |
+
以下示例代码展示接口调用流程,可供编译和运行时参考。
|
| 244 |
+
|
| 245 |
+
```Cpp
|
| 246 |
+
#include "acl/acl.h"
|
| 247 |
+
#include "aclnnop/aclnn_interleave_rope.h"
|
| 248 |
+
#include <iostream>
|
| 249 |
+
#include <vector>
|
| 250 |
+
|
| 251 |
+
#define CHECK_RET(cond, return_expr) \
|
| 252 |
+
do { \
|
| 253 |
+
if (!(cond)) { \
|
| 254 |
+
return_expr; \
|
| 255 |
+
} \
|
| 256 |
+
} while (0)
|
| 257 |
+
|
| 258 |
+
#define LOG_PRINT(message, ...) \
|
| 259 |
+
do { \
|
| 260 |
+
printf(message, ##__VA_ARGS__); \
|
| 261 |
+
} while (0)
|
| 262 |
+
|
| 263 |
+
int64_t GetShapeSize(const std::vector<int64_t>& shape) {
|
| 264 |
+
int64_t shape_size = 1;
|
| 265 |
+
for (auto i : shape) {
|
| 266 |
+
shape_size *= i;
|
| 267 |
+
}
|
| 268 |
+
return shape_size;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
std::vector<aclFloat16> ConvertToFloat16(const std::vector<float>& data) {
|
| 272 |
+
std::vector<aclFloat16> converted;
|
| 273 |
+
converted.reserve(data.size());
|
| 274 |
+
for (float value : data) {
|
| 275 |
+
converted.push_back(aclFloatToFloat16(value));
|
| 276 |
+
}
|
| 277 |
+
return converted;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
int Init(int32_t deviceId, aclrtStream* stream) {
|
| 281 |
+
// 固定写法,资源初始化
|
| 282 |
+
auto ret = aclInit(nullptr);
|
| 283 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
|
| 284 |
+
ret = aclrtSetDevice(deviceId);
|
| 285 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
|
| 286 |
+
ret = aclrtCreateStream(stream);
|
| 287 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
|
| 288 |
+
return 0;
|
| 289 |
+
}
|
| 290 |
+
|
| 291 |
+
template <typename T>
|
| 292 |
+
int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr,
|
| 293 |
+
aclDataType dataType, aclTensor** tensor) {
|
| 294 |
+
auto size = GetShapeSize(shape) * sizeof(T);
|
| 295 |
+
// 调用aclrtMalloc申请device侧内存
|
| 296 |
+
auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
|
| 297 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);
|
| 298 |
+
|
| 299 |
+
// 调用aclrtMemcpy将host侧数据拷贝到device侧内存上
|
| 300 |
+
ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
|
| 301 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret);
|
| 302 |
+
|
| 303 |
+
// 计算连续tensor的strides
|
| 304 |
+
std::vector<int64_t> strides(shape.size(), 1);
|
| 305 |
+
for (int64_t i = shape.size() - 2; i >= 0; i--) {
|
| 306 |
+
strides[i] = shape[i + 1] * strides[i + 1];
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
// 调用aclCreateTensor接口创建aclTensor
|
| 310 |
+
*tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND,
|
| 311 |
+
shape.data(), shape.size(), *deviceAddr);
|
| 312 |
+
return 0;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
int main() {
|
| 316 |
+
// 1. 固定写法,device/stream初始化,参考acl API手册
|
| 317 |
+
// 根据自己的实际device填写deviceId
|
| 318 |
+
int32_t deviceId = 0;
|
| 319 |
+
aclrtStream stream;
|
| 320 |
+
auto ret = Init(deviceId, &stream);
|
| 321 |
+
// check根据自己的需要处理
|
| 322 |
+
CHECK_RET(ret == 0, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
|
| 323 |
+
// 2. 构造输入与输出,需要根据API的接口定义构造
|
| 324 |
+
// interleave_rope约束:D=64, N=1
|
| 325 |
+
std::vector<int64_t> xShape = {1, 1, 1, 64};
|
| 326 |
+
std::vector<int64_t> cosShape = {1, 1, 1, 64};
|
| 327 |
+
std::vector<int64_t> sinShape = {1, 1, 1, 64};
|
| 328 |
+
std::vector<int64_t> outShape = {1, 1, 1, 64};
|
| 329 |
+
|
| 330 |
+
void* xDeviceAddr = nullptr;
|
| 331 |
+
void* cosDeviceAddr = nullptr;
|
| 332 |
+
void* sinDeviceAddr = nullptr;
|
| 333 |
+
void* outDeviceAddr = nullptr;
|
| 334 |
+
aclTensor* x = nullptr;
|
| 335 |
+
aclTensor* cos = nullptr;
|
| 336 |
+
aclTensor* sin = nullptr;
|
| 337 |
+
aclTensor* out = nullptr;
|
| 338 |
+
|
| 339 |
+
std::vector<aclFloat16> xHostData = ConvertToFloat16({
|
| 340 |
+
74, 54, 84, 125, 23, 78, 37, 72, 27, 98, 34, 107, 29, 23, 54, 60,
|
| 341 |
+
70, 49, 119, 54, 29, 54, 41, 99, 27, 62, 5, 46, 108, 39, 24, 123,
|
| 342 |
+
33, 82, 6, 40, 88, 24, 6, 116, 38, 119, 110, 5, 30, 79, 87, 18,
|
| 343 |
+
29, 100, 90, 24, 21, 93, 63, 68, 34, 112, 119, 48, 74, 43, 85, 64
|
| 344 |
+
});
|
| 345 |
+
std::vector<aclFloat16> cosHostData = ConvertToFloat16({
|
| 346 |
+
41, 37, 17, 25, 49, 25, 22, 24, 110, 120, 107, 3, 82, 66, 75, 86,
|
| 347 |
+
85, 115, 110, 56, 52, 39, 86, 23, 36, 71, 20, 73, 113, 25, 114, 56,
|
| 348 |
+
125, 80, 95, 82, 31, 63, 99, 62, 23, 55, 30, 99, 42, 121, 15, 24,
|
| 349 |
+
97, 87, 81, 67, 43, 21, 13, 9, 33, 29, 117, 10, 114, 61, 98, 15
|
| 350 |
+
});
|
| 351 |
+
std::vector<aclFloat16> sinHostData = ConvertToFloat16({
|
| 352 |
+
46, 56, 56, 101, 66, 10, 96, 16, 86, 57, 102, 66, 12, 105, 76, 58,
|
| 353 |
+
90, 6, 79, 128, 126, 82, 41, 3, 45, 7, 66, 4, 46, 22, 31, 26,
|
| 354 |
+
37, 63, 97, 84, 91, 90, 47, 77, 90, 34, 41, 83, 91, 108, 120, 13,
|
| 355 |
+
90, 32, 85, 37, 119, 31, 51, 82, 122, 125, 7, 116, 121, 108, 38, 56
|
| 356 |
+
});
|
| 357 |
+
std::vector<aclFloat16> outHostData(64, aclFloatToFloat16(0.0f));
|
| 358 |
+
|
| 359 |
+
// 创建x aclTensor
|
| 360 |
+
ret = CreateAclTensor(xHostData, xShape, &xDeviceAddr, aclDataType::ACL_FLOAT16, &x);
|
| 361 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 362 |
+
// 创建cos aclTensor
|
| 363 |
+
ret = CreateAclTensor(cosHostData, cosShape, &cosDeviceAddr, aclDataType::ACL_FLOAT16, &cos);
|
| 364 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 365 |
+
// 创建sin aclTensor
|
| 366 |
+
ret = CreateAclTensor(sinHostData, sinShape, &sinDeviceAddr, aclDataType::ACL_FLOAT16, &sin);
|
| 367 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 368 |
+
// 创建out aclTensor
|
| 369 |
+
ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT16, &out);
|
| 370 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 371 |
+
|
| 372 |
+
// 3. 调用CANN算子库API,需要修改为具体的API
|
| 373 |
+
uint64_t workspaceSize = 0;
|
| 374 |
+
aclOpExecutor* executor;
|
| 375 |
+
// 调用aclnnInterleaveRope第一段接口
|
| 376 |
+
ret = aclnnInterleaveRopeGetWorkspaceSize(x, cos, sin, out, &workspaceSize, &executor);
|
| 377 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnInterleaveRopeGetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
|
| 378 |
+
// 根据第一段接口计算出的workspaceSize申请device内存
|
| 379 |
+
void* workspaceAddr = nullptr;
|
| 380 |
+
if (workspaceSize > 0) {
|
| 381 |
+
ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
|
| 382 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
|
| 383 |
+
}
|
| 384 |
+
// 调用aclnnInterleaveRope第二段接口
|
| 385 |
+
ret = aclnnInterleaveRope(workspaceAddr, workspaceSize, executor, stream);
|
| 386 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnInterleaveRope failed. ERROR: %d\n", ret); return ret);
|
| 387 |
+
// 4. 固定写法,同步等待任务执行结束
|
| 388 |
+
ret = aclrtSynchronizeStream(stream);
|
| 389 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
|
| 390 |
+
// 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改
|
| 391 |
+
auto size = GetShapeSize(outShape);
|
| 392 |
+
std::vector<aclFloat16> resultData(size, aclFloatToFloat16(0.0f));
|
| 393 |
+
ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr,
|
| 394 |
+
size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST);
|
| 395 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret);
|
| 396 |
+
|
| 397 |
+
for (int64_t i = 0; i < size; i++) {
|
| 398 |
+
LOG_PRINT("result[%ld] is: %f\n", i, aclFloat16ToFloat(resultData[i]));
|
| 399 |
+
}
|
| 400 |
+
|
| 401 |
+
// 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改
|
| 402 |
+
aclDestroyTensor(x);
|
| 403 |
+
aclDestroyTensor(cos);
|
| 404 |
+
aclDestroyTensor(sin);
|
| 405 |
+
aclDestroyTensor(out);
|
| 406 |
+
|
| 407 |
+
// 7. 释放device资源
|
| 408 |
+
aclrtFree(xDeviceAddr);
|
| 409 |
+
aclrtFree(cosDeviceAddr);
|
| 410 |
+
aclrtFree(sinDeviceAddr);
|
| 411 |
+
aclrtFree(outDeviceAddr);
|
| 412 |
+
if (workspaceSize > 0) {
|
| 413 |
+
aclrtFree(workspaceAddr);
|
| 414 |
+
}
|
| 415 |
+
aclrtDestroyStream(stream);
|
| 416 |
+
aclrtResetDevice(deviceId);
|
| 417 |
+
aclFinalize();
|
| 418 |
+
|
| 419 |
+
return 0;
|
| 420 |
+
}
|
| 421 |
+
```
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/examples/aclnn_interleave_rope.h
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#ifndef OP_API_INC_INTERLEAVE_ROPE_H_
|
| 12 |
+
#define OP_API_INC_INTERLEAVE_ROPE_H_
|
| 13 |
+
|
| 14 |
+
#include "aclnn/aclnn_base.h"
|
| 15 |
+
#include "aclnn_util.h"
|
| 16 |
+
|
| 17 |
+
#ifdef __cplusplus
|
| 18 |
+
extern "C" {
|
| 19 |
+
#endif
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @brief aclnnInterleaveRope的第一段接口,根据具体的计算流程,计算workspace大小。
|
| 23 |
+
* @domain aclnn_ops_infer
|
| 24 |
+
*
|
| 25 |
+
* @param [in] x: npu
|
| 26 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,支持非连续的Tensor,数据格式支持ND。
|
| 27 |
+
* @param [in] sin: npu
|
| 28 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,数据类型与x一致,shape与x满足broadcast关系
|
| 29 |
+
* 支持非连续的Tensor,数据格式支持ND。
|
| 30 |
+
* @param [in] cos: npu
|
| 31 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,数据类型与x一致,shape与sin一致
|
| 32 |
+
* 支持非连续的Tensor,数据格式支持ND。
|
| 33 |
+
* @param [in] out: npu
|
| 34 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,且数据类型与x一致,
|
| 35 |
+
* shape与x相同, 数据格式支持ND, 且数据格式需要与x一致。
|
| 36 |
+
* @param [out] workspaceSize: 返回用户需要在npu device侧申请的workspace大小.
|
| 37 |
+
* @param [out] executor: 返回op执行器,包含算子计算流程。
|
| 38 |
+
* @return aclnnStatus: 返回状态码。
|
| 39 |
+
*/
|
| 40 |
+
ACLNN_API aclnnStatus aclnnInterleaveRopeGetWorkspaceSize(
|
| 41 |
+
const aclTensor* x, const aclTensor* cos, const aclTensor* sin, aclTensor* out, uint64_t* workspaceSize,
|
| 42 |
+
aclOpExecutor** executor);
|
| 43 |
+
|
| 44 |
+
/* @brief aclnnInterleaveRope的第二段接口,用于执行计算.
|
| 45 |
+
* @param [in] workspace: 在npu device侧申请的workspace内存起址
|
| 46 |
+
* @param [in] workspace_size: 在npu device侧申请的workspace大小,由第一段接口aclnnBitwiseNotGetWorkspaceSize获取.
|
| 47 |
+
* @param [in] executor: op执行器,包含了算子计算流程.
|
| 48 |
+
* @param [in] stream: acl stream流.
|
| 49 |
+
* @return aclnnStatus: 返回状态码。
|
| 50 |
+
*/
|
| 51 |
+
ACLNN_API aclnnStatus
|
| 52 |
+
aclnnInterleaveRope(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, aclrtStream stream);
|
| 53 |
+
|
| 54 |
+
#ifdef __cplusplus
|
| 55 |
+
}
|
| 56 |
+
#endif
|
| 57 |
+
|
| 58 |
+
#endif
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/examples/test_aclnn_interleave_rope.cpp
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include "acl/acl.h"
|
| 12 |
+
#include "aclnnop/aclnn_interleave_rope.h"
|
| 13 |
+
#include <iostream>
|
| 14 |
+
#include <vector>
|
| 15 |
+
|
| 16 |
+
#define CHECK_RET(cond, return_expr) \
|
| 17 |
+
do { \
|
| 18 |
+
if (!(cond)) { \
|
| 19 |
+
return_expr; \
|
| 20 |
+
} \
|
| 21 |
+
} while (0)
|
| 22 |
+
|
| 23 |
+
#define LOG_PRINT(message, ...) \
|
| 24 |
+
do { \
|
| 25 |
+
printf(message, ##__VA_ARGS__); \
|
| 26 |
+
} while (0)
|
| 27 |
+
|
| 28 |
+
int64_t GetShapeSize(const std::vector<int64_t>& shape) {
|
| 29 |
+
int64_t shape_size = 1;
|
| 30 |
+
for (auto i : shape) {
|
| 31 |
+
shape_size *= i;
|
| 32 |
+
}
|
| 33 |
+
return shape_size;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
std::vector<aclFloat16> ConvertToFloat16(const std::vector<float>& data) {
|
| 37 |
+
std::vector<aclFloat16> converted;
|
| 38 |
+
converted.reserve(data.size());
|
| 39 |
+
for (float value : data) {
|
| 40 |
+
converted.push_back(aclFloatToFloat16(value));
|
| 41 |
+
}
|
| 42 |
+
return converted;
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
int Init(int32_t deviceId, aclrtStream* stream) {
|
| 46 |
+
// 固定写法,资源初始化
|
| 47 |
+
auto ret = aclInit(nullptr);
|
| 48 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
|
| 49 |
+
ret = aclrtSetDevice(deviceId);
|
| 50 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
|
| 51 |
+
ret = aclrtCreateStream(stream);
|
| 52 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
|
| 53 |
+
return 0;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
template <typename T>
|
| 57 |
+
int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr,
|
| 58 |
+
aclDataType dataType, aclTensor** tensor) {
|
| 59 |
+
auto size = GetShapeSize(shape) * sizeof(T);
|
| 60 |
+
// 调用aclrtMalloc申请device侧内存
|
| 61 |
+
auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
|
| 62 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);
|
| 63 |
+
|
| 64 |
+
// 调用aclrtMemcpy将host侧数据拷贝到device侧内存上
|
| 65 |
+
ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
|
| 66 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret);
|
| 67 |
+
|
| 68 |
+
// 计算连续tensor的strides
|
| 69 |
+
std::vector<int64_t> strides(shape.size(), 1);
|
| 70 |
+
for (int64_t i = shape.size() - 2; i >= 0; i--) {
|
| 71 |
+
strides[i] = shape[i + 1] * strides[i + 1];
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
// 调用aclCreateTensor接口创建aclTensor
|
| 75 |
+
*tensor = aclCreateTensor(shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND,
|
| 76 |
+
shape.data(), shape.size(), *deviceAddr);
|
| 77 |
+
return 0;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
int main() {
|
| 81 |
+
// 1. 固定写法,device/stream初始化, 参考AscendCL对外接口列表
|
| 82 |
+
// 根据自己的实际device填写deviceId
|
| 83 |
+
int32_t deviceId = 0;
|
| 84 |
+
aclrtStream stream;
|
| 85 |
+
auto ret = Init(deviceId, &stream);
|
| 86 |
+
// check根据自己的需要处理
|
| 87 |
+
CHECK_RET(ret == 0, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
|
| 88 |
+
// 2. 构造输入与输出,需要根据API的接口定义构造
|
| 89 |
+
// interleave_rope约束:D=64, N=1
|
| 90 |
+
std::vector<int64_t> xShape = {1, 1, 1, 64};
|
| 91 |
+
std::vector<int64_t> cosShape = {1, 1, 1, 64};
|
| 92 |
+
std::vector<int64_t> sinShape = {1, 1, 1, 64};
|
| 93 |
+
std::vector<int64_t> outShape = {1, 1, 1, 64};
|
| 94 |
+
|
| 95 |
+
void* xDeviceAddr = nullptr;
|
| 96 |
+
void* cosDeviceAddr = nullptr;
|
| 97 |
+
void* sinDeviceAddr = nullptr;
|
| 98 |
+
void* outDeviceAddr = nullptr;
|
| 99 |
+
aclTensor* x = nullptr;
|
| 100 |
+
aclTensor* cos = nullptr;
|
| 101 |
+
aclTensor* sin = nullptr;
|
| 102 |
+
aclTensor* out = nullptr;
|
| 103 |
+
|
| 104 |
+
std::vector<aclFloat16> xHostData = ConvertToFloat16({
|
| 105 |
+
74, 54, 84, 125, 23, 78, 37, 72, 27, 98, 34, 107, 29, 23, 54, 60,
|
| 106 |
+
70, 49, 119, 54, 29, 54, 41, 99, 27, 62, 5, 46, 108, 39, 24, 123,
|
| 107 |
+
33, 82, 6, 40, 88, 24, 6, 116, 38, 119, 110, 5, 30, 79, 87, 18,
|
| 108 |
+
29, 100, 90, 24, 21, 93, 63, 68, 34, 112, 119, 48, 74, 43, 85, 64
|
| 109 |
+
});
|
| 110 |
+
std::vector<aclFloat16> cosHostData = ConvertToFloat16({
|
| 111 |
+
41, 37, 17, 25, 49, 25, 22, 24, 110, 120, 107, 3, 82, 66, 75, 86,
|
| 112 |
+
85, 115, 110, 56, 52, 39, 86, 23, 36, 71, 20, 73, 113, 25, 114, 56,
|
| 113 |
+
125, 80, 95, 82, 31, 63, 99, 62, 23, 55, 30, 99, 42, 121, 15, 24,
|
| 114 |
+
97, 87, 81, 67, 43, 21, 13, 9, 33, 29, 117, 10, 114, 61, 98, 15
|
| 115 |
+
});
|
| 116 |
+
std::vector<aclFloat16> sinHostData = ConvertToFloat16({
|
| 117 |
+
46, 56, 56, 101, 66, 10, 96, 16, 86, 57, 102, 66, 12, 105, 76, 58,
|
| 118 |
+
90, 6, 79, 128, 126, 82, 41, 3, 45, 7, 66, 4, 46, 22, 31, 26,
|
| 119 |
+
37, 63, 97, 84, 91, 90, 47, 77, 90, 34, 41, 83, 91, 108, 120, 13,
|
| 120 |
+
90, 32, 85, 37, 119, 31, 51, 82, 122, 125, 7, 116, 121, 108, 38, 56
|
| 121 |
+
});
|
| 122 |
+
std::vector<aclFloat16> outHostData(64, aclFloatToFloat16(0.0f));
|
| 123 |
+
|
| 124 |
+
// 创建x aclTensor
|
| 125 |
+
ret = CreateAclTensor(xHostData, xShape, &xDeviceAddr, aclDataType::ACL_FLOAT16, &x);
|
| 126 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 127 |
+
// 创建cos aclTensor
|
| 128 |
+
ret = CreateAclTensor(cosHostData, cosShape, &cosDeviceAddr, aclDataType::ACL_FLOAT16, &cos);
|
| 129 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 130 |
+
// 创建sin aclTensor
|
| 131 |
+
ret = CreateAclTensor(sinHostData, sinShape, &sinDeviceAddr, aclDataType::ACL_FLOAT16, &sin);
|
| 132 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 133 |
+
// 创建out aclTensor
|
| 134 |
+
ret = CreateAclTensor(outHostData, outShape, &outDeviceAddr, aclDataType::ACL_FLOAT16, &out);
|
| 135 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 136 |
+
|
| 137 |
+
// 3. 调用CANN算子库API,需要修改为具体的API
|
| 138 |
+
uint64_t workspaceSize = 0;
|
| 139 |
+
aclOpExecutor* executor;
|
| 140 |
+
// 调用aclnnInterleaveRope第一段接口
|
| 141 |
+
ret = aclnnInterleaveRopeGetWorkspaceSize(x, cos, sin, out, &workspaceSize, &executor);
|
| 142 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnInterleaveRopeGetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
|
| 143 |
+
// 根据第一段接口计算出的workspaceSize申请device内存
|
| 144 |
+
void* workspaceAddr = nullptr;
|
| 145 |
+
if (workspaceSize > 0) {
|
| 146 |
+
ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
|
| 147 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
|
| 148 |
+
}
|
| 149 |
+
// 调用aclnnInterleaveRope第二段接口
|
| 150 |
+
ret = aclnnInterleaveRope(workspaceAddr, workspaceSize, executor, stream);
|
| 151 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnInterleaveRope failed. ERROR: %d\n", ret); return ret);
|
| 152 |
+
// 4. 固定写法,同步等待任务执行结束
|
| 153 |
+
ret = aclrtSynchronizeStream(stream);
|
| 154 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
|
| 155 |
+
// 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改
|
| 156 |
+
auto size = GetShapeSize(outShape);
|
| 157 |
+
std::vector<aclFloat16> resultData(size, aclFloatToFloat16(0.0f));
|
| 158 |
+
ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), outDeviceAddr,
|
| 159 |
+
size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST);
|
| 160 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return ret);
|
| 161 |
+
|
| 162 |
+
for (int64_t i = 0; i < size; i++) {
|
| 163 |
+
LOG_PRINT("result[%ld] is: %f\n", i, aclFloat16ToFloat(resultData[i]));
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
// 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改
|
| 167 |
+
aclDestroyTensor(x);
|
| 168 |
+
aclDestroyTensor(cos);
|
| 169 |
+
aclDestroyTensor(sin);
|
| 170 |
+
aclDestroyTensor(out);
|
| 171 |
+
|
| 172 |
+
// 7. 释放device 资源
|
| 173 |
+
aclrtFree(xDeviceAddr);
|
| 174 |
+
aclrtFree(cosDeviceAddr);
|
| 175 |
+
aclrtFree(sinDeviceAddr);
|
| 176 |
+
aclrtFree(outDeviceAddr);
|
| 177 |
+
if (workspaceSize > 0) {
|
| 178 |
+
aclrtFree(workspaceAddr);
|
| 179 |
+
}
|
| 180 |
+
aclrtDestroyStream(stream);
|
| 181 |
+
aclrtResetDevice(deviceId);
|
| 182 |
+
aclFinalize();
|
| 183 |
+
|
| 184 |
+
return 0;
|
| 185 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/interleave_rope_collect.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Collect golden data for interleave_rope by running the NPU operator on every case.
|
| 3 |
+
|
| 4 |
+
Re-run ONLY after an intentional kernel change — this overwrites the regression baseline.
|
| 5 |
+
|
| 6 |
+
Shape constraints from tiling code:
|
| 7 |
+
- x: (B, N, S, 64) — N>=1, S>=1, B>=1
|
| 8 |
+
- cos/sin: (B, 1, cosS, 64) — cosB MUST equal x's B, cosN=1, cosS=1 or S
|
| 9 |
+
- D must be exactly 64
|
| 10 |
+
|
| 11 |
+
Tiling branches (from DoOpTiling):
|
| 12 |
+
1. BN1D: seq >= 512 AND cosS == seq (seq-per-core split)
|
| 13 |
+
2. FIXED_BNSD: B==32, N==32, S==1, cosN==1, cosS==1 (batch-per-block=4)
|
| 14 |
+
3. B11D: cosS==1 and (B >= coreNum OR B >= N*S) (batch split)
|
| 15 |
+
4. B11D: cosS==1 and B < coreNum AND B < N*S (NS split)
|
| 16 |
+
5. B1SD: cosS != 1 and cosS != seq (batch split) — NOT reachable due to shape check
|
| 17 |
+
|
| 18 |
+
All shapes are multiples of 32 for alignment.
|
| 19 |
+
"""
|
| 20 |
+
import json, os, sys
|
| 21 |
+
import torch
|
| 22 |
+
import torch_npu # noqa: F401
|
| 23 |
+
import gtsrusops as ops
|
| 24 |
+
|
| 25 |
+
OP_NAME = "interleave_rope"
|
| 26 |
+
OP_CAMEL = "InterleaveRope"
|
| 27 |
+
DEVICE = "npu:0"
|
| 28 |
+
SEED = 2026
|
| 29 |
+
|
| 30 |
+
# Positional order expected by ops.npu_interleave_rope(...), excluding output buffers.
|
| 31 |
+
PARAM_NAMES = ["x", "cos", "sin"]
|
| 32 |
+
OUTPUT_KEYS = ["y"]
|
| 33 |
+
|
| 34 |
+
# 10 cases spanning dtypes / sizes / cos/sin broadcast patterns
|
| 35 |
+
# cos/sin batch MUST equal x batch (enforced in tiling code: cosB_ != batchSize_)
|
| 36 |
+
# cos/sin N must be 1 (enforced in tiling code: cosN_ != 1)
|
| 37 |
+
# cosS must be 1 or equal to seq (enforced in tiling code)
|
| 38 |
+
# D must be 64
|
| 39 |
+
CASES = [
|
| 40 |
+
{"id": 0, "dtype": torch.float16, "batch": 32, "seq": 32, "cos_s": 1}, # B11D, batch split
|
| 41 |
+
{"id": 1, "dtype": torch.float16, "batch": 32, "seq": 64, "cos_s": 1}, # B11D, batch split
|
| 42 |
+
{"id": 2, "dtype": torch.float16, "batch": 32, "seq": 128, "cos_s": 1}, # B11D, batch split
|
| 43 |
+
{"id": 3, "dtype": torch.bfloat16, "batch": 64, "seq": 32, "cos_s": 1}, # B11D, batch split
|
| 44 |
+
{"id": 4, "dtype": torch.bfloat16, "batch": 64, "seq": 64, "cos_s": 1}, # B11D, batch split
|
| 45 |
+
{"id": 5, "dtype": torch.float16, "batch": 128,"seq": 32, "cos_s": 1}, # B11D, batch split
|
| 46 |
+
{"id": 6, "dtype": torch.float16, "batch": 32, "seq": 512, "cos_s": 512}, # BN1D (seq >= 512)
|
| 47 |
+
{"id": 7, "dtype": torch.bfloat16, "batch": 128,"seq": 64, "cos_s": 1}, # B11D, batch split
|
| 48 |
+
{"id": 8, "dtype": torch.float16, "batch": 64, "seq": 1024, "cos_s": 1024},# BN1D (seq >= 512)
|
| 49 |
+
{"id": 9, "dtype": torch.bfloat16, "batch": 32, "seq": 1, "cos_s": 1}, # B11D, batch split
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
DATA_ROOT = "test_data"
|
| 53 |
+
INPUT_DIR = os.path.join(DATA_ROOT, "golden_input", OP_CAMEL)
|
| 54 |
+
RESULT_DIR = os.path.join(DATA_ROOT, "golden_result", OP_CAMEL)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def make_inputs(case):
|
| 58 |
+
"""Build every entry of PARAM_NAMES for this case.
|
| 59 |
+
|
| 60 |
+
Key constraint from tiling code:
|
| 61 |
+
cosB_ must equal batchSize_ (cos/sin batch == x batch)
|
| 62 |
+
cosN_ must be 1
|
| 63 |
+
cosS_ must be 1 or seqLength_
|
| 64 |
+
cosD_ must equal hiddenDim_ (64)
|
| 65 |
+
"""
|
| 66 |
+
torch.manual_seed(SEED + case["id"])
|
| 67 |
+
dtype = case["dtype"]
|
| 68 |
+
batch, seq = case["batch"], case["seq"]
|
| 69 |
+
cos_s = case["cos_s"]
|
| 70 |
+
# Shape is always (B, N, S, D) with N=1, D=64
|
| 71 |
+
# cos/sin batch MUST equal x batch (not 1!)
|
| 72 |
+
x_shape = (batch, 1, seq, 64)
|
| 73 |
+
cos_shape = (batch, 1, cos_s, 64)
|
| 74 |
+
sin_shape = (batch, 1, cos_s, 64)
|
| 75 |
+
return {
|
| 76 |
+
"x": torch.randn(x_shape, dtype=dtype, device=DEVICE),
|
| 77 |
+
"cos": torch.randn(cos_shape, dtype=dtype, device=DEVICE),
|
| 78 |
+
"sin": torch.randn(sin_shape, dtype=dtype, device=DEVICE),
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def make_output_bufs(case):
|
| 83 |
+
"""(shape, dtype) per output, in OUTPUT_KEYS order."""
|
| 84 |
+
batch, seq = case["batch"], case["seq"]
|
| 85 |
+
dtype = case["dtype"]
|
| 86 |
+
return [torch.empty((batch, 1, seq, 64), dtype=dtype, device=DEVICE)]
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def build_call_args(case):
|
| 90 |
+
inputs = make_inputs(case)
|
| 91 |
+
positional = [inputs[p] for p in PARAM_NAMES]
|
| 92 |
+
return positional, inputs
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def collect_case(case):
|
| 96 |
+
call_args, inputs = build_call_args(case)
|
| 97 |
+
|
| 98 |
+
out_bufs = make_output_bufs(case)
|
| 99 |
+
out_arg = out_bufs[0] if len(out_bufs) == 1 else out_bufs
|
| 100 |
+
|
| 101 |
+
outputs = ops.npu_interleave_rope(*call_args, out_arg)
|
| 102 |
+
torch.npu.synchronize()
|
| 103 |
+
|
| 104 |
+
outputs = [outputs] if isinstance(outputs, torch.Tensor) else list(outputs)
|
| 105 |
+
if len(outputs) != len(OUTPUT_KEYS):
|
| 106 |
+
raise RuntimeError(f"case_{case['id']}: got {len(outputs)} outputs, expected {OUTPUT_KEYS}")
|
| 107 |
+
|
| 108 |
+
saved_out = {k: outputs[i].cpu() for i, k in enumerate(OUTPUT_KEYS)}
|
| 109 |
+
for k, t in saved_out.items():
|
| 110 |
+
if not torch.isfinite(t.float()).all():
|
| 111 |
+
raise RuntimeError(f"case_{case['id']}: output '{k}' has NaN/Inf — bad golden data")
|
| 112 |
+
|
| 113 |
+
saved_in = {k: (v.cpu() if isinstance(v, torch.Tensor) else v) for k, v in inputs.items()}
|
| 114 |
+
return saved_in, saved_out
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def describe_call(call_args):
|
| 118 |
+
"""Compact argument summary."""
|
| 119 |
+
parts = []
|
| 120 |
+
for name, val in zip(PARAM_NAMES, call_args):
|
| 121 |
+
if isinstance(val, torch.Tensor):
|
| 122 |
+
parts.append(f"{name}=Tensor{tuple(val.shape)}:{str(val.dtype).replace('torch.', '')}")
|
| 123 |
+
else:
|
| 124 |
+
parts.append(f"{name}={val!r}")
|
| 125 |
+
return ", ".join(parts)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def main():
|
| 129 |
+
os.makedirs(INPUT_DIR, exist_ok=True)
|
| 130 |
+
os.makedirs(RESULT_DIR, exist_ok=True)
|
| 131 |
+
manifest = {"op_name": OP_NAME, "op_camel": OP_CAMEL, "output_keys": OUTPUT_KEYS, "cases": []}
|
| 132 |
+
|
| 133 |
+
for case in CASES:
|
| 134 |
+
name = f"case_{case['id']}"
|
| 135 |
+
try:
|
| 136 |
+
saved_in, saved_out = collect_case(case)
|
| 137 |
+
except TypeError as exc:
|
| 138 |
+
print(f"{name}: signature mismatch")
|
| 139 |
+
print(f" passed: {describe_call(build_call_args(case)[0])}")
|
| 140 |
+
print(f" binding expects: {ops.npu_interleave_rope.__doc__.splitlines()[0] if ops.npu_interleave_rope.__doc__ else '?'}")
|
| 141 |
+
print(f" {type(exc).__name__}: {str(exc)[:400]}")
|
| 142 |
+
sys.exit(1)
|
| 143 |
+
except Exception as exc:
|
| 144 |
+
print(f"{name}: COLLECT FAILED — {type(exc).__name__}: {str(exc)[:400]}")
|
| 145 |
+
sys.exit(1)
|
| 146 |
+
in_path, out_path = os.path.join(INPUT_DIR, f"{name}.pt"), os.path.join(RESULT_DIR, f"{name}.pt")
|
| 147 |
+
torch.save(saved_in, in_path)
|
| 148 |
+
torch.save(saved_out, out_path)
|
| 149 |
+
manifest["cases"].append({
|
| 150 |
+
"id": case["id"], "dtype": str(case["dtype"]).replace("torch.", ""),
|
| 151 |
+
"shape": [case["batch"], 1, case["seq"], 64],
|
| 152 |
+
"attrs": {k: v for k, v in case.items() if k not in ("id", "dtype", "batch", "seq")},
|
| 153 |
+
})
|
| 154 |
+
print(f"{name}: OK input={os.path.getsize(in_path)}B result={os.path.getsize(out_path)}B")
|
| 155 |
+
|
| 156 |
+
with open(os.path.join(DATA_ROOT, "cases_manifest.json"), "w") as fh:
|
| 157 |
+
json.dump(manifest, fh, indent=2)
|
| 158 |
+
print(f"\nCollected {len(manifest['cases'])}/{len(CASES)} cases into {DATA_ROOT}/")
|
| 159 |
+
|
| 160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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Reference regression test: NPU operator vs golden data collected from the same operator.
|
| 3 |
+
|
| 4 |
+
This is the canonical test script for the sandbox workflow. To adapt it to another operator,
|
| 5 |
+
change only OP_NAME/OP_CAMEL, PARAM_NAMES, OUTPUT_KEYS, INTERMEDIATE_OUTPUT_KEYS and the
|
| 6 |
+
ops.npu_<op_name>(...) call in run_case(). Leave path resolution, the comparator and the exit code alone.
|
| 7 |
+
|
| 8 |
+
Inputs are LOADED from golden_input/, never regenerated from a seed: the comparison is only
|
| 9 |
+
meaningful if the inputs are byte-identical to the ones used at collection time.
|
| 10 |
+
|
| 11 |
+
Tolerance: golden is frozen while the sources keep changing, so the check carries slack —
|
| 12 |
+
|ref - cur| / max(|ref|, 1) <= 1e-4 for every element. Note this is stricter than one ulp for
|
| 13 |
+
fp16/bf16 outputs of order 1 (spacing 2**-10 and 2**-8 there); the slack is real for float32 and
|
| 14 |
+
for small-magnitude outputs. A legitimate rounding shift in bf16 needs a per-case override.
|
| 15 |
+
|
| 16 |
+
Naming: the operator is called as ops.npu_{op_name} verbatim — the npu_ prefix is part of the
|
| 17 |
+
registered name; no _custom/_v2/_kernel suffixes, no wrapper function, no alias.
|
| 18 |
+
"""
|
| 19 |
+
import json
|
| 20 |
+
import os
|
| 21 |
+
import sys
|
| 22 |
+
|
| 23 |
+
import numpy as np
|
| 24 |
+
import torch
|
| 25 |
+
import torch_npu # noqa: F401
|
| 26 |
+
import gtsrusops as ops
|
| 27 |
+
|
| 28 |
+
OP_NAME = "interleave_rope"
|
| 29 |
+
OP_CAMEL = "InterleaveRope"
|
| 30 |
+
DEVICE = "npu:0"
|
| 31 |
+
|
| 32 |
+
# Actual binding signature (from op_desc inputs + attrs):
|
| 33 |
+
# npu_interleave_rope(x, cos, sin, out)
|
| 34 |
+
PARAM_NAMES = ["x", "cos", "sin"]
|
| 35 |
+
# Order in which the operator returns its outputs.
|
| 36 |
+
OUTPUT_KEYS = ["y"]
|
| 37 |
+
|
| 38 |
+
# Outputs that are intermediate statistics: stored as float32 but derived from the input tensor,
|
| 39 |
+
# so their real precision floor is the INPUT dtype, not their storage dtype.
|
| 40 |
+
INTERMEDIATE_OUTPUT_KEYS = set()
|
| 41 |
+
|
| 42 |
+
# Default tolerance. atol applies per element to diff / max(|ref|, 1); err_rate is the allowed
|
| 43 |
+
# fraction of elements exceeding atol. Do not widen these globally.
|
| 44 |
+
ATOL_DEFAULT = 1e-4
|
| 45 |
+
ERR_RATE_DEFAULT = 0.0
|
| 46 |
+
|
| 47 |
+
# Dtype floor, a couple of ulp of headroom — used only when an override sets "atol": None.
|
| 48 |
+
ATOL_BY_DTYPE = {torch.float16: 2 ** -8, torch.bfloat16: 2 ** -7, torch.float32: 2 ** -11}
|
| 49 |
+
|
| 50 |
+
# Per-case tolerance overrides, for cases where an intentional source change shifted the rounding
|
| 51 |
+
# (or where the kernel's reduction order is nondeterministic). Each entry needs a comment naming
|
| 52 |
+
# the case, the output tensor and the cause. {case_id: {"atol": float or None, "err_rate": float}}
|
| 53 |
+
TOLERANCE_OVERRIDES = {}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def resolve_data_root():
|
| 57 |
+
"""Find test_data/ in both layouts: sandbox (CWD/<op>/test_data) and local (script dir/test_data).
|
| 58 |
+
|
| 59 |
+
Do not branch on __file__.startswith("tmp") — that breaks when the client's temp naming changes.
|
| 60 |
+
Absolute host paths never resolve inside the sandbox, so everything is relative to here or CWD.
|
| 61 |
+
"""
|
| 62 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 63 |
+
candidates = [
|
| 64 |
+
os.path.join(here, "test_data"),
|
| 65 |
+
os.path.join(here, OP_NAME, "test_data"),
|
| 66 |
+
os.path.join(os.getcwd(), OP_NAME, "test_data"),
|
| 67 |
+
os.path.join(os.getcwd(), "test_data"),
|
| 68 |
+
]
|
| 69 |
+
for path in candidates:
|
| 70 |
+
if os.path.isdir(os.path.join(path, "golden_result", OP_CAMEL)):
|
| 71 |
+
return path
|
| 72 |
+
raise FileNotFoundError(
|
| 73 |
+
"golden data not found. Tried:\n " + "\n ".join(candidates)
|
| 74 |
+
+ f"\nRun datamining/{OP_NAME}_collect.sh first."
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
DATA_ROOT = resolve_data_root()
|
| 79 |
+
INPUT_DIR = os.path.join(DATA_ROOT, "golden_input", OP_CAMEL)
|
| 80 |
+
RESULT_DIR = os.path.join(DATA_ROOT, "golden_result", OP_CAMEL)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def compare_tensor(ref_t, cur_t, atol=ATOL_DEFAULT, err_rate=ERR_RATE_DEFAULT):
|
| 84 |
+
"""Two independent knobs:
|
| 85 |
+
atol — per-element threshold on diff / max(|ref|, 1)
|
| 86 |
+
err_rate — allowed fraction of elements exceeding atol
|
| 87 |
+
Never compare error_rate against atol; they are different quantities.
|
| 88 |
+
"""
|
| 89 |
+
if tuple(ref_t.shape) != tuple(cur_t.shape):
|
| 90 |
+
return float("inf"), 1.0, f"SHAPE {tuple(cur_t.shape)}!={tuple(ref_t.shape)}"
|
| 91 |
+
if ref_t.dtype != cur_t.dtype:
|
| 92 |
+
return float("inf"), 1.0, f"DTYPE {cur_t.dtype}!={ref_t.dtype}"
|
| 93 |
+
|
| 94 |
+
ref_np = ref_t.float().cpu().detach().numpy().flatten().astype("float64")
|
| 95 |
+
cur_np = cur_t.float().cpu().detach().numpy().flatten().astype("float64")
|
| 96 |
+
diff = np.abs(ref_np - cur_np)
|
| 97 |
+
rel = diff / np.maximum(np.abs(ref_np), 1.0)
|
| 98 |
+
|
| 99 |
+
max_diff = float(diff.max()) if diff.size else 0.0
|
| 100 |
+
error_rate = float((rel > atol).sum()) / max(ref_np.size, 1)
|
| 101 |
+
status = "PASS" if error_rate <= err_rate else "FAIL"
|
| 102 |
+
return max_diff, error_rate, status
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def tolerance_for(case_id, output_key, input_dtype, ref_dtype):
|
| 106 |
+
override = TOLERANCE_OVERRIDES.get(case_id)
|
| 107 |
+
if override is None:
|
| 108 |
+
return ATOL_DEFAULT, ERR_RATE_DEFAULT
|
| 109 |
+
atol = override.get("atol", ATOL_DEFAULT)
|
| 110 |
+
if atol is None:
|
| 111 |
+
dtype = input_dtype if output_key in INTERMEDIATE_OUTPUT_KEYS else ref_dtype
|
| 112 |
+
atol = max(ATOL_DEFAULT, ATOL_BY_DTYPE.get(dtype, 0.0))
|
| 113 |
+
return atol, override.get("err_rate", ERR_RATE_DEFAULT)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def run_case(case_id):
|
| 117 |
+
name = f"case_{case_id}"
|
| 118 |
+
input_data = torch.load(os.path.join(INPUT_DIR, f"{name}.pt"), weights_only=False)
|
| 119 |
+
golden = torch.load(os.path.join(RESULT_DIR, f"{name}.pt"), weights_only=False)
|
| 120 |
+
|
| 121 |
+
# Build kwargs dict — the wrapper (binding.py) calls the raw func by keyword,
|
| 122 |
+
# so we do the same here.
|
| 123 |
+
call_kwargs = {}
|
| 124 |
+
for pname in PARAM_NAMES:
|
| 125 |
+
if pname not in input_data:
|
| 126 |
+
raise KeyError(f"{name}: missing param '{pname}' in golden_input")
|
| 127 |
+
val = input_data[pname]
|
| 128 |
+
if isinstance(val, torch.Tensor):
|
| 129 |
+
call_kwargs[pname] = val.to(DEVICE)
|
| 130 |
+
elif isinstance(val, list):
|
| 131 |
+
call_kwargs[pname] = [v.to(DEVICE) if isinstance(v, torch.Tensor) else v for v in val]
|
| 132 |
+
else:
|
| 133 |
+
call_kwargs[pname] = val
|
| 134 |
+
|
| 135 |
+
# Size the output buffers from the golden tensors — this also checks shape and dtype.
|
| 136 |
+
out_bufs = []
|
| 137 |
+
for k in OUTPUT_KEYS:
|
| 138 |
+
if k in golden:
|
| 139 |
+
out_bufs.append(torch.empty_like(golden[k]).to(DEVICE))
|
| 140 |
+
# Call with positional args: (x, cos, sin, out)
|
| 141 |
+
positional = [call_kwargs[p] for p in PARAM_NAMES] + [out_bufs[0]]
|
| 142 |
+
outputs = ops.npu_interleave_rope(*positional)
|
| 143 |
+
torch.npu.synchronize()
|
| 144 |
+
|
| 145 |
+
outputs = [outputs] if isinstance(outputs, torch.Tensor) else list(outputs)
|
| 146 |
+
input_dtype = input_data[PARAM_NAMES[0]].dtype
|
| 147 |
+
|
| 148 |
+
results = []
|
| 149 |
+
for i, okey in enumerate(OUTPUT_KEYS):
|
| 150 |
+
if okey not in golden:
|
| 151 |
+
continue
|
| 152 |
+
if i >= len(outputs):
|
| 153 |
+
results.append((okey, float("nan"), 1.0, "MISSING"))
|
| 154 |
+
continue
|
| 155 |
+
atol, err_rate = tolerance_for(case_id, okey, input_dtype, golden[okey].dtype)
|
| 156 |
+
results.append((okey,) + compare_tensor(
|
| 157 |
+
golden[okey].to(DEVICE), outputs[i], atol=atol, err_rate=err_rate
|
| 158 |
+
))
|
| 159 |
+
return results
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def main():
|
| 163 |
+
manifest_path = os.path.join(DATA_ROOT, "cases_manifest.json")
|
| 164 |
+
if os.path.isfile(manifest_path):
|
| 165 |
+
with open(manifest_path) as fh:
|
| 166 |
+
collected = [c["id"] for c in json.load(fh)["cases"]]
|
| 167 |
+
else:
|
| 168 |
+
collected = sorted(
|
| 169 |
+
int(f[len("case_"):-len(".pt")])
|
| 170 |
+
for f in os.listdir(RESULT_DIR)
|
| 171 |
+
if f.startswith("case_") and f.endswith(".pt")
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
if not collected:
|
| 175 |
+
print(f"No golden cases in {RESULT_DIR} — run the collect script first.")
|
| 176 |
+
sys.exit(1)
|
| 177 |
+
|
| 178 |
+
print(f"Golden data: {DATA_ROOT} (atol={ATOL_DEFAULT:.0e})")
|
| 179 |
+
print(f"{'case':<12}{'output':<16}{'max_diff':<18}{'err_rate':<14}{'status':<8}")
|
| 180 |
+
print("-" * 68)
|
| 181 |
+
|
| 182 |
+
all_pass = True
|
| 183 |
+
for case_id in collected:
|
| 184 |
+
for okey, max_diff, error_rate, status in run_case(case_id):
|
| 185 |
+
if status != "PASS":
|
| 186 |
+
all_pass = False
|
| 187 |
+
print(f"{'case_' + str(case_id):<12}{okey:<16}{max_diff:<18.10f}{error_rate:<14.6f}{status:<8}")
|
| 188 |
+
|
| 189 |
+
print("-" * 68)
|
| 190 |
+
if all_pass:
|
| 191 |
+
print(f"ALL CHECKS PASSED ({len(collected)} cases)")
|
| 192 |
+
else:
|
| 193 |
+
print("REGRESSION DETECTED — do NOT re-collect golden data to make this pass.")
|
| 194 |
+
sys.exit(1)
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def _run_suite(runs):
|
| 200 |
+
"""重复整套测试 runs 次(warmup + 测量);单次 FAIL 不中断后续轮次。"""
|
| 201 |
+
all_ok = True
|
| 202 |
+
for run_idx in range(1, runs + 1):
|
| 203 |
+
print(f"\n{'=' * 98}")
|
| 204 |
+
print(f"Run {run_idx}/{runs}")
|
| 205 |
+
print(f"{'=' * 98}")
|
| 206 |
+
try:
|
| 207 |
+
main()
|
| 208 |
+
except SystemExit as exc:
|
| 209 |
+
if exc.code not in (0, None):
|
| 210 |
+
all_ok = False
|
| 211 |
+
return all_ok
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
if __name__ == "__main__":
|
| 215 |
+
import argparse
|
| 216 |
+
parser = argparse.ArgumentParser(description="repeated suite runs for warmup + measurement")
|
| 217 |
+
parser.add_argument("--runs", type=int, default=1,
|
| 218 |
+
help="Number of repeated runs (each run iterates all cases)")
|
| 219 |
+
args = parser.parse_args()
|
| 220 |
+
raise SystemExit(0 if _run_suite(args.runs) else 1)
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_graph/CMakeLists.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 2 |
+
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
# CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
message(STATUS "=== Debug: start ops.posembedding.interleave_rope.op_graph.CMakeLists.txt ")
|
| 12 |
+
add_graph_plugin_sources()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_graph/fusion_pass/.gitkeep
ADDED
|
File without changes
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_graph/interleave_rope_proto.h
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope_proto.h
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
#ifndef OPS_OP_PROTO_INC_INTERLEAVEROPE_OPS_H_
|
| 16 |
+
#define OPS_OP_PROTO_INC_INTERLEAVEROPE_OPS_H_
|
| 17 |
+
|
| 18 |
+
#include "graph/operator_reg.h"
|
| 19 |
+
namespace ge {
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @brief The fusion operator of Interleave RotaryPositionEmbedding.
|
| 23 |
+
*
|
| 24 |
+
* @par Inputs:
|
| 25 |
+
* @li x: A tensor. The type support float16, bfloat16. Format: ND.
|
| 26 |
+
* @li cos: A tensor. The type support float16, bfloat16. Format: ND.
|
| 27 |
+
* @li sin: A tensor. The type support float16, bfloat16. Format: ND.
|
| 28 |
+
*
|
| 29 |
+
* @par Outputs:
|
| 30 |
+
* y: A tensor. The type support float16, bfloat16. Format: ND.
|
| 31 |
+
*
|
| 32 |
+
* @par Restrictions:
|
| 33 |
+
* Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
|
| 34 |
+
*/
|
| 35 |
+
|
| 36 |
+
REG_OP(InterleaveRope)
|
| 37 |
+
.INPUT(x, TensorType({DT_FLOAT16, DT_BF16}))
|
| 38 |
+
.INPUT(cos, TensorType({DT_FLOAT16, DT_BF16}))
|
| 39 |
+
.INPUT(sin, TensorType({DT_FLOAT16, DT_BF16}))
|
| 40 |
+
.OUTPUT(y, TensorType({DT_FLOAT16, DT_BF16}))
|
| 41 |
+
.OP_END_FACTORY_REG(InterleaveRope)
|
| 42 |
+
|
| 43 |
+
} // namespace ge
|
| 44 |
+
|
| 45 |
+
#endif
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/CMakeLists.txt
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 2 |
+
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
# CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
message(STATUS "=== Debug: start ops.posembedding.interleave_rope.op_host.CMakeLists.txt ")
|
| 12 |
+
|
| 13 |
+
if (BUILD_OPEN_PROJECT)
|
| 14 |
+
message(STATUS "=== Debug: BUILD is BUILD_OPEN_PROJECT")
|
| 15 |
+
set(interleave_rope_depends posembedding/rotary_position_embedding CACHE INTERNAL "Dependencies for rotary_position_embedding")
|
| 16 |
+
target_sources(op_host_aclnnInner PRIVATE
|
| 17 |
+
interleave_rope_def.cpp
|
| 18 |
+
)
|
| 19 |
+
add_ops_compile_options(
|
| 20 |
+
OP_NAME InterleaveRope
|
| 21 |
+
OPTIONS --cce-auto-sync=on
|
| 22 |
+
-Wno-deprecated-declarations
|
| 23 |
+
-Werror
|
| 24 |
+
)
|
| 25 |
+
endif()
|
| 26 |
+
|
| 27 |
+
if(NOT BUILD_OPS_RTY_KERNEL)
|
| 28 |
+
message(STATUS "=== Debug: BUILD is NOT BUILD_OPS_RTY_KERNEL")
|
| 29 |
+
add_modules_sources(OPTYPE interleave_rope ACLNNTYPE aclnn_inner)
|
| 30 |
+
endif()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/ascend910_93/interleave_rope_binary.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op_type": "InterleaveRope",
|
| 3 |
+
"op_list": [
|
| 4 |
+
{
|
| 5 |
+
"bin_filename": "InterleaveRope_B8B1918CF4B1F919BC0F2A58138E37AB",
|
| 6 |
+
"inputs": [
|
| 7 |
+
{
|
| 8 |
+
"name": "x",
|
| 9 |
+
"index": 0,
|
| 10 |
+
"dtype": "float16",
|
| 11 |
+
"format": "ND",
|
| 12 |
+
"paramType": "required",
|
| 13 |
+
"shape": [
|
| 14 |
+
-2
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"name": "cos",
|
| 19 |
+
"index": 1,
|
| 20 |
+
"dtype": "float16",
|
| 21 |
+
"format": "ND",
|
| 22 |
+
"paramType": "required",
|
| 23 |
+
"shape": [
|
| 24 |
+
-2
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"name": "sin",
|
| 29 |
+
"index": 2,
|
| 30 |
+
"dtype": "float16",
|
| 31 |
+
"format": "ND",
|
| 32 |
+
"paramType": "required",
|
| 33 |
+
"shape": [
|
| 34 |
+
-2
|
| 35 |
+
]
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"outputs": [
|
| 39 |
+
{
|
| 40 |
+
"name": "y",
|
| 41 |
+
"index": 0,
|
| 42 |
+
"dtype": "float16",
|
| 43 |
+
"format": "ND",
|
| 44 |
+
"paramType": "required",
|
| 45 |
+
"shape": [
|
| 46 |
+
-2
|
| 47 |
+
]
|
| 48 |
+
}
|
| 49 |
+
]
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"bin_filename": "InterleaveRope_5A99F786F3FB24A70D3CBC0A8D16CA01",
|
| 53 |
+
"inputs": [
|
| 54 |
+
{
|
| 55 |
+
"name": "x",
|
| 56 |
+
"index": 0,
|
| 57 |
+
"dtype": "bfloat16",
|
| 58 |
+
"format": "ND",
|
| 59 |
+
"paramType": "required",
|
| 60 |
+
"shape": [
|
| 61 |
+
-2
|
| 62 |
+
]
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"name": "cos",
|
| 66 |
+
"index": 1,
|
| 67 |
+
"dtype": "bfloat16",
|
| 68 |
+
"format": "ND",
|
| 69 |
+
"paramType": "required",
|
| 70 |
+
"shape": [
|
| 71 |
+
-2
|
| 72 |
+
]
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"name": "sin",
|
| 76 |
+
"index": 2,
|
| 77 |
+
"dtype": "bfloat16",
|
| 78 |
+
"format": "ND",
|
| 79 |
+
"paramType": "required",
|
| 80 |
+
"shape": [
|
| 81 |
+
-2
|
| 82 |
+
]
|
| 83 |
+
}
|
| 84 |
+
],
|
| 85 |
+
"outputs": [
|
| 86 |
+
{
|
| 87 |
+
"name": "y",
|
| 88 |
+
"index": 0,
|
| 89 |
+
"dtype": "bfloat16",
|
| 90 |
+
"format": "ND",
|
| 91 |
+
"paramType": "required",
|
| 92 |
+
"shape": [
|
| 93 |
+
-2
|
| 94 |
+
]
|
| 95 |
+
}
|
| 96 |
+
]
|
| 97 |
+
}
|
| 98 |
+
]
|
| 99 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/ascend910_93/interleave_rope_simplified_key.ini
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
; 该文件主要影响 opc 工具 编译二进制kernel时, --simplified_key_mode 选项中填写的值,格式如下所示:
|
| 2 |
+
; [某算子]
|
| 3 |
+
; default=xx
|
| 4 |
+
; ascendxx=xx
|
| 5 |
+
; 其中,default为默认mode,ascnedxx为可选mode,如果不同芯片有差异化要求时,需要配置;
|
| 6 |
+
; 1)如果没有配置:非ascendC算子继续按空处理,即opc编译命令中不添加 --simplified_key_mode 选项,AscendC算子按照 simplified_key_mode=0 处理
|
| 7 |
+
; 2)如果仅有default配置:各个版本按default配置
|
| 8 |
+
; 3)如果仅有某些平台的配置,没有default配置:对应平台的按照配置的值传递,非对应平台的:非AscendC算子继续按空处理,AscendC算子按照 simplified_key_mode=0 处理
|
| 9 |
+
; 4)如果default配置和平台配置都有:对应平台的使用平台的配置,非对应的平台的以default值配置。
|
| 10 |
+
; 5)对于自定义simplified key的情况,需要在binary_simplified_key_mode.ini 文件中显式配置为None,不传入 --simplified_key_mode 选项,由opc工具和FE框架自行判断使用何种模式
|
| 11 |
+
; 6)是否是AscendC算子,由 ops/build-in/tbe/op_info_cfg/parser/ascendc_config.json 中配置的算子名字和对于的平台决定
|
| 12 |
+
[InterleaveRope]
|
| 13 |
+
default=0
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/ascend910b/interleave_rope_binary.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op_type": "InterleaveRope",
|
| 3 |
+
"op_list": [
|
| 4 |
+
{
|
| 5 |
+
"bin_filename": "InterleaveRope_B8B1918CF4B1F919BC0F2A58138E37AB",
|
| 6 |
+
"inputs": [
|
| 7 |
+
{
|
| 8 |
+
"name": "x",
|
| 9 |
+
"index": 0,
|
| 10 |
+
"dtype": "float16",
|
| 11 |
+
"format": "ND",
|
| 12 |
+
"paramType": "required",
|
| 13 |
+
"shape": [
|
| 14 |
+
-2
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"name": "cos",
|
| 19 |
+
"index": 1,
|
| 20 |
+
"dtype": "float16",
|
| 21 |
+
"format": "ND",
|
| 22 |
+
"paramType": "required",
|
| 23 |
+
"shape": [
|
| 24 |
+
-2
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"name": "sin",
|
| 29 |
+
"index": 2,
|
| 30 |
+
"dtype": "float16",
|
| 31 |
+
"format": "ND",
|
| 32 |
+
"paramType": "required",
|
| 33 |
+
"shape": [
|
| 34 |
+
-2
|
| 35 |
+
]
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"outputs": [
|
| 39 |
+
{
|
| 40 |
+
"name": "y",
|
| 41 |
+
"index": 0,
|
| 42 |
+
"dtype": "float16",
|
| 43 |
+
"format": "ND",
|
| 44 |
+
"paramType": "required",
|
| 45 |
+
"shape": [
|
| 46 |
+
-2
|
| 47 |
+
]
|
| 48 |
+
}
|
| 49 |
+
]
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"bin_filename": "InterleaveRope_5A99F786F3FB24A70D3CBC0A8D16CA01",
|
| 53 |
+
"inputs": [
|
| 54 |
+
{
|
| 55 |
+
"name": "x",
|
| 56 |
+
"index": 0,
|
| 57 |
+
"dtype": "bfloat16",
|
| 58 |
+
"format": "ND",
|
| 59 |
+
"paramType": "required",
|
| 60 |
+
"shape": [
|
| 61 |
+
-2
|
| 62 |
+
]
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"name": "cos",
|
| 66 |
+
"index": 1,
|
| 67 |
+
"dtype": "bfloat16",
|
| 68 |
+
"format": "ND",
|
| 69 |
+
"paramType": "required",
|
| 70 |
+
"shape": [
|
| 71 |
+
-2
|
| 72 |
+
]
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"name": "sin",
|
| 76 |
+
"index": 2,
|
| 77 |
+
"dtype": "bfloat16",
|
| 78 |
+
"format": "ND",
|
| 79 |
+
"paramType": "required",
|
| 80 |
+
"shape": [
|
| 81 |
+
-2
|
| 82 |
+
]
|
| 83 |
+
}
|
| 84 |
+
],
|
| 85 |
+
"outputs": [
|
| 86 |
+
{
|
| 87 |
+
"name": "y",
|
| 88 |
+
"index": 0,
|
| 89 |
+
"dtype": "bfloat16",
|
| 90 |
+
"format": "ND",
|
| 91 |
+
"paramType": "required",
|
| 92 |
+
"shape": [
|
| 93 |
+
-2
|
| 94 |
+
]
|
| 95 |
+
}
|
| 96 |
+
]
|
| 97 |
+
}
|
| 98 |
+
]
|
| 99 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/ascend910b/interleave_rope_simplified_key.ini
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
; 该文件主要影响 opc 工具 编译二进制kernel时, --simplified_key_mode 选项中填写的值,格式如下所示:
|
| 2 |
+
; [某算子]
|
| 3 |
+
; default=xx
|
| 4 |
+
; ascendxx=xx
|
| 5 |
+
; 其中,default为默认mode,ascnedxx为可选mode,如果不同芯片有差异化要求时,需要配置;
|
| 6 |
+
; 1)如果没有配置:非ascendC算子继续按空处理,即opc编译命令中不添加 --simplified_key_mode 选项,AscendC算子按照 simplified_key_mode=0 处理
|
| 7 |
+
; 2)如果仅有default配置:各个版本按default配置
|
| 8 |
+
; 3)如果仅有某些平台的配置,没有default配置:对应平台的按照配置的值传递,非对应平台的:非AscendC算子继续按空处理,AscendC算子按照 simplified_key_mode=0 处理
|
| 9 |
+
; 4)如果default配置和平台配置都有:对应平台的使用平台的配置,非对应的平台的以default值配置。
|
| 10 |
+
; 5)对于自定义simplified key的情况,需要在binary_simplified_key_mode.ini 文件中显式配置为None,不传入 --simplified_key_mode 选项,由opc工具和FE框架自行判断使用何种模式
|
| 11 |
+
; 6)是否是AscendC算子,由 ops/build-in/tbe/op_info_cfg/parser/ascendc_config.json 中配置的算子名字和对于的平台决定
|
| 12 |
+
[InterleaveRope]
|
| 13 |
+
default=0
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/kirin9030/interleave_rope_binary.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op_type": "InterleaveRope",
|
| 3 |
+
"op_list": [
|
| 4 |
+
{
|
| 5 |
+
"bin_filename": "InterleaveRope_B8B1918CF4B1F919BC0F2A58138E37AB",
|
| 6 |
+
"inputs": [
|
| 7 |
+
{
|
| 8 |
+
"name": "x",
|
| 9 |
+
"index": 0,
|
| 10 |
+
"dtype": "float16",
|
| 11 |
+
"format": "ND",
|
| 12 |
+
"paramType": "required",
|
| 13 |
+
"shape": [
|
| 14 |
+
-2
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"name": "cos",
|
| 19 |
+
"index": 1,
|
| 20 |
+
"dtype": "float16",
|
| 21 |
+
"format": "ND",
|
| 22 |
+
"paramType": "required",
|
| 23 |
+
"shape": [
|
| 24 |
+
-2
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"name": "sin",
|
| 29 |
+
"index": 2,
|
| 30 |
+
"dtype": "float16",
|
| 31 |
+
"format": "ND",
|
| 32 |
+
"paramType": "required",
|
| 33 |
+
"shape": [
|
| 34 |
+
-2
|
| 35 |
+
]
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"outputs": [
|
| 39 |
+
{
|
| 40 |
+
"name": "y",
|
| 41 |
+
"index": 0,
|
| 42 |
+
"dtype": "float16",
|
| 43 |
+
"format": "ND",
|
| 44 |
+
"paramType": "required",
|
| 45 |
+
"shape": [
|
| 46 |
+
-2
|
| 47 |
+
]
|
| 48 |
+
}
|
| 49 |
+
]
|
| 50 |
+
}
|
| 51 |
+
]
|
| 52 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/kirin9030/interleave_rope_simplified_key.ini
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
; 该文件主要影响 opc 工具 编译二进制kernel时, --simplified_key_mode 选项中填写的值,格式如下所示:
|
| 2 |
+
; [某算子]
|
| 3 |
+
; default=xx
|
| 4 |
+
; ascendxx=xx
|
| 5 |
+
; 其中,default为默认mode,ascnedxx为可选mode,如果不同芯片有差异化要求时,需要配置;
|
| 6 |
+
; 1)如果没有配置:非ascendC算子继续按空处理,即opc编译命令中不添加 --simplified_key_mode 选项,AscendC算子按照 simplified_key_mode=0 处理
|
| 7 |
+
; 2)如果仅有default配置:各个版本按default配置
|
| 8 |
+
; 3)如果仅有某些平台的配置,没有default配置:对应平台的按照配置的值传递,非对应平台的:非AscendC算子继续按空处理,AscendC算子按照 simplified_key_mode=0 处理
|
| 9 |
+
; 4)如果default配置和平台配置都有:对应平台的使用平台的配置,非对应的平台的以default值配置。
|
| 10 |
+
; 5)对于自定义simplified key的情况,需要在binary_simplified_key_mode.ini 文件中显式配置为None,不传入 --simplified_key_mode 选项,由opc工具和FE框架自行判断使用何种模式
|
| 11 |
+
; 6)是否是AscendC算子,由 ops/build-in/tbe/op_info_cfg/parser/ascendc_config.json 中配置的算子名字和对于的平台决定
|
| 12 |
+
[InterleaveRope]
|
| 13 |
+
default=0
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/kirinx90/interleave_rope_binary.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op_type": "InterleaveRope",
|
| 3 |
+
"op_list": [
|
| 4 |
+
{
|
| 5 |
+
"bin_filename": "InterleaveRope_B8B1918CF4B1F919BC0F2A58138E37AB",
|
| 6 |
+
"inputs": [
|
| 7 |
+
{
|
| 8 |
+
"name": "x",
|
| 9 |
+
"index": 0,
|
| 10 |
+
"dtype": "float16",
|
| 11 |
+
"format": "ND",
|
| 12 |
+
"paramType": "required",
|
| 13 |
+
"shape": [
|
| 14 |
+
-2
|
| 15 |
+
]
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"name": "cos",
|
| 19 |
+
"index": 1,
|
| 20 |
+
"dtype": "float16",
|
| 21 |
+
"format": "ND",
|
| 22 |
+
"paramType": "required",
|
| 23 |
+
"shape": [
|
| 24 |
+
-2
|
| 25 |
+
]
|
| 26 |
+
},
|
| 27 |
+
{
|
| 28 |
+
"name": "sin",
|
| 29 |
+
"index": 2,
|
| 30 |
+
"dtype": "float16",
|
| 31 |
+
"format": "ND",
|
| 32 |
+
"paramType": "required",
|
| 33 |
+
"shape": [
|
| 34 |
+
-2
|
| 35 |
+
]
|
| 36 |
+
}
|
| 37 |
+
],
|
| 38 |
+
"outputs": [
|
| 39 |
+
{
|
| 40 |
+
"name": "y",
|
| 41 |
+
"index": 0,
|
| 42 |
+
"dtype": "float16",
|
| 43 |
+
"format": "ND",
|
| 44 |
+
"paramType": "required",
|
| 45 |
+
"shape": [
|
| 46 |
+
-2
|
| 47 |
+
]
|
| 48 |
+
}
|
| 49 |
+
]
|
| 50 |
+
}
|
| 51 |
+
]
|
| 52 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/config/kirinx90/interleave_rope_simplified_key.ini
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
; 该文件主要影响 opc 工具 编译二进制kernel时, --simplified_key_mode 选项中填写的值,格式如下所示:
|
| 2 |
+
; [某算子]
|
| 3 |
+
; default=xx
|
| 4 |
+
; ascendxx=xx
|
| 5 |
+
; 其中,default为默认mode,ascnedxx为可选mode,如果不同芯片有差异化要求时,需要配置;
|
| 6 |
+
; 1)如果没有配置:非ascendC算子继续按空处理,即opc编译命令中不添加 --simplified_key_mode 选项,AscendC算子按照 simplified_key_mode=0 处理
|
| 7 |
+
; 2)如果仅有default配置:各个版本按default配置
|
| 8 |
+
; 3)如果仅有某些平台的配置,没有default配置:对应平台的按照配置的值传递,非对应平台的:非AscendC算子继续按空处理,AscendC算子按照 simplified_key_mode=0 处理
|
| 9 |
+
; 4)如果default配置和平台配置都有:对应平台的使用平台的配置,非对应的平台的以default值配置。
|
| 10 |
+
; 5)对于自定义simplified key的情况,需要在binary_simplified_key_mode.ini 文件中显式配置为None,不传入 --simplified_key_mode 选项,由opc工具和FE框架自行判断使用何种模式
|
| 11 |
+
; 6)是否是AscendC算子,由 ops/build-in/tbe/op_info_cfg/parser/ascendc_config.json 中配置的算子名字和对于的平台决定
|
| 12 |
+
[InterleaveRope]
|
| 13 |
+
default=0
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/interleave_rope_def.cpp
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope_def.cpp
|
| 13 |
+
* \brief InterleaveRope op host config
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#include "register/op_def_registry.h"
|
| 17 |
+
|
| 18 |
+
namespace ops {
|
| 19 |
+
class InterleaveRope : public OpDef {
|
| 20 |
+
public:
|
| 21 |
+
explicit InterleaveRope(const char* name) : OpDef(name)
|
| 22 |
+
{
|
| 23 |
+
this->Input("x")
|
| 24 |
+
.ParamType(REQUIRED)
|
| 25 |
+
.DataType({ge::DT_FLOAT16, ge::DT_BF16})
|
| 26 |
+
.Format({ge::FORMAT_ND, ge::FORMAT_ND})
|
| 27 |
+
.UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND})
|
| 28 |
+
.AutoContiguous();
|
| 29 |
+
this->Input("cos")
|
| 30 |
+
.ParamType(REQUIRED)
|
| 31 |
+
.DataType({ge::DT_FLOAT16, ge::DT_BF16})
|
| 32 |
+
.Format({ge::FORMAT_ND, ge::FORMAT_ND})
|
| 33 |
+
.UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND})
|
| 34 |
+
.AutoContiguous();
|
| 35 |
+
this->Input("sin")
|
| 36 |
+
.ParamType(REQUIRED)
|
| 37 |
+
.DataType({ge::DT_FLOAT16, ge::DT_BF16})
|
| 38 |
+
.Format({ge::FORMAT_ND, ge::FORMAT_ND})
|
| 39 |
+
.UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND})
|
| 40 |
+
.AutoContiguous();
|
| 41 |
+
this->Output("y")
|
| 42 |
+
.ParamType(REQUIRED)
|
| 43 |
+
.DataType({ge::DT_FLOAT16, ge::DT_BF16})
|
| 44 |
+
.Format({ge::FORMAT_ND, ge::FORMAT_ND})
|
| 45 |
+
.UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND});
|
| 46 |
+
|
| 47 |
+
this->AICore().AddConfig("ascend910b");
|
| 48 |
+
this->AICore().AddConfig("ascend910_93");
|
| 49 |
+
|
| 50 |
+
OpAICoreConfig config_kirin = GetKirinCoreConfig();
|
| 51 |
+
this->AICore().AddConfig("kirinx90", config_kirin);
|
| 52 |
+
this->AICore().AddConfig("kirin9030", config_kirin);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
private:
|
| 56 |
+
OpAICoreConfig GetKirinCoreConfig() const
|
| 57 |
+
{
|
| 58 |
+
OpAICoreConfig config_kirin;
|
| 59 |
+
config_kirin.DynamicCompileStaticFlag(true)
|
| 60 |
+
.DynamicFormatFlag(true)
|
| 61 |
+
.DynamicRankSupportFlag(true)
|
| 62 |
+
.DynamicShapeSupportFlag(true)
|
| 63 |
+
.NeedCheckSupportFlag(false)
|
| 64 |
+
.PrecisionReduceFlag(true);
|
| 65 |
+
config_kirin.Input("x")
|
| 66 |
+
.ParamType(REQUIRED)
|
| 67 |
+
.DataType({ge::DT_FLOAT16})
|
| 68 |
+
.Format({ge::FORMAT_ND})
|
| 69 |
+
.UnknownShapeFormat({ge::FORMAT_ND})
|
| 70 |
+
.AutoContiguous();
|
| 71 |
+
config_kirin.Input("cos")
|
| 72 |
+
.ParamType(REQUIRED)
|
| 73 |
+
.DataType({ge::DT_FLOAT16})
|
| 74 |
+
.Format({ge::FORMAT_ND})
|
| 75 |
+
.UnknownShapeFormat({ge::FORMAT_ND})
|
| 76 |
+
.AutoContiguous();
|
| 77 |
+
config_kirin.Input("sin")
|
| 78 |
+
.ParamType(REQUIRED)
|
| 79 |
+
.DataType({ge::DT_FLOAT16})
|
| 80 |
+
.Format({ge::FORMAT_ND})
|
| 81 |
+
.UnknownShapeFormat({ge::FORMAT_ND})
|
| 82 |
+
.AutoContiguous();
|
| 83 |
+
config_kirin.Output("y")
|
| 84 |
+
.ParamType(REQUIRED)
|
| 85 |
+
.DataType({ge::DT_FLOAT16})
|
| 86 |
+
.Format({ge::FORMAT_ND})
|
| 87 |
+
.UnknownShapeFormat({ge::FORMAT_ND});
|
| 88 |
+
return config_kirin;
|
| 89 |
+
}
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
OP_ADD(InterleaveRope);
|
| 93 |
+
} // namespace ops
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/interleave_rope_infershape.cpp
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope_infer.cpp
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
#include <sstream>
|
| 16 |
+
#include <string>
|
| 17 |
+
#include <vector>
|
| 18 |
+
#include "register/op_def_registry.h"
|
| 19 |
+
#include "log/log.h"
|
| 20 |
+
#include "util/math_util.h"
|
| 21 |
+
#include "util/shape_util.h"
|
| 22 |
+
|
| 23 |
+
using namespace ge;
|
| 24 |
+
namespace ops {
|
| 25 |
+
constexpr size_t INPUT_IDX_X = 0;
|
| 26 |
+
constexpr size_t INPUT_IDX_COS = 1;
|
| 27 |
+
constexpr size_t INPUT_IDX_SIN = 2;
|
| 28 |
+
constexpr size_t OUTPUT_IDX_Y = 0;
|
| 29 |
+
|
| 30 |
+
graphStatus InferShape4InterleaveRope(gert::InferShapeContext* context)
|
| 31 |
+
{
|
| 32 |
+
OP_LOGI(context, "Begin to do InferShape4InterleaveRope.");
|
| 33 |
+
|
| 34 |
+
const gert::Shape* xInputShape = context->GetInputShape(INPUT_IDX_X);
|
| 35 |
+
OP_CHECK_NULL_WITH_CONTEXT(context, xInputShape);
|
| 36 |
+
gert::Shape* yShape = context->GetOutputShape(OUTPUT_IDX_Y);
|
| 37 |
+
OP_CHECK_NULL_WITH_CONTEXT(context, yShape);
|
| 38 |
+
*yShape = *xInputShape;
|
| 39 |
+
|
| 40 |
+
OP_LOGD(context, "End to do InferShape4InterleaveRope.");
|
| 41 |
+
return GRAPH_SUCCESS;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
graphStatus InferDtype4InterleaveRope(gert::InferDataTypeContext* context)
|
| 45 |
+
{
|
| 46 |
+
OP_LOGD(context, "InferDtype4InterleaveRope enter");
|
| 47 |
+
|
| 48 |
+
auto x_dtype = context->GetInputDataType(INPUT_IDX_X);
|
| 49 |
+
context->SetOutputDataType(OUTPUT_IDX_Y, x_dtype);
|
| 50 |
+
|
| 51 |
+
OP_LOGD(context, "InferDtype4InterleaveRope end");
|
| 52 |
+
|
| 53 |
+
return GRAPH_SUCCESS;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
IMPL_OP_INFERSHAPE(InterleaveRope).InferShape(InferShape4InterleaveRope).InferDataType(InferDtype4InterleaveRope);
|
| 57 |
+
} // namespace ops
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/interleave_rope_tiling.cpp
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope_tiling.cpp
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
#include "interleave_rope_tiling.h"
|
| 16 |
+
#include "register/op_def_registry.h"
|
| 17 |
+
#include "tiling/tiling_api.h"
|
| 18 |
+
#include "log/log.h"
|
| 19 |
+
|
| 20 |
+
namespace optiling {
|
| 21 |
+
|
| 22 |
+
constexpr int64_t X_INDEX = 0;
|
| 23 |
+
constexpr int64_t COS_INDEX = 1;
|
| 24 |
+
constexpr int64_t SIN_INDEX = 2;
|
| 25 |
+
constexpr int64_t INPUT_NUM = 3;
|
| 26 |
+
constexpr int64_t OUTPUT_NUM = 1;
|
| 27 |
+
constexpr int64_t SHAPE_IDX_B = 0;
|
| 28 |
+
constexpr int64_t SHAPE_IDX_N = 1;
|
| 29 |
+
constexpr int64_t SHAPE_IDX_S = 2;
|
| 30 |
+
constexpr int64_t SHAPE_IDX_D = 3;
|
| 31 |
+
constexpr int64_t DIM_SIZE = 4;
|
| 32 |
+
constexpr int64_t DIM_ONE = 1;
|
| 33 |
+
constexpr int64_t DEFAULT_WORKSPACE_SIZE = 32;
|
| 34 |
+
constexpr int64_t DEFAULT_HIDDEN_DIM = 64;
|
| 35 |
+
constexpr int64_t DEFAULT_BATCH_SIZE = 32;
|
| 36 |
+
constexpr int64_t DEFAULT_NUM_HEAD = 32;
|
| 37 |
+
constexpr int64_t DEFAULT_BATCH_PER_BLOCK = 4;
|
| 38 |
+
constexpr uint64_t SPLIT_BATCH = 0;
|
| 39 |
+
constexpr uint64_t SPLIT_NS = 1;
|
| 40 |
+
constexpr uint64_t SPLIT_N = 2;
|
| 41 |
+
constexpr uint64_t SPLIT_S = 3;
|
| 42 |
+
constexpr uint64_t SPLIT_BNS = 4;
|
| 43 |
+
|
| 44 |
+
constexpr int64_t NUM_TWO = 2;
|
| 45 |
+
constexpr int64_t NUM_FOUR = 4;
|
| 46 |
+
constexpr int64_t NUM_SIX = 6;
|
| 47 |
+
constexpr int64_t NUM_TEN = 10;
|
| 48 |
+
constexpr int64_t MIN_SEQUANCE_LEN = 512;
|
| 49 |
+
|
| 50 |
+
constexpr uint64_t FIXED_BNSD_B11D_TILINGKEY = 1000;
|
| 51 |
+
constexpr uint64_t B11D_TILINGKEY = 2000;
|
| 52 |
+
constexpr uint64_t B1SD_TILINGKEY = 3000;
|
| 53 |
+
constexpr uint64_t BN1D_TILINGKEY = 4000;
|
| 54 |
+
constexpr uint64_t BNSD_TILINGKEY = 5000;
|
| 55 |
+
|
| 56 |
+
static std::tuple<int64_t, int64_t, int64_t, int64_t> GetShapeTuple(
|
| 57 |
+
const gert::TilingContext* context, const int64_t index = 0)
|
| 58 |
+
{
|
| 59 |
+
const gert::StorageShape* shapePtr = context->GetInputShape(index);
|
| 60 |
+
OP_CHECK_IF(
|
| 61 |
+
shapePtr == nullptr, OP_LOGE(context, "Shape is nullptr."), return std::make_tuple(0, 0, 0, 0));
|
| 62 |
+
|
| 63 |
+
// check shape length is DIM_SIZE
|
| 64 |
+
OP_CHECK_IF(
|
| 65 |
+
shapePtr->GetStorageShape().GetDimNum() != DIM_SIZE,
|
| 66 |
+
OP_LOGE(context, "Shape must be (B,N,S,D)."), return std::make_tuple(0, 0, 0, 0));
|
| 67 |
+
|
| 68 |
+
return std::make_tuple(
|
| 69 |
+
shapePtr->GetStorageShape().GetDim(SHAPE_IDX_B), shapePtr->GetStorageShape().GetDim(SHAPE_IDX_N),
|
| 70 |
+
shapePtr->GetStorageShape().GetDim(SHAPE_IDX_S), shapePtr->GetStorageShape().GetDim(SHAPE_IDX_D));
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
ge::graphStatus InterleaveRopeTiling::GetPlatformInfo()
|
| 74 |
+
{
|
| 75 |
+
auto platformInfo = context_->GetPlatformInfo();
|
| 76 |
+
if (platformInfo == nullptr) {
|
| 77 |
+
auto compileInfoPtr = reinterpret_cast<const InterleaveRopeCompileInfo*>(context_->GetCompileInfo());
|
| 78 |
+
OP_CHECK_IF(
|
| 79 |
+
compileInfoPtr == nullptr, OP_LOGE(context_, "CompileInfo is nullptr."),
|
| 80 |
+
return ge::GRAPH_FAILED);
|
| 81 |
+
coreNum_ = compileInfoPtr->coreNum;
|
| 82 |
+
ubSize_ = compileInfoPtr->ubSize;
|
| 83 |
+
} else {
|
| 84 |
+
auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo);
|
| 85 |
+
coreNum_ = ascendcPlatform.GetCoreNumAiv();
|
| 86 |
+
uint64_t ubSize = 0;
|
| 87 |
+
ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize);
|
| 88 |
+
ubSize_ = ubSize;
|
| 89 |
+
}
|
| 90 |
+
return ge::GRAPH_SUCCESS;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
ge::graphStatus InterleaveRopeTiling::GetShapeAttrsInfo()
|
| 94 |
+
{
|
| 95 |
+
auto xShapeTuple = GetShapeTuple(context_, X_INDEX);
|
| 96 |
+
auto cosShapeTuple = GetShapeTuple(context_, COS_INDEX);
|
| 97 |
+
|
| 98 |
+
batchSize_ = std::get<SHAPE_IDX_B>(xShapeTuple);
|
| 99 |
+
numHead_ = std::get<SHAPE_IDX_N>(xShapeTuple);
|
| 100 |
+
seqLength_ = std::get<SHAPE_IDX_S>(xShapeTuple);
|
| 101 |
+
hiddenDim_ = std::get<SHAPE_IDX_D>(xShapeTuple);
|
| 102 |
+
OP_CHECK_IF(
|
| 103 |
+
batchSize_ <= 0, OP_LOGE(context_, "batchSize should be greater than 0."),
|
| 104 |
+
return ge::GRAPH_FAILED);
|
| 105 |
+
OP_CHECK_IF(
|
| 106 |
+
numHead_ <= 0, OP_LOGE(context_, "numHead should be greater than 0."), return ge::GRAPH_FAILED);
|
| 107 |
+
OP_CHECK_IF(
|
| 108 |
+
seqLength_ <= 0, OP_LOGE(context_, "seqLength should be greater than 0."),
|
| 109 |
+
return ge::GRAPH_FAILED);
|
| 110 |
+
OP_CHECK_IF(
|
| 111 |
+
hiddenDim_ <= 0, OP_LOGE(context_, "hiddenDim should be greater than 0."),
|
| 112 |
+
return ge::GRAPH_FAILED);
|
| 113 |
+
|
| 114 |
+
tilingData_.set_batchSize(batchSize_);
|
| 115 |
+
tilingData_.set_numHead(numHead_);
|
| 116 |
+
tilingData_.set_seqLength(seqLength_);
|
| 117 |
+
tilingData_.set_hiddenDim(hiddenDim_);
|
| 118 |
+
|
| 119 |
+
// Check hiddenDim must be DEFAULT_HIDDEN_DIM
|
| 120 |
+
OP_CHECK_IF(
|
| 121 |
+
hiddenDim_ != DEFAULT_HIDDEN_DIM, OP_LOGE(context_, "hiddenDim must be 64."),
|
| 122 |
+
return ge::GRAPH_FAILED);
|
| 123 |
+
// Check cos sin shape must be same
|
| 124 |
+
OP_CHECK_IF(
|
| 125 |
+
cosShapeTuple != GetShapeTuple(context_, SIN_INDEX),
|
| 126 |
+
OP_LOGE(context_, "cos and sin shape must be the same."), return ge::GRAPH_FAILED);
|
| 127 |
+
|
| 128 |
+
// Check cosB must be batchSize
|
| 129 |
+
cosB_ = std::get<SHAPE_IDX_B>(cosShapeTuple);
|
| 130 |
+
OP_CHECK_IF(
|
| 131 |
+
cosB_ != batchSize_, OP_LOGE(context_, "cos or sin batchSize must same as x batchSize."),
|
| 132 |
+
return ge::GRAPH_FAILED);
|
| 133 |
+
// Check cosN must be 1
|
| 134 |
+
cosN_ = std::get<SHAPE_IDX_N>(cosShapeTuple);
|
| 135 |
+
OP_CHECK_IF(
|
| 136 |
+
cosN_ != 1, OP_LOGE(context_, "cos or sin numHead must be 1."), return ge::GRAPH_FAILED);
|
| 137 |
+
// Check cosS must 1
|
| 138 |
+
cosS_ = std::get<SHAPE_IDX_S>(cosShapeTuple);
|
| 139 |
+
OP_CHECK_IF(
|
| 140 |
+
cosS_ != seqLength_ && cosS_ != 1,
|
| 141 |
+
OP_LOGE(context_, "cos or sin seqLength must be 1 or the same as x seqLength."),
|
| 142 |
+
return ge::GRAPH_FAILED);
|
| 143 |
+
// Check cosD must be hiddenDim
|
| 144 |
+
int64_t cosD = std::get<SHAPE_IDX_D>(cosShapeTuple);
|
| 145 |
+
OP_CHECK_IF(
|
| 146 |
+
cosD != hiddenDim_, OP_LOGE(context_, "cos or sin hiddenDim must same as x hiddenDim."),
|
| 147 |
+
return ge::GRAPH_FAILED);
|
| 148 |
+
|
| 149 |
+
return ge::GRAPH_SUCCESS;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
ge::graphStatus InterleaveRopeTiling::SplitBlockForFixBNS()
|
| 153 |
+
{
|
| 154 |
+
int64_t batchsPerBlock = DEFAULT_BATCH_PER_BLOCK;
|
| 155 |
+
tilingData_.set_batchsPerBlock(batchsPerBlock);
|
| 156 |
+
tilingData_.set_batchsLastBlock(batchsPerBlock);
|
| 157 |
+
tilingData_.set_numBlocks(batchSize_ / batchsPerBlock);
|
| 158 |
+
return ge::GRAPH_SUCCESS;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
ge::graphStatus InterleaveRopeTiling::SplitBlockForBatch()
|
| 162 |
+
{
|
| 163 |
+
int64_t batchsPerBlock = Ops::Base::CeilDiv(batchSize_, static_cast<int64_t>(coreNum_));
|
| 164 |
+
int64_t needBlocks = Ops::Base::CeilDiv(batchSize_, batchsPerBlock);
|
| 165 |
+
int64_t batchsLastBlock = batchSize_ - (needBlocks - 1) * batchsPerBlock;
|
| 166 |
+
tilingData_.set_batchsPerBlock(batchsPerBlock);
|
| 167 |
+
tilingData_.set_batchsLastBlock(batchsLastBlock);
|
| 168 |
+
tilingData_.set_numBlocks(needBlocks);
|
| 169 |
+
|
| 170 |
+
if (tilingKey_ == B11D_TILINGKEY) {
|
| 171 |
+
int64_t NS = numHead_ * seqLength_;
|
| 172 |
+
tilingData_.set_hiddenDimCountPerBlock(NS);
|
| 173 |
+
tilingData_.set_hiddenDimCountLastBlock(NS);
|
| 174 |
+
SplitHiddenDim();
|
| 175 |
+
return ge::GRAPH_SUCCESS;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
if (tilingKey_ == B1SD_TILINGKEY) {
|
| 179 |
+
tilingData_.set_hiddenDimCountPerBlock(seqLength_);
|
| 180 |
+
tilingData_.set_hiddenDimCountLastBlock(seqLength_);
|
| 181 |
+
SplitHiddenDim();
|
| 182 |
+
return ge::GRAPH_SUCCESS;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
return ge::GRAPH_SUCCESS;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
ge::graphStatus InterleaveRopeTiling::SplitBlockForNS()
|
| 189 |
+
{
|
| 190 |
+
tilingData_.set_batchsPerBlock(batchSize_);
|
| 191 |
+
tilingData_.set_batchsLastBlock(batchSize_);
|
| 192 |
+
|
| 193 |
+
int64_t NS = numHead_ * seqLength_;
|
| 194 |
+
int64_t NSPerBlock = Ops::Base::CeilDiv(NS, static_cast<int64_t>(coreNum_));
|
| 195 |
+
int64_t needBlocks = Ops::Base::CeilDiv(NS, NSPerBlock);
|
| 196 |
+
int64_t NSLastBlock = NS - (needBlocks - 1) * NSPerBlock;
|
| 197 |
+
tilingData_.set_numBlocks(needBlocks);
|
| 198 |
+
|
| 199 |
+
tilingData_.set_hiddenDimCountPerBlock(NSPerBlock);
|
| 200 |
+
tilingData_.set_hiddenDimCountLastBlock(NSLastBlock);
|
| 201 |
+
SplitHiddenDim();
|
| 202 |
+
return ge::GRAPH_SUCCESS;
|
| 203 |
+
}
|
| 204 |
+
|
| 205 |
+
ge::graphStatus InterleaveRopeTiling::SplitHiddenDim()
|
| 206 |
+
{
|
| 207 |
+
int64_t hiddenDimCountPerBlock = tilingData_.get_hiddenDimCountPerBlock();
|
| 208 |
+
int64_t hiddenDimCountLastBlock = tilingData_.get_hiddenDimCountLastBlock();
|
| 209 |
+
|
| 210 |
+
int64_t hiddenDimLoopsPerBlock;
|
| 211 |
+
int64_t hiddenDimCountPerLoopPerBlock;
|
| 212 |
+
int64_t hiddenDimCountLastLoopPerBlock;
|
| 213 |
+
SplitHiddenDimInblock(
|
| 214 |
+
hiddenDimCountPerBlock, hiddenDimLoopsPerBlock, hiddenDimCountPerLoopPerBlock, hiddenDimCountLastLoopPerBlock);
|
| 215 |
+
tilingData_.set_hiddenDimLoopsPerBlock(hiddenDimLoopsPerBlock);
|
| 216 |
+
tilingData_.set_hiddenDimCountPerLoopPerBlock(hiddenDimCountPerLoopPerBlock);
|
| 217 |
+
tilingData_.set_hiddenDimCountLastLoopPerBlock(hiddenDimCountLastLoopPerBlock);
|
| 218 |
+
OP_LOGD(
|
| 219 |
+
context_,
|
| 220 |
+
"hiddenDimLoopsPerBlock is: %ld, hiddenDimCountPerLoopPerBlock is: %ld, hiddenDimCountLastLoopPerBlock is: "
|
| 221 |
+
"%ld.",
|
| 222 |
+
hiddenDimLoopsPerBlock, hiddenDimCountPerLoopPerBlock, hiddenDimCountLastLoopPerBlock);
|
| 223 |
+
|
| 224 |
+
int64_t hiddenDimLoopsLastBlock;
|
| 225 |
+
int64_t hiddenDimCountPerLoopLastBlock;
|
| 226 |
+
int64_t hiddenDimCountLastLoopLastBlock;
|
| 227 |
+
SplitHiddenDimInblock(
|
| 228 |
+
hiddenDimCountLastBlock, hiddenDimLoopsLastBlock, hiddenDimCountPerLoopLastBlock,
|
| 229 |
+
hiddenDimCountLastLoopLastBlock);
|
| 230 |
+
tilingData_.set_hiddenDimLoopsLastBlock(hiddenDimLoopsLastBlock);
|
| 231 |
+
tilingData_.set_hiddenDimCountPerLoopLastBlock(hiddenDimCountPerLoopLastBlock);
|
| 232 |
+
tilingData_.set_hiddenDimCountLastLoopLastBlock(hiddenDimCountLastLoopLastBlock);
|
| 233 |
+
OP_LOGD(
|
| 234 |
+
context_,
|
| 235 |
+
"hiddenDimLoopsLastBlock is: %ld, hiddenDimCountPerLoopLastBlock is: %ld, hiddenDimCountLastLoopLastBlock is: "
|
| 236 |
+
"%ld.",
|
| 237 |
+
hiddenDimLoopsLastBlock, hiddenDimCountPerLoopLastBlock, hiddenDimCountLastLoopLastBlock);
|
| 238 |
+
return ge::GRAPH_SUCCESS;
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
ge::graphStatus InterleaveRopeTiling::SplitHiddenDimInblock(
|
| 242 |
+
int64_t hiddenDimCount, int64_t& hiddenDimLoops, int64_t& hiddenDimCountPerLoop, int64_t& hiddenDimCountLastLoop)
|
| 243 |
+
{
|
| 244 |
+
if (tilingKey_ == B11D_TILINGKEY) {
|
| 245 |
+
hiddenDimCountPerLoop =
|
| 246 |
+
(ubSize_ - hiddenDim_ * sizeof(float) * NUM_FOUR) / (hiddenDim_ * sizeof(float) * NUM_SIX) / NUM_TWO;
|
| 247 |
+
} else if (tilingKey_ == B1SD_TILINGKEY) {
|
| 248 |
+
hiddenDimCountPerLoop = (ubSize_) / (hiddenDim_ * sizeof(float) * NUM_TEN) / NUM_TWO;
|
| 249 |
+
}
|
| 250 |
+
hiddenDimCountPerLoop = hiddenDimCount > hiddenDimCountPerLoop ? hiddenDimCountPerLoop : hiddenDimCount;
|
| 251 |
+
hiddenDimLoops = Ops::Base::CeilDiv(hiddenDimCount, hiddenDimCountPerLoop);
|
| 252 |
+
hiddenDimCountLastLoop = hiddenDimCount - (hiddenDimLoops - 1) * hiddenDimCountPerLoop;
|
| 253 |
+
return ge::GRAPH_SUCCESS;
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
bool InterleaveRopeTiling::IsCapable()
|
| 257 |
+
{
|
| 258 |
+
return true;
|
| 259 |
+
}
|
| 260 |
+
|
| 261 |
+
ge::graphStatus InterleaveRopeTiling::DoOpTiling()
|
| 262 |
+
{
|
| 263 |
+
OP_LOGD(context_, "Start DoOpTiling.");
|
| 264 |
+
|
| 265 |
+
if (seqLength_ >= MIN_SEQUANCE_LEN && cosS_ == seqLength_) {
|
| 266 |
+
int64_t seqPerBlock = Ops::Base::CeilDiv(seqLength_, static_cast<int64_t>(coreNum_));
|
| 267 |
+
int64_t needBlocks = Ops::Base::CeilDiv(seqLength_, seqPerBlock);
|
| 268 |
+
tilingData_.set_numBlocks(needBlocks);
|
| 269 |
+
tilingKey_ = BN1D_TILINGKEY;
|
| 270 |
+
return ge::GRAPH_SUCCESS;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
if (batchSize_ == DEFAULT_BATCH_SIZE && numHead_ == DEFAULT_NUM_HEAD && seqLength_ == 1 && cosN_ == 1 &&
|
| 274 |
+
cosS_ == 1) {
|
| 275 |
+
tilingKey_ = FIXED_BNSD_B11D_TILINGKEY;
|
| 276 |
+
SplitBlockForFixBNS();
|
| 277 |
+
} else if (cosN_ == 1 && cosS_ == 1) { // bnsd -> b11d
|
| 278 |
+
tilingKey_ = B11D_TILINGKEY;
|
| 279 |
+
if (batchSize_ >= static_cast<int64_t>(coreNum_) || batchSize_ >= numHead_ * seqLength_) {
|
| 280 |
+
tilingData_.set_splitAxis(SPLIT_BATCH);
|
| 281 |
+
SplitBlockForBatch();
|
| 282 |
+
} else {
|
| 283 |
+
tilingData_.set_splitAxis(SPLIT_NS);
|
| 284 |
+
SplitBlockForNS();
|
| 285 |
+
}
|
| 286 |
+
} else if (cosN_ == 1) { // bnsd -> b1sd
|
| 287 |
+
tilingKey_ = B1SD_TILINGKEY;
|
| 288 |
+
tilingData_.set_splitAxis(SPLIT_BATCH);
|
| 289 |
+
SplitBlockForBatch();
|
| 290 |
+
} else {
|
| 291 |
+
OP_LOGE(context_, "DoOpTiling failed, set tilingkey failed.");
|
| 292 |
+
return ge::GRAPH_FAILED;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
OP_LOGD(context_, "DoOpTiling success.");
|
| 296 |
+
return ge::GRAPH_SUCCESS;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
ge::graphStatus InterleaveRopeTiling::DoLibApiTiling()
|
| 300 |
+
{
|
| 301 |
+
return ge::GRAPH_SUCCESS;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
ge::graphStatus InterleaveRopeTiling::GetWorkspaceSize()
|
| 305 |
+
{
|
| 306 |
+
return ge::GRAPH_SUCCESS;
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
uint64_t InterleaveRopeTiling::GetTilingKey() const
|
| 310 |
+
{
|
| 311 |
+
return tilingKey_;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
ge::graphStatus InterleaveRopeTiling::PostTiling()
|
| 315 |
+
{
|
| 316 |
+
context_->SetTilingKey(GetTilingKey());
|
| 317 |
+
context_->SetBlockDim(tilingData_.get_numBlocks());
|
| 318 |
+
size_t* workspaces = context_->GetWorkspaceSizes(1);
|
| 319 |
+
workspaces[0] = DEFAULT_WORKSPACE_SIZE;
|
| 320 |
+
tilingData_.SaveToBuffer(context_->GetRawTilingData()->GetData(), context_->GetRawTilingData()->GetCapacity());
|
| 321 |
+
context_->GetRawTilingData()->SetDataSize(tilingData_.GetDataSize());
|
| 322 |
+
return ge::GRAPH_SUCCESS;
|
| 323 |
+
}
|
| 324 |
+
REGISTER_OPS_TILING_TEMPLATE(InterleaveRope, InterleaveRopeTiling, 1000);
|
| 325 |
+
|
| 326 |
+
ge::graphStatus Tiling4InterleaveRope(gert::TilingContext* context)
|
| 327 |
+
{
|
| 328 |
+
OP_LOGD(context, "TilingForInterleaveRope running.");
|
| 329 |
+
return Ops::Transformer::OpTiling::TilingRegistry::GetInstance().DoTilingImpl(context);
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
ge::graphStatus TilingPrepare4InterleaveRope(gert::TilingParseContext* context)
|
| 333 |
+
{
|
| 334 |
+
OP_LOGD(context, "TilingPrepare4InterleaveRope running.");
|
| 335 |
+
auto compileInfo = context->GetCompiledInfo<InterleaveRopeCompileInfo>();
|
| 336 |
+
OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo);
|
| 337 |
+
auto platformInfo = context->GetPlatformInfo();
|
| 338 |
+
OP_CHECK_NULL_WITH_CONTEXT(context, platformInfo);
|
| 339 |
+
auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo);
|
| 340 |
+
compileInfo->coreNum = ascendcPlatform.GetCoreNumAiv();
|
| 341 |
+
OP_CHECK_IF(
|
| 342 |
+
compileInfo->coreNum <= 0, OP_LOGE(context, "coreNum must be greater than 0."),
|
| 343 |
+
return ge::GRAPH_FAILED);
|
| 344 |
+
uint64_t ubSize = 0;
|
| 345 |
+
ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSize);
|
| 346 |
+
compileInfo->ubSize = ubSize;
|
| 347 |
+
OP_CHECK_IF(
|
| 348 |
+
compileInfo->ubSize <= 0, OP_LOGE(context, "ubSize must be greater than 0."),
|
| 349 |
+
return ge::GRAPH_FAILED);
|
| 350 |
+
OP_LOGD(context, "coreNum: %ld, ubSize: %ld", compileInfo->coreNum, compileInfo->ubSize);
|
| 351 |
+
OP_LOGD(context, "TilingPrepare4InterleaveRope success.");
|
| 352 |
+
return ge::GRAPH_SUCCESS;
|
| 353 |
+
}
|
| 354 |
+
|
| 355 |
+
IMPL_OP_OPTILING(InterleaveRope)
|
| 356 |
+
.Tiling(Tiling4InterleaveRope)
|
| 357 |
+
.TilingParse<InterleaveRopeCompileInfo>(TilingPrepare4InterleaveRope);
|
| 358 |
+
|
| 359 |
+
} // namespace optiling
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/interleave_rope_tiling.h
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope_tiling.h
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
#ifndef OPS_BUILT_IN_OP_TILING_RUNTIME_INTERLEAVE_ROPE_H_
|
| 16 |
+
#define OPS_BUILT_IN_OP_TILING_RUNTIME_INTERLEAVE_ROPE_H_
|
| 17 |
+
|
| 18 |
+
#include "op_host/tiling_base.h"
|
| 19 |
+
#include "op_host/tiling_type.h"
|
| 20 |
+
#include "register/op_impl_registry.h"
|
| 21 |
+
#include "register/tilingdata_base.h"
|
| 22 |
+
#include "tiling/tiling_api.h"
|
| 23 |
+
#include "op_host/tiling_templates_registry.h"
|
| 24 |
+
#include "register/op_def_registry.h"
|
| 25 |
+
#include "log/log.h"
|
| 26 |
+
#include "platform/platform_infos_def.h"
|
| 27 |
+
#include "util/math_util.h"
|
| 28 |
+
#include "tiling/platform/platform_ascendc.h"
|
| 29 |
+
|
| 30 |
+
namespace optiling {
|
| 31 |
+
BEGIN_TILING_DATA_DEF(InterleaveRopeTilingData)
|
| 32 |
+
TILING_DATA_FIELD_DEF(int64_t, numBlocks);
|
| 33 |
+
TILING_DATA_FIELD_DEF(int64_t, splitAxis);
|
| 34 |
+
|
| 35 |
+
TILING_DATA_FIELD_DEF(int64_t, batchSize);
|
| 36 |
+
TILING_DATA_FIELD_DEF(int64_t, numHead);
|
| 37 |
+
TILING_DATA_FIELD_DEF(int64_t, seqLength);
|
| 38 |
+
TILING_DATA_FIELD_DEF(int64_t, hiddenDim);
|
| 39 |
+
|
| 40 |
+
TILING_DATA_FIELD_DEF(int64_t, batchsPerBlock);
|
| 41 |
+
TILING_DATA_FIELD_DEF(int64_t, batchsLastBlock);
|
| 42 |
+
TILING_DATA_FIELD_DEF(int64_t, batchLoops);
|
| 43 |
+
TILING_DATA_FIELD_DEF(int64_t, batchPerLoop);
|
| 44 |
+
TILING_DATA_FIELD_DEF(int64_t, batchLastLoop);
|
| 45 |
+
|
| 46 |
+
TILING_DATA_FIELD_DEF(int64_t, hiddenDimCountPerBlock);
|
| 47 |
+
TILING_DATA_FIELD_DEF(int64_t, hiddenDimCountLastBlock);
|
| 48 |
+
TILING_DATA_FIELD_DEF(int64_t, hiddenDimLoopsPerBlock);
|
| 49 |
+
TILING_DATA_FIELD_DEF(int64_t, hiddenDimCountPerLoopPerBlock);
|
| 50 |
+
TILING_DATA_FIELD_DEF(int64_t, hiddenDimCountLastLoopPerBlock);
|
| 51 |
+
TILING_DATA_FIELD_DEF(int64_t, hiddenDimLoopsLastBlock);
|
| 52 |
+
TILING_DATA_FIELD_DEF(int64_t, hiddenDimCountPerLoopLastBlock);
|
| 53 |
+
TILING_DATA_FIELD_DEF(int64_t, hiddenDimCountLastLoopLastBlock);
|
| 54 |
+
|
| 55 |
+
END_TILING_DATA_DEF;
|
| 56 |
+
|
| 57 |
+
REGISTER_TILING_DATA_CLASS(InterleaveRope, InterleaveRopeTilingData)
|
| 58 |
+
|
| 59 |
+
struct InterleaveRopeCompileInfo {
|
| 60 |
+
int64_t coreNum = 0;
|
| 61 |
+
int64_t ubSize = 0;
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
class InterleaveRopeTiling : public Ops::Transformer::OpTiling::TilingBaseClass {
|
| 65 |
+
public:
|
| 66 |
+
explicit InterleaveRopeTiling(gert::TilingContext* p_context_) : TilingBaseClass(p_context_)
|
| 67 |
+
{}
|
| 68 |
+
~InterleaveRopeTiling() override = default;
|
| 69 |
+
|
| 70 |
+
uint64_t coreNum_ = 0;
|
| 71 |
+
uint64_t ubSize_ = 0;
|
| 72 |
+
int64_t batchSize_ = 0;
|
| 73 |
+
int64_t numHead_ = 0;
|
| 74 |
+
int64_t seqLength_ = 0;
|
| 75 |
+
int64_t hiddenDim_ = 0;
|
| 76 |
+
int64_t cosB_ = 0;
|
| 77 |
+
int64_t cosN_ = 0;
|
| 78 |
+
int64_t cosS_ = 0;
|
| 79 |
+
int64_t cosD_ = 0;
|
| 80 |
+
|
| 81 |
+
protected:
|
| 82 |
+
bool IsCapable() override;
|
| 83 |
+
ge::graphStatus DoOpTiling() override;
|
| 84 |
+
ge::graphStatus DoLibApiTiling() override;
|
| 85 |
+
uint64_t GetTilingKey() const override;
|
| 86 |
+
ge::graphStatus GetPlatformInfo() override;
|
| 87 |
+
ge::graphStatus GetShapeAttrsInfo() override;
|
| 88 |
+
ge::graphStatus GetWorkspaceSize() override;
|
| 89 |
+
ge::graphStatus PostTiling() override;
|
| 90 |
+
ge::graphStatus SplitBlockForFixBNS();
|
| 91 |
+
ge::graphStatus SplitBlockForBatch();
|
| 92 |
+
ge::graphStatus SplitBlockForNS();
|
| 93 |
+
ge::graphStatus SplitHiddenDim();
|
| 94 |
+
ge::graphStatus SplitHiddenDimInblock(
|
| 95 |
+
int64_t hiddenDimCount, int64_t& hiddenDimLoops, int64_t& hiddenDimCountPerLoop,
|
| 96 |
+
int64_t& hiddenDimCountLastLoop);
|
| 97 |
+
|
| 98 |
+
private:
|
| 99 |
+
InterleaveRopeTilingData tilingData_;
|
| 100 |
+
};
|
| 101 |
+
|
| 102 |
+
} // namespace optiling
|
| 103 |
+
|
| 104 |
+
#endif // OPS_BUILT_IN_OP_TILING_RUNTIME_INTERLEAVE_ROPE_H_
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/op_api/aclnn_interleave_rope.cpp
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include "aclnn_interleave_rope.h"
|
| 12 |
+
#include "opdev/make_op_executor.h"
|
| 13 |
+
#include "opdev/op_dfx.h"
|
| 14 |
+
#include "opdev/op_executor.h"
|
| 15 |
+
#include "op_api/op_api_def.h"
|
| 16 |
+
#include "aclnn_kernels/common/op_error_check.h"
|
| 17 |
+
#include "external/aclnn_kernels/aclnn_platform.h"
|
| 18 |
+
#include "posembedding/rotary_position_embedding/op_host/op_api/aclnn_rotary_position_embedding.h"
|
| 19 |
+
#include "aclnnInner_interleave_rope.h"
|
| 20 |
+
|
| 21 |
+
using namespace op;
|
| 22 |
+
|
| 23 |
+
#ifdef __cplusplus
|
| 24 |
+
extern "C" {
|
| 25 |
+
#endif
|
| 26 |
+
|
| 27 |
+
constexpr int64_t HALF_INTERLEAVE_MODE = 3;
|
| 28 |
+
|
| 29 |
+
aclnnStatus aclnnInterleaveRopeGetWorkspaceSize(
|
| 30 |
+
const aclTensor* x, const aclTensor* cos, const aclTensor* sin, aclTensor* out, uint64_t* workspaceSize,
|
| 31 |
+
aclOpExecutor** executor)
|
| 32 |
+
{
|
| 33 |
+
if (Ops::Transformer::AclnnUtil::IsRegbase()) {
|
| 34 |
+
return aclnnRotaryPositionEmbeddingGetWorkspaceSize(
|
| 35 |
+
x, cos, sin, HALF_INTERLEAVE_MODE, out, workspaceSize, executor);
|
| 36 |
+
} else {
|
| 37 |
+
return aclnnInnerInterleaveRopeGetWorkspaceSize(x, cos, sin, out, workspaceSize, executor);
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
aclnnStatus aclnnInterleaveRope(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, aclrtStream stream)
|
| 42 |
+
{
|
| 43 |
+
if (Ops::Transformer::AclnnUtil::IsRegbase()) {
|
| 44 |
+
return aclnnRotaryPositionEmbedding(workspace, workspaceSize, executor, stream);
|
| 45 |
+
} else {
|
| 46 |
+
return aclnnInnerInterleaveRope(workspace, workspaceSize, executor, stream);
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
#ifdef __cplusplus
|
| 51 |
+
}
|
| 52 |
+
#endif
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/op_api/aclnn_interleave_rope.h
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#ifndef OP_API_INC_INTERLEAVE_ROPE_H_
|
| 12 |
+
#define OP_API_INC_INTERLEAVE_ROPE_H_
|
| 13 |
+
|
| 14 |
+
#include "aclnn/aclnn_base.h"
|
| 15 |
+
#include "aclnn_util.h"
|
| 16 |
+
|
| 17 |
+
#ifdef __cplusplus
|
| 18 |
+
extern "C" {
|
| 19 |
+
#endif
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @brief aclnnInterleaveRope的第一段接口,根据具体的计算流程,计算workspace大小。
|
| 23 |
+
* @domain aclnn_ops_infer
|
| 24 |
+
*
|
| 25 |
+
* @param [in] x: npu
|
| 26 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,支持非连续的Tensor,数据格式支持ND。
|
| 27 |
+
* @param [in] sin: npu
|
| 28 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,数据类型与x一致,shape与x满足broadcast关系
|
| 29 |
+
* 支持非连续的Tensor,数据格式支持ND。
|
| 30 |
+
* @param [in] cos: npu
|
| 31 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,数据类型与x一致,shape与sin一致
|
| 32 |
+
* 支持非连续的Tensor,数据格式支持ND。
|
| 33 |
+
* @param [in] out: npu
|
| 34 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,且数据类型与x一致,
|
| 35 |
+
* shape与x相同, 数据格式支持ND, 且数据格式需要与x一致。
|
| 36 |
+
* @param [out] workspaceSize: 返回用户需要在npu device侧申请的workspace大小.
|
| 37 |
+
* @param [out] executor: 返回op执行器,包含算子计算流程。
|
| 38 |
+
* @return aclnnStatus: 返回状态码。
|
| 39 |
+
*/
|
| 40 |
+
ACLNN_API aclnnStatus aclnnInterleaveRopeGetWorkspaceSize(
|
| 41 |
+
const aclTensor* x, const aclTensor* cos, const aclTensor* sin, aclTensor* out, uint64_t* workspaceSize,
|
| 42 |
+
aclOpExecutor** executor);
|
| 43 |
+
|
| 44 |
+
/* @brief aclnnInterleaveRope的第二段接口,用于执行计算.
|
| 45 |
+
* @param [in] workspace: 在npu device侧申请的workspace内存起址
|
| 46 |
+
* @param [in] workspace_size: 在npu device侧申请的workspace大小,由第一段接口aclnnBitwiseNotGetWorkspaceSize获取.
|
| 47 |
+
* @param [in] executor: op执行器,包含了算子计算流程.
|
| 48 |
+
* @param [in] stream: acl stream流.
|
| 49 |
+
* @return aclnnStatus: 返回状态码。
|
| 50 |
+
*/
|
| 51 |
+
ACLNN_API aclnnStatus
|
| 52 |
+
aclnnInterleaveRope(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, aclrtStream stream);
|
| 53 |
+
|
| 54 |
+
#ifdef __cplusplus
|
| 55 |
+
}
|
| 56 |
+
#endif
|
| 57 |
+
|
| 58 |
+
#endif
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_host/op_api/aclnn_rotary_position_embedding.h
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#ifndef OP_API_INC_ROTARY_POSITION_EMBEDDING_H_
|
| 12 |
+
#define OP_API_INC_ROTARY_POSITION_EMBEDDING_H_
|
| 13 |
+
|
| 14 |
+
#include "aclnn/aclnn_base.h"
|
| 15 |
+
#include "aclnn_util.h"
|
| 16 |
+
|
| 17 |
+
#ifdef __cplusplus
|
| 18 |
+
extern "C" {
|
| 19 |
+
#endif
|
| 20 |
+
|
| 21 |
+
/**
|
| 22 |
+
* @brief aclnnRotaryPositionEmbedding的第一段接口,根据具体的计算流程,计算workspace大小。
|
| 23 |
+
* @domain aclnn_ops_infer
|
| 24 |
+
*
|
| 25 |
+
* @param [in] x: npu
|
| 26 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,支持非连续的Tensor,数据格式支持ND。
|
| 27 |
+
* @param [in] sin: npu
|
| 28 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,数据类型与x一致,shape与x满足broadcast关系
|
| 29 |
+
* 支持非连续的Tensor,数据格式支持ND。
|
| 30 |
+
* @param [in] cos: npu
|
| 31 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,数据类型与x一致,shape与sin一致
|
| 32 |
+
* 支持非连续的Tensor,数据格式支持ND。
|
| 33 |
+
* @param [in] mode: 支持int64_t类型,取值范围[0, 3],分别表示half,quarter,interleave,half-interleave四种模式.
|
| 34 |
+
* @param [in] out: npu
|
| 35 |
+
* device侧的aclTensor, 数据类型支持FLOAT32,FLOAT16,BFLOAT16,且数据类型与x一致,
|
| 36 |
+
* shape与x相同, 数据格式支持ND, 且数据格式需要与x一致。
|
| 37 |
+
* @param [out] workspaceSize: 返回用户需要在npu device侧申请的workspace大小。
|
| 38 |
+
* @param [out] executor: 返回op执行器,包含算子计算流程。
|
| 39 |
+
* @return aclnnStatus: 返回状态码。
|
| 40 |
+
*/
|
| 41 |
+
ACLNN_API aclnnStatus aclnnRotaryPositionEmbeddingGetWorkspaceSize(const aclTensor* x, const aclTensor* cos,
|
| 42 |
+
const aclTensor* sin, int64_t mode, aclTensor* out,
|
| 43 |
+
uint64_t* workspaceSize, aclOpExecutor** executor);
|
| 44 |
+
/* @brief aclnnRotaryPositionEmbedding的第二段接口,用于执行计算.
|
| 45 |
+
* @param [in] workspace: 在npu device侧申请的workspace内存起址
|
| 46 |
+
* @param [in] workspace_size: 在npu device侧申请的workspace大小,由第一段接口aclnnBitwiseNotGetWorkspaceSize获取。
|
| 47 |
+
* @param [in] executor: op执行器,包含了算子计算流程。
|
| 48 |
+
* @param [in] stream: acl stream流。
|
| 49 |
+
* @return aclnnStatus: 返回状态码。
|
| 50 |
+
*/
|
| 51 |
+
ACLNN_API aclnnStatus aclnnRotaryPositionEmbedding(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor,
|
| 52 |
+
aclrtStream stream);
|
| 53 |
+
|
| 54 |
+
#ifdef __cplusplus
|
| 55 |
+
}
|
| 56 |
+
#endif
|
| 57 |
+
|
| 58 |
+
#endif
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_kernel/interleave_rope.cpp
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope.cpp
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#include "interleave_rope_fixed_bnsd_b11d.h"
|
| 17 |
+
#include "interleave_rope_b11d.h"
|
| 18 |
+
#include "interleave_rope_b1sd.h"
|
| 19 |
+
#include "interleave_rope_split_s.h"
|
| 20 |
+
|
| 21 |
+
using namespace InterleaveRope;
|
| 22 |
+
|
| 23 |
+
#define INTERLEAVE_ROPE_FIXED_BNSD_B11D 1000
|
| 24 |
+
#define INTERLEAVE_ROPE_B11D 2000
|
| 25 |
+
#define INTERLEAVE_ROPE_B1SD 3000
|
| 26 |
+
#define INTERLEAVE_ROPE_SPLIT_S 4000
|
| 27 |
+
|
| 28 |
+
extern "C" __global__ __aicore__ void interleave_rope(
|
| 29 |
+
GM_ADDR x, GM_ADDR cos, GM_ADDR sin, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling)
|
| 30 |
+
{
|
| 31 |
+
TPipe pipe;
|
| 32 |
+
GET_TILING_DATA(tilingData, tiling);
|
| 33 |
+
if (TILING_KEY_IS(INTERLEAVE_ROPE_FIXED_BNSD_B11D)) {
|
| 34 |
+
KernelInterleaveRopeFixBNSD<DTYPE_X> op(&pipe, &tilingData);
|
| 35 |
+
op.Init(x, cos, sin, y);
|
| 36 |
+
op.Process();
|
| 37 |
+
} else if (TILING_KEY_IS(INTERLEAVE_ROPE_B11D)) {
|
| 38 |
+
KernelInterleaveRopeB11D<DTYPE_X> op(&pipe, &tilingData);
|
| 39 |
+
op.Init(x, cos, sin, y);
|
| 40 |
+
op.Process();
|
| 41 |
+
} else if (TILING_KEY_IS(INTERLEAVE_ROPE_B1SD)) {
|
| 42 |
+
KernelInterleaveRopeB1SD<DTYPE_X> op(&pipe, &tilingData);
|
| 43 |
+
op.Init(x, cos, sin, y);
|
| 44 |
+
op.Process();
|
| 45 |
+
} else if (TILING_KEY_IS(INTERLEAVE_ROPE_SPLIT_S)) {
|
| 46 |
+
KernelInterleaveRopeSplitS<DTYPE_X> op(&pipe, &tilingData);
|
| 47 |
+
op.Init(x, cos, sin, y);
|
| 48 |
+
op.Process();
|
| 49 |
+
}
|
| 50 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope_b11d.h
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
#ifndef _INTERLEAVE_ROPE_B11D_H_
|
| 16 |
+
#define _INTERLEAVE_ROPE_B11D_H_
|
| 17 |
+
#include "platform/platform_infos_def.h"
|
| 18 |
+
#include "kernel_operator.h"
|
| 19 |
+
|
| 20 |
+
namespace InterleaveRope {
|
| 21 |
+
using namespace AscendC;
|
| 22 |
+
|
| 23 |
+
constexpr uint64_t SPLIT_BATCH = 0;
|
| 24 |
+
constexpr uint64_t SPLIT_NS = 1;
|
| 25 |
+
|
| 26 |
+
template <typename T>
|
| 27 |
+
class KernelInterleaveRopeB11D {
|
| 28 |
+
public:
|
| 29 |
+
__aicore__ inline KernelInterleaveRopeB11D(TPipe* pipe, const InterleaveRopeTilingData* tiling)
|
| 30 |
+
: pipe_(pipe), tilingData_(tiling)
|
| 31 |
+
{}
|
| 32 |
+
|
| 33 |
+
__aicore__ inline void Init(GM_ADDR x, GM_ADDR cos, GM_ADDR sin, GM_ADDR y)
|
| 34 |
+
{
|
| 35 |
+
/*
|
| 36 |
+
* For each block, process
|
| 37 |
+
* x: [B, N, S, 64]
|
| 38 |
+
* cos: [B, 1, 1, 64]
|
| 39 |
+
* sin: [B, 1, 1, 64]
|
| 40 |
+
* y: [B, N, S, 64]
|
| 41 |
+
*/
|
| 42 |
+
|
| 43 |
+
numHead_ = tilingData_->numHead;
|
| 44 |
+
seqLength_ = tilingData_->seqLength;
|
| 45 |
+
NS_ = numHead_ * seqLength_;
|
| 46 |
+
|
| 47 |
+
batchsPerBlock_ = tilingData_->batchsPerBlock;
|
| 48 |
+
curBlockBatchs_ = tilingData_->batchsPerBlock;
|
| 49 |
+
batchLoops_ = tilingData_->batchLoops;
|
| 50 |
+
batchPerLoop_ = tilingData_->batchPerLoop;
|
| 51 |
+
batchLastLoop_ = tilingData_->batchLastLoop;
|
| 52 |
+
hiddenDimLoops_ = tilingData_->hiddenDimLoopsPerBlock;
|
| 53 |
+
hiddenDimCountPerLoop_ = tilingData_->hiddenDimCountPerLoopPerBlock;
|
| 54 |
+
hiddenDimCountLastLoop_ = tilingData_->hiddenDimCountLastLoopPerBlock;
|
| 55 |
+
if (GetBlockIdx() == GetBlockNum() - 1) {
|
| 56 |
+
curBlockBatchs_ = tilingData_->batchsLastBlock;
|
| 57 |
+
hiddenDimLoops_ = tilingData_->hiddenDimLoopsLastBlock;
|
| 58 |
+
hiddenDimCountPerLoop_ = tilingData_->hiddenDimCountPerLoopLastBlock;
|
| 59 |
+
hiddenDimCountLastLoop_ = tilingData_->hiddenDimCountLastLoopLastBlock;
|
| 60 |
+
}
|
| 61 |
+
|
| 62 |
+
if (tilingData_->splitAxis == SPLIT_BATCH) {
|
| 63 |
+
sinCosIdxOffsetBase_ = GetBlockIdx() * batchsPerBlock_;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
xGm.SetGlobalBuffer((__gm__ T*)x);
|
| 67 |
+
yGm.SetGlobalBuffer((__gm__ T*)y);
|
| 68 |
+
cosGm.SetGlobalBuffer((__gm__ T*)cos);
|
| 69 |
+
sinGm.SetGlobalBuffer((__gm__ T*)sin);
|
| 70 |
+
|
| 71 |
+
// init pipe
|
| 72 |
+
pipe_->InitBuffer(inQueueX, 1, hiddenDimCountPerLoop_ * hiddenDim * sizeof(T));
|
| 73 |
+
pipe_->InitBuffer(outQueueY, 1, hiddenDimCountPerLoop_ * hiddenDim * sizeof(float) * numTwo);
|
| 74 |
+
pipe_->InitBuffer(inQueueCos, 1, hiddenDim * sizeof(float) * numTwo);
|
| 75 |
+
pipe_->InitBuffer(inQueueSin, 1, hiddenDim * sizeof(float) * numTwo);
|
| 76 |
+
|
| 77 |
+
pipe_->InitBuffer(bufferReal, hiddenDimCountPerLoop_ * hiddenDimHalf * sizeof(float) * numTwo);
|
| 78 |
+
pipe_->InitBuffer(bufferImag, hiddenDimCountPerLoop_ * hiddenDimHalf * sizeof(float) * numTwo);
|
| 79 |
+
pipe_->InitBuffer(buffer_, hiddenDimCountPerLoop_ * hiddenDim * sizeof(float));
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
__aicore__ inline void Process()
|
| 83 |
+
{
|
| 84 |
+
for (int64_t i = 0; i < curBlockBatchs_; i++) {
|
| 85 |
+
Rope(i);
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
__aicore__ inline void Rope(int64_t idx)
|
| 90 |
+
{
|
| 91 |
+
int64_t sinCosIdxOffset = sinCosIdxOffsetBase_ + idx;
|
| 92 |
+
// rope
|
| 93 |
+
LocalTensor<float> cosLocal = inQueueCos.AllocTensor<float>();
|
| 94 |
+
DataCopy(cosLocal[hiddenDim].template ReinterpretCast<T>(), cosGm[sinCosIdxOffset * hiddenDim], hiddenDim);
|
| 95 |
+
|
| 96 |
+
inQueueCos.EnQue(cosLocal);
|
| 97 |
+
cosLocal = inQueueCos.DeQue<float>();
|
| 98 |
+
Cast(cosLocal, cosLocal[hiddenDim].template ReinterpretCast<T>(), RoundMode::CAST_NONE, hiddenDim);
|
| 99 |
+
|
| 100 |
+
LocalTensor<float> sinLocal = inQueueSin.AllocTensor<float>();
|
| 101 |
+
DataCopy(sinLocal[hiddenDim].template ReinterpretCast<T>(), sinGm[sinCosIdxOffset * hiddenDim], hiddenDim);
|
| 102 |
+
inQueueSin.EnQue(sinLocal);
|
| 103 |
+
sinLocal = inQueueSin.DeQue<float>();
|
| 104 |
+
Cast(sinLocal, sinLocal[hiddenDim].template ReinterpretCast<T>(), RoundMode::CAST_NONE, hiddenDim);
|
| 105 |
+
int64_t factor = hiddenDimCountPerLoop_;
|
| 106 |
+
int64_t batchOffset = tilingData_->splitAxis == SPLIT_BATCH ?
|
| 107 |
+
(GetBlockIdx() * batchsPerBlock_ + idx) * NS_ :
|
| 108 |
+
idx * NS_ + GetBlockIdx() * tilingData_->hiddenDimCountPerBlock;
|
| 109 |
+
for (int i = 0; i < hiddenDimLoops_; i++) {
|
| 110 |
+
if (i == hiddenDimLoops_ - 1) {
|
| 111 |
+
factor = hiddenDimCountLastLoop_;
|
| 112 |
+
}
|
| 113 |
+
int64_t xOffset = (batchOffset + i * hiddenDimCountPerLoop_) * hiddenDim;
|
| 114 |
+
|
| 115 |
+
// load xLocal
|
| 116 |
+
LocalTensor<T> xLocal = inQueueX.AllocTensor<T>();
|
| 117 |
+
DataCopy(xLocal, xGm[xOffset], factor * hiddenDim);
|
| 118 |
+
inQueueX.EnQue(xLocal);
|
| 119 |
+
xLocal = inQueueX.DeQue<T>();
|
| 120 |
+
|
| 121 |
+
// split Real and Imag
|
| 122 |
+
LocalTensor<float> realLocal = bufferReal.Get<float>();
|
| 123 |
+
LocalTensor<float> imagLocal = bufferImag.Get<float>();
|
| 124 |
+
LocalTensor<float> buf_ = buffer_.Get<float>();
|
| 125 |
+
uint64_t rsvdCnt = 0;
|
| 126 |
+
GatherMask(
|
| 127 |
+
realLocal[hiddenDimCountPerLoop_ * hiddenDimHalf].template ReinterpretCast<T>(), xLocal, 1, true,
|
| 128 |
+
factor * hiddenDim, {1, 1, 8, 0}, rsvdCnt);
|
| 129 |
+
GatherMask(
|
| 130 |
+
imagLocal[hiddenDimCountPerLoop_ * hiddenDimHalf].template ReinterpretCast<T>(), xLocal, numTwo, true,
|
| 131 |
+
factor * hiddenDim, {1, 1, 8, 0}, rsvdCnt);
|
| 132 |
+
Cast(
|
| 133 |
+
realLocal, realLocal[hiddenDimCountPerLoop_ * hiddenDimHalf].template ReinterpretCast<T>(),
|
| 134 |
+
RoundMode::CAST_NONE, factor * hiddenDimHalf);
|
| 135 |
+
Cast(
|
| 136 |
+
imagLocal, imagLocal[hiddenDimCountPerLoop_ * hiddenDimHalf].template ReinterpretCast<T>(),
|
| 137 |
+
RoundMode::CAST_NONE, factor * hiddenDimHalf);
|
| 138 |
+
inQueueX.FreeTensor(xLocal);
|
| 139 |
+
|
| 140 |
+
uint64_t mask[numTwo] = {0xffffffff, 0}; // mask hiddenDimHalf Elements
|
| 141 |
+
LocalTensor<float> outLocal = outQueueY.AllocTensor<float>();
|
| 142 |
+
Mul(outLocal, realLocal, cosLocal, mask, factor * numTwo, {1, 1, 1, 8, 4, 0});
|
| 143 |
+
Mul(outLocal[hiddenDimHalf], imagLocal, cosLocal[hiddenDimHalf], mask, factor * numTwo, {1, 1, 1, 8, 4, 0});
|
| 144 |
+
PipeBarrier<PIPE_V>();
|
| 145 |
+
|
| 146 |
+
Muls<float>(imagLocal, imagLocal, -1.0f, factor * hiddenDimHalf);
|
| 147 |
+
PipeBarrier<PIPE_V>();
|
| 148 |
+
Mul(buf_, imagLocal, sinLocal, mask, factor * numTwo, {1, 1, 1, 8, 4, 0});
|
| 149 |
+
Mul(buf_[hiddenDimHalf], realLocal, sinLocal[hiddenDimHalf], mask, factor * numTwo, {1, 1, 1, 8, 4, 0});
|
| 150 |
+
PipeBarrier<PIPE_V>();
|
| 151 |
+
|
| 152 |
+
Add(outLocal, outLocal, buf_, factor * hiddenDim);
|
| 153 |
+
PipeBarrier<PIPE_V>();
|
| 154 |
+
Cast(
|
| 155 |
+
outLocal[hiddenDimCountPerLoop_ * hiddenDim].template ReinterpretCast<T>(), outLocal,
|
| 156 |
+
RoundMode::CAST_RINT, factor * hiddenDim);
|
| 157 |
+
PipeBarrier<PIPE_V>();
|
| 158 |
+
|
| 159 |
+
outQueueY.EnQue(outLocal);
|
| 160 |
+
outLocal = outQueueY.DeQue<float>();
|
| 161 |
+
DataCopy(
|
| 162 |
+
yGm[xOffset], outLocal[hiddenDimCountPerLoop_ * hiddenDim].template ReinterpretCast<T>(),
|
| 163 |
+
factor * hiddenDim);
|
| 164 |
+
outQueueY.FreeTensor(outLocal);
|
| 165 |
+
}
|
| 166 |
+
inQueueCos.FreeTensor(cosLocal);
|
| 167 |
+
inQueueSin.FreeTensor(sinLocal);
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
private:
|
| 171 |
+
TPipe* pipe_ = nullptr;
|
| 172 |
+
const InterleaveRopeTilingData* tilingData_;
|
| 173 |
+
GlobalTensor<T> xGm;
|
| 174 |
+
GlobalTensor<T> yGm;
|
| 175 |
+
GlobalTensor<T> cosGm;
|
| 176 |
+
GlobalTensor<T> sinGm;
|
| 177 |
+
|
| 178 |
+
TQue<QuePosition::VECIN, 1> inQueueX;
|
| 179 |
+
TQue<QuePosition::VECIN, 1> inQueueCos;
|
| 180 |
+
TQue<QuePosition::VECIN, 1> inQueueSin;
|
| 181 |
+
TQue<QuePosition::VECOUT, 1> outQueueY;
|
| 182 |
+
TBuf<TPosition::VECCALC> bufferReal;
|
| 183 |
+
TBuf<TPosition::VECCALC> bufferImag;
|
| 184 |
+
TBuf<TPosition::VECCALC> buffer_;
|
| 185 |
+
int64_t numHead_ = 0;
|
| 186 |
+
int64_t seqLength_ = 0;
|
| 187 |
+
int64_t NS_ = 0;
|
| 188 |
+
|
| 189 |
+
constexpr static int64_t hiddenDim = 64;
|
| 190 |
+
constexpr static int64_t hiddenDimHalf = 32;
|
| 191 |
+
constexpr static int64_t numTwo = 2;
|
| 192 |
+
int64_t batchLoops_ = 0;
|
| 193 |
+
int64_t batchPerLoop_ = 0;
|
| 194 |
+
int64_t batchLastLoop_ = 0;
|
| 195 |
+
int64_t batchsPerBlock_ = 0;
|
| 196 |
+
int64_t curBlockBatchs_ = 0;
|
| 197 |
+
int64_t hiddenDimLoops_ = 0;
|
| 198 |
+
int64_t hiddenDimCountPerLoop_ = 0;
|
| 199 |
+
int64_t hiddenDimCountLastLoop_ = 0;
|
| 200 |
+
int64_t sinCosIdxOffsetBase_ = 0;
|
| 201 |
+
};
|
| 202 |
+
} // namespace InterleaveRope
|
| 203 |
+
|
| 204 |
+
#endif // _INTERLEAVE_ROPE_B11D_H_
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_kernel/interleave_rope_b1sd.h
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope_b1sd.h
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
#ifndef _INTERLEAVE_ROPE_B1SD_H_
|
| 16 |
+
#define _INTERLEAVE_ROPE_B1SD_H_
|
| 17 |
+
#include "platform/platform_infos_def.h"
|
| 18 |
+
#include "kernel_operator.h"
|
| 19 |
+
|
| 20 |
+
namespace InterleaveRope {
|
| 21 |
+
using namespace AscendC;
|
| 22 |
+
|
| 23 |
+
template <typename T>
|
| 24 |
+
class KernelInterleaveRopeB1SD {
|
| 25 |
+
public:
|
| 26 |
+
__aicore__ inline KernelInterleaveRopeB1SD(TPipe* pipe, const InterleaveRopeTilingData* tiling)
|
| 27 |
+
: pipe_(pipe), tilingData_(tiling)
|
| 28 |
+
{}
|
| 29 |
+
|
| 30 |
+
__aicore__ inline void Init(GM_ADDR x, GM_ADDR cos, GM_ADDR sin, GM_ADDR y)
|
| 31 |
+
{
|
| 32 |
+
/*
|
| 33 |
+
* For each block, process
|
| 34 |
+
* x: [B, N, S, 64]
|
| 35 |
+
* cos: [B, 1, S, 64]
|
| 36 |
+
* sin: [B, 1, S, 64]
|
| 37 |
+
* y: [B, N, S, 64]
|
| 38 |
+
*/
|
| 39 |
+
|
| 40 |
+
numHead_ = tilingData_->numHead;
|
| 41 |
+
seqLength_ = tilingData_->seqLength;
|
| 42 |
+
NS_ = numHead_ * seqLength_;
|
| 43 |
+
|
| 44 |
+
batchsPerBlock_ = tilingData_->batchsPerBlock;
|
| 45 |
+
curBlockBatchs_ = tilingData_->batchsPerBlock;
|
| 46 |
+
batchLoops_ = tilingData_->batchLoops;
|
| 47 |
+
batchPerLoop_ = tilingData_->batchPerLoop;
|
| 48 |
+
batchLastLoop_ = tilingData_->batchLastLoop;
|
| 49 |
+
hiddenDimLoops_ = tilingData_->hiddenDimLoopsPerBlock;
|
| 50 |
+
hiddenDimCountPerLoop_ = tilingData_->hiddenDimCountPerLoopPerBlock;
|
| 51 |
+
hiddenDimCountLastLoop_ = tilingData_->hiddenDimCountLastLoopPerBlock;
|
| 52 |
+
if (GetBlockIdx() == GetBlockNum() - 1) {
|
| 53 |
+
curBlockBatchs_ = tilingData_->batchsLastBlock;
|
| 54 |
+
hiddenDimLoops_ = tilingData_->hiddenDimLoopsLastBlock;
|
| 55 |
+
hiddenDimCountPerLoop_ = tilingData_->hiddenDimCountPerLoopLastBlock;
|
| 56 |
+
hiddenDimCountLastLoop_ = tilingData_->hiddenDimCountLastLoopLastBlock;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
xGm.SetGlobalBuffer((__gm__ T*)x);
|
| 60 |
+
yGm.SetGlobalBuffer((__gm__ T*)y);
|
| 61 |
+
cosGm.SetGlobalBuffer((__gm__ T*)cos);
|
| 62 |
+
sinGm.SetGlobalBuffer((__gm__ T*)sin);
|
| 63 |
+
|
| 64 |
+
// init pipe
|
| 65 |
+
pipe_->InitBuffer(inQueueX, 1, hiddenDimCountPerLoop_ * hiddenDim * sizeof(T));
|
| 66 |
+
pipe_->InitBuffer(outQueueY, 1, hiddenDimCountPerLoop_ * hiddenDim * sizeof(float) * numTwo);
|
| 67 |
+
pipe_->InitBuffer(inQueueCos, 1, hiddenDimCountPerLoop_ * hiddenDim * sizeof(float) * numTwo);
|
| 68 |
+
pipe_->InitBuffer(inQueueSin, 1, hiddenDimCountPerLoop_ * hiddenDim * sizeof(float) * numTwo);
|
| 69 |
+
|
| 70 |
+
pipe_->InitBuffer(bufferReal, hiddenDimCountPerLoop_ * hiddenDimHalf * sizeof(float) * numTwo);
|
| 71 |
+
pipe_->InitBuffer(bufferImag, hiddenDimCountPerLoop_ * hiddenDimHalf * sizeof(float) * numTwo);
|
| 72 |
+
pipe_->InitBuffer(buffer_, hiddenDimCountPerLoop_ * hiddenDim * sizeof(float));
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
__aicore__ inline void Process()
|
| 76 |
+
{
|
| 77 |
+
for (int64_t i = 0; i < curBlockBatchs_; i++) {
|
| 78 |
+
Rope(i);
|
| 79 |
+
}
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
__aicore__ inline void Rope(int64_t idx)
|
| 83 |
+
{
|
| 84 |
+
int64_t hiddenDimCount = hiddenDimCountPerLoop_;
|
| 85 |
+
for (int64_t hiddenDimLoop = 0; hiddenDimLoop < hiddenDimLoops_; hiddenDimLoop++) {
|
| 86 |
+
if (hiddenDimLoop == hiddenDimLoops_ - 1) {
|
| 87 |
+
hiddenDimCount = hiddenDimCountLastLoop_;
|
| 88 |
+
}
|
| 89 |
+
int64_t sinCosIdxOffset = ((GetBlockIdx() * tilingData_->batchsPerBlock + idx) * seqLength_ +
|
| 90 |
+
hiddenDimLoop * hiddenDimCountPerLoop_) *
|
| 91 |
+
hiddenDim;
|
| 92 |
+
LocalTensor<float> cosLocal = inQueueCos.AllocTensor<float>();
|
| 93 |
+
DataCopy(
|
| 94 |
+
cosLocal[hiddenDimCount * hiddenDim].template ReinterpretCast<T>(), cosGm[sinCosIdxOffset],
|
| 95 |
+
hiddenDimCount * hiddenDim);
|
| 96 |
+
|
| 97 |
+
inQueueCos.EnQue(cosLocal);
|
| 98 |
+
cosLocal = inQueueCos.DeQue<float>();
|
| 99 |
+
Cast(
|
| 100 |
+
cosLocal, cosLocal[hiddenDimCount * hiddenDim].template ReinterpretCast<T>(), RoundMode::CAST_NONE,
|
| 101 |
+
hiddenDimCount * hiddenDim);
|
| 102 |
+
|
| 103 |
+
LocalTensor<float> sinLocal = inQueueSin.AllocTensor<float>();
|
| 104 |
+
DataCopy(
|
| 105 |
+
sinLocal[hiddenDimCount * hiddenDim].template ReinterpretCast<T>(), sinGm[sinCosIdxOffset],
|
| 106 |
+
hiddenDimCount * hiddenDim);
|
| 107 |
+
inQueueSin.EnQue(sinLocal);
|
| 108 |
+
sinLocal = inQueueSin.DeQue<float>();
|
| 109 |
+
Cast(
|
| 110 |
+
sinLocal, sinLocal[hiddenDimCount * hiddenDim].template ReinterpretCast<T>(), RoundMode::CAST_NONE,
|
| 111 |
+
hiddenDimCount * hiddenDim);
|
| 112 |
+
|
| 113 |
+
int64_t batchOffset = (GetBlockIdx() * tilingData_->batchsPerBlock + idx) * numHead_ * seqLength_;
|
| 114 |
+
for (int64_t nIdx = 0; nIdx < numHead_; nIdx++) {
|
| 115 |
+
int64_t xOffset =
|
| 116 |
+
(batchOffset + nIdx * seqLength_ + hiddenDimLoop * hiddenDimCountPerLoop_) * hiddenDim;
|
| 117 |
+
// load xLocal
|
| 118 |
+
LocalTensor<T> xLocal = inQueueX.AllocTensor<T>();
|
| 119 |
+
DataCopy(xLocal, xGm[xOffset], hiddenDimCount * hiddenDim);
|
| 120 |
+
inQueueX.EnQue(xLocal);
|
| 121 |
+
xLocal = inQueueX.DeQue<T>();
|
| 122 |
+
|
| 123 |
+
// split Real and Imag
|
| 124 |
+
LocalTensor<float> realLocal = bufferReal.Get<float>();
|
| 125 |
+
LocalTensor<float> imagLocal = bufferImag.Get<float>();
|
| 126 |
+
LocalTensor<float> buf_ = buffer_.Get<float>();
|
| 127 |
+
uint64_t rsvdCnt = 0;
|
| 128 |
+
GatherMask(
|
| 129 |
+
realLocal[hiddenDimCount * hiddenDimHalf].template ReinterpretCast<T>(), xLocal, 1, true,
|
| 130 |
+
hiddenDimCount * hiddenDim, {1, 1, 8, 0}, rsvdCnt);
|
| 131 |
+
GatherMask(
|
| 132 |
+
imagLocal[hiddenDimCount * hiddenDimHalf].template ReinterpretCast<T>(), xLocal, numTwo, true,
|
| 133 |
+
hiddenDimCount * hiddenDim, {1, 1, 8, 0}, rsvdCnt);
|
| 134 |
+
Cast(
|
| 135 |
+
realLocal, realLocal[hiddenDimCount * hiddenDimHalf].template ReinterpretCast<T>(),
|
| 136 |
+
RoundMode::CAST_NONE, hiddenDimCount * hiddenDimHalf);
|
| 137 |
+
Cast(
|
| 138 |
+
imagLocal, imagLocal[hiddenDimCount * hiddenDimHalf].template ReinterpretCast<T>(),
|
| 139 |
+
RoundMode::CAST_NONE, hiddenDimCount * hiddenDimHalf);
|
| 140 |
+
inQueueX.FreeTensor(xLocal);
|
| 141 |
+
|
| 142 |
+
uint64_t mask[numTwo] = {0xffffffff, 0}; // mask hiddenDimHalf Elements
|
| 143 |
+
LocalTensor<float> outLocal = outQueueY.AllocTensor<float>();
|
| 144 |
+
Mul(outLocal, realLocal, cosLocal, mask, hiddenDimCount, {1, 1, 1, 8, 4, 8});
|
| 145 |
+
Mul(outLocal[hiddenDimHalf], imagLocal, cosLocal[hiddenDimHalf], mask, hiddenDimCount,
|
| 146 |
+
{1, 1, 1, 8, 4, 8});
|
| 147 |
+
PipeBarrier<PIPE_V>();
|
| 148 |
+
Muls<float>(imagLocal, imagLocal, -1.0f, hiddenDimCount * hiddenDimHalf);
|
| 149 |
+
PipeBarrier<PIPE_V>();
|
| 150 |
+
Mul(buf_, imagLocal, sinLocal, mask, hiddenDimCount, {1, 1, 1, 8, 4, 8});
|
| 151 |
+
Mul(buf_[hiddenDimHalf], realLocal, sinLocal[hiddenDimHalf], mask, hiddenDimCount, {1, 1, 1, 8, 4, 8});
|
| 152 |
+
PipeBarrier<PIPE_V>();
|
| 153 |
+
Add(outLocal, outLocal, buf_, hiddenDimCount * hiddenDim);
|
| 154 |
+
PipeBarrier<PIPE_V>();
|
| 155 |
+
Cast(
|
| 156 |
+
outLocal[hiddenDimCount * hiddenDim].template ReinterpretCast<T>(), outLocal, RoundMode::CAST_RINT,
|
| 157 |
+
hiddenDimCount * hiddenDim);
|
| 158 |
+
PipeBarrier<PIPE_V>();
|
| 159 |
+
outQueueY.EnQue(outLocal);
|
| 160 |
+
outLocal = outQueueY.DeQue<float>();
|
| 161 |
+
DataCopy(
|
| 162 |
+
yGm[xOffset], outLocal[hiddenDimCount * hiddenDim].template ReinterpretCast<T>(),
|
| 163 |
+
hiddenDimCount * hiddenDim);
|
| 164 |
+
outQueueY.FreeTensor(outLocal);
|
| 165 |
+
}
|
| 166 |
+
inQueueCos.FreeTensor(cosLocal);
|
| 167 |
+
inQueueSin.FreeTensor(sinLocal);
|
| 168 |
+
}
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
private:
|
| 172 |
+
TPipe* pipe_ = nullptr;
|
| 173 |
+
const InterleaveRopeTilingData* tilingData_;
|
| 174 |
+
GlobalTensor<T> xGm;
|
| 175 |
+
GlobalTensor<T> yGm;
|
| 176 |
+
GlobalTensor<T> cosGm;
|
| 177 |
+
GlobalTensor<T> sinGm;
|
| 178 |
+
|
| 179 |
+
TQue<QuePosition::VECIN, 1> inQueueX;
|
| 180 |
+
TQue<QuePosition::VECIN, 1> inQueueCos;
|
| 181 |
+
TQue<QuePosition::VECIN, 1> inQueueSin;
|
| 182 |
+
TQue<QuePosition::VECOUT, 1> outQueueY;
|
| 183 |
+
TBuf<TPosition::VECCALC> bufferReal;
|
| 184 |
+
TBuf<TPosition::VECCALC> bufferImag;
|
| 185 |
+
TBuf<TPosition::VECCALC> buffer_;
|
| 186 |
+
int64_t numHead_ = 0;
|
| 187 |
+
int64_t seqLength_ = 0;
|
| 188 |
+
int64_t NS_ = 0;
|
| 189 |
+
|
| 190 |
+
constexpr static int64_t hiddenDim = 64;
|
| 191 |
+
constexpr static int64_t hiddenDimHalf = 32;
|
| 192 |
+
constexpr static int64_t numTwo = 2;
|
| 193 |
+
int64_t batchLoops_ = 0;
|
| 194 |
+
int64_t batchPerLoop_ = 0;
|
| 195 |
+
int64_t batchLastLoop_ = 0;
|
| 196 |
+
|
| 197 |
+
int64_t batchsPerBlock_ = 0;
|
| 198 |
+
int64_t curBlockBatchs_ = 0;
|
| 199 |
+
int64_t hiddenDimLoops_ = 0;
|
| 200 |
+
int64_t hiddenDimCountPerLoop_ = 0;
|
| 201 |
+
int64_t hiddenDimCountLastLoop_ = 0;
|
| 202 |
+
};
|
| 203 |
+
} // namespace InterleaveRope
|
| 204 |
+
|
| 205 |
+
#endif // _INTERLEAVE_ROPE_B1SD_H_
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_kernel/interleave_rope_fixed_bnsd_b11d.h
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope_fixed_bnsd_b11d.h
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
#ifndef _INTERLEAVE_ROPE_FIX_BNSD_B11D_H_
|
| 16 |
+
#define _INTERLEAVE_ROPE_FIX_BNSD_B11D_H_
|
| 17 |
+
#include "platform/platform_infos_def.h"
|
| 18 |
+
#include "kernel_operator.h"
|
| 19 |
+
|
| 20 |
+
namespace InterleaveRope {
|
| 21 |
+
using namespace AscendC;
|
| 22 |
+
|
| 23 |
+
template <typename T>
|
| 24 |
+
class KernelInterleaveRopeFixBNSD {
|
| 25 |
+
public:
|
| 26 |
+
__aicore__ inline KernelInterleaveRopeFixBNSD(TPipe* pipe, const InterleaveRopeTilingData* tiling)
|
| 27 |
+
: pipe_(pipe), tilingData_(tiling)
|
| 28 |
+
{}
|
| 29 |
+
|
| 30 |
+
__aicore__ inline void Init(GM_ADDR x, GM_ADDR cos, GM_ADDR sin, GM_ADDR y)
|
| 31 |
+
{
|
| 32 |
+
/*
|
| 33 |
+
* original shape:
|
| 34 |
+
* x: [32, 32, 1, 64]
|
| 35 |
+
* cos: [32, 1, 1, 64]
|
| 36 |
+
* sin: [32, 1, 1, 64]
|
| 37 |
+
* y: [32, 32, 1, 64]
|
| 38 |
+
* For each block, process
|
| 39 |
+
* x: [4, 32, 1, 64]
|
| 40 |
+
* cos: [4, 1, 1, 64]
|
| 41 |
+
* sin: [4, 1, 1, 64]
|
| 42 |
+
* y: [4, 32, 1, 64]
|
| 43 |
+
*/
|
| 44 |
+
|
| 45 |
+
// init global memory
|
| 46 |
+
xGm.SetGlobalBuffer(
|
| 47 |
+
(__gm__ T*)x + GetBlockIdx() * tilingData_->batchsPerBlock * numHead * hiddenDim,
|
| 48 |
+
tilingData_->batchsPerBlock * numHead * hiddenDim);
|
| 49 |
+
cosGm.SetGlobalBuffer(
|
| 50 |
+
(__gm__ T*)cos + GetBlockIdx() * tilingData_->batchsPerBlock * hiddenDim,
|
| 51 |
+
tilingData_->batchsPerBlock * hiddenDim);
|
| 52 |
+
sinGm.SetGlobalBuffer(
|
| 53 |
+
(__gm__ T*)sin + GetBlockIdx() * tilingData_->batchsPerBlock * hiddenDim,
|
| 54 |
+
tilingData_->batchsPerBlock * hiddenDim);
|
| 55 |
+
yGm.SetGlobalBuffer(
|
| 56 |
+
(__gm__ T*)y + GetBlockIdx() * tilingData_->batchsPerBlock * numHead * hiddenDim,
|
| 57 |
+
tilingData_->batchsPerBlock * numHead * hiddenDim);
|
| 58 |
+
|
| 59 |
+
// init pipe
|
| 60 |
+
pipe_->InitBuffer(inQueueX, 1, tilingData_->batchsPerBlock * numHead * hiddenDim * sizeof(T));
|
| 61 |
+
pipe_->InitBuffer(outQueueY, 1, tilingData_->batchsPerBlock * numHead * hiddenDim * sizeof(float) * numTwo);
|
| 62 |
+
|
| 63 |
+
pipe_->InitBuffer(inQueueCos, 1, tilingData_->batchsPerBlock * hiddenDim * sizeof(float) * numTwo);
|
| 64 |
+
pipe_->InitBuffer(inQueueSin, 1, tilingData_->batchsPerBlock * hiddenDim * sizeof(float) * numTwo);
|
| 65 |
+
|
| 66 |
+
pipe_->InitBuffer(bufferReal, tilingData_->batchsPerBlock * numHead * hiddenDimHalf * sizeof(float) * numTwo);
|
| 67 |
+
pipe_->InitBuffer(bufferImag, tilingData_->batchsPerBlock * numHead * hiddenDimHalf * sizeof(float) * numTwo);
|
| 68 |
+
pipe_->InitBuffer(buffer_, tilingData_->batchsPerBlock * numHead * hiddenDim * sizeof(float) * numTwo);
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
__aicore__ inline void Process()
|
| 72 |
+
{
|
| 73 |
+
Rope();
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
__aicore__ inline void Rope()
|
| 77 |
+
{
|
| 78 |
+
// load
|
| 79 |
+
LocalTensor<T> xLocal = inQueueX.AllocTensor<T>();
|
| 80 |
+
DataCopy(xLocal, xGm, tilingData_->batchsPerBlock * numHead * hiddenDim);
|
| 81 |
+
inQueueX.EnQue(xLocal);
|
| 82 |
+
xLocal = inQueueX.DeQue<T>();
|
| 83 |
+
|
| 84 |
+
// split Real and Imag
|
| 85 |
+
LocalTensor<float> realLocal = bufferReal.Get<float>();
|
| 86 |
+
LocalTensor<float> imagLocal = bufferImag.Get<float>();
|
| 87 |
+
LocalTensor<float> buf_ = buffer_.Get<float>();
|
| 88 |
+
uint64_t rsvdCnt = 0;
|
| 89 |
+
GatherMask(
|
| 90 |
+
realLocal[tilingData_->batchsPerBlock * numHead * hiddenDimHalf].template ReinterpretCast<T>(), xLocal, 1,
|
| 91 |
+
true, tilingData_->batchsPerBlock * numHead * hiddenDim, {1, 1, 8, 0}, rsvdCnt);
|
| 92 |
+
GatherMask(
|
| 93 |
+
imagLocal[tilingData_->batchsPerBlock * numHead * hiddenDimHalf].template ReinterpretCast<T>(), xLocal,
|
| 94 |
+
numTwo, true, tilingData_->batchsPerBlock * numHead * hiddenDim, {1, 1, 8, 0}, rsvdCnt);
|
| 95 |
+
PipeBarrier<PIPE_V>();
|
| 96 |
+
Cast(
|
| 97 |
+
realLocal, realLocal[tilingData_->batchsPerBlock * numHead * hiddenDimHalf].template ReinterpretCast<T>(),
|
| 98 |
+
RoundMode::CAST_NONE, tilingData_->batchsPerBlock * numHead * hiddenDimHalf);
|
| 99 |
+
Cast(
|
| 100 |
+
imagLocal, imagLocal[tilingData_->batchsPerBlock * numHead * hiddenDimHalf].template ReinterpretCast<T>(),
|
| 101 |
+
RoundMode::CAST_NONE, tilingData_->batchsPerBlock * numHead * hiddenDimHalf);
|
| 102 |
+
|
| 103 |
+
inQueueX.FreeTensor(xLocal);
|
| 104 |
+
|
| 105 |
+
// rope
|
| 106 |
+
LocalTensor<float> cosLocal = inQueueCos.AllocTensor<float>();
|
| 107 |
+
DataCopy(
|
| 108 |
+
cosLocal[tilingData_->batchsPerBlock * hiddenDim].template ReinterpretCast<T>(), cosGm,
|
| 109 |
+
tilingData_->batchsPerBlock * hiddenDim);
|
| 110 |
+
|
| 111 |
+
inQueueCos.EnQue(cosLocal);
|
| 112 |
+
cosLocal = inQueueCos.DeQue<float>();
|
| 113 |
+
|
| 114 |
+
Cast(
|
| 115 |
+
cosLocal, cosLocal[tilingData_->batchsPerBlock * hiddenDim].template ReinterpretCast<T>(),
|
| 116 |
+
RoundMode::CAST_NONE, tilingData_->batchsPerBlock * hiddenDim);
|
| 117 |
+
PipeBarrier<PIPE_V>();
|
| 118 |
+
uint64_t mask[numTwo] = {0xffffffff, 0};
|
| 119 |
+
LocalTensor<float> outLocal = outQueueY.AllocTensor<float>();
|
| 120 |
+
for (int64_t i = 0; i < tilingData_->batchsPerBlock; i++) {
|
| 121 |
+
Mul(outLocal[i * numHead * hiddenDim], realLocal[i * numHead * hiddenDimHalf], cosLocal[i * hiddenDim],
|
| 122 |
+
mask, hiddenDim, {1, 1, 1, 8, 4, 0});
|
| 123 |
+
Mul(outLocal[i * numHead * hiddenDim + numHead], imagLocal[i * numHead * hiddenDimHalf],
|
| 124 |
+
cosLocal[i * hiddenDim + hiddenDimHalf], mask, hiddenDim, {1, 1, 1, 8, 4, 0});
|
| 125 |
+
}
|
| 126 |
+
PipeBarrier<PIPE_V>();
|
| 127 |
+
inQueueCos.FreeTensor(cosLocal);
|
| 128 |
+
|
| 129 |
+
LocalTensor<float> sinLocal = inQueueSin.AllocTensor<float>();
|
| 130 |
+
|
| 131 |
+
DataCopy(
|
| 132 |
+
sinLocal[tilingData_->batchsPerBlock * hiddenDim].template ReinterpretCast<T>(), sinGm,
|
| 133 |
+
tilingData_->batchsPerBlock * hiddenDim);
|
| 134 |
+
|
| 135 |
+
inQueueSin.EnQue(sinLocal);
|
| 136 |
+
sinLocal = inQueueSin.DeQue<float>();
|
| 137 |
+
Cast(
|
| 138 |
+
sinLocal, sinLocal[tilingData_->batchsPerBlock * hiddenDim].template ReinterpretCast<T>(),
|
| 139 |
+
RoundMode::CAST_NONE, tilingData_->batchsPerBlock * hiddenDim);
|
| 140 |
+
PipeBarrier<PIPE_V>();
|
| 141 |
+
Muls<float>(imagLocal, imagLocal, -1.0f, tilingData_->batchsPerBlock * numHead * hiddenDimHalf);
|
| 142 |
+
PipeBarrier<PIPE_V>();
|
| 143 |
+
for (int64_t i = 0; i < tilingData_->batchsPerBlock; i++) {
|
| 144 |
+
Mul(buf_[i * numHead * hiddenDim], imagLocal[i * numHead * hiddenDimHalf], sinLocal[i * hiddenDim], mask,
|
| 145 |
+
hiddenDim, {1, 1, 1, 8, 4, 0});
|
| 146 |
+
Mul(buf_[i * numHead * hiddenDim + hiddenDimHalf], realLocal[i * numHead * hiddenDimHalf],
|
| 147 |
+
sinLocal[i * hiddenDim + hiddenDimHalf], mask, hiddenDim, {1, 1, 1, 8, 4, 0});
|
| 148 |
+
}
|
| 149 |
+
PipeBarrier<PIPE_V>();
|
| 150 |
+
inQueueSin.FreeTensor(sinLocal);
|
| 151 |
+
Add(outLocal, outLocal, buf_, tilingData_->batchsPerBlock * numHead * hiddenDim);
|
| 152 |
+
PipeBarrier<PIPE_V>();
|
| 153 |
+
Cast(
|
| 154 |
+
outLocal[tilingData_->batchsPerBlock * numHead * hiddenDim].template ReinterpretCast<T>(), outLocal,
|
| 155 |
+
RoundMode::CAST_RINT, tilingData_->batchsPerBlock * numHead * hiddenDim);
|
| 156 |
+
outQueueY.EnQue(outLocal);
|
| 157 |
+
outLocal = outQueueY.DeQue<float>();
|
| 158 |
+
DataCopy(
|
| 159 |
+
yGm, outLocal[tilingData_->batchsPerBlock * numHead * hiddenDim].template ReinterpretCast<T>(),
|
| 160 |
+
tilingData_->batchsPerBlock * numHead * hiddenDim);
|
| 161 |
+
outQueueY.FreeTensor(outLocal);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
private:
|
| 165 |
+
TPipe* pipe_ = nullptr;
|
| 166 |
+
const InterleaveRopeTilingData* tilingData_;
|
| 167 |
+
GlobalTensor<T> xGm;
|
| 168 |
+
GlobalTensor<T> yGm;
|
| 169 |
+
GlobalTensor<T> cosGm;
|
| 170 |
+
GlobalTensor<T> sinGm;
|
| 171 |
+
|
| 172 |
+
TQue<QuePosition::VECIN, 1> inQueueX;
|
| 173 |
+
TQue<QuePosition::VECIN, 1> inQueueCos;
|
| 174 |
+
TQue<QuePosition::VECIN, 1> inQueueSin;
|
| 175 |
+
TQue<QuePosition::VECOUT, 1> outQueueY;
|
| 176 |
+
TBuf<TPosition::VECCALC> bufferReal;
|
| 177 |
+
TBuf<TPosition::VECCALC> bufferImag;
|
| 178 |
+
TBuf<TPosition::VECCALC> buffer_;
|
| 179 |
+
|
| 180 |
+
constexpr static int64_t hiddenDim = 64;
|
| 181 |
+
constexpr static int64_t hiddenDimHalf = 32;
|
| 182 |
+
constexpr static int64_t numHead = 32;
|
| 183 |
+
constexpr static int64_t seqLength = 1;
|
| 184 |
+
constexpr static int64_t numTwo = 2;
|
| 185 |
+
};
|
| 186 |
+
} // namespace InterleaveRope
|
| 187 |
+
|
| 188 |
+
#endif // _INTERLEAVE_ROPE_FIX_BNSD_B11D_H_
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/op_kernel/interleave_rope_split_s.h
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file interleave_rope_split_s.h
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
#ifndef _INTERLEAVE_ROPE_SPLIT_S_H_
|
| 16 |
+
#define _INTERLEAVE_ROPE_SPLIT_S_H_
|
| 17 |
+
#include "platform/platform_infos_def.h"
|
| 18 |
+
#include "kernel_operator.h"
|
| 19 |
+
|
| 20 |
+
namespace InterleaveRope {
|
| 21 |
+
using namespace AscendC;
|
| 22 |
+
|
| 23 |
+
template <typename T>
|
| 24 |
+
class KernelInterleaveRopeSplitS {
|
| 25 |
+
public:
|
| 26 |
+
__aicore__ inline KernelInterleaveRopeSplitS(TPipe* pipe, const InterleaveRopeTilingData* tiling)
|
| 27 |
+
: pipe_(pipe), tilingData_(tiling)
|
| 28 |
+
{}
|
| 29 |
+
|
| 30 |
+
__aicore__ inline void Init(GM_ADDR x, GM_ADDR cos, GM_ADDR sin, GM_ADDR y)
|
| 31 |
+
{
|
| 32 |
+
/*
|
| 33 |
+
* For each block, process
|
| 34 |
+
* x: [B, N, S, 64]
|
| 35 |
+
* cos: [B, 1, S, 64]
|
| 36 |
+
* sin: [B, 1, S, 64]
|
| 37 |
+
* y: [B, N, S, 64]
|
| 38 |
+
*/
|
| 39 |
+
// tilingData
|
| 40 |
+
int64_t blockFactor = (tilingData_->seqLength + tilingData_->numBlocks - 1) / tilingData_->numBlocks;
|
| 41 |
+
int64_t currentBlockFactor = blockFactor;
|
| 42 |
+
if (GetBlockIdx() == tilingData_->numBlocks - 1) {
|
| 43 |
+
currentBlockFactor = tilingData_->seqLength - GetBlockIdx() * blockFactor;
|
| 44 |
+
}
|
| 45 |
+
ubFactor = 32; // ubfactor: 32
|
| 46 |
+
ubLoop = currentBlockFactor / ubFactor;
|
| 47 |
+
ubTail = currentBlockFactor - ubFactor * ubLoop;
|
| 48 |
+
|
| 49 |
+
xGm.SetGlobalBuffer((__gm__ T*)x + GetBlockIdx() * blockFactor * ROPE_LENGTH);
|
| 50 |
+
yGm.SetGlobalBuffer((__gm__ T*)y + GetBlockIdx() * blockFactor * ROPE_LENGTH);
|
| 51 |
+
cosGm.SetGlobalBuffer((__gm__ T*)cos + GetBlockIdx() * blockFactor * ROPE_LENGTH);
|
| 52 |
+
sinGm.SetGlobalBuffer((__gm__ T*)sin + GetBlockIdx() * blockFactor * ROPE_LENGTH);
|
| 53 |
+
|
| 54 |
+
// init pipe
|
| 55 |
+
pipe_->InitBuffer(inQueueX, 2, ubFactor * ROPE_LENGTH * sizeof(T)); // 2*ubFactor*64*2=256*ubFactor
|
| 56 |
+
pipe_->InitBuffer(inQueuePosEmb, 2, 2 * ubFactor * ROPE_LENGTH * sizeof(T)); // 2*2*ubFactor*64*2=512*ubFactor
|
| 57 |
+
pipe_->InitBuffer(outQueue, 2, ubFactor * ROPE_LENGTH * sizeof(T)); // 2*ubFactor*64*2=256*ubFactor
|
| 58 |
+
pipe_->InitBuffer(wsBuffer, 8 * ubFactor * ROPE_LENGTH * sizeof(float)); // 8*ubFactor*64*4=2048*ubFactor
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
__aicore__ inline void Process()
|
| 62 |
+
{
|
| 63 |
+
LocalTensor<float> workspaceBuffer = wsBuffer.Get<float>();
|
| 64 |
+
|
| 65 |
+
DataCopyPadExtParams<T> padParams{false, 0, 0, 0};
|
| 66 |
+
DataCopyExtParams copyParamsContinguous;
|
| 67 |
+
copyParamsContinguous.blockCount = 1;
|
| 68 |
+
int64_t xOffset = 0;
|
| 69 |
+
int64_t freqOffset = 0;
|
| 70 |
+
for (int64_t batchId = 0; batchId < tilingData_->batchSize; batchId++) {
|
| 71 |
+
copyParamsContinguous.blockLen = ubFactor * ROPE_LENGTH * sizeof(T);
|
| 72 |
+
for (int64_t loopIdx = 0; loopIdx < ubLoop; ++loopIdx) {
|
| 73 |
+
freqOffset = batchId * tilingData_->seqLength * ROPE_LENGTH + loopIdx * ubFactor * ROPE_LENGTH;
|
| 74 |
+
/*
|
| 75 |
+
* cosLocal = [batchId, 0, :ubFactor:, 64]
|
| 76 |
+
* sinLocal = [batchId, 0, :ubFactor:, 64]
|
| 77 |
+
*/
|
| 78 |
+
LocalTensor<T> cosLocal = inQueuePosEmb.AllocTensor<T>();
|
| 79 |
+
LocalTensor<T> sinLocal = cosLocal[ubFactor * ROPE_LENGTH];
|
| 80 |
+
DataCopyPad(cosLocal, cosGm[freqOffset], copyParamsContinguous, padParams);
|
| 81 |
+
DataCopyPad(sinLocal, sinGm[freqOffset], copyParamsContinguous, padParams);
|
| 82 |
+
inQueuePosEmb.EnQue(cosLocal);
|
| 83 |
+
cosLocal = inQueuePosEmb.DeQue<T>();
|
| 84 |
+
sinLocal = cosLocal[ubFactor * ROPE_LENGTH];
|
| 85 |
+
|
| 86 |
+
for (int64_t headId = 0; headId < tilingData_->numHead; ++headId) {
|
| 87 |
+
xOffset = batchId * tilingData_->numHead * tilingData_->seqLength * ROPE_LENGTH +
|
| 88 |
+
loopIdx * ubFactor * ROPE_LENGTH + headId * tilingData_->seqLength * ROPE_LENGTH;
|
| 89 |
+
/*
|
| 90 |
+
* xLocal = [batchId, headId, seqId: seqId+ubFactor, 64]
|
| 91 |
+
* yLocal = [batchId, headId, seqId: seqId+ubFactor, 64]
|
| 92 |
+
*/
|
| 93 |
+
LocalTensor<T> xLocal = inQueueX.AllocTensor<T>();
|
| 94 |
+
DataCopyPad(xLocal, xGm[xOffset], copyParamsContinguous, padParams);
|
| 95 |
+
inQueueX.EnQue(xLocal);
|
| 96 |
+
xLocal = inQueueX.DeQue<T>();
|
| 97 |
+
LocalTensor<T> yLocal = outQueue.AllocTensor<T>();
|
| 98 |
+
RoPE<T, true, ROPE_LENGTH>(yLocal, xLocal, cosLocal, sinLocal, workspaceBuffer, ubFactor);
|
| 99 |
+
inQueueX.FreeTensor(xLocal);
|
| 100 |
+
outQueue.EnQue(yLocal);
|
| 101 |
+
yLocal = outQueue.DeQue<T>();
|
| 102 |
+
DataCopyPad(yGm[xOffset], yLocal, copyParamsContinguous);
|
| 103 |
+
outQueue.FreeTensor(yLocal);
|
| 104 |
+
}
|
| 105 |
+
inQueuePosEmb.FreeTensor(cosLocal);
|
| 106 |
+
}
|
| 107 |
+
copyParamsContinguous.blockLen = ubTail * ROPE_LENGTH * sizeof(T);
|
| 108 |
+
if (ubTail > 0) {
|
| 109 |
+
freqOffset = batchId * tilingData_->seqLength * ROPE_LENGTH + ubLoop * ubFactor * ROPE_LENGTH;
|
| 110 |
+
/*
|
| 111 |
+
* cosLocal = [batchId, 0, :ubTail:, 64]
|
| 112 |
+
* sinLocal = [batchId, 0, :ubTail:, 64]
|
| 113 |
+
*/
|
| 114 |
+
LocalTensor<T> cosLocal = inQueuePosEmb.AllocTensor<T>();
|
| 115 |
+
LocalTensor<T> sinLocal = cosLocal[ubFactor * ROPE_LENGTH];
|
| 116 |
+
DataCopyPad(cosLocal, cosGm[freqOffset], copyParamsContinguous, padParams);
|
| 117 |
+
DataCopyPad(sinLocal, sinGm[freqOffset], copyParamsContinguous, padParams);
|
| 118 |
+
inQueuePosEmb.EnQue(cosLocal);
|
| 119 |
+
cosLocal = inQueuePosEmb.DeQue<T>();
|
| 120 |
+
sinLocal = cosLocal[ubFactor * ROPE_LENGTH];
|
| 121 |
+
|
| 122 |
+
for (int64_t headId = 0; headId < tilingData_->numHead; ++headId) {
|
| 123 |
+
xOffset = batchId * tilingData_->numHead * tilingData_->seqLength * ROPE_LENGTH +
|
| 124 |
+
ubLoop * ubFactor * ROPE_LENGTH + headId * tilingData_->seqLength * ROPE_LENGTH;
|
| 125 |
+
/*
|
| 126 |
+
* xLocal = [batchId, headId, seqId: seqId+ubFactor, 64]
|
| 127 |
+
* yLocal = [batchId, headId, seqId: seqId+ubFactor, 64]
|
| 128 |
+
*/
|
| 129 |
+
LocalTensor<T> xLocal = inQueueX.AllocTensor<T>();
|
| 130 |
+
DataCopyPad(xLocal, xGm[xOffset], copyParamsContinguous, padParams);
|
| 131 |
+
inQueueX.EnQue(xLocal);
|
| 132 |
+
xLocal = inQueueX.DeQue<T>();
|
| 133 |
+
LocalTensor<T> yLocal = outQueue.AllocTensor<T>();
|
| 134 |
+
RoPE<T, true, ROPE_LENGTH>(yLocal, xLocal, cosLocal, sinLocal, workspaceBuffer, ubTail);
|
| 135 |
+
inQueueX.FreeTensor(xLocal);
|
| 136 |
+
outQueue.EnQue(yLocal);
|
| 137 |
+
yLocal = outQueue.DeQue<T>();
|
| 138 |
+
DataCopyPad(yGm[xOffset], yLocal, copyParamsContinguous);
|
| 139 |
+
outQueue.FreeTensor(yLocal);
|
| 140 |
+
}
|
| 141 |
+
inQueuePosEmb.FreeTensor(cosLocal);
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
template <typename T1, bool isElementWise = true, int64_t headSize>
|
| 147 |
+
__aicore__ inline void RoPE(
|
| 148 |
+
const LocalTensor<T1>& outLocal, const LocalTensor<T1>& xLocal, const LocalTensor<T1>& cosLocal,
|
| 149 |
+
const LocalTensor<T1>& sinLocal, const LocalTensor<float>& wsLocal, int64_t rows)
|
| 150 |
+
{
|
| 151 |
+
constexpr static int64_t NUM_ONE = 1;
|
| 152 |
+
constexpr static int64_t NUM_TWO = 2;
|
| 153 |
+
constexpr static int64_t NUM_THREE = 3;
|
| 154 |
+
constexpr static int64_t NUM_FOUR = 4;
|
| 155 |
+
constexpr static int64_t NUM_EIGHT = 8;
|
| 156 |
+
if constexpr (isElementWise) {
|
| 157 |
+
/**
|
| 158 |
+
* cosLocalFp32 : [rows * headSize * 0, rows * headSize * 1]
|
| 159 |
+
* sinLocalFp32 : [rows * headSize * 1, rows * headSize * 2]
|
| 160 |
+
* y0 : [rows * headSize * 2, rows * headSize * 3]
|
| 161 |
+
* y1 : [rows * headSize * 3, rows * headSize * 4]
|
| 162 |
+
* realLocalFp32: [rows * headSize * 4, rows * headSize * 5]
|
| 163 |
+
* imagLocalFp32: [rows * headSize * 5, rows * headSize * 6]
|
| 164 |
+
* realLocal : [rows * headSize * 6, rows * headSize * 7]
|
| 165 |
+
* imagLocal : [rows * headSize * 7, rows * headSize * 8]
|
| 166 |
+
*/
|
| 167 |
+
int64_t cosLocalFp32Offset = rows * headSize * 0;
|
| 168 |
+
int64_t sinLocalFp32Offset = rows * headSize * 1;
|
| 169 |
+
int64_t y0Offset = rows * headSize * 2;
|
| 170 |
+
int64_t y1Offset = rows * headSize * 3;
|
| 171 |
+
int64_t realLocalFp32Offset = rows * headSize * 4;
|
| 172 |
+
int64_t imagLocalFp32Offset = rows * headSize * 5;
|
| 173 |
+
int64_t realLocalOffset = rows * headSize * 6;
|
| 174 |
+
int64_t imagLocalOffset = rows * headSize * 7;
|
| 175 |
+
|
| 176 |
+
LocalTensor<float> cosLocalFp32 = wsLocal[cosLocalFp32Offset];
|
| 177 |
+
LocalTensor<float> sinLocalFp32 = wsLocal[sinLocalFp32Offset];
|
| 178 |
+
LocalTensor<float> y0 = wsLocal[y0Offset];
|
| 179 |
+
LocalTensor<float> y1 = wsLocal[y1Offset];
|
| 180 |
+
LocalTensor<float> realLocalFp32 = wsLocal[realLocalFp32Offset];
|
| 181 |
+
LocalTensor<float> imagLocalFp32 = wsLocal[imagLocalFp32Offset];
|
| 182 |
+
LocalTensor<T1> realLocal = wsLocal[realLocalOffset].template ReinterpretCast<T1>();
|
| 183 |
+
LocalTensor<T1> imagLocal = wsLocal[imagLocalOffset].template ReinterpretCast<T1>();
|
| 184 |
+
|
| 185 |
+
// step #1: cast cosLocal and sinLocal to fp32
|
| 186 |
+
Cast(cosLocalFp32, cosLocal, RoundMode::CAST_NONE, rows * headSize);
|
| 187 |
+
Cast(sinLocalFp32, sinLocal, RoundMode::CAST_NONE, rows * headSize);
|
| 188 |
+
PipeBarrier<PIPE_V>();
|
| 189 |
+
|
| 190 |
+
// step #2: Gather out real and imag
|
| 191 |
+
uint64_t rsvdCnt = 0;
|
| 192 |
+
GatherMask(realLocal, xLocal, NUM_ONE, true, rows * headSize, {1, 1, NUM_EIGHT, 0}, rsvdCnt);
|
| 193 |
+
GatherMask(imagLocal, xLocal, NUM_TWO, true, rows * headSize, {1, 1, NUM_EIGHT, 0}, rsvdCnt);
|
| 194 |
+
PipeBarrier<PIPE_V>();
|
| 195 |
+
|
| 196 |
+
// step #3: Cast realLocal and imagLocal to Fp32
|
| 197 |
+
Cast(realLocalFp32, realLocal, RoundMode::CAST_NONE, rows * (headSize >> 1));
|
| 198 |
+
Cast(imagLocalFp32, imagLocal, RoundMode::CAST_NONE, rows * (headSize >> 1));
|
| 199 |
+
PipeBarrier<PIPE_V>();
|
| 200 |
+
|
| 201 |
+
// step #4: y0 = (realLocalFp32, imagLocalFp32) * cosLocalFp32
|
| 202 |
+
Mul(y0, realLocalFp32, cosLocalFp32, /* mask */ (headSize >> 1), /* repeat */ rows,
|
| 203 |
+
{1, 1, 1, NUM_EIGHT, NUM_FOUR, NUM_EIGHT});
|
| 204 |
+
Mul(y0[(headSize >> 1)], imagLocalFp32, cosLocalFp32[(headSize >> 1)], /* mask */ (headSize >> 1),
|
| 205 |
+
/* repeat */ rows, {1, 1, 1, NUM_EIGHT, NUM_FOUR, NUM_EIGHT});
|
| 206 |
+
PipeBarrier<PIPE_V>();
|
| 207 |
+
|
| 208 |
+
// step #5: y1 = (-imagLocalFp32, realLocalFp32) * sinLocalFp32
|
| 209 |
+
Muls<float>(imagLocalFp32, imagLocalFp32, -1.0f, rows * (headSize >> 1));
|
| 210 |
+
PipeBarrier<PIPE_V>();
|
| 211 |
+
Mul(y1, imagLocalFp32, sinLocalFp32, /* mask */ (headSize >> 1), /* repeat */ rows,
|
| 212 |
+
{1, 1, 1, NUM_EIGHT, NUM_FOUR, NUM_EIGHT});
|
| 213 |
+
Mul(y1[(headSize >> 1)], realLocalFp32, sinLocalFp32[(headSize >> 1)], /* mask */ (headSize >> 1),
|
| 214 |
+
/* repeat */ rows, {1, 1, 1, NUM_EIGHT, NUM_FOUR, NUM_EIGHT});
|
| 215 |
+
PipeBarrier<PIPE_V>();
|
| 216 |
+
|
| 217 |
+
// step #6: y0 = y0 + y1
|
| 218 |
+
Add(y0, y0, y1, rows * headSize);
|
| 219 |
+
PipeBarrier<PIPE_V>();
|
| 220 |
+
|
| 221 |
+
// step #7: outLocal = Cast(y0, T1)
|
| 222 |
+
if constexpr (std::is_same<T1, bfloat16_t>::value) {
|
| 223 |
+
Cast(outLocal, y0, RoundMode::CAST_RINT, rows * headSize);
|
| 224 |
+
} else if constexpr (std::is_same<T1, half>::value) {
|
| 225 |
+
Cast(outLocal, y0, RoundMode::CAST_NONE, rows * headSize);
|
| 226 |
+
}
|
| 227 |
+
}
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
private:
|
| 231 |
+
TPipe* pipe_ = nullptr;
|
| 232 |
+
const InterleaveRopeTilingData* tilingData_;
|
| 233 |
+
constexpr static int64_t ROPE_LENGTH = 64;
|
| 234 |
+
GlobalTensor<T> xGm;
|
| 235 |
+
GlobalTensor<T> yGm;
|
| 236 |
+
GlobalTensor<T> cosGm;
|
| 237 |
+
GlobalTensor<T> sinGm;
|
| 238 |
+
|
| 239 |
+
TQue<QuePosition::VECIN, 1> inQueueX;
|
| 240 |
+
TQue<QuePosition::VECIN, 1> inQueuePosEmb;
|
| 241 |
+
TQue<QuePosition::VECOUT, 1> outQueue;
|
| 242 |
+
TBuf<TPosition::VECCALC> wsBuffer;
|
| 243 |
+
int64_t ubFactor = 1;
|
| 244 |
+
int64_t ubTail = 0;
|
| 245 |
+
int64_t ubLoop = 0;
|
| 246 |
+
};
|
| 247 |
+
} // namespace InterleaveRope
|
| 248 |
+
|
| 249 |
+
#endif // _INTERLEAVE_ROPE_SPLIT_S_H_
|
datasets/ops_src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
| 8 |
+
{
|
| 9 |
+
"id": 0,
|
| 10 |
+
"dtype": "float16",
|
| 11 |
+
"shape": [
|
| 12 |
+
32,
|
| 13 |
+
1,
|
| 14 |
+
32,
|
| 15 |
+
64
|
| 16 |
+
],
|
| 17 |
+
"attrs": {
|
| 18 |
+
"cos_s": 1
|
| 19 |
+
}
|
| 20 |
+
},
|
| 21 |
+
{
|
| 22 |
+
"id": 1,
|
| 23 |
+
"dtype": "float16",
|
| 24 |
+
"shape": [
|
| 25 |
+
32,
|
| 26 |
+
1,
|
| 27 |
+
64,
|
| 28 |
+
64
|
| 29 |
+
],
|
| 30 |
+
"attrs": {
|
| 31 |
+
"cos_s": 1
|
| 32 |
+
}
|
| 33 |
+
},
|
| 34 |
+
{
|
| 35 |
+
"id": 2,
|
| 36 |
+
"dtype": "float16",
|
| 37 |
+
"shape": [
|
| 38 |
+
32,
|
| 39 |
+
1,
|
| 40 |
+
128,
|
| 41 |
+
64
|
| 42 |
+
],
|
| 43 |
+
"attrs": {
|
| 44 |
+
"cos_s": 1
|
| 45 |
+
}
|
| 46 |
+
},
|
| 47 |
+
{
|
| 48 |
+
"id": 3,
|
| 49 |
+
"dtype": "bfloat16",
|
| 50 |
+
"shape": [
|
| 51 |
+
64,
|
| 52 |
+
1,
|
| 53 |
+
32,
|
| 54 |
+
64
|
| 55 |
+
],
|
| 56 |
+
"attrs": {
|
| 57 |
+
"cos_s": 1
|
| 58 |
+
}
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"id": 4,
|
| 62 |
+
"dtype": "bfloat16",
|
| 63 |
+
"shape": [
|
| 64 |
+
64,
|
| 65 |
+
1,
|
| 66 |
+
64,
|
| 67 |
+
64
|
| 68 |
+
],
|
| 69 |
+
"attrs": {
|
| 70 |
+
"cos_s": 1
|
| 71 |
+
}
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"id": 5,
|
| 75 |
+
"dtype": "float16",
|
| 76 |
+
"shape": [
|
| 77 |
+
128,
|
| 78 |
+
1,
|
| 79 |
+
32,
|
| 80 |
+
64
|
| 81 |
+
],
|
| 82 |
+
"attrs": {
|
| 83 |
+
"cos_s": 1
|
| 84 |
+
}
|
| 85 |
+
},
|
| 86 |
+
{
|
| 87 |
+
"id": 6,
|
| 88 |
+
"dtype": "float16",
|
| 89 |
+
"shape": [
|
| 90 |
+
32,
|
| 91 |
+
1,
|
| 92 |
+
512,
|
| 93 |
+
64
|
| 94 |
+
],
|
| 95 |
+
"attrs": {
|
| 96 |
+
"cos_s": 512
|
| 97 |
+
}
|
| 98 |
+
},
|
| 99 |
+
{
|
| 100 |
+
"id": 7,
|
| 101 |
+
"dtype": "bfloat16",
|
| 102 |
+
"shape": [
|
| 103 |
+
128,
|
| 104 |
+
1,
|
| 105 |
+
64,
|
| 106 |
+
64
|
| 107 |
+
],
|
| 108 |
+
"attrs": {
|
| 109 |
+
"cos_s": 1
|
| 110 |
+
}
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"id": 8,
|
| 114 |
+
"dtype": "float16",
|
| 115 |
+
"shape": [
|
| 116 |
+
64,
|
| 117 |
+
1,
|
| 118 |
+
1024,
|
| 119 |
+
64
|
| 120 |
+
],
|
| 121 |
+
"attrs": {
|
| 122 |
+
"cos_s": 1024
|
| 123 |
+
}
|
| 124 |
+
},
|
| 125 |
+
{
|
| 126 |
+
"id": 9,
|
| 127 |
+
"dtype": "bfloat16",
|
| 128 |
+
"shape": [
|
| 129 |
+
32,
|
| 130 |
+
1,
|
| 131 |
+
1,
|
| 132 |
+
64
|
| 133 |
+
],
|
| 134 |
+
"attrs": {
|
| 135 |
+
"cos_s": 1
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
]
|
| 139 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/CMakeLists.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 2 |
+
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
# CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
message(STATUS "=== Debug: start ops.posembedding.interleave_rope.tests.CMakeLists.txt ")
|
| 12 |
+
file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
|
| 13 |
+
foreach(SUB_DIR ${CURRENT_DIRS})
|
| 14 |
+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
|
| 15 |
+
add_subdirectory(${SUB_DIR})
|
| 16 |
+
endif()
|
| 17 |
+
endforeach()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/CMakeLists.txt
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 2 |
+
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
# CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
# 每个目录下需要生成的可执行文件,具体参考:ops/built-in/test/CMakeLists.txt: 50~124
|
| 12 |
+
file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
|
| 13 |
+
foreach(SUB_DIR ${CURRENT_DIRS})
|
| 14 |
+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
|
| 15 |
+
add_subdirectory(${SUB_DIR})
|
| 16 |
+
endif()
|
| 17 |
+
endforeach()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/CMakeLists.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 2 |
+
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
# CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
if(UT_TEST_ALL OR OP_HOST_UT)
|
| 12 |
+
add_modules_ut_sources(UT_NAME ${OP_TILING_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
| 13 |
+
add_modules_ut_sources(UT_NAME ${OP_INFERSHAPE_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
| 14 |
+
endif()
|
| 15 |
+
|
| 16 |
+
file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
|
| 17 |
+
foreach(SUB_DIR ${CURRENT_DIRS})
|
| 18 |
+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
|
| 19 |
+
add_subdirectory(${SUB_DIR})
|
| 20 |
+
endif()
|
| 21 |
+
endforeach()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/op_api/CMakeLists.txt
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 2 |
+
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
# CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
message(STATUS "=== Debug: target_sources add test_interleave_rope")
|
| 12 |
+
|
| 13 |
+
if(UT_TEST_ALL OR OP_API_UT)
|
| 14 |
+
add_modules_ut_sources(UT_NAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
| 15 |
+
endif()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/op_api/test_aclnn_interleave_rope.cpp
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include <vector>
|
| 12 |
+
#include <array>
|
| 13 |
+
#include <float.h>
|
| 14 |
+
#include "gtest/gtest.h"
|
| 15 |
+
#include "../../../../op_host/op_api/aclnn_interleave_rope.h"
|
| 16 |
+
#include "opdev/platform.h"
|
| 17 |
+
#include "op_api_ut_common/tensor_desc.h"
|
| 18 |
+
#include "op_api_ut_common/scalar_desc.h"
|
| 19 |
+
#include "op_api_ut_common/op_api_ut.h"
|
| 20 |
+
|
| 21 |
+
using namespace std;
|
| 22 |
+
|
| 23 |
+
class l2_interleave_rope_test : public testing::Test
|
| 24 |
+
{
|
| 25 |
+
protected:
|
| 26 |
+
static void SetUpTestCase()
|
| 27 |
+
{
|
| 28 |
+
cout << "l2_interleave_rope_test SetUp" << endl;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
static void TearDownTestCase()
|
| 32 |
+
{
|
| 33 |
+
cout << "l2_interleave_rope_test TearDown" << endl;
|
| 34 |
+
}
|
| 35 |
+
};
|
| 36 |
+
|
| 37 |
+
// dtype fp32
|
| 38 |
+
TEST_F(l2_interleave_rope_test, Ascend910B2_interleave_rope_fp32)
|
| 39 |
+
{
|
| 40 |
+
auto x = TensorDesc({8, 1, 1, 64}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-10, 10);
|
| 41 |
+
auto cos = TensorDesc({8, 1, 1, 64}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(0, 8);
|
| 42 |
+
auto sin = TensorDesc({8, 1, 1, 64}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(0, 8);
|
| 43 |
+
auto out = TensorDesc({8, 1, 1, 64}, ACL_FLOAT16, ACL_FORMAT_ND);
|
| 44 |
+
auto ut = OP_API_UT(aclnnInterleaveRope, INPUT(x, cos, sin), OUTPUT(out));
|
| 45 |
+
uint64_t workspaceSize = 0;
|
| 46 |
+
aclOpExecutor* executor = nullptr;
|
| 47 |
+
aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSizeWithNNopbaseInner(&workspaceSize, executor);
|
| 48 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/test_interleave_rope_infershape.cpp
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include <gtest/gtest.h>
|
| 12 |
+
#include <iostream>
|
| 13 |
+
#include "infer_shape_context_faker.h"
|
| 14 |
+
#include "infer_shape_case_executor.h"
|
| 15 |
+
#include "base/registry/op_impl_space_registry_v2.h"
|
| 16 |
+
#include "infer_datatype_context_faker.h"
|
| 17 |
+
|
| 18 |
+
class InterleaveRope : public testing::Test {
|
| 19 |
+
protected:
|
| 20 |
+
static void SetUpTestCase()
|
| 21 |
+
{
|
| 22 |
+
std::cout << "InterleaveRope SetUp" << std::endl;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
static void TearDownTestCase()
|
| 26 |
+
{
|
| 27 |
+
std::cout << "InterleaveRope TearDown" << std::endl;
|
| 28 |
+
}
|
| 29 |
+
};
|
| 30 |
+
|
| 31 |
+
TEST_F(InterleaveRope, InterleaveRope_infer_shape_00)
|
| 32 |
+
{
|
| 33 |
+
gert::InfershapeContextPara infershapeContextPara(
|
| 34 |
+
"InterleaveRope",
|
| 35 |
+
{
|
| 36 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 37 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 38 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
{{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 42 |
+
});
|
| 43 |
+
std::vector<std::vector<int64_t>> expectOutputShape = {{32, 32, 1, 64}};
|
| 44 |
+
ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape);
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
TEST_F(InterleaveRope, InterleaveRope_infer_shape_01)
|
| 48 |
+
{
|
| 49 |
+
gert::InfershapeContextPara infershapeContextPara(
|
| 50 |
+
"InterleaveRope",
|
| 51 |
+
{
|
| 52 |
+
{{{32, 32, 4, 64}, {32, 32, 4, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 53 |
+
{{{32, 1, 4, 64}, {32, 1, 4, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 54 |
+
{{{32, 1, 4, 64}, {32, 1, 4, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 55 |
+
},
|
| 56 |
+
{
|
| 57 |
+
{{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 58 |
+
});
|
| 59 |
+
std::vector<std::vector<int64_t>> expectOutputShape = {{32, 32, 4, 64}};
|
| 60 |
+
ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape);
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
TEST_F(InterleaveRope, InterleaveRope_inferdtype)
|
| 64 |
+
{
|
| 65 |
+
ASSERT_NE(gert::DefaultOpImplSpaceRegistryV2::GetInstance().GetSpaceRegistry()->GetOpImpl("InterleaveRope"),
|
| 66 |
+
nullptr);
|
| 67 |
+
auto data_type_func = gert::DefaultOpImplSpaceRegistryV2::GetInstance()
|
| 68 |
+
.GetSpaceRegistry()
|
| 69 |
+
->GetOpImpl("InterleaveRope")
|
| 70 |
+
->infer_datatype;
|
| 71 |
+
ASSERT_NE(data_type_func, nullptr);
|
| 72 |
+
|
| 73 |
+
ge::DataType input_0 = ge::DT_FLOAT16;
|
| 74 |
+
ge::DataType output_0 = ge::DT_FLOAT16;
|
| 75 |
+
auto context_holder = gert::InferDataTypeContextFaker()
|
| 76 |
+
.IrInputNum(3)
|
| 77 |
+
.NodeIoNum(3, 1)
|
| 78 |
+
.IrInstanceNum({1, 1, 1})
|
| 79 |
+
.NodeInputTd(0, ge::DT_FLOAT16, ge::FORMAT_ND, ge::FORMAT_ND)
|
| 80 |
+
.NodeInputTd(1, ge::DT_FLOAT16, ge::FORMAT_ND, ge::FORMAT_ND)
|
| 81 |
+
.NodeInputTd(2, ge::DT_FLOAT16, ge::FORMAT_ND, ge::FORMAT_ND)
|
| 82 |
+
.NodeOutputTd(0, ge::FORMAT_ND, ge::FORMAT_ND)
|
| 83 |
+
.InputDataTypes({&input_0, &input_0, &input_0})
|
| 84 |
+
.OutputDataTypes({&output_0})
|
| 85 |
+
.Build();
|
| 86 |
+
|
| 87 |
+
auto context = context_holder.GetContext<gert::InferDataTypeContext>();
|
| 88 |
+
EXPECT_EQ(data_type_func(context), ge::GRAPH_SUCCESS);
|
| 89 |
+
ASSERT_NE(context, nullptr);
|
| 90 |
+
|
| 91 |
+
EXPECT_EQ(context->GetOutputDataType(0), ge::DT_FLOAT16);
|
| 92 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_host/test_interleave_rope_tiling.cpp
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/* !
|
| 12 |
+
* \file test_interleave_rope_tiling.cpp
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#include <iostream>
|
| 17 |
+
#include <gtest/gtest.h>
|
| 18 |
+
#include "tiling_context_faker.h"
|
| 19 |
+
#include "tiling_case_executor.h"
|
| 20 |
+
#include "../../../op_host/interleave_rope_tiling.h"
|
| 21 |
+
|
| 22 |
+
using namespace std;
|
| 23 |
+
|
| 24 |
+
class InterleaveRopeTiling : public testing::Test
|
| 25 |
+
{
|
| 26 |
+
protected:
|
| 27 |
+
static void SetUpTestCase()
|
| 28 |
+
{
|
| 29 |
+
std::cout << "InterleaveRopeTiling SetUp" << std::endl;
|
| 30 |
+
}
|
| 31 |
+
|
| 32 |
+
static void TearDownTestCase()
|
| 33 |
+
{
|
| 34 |
+
std::cout << "InterleaveRopeTiling TearDown" << std::endl;
|
| 35 |
+
}
|
| 36 |
+
};
|
| 37 |
+
|
| 38 |
+
static string TilingData2Str(const gert::TilingData* tiling_data)
|
| 39 |
+
{
|
| 40 |
+
auto data = tiling_data->GetData();
|
| 41 |
+
string result;
|
| 42 |
+
for (size_t i = 0; i < tiling_data->GetDataSize(); i += sizeof(int64_t)) {
|
| 43 |
+
result += std::to_string((reinterpret_cast<const int64_t*>(tiling_data->GetData())[i / sizeof(int64_t)]));
|
| 44 |
+
result += " ";
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
return result;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
TEST_F(InterleaveRopeTiling, interleave_rope_tiling_000)
|
| 51 |
+
{
|
| 52 |
+
optiling::InterleaveRopeCompileInfo compileInfo = {};
|
| 53 |
+
gert::TilingContextPara tilingContextPara("InterleaveRope",
|
| 54 |
+
{
|
| 55 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 56 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 57 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 58 |
+
},
|
| 59 |
+
{
|
| 60 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 61 |
+
},
|
| 62 |
+
&compileInfo);
|
| 63 |
+
uint64_t expectTilingKey = 1000;
|
| 64 |
+
string expectTilingData = "8 0 32 32 1 64 4 4 0 0 0 0 0 0 0 0 0 0 0 ";
|
| 65 |
+
std::vector<size_t> expectWorkspaces = {32};
|
| 66 |
+
ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces);
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
TEST_F(InterleaveRopeTiling, interleave_rope_tiling_001)
|
| 70 |
+
{
|
| 71 |
+
optiling::InterleaveRopeCompileInfo compileInfo = {};
|
| 72 |
+
gert::TilingContextPara tilingContextPara("InterleaveRope",
|
| 73 |
+
{
|
| 74 |
+
{{{32, 32, 4, 64}, {32, 32, 4, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 75 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 76 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 77 |
+
},
|
| 78 |
+
{
|
| 79 |
+
{{{32, 32, 4, 64}, {32, 32, 4, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 80 |
+
},
|
| 81 |
+
&compileInfo);
|
| 82 |
+
uint64_t expectTilingKey = 2000;
|
| 83 |
+
string expectTilingData = "64 1 32 32 4 64 32 32 0 0 0 2 2 1 2 2 1 2 2 ";
|
| 84 |
+
std::vector<size_t> expectWorkspaces = {32};
|
| 85 |
+
ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces);
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
TEST_F(InterleaveRopeTiling, interleave_rope_tiling_002)
|
| 89 |
+
{
|
| 90 |
+
optiling::InterleaveRopeCompileInfo compileInfo = {};
|
| 91 |
+
gert::TilingContextPara tilingContextPara("InterleaveRope",
|
| 92 |
+
{
|
| 93 |
+
{{{32, 32, 4, 64}, {32, 32, 4, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 94 |
+
{{{32, 1, 4, 64}, {32, 1, 4, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 95 |
+
{{{32, 1, 4, 64}, {32, 1, 4, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
{{{32, 32, 4, 64}, {32, 32, 4, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 99 |
+
},
|
| 100 |
+
&compileInfo);
|
| 101 |
+
uint64_t expectTilingKey = 3000;
|
| 102 |
+
string expectTilingData = "32 0 32 32 4 64 1 1 0 0 0 4 4 1 4 4 1 4 4 ";
|
| 103 |
+
std::vector<size_t> expectWorkspaces = {32};
|
| 104 |
+
ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces);
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
TEST_F(InterleaveRopeTiling, interleave_rope_tiling_hidden_dim_not_64)
|
| 108 |
+
{
|
| 109 |
+
optiling::InterleaveRopeCompileInfo compileInfo = {};
|
| 110 |
+
gert::TilingContextPara tilingContextPara("InterleaveRope",
|
| 111 |
+
{
|
| 112 |
+
{{{32, 32, 1, 63}, {32, 32, 1, 63}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 113 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 114 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 115 |
+
},
|
| 116 |
+
{
|
| 117 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 118 |
+
},
|
| 119 |
+
&compileInfo);
|
| 120 |
+
uint64_t expectTilingKey = 0;
|
| 121 |
+
string expectTilingData = "";
|
| 122 |
+
std::vector<size_t> expectWorkspaces = {};
|
| 123 |
+
ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED, expectTilingKey, expectTilingData, expectWorkspaces);
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
TEST_F(InterleaveRopeTiling, interleave_rope_tiling_shape_len_not_4)
|
| 127 |
+
{
|
| 128 |
+
optiling::InterleaveRopeCompileInfo compileInfo = {};
|
| 129 |
+
gert::TilingContextPara tilingContextPara("InterleaveRope",
|
| 130 |
+
{
|
| 131 |
+
{{{32, 32, 1}, {32, 32, 1}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 132 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 133 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 134 |
+
},
|
| 135 |
+
{
|
| 136 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 137 |
+
},
|
| 138 |
+
&compileInfo);
|
| 139 |
+
uint64_t expectTilingKey = 0;
|
| 140 |
+
string expectTilingData = "";
|
| 141 |
+
std::vector<size_t> expectWorkspaces = {};
|
| 142 |
+
ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED, expectTilingKey, expectTilingData, expectWorkspaces);
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
TEST_F(InterleaveRopeTiling, interleave_rope_tiling_sin_not_eq_cos)
|
| 146 |
+
{
|
| 147 |
+
optiling::InterleaveRopeCompileInfo compileInfo = {};
|
| 148 |
+
gert::TilingContextPara tilingContextPara("InterleaveRope",
|
| 149 |
+
{
|
| 150 |
+
{{{32, 32, 1, 63}, {32, 32, 1, 63}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 151 |
+
{{{32, 1, 1, 64}, {32, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 152 |
+
{{{33, 1, 1, 64}, {33, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 156 |
+
},
|
| 157 |
+
&compileInfo);
|
| 158 |
+
uint64_t expectTilingKey = 0;
|
| 159 |
+
string expectTilingData = "";
|
| 160 |
+
std::vector<size_t> expectWorkspaces = {};
|
| 161 |
+
ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED, expectTilingKey, expectTilingData, expectWorkspaces);
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
TEST_F(InterleaveRopeTiling, interleave_rope_tiling_cosB_not_eq_batch_size)
|
| 165 |
+
{
|
| 166 |
+
optiling::InterleaveRopeCompileInfo compileInfo = {};
|
| 167 |
+
gert::TilingContextPara tilingContextPara("InterleaveRope",
|
| 168 |
+
{
|
| 169 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 170 |
+
{{{3, 1, 1, 64}, {3, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 171 |
+
{{{3, 1, 1, 64}, {3, 1, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 172 |
+
},
|
| 173 |
+
{
|
| 174 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 175 |
+
},
|
| 176 |
+
&compileInfo);
|
| 177 |
+
uint64_t expectTilingKey = 0;
|
| 178 |
+
string expectTilingData = "";
|
| 179 |
+
std::vector<size_t> expectWorkspaces = {};
|
| 180 |
+
ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED, expectTilingKey, expectTilingData, expectWorkspaces);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
TEST_F(InterleaveRopeTiling, interleave_rope_tiling_cosN_not_eq_1)
|
| 184 |
+
{
|
| 185 |
+
optiling::InterleaveRopeCompileInfo compileInfo = {};
|
| 186 |
+
gert::TilingContextPara tilingContextPara("InterleaveRope",
|
| 187 |
+
{
|
| 188 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 189 |
+
{{{32, 3, 1, 64}, {32, 3, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 190 |
+
{{{33, 3, 1, 64}, {33, 3, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 191 |
+
},
|
| 192 |
+
{
|
| 193 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 194 |
+
},
|
| 195 |
+
&compileInfo);
|
| 196 |
+
uint64_t expectTilingKey = 0;
|
| 197 |
+
string expectTilingData = "";
|
| 198 |
+
std::vector<size_t> expectWorkspaces = {};
|
| 199 |
+
ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED, expectTilingKey, expectTilingData, expectWorkspaces);
|
| 200 |
+
}
|
| 201 |
+
|
| 202 |
+
TEST_F(InterleaveRopeTiling, interleave_rope_tiling_cosD_not_eq_HiddenDim)
|
| 203 |
+
{
|
| 204 |
+
optiling::InterleaveRopeCompileInfo compileInfo = {};
|
| 205 |
+
gert::TilingContextPara tilingContextPara("InterleaveRope",
|
| 206 |
+
{
|
| 207 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 208 |
+
{{{32, 1, 1, 62}, {32, 1, 1, 62}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 209 |
+
{{{33, 1, 1, 62}, {33, 1, 1, 62}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 210 |
+
},
|
| 211 |
+
{
|
| 212 |
+
{{{32, 32, 1, 64}, {32, 32, 1, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND},
|
| 213 |
+
},
|
| 214 |
+
&compileInfo);
|
| 215 |
+
uint64_t expectTilingKey = 0;
|
| 216 |
+
string expectTilingData = "";
|
| 217 |
+
std::vector<size_t> expectWorkspaces = {};
|
| 218 |
+
ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED, expectTilingKey, expectTilingData, expectWorkspaces);
|
| 219 |
+
}
|
| 220 |
+
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_kernel/CMakeLists.txt
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 2 |
+
# Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
# CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
# -----------------------------------------------------------------------------------------------------------
|
| 10 |
+
|
| 11 |
+
file(GLOB CURRENT_SOURCE_DIRS LIST_DIRECTORIES true ${CMAKE_CURRENT_SOURCE_DIR}/*)
|
| 12 |
+
message(STATUS "=== Debug: CURRENT_SOURCE_DIRS =${CURRENT_SOURCE_DIRS} ")
|
| 13 |
+
foreach(SUB_DIR ${CURRENT_SOURCE_DIRS})
|
| 14 |
+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
|
| 15 |
+
add_subdirectory(${SUB_DIR})
|
| 16 |
+
endif()
|
| 17 |
+
endforeach()
|
| 18 |
+
|
| 19 |
+
if (UT_TEST_ALL OR OP_KERNEL_UT)
|
| 20 |
+
# 算子自己的tiling文件路径
|
| 21 |
+
set(interleave_rope_tiling_files
|
| 22 |
+
${CMAKE_CURRENT_SOURCE_DIR}/../../../op_host/interleave_rope_tiling.cpp
|
| 23 |
+
)
|
| 24 |
+
# 使用AddOpTestCase
|
| 25 |
+
# param1:算子名称,以kernel方式命名
|
| 26 |
+
# param2:soc版本,多个以分号分隔,例如:"Ascend950PR_9599;AscendB1"
|
| 27 |
+
# param3:自定义编译选项,一般填写测试的一种典型数据类型组合,不需要则传入空字符串,例如:"-DDTYPE_X=float",多个使用空格分隔,例如:"-DDTYPE_X=float -DDTYPE_Y=float"
|
| 28 |
+
# param4:该算子依赖的所有tiling源码文件
|
| 29 |
+
|
| 30 |
+
AddOpTestCase(interleave_rope "ascend910B1" "-DDTYPE_X=float" "${interleave_rope_tiling_files}")
|
| 31 |
+
endif()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_kernel/test_interleave_rope.cpp
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file test_interleave_rope.cpp
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#include <array>
|
| 17 |
+
#include <vector>
|
| 18 |
+
#include <iostream>
|
| 19 |
+
#include <string>
|
| 20 |
+
#include <cstdint>
|
| 21 |
+
#include "gtest/gtest.h"
|
| 22 |
+
#include "tikicpulib.h"
|
| 23 |
+
#include "test_interleave_rope.h"
|
| 24 |
+
#include "data_utils.h"
|
| 25 |
+
#include "tiling_case_executor.h"
|
| 26 |
+
|
| 27 |
+
using namespace std;
|
| 28 |
+
|
| 29 |
+
extern "C" __global__ __aicore__ void interleave_rope(
|
| 30 |
+
GM_ADDR x, GM_ADDR cos, GM_ADDR sin, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling);
|
| 31 |
+
|
| 32 |
+
class interleave_rope_test : public testing::Test
|
| 33 |
+
{
|
| 34 |
+
protected:
|
| 35 |
+
static void SetUpTestCase()
|
| 36 |
+
{
|
| 37 |
+
cout << "interleave_rope_test SetUp\n" << endl;
|
| 38 |
+
}
|
| 39 |
+
static void TearDownTestCase()
|
| 40 |
+
{
|
| 41 |
+
cout << "interleave_rope_test TearDown\n" << endl;
|
| 42 |
+
}
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
TEST_F(interleave_rope_test, test_case_0001)
|
| 46 |
+
{
|
| 47 |
+
size_t xSize = 32 * 32 * 64 * sizeof(half);
|
| 48 |
+
size_t ySize = 32 * 32 * 64 * sizeof(half);
|
| 49 |
+
size_t cosSize = 32 * 1 * 64 * sizeof(half);
|
| 50 |
+
size_t sinSize = 32 * 1 * 64 * sizeof(half);
|
| 51 |
+
size_t tiling_data_size = sizeof(InterleaveRopeTilingData);
|
| 52 |
+
uint32_t blockDim = 8;
|
| 53 |
+
|
| 54 |
+
uint8_t* x = (uint8_t*)AscendC::GmAlloc(xSize);
|
| 55 |
+
uint8_t* y = (uint8_t*)AscendC::GmAlloc(ySize);
|
| 56 |
+
uint8_t* cos = (uint8_t*)AscendC::GmAlloc(cosSize);
|
| 57 |
+
uint8_t* sin = (uint8_t*)AscendC::GmAlloc(sinSize);
|
| 58 |
+
uint8_t* workspace = (uint8_t*)AscendC::GmAlloc(16 * 2);
|
| 59 |
+
uint8_t* tiling = (uint8_t*)AscendC::GmAlloc(tiling_data_size);
|
| 60 |
+
|
| 61 |
+
char* path_ = get_current_dir_name();
|
| 62 |
+
string path(path_);
|
| 63 |
+
|
| 64 |
+
InterleaveRopeTilingData* tilingDatafromBin = reinterpret_cast<InterleaveRopeTilingData*>(tiling);
|
| 65 |
+
|
| 66 |
+
tilingDatafromBin->blockDim = 8;
|
| 67 |
+
|
| 68 |
+
ICPU_SET_TILING_KEY(1000);
|
| 69 |
+
// ICPU_RUN_KF(interleave_rope, blockDim, x, cos, sin, y, workspace, (uint8_t*)(tilingDatafromBin));
|
| 70 |
+
|
| 71 |
+
AscendC::GmFree(x);
|
| 72 |
+
AscendC::GmFree(y);
|
| 73 |
+
AscendC::GmFree(cos);
|
| 74 |
+
AscendC::GmFree(sin);
|
| 75 |
+
AscendC::GmFree(workspace);
|
| 76 |
+
AscendC::GmFree(tiling);
|
| 77 |
+
free(path_);
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
TEST_F(interleave_rope_test, test_case_0002)
|
| 81 |
+
{
|
| 82 |
+
size_t xSize = 32 * 32 * 64 * sizeof(half);
|
| 83 |
+
size_t ySize = 32 * 32 * 64 * sizeof(half);
|
| 84 |
+
size_t cosSize = 32 * 1 * 64 * sizeof(half);
|
| 85 |
+
size_t sinSize = 32 * 1 * 64 * sizeof(half);
|
| 86 |
+
size_t tiling_data_size = sizeof(InterleaveRopeTilingData);
|
| 87 |
+
uint32_t blockDim = 8;
|
| 88 |
+
|
| 89 |
+
uint8_t* x = (uint8_t*)AscendC::GmAlloc(xSize);
|
| 90 |
+
uint8_t* y = (uint8_t*)AscendC::GmAlloc(ySize);
|
| 91 |
+
uint8_t* cos = (uint8_t*)AscendC::GmAlloc(cosSize);
|
| 92 |
+
uint8_t* sin = (uint8_t*)AscendC::GmAlloc(sinSize);
|
| 93 |
+
uint8_t* workspace = (uint8_t*)AscendC::GmAlloc(16 * 2);
|
| 94 |
+
uint8_t* tiling = (uint8_t*)AscendC::GmAlloc(tiling_data_size);
|
| 95 |
+
|
| 96 |
+
char* path_ = get_current_dir_name();
|
| 97 |
+
string path(path_);
|
| 98 |
+
|
| 99 |
+
InterleaveRopeTilingData* tilingDatafromBin = reinterpret_cast<InterleaveRopeTilingData*>(tiling);
|
| 100 |
+
|
| 101 |
+
tilingDatafromBin->blockDim = 8;
|
| 102 |
+
|
| 103 |
+
ICPU_SET_TILING_KEY(2000);
|
| 104 |
+
// ICPU_RUN_KF(interleave_rope, blockDim, x, cos, sin, y, workspace, (uint8_t*)(tilingDatafromBin));
|
| 105 |
+
|
| 106 |
+
AscendC::GmFree(x);
|
| 107 |
+
AscendC::GmFree(y);
|
| 108 |
+
AscendC::GmFree(cos);
|
| 109 |
+
AscendC::GmFree(sin);
|
| 110 |
+
AscendC::GmFree(workspace);
|
| 111 |
+
AscendC::GmFree(tiling);
|
| 112 |
+
free(path_);
|
| 113 |
+
}
|
| 114 |
+
|
| 115 |
+
TEST_F(interleave_rope_test, test_case_0003)
|
| 116 |
+
{
|
| 117 |
+
size_t xSize = 32 * 32 * 64 * sizeof(half);
|
| 118 |
+
size_t ySize = 32 * 32 * 64 * sizeof(half);
|
| 119 |
+
size_t cosSize = 32 * 1 * 64 * sizeof(half);
|
| 120 |
+
size_t sinSize = 32 * 1 * 64 * sizeof(half);
|
| 121 |
+
size_t tiling_data_size = sizeof(InterleaveRopeTilingData);
|
| 122 |
+
uint32_t blockDim = 8;
|
| 123 |
+
|
| 124 |
+
uint8_t* x = (uint8_t*)AscendC::GmAlloc(xSize);
|
| 125 |
+
uint8_t* y = (uint8_t*)AscendC::GmAlloc(ySize);
|
| 126 |
+
uint8_t* cos = (uint8_t*)AscendC::GmAlloc(cosSize);
|
| 127 |
+
uint8_t* sin = (uint8_t*)AscendC::GmAlloc(sinSize);
|
| 128 |
+
uint8_t* workspace = (uint8_t*)AscendC::GmAlloc(16 * 2);
|
| 129 |
+
uint8_t* tiling = (uint8_t*)AscendC::GmAlloc(tiling_data_size);
|
| 130 |
+
|
| 131 |
+
char* path_ = get_current_dir_name();
|
| 132 |
+
string path(path_);
|
| 133 |
+
|
| 134 |
+
InterleaveRopeTilingData* tilingDatafromBin = reinterpret_cast<InterleaveRopeTilingData*>(tiling);
|
| 135 |
+
|
| 136 |
+
tilingDatafromBin->blockDim = 8;
|
| 137 |
+
|
| 138 |
+
ICPU_SET_TILING_KEY(3000);
|
| 139 |
+
// ICPU_RUN_KF(interleave_rope, blockDim, x, cos, sin, y, workspace, (uint8_t*)(tilingDatafromBin));
|
| 140 |
+
|
| 141 |
+
AscendC::GmFree(x);
|
| 142 |
+
AscendC::GmFree(y);
|
| 143 |
+
AscendC::GmFree(cos);
|
| 144 |
+
AscendC::GmFree(sin);
|
| 145 |
+
AscendC::GmFree(workspace);
|
| 146 |
+
AscendC::GmFree(tiling);
|
| 147 |
+
free(path_);
|
| 148 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/interleave_rope/tests/ut/op_kernel/test_interleave_rope.h
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2025 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file test_interleave_rope.h
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
|
| 16 |
+
#ifndef _INTERLEAVE_ROPE_TILING_H_
|
| 17 |
+
#define _INTERLEAVE_ROPE_TILING_H_
|
| 18 |
+
|
| 19 |
+
#include "kernel_tiling/kernel_tiling.h"
|
| 20 |
+
|
| 21 |
+
#define DT_BF16 bfloat16_t
|
| 22 |
+
#define ORIG_DTYPE_START DT_BF16
|
| 23 |
+
#define __CCE_UT_TEST__
|
| 24 |
+
|
| 25 |
+
#pragma pack(1)
|
| 26 |
+
|
| 27 |
+
#pragma pack()
|
| 28 |
+
|
| 29 |
+
#define CONVERT_TILING_DATA(tilingStruct, tilingDataPointer, tilingPointer) \
|
| 30 |
+
__ubuf__ tilingStruct* tilingDataPointer = \
|
| 31 |
+
reinterpret_cast<__ubuf__ tilingStruct*>((__ubuf__ uint8_t*)(tilingPointer));
|
| 32 |
+
|
| 33 |
+
#define INIT_TILING_DATA(tilingStruct, tilingDataPointer, tilingPointer) \
|
| 34 |
+
CONVERT_TILING_DATA(tilingStruct, tilingDataPointer, tilingPointer);
|
| 35 |
+
|
| 36 |
+
#define GET_TILING_DATA(tilingData, tilingPointer) \
|
| 37 |
+
InterleaveRopeTilingData tilingData; \
|
| 38 |
+
INIT_TILING_DATA(InterleaveRopeTilingData, tilingDataPointer, tilingPointer); \
|
| 39 |
+
(tilingData).blockDim = tilingDataPointer->blockDim; \
|
| 40 |
+
(tilingData).splitAxis = tilingDataPointer->splitAxis; \
|
| 41 |
+
(tilingData).batchSize = tilingDataPointer->batchSize; \
|
| 42 |
+
(tilingData).numHead = tilingDataPointer->numHead; \
|
| 43 |
+
(tilingData).seqLength = tilingDataPointer->seqLength; \
|
| 44 |
+
(tilingData).hiddenDim = tilingDataPointer->hiddenDim; \
|
| 45 |
+
(tilingData).batchsPerBlock = tilingDataPointer->batchsPerBlock; \
|
| 46 |
+
(tilingData).batchsLastBlock = tilingDataPointer->batchsLastBlock; \
|
| 47 |
+
(tilingData).batchLoops = tilingDataPointer->batchLoops; \
|
| 48 |
+
(tilingData).batchPerLoop = tilingDataPointer->batchPerLoop; \
|
| 49 |
+
(tilingData).batchLastLoop = tilingDataPointer->batchLastLoop; \
|
| 50 |
+
(tilingData).hiddenDimCountPerBlock = tilingDataPointer->hiddenDimCountPerBlock; \
|
| 51 |
+
(tilingData).hiddenDimCountLastBlock = tilingDataPointer->hiddenDimCountLastBlock; \
|
| 52 |
+
(tilingData).hiddenDimLoopsPerBlock = tilingDataPointer->hiddenDimLoopsPerBlock; \
|
| 53 |
+
(tilingData).hiddenDimCountPerLoopPerBlock = tilingDataPointer->hiddenDimCountPerLoopPerBlock; \
|
| 54 |
+
(tilingData).hiddenDimCountLastLoopPerBlock = tilingDataPointer->hiddenDimCountLastLoopPerBlock; \
|
| 55 |
+
(tilingData).hiddenDimLoopsLastBlock = tilingDataPointer->hiddenDimLoopsLastBlock; \
|
| 56 |
+
(tilingData).hiddenDimCountPerLoopLastBlock = tilingDataPointer->hiddenDimCountPerLoopLastBlock; \
|
| 57 |
+
(tilingData).hiddenDimCountLastLoopLastBlock = tilingDataPointer->hiddenDimCountLastLoopLastBlock;
|
| 58 |
+
|
| 59 |
+
#define DTYPE_X half
|
| 60 |
+
|
| 61 |
+
#endif
|
datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/CMakeLists.txt
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This program is free software, you can redistribute it and/or modify.
|
| 2 |
+
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This file is a part of the CANN Open Software.
|
| 4 |
+
# Licensed under CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# 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.
|
| 7 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 8 |
+
# ============================================================================
|
| 9 |
+
|
| 10 |
+
message(STATUS "=== Debug: start ops.posembedding.qkv_rms_norm_rope_cache.CMakeLists.txt ")
|
| 11 |
+
file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
|
| 12 |
+
if(NOT ENABLE_TEST AND NOT BENCHMARK)
|
| 13 |
+
list(REMOVE_ITEM CURRENT_DIRS tests)
|
| 14 |
+
endif()
|
| 15 |
+
foreach(SUB_DIR ${CURRENT_DIRS})
|
| 16 |
+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt")
|
| 17 |
+
add_subdirectory(${SUB_DIR})
|
| 18 |
+
endif()
|
| 19 |
+
endforeach()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/README.md
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# QkvRmsNormRopeCache
|
| 2 |
+
|
| 3 |
+
## 产品支持情况
|
| 4 |
+
|
| 5 |
+
|产品 | 是否支持 |
|
| 6 |
+
|:-------------------------|:----------:|
|
| 7 |
+
| <term>Ascend 950PR/Ascend 950DT</term> | × |
|
| 8 |
+
| <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ |
|
| 9 |
+
| <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | √ |
|
| 10 |
+
| <term>Atlas 200I/500 A2 推理产品</term> | × |
|
| 11 |
+
| <term>Atlas 推理系列产品</term> | × |
|
| 12 |
+
| <term>Atlas 训练系列产品</term> | × |
|
| 13 |
+
|
| 14 |
+
## 功能说明
|
| 15 |
+
|
| 16 |
+
- 算子功能:输入qkv融合张量,通过SplitVD拆分q、k、v张量,执行RmsNorm、ApplyRotaryPosEmb、Quant、Scatter融合操作,输出q_out、k_cache、v_cache、q_out_before_quant(可选)、k_out_before_quant(可选)、v_out_before_quant(可选)。
|
| 17 |
+
- 本算子目前支持的场景如下表:
|
| 18 |
+
|
| 19 |
+
| 场景类型 | 情况概要 |
|
| 20 |
+
|:----------------------|:-----------------------------|
|
| 21 |
+
|<ul><li>cache_mode为PA_NZ</li><li>q无量化</li><li>k和v支持无量化、对称量化和非对称量化</li><li>q_out_before_quant/k_out_before_quant/v_out_before_quant不输出</li></ul>|qkv Shape为[$B_{qkv}$ * $S_{qkv}$, $N_{qkv}$ * $D_{qkv}$],q、k、v具有完全相同的D维度。主要计算过程与输出对应关系:<br><ul><li>qkv经过SplitVD->q、k、v</li><li>q经过RmsNorm、RoPE->q_out</li><li>k经过RmsNorm、RoPE、Quant(可选)、Scatter->k_cache</li><li>v经过Quant(可选)、Scatter->v_cache</li></ul>|
|
| 22 |
+
|
| 23 |
+
- 计算公式:
|
| 24 |
+
|
| 25 |
+
(1) SplitVD:
|
| 26 |
+
|
| 27 |
+
下式中,$N_q$、$N_k$、$N_v$分别表示q、k、v分量的注意力头数量,必须满足:
|
| 28 |
+
|
| 29 |
+
$$
|
| 30 |
+
\begin{cases}
|
| 31 |
+
N_k = N_v \\
|
| 32 |
+
N_{qkv} = N_k + N_v + N_q \\
|
| 33 |
+
D_{qkv} = D_q = D_k = D_v
|
| 34 |
+
\end{cases}
|
| 35 |
+
$$
|
| 36 |
+
|
| 37 |
+
$$
|
| 38 |
+
\begin{aligned}
|
| 39 |
+
q &= qkv[..., [:N_q] * D_{qkv}] \\
|
| 40 |
+
k &= qkv[..., [N_q:-N_v] * D_{qkv}] \\
|
| 41 |
+
v &= qkv[..., [-N_v:] * D_{qkv}]
|
| 42 |
+
\end{aligned}
|
| 43 |
+
$$
|
| 44 |
+
|
| 45 |
+
(2) RmsNorm:
|
| 46 |
+
|
| 47 |
+
此处x和y分别表示RmsNorm的输入张量和输出张量,归一化沿最后一维(feature dimension)进行,该计算规则通用于q、k分量。
|
| 48 |
+
|
| 49 |
+
$$
|
| 50 |
+
squareX = x * x
|
| 51 |
+
$$
|
| 52 |
+
|
| 53 |
+
$$
|
| 54 |
+
meanSquareX = squareX.mean(dim = -1, keepdim = True)
|
| 55 |
+
$$
|
| 56 |
+
|
| 57 |
+
$$
|
| 58 |
+
rms = \sqrt{meanSquareX + epsilon}
|
| 59 |
+
$$
|
| 60 |
+
|
| 61 |
+
$$
|
| 62 |
+
y = (x / rms) * gamma
|
| 63 |
+
$$
|
| 64 |
+
|
| 65 |
+
(3) RoPE (Half-and-Half):
|
| 66 |
+
|
| 67 |
+
此处的y指代完成RmsNorm计算的输出结果。
|
| 68 |
+
|
| 69 |
+
$$
|
| 70 |
+
y1 = y[\ldots, :d/2]
|
| 71 |
+
$$
|
| 72 |
+
|
| 73 |
+
$$
|
| 74 |
+
y2 = y[\ldots, d/2:]
|
| 75 |
+
$$
|
| 76 |
+
|
| 77 |
+
$$
|
| 78 |
+
y\_RoPE = torch.cat((-y2, y1), dim = -1)
|
| 79 |
+
$$
|
| 80 |
+
|
| 81 |
+
$$
|
| 82 |
+
y\_embed = (y * cos) + y\_RoPE * sin
|
| 83 |
+
$$
|
| 84 |
+
|
| 85 |
+
(4) Quant:
|
| 86 |
+
|
| 87 |
+
无量化:
|
| 88 |
+
|
| 89 |
+
$$
|
| 90 |
+
kQuant = kRoPE \\
|
| 91 |
+
vQuant = v
|
| 92 |
+
$$
|
| 93 |
+
|
| 94 |
+
对称量化部分:
|
| 95 |
+
|
| 96 |
+
$$
|
| 97 |
+
kQuant = kRoPE / kScale \\
|
| 98 |
+
vQuant = v / vScale
|
| 99 |
+
$$
|
| 100 |
+
|
| 101 |
+
非对称量化部分:
|
| 102 |
+
|
| 103 |
+
$$
|
| 104 |
+
kQuant = kRoPE / kScale + kOffset \\
|
| 105 |
+
vQuant = v / vScale + vOffset
|
| 106 |
+
$$
|
| 107 |
+
|
| 108 |
+
## 参数说明
|
| 109 |
+
|
| 110 |
+
<table style="undefined;table-layout: fixed; width: 1576px"><colgroup>
|
| 111 |
+
<col style="width: 170px">
|
| 112 |
+
<col style="width: 170px">
|
| 113 |
+
<col style="width: 312px">
|
| 114 |
+
<col style="width: 213px">
|
| 115 |
+
<col style="width: 100px">
|
| 116 |
+
</colgroup>
|
| 117 |
+
<thead>
|
| 118 |
+
<tr>
|
| 119 |
+
<th>参数名</th>
|
| 120 |
+
<th>输入/输出/属性</th>
|
| 121 |
+
<th>描述</th>
|
| 122 |
+
<th>数据类型</th>
|
| 123 |
+
<th>数据格式</th>
|
| 124 |
+
</tr></thead>
|
| 125 |
+
<tbody>
|
| 126 |
+
<tr>
|
| 127 |
+
<td>qkv</td>
|
| 128 |
+
<td>输入</td>
|
| 129 |
+
<td>用于切分出q、k、v的输入数据,对应公式中的qkv。shape为[B<sub>qkv</sub> * S<sub>qkv</sub>, N<sub>qkv</sub> * D<sub>qkv</sub>]。</td>
|
| 130 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 131 |
+
<td>ND</td>
|
| 132 |
+
</tr>
|
| 133 |
+
<tr>
|
| 134 |
+
<td>q_gamma</td>
|
| 135 |
+
<td>输入</td>
|
| 136 |
+
<td>用于q的rms_norm计算的输入数据,对应公式中的gamma。与输入qkv的数据类型相同,shape为[D<sub>qkv</sub>]。</td>
|
| 137 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 138 |
+
<td>ND</td>
|
| 139 |
+
</tr>
|
| 140 |
+
<tr>
|
| 141 |
+
<td>k_gamma</td>
|
| 142 |
+
<td>输入</td>
|
| 143 |
+
<td>用于k的rms_norm计算的输入数据,对应公式中的gamma。与输入qkv的数据类型相同,shape为[D<sub>qkv</sub>]。</td>
|
| 144 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 145 |
+
<td>ND</td>
|
| 146 |
+
</tr>
|
| 147 |
+
<tr>
|
| 148 |
+
<td>cos</td>
|
| 149 |
+
<td>输入</td>
|
| 150 |
+
<td>用于rope计算的输入数据,对输入张量进行余弦变换,对应公式中的cos。与输入qkv的数据类型相同,shape为[B<sub>qkv</sub> * S<sub>qkv</sub>, 1 * D_rope],D_rope = D<sub>qkv</sub>且要求(D<sub>qkv</sub> * qkv数据类型所占字节数)可以被32整除。</td>
|
| 151 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 152 |
+
<td>ND</td>
|
| 153 |
+
</tr>
|
| 154 |
+
<tr>
|
| 155 |
+
<td>sin</td>
|
| 156 |
+
<td>输入</td>
|
| 157 |
+
<td>用于rope计算的输入数据,对输入张量进行正弦变换,对应公式中的sin。与输入cos的数据类型、格式保持一致。</td>
|
| 158 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 159 |
+
<td>ND</td>
|
| 160 |
+
</tr>
|
| 161 |
+
<tr>
|
| 162 |
+
<td>index</td>
|
| 163 |
+
<td>输入</td>
|
| 164 |
+
<td>用于指定写入cache的具体索引位置。shape为[B<sub>qkv</sub> * S<sub>qkv</sub>]。</td>
|
| 165 |
+
<td>INT64</td>
|
| 166 |
+
<td>ND</td>
|
| 167 |
+
</tr>
|
| 168 |
+
<tr>
|
| 169 |
+
<td>q_out</td>
|
| 170 |
+
<td>输入/输出</td>
|
| 171 |
+
<td>提前申请的cache,输入输出同地址复用。与输入qkv的数据类型相同,shape为[B<sub>qkv</sub> * S<sub>qkv</sub>, N<sub>q</sub> * D<sub>qkv</sub>]。</td>
|
| 172 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 173 |
+
<td>ND</td>
|
| 174 |
+
</tr>
|
| 175 |
+
<tr>
|
| 176 |
+
<td>k_cache</td>
|
| 177 |
+
<td>输入/输出</td>
|
| 178 |
+
<td>提前申请的cache,输入输出同地址复用。与输入qkv的数据类型相同(k不量化),或者INT8(k量化)。shape为[BlockNum, N<sub>k</sub> * D<sub>qkv</sub> // 16, BlockSize, 16](k不量化),或者[BlockNum, N<sub>k</sub> * D<sub>qkv</sub> // 32, BlockSize, 32](k量化)。</td>
|
| 179 |
+
<td>FLOAT16、BFLOAT16、INT8</td>
|
| 180 |
+
<td>ND</td>
|
| 181 |
+
</tr>
|
| 182 |
+
<tr>
|
| 183 |
+
<td>v_cache</td>
|
| 184 |
+
<td>输入/输出</td>
|
| 185 |
+
<td>提前申请的cache,输入输出同地址复用。与输入qkv的数据类型相同(v不量化),或者INT8(v量化)。shape为[BlockNum, N<sub>k</sub> * D<sub>qkv</sub> // 16, BlockSize, 16](v不量化),或者[BlockNum, N<sub>k</sub> * D<sub>qkv</sub> // 32, BlockSize, 32](v量化)。</td>
|
| 186 |
+
<td>FLOAT16、BFLOAT16、INT8</td>
|
| 187 |
+
<td>ND</td>
|
| 188 |
+
</tr>
|
| 189 |
+
<tr>
|
| 190 |
+
<td>k_scale</td>
|
| 191 |
+
<td>可选输入</td>
|
| 192 |
+
<td>当k_cache数据类型为INT8时需要此输入参数,对应公式中的kScale。shape为[N<sub>k</sub>, D<sub>qkv</sub>]。</td>
|
| 193 |
+
<td>FLOAT32</td>
|
| 194 |
+
<td>ND</td>
|
| 195 |
+
</tr>
|
| 196 |
+
<tr>
|
| 197 |
+
<td>v_scale</td>
|
| 198 |
+
<td>可选输入</td>
|
| 199 |
+
<td>当v_cache数据类型为INT8时需要此输入参数,对应公式中的vScale。shape为[N<sub>v</sub>, D<sub>qkv</sub>]。</td>
|
| 200 |
+
<td>FLOAT32</td>
|
| 201 |
+
<td>ND</td>
|
| 202 |
+
</tr>
|
| 203 |
+
<tr>
|
| 204 |
+
<td>k_offset</td>
|
| 205 |
+
<td>可选输入</td>
|
| 206 |
+
<td>当k_cache数据类型为INT8且对应的k_scale输入存在并量化场景为非对称量化时,需要此参数输入,对应公式中的kOffset。shape为[N<sub>k</sub>, D<sub>qkv</sub>]。</td>
|
| 207 |
+
<td>FLOAT32</td>
|
| 208 |
+
<td>ND</td>
|
| 209 |
+
</tr>
|
| 210 |
+
<tr>
|
| 211 |
+
<td>v_offset</td>
|
| 212 |
+
<td>可选输入</td>
|
| 213 |
+
<td>当v_cache数据类型为INT8且对应的v_scale输入存在并量化场景为非对称量化时,需要此参数输入,对应公式中的vOffset。shape为[N<sub>v</sub>, D<sub>qkv</sub>]。</td>
|
| 214 |
+
<td>FLOAT32</td>
|
| 215 |
+
<td>ND</td>
|
| 216 |
+
</tr>
|
| 217 |
+
<tr>
|
| 218 |
+
<td>q_out_before_quant</td>
|
| 219 |
+
<td>可选输出</td>
|
| 220 |
+
<td>即将写入到q_out中的数据。</td>
|
| 221 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 222 |
+
<td>ND</td>
|
| 223 |
+
</tr>
|
| 224 |
+
<tr>
|
| 225 |
+
<td>k_out_before_quant</td>
|
| 226 |
+
<td>可选输出</td>
|
| 227 |
+
<td>即将写入到k_cache中的数据,在未经量化和Scatter前的中间计算结果。</td>
|
| 228 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 229 |
+
<td>ND</td>
|
| 230 |
+
</tr>
|
| 231 |
+
<tr>
|
| 232 |
+
<td>v_out_before_quant</td>
|
| 233 |
+
<td>可选输出</td>
|
| 234 |
+
<td>即将写入到v_cache中的数据,在未经量化和Scatter前的中间计算结果。</td>
|
| 235 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 236 |
+
<td>ND</td>
|
| 237 |
+
</tr>
|
| 238 |
+
<tr>
|
| 239 |
+
<td>qkv_size</td>
|
| 240 |
+
<td>属性</td>
|
| 241 |
+
<td>按[B<sub>qkv</sub>, S<sub>qkv</sub>, N<sub>qkv</sub>, D<sub>qkv</sub>]顺序传入,提供输入参数qkv矩阵的B,S,N,D维度具体尺寸。</td>
|
| 242 |
+
<td>INT64</td>
|
| 243 |
+
<td>-</td>
|
| 244 |
+
</tr>
|
| 245 |
+
<tr>
|
| 246 |
+
<td>head_nums</td>
|
| 247 |
+
<td>属性</td>
|
| 248 |
+
<td>按[N<sub>q</sub>, N<sub>k</sub>, N<sub>v</sub>]顺序传入,提供输入参数qkv矩阵中,qkv分量单元中分的N维度具体尺寸。</td>
|
| 249 |
+
<td>INT64</td>
|
| 250 |
+
<td>-</td>
|
| 251 |
+
</tr>
|
| 252 |
+
<tr>
|
| 253 |
+
<td>epsilon</td>
|
| 254 |
+
<td>可选属性</td>
|
| 255 |
+
<td><ul>
|
| 256 |
+
<li>用于防止RmsNorm计算除0错误,对应公式中的epsilon。</li>
|
| 257 |
+
<li>默认值为1e-6。</li>
|
| 258 |
+
</ul></td>
|
| 259 |
+
<td>FLOAT32</td>
|
| 260 |
+
<td>-</td>
|
| 261 |
+
</tr>
|
| 262 |
+
<tr>
|
| 263 |
+
<td>cache_mode</td>
|
| 264 |
+
<td>可选属性</td>
|
| 265 |
+
<td><ul>
|
| 266 |
+
<li>cache格式的选择标记,目前只支持PA_NZ。</li>
|
| 267 |
+
<li>默认值为PA_NZ。</li>
|
| 268 |
+
</ul></td>
|
| 269 |
+
<td>CHAR*</td>
|
| 270 |
+
<td>-</td>
|
| 271 |
+
</tr>
|
| 272 |
+
<tr>
|
| 273 |
+
<td>is_output_qkv</td>
|
| 274 |
+
<td>可选属性</td>
|
| 275 |
+
<td><ul>
|
| 276 |
+
<li>表示是否需要输出各cache输出中对应内容在未经量化和Scatter前的原始值。</li>
|
| 277 |
+
<li>默认值为false。</li>
|
| 278 |
+
</ul></td>
|
| 279 |
+
<td>BOOL</td>
|
| 280 |
+
<td>-</td>
|
| 281 |
+
</tr>
|
| 282 |
+
|
| 283 |
+
</tbody></table>
|
| 284 |
+
|
| 285 |
+
## 约束说明
|
| 286 |
+
|
| 287 |
+
* 输入shape限制:
|
| 288 |
+
* B<sub>qkv</sub>为输入qkv的batch_size,S<sub>qkv</sub>为输入qkv的sequence length,大小由qkvSize决定。
|
| 289 |
+
* N<sub>qkv</sub>为输入qkv的head number。D<sub>qkv</sub>为输入qkv的head dim,目前仅支持128。D<sub>q</sub>、D<sub>k</sub>和D<sub>k</sub>分别为q、k、v的head dim,要求D<sub>qkv</sub> = D<sub>q</sub> = D<sub>k</sub> = D<sub>v</sub>,D<sub>qkv</sub>需要满足(D<sub>qkv</sub>*qkv数据类型占字节数)可以被32整除。
|
| 290 |
+
* 根据rope规则,D<sub>k</sub>和D<sub>q</sub>为偶数。若cache_mode为PA_NZ场景下,D<sub>k</sub>、D<sub>q</sub>需32B对齐;BlockSize需32B对齐。
|
| 291 |
+
* 关于上述32B对齐的情形,对齐值由cache的数据类型决定。以BlockSize为例,若cache的数据类型为int8,则需要满足BlockSize % 32 = 0;若cache的数据类型为float16,则需要满足BlockSize % 16 = 0;若k_cache与v_cache参数的dtype不一致,BlockSize需同时满足BlockSize % 32 = 0和BlockSize % 16 = 0。
|
| 292 |
+
* BlockNum为写入cache的内存块数,大小由用户输入场景决定,要求BlockNum >= Ceil(S<sub>qkv</sub> / BlockSize) * B<sub>qkv</sub>。
|
| 293 |
+
* 使用requireMemory表示存放数据所需的空间大小,需满足:requireMemory >= (B<sub>qkv</sub> * S<sub>qkv</sub> * N<sub>qkv</sub> * D<sub>qkv</sub> + 2 * D<sub>qkv</sub> + 2 * B<sub>qkv</sub> * S<sub>qkv</sub> * D<sub>qkv</sub> + B<sub>qkv</sub> * S<sub>qkv</sub> * N<sub>q</sub> * D<sub>qkv</sub> + BlockNum * BlockSize * N<sub>v</sub> * D<sub>qkv</sub> + BlockNum * BlockSize * N<sub>k</sub> * D<sub>qkv</sub>) * sizeof(FLOAT16) + B<sub>qkv</sub> * S<sub>qkv</sub> * sizeof(INT64) + (2 * N<sub>k</sub> * D<sub>qkv</sub> + 2 * N<sub>v</sub>) * sizeof(FLOAT),当计算出requireMemory的大小超过当前AI处理器的GM空间总大小,不支持使用该算子。
|
| 294 |
+
* 其他限制:
|
| 295 |
+
* 对于index,要求index的value值范围为[-1, BlockNum * BlockSize)。value数值不可以重复,index为-1时,代表跳过更新。
|
| 296 |
+
* k_scale, v_scale表示对称量化的缩放因子,因此若传参,则值不能为0。
|
| 297 |
+
|
| 298 |
+
## 调用说明
|
| 299 |
+
|
| 300 |
+
| 调用方式 | 样例代码 | 说明 |
|
| 301 |
+
| ---------------- | --------------------------- | --------------------------------------------------- |
|
| 302 |
+
| aclnn接口 | [test_aclnn_qkv_rms_norm_rope_cache](examples/test_aclnn_qkv_rms_norm_rope_cache.cpp) | 通过[aclnnQkvRmsNormRopeCache](docs/aclnnQkvRmsNormR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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# aclnnQkvRmsNormRopeCache
|
| 2 |
+
|
| 3 |
+
## 产品支持情况
|
| 4 |
+
|
| 5 |
+
| 产品 | 是否支持 |
|
| 6 |
+
| :----------------------------------------------------------- | :------: |
|
| 7 |
+
| <term>Ascend 950PR/Ascend 950DT</term> | × |
|
| 8 |
+
| <term>Atlas A3 训练系列产品/Atlas A3 推理系列产品</term> | √ |
|
| 9 |
+
| <term>Atlas A2 训练系列产品/Atlas A2 推理系列产品</term> | √ |
|
| 10 |
+
| <term>Atlas 200I/500 A2 推理产品</term> | × |
|
| 11 |
+
| <term>Atlas 推理系列产品</term> | × |
|
| 12 |
+
| <term>Atlas 训练系列产品</term> | × |
|
| 13 |
+
|
| 14 |
+
## 功能说明
|
| 15 |
+
|
| 16 |
+
- 接口功能:输入qkv融合张量,通过SplitVD拆分q、k、v张量,执行RmsNorm、ApplyRotaryPosEmb、Quant、Scatter融合操作,输出qOut、kCache、vCache、qBeforeQuant(可选)、kBeforeQuant(可选)、vBeforeQuant(可选)。
|
| 17 |
+
- 本接口目前支持的场景如下表:
|
| 18 |
+
|
| 19 |
+
|场景类型|情况概要|
|
| 20 |
+
|:---|:---|
|
| 21 |
+
|<ul><li>cacheMode为PA_NZ</li><li>q无量化</li><li>k和v支持无量化、对称量化和非对称量化</li><li>qBeforeQuant/kBeforeQuant/vBeforeQuant不输出</li></ul>|qkv Shape为[$B_{qkv}$ * $S_{qkv}$, $N_{qkv}$ * $D_{qkv}$],q、k、v具有完全相同的D维度。主要计算过程与输出对应关系:<br><ul><li>qkv经过SplitVD->q、k、v</li><li>q经过RmsNorm、RoPE->qOut</li><li>k经过RmsNorm、RoPE、Quant(可选)、Scatter->kCache</li><li>v经过Quant(可选)、Scatter->vCache</li></ul>|
|
| 22 |
+
|
| 23 |
+
- 计算公式:
|
| 24 |
+
|
| 25 |
+
(1) SplitVD:
|
| 26 |
+
|
| 27 |
+
下式中,$N_q$、$N_k$、$N_v$分别表示q、k、v分量的注意力头数量,必须满足:
|
| 28 |
+
|
| 29 |
+
$$
|
| 30 |
+
\begin{cases}
|
| 31 |
+
N_k = N_v \\
|
| 32 |
+
N_{qkv} = N_k + N_v + N_q \\
|
| 33 |
+
D_{qkv} = D_q = D_k = D_v
|
| 34 |
+
\end{cases}
|
| 35 |
+
$$
|
| 36 |
+
|
| 37 |
+
$$
|
| 38 |
+
\begin{aligned}
|
| 39 |
+
q &= qkv[..., [:N_q] * D_{qkv}] \\
|
| 40 |
+
k &= qkv[..., [N_q:-N_v] * D_{qkv}] \\
|
| 41 |
+
v &= qkv[..., [-N_v:] * D_{qkv}]
|
| 42 |
+
\end{aligned}
|
| 43 |
+
$$
|
| 44 |
+
|
| 45 |
+
(2) RmsNorm:
|
| 46 |
+
|
| 47 |
+
此处x和y分别表示RmsNorm的输入张量和输出张量,归一化沿最后一维(feature dimension)进行,该计算规则通用于q、k分量。
|
| 48 |
+
|
| 49 |
+
$$
|
| 50 |
+
squareX = x * x
|
| 51 |
+
$$
|
| 52 |
+
|
| 53 |
+
$$
|
| 54 |
+
meanSquareX = squareX.mean(dim = -1, keepdim = True)
|
| 55 |
+
$$
|
| 56 |
+
|
| 57 |
+
$$
|
| 58 |
+
rms = \sqrt{meanSquareX + epsilon}
|
| 59 |
+
$$
|
| 60 |
+
|
| 61 |
+
$$
|
| 62 |
+
y = (x / rms) * gamma
|
| 63 |
+
$$
|
| 64 |
+
|
| 65 |
+
(3) RoPE (Half-and-Half):
|
| 66 |
+
|
| 67 |
+
此处的y指代完成RmsNorm计算的输出结果。
|
| 68 |
+
|
| 69 |
+
$$
|
| 70 |
+
y1 = y[\ldots, :d/2]
|
| 71 |
+
$$
|
| 72 |
+
|
| 73 |
+
$$
|
| 74 |
+
y2 = y[\ldots, d/2:]
|
| 75 |
+
$$
|
| 76 |
+
|
| 77 |
+
$$
|
| 78 |
+
y\_RoPE = torch.cat((-y2, y1), dim = -1)
|
| 79 |
+
$$
|
| 80 |
+
|
| 81 |
+
$$
|
| 82 |
+
y\_embed = (y * cos) + y\_RoPE * sin
|
| 83 |
+
$$
|
| 84 |
+
|
| 85 |
+
(4) Quant:
|
| 86 |
+
|
| 87 |
+
无量化:
|
| 88 |
+
|
| 89 |
+
$$
|
| 90 |
+
kQuant = kRoPE \\
|
| 91 |
+
vQuant = v
|
| 92 |
+
$$
|
| 93 |
+
|
| 94 |
+
对称量化部分:
|
| 95 |
+
|
| 96 |
+
$$
|
| 97 |
+
kQuant = kRoPE / kScale \\
|
| 98 |
+
vQuant = v / vScale
|
| 99 |
+
$$
|
| 100 |
+
|
| 101 |
+
非对称量化部分:
|
| 102 |
+
|
| 103 |
+
$$
|
| 104 |
+
kQuant = kRoPE / kScale + kOffset \\
|
| 105 |
+
vQuant = v / vScale + vOffset
|
| 106 |
+
$$
|
| 107 |
+
|
| 108 |
+
## 函数原型
|
| 109 |
+
|
| 110 |
+
该算子采用两段式接口,必须先调用“aclnnQkvRmsNormRopeCacheGetWorkspaceSize”接口获得入参并根据流程计算所需workspace大小,再调用“aclnnQkvRmsNormRopeCache”接口执行计算。
|
| 111 |
+
|
| 112 |
+
```Cpp
|
| 113 |
+
aclnnStatus aclnnQkvRmsNormRopeCacheGetWorkspaceSize(
|
| 114 |
+
const aclTensor *qkv,
|
| 115 |
+
const aclTensor *qGamma,
|
| 116 |
+
const aclTensor *kGamma,
|
| 117 |
+
const aclTensor *cos,
|
| 118 |
+
const aclTensor *sin,
|
| 119 |
+
const aclTensor *index,
|
| 120 |
+
aclTensor *qOut,
|
| 121 |
+
aclTensor *kCache,
|
| 122 |
+
aclTensor *vCache,
|
| 123 |
+
const aclTensor *kScaleOptional,
|
| 124 |
+
const aclTensor *vScaleOptional,
|
| 125 |
+
const aclTensor *kOffsetOptional,
|
| 126 |
+
const aclTensor *vOffsetOptional,
|
| 127 |
+
const aclIntArray *qkvSize,
|
| 128 |
+
const aclIntArray *headNums,
|
| 129 |
+
double epsilon,
|
| 130 |
+
char *cacheModeOptional,
|
| 131 |
+
const aclTensor *qOutBeforeQuant,
|
| 132 |
+
const aclTensor *kOutBeforeQuant,
|
| 133 |
+
const aclTensor *vOutBeforeQuant,
|
| 134 |
+
uint64_t *workspaceSize,
|
| 135 |
+
aclOpExecutor **executor)
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
```Cpp
|
| 139 |
+
aclnnStatus aclnnQkvRmsNormRopeCache(
|
| 140 |
+
void *workspace,
|
| 141 |
+
uint64_t workspaceSize,
|
| 142 |
+
aclOpExecutor *executor,
|
| 143 |
+
aclrtStream stream)
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
## aclnnQkvRmsNormRopeCacheGetWorkspaceSize
|
| 147 |
+
|
| 148 |
+
- **参数说明:**
|
| 149 |
+
|
| 150 |
+
<table style="undefined;table-layout: fixed; width: 1503px"><colgroup>
|
| 151 |
+
<col style="width: 146px">
|
| 152 |
+
<col style="width: 120px">
|
| 153 |
+
<col style="width: 271px">
|
| 154 |
+
<col style="width: 392px">
|
| 155 |
+
<col style="width: 228px">
|
| 156 |
+
<col style="width: 101px">
|
| 157 |
+
<col style="width: 100px">
|
| 158 |
+
<col style="width: 145px">
|
| 159 |
+
</colgroup>
|
| 160 |
+
<thead>
|
| 161 |
+
<tr>
|
| 162 |
+
<th>参数名</th>
|
| 163 |
+
<th>输入/输出</th>
|
| 164 |
+
<th>描述</th>
|
| 165 |
+
<th>使用说明</th>
|
| 166 |
+
<th>数据类型</th>
|
| 167 |
+
<th>数据格式</th>
|
| 168 |
+
<th>维度(shape)</th>
|
| 169 |
+
<th>非连续Tensor</th>
|
| 170 |
+
</tr></thead>
|
| 171 |
+
<tbody>
|
| 172 |
+
<tr>
|
| 173 |
+
<td>qkv</td>
|
| 174 |
+
<td>输入</td>
|
| 175 |
+
<td>用于切分出q、k、v的输入数据,对应计算公式中的qkv。</td>
|
| 176 |
+
<td><ul><li>不支持空Tensor。</li><li>shape为[B<sub>qkv</sub> * S<sub>qkv</sub>, N<sub>qkv</sub> * D<sub>qkv</sub>]。</li></ul></td>
|
| 177 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 178 |
+
<td>ND</td>
|
| 179 |
+
<td>2</td>
|
| 180 |
+
<td>√</td>
|
| 181 |
+
</tr>
|
| 182 |
+
<tr>
|
| 183 |
+
<td>qGamma</td>
|
| 184 |
+
<td>输入</td>
|
| 185 |
+
<td>用于q的rms_norm计算的输入数据,对应计算公式中的gamma。</td>
|
| 186 |
+
<td><ul><li>不支持空Tensor。</li><li>与输入qkv的数据类型相同。</li><li>shape为[D<sub>qkv</sub>]。</li></ul></td>
|
| 187 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 188 |
+
<td>ND</td>
|
| 189 |
+
<td>1</td>
|
| 190 |
+
<td>√</td>
|
| 191 |
+
</tr>
|
| 192 |
+
<tr>
|
| 193 |
+
<td>kGamma</td>
|
| 194 |
+
<td>输入</td>
|
| 195 |
+
<td>用于k的rms_norm计算的输入数据,对应计算公式中的gamma。</td>
|
| 196 |
+
<td><ul><li>不支持空Tensor。</li><li>与输入qkv的数据类型相同。</li><li>shape为[D<sub>qkv</sub>]。</li></ul></td>
|
| 197 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 198 |
+
<td>ND</td>
|
| 199 |
+
<td>1</td>
|
| 200 |
+
<td>√</td>
|
| 201 |
+
</tr>
|
| 202 |
+
<tr>
|
| 203 |
+
<td>cos</td>
|
| 204 |
+
<td>输入</td>
|
| 205 |
+
<td>用于rope计算的输入数据,对输入张量进行余弦变换,对应计算公式中的cos。</td>
|
| 206 |
+
<td><ul><li>不支持空Tensor。</li><li>与输入qkv的数据类型相同。</li><li>shape为[B<sub>qkv</sub> * S<sub>qkv</sub>, 1 * D_rope],D_rope = D<sub>qkv</sub>且要求(D<sub>qkv</sub> * qkv数据类型所占字节数)可以被32整除。</li></ul></td>
|
| 207 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 208 |
+
<td>ND</td>
|
| 209 |
+
<td>2</td>
|
| 210 |
+
<td>√</td>
|
| 211 |
+
</tr>
|
| 212 |
+
<tr>
|
| 213 |
+
<td>sin</td>
|
| 214 |
+
<td>输入</td>
|
| 215 |
+
<td>用于rope计算的输入数据,对输入张量进行正弦变换,对应计算公式中的sin。</td>
|
| 216 |
+
<td><ul><li>不支持空Tensor。</li><li>与输入cos的数据类型、格式保持一致。</li></ul></td>
|
| 217 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 218 |
+
<td>ND</td>
|
| 219 |
+
<td>2</td>
|
| 220 |
+
<td>√</td>
|
| 221 |
+
</tr>
|
| 222 |
+
<tr>
|
| 223 |
+
<td>index</td>
|
| 224 |
+
<td>输入</td>
|
| 225 |
+
<td>用于指定写入cache的具体索引位置,对应计算公式中的index。</td>
|
| 226 |
+
<td><ul><li>不支持空Tensor。</li><li>与输入qkv的数据类型相同。</li><li>shape为[B<sub>qkv</sub> * S<sub>qkv</sub>],要求index的value不能重复,value的数值范围为[-1, BlockNum * BlockSize]。</li></ul></td>
|
| 227 |
+
<td>INT64</td>
|
| 228 |
+
<td>ND</td>
|
| 229 |
+
<td>1</td>
|
| 230 |
+
<td>√</td>
|
| 231 |
+
</tr>
|
| 232 |
+
<tr>
|
| 233 |
+
<td>qOut</td>
|
| 234 |
+
<td>输入\输出</td>
|
| 235 |
+
<td>提请申请的cache,输入输出同地址复用。</td>
|
| 236 |
+
<td><ul><li>不支持空Tensor。</li><li>与输入qkv的数据类型相同。</li><li>shape为[B<sub>qkv</sub> * S<sub>qkv</sub>, N<sub>q</sub> * D<sub>qkv</sub>]。</li></ul></td>
|
| 237 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 238 |
+
<td>ND</td>
|
| 239 |
+
<td>2</td>
|
| 240 |
+
<td>√</td>
|
| 241 |
+
</tr>
|
| 242 |
+
<tr>
|
| 243 |
+
<td>kCache</td>
|
| 244 |
+
<td>输入\输出</td>
|
| 245 |
+
<td>提请申请的cache,输入输出同地址复用。</td>
|
| 246 |
+
<td><ul><li>不支持空Tensor。</li><li>与输入qkv的数据类型相同(k不量化),或者INT8(k量化)。</li><li>shape为[BlockNum, N<sub>k</sub> * D<sub>qkv</sub> // 16, BlockSize, 16](k不量化),或者[BlockNum, N<sub>k</sub> * D<sub>qkv</sub> // 32, BlockSize, 32](k量化)。</li></ul></td>
|
| 247 |
+
<td>FLOAT16、BFLOAT16、INT8</td>
|
| 248 |
+
<td>ND</td>
|
| 249 |
+
<td>4</td>
|
| 250 |
+
<td>√</td>
|
| 251 |
+
</tr>
|
| 252 |
+
<tr>
|
| 253 |
+
<td>vCache</td>
|
| 254 |
+
<td>输入\输出</td>
|
| 255 |
+
<td>提请申请的cache,输入输出同地址复用。</td>
|
| 256 |
+
<td><ul><li>不支持空Tensor。</li><li>与输入qkv的数据类型相同(v不量化),或者INT8(v量化)。</li><li>shape为[BlockNum, N<sub>k</sub> * D<sub>qkv</sub> // 16, BlockSize, 16](v不量化),或者[BlockNum, N<sub>k</sub> * D<sub>qkv</sub> // 32, BlockSize, 32](v量化)。</li></ul></td>
|
| 257 |
+
<td>FLOAT16、BFLOAT16、INT8</td>
|
| 258 |
+
<td>ND</td>
|
| 259 |
+
<td>4</td>
|
| 260 |
+
<td>√</td>
|
| 261 |
+
</tr>
|
| 262 |
+
<tr>
|
| 263 |
+
<td>kScaleOptional</td>
|
| 264 |
+
<td>可选输入</td>
|
| 265 |
+
<td>当kCache为INT8数据类型时需要存在。对应计算公式中的kScale。</td>
|
| 266 |
+
<td>shape为[N<sub>k</sub>, D<sub>qkv</sub>]。</td>
|
| 267 |
+
<td>FLOAT32</td>
|
| 268 |
+
<td>ND</td>
|
| 269 |
+
<td>2</td>
|
| 270 |
+
<td>√</td>
|
| 271 |
+
</tr>
|
| 272 |
+
<tr>
|
| 273 |
+
<td>vScaleOptional</td>
|
| 274 |
+
<td>可选输入</td>
|
| 275 |
+
<td>当vCache为INT8数据类型时需要存在。对应计算公式中的vScale。</td>
|
| 276 |
+
<td>shape为[N<sub>v</sub>, D<sub>qkv</sub>]。</td>
|
| 277 |
+
<td>FLOAT32</td>
|
| 278 |
+
<td>ND</td>
|
| 279 |
+
<td>2</td>
|
| 280 |
+
<td>√</td>
|
| 281 |
+
</tr>
|
| 282 |
+
<tr>
|
| 283 |
+
<td>kOffsetOptional</td>
|
| 284 |
+
<td>可选输入</td>
|
| 285 |
+
<td>对应计算公式中的kOffset。</td>
|
| 286 |
+
<td><ul><li>当kCache数据类型为INT8且对应的kScaleOptional输入存在并量化场景为非对称量化时,需要此参数输入。</li><li>shape为[N<sub>k</sub>, D<sub>qkv</sub>]。</li></ul></td>
|
| 287 |
+
<td>FLOAT32</td>
|
| 288 |
+
<td>ND</td>
|
| 289 |
+
<td>2</td>
|
| 290 |
+
<td>√</td>
|
| 291 |
+
</tr>
|
| 292 |
+
<tr>
|
| 293 |
+
<td>vOffsetOptional</td>
|
| 294 |
+
<td>可选输入</td>
|
| 295 |
+
<td>对应计算公式中的vOffset。</td>
|
| 296 |
+
<td><ul><li>当vCache数据类型为INT8且对应的vScaleOptional输入存在并量化场景为非对称量化时,需要此参数输入。</li><li>shape为[N<sub>v</sub>, D<sub>qkv</sub>]。</li></ul></td>
|
| 297 |
+
<td>FLOAT32</td>
|
| 298 |
+
<td>ND</td>
|
| 299 |
+
<td>2</td>
|
| 300 |
+
<td>√</td>
|
| 301 |
+
</tr>
|
| 302 |
+
<tr>
|
| 303 |
+
<td>qkvSize</td>
|
| 304 |
+
<td>输入</td>
|
| 305 |
+
<td>按[B<sub>qkv</sub>, S<sub>qkv</sub>, N<sub>qkv</sub>, D<sub>qkv</sub>]顺序传入,提供输入参数qkv矩阵的B,S,N,D维度具体尺寸。</td>
|
| 306 |
+
<td><ul><li>要求N<sub>qkv</sub> = N<sub>q</sub> + N<sub>k</sub> + N<sub>v</sub>。</li><li>元素数量严格等于4,各元素必须为非零有效正整数。</li></ul></td>
|
| 307 |
+
<td>INT64</td>
|
| 308 |
+
<td>-</td>
|
| 309 |
+
<td>-</td>
|
| 310 |
+
<td>-</td>
|
| 311 |
+
</tr>
|
| 312 |
+
<tr>
|
| 313 |
+
<td>headNums</td>
|
| 314 |
+
<td>输入</td>
|
| 315 |
+
<td>按[N<sub>q</sub>, N<sub>k</sub>, N<sub>v</sub>]顺序传入,提供输入参数qkv矩阵中,qkv分量单元中分的N维度具体尺寸。</td>
|
| 316 |
+
<td>[N<sub>q</sub>, N<sub>k</sub>, N<sub>v</sub>]必须为实际原始值,不可进行约化。</td>
|
| 317 |
+
<td>INT64</td>
|
| 318 |
+
<td>-</td>
|
| 319 |
+
<td>-</td>
|
| 320 |
+
<td>-</td>
|
| 321 |
+
</tr>
|
| 322 |
+
<tr>
|
| 323 |
+
<td>epsilon</td>
|
| 324 |
+
<td>输入</td>
|
| 325 |
+
<td>RmsNorm计算中防止除0。对应计算公式中的epsilon。</td>
|
| 326 |
+
<td>建议值为1e-6</td>
|
| 327 |
+
<td>FLOAT32</td>
|
| 328 |
+
<td>-</td>
|
| 329 |
+
<td>-</td>
|
| 330 |
+
<td>-</td>
|
| 331 |
+
</tr>
|
| 332 |
+
<tr>
|
| 333 |
+
<td>cacheModeOptional</td>
|
| 334 |
+
<td>输入</td>
|
| 335 |
+
<td>表示cache的格式。</td>
|
| 336 |
+
<td>建议值为"PA_NZ"。</td>
|
| 337 |
+
<td>CHAR*</td>
|
| 338 |
+
<td>-</td>
|
| 339 |
+
<td>-</td>
|
| 340 |
+
<td>-</td>
|
| 341 |
+
</tr>
|
| 342 |
+
<tr>
|
| 343 |
+
<td>qOutBeforeQuant</td>
|
| 344 |
+
<td>输出</td>
|
| 345 |
+
<td>表示即将写入到qOut中的数据。</td>
|
| 346 |
+
<td><ul><li>分型、数据类型,需要与输入参数qkv保持一致。</li><li>shape为[B<sub>qkv</sub> * S<sub>qkv</sub>, N<sub>q</sub> * D<sub>qkv</sub>]。</li></ul></td>
|
| 347 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 348 |
+
<td>ND</td>
|
| 349 |
+
<td>2</td>
|
| 350 |
+
<td>√</td>
|
| 351 |
+
</tr>
|
| 352 |
+
<tr>
|
| 353 |
+
<td>kOutBeforeQuant</td>
|
| 354 |
+
<td>输出</td>
|
| 355 |
+
<td>表示即将写入到vCache中的数据,在未经量化和Scatter前的中间计算结果。</td>
|
| 356 |
+
<td><ul><li>分型、数据类型,需要与输入参数qkv保持一致。</li><li>shape为[B<sub>qkv</sub> * S<sub>qkv</sub>, N<sub>q</sub> * D<sub>qkv</sub>]。</li></ul></td>
|
| 357 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 358 |
+
<td>ND</td>
|
| 359 |
+
<td>2</td>
|
| 360 |
+
<td>√</td>
|
| 361 |
+
</tr>
|
| 362 |
+
<tr>
|
| 363 |
+
<td>vOutBeforeQuant</td>
|
| 364 |
+
<td>输出</td>
|
| 365 |
+
<td>表示即将写入到vCache中的数据,在未经量化和Scatter前的中间计算结果。</td>
|
| 366 |
+
<td><ul><li>分型、数据类型,需要与输入参数qkv保持一致。</li><li>shape为[B<sub>qkv</sub> * S<sub>qkv</sub>, N<sub>q</sub> * D<sub>qkv</sub>]。</li></ul></td>
|
| 367 |
+
<td>FLOAT16、BFLOAT16</td>
|
| 368 |
+
<td>ND</td>
|
| 369 |
+
<td>2</td>
|
| 370 |
+
<td>√</td>
|
| 371 |
+
</tr>
|
| 372 |
+
<tr>
|
| 373 |
+
<td>workspaceSize</td>
|
| 374 |
+
<td>输出</td>
|
| 375 |
+
<td>返回需要在Device侧申请的workspace大小。</td>
|
| 376 |
+
<td>-</td>
|
| 377 |
+
<td>-</td>
|
| 378 |
+
<td>-</td>
|
| 379 |
+
<td>-</td>
|
| 380 |
+
<td>-</td>
|
| 381 |
+
</tr>
|
| 382 |
+
<tr>
|
| 383 |
+
<td>executor</td>
|
| 384 |
+
<td>输出</td>
|
| 385 |
+
<td>返回op执行器,包含了算子计算流程。</td>
|
| 386 |
+
<td>-</td>
|
| 387 |
+
<td>-</td>
|
| 388 |
+
<td>-</td>
|
| 389 |
+
<td>-</td>
|
| 390 |
+
<td>-</td>
|
| 391 |
+
</tr>
|
| 392 |
+
</tbody>
|
| 393 |
+
</table>
|
| 394 |
+
|
| 395 |
+
- **返回值:**
|
| 396 |
+
|
| 397 |
+
aclnnStatus:返回算子的执行状态码。
|
| 398 |
+
|
| 399 |
+
第一段接口完成入参校验,出现以下场景时报错:
|
| 400 |
+
<table style="undefined;table-layout: fixed;width: 1155px"><colgroup>
|
| 401 |
+
<col style="width: 253px">
|
| 402 |
+
<col style="width: 140px">
|
| 403 |
+
<col style="width: 762px">
|
| 404 |
+
</colgroup>
|
| 405 |
+
<thead>
|
| 406 |
+
<tr>
|
| 407 |
+
<th>返回值</th>
|
| 408 |
+
<th>错误码</th>
|
| 409 |
+
<th>描述</th>
|
| 410 |
+
</tr>
|
| 411 |
+
</thead>
|
| 412 |
+
<tbody>
|
| 413 |
+
<tr>
|
| 414 |
+
<td rowspan="1">ACLNN_ERR_PARAM_NULLPTR</td>
|
| 415 |
+
<td rowspan="1">161001</td>
|
| 416 |
+
<td>传入的qkv、qGamma、kGamma、cos、sin等为空指针。</td>
|
| 417 |
+
</tr>
|
| 418 |
+
<tr>
|
| 419 |
+
<td rowspan="3">ACLNN_ERR_PARAM_INVALID</td>
|
| 420 |
+
<td rowspan="3">161002</td>
|
| 421 |
+
<td>输入或输出的数据类型不在支持的范围内。</td>
|
| 422 |
+
</tr>
|
| 423 |
+
<tr>
|
| 424 |
+
<td>输入或输出的参数维度不在支持的范围内。</td>
|
| 425 |
+
</tr>
|
| 426 |
+
<tr>
|
| 427 |
+
<td>dim不在指定的取值范围内。</td>
|
| 428 |
+
</tr>
|
| 429 |
+
</tbody></table>
|
| 430 |
+
|
| 431 |
+
## aclnnQkvRmsNormRopeCache
|
| 432 |
+
|
| 433 |
+
- **参数说明:**
|
| 434 |
+
|
| 435 |
+
<table style="undefined;table-layout: fixed; width: 953px"><colgroup>
|
| 436 |
+
<col style="width: 173px">
|
| 437 |
+
<col style="width: 112px">
|
| 438 |
+
<col style="width: 668px">
|
| 439 |
+
</colgroup>
|
| 440 |
+
<thead>
|
| 441 |
+
<tr>
|
| 442 |
+
<th>参数名</th>
|
| 443 |
+
<th>输入/输出</th>
|
| 444 |
+
<th>描述</th>
|
| 445 |
+
</tr></thead>
|
| 446 |
+
<tbody>
|
| 447 |
+
<tr>
|
| 448 |
+
<td>workspace</td>
|
| 449 |
+
<td>输入</td>
|
| 450 |
+
<td>在Device侧申请的workspace内存地址。</td>
|
| 451 |
+
</tr>
|
| 452 |
+
<tr>
|
| 453 |
+
<td>workspaceSize</td>
|
| 454 |
+
<td>输入</td>
|
| 455 |
+
<td>在Device侧申请的workspace大小,由第一段接口aclnnQkvRmsNormRopeCacheGetWorkspaceSize获取。</td>
|
| 456 |
+
</tr>
|
| 457 |
+
<tr>
|
| 458 |
+
<td>executor</td>
|
| 459 |
+
<td>输入</td>
|
| 460 |
+
<td>op执行器,包含了算子计算流程。</td>
|
| 461 |
+
</tr>
|
| 462 |
+
<tr>
|
| 463 |
+
<td>stream</td>
|
| 464 |
+
<td>输入</td>
|
| 465 |
+
<td>指定执行任务的Stream。</td>
|
| 466 |
+
</tr>
|
| 467 |
+
</tbody>
|
| 468 |
+
</table>
|
| 469 |
+
|
| 470 |
+
- **返回值:**
|
| 471 |
+
|
| 472 |
+
aclnnStatus:返回算子的执行状态码。
|
| 473 |
+
|
| 474 |
+
## 约束说明
|
| 475 |
+
|
| 476 |
+
- 确定性计算:
|
| 477 |
+
- aclnnQkvRmsNormRopeCache默认确定性实现。
|
| 478 |
+
|
| 479 |
+
- 输入shape限制:
|
| 480 |
+
* B<sub>qkv</sub>为输入qkv的batch_size,S<sub>qkv</sub>为输入qkv的sequence length,大小由qkvSize决定。
|
| 481 |
+
* N<sub>qkv</sub>为输入qkv的head number。D<sub>qkv</sub>为输入qkv的head dim,目前仅支持128。D<sub>q</sub>、D<sub>k</sub>和D<sub>k</sub>分别为q、k、v的head dim,要求D<sub>qkv</sub> = D<sub>q</sub> = D<sub>k</sub> = D<sub>v</sub>,D<sub>qkv</sub>需要满足(D<sub>qkv</sub>*qkv数据类型占字节数)可以被32整除。
|
| 482 |
+
* 根据rope规则,D<sub>k</sub>和D<sub>q</sub>为偶数。若cacheMode为PA_NZ场景下,D<sub>k</sub>、D<sub>q</sub>需32B对齐;BlockSize需32B对齐。
|
| 483 |
+
* 关于上述32B对齐的情形,对齐值由cache的数据类型决定。以BlockSize为例,若cache的数据类型为int8,则需要满足BlockSize % 32 = 0;若cache的数据类型为float16,则需要满足BlockSize % 16 = 0;若kCache与vCache参数的dtype不一致,BlockSize需同时满足BlockSize % 32 = 0和BlockSize % 16 = 0。
|
| 484 |
+
* BlockNum为写入cache的内存块数,大小由用户输入场景决定,要求BlockNum >= Ceil(S<sub>qkv</sub> / BlockSize) * B<sub>qkv</sub>。
|
| 485 |
+
* 使用requireMemory表示存放数据所需的空间大小,需满足:requireMemory >= (B<sub>qkv</sub> * S<sub>qkv</sub> * N<sub>qkv</sub> * D<sub>qkv</sub> + 2 * D<sub>qkv</sub> + 2 * B<sub>qkv</sub> * S<sub>qkv</sub> * D<sub>qkv</sub> + B<sub>qkv</sub> * S<sub>qkv</sub> * N<sub>q</sub> * D<sub>qkv</sub> + BlockNum * BlockSize * N<sub>v</sub> * D<sub>qkv</sub> + BlockNum * BlockSize * N<sub>k</sub> * D<sub>qkv</sub>) * sizeof(FLOAT16) + B<sub>qkv</sub> * S<sub>qkv</sub> * sizeof(INT64) + (2 * N<sub>k</sub> * D<sub>qkv</sub> + 2 * N<sub>v</sub>) * sizeof(FLOAT),当计算出requireMemory的大小超过当前AI处理器的GM空间总大小,不支持使用该接口。
|
| 486 |
+
- 其他限制:
|
| 487 |
+
* 对于index,要求index的value值范围为[-1, BlockNum * BlockSize)。value数值不可以重复,index为-1时,代表跳过更新。
|
| 488 |
+
* kScaleOptional, vScaleOptional表示对称量化的缩放因子,因此若传参,则值不能为0。
|
| 489 |
+
|
| 490 |
+
## 调用示例
|
| 491 |
+
|
| 492 |
+
以下示例代码展示接口调用流程,可供编译和运行时参考。
|
| 493 |
+
|
| 494 |
+
```Cpp
|
| 495 |
+
#include <iostream>
|
| 496 |
+
#include <vector>
|
| 497 |
+
#include "acl/acl.h"
|
| 498 |
+
#include "aclnnop/aclnn_qkv_rms_norm_rope_cache.h"
|
| 499 |
+
|
| 500 |
+
#define CHECK_RET(cond, return_expr) \
|
| 501 |
+
do { \
|
| 502 |
+
if (!(cond)) { \
|
| 503 |
+
return_expr; \
|
| 504 |
+
} \
|
| 505 |
+
} while (0)
|
| 506 |
+
|
| 507 |
+
#define LOG_PRINT(message, ...) \
|
| 508 |
+
do { \
|
| 509 |
+
printf(message, ##__VA_ARGS__); \
|
| 510 |
+
} while (0)
|
| 511 |
+
|
| 512 |
+
int64_t GetShapeSize(const std::vector<int64_t>& shape)
|
| 513 |
+
{
|
| 514 |
+
int64_t shapeSize = 1;
|
| 515 |
+
for (auto i : shape) {
|
| 516 |
+
shapeSize *= i;
|
| 517 |
+
}
|
| 518 |
+
return shapeSize;
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
void PrintOutResult(std::vector<int64_t>& shape, void** deviceAddr)
|
| 522 |
+
{
|
| 523 |
+
auto size = GetShapeSize(shape);
|
| 524 |
+
std::vector<int8_t> resultData(size, 0);
|
| 525 |
+
auto ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), *deviceAddr, size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST);
|
| 526 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return);
|
| 527 |
+
for (int64_t i = 0; i < size; i++) {
|
| 528 |
+
LOG_PRINT("result[%ld] is: %d\n", i, resultData[i]);
|
| 529 |
+
}
|
| 530 |
+
}
|
| 531 |
+
|
| 532 |
+
int Init(int32_t deviceId, aclrtStream* stream)
|
| 533 |
+
{
|
| 534 |
+
// 固定写法,资源初始化
|
| 535 |
+
auto ret = aclInit(nullptr);
|
| 536 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
|
| 537 |
+
ret = aclrtSetDevice(deviceId);
|
| 538 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
|
| 539 |
+
ret = aclrtCreateStream(stream);
|
| 540 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
|
| 541 |
+
return 0;
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
template <typename T>
|
| 545 |
+
int CreateAclTensor(
|
| 546 |
+
const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, aclDataType dataType,
|
| 547 |
+
aclTensor** tensor)
|
| 548 |
+
{
|
| 549 |
+
auto size = GetShapeSize(shape) * sizeof(T);
|
| 550 |
+
// 调用aclrtMalloc申请device侧内存
|
| 551 |
+
auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
|
| 552 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);
|
| 553 |
+
// 调用aclrtMemcpy将host侧数据拷贝到device侧内存上
|
| 554 |
+
ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
|
| 555 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret);
|
| 556 |
+
|
| 557 |
+
// 计算连续tensor的strides
|
| 558 |
+
std::vector<int64_t> strides(shape.size(), 1);
|
| 559 |
+
for (int64_t i = shape.size() - 2; i >= 0; i--) {
|
| 560 |
+
strides[i] = shape[i + 1] * strides[i + 1];
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
// 调用aclCreateTensor接口创建aclTensor
|
| 564 |
+
*tensor = aclCreateTensor(
|
| 565 |
+
shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(),
|
| 566 |
+
*deviceAddr);
|
| 567 |
+
return 0;
|
| 568 |
+
}
|
| 569 |
+
|
| 570 |
+
int main()
|
| 571 |
+
{
|
| 572 |
+
// 1. 固定写法,device/stream初始化,参考acl API
|
| 573 |
+
// 根据自己的实际device填写deviceId
|
| 574 |
+
int32_t deviceId = 0;
|
| 575 |
+
aclrtStream stream;
|
| 576 |
+
auto ret = Init(deviceId, &stream);
|
| 577 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
|
| 578 |
+
|
| 579 |
+
// 2. 构造输入与输出,需要根据API的接口定义构造
|
| 580 |
+
std::vector<int64_t> qkvShape = {48, 2304};
|
| 581 |
+
std::vector<int64_t> qGammaShape = {128};
|
| 582 |
+
std::vector<int64_t> kGammaShape = {128};
|
| 583 |
+
std::vector<int64_t> cosShape = {48, 128};
|
| 584 |
+
std::vector<int64_t> sinShape = {48, 128};
|
| 585 |
+
std::vector<int64_t> indexShape = {48};
|
| 586 |
+
std::vector<int64_t> qOutShape = {48, 2048};
|
| 587 |
+
std::vector<int64_t> kCacheShape = {16, 4, 128, 32};
|
| 588 |
+
std::vector<int64_t> vCacheShape = {16, 4, 128, 32};
|
| 589 |
+
std::vector<int64_t> kScaleShape = {1, 128};
|
| 590 |
+
std::vector<int64_t> vScaleShape = {1, 128};
|
| 591 |
+
std::vector<int64_t> qkv_size_list = {16, 3, 18, 128};
|
| 592 |
+
std::vector<int64_t> head_nums_list = {16, 1, 1};
|
| 593 |
+
|
| 594 |
+
std::vector<int16_t> qkvHostData(48 * 2304, 0);
|
| 595 |
+
std::vector<int16_t> qGammaHostData(128, 0);
|
| 596 |
+
std::vector<int16_t> kGammaHostData(128, 0);
|
| 597 |
+
std::vector<int16_t> cosHostData(48 * 128, 0);
|
| 598 |
+
std::vector<int16_t> sinHostData(48 * 128, 0);
|
| 599 |
+
std::vector<int64_t> indexHostData(48, 0);
|
| 600 |
+
std::vector<int16_t> qOutHostData(48 * 2048, 0);
|
| 601 |
+
std::vector<int16_t> kCacheHostData(16 * 4 * 128 * 32, 0);
|
| 602 |
+
std::vector<int16_t> vCacheHostData(16 * 4 * 128 * 32, 0);
|
| 603 |
+
std::vector<int16_t> kScaleHostData(1 * 128, 0);
|
| 604 |
+
std::vector<int16_t> vScaleHostData(1 * 128, 0);
|
| 605 |
+
|
| 606 |
+
void* qkvDeviceAddr = nullptr;
|
| 607 |
+
void* qGammaDeviceAddr = nullptr;
|
| 608 |
+
void* kGammaDeviceAddr = nullptr;
|
| 609 |
+
void* cosDeviceAddr = nullptr;
|
| 610 |
+
void* sinDeviceAddr = nullptr;
|
| 611 |
+
void* indexDeviceAddr = nullptr;
|
| 612 |
+
void* qOutDeviceAddr = nullptr;
|
| 613 |
+
void* kCacheDeviceAddr = nullptr;
|
| 614 |
+
void* vCacheDeviceAddr = nullptr;
|
| 615 |
+
void* kScaleDeviceAddr = nullptr;
|
| 616 |
+
void* vScaleDeviceAddr = nullptr;
|
| 617 |
+
|
| 618 |
+
aclTensor* qkv = nullptr;
|
| 619 |
+
aclTensor* qGamma = nullptr;
|
| 620 |
+
aclTensor* kGamma = nullptr;
|
| 621 |
+
aclTensor* cos = nullptr;
|
| 622 |
+
aclTensor* sin = nullptr;
|
| 623 |
+
aclTensor* index = nullptr;
|
| 624 |
+
aclTensor* qOut = nullptr;
|
| 625 |
+
aclTensor* kCache = nullptr;
|
| 626 |
+
aclTensor* vCache = nullptr;
|
| 627 |
+
aclTensor* kScale = nullptr;
|
| 628 |
+
aclTensor* vScale = nullptr;
|
| 629 |
+
|
| 630 |
+
aclIntArray *qkv_size = aclCreateIntArray(qkv_size_list.data(), qkv_size_list.size());
|
| 631 |
+
aclIntArray *head_nums = aclCreateIntArray(head_nums_list.data(), head_nums_list.size());
|
| 632 |
+
|
| 633 |
+
double epsilon = 1e-6;
|
| 634 |
+
char* cacheMode = "PA_NZ";
|
| 635 |
+
bool isOutputQkv = false;
|
| 636 |
+
|
| 637 |
+
ret = CreateAclTensor(qkvHostData, qkvShape, &qkvDeviceAddr, aclDataType::ACL_FLOAT16, &qkv);
|
| 638 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 639 |
+
ret = CreateAclTensor(qGammaHostData, qGammaShape, &qGammaDeviceAddr, aclDataType::ACL_FLOAT16, &qGamma);
|
| 640 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 641 |
+
ret = CreateAclTensor(kGammaHostData, kGammaShape, &kGammaDeviceAddr, aclDataType::ACL_FLOAT16, &kGamma);
|
| 642 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 643 |
+
ret = CreateAclTensor(cosHostData, cosShape, &cosDeviceAddr, aclDataType::ACL_FLOAT16, &cos);
|
| 644 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 645 |
+
ret = CreateAclTensor(sinHostData, sinShape, &sinDeviceAddr, aclDataType::ACL_FLOAT16, &sin);
|
| 646 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 647 |
+
ret = CreateAclTensor(indexHostData, indexShape, &indexDeviceAddr, aclDataType::ACL_INT64, &index);
|
| 648 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 649 |
+
ret = CreateAclTensor(qOutHostData, qOutShape, &qOutDeviceAddr, aclDataType::ACL_FLOAT16, &qOut);
|
| 650 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 651 |
+
ret = CreateAclTensor(kCacheHostData, kCacheShape, &kCacheDeviceAddr, aclDataType::ACL_INT8, &kCache);
|
| 652 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 653 |
+
ret = CreateAclTensor(vCacheHostData, vCacheShape, &vCacheDeviceAddr, aclDataType::ACL_INT8, &vCache);
|
| 654 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 655 |
+
ret = CreateAclTensor(kScaleHostData, kScaleShape, &kScaleDeviceAddr, aclDataType::ACL_FLOAT, &kScale);
|
| 656 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 657 |
+
ret = CreateAclTensor(vScaleHostData, vScaleShape, &vScaleDeviceAddr, aclDataType::ACL_FLOAT, &vScale);
|
| 658 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 659 |
+
|
| 660 |
+
// 3. 调用CANN算子库API,需要修改为具体的API
|
| 661 |
+
uint64_t workspaceSize = 0;
|
| 662 |
+
aclOpExecutor* executor;
|
| 663 |
+
|
| 664 |
+
// 调用aclnnQkvRmsNormRopeCache第一段接口
|
| 665 |
+
ret = aclnnQkvRmsNormRopeCacheGetWorkspaceSize(
|
| 666 |
+
qkv, qGamma, kGamma, cos, sin, index, qOut, kCache, vCache, kScale, vScale, nullptr, nullptr, qkv_size,
|
| 667 |
+
head_nums, epsilon, cacheMode, nullptr, nullptr, nullptr, &workspaceSize, &executor);
|
| 668 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnQkvRmsNormRopeCacheGetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
|
| 669 |
+
|
| 670 |
+
// 根据第一段接口计算出的workspaceSize申请device内存
|
| 671 |
+
void* workspaceAddr = nullptr;
|
| 672 |
+
if (workspaceSize > 0) {
|
| 673 |
+
ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
|
| 674 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
// 调用aclnnQkvRmsNormRopeCache第二段接口
|
| 678 |
+
ret = aclnnQkvRmsNormRopeCache(workspaceAddr, workspaceSize, executor, stream);
|
| 679 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnQkvRmsNormRopeCache failed. ERROR: %d\n", ret); return ret);
|
| 680 |
+
|
| 681 |
+
// 4. 固定写法,同步等待任务执行结束
|
| 682 |
+
ret = aclrtSynchronizeStream(stream);
|
| 683 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
|
| 684 |
+
|
| 685 |
+
// 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改
|
| 686 |
+
PrintOutResult(kCacheShape, &kCacheDeviceAddr);
|
| 687 |
+
PrintOutResult(vCacheShape, &vCacheDeviceAddr);
|
| 688 |
+
|
| 689 |
+
// 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改
|
| 690 |
+
aclDestroyTensor(qkv);
|
| 691 |
+
aclDestroyTensor(qGamma);
|
| 692 |
+
aclDestroyTensor(kGamma);
|
| 693 |
+
aclDestroyTensor(cos);
|
| 694 |
+
aclDestroyTensor(sin);
|
| 695 |
+
aclDestroyTensor(index);
|
| 696 |
+
aclDestroyTensor(qOut);
|
| 697 |
+
aclDestroyTensor(kCache);
|
| 698 |
+
aclDestroyTensor(vCache);
|
| 699 |
+
aclDestroyTensor(kScale);
|
| 700 |
+
aclDestroyTensor(vScale);
|
| 701 |
+
|
| 702 |
+
// 7. 释放device资源
|
| 703 |
+
aclrtFree(qkvDeviceAddr);
|
| 704 |
+
aclrtFree(qGammaDeviceAddr);
|
| 705 |
+
aclrtFree(kGammaDeviceAddr);
|
| 706 |
+
aclrtFree(cosDeviceAddr);
|
| 707 |
+
aclrtFree(sinDeviceAddr);
|
| 708 |
+
aclrtFree(indexDeviceAddr);
|
| 709 |
+
aclrtFree(qOutDeviceAddr);
|
| 710 |
+
aclrtFree(kCacheDeviceAddr);
|
| 711 |
+
aclrtFree(vCacheDeviceAddr);
|
| 712 |
+
aclrtFree(kScaleDeviceAddr);
|
| 713 |
+
aclrtFree(vScaleDeviceAddr);
|
| 714 |
+
|
| 715 |
+
if (workspaceSize > 0) {
|
| 716 |
+
aclrtFree(workspaceAddr);
|
| 717 |
+
}
|
| 718 |
+
aclrtDestroyStream(stream);
|
| 719 |
+
aclrtResetDevice(deviceId);
|
| 720 |
+
aclFinalize();
|
| 721 |
+
|
| 722 |
+
return 0;
|
| 723 |
+
}
|
| 724 |
+
```
|
datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/examples/test_aclnn_qkv_rms_norm_rope_cache.cpp
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 2026 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
#include <iostream>
|
| 12 |
+
#include <vector>
|
| 13 |
+
#include "acl/acl.h"
|
| 14 |
+
#include "aclnnop/aclnn_qkv_rms_norm_rope_cache.h"
|
| 15 |
+
|
| 16 |
+
#define CHECK_RET(cond, return_expr) \
|
| 17 |
+
do { \
|
| 18 |
+
if (!(cond)) { \
|
| 19 |
+
return_expr; \
|
| 20 |
+
} \
|
| 21 |
+
} while (0)
|
| 22 |
+
|
| 23 |
+
#define LOG_PRINT(message, ...) \
|
| 24 |
+
do { \
|
| 25 |
+
printf(message, ##__VA_ARGS__); \
|
| 26 |
+
} while (0)
|
| 27 |
+
|
| 28 |
+
int64_t GetShapeSize(const std::vector<int64_t>& shape)
|
| 29 |
+
{
|
| 30 |
+
int64_t shapeSize = 1;
|
| 31 |
+
for (auto i : shape) {
|
| 32 |
+
shapeSize *= i;
|
| 33 |
+
}
|
| 34 |
+
return shapeSize;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
void PrintOutResult(std::vector<int64_t>& shape, void** deviceAddr)
|
| 38 |
+
{
|
| 39 |
+
auto size = GetShapeSize(shape);
|
| 40 |
+
std::vector<int8_t> resultData(size, 0);
|
| 41 |
+
auto ret = aclrtMemcpy(resultData.data(), resultData.size() * sizeof(resultData[0]), *deviceAddr, size * sizeof(resultData[0]), ACL_MEMCPY_DEVICE_TO_HOST);
|
| 42 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return);
|
| 43 |
+
for (int64_t i = 0; i < size; i++) {
|
| 44 |
+
LOG_PRINT("result[%ld] is: %d\n", i, resultData[i]);
|
| 45 |
+
}
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
int Init(int32_t deviceId, aclrtStream* stream)
|
| 49 |
+
{
|
| 50 |
+
// 固定写法,资源初始化
|
| 51 |
+
auto ret = aclInit(nullptr);
|
| 52 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclInit failed. ERROR: %d\n", ret); return ret);
|
| 53 |
+
ret = aclrtSetDevice(deviceId);
|
| 54 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSetDevice failed. ERROR: %d\n", ret); return ret);
|
| 55 |
+
ret = aclrtCreateStream(stream);
|
| 56 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtCreateStream failed. ERROR: %d\n", ret); return ret);
|
| 57 |
+
return 0;
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
template <typename T>
|
| 61 |
+
int CreateAclTensor(
|
| 62 |
+
const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, aclDataType dataType,
|
| 63 |
+
aclTensor** tensor)
|
| 64 |
+
{
|
| 65 |
+
auto size = GetShapeSize(shape) * sizeof(T);
|
| 66 |
+
// 调用aclrtMalloc申请device侧内存
|
| 67 |
+
auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST);
|
| 68 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret);
|
| 69 |
+
// 调用aclrtMemcpy将host侧数据拷贝到device侧内存上
|
| 70 |
+
ret = aclrtMemcpy(*deviceAddr, size, hostData.data(), size, ACL_MEMCPY_HOST_TO_DEVICE);
|
| 71 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMemcpy failed. ERROR: %d\n", ret); return ret);
|
| 72 |
+
|
| 73 |
+
// 计算连续tensor的strides
|
| 74 |
+
std::vector<int64_t> strides(shape.size(), 1);
|
| 75 |
+
for (int64_t i = shape.size() - 2; i >= 0; i--) {
|
| 76 |
+
strides[i] = shape[i + 1] * strides[i + 1];
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// 调用aclCreateTensor接口创建aclTensor
|
| 80 |
+
*tensor = aclCreateTensor(
|
| 81 |
+
shape.data(), shape.size(), dataType, strides.data(), 0, aclFormat::ACL_FORMAT_ND, shape.data(), shape.size(),
|
| 82 |
+
*deviceAddr);
|
| 83 |
+
return 0;
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
int main()
|
| 87 |
+
{
|
| 88 |
+
// 1. 固定写法,device/stream初始化, 参考acl API
|
| 89 |
+
// 根据自己的实际device填写deviceId
|
| 90 |
+
int32_t deviceId = 0;
|
| 91 |
+
aclrtStream stream;
|
| 92 |
+
auto ret = Init(deviceId, &stream);
|
| 93 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("Init acl failed. ERROR: %d\n", ret); return ret);
|
| 94 |
+
|
| 95 |
+
// 2. 构造输入与输出,需要根据API的接口定义构造
|
| 96 |
+
std::vector<int64_t> qkvShape = {48, 2304};
|
| 97 |
+
std::vector<int64_t> qGammaShape = {128};
|
| 98 |
+
std::vector<int64_t> kGammaShape = {128};
|
| 99 |
+
std::vector<int64_t> cosShape = {48, 128};
|
| 100 |
+
std::vector<int64_t> sinShape = {48, 128};
|
| 101 |
+
std::vector<int64_t> indexShape = {48};
|
| 102 |
+
std::vector<int64_t> qOutShape = {48, 2048};
|
| 103 |
+
std::vector<int64_t> kCacheShape = {16, 4, 128, 32};
|
| 104 |
+
std::vector<int64_t> vCacheShape = {16, 4, 128, 32};
|
| 105 |
+
std::vector<int64_t> kScaleShape = {1, 128};
|
| 106 |
+
std::vector<int64_t> vScaleShape = {1, 128};
|
| 107 |
+
std::vector<int64_t> qkv_size_list = {16, 3, 18, 128};
|
| 108 |
+
std::vector<int64_t> head_nums_list = {16, 1, 1};
|
| 109 |
+
|
| 110 |
+
std::vector<int16_t> qkvHostData(48 * 2304, 0);
|
| 111 |
+
std::vector<int16_t> qGammaHostData(128, 0);
|
| 112 |
+
std::vector<int16_t> kGammaHostData(128, 0);
|
| 113 |
+
std::vector<int16_t> cosHostData(48 * 128, 0);
|
| 114 |
+
std::vector<int16_t> sinHostData(48 * 128, 0);
|
| 115 |
+
std::vector<int64_t> indexHostData(48, 0);
|
| 116 |
+
std::vector<int16_t> qOutHostData(48 * 2048, 0);
|
| 117 |
+
std::vector<int16_t> kCacheHostData(16 * 4 * 128 * 32, 0);
|
| 118 |
+
std::vector<int16_t> vCacheHostData(16 * 4 * 128 * 32, 0);
|
| 119 |
+
std::vector<int16_t> kScaleHostData(1 * 128, 0);
|
| 120 |
+
std::vector<int16_t> vScaleHostData(1 * 128, 0);
|
| 121 |
+
|
| 122 |
+
void* qkvDeviceAddr = nullptr;
|
| 123 |
+
void* qGammaDeviceAddr = nullptr;
|
| 124 |
+
void* kGammaDeviceAddr = nullptr;
|
| 125 |
+
void* cosDeviceAddr = nullptr;
|
| 126 |
+
void* sinDeviceAddr = nullptr;
|
| 127 |
+
void* indexDeviceAddr = nullptr;
|
| 128 |
+
void* qOutDeviceAddr = nullptr;
|
| 129 |
+
void* kCacheDeviceAddr = nullptr;
|
| 130 |
+
void* vCacheDeviceAddr = nullptr;
|
| 131 |
+
void* kScaleDeviceAddr = nullptr;
|
| 132 |
+
void* vScaleDeviceAddr = nullptr;
|
| 133 |
+
|
| 134 |
+
aclTensor* qkv = nullptr;
|
| 135 |
+
aclTensor* qGamma = nullptr;
|
| 136 |
+
aclTensor* kGamma = nullptr;
|
| 137 |
+
aclTensor* cos = nullptr;
|
| 138 |
+
aclTensor* sin = nullptr;
|
| 139 |
+
aclTensor* index = nullptr;
|
| 140 |
+
aclTensor* qOut = nullptr;
|
| 141 |
+
aclTensor* kCache = nullptr;
|
| 142 |
+
aclTensor* vCache = nullptr;
|
| 143 |
+
aclTensor* kScale = nullptr;
|
| 144 |
+
aclTensor* vScale = nullptr;
|
| 145 |
+
|
| 146 |
+
aclIntArray *qkv_size = aclCreateIntArray(qkv_size_list.data(), qkv_size_list.size());
|
| 147 |
+
aclIntArray *head_nums = aclCreateIntArray(head_nums_list.data(), head_nums_list.size());
|
| 148 |
+
|
| 149 |
+
double epsilon = 1e-6;
|
| 150 |
+
char* cacheMode = "PA_NZ";
|
| 151 |
+
bool isOutputQkv = false;
|
| 152 |
+
|
| 153 |
+
ret = CreateAclTensor(qkvHostData, qkvShape, &qkvDeviceAddr, aclDataType::ACL_FLOAT16, &qkv);
|
| 154 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 155 |
+
ret = CreateAclTensor(qGammaHostData, qGammaShape, &qGammaDeviceAddr, aclDataType::ACL_FLOAT16, &qGamma);
|
| 156 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 157 |
+
ret = CreateAclTensor(kGammaHostData, kGammaShape, &kGammaDeviceAddr, aclDataType::ACL_FLOAT16, &kGamma);
|
| 158 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 159 |
+
ret = CreateAclTensor(cosHostData, cosShape, &cosDeviceAddr, aclDataType::ACL_FLOAT16, &cos);
|
| 160 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 161 |
+
ret = CreateAclTensor(sinHostData, sinShape, &sinDeviceAddr, aclDataType::ACL_FLOAT16, &sin);
|
| 162 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 163 |
+
ret = CreateAclTensor(indexHostData, indexShape, &indexDeviceAddr, aclDataType::ACL_INT64, &index);
|
| 164 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 165 |
+
ret = CreateAclTensor(qOutHostData, qOutShape, &qOutDeviceAddr, aclDataType::ACL_FLOAT16, &qOut);
|
| 166 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 167 |
+
ret = CreateAclTensor(kCacheHostData, kCacheShape, &kCacheDeviceAddr, aclDataType::ACL_INT8, &kCache);
|
| 168 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 169 |
+
ret = CreateAclTensor(vCacheHostData, vCacheShape, &vCacheDeviceAddr, aclDataType::ACL_INT8, &vCache);
|
| 170 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 171 |
+
ret = CreateAclTensor(kScaleHostData, kScaleShape, &kScaleDeviceAddr, aclDataType::ACL_FLOAT, &kScale);
|
| 172 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 173 |
+
ret = CreateAclTensor(vScaleHostData, vScaleShape, &vScaleDeviceAddr, aclDataType::ACL_FLOAT, &vScale);
|
| 174 |
+
CHECK_RET(ret == ACL_SUCCESS, return ret);
|
| 175 |
+
|
| 176 |
+
// 3. 调用CANN算子库API,需要修改为具体的API
|
| 177 |
+
uint64_t workspaceSize = 0;
|
| 178 |
+
aclOpExecutor* executor;
|
| 179 |
+
|
| 180 |
+
// 调用aclnnQkvRmsNormRopeCache第一段接口
|
| 181 |
+
ret = aclnnQkvRmsNormRopeCacheGetWorkspaceSize(
|
| 182 |
+
qkv, qGamma, kGamma, cos, sin, index, qOut, kCache, vCache, kScale, vScale, nullptr, nullptr, qkv_size,
|
| 183 |
+
head_nums, epsilon, cacheMode, nullptr, nullptr, nullptr, &workspaceSize, &executor);
|
| 184 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnQkvRmsNormRopeCacheGetWorkspaceSize failed. ERROR: %d\n", ret); return ret);
|
| 185 |
+
|
| 186 |
+
// 根据第一段接口计算出的workspaceSize申请device内存
|
| 187 |
+
void* workspaceAddr = nullptr;
|
| 188 |
+
if (workspaceSize > 0) {
|
| 189 |
+
ret = aclrtMalloc(&workspaceAddr, workspaceSize, ACL_MEM_MALLOC_HUGE_FIRST);
|
| 190 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("allocate workspace failed. ERROR: %d\n", ret); return ret);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
// 调用aclnnQkvRmsNormRopeCache第二段接口
|
| 194 |
+
ret = aclnnQkvRmsNormRopeCache(workspaceAddr, workspaceSize, executor, stream);
|
| 195 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclnnQkvRmsNormRopeCache failed. ERROR: %d\n", ret); return ret);
|
| 196 |
+
|
| 197 |
+
// 4. 固定写法,同步等待任务执行结束
|
| 198 |
+
ret = aclrtSynchronizeStream(stream);
|
| 199 |
+
CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtSynchronizeStream failed. ERROR: %d\n", ret); return ret);
|
| 200 |
+
|
| 201 |
+
// 5. 获取输出的值,将device侧内存上的结果拷贝至host侧,需要根据具体API的接口定义修改
|
| 202 |
+
PrintOutResult(kCacheShape, &kCacheDeviceAddr);
|
| 203 |
+
PrintOutResult(vCacheShape, &vCacheDeviceAddr);
|
| 204 |
+
|
| 205 |
+
// 6. 释放aclTensor和aclScalar,需要根据具体API的接口定义修改
|
| 206 |
+
aclDestroyTensor(qkv);
|
| 207 |
+
aclDestroyTensor(qGamma);
|
| 208 |
+
aclDestroyTensor(kGamma);
|
| 209 |
+
aclDestroyTensor(cos);
|
| 210 |
+
aclDestroyTensor(sin);
|
| 211 |
+
aclDestroyTensor(index);
|
| 212 |
+
aclDestroyTensor(qOut);
|
| 213 |
+
aclDestroyTensor(kCache);
|
| 214 |
+
aclDestroyTensor(vCache);
|
| 215 |
+
aclDestroyTensor(kScale);
|
| 216 |
+
aclDestroyTensor(vScale);
|
| 217 |
+
|
| 218 |
+
// 7. 释放device 资源
|
| 219 |
+
aclrtFree(qkvDeviceAddr);
|
| 220 |
+
aclrtFree(qGammaDeviceAddr);
|
| 221 |
+
aclrtFree(kGammaDeviceAddr);
|
| 222 |
+
aclrtFree(cosDeviceAddr);
|
| 223 |
+
aclrtFree(sinDeviceAddr);
|
| 224 |
+
aclrtFree(indexDeviceAddr);
|
| 225 |
+
aclrtFree(qOutDeviceAddr);
|
| 226 |
+
aclrtFree(kCacheDeviceAddr);
|
| 227 |
+
aclrtFree(vCacheDeviceAddr);
|
| 228 |
+
aclrtFree(kScaleDeviceAddr);
|
| 229 |
+
aclrtFree(vScaleDeviceAddr);
|
| 230 |
+
|
| 231 |
+
if (workspaceSize > 0) {
|
| 232 |
+
aclrtFree(workspaceAddr);
|
| 233 |
+
}
|
| 234 |
+
aclrtDestroyStream(stream);
|
| 235 |
+
aclrtResetDevice(deviceId);
|
| 236 |
+
aclFinalize();
|
| 237 |
+
|
| 238 |
+
return 0;
|
| 239 |
+
}
|
datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/op_graph/CMakeLists.txt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This program is free software, you can redistribute it and/or modify.
|
| 2 |
+
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This file is a part of the CANN Open Software.
|
| 4 |
+
# Licensed under CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# 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.
|
| 7 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 8 |
+
# ============================================================================
|
| 9 |
+
|
| 10 |
+
message(STATUS "=== Debug: start ops.posembedding.qkv_rms_norm_rope_cache.graph_plugin.CMakeLists.txt ")
|
| 11 |
+
add_graph_plugin_sources()
|
datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/op_graph/qkv_rms_norm_rope_cache_proto.h
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
| 3 |
+
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
|
| 4 |
+
* CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
* Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
|
| 7 |
+
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
|
| 8 |
+
* See LICENSE in the root of the software repository for the full text of the License.
|
| 9 |
+
*/
|
| 10 |
+
|
| 11 |
+
/*!
|
| 12 |
+
* \file qkv_rms_norm_rope_cache_proto.h
|
| 13 |
+
* \brief
|
| 14 |
+
*/
|
| 15 |
+
#ifndef OPS_OP_PROTO_INC_QKV_RMS_NORM_ROPE_CACHE_H_
|
| 16 |
+
#define OPS_OP_PROTO_INC_QKV_RMS_NORM_ROPE_CACHE_H_
|
| 17 |
+
|
| 18 |
+
#include "graph/operator_reg.h"
|
| 19 |
+
#include "graph/types.h"
|
| 20 |
+
|
| 21 |
+
namespace ge {
|
| 22 |
+
/**
|
| 23 |
+
* @brief The fusion operator of SpiltVD, RMSNorm, RotaryPositionEmbedding, Quant and Update KVCache.
|
| 24 |
+
*
|
| 25 |
+
* @par Inputs:
|
| 26 |
+
* @li qkv: A tensor. The type support float16 and bfloat16. Its shape is [Bqkv*Sqkv,Nqkv*Dqkv]. Format: ND.
|
| 27 |
+
* @li q_gamma: A tensor, used in RMS Norm. Its type is consistent with qkv. Its shape is [Dqkv,]. Format: ND.
|
| 28 |
+
* @li k_gamma: A tensor, used in RMS Norm. Its type is consistent with qkv. Its shape is [Dqkv,]. Format: ND.
|
| 29 |
+
* @li cos: A tensor, from position embedding. Its type is consistent with kv. Its shape is [Bqkv*Sqkv,Dqkv]. Format: ND.
|
| 30 |
+
* @li sin: A tensor, from position embedding. Its type is consistent with qkv. [Bqkv*Sqkv,Dqkv].
|
| 31 |
+
* The shape of sin should be consistent with that of cos. Format: ND.
|
| 32 |
+
* @li index: A tensor. The type support int64. When the cache_mode is PA_NZ, its shape is [Bqkv*Sqkv] Format: ND.
|
| 33 |
+
* @li q_out: A tensor. Its type is consistent with qkv. Its shape is [Bqkv*Sqkv, Nq*Dqkv]. Format: ND.
|
| 34 |
+
* @li k_cache: A tensor. Its type is consistent with qkv or int8. When the type is int8,
|
| 35 |
+
* its shape is [BlockNum, Nk * Dqkv // 32, BlockSize, 32]. when the type consistent with qkv,
|
| 36 |
+
* its shape is [BlockNum, Nk * Dqkv // 16, BlockSize, 16]. Format: ND.
|
| 37 |
+
* @li v_cache: A tensor. Its type is consistent with qkv or int8. When the type is int8,
|
| 38 |
+
* its shape is [BlockNum, Nv * Dqkv // 32, BlockSize, 32]. when the type consistent with qkv,
|
| 39 |
+
* its shape is [BlockNum, Nv * Dqkv // 16, BlockSize, 16]. Format: ND.
|
| 40 |
+
* @li k_scale: A tensor. The type support float32. This input parameter is required when the data type of k_cache
|
| 41 |
+
* is int8. Its shape can be [Nk,Dqkv]. Format: ND.
|
| 42 |
+
* @li v_scale: A tensor. The type support float32. This input parameter is required when the data type of v_cache
|
| 43 |
+
* is int8. Its shape can be [Nv,Dqkv]. Format: ND.
|
| 44 |
+
* @li k_offset: A tensor. The type support float32. When the data type of k_cache is int8 and the corresponding
|
| 45 |
+
* input exists with the quantization scenario being asymmetric quantization, this parameter input is required. Its
|
| 46 |
+
* shape can be [Nk,Dqkv]. Format: ND.
|
| 47 |
+
* @li v_offset: A tensor. The type support float32. When the data type of v_cache is int8 and the corresponding
|
| 48 |
+
* input exists with the quantization scenario being asymmetric quantization, this parameter input is required. Its
|
| 49 |
+
* shape can be [Nv,Dqkv]. Format: ND.
|
| 50 |
+
*
|
| 51 |
+
* @par Outputs:
|
| 52 |
+
* @li q_out: A tensor. Its type is consistent with qkv. Its shape is [Bqkv*Sqkv, Nq*Dqkv]. Format: ND.
|
| 53 |
+
* @li k_cache: A tensor. Its type is consistent with qkv or int8. When the type is int8,
|
| 54 |
+
* its shape is [BlockNum, Nk * Dqkv // 32, BlockSize, 32]. when the type consistent with qkv,
|
| 55 |
+
* its shape is [BlockNum, Nk * Dqkv // 16, BlockSize, 16]. Format: ND.
|
| 56 |
+
* @li v_cache: A tensor. Its type is consistent with qkv or int8. When the type is int8,
|
| 57 |
+
* its shape is [BlockNum, Nk * Dqkv // 32, BlockSize, 32]. when the type consistent with qkv,
|
| 58 |
+
* its shape is [BlockNum, Nk * Dqkv // 16, BlockSize, 16]. Format: ND.
|
| 59 |
+
* @li q_out_before_quant: A tensor. Its type is consistent with qkv. If is_output_qkv is true, this parameter output is required.
|
| 60 |
+
* Its shape is [Bqkv*Sqkv, Nq*Dqkv]. Format: ND.
|
| 61 |
+
* @li k_out_before_quant: A tensor. Its type is consistent with qkv. If is_output_qkv is true, this parameter output is required.
|
| 62 |
+
* Its shape is [Bqkv*Sqkv, Nk*Dqkv]. Format: ND.
|
| 63 |
+
* @li v_out_before_quant: A tensor. Its type is consistent with qkv. If is_output_qkv is true, this parameter output is required.
|
| 64 |
+
* Its shape is [Bqkv*Sqkv, Nv*Dqkv]. Format: ND.
|
| 65 |
+
*
|
| 66 |
+
* @par Attributes:
|
| 67 |
+
* @li qkv_size: A Listint. Provide the specific dimension sizes of the input of qkv matrices in the order of [Bqkv, Sqkv, Nqkv, Dqkv].
|
| 68 |
+
* @li head_nums: A Listint. Specifying the N-dim,ensional sizes of the q, k, v components in the qkv input matrix, in the order [Nq, Nk, Nv].
|
| 69 |
+
* @li epsilon: A float32. The epsilon value for RMSNorm. Default: 1e-6.
|
| 70 |
+
* @li cache_mode: A string. The cache dtype. There is one types:PA_NZ. Default: PA_NZ.
|
| 71 |
+
* @li is_output_qkv: A bool. Control whether k_cache_proto and v_cache_proto are output. If it is true, then k_out_before_quant and v_out_before_quant need to be
|
| 72 |
+
* output. If it is false, then k_cache_proto and v_cache_proto do not need to be output. Default: false.
|
| 73 |
+
*
|
| 74 |
+
* @attention Constraints:
|
| 75 |
+
* @li The shape format description in the parameter description:
|
| 76 |
+
* - Bqkv represents the batch size of the input qkv, and Skv represents the sequence length of the input qkv. The
|
| 77 |
+
* size is determined by the user's input scenario and has no explicit restrictions.
|
| 78 |
+
* - Nqkv is the head number of the input qkv. This operator is strongly related to the Qwen3-Moe 235b network structure.
|
| 79 |
+
* - Dqkv is the head dim of the input qkv. The data Dqkv required for rms norm calculation and the data Dqkv required
|
| 80 |
+
* for rope calculation are split from the Dqkv of the input qkv. In rope calculation, Drope=Dqkv.
|
| 81 |
+
* Therefore, Dqkv must comply with the rope rules. According to the rope rule, Dqkv is an even number.
|
| 82 |
+
* If cache_mode is an NZ scenario(cahce_mode is PA_NZ), Dqkv needs to be 32B aligned.
|
| 83 |
+
* - If cache_mode is a PA scenario, the BlockSize needs to be 32B aligned.
|
| 84 |
+
* - Regarding the above-mentioned 32B alignment situation, the alignment value is determined by the data type
|
| 85 |
+
* of the cache. Take BlockSize as an example. If the data type of the cache is int8, then BlockSize%32=0 is
|
| 86 |
+
* required. If the data type of the cache is flaot16, then BlockSize%16=0 is required.
|
| 87 |
+
* - BlockNum is the number of memory blocks written to the cache, and its size is determined by the user's input
|
| 88 |
+
* scenario without any definite limit.
|
| 89 |
+
* @li The index-related constraints:
|
| 90 |
+
* When cache_mode is PA_NZ, the shape is [Bqkv*Sqkv], and the value range of the index must be
|
| 91 |
+
* [-1,BlockNum*BlockSize). The values cannot be repeated.
|
| 92 |
+
*/
|
| 93 |
+
REG_OP(QkvRmsNormRopeCache)
|
| 94 |
+
.INPUT(qkv, TensorType({DT_FLOAT16, DT_BF16}))
|
| 95 |
+
.INPUT(q_gamma, TensorType({DT_FLOAT16, DT_BF16}))
|
| 96 |
+
.INPUT(k_gamma, TensorType({DT_FLOAT16, DT_BF16}))
|
| 97 |
+
.INPUT(cos, TensorType({DT_FLOAT16, DT_BF16}))
|
| 98 |
+
.INPUT(sin, TensorType({DT_FLOAT16, DT_BF16}))
|
| 99 |
+
.INPUT(index, TensorType({DT_INT64}))
|
| 100 |
+
.INPUT(q_out, TensorType({DT_FLOAT16, DT_BF16}))
|
| 101 |
+
.INPUT(k_cache, TensorType({DT_FLOAT16, DT_BF16, DT_INT8}))
|
| 102 |
+
.INPUT(v_cache, TensorType({DT_FLOAT16, DT_BF16, DT_INT8}))
|
| 103 |
+
.OPTIONAL_INPUT(k_scale, TensorType({DT_FLOAT}))
|
| 104 |
+
.OPTIONAL_INPUT(v_scale, TensorType({DT_FLOAT}))
|
| 105 |
+
.OPTIONAL_INPUT(k_offset, TensorType({DT_FLOAT}))
|
| 106 |
+
.OPTIONAL_INPUT(v_offset, TensorType({DT_FLOAT}))
|
| 107 |
+
.OUTPUT(q_out, TensorType({DT_FLOAT16, DT_BF16}))
|
| 108 |
+
.OUTPUT(k_cache, TensorType({DT_FLOAT16, DT_BF16, DT_INT8}))
|
| 109 |
+
.OUTPUT(v_cache, TensorType({DT_FLOAT16, DT_BF16, DT_INT8}))
|
| 110 |
+
.OUTPUT(q_out_before_quant, TensorType({DT_FLOAT16, DT_BF16}))
|
| 111 |
+
.OUTPUT(k_out_before_quant, TensorType({DT_FLOAT16, DT_BF16}))
|
| 112 |
+
.OUTPUT(v_out_before_quant, TensorType({DT_FLOAT16, DT_BF16}))
|
| 113 |
+
.REQUIRED_ATTR(qkv_size, ListInt)
|
| 114 |
+
.REQUIRED_ATTR(head_nums, ListInt)
|
| 115 |
+
.ATTR(epsilon, Float, 1e-6)
|
| 116 |
+
.ATTR(cache_mode, String, "PA_NZ")
|
| 117 |
+
.ATTR(is_output_qkv, Bool, false)
|
| 118 |
+
.OP_END_FACTORY_REG(QkvRmsNormRopeCache)
|
| 119 |
+
} // namespace ge
|
| 120 |
+
|
| 121 |
+
#endif // OPS_OP_PROTO_INC_QKV_RMS_NORM_ROPE_CACHE_H_
|
datasets/ops_src/ops_transformer/test_kernels/kernels/qkv_rms_norm_rope_cache/op_host/CMakeLists.txt
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This program is free software, you can redistribute it and/or modify.
|
| 2 |
+
# Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
| 3 |
+
# This file is a part of the CANN Open Software.
|
| 4 |
+
# Licensed under CANN Open Software License Agreement Version 2.0 (the "License").
|
| 5 |
+
# Please refer to the License for details. You may not use this file except in compliance with the License.
|
| 6 |
+
# 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.
|
| 7 |
+
# See LICENSE in the root of the software repository for the full text of the License.
|
| 8 |
+
# ============================================================================
|
| 9 |
+
|
| 10 |
+
message(STATUS "=== Debug: start ops.posembedding.qkv_rms_norm_rope_cache.op_host.CMakeLists.txt ")
|
| 11 |
+
|
| 12 |
+
if (BUILD_OPEN_PROJECT)
|
| 13 |
+
message(STATUS "=== Debug: BUILD is BUILD_OPEN_PROJECT")
|
| 14 |
+
target_sources(op_host_aclnnExc PRIVATE
|
| 15 |
+
qkv_rms_norm_rope_cache_def.cpp
|
| 16 |
+
)
|
| 17 |
+
add_ops_compile_options(
|
| 18 |
+
OP_NAME QkvRmsNormRopeCache
|
| 19 |
+
OPTIONS --cce-auto-sync=on
|
| 20 |
+
-Wno-deprecated-declarations
|
| 21 |
+
-Werror
|
| 22 |
+
)
|
| 23 |
+
endif()
|
| 24 |
+
|
| 25 |
+
if(NOT BUILD_OPS_RTY_KERNEL)
|
| 26 |
+
message(STATUS "=== Debug: BUILD is NOT BUILD_OPS_RTY_KERNEL")
|
| 27 |
+
add_modules_sources(OPTYPE qkv_rms_norm_rope_cache ACLNNTYPE aclnn_exclude)
|
| 28 |
+
endif()
|
datasets/ops_src/ops_transform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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"op_type": "QkvRmsNormRopeCache",
|
| 3 |
+
"op_list": [
|
| 4 |
+
{
|
| 5 |
+
"bin_filename": "QkvRmsNormRopeCache_fp16",
|
| 6 |
+
"inputs": [
|
| 7 |
+
{
|
| 8 |
+
"name": "qkv",
|
| 9 |
+
"index": 0,
|
| 10 |
+
"dtype": "float16",
|
| 11 |
+
"format": "ND",
|
| 12 |
+
"paramType": "required",
|
| 13 |
+
"shape": [
|
| 14 |
+
-2
|
| 15 |
+
],
|
| 16 |
+
"format_match_mode": "FormatAgnostic"
|
| 17 |
+
},
|
| 18 |
+
{
|
| 19 |
+
"name": "q_gamma",
|
| 20 |
+
"index": 1,
|
| 21 |
+
"dtype": "float16",
|
| 22 |
+
"format": "ND",
|
| 23 |
+
"paramType": "required",
|
| 24 |
+
"shape": [
|
| 25 |
+
-2
|
| 26 |
+
],
|
| 27 |
+
"format_match_mode": "FormatAgnostic"
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"name": "k_gamma",
|
| 31 |
+
"index": 2,
|
| 32 |
+
"dtype": "float16",
|
| 33 |
+
"format": "ND",
|
| 34 |
+
"paramType": "required",
|
| 35 |
+
"shape": [
|
| 36 |
+
-2
|
| 37 |
+
],
|
| 38 |
+
"format_match_mode": "FormatAgnostic"
|
| 39 |
+
},
|
| 40 |
+
{
|
| 41 |
+
"name": "cos",
|
| 42 |
+
"index": 3,
|
| 43 |
+
"dtype": "float16",
|
| 44 |
+
"format": "ND",
|
| 45 |
+
"paramType": "required",
|
| 46 |
+
"shape": [
|
| 47 |
+
-2
|
| 48 |
+
],
|
| 49 |
+
"format_match_mode": "FormatAgnostic"
|
| 50 |
+
},
|
| 51 |
+
{
|
| 52 |
+
"name": "sin",
|
| 53 |
+
"index": 4,
|
| 54 |
+
"dtype": "float16",
|
| 55 |
+
"format": "ND",
|
| 56 |
+
"paramType": "required",
|
| 57 |
+
"shape": [
|
| 58 |
+
-2
|
| 59 |
+
],
|
| 60 |
+
"format_match_mode": "FormatAgnostic"
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"name": "index",
|
| 64 |
+
"index": 5,
|
| 65 |
+
"dtype": "int64",
|
| 66 |
+
"format": "ND",
|
| 67 |
+
"paramType": "required",
|
| 68 |
+
"shape": [
|
| 69 |
+
-2
|
| 70 |
+
],
|
| 71 |
+
"format_match_mode": "FormatAgnostic"
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"name": "q_out",
|
| 75 |
+
"index": 6,
|
| 76 |
+
"dtype": "float16",
|
| 77 |
+
"format": "ND",
|
| 78 |
+
"paramType": "required",
|
| 79 |
+
"shape": [
|
| 80 |
+
-2
|
| 81 |
+
],
|
| 82 |
+
"format_match_mode": "FormatAgnostic"
|
| 83 |
+
},
|
| 84 |
+
{
|
| 85 |
+
"name": "k_cache",
|
| 86 |
+
"index": 7,
|
| 87 |
+
"dtype": "float16",
|
| 88 |
+
"format": "ND",
|
| 89 |
+
"paramType": "required",
|
| 90 |
+
"shape": [
|
| 91 |
+
-2
|
| 92 |
+
],
|
| 93 |
+
"format_match_mode": "FormatAgnostic"
|
| 94 |
+
},
|
| 95 |
+
{
|
| 96 |
+
"name": "v_cache",
|
| 97 |
+
"index": 8,
|
| 98 |
+
"dtype": "float16",
|
| 99 |
+
"format": "ND",
|
| 100 |
+
"paramType": "required",
|
| 101 |
+
"shape": [
|
| 102 |
+
-2
|
| 103 |
+
],
|
| 104 |
+
"format_match_mode": "FormatAgnostic"
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"name": "k_scale",
|
| 108 |
+
"index": 9,
|
| 109 |
+
"dtype": "float32",
|
| 110 |
+
"format": "ND",
|
| 111 |
+
"paramType": "optional",
|
| 112 |
+
"shape": [
|
| 113 |
+
-2
|
| 114 |
+
],
|
| 115 |
+
"format_match_mode": "FormatAgnostic"
|
| 116 |
+
},
|
| 117 |
+
{
|
| 118 |
+
"name": "v_scale",
|
| 119 |
+
"index": 10,
|
| 120 |
+
"dtype": "float32",
|
| 121 |
+
"format": "ND",
|
| 122 |
+
"paramType": "optional",
|
| 123 |
+
"shape": [
|
| 124 |
+
-2
|
| 125 |
+
],
|
| 126 |
+
"format_match_mode": "FormatAgnostic"
|
| 127 |
+
},
|
| 128 |
+
{
|
| 129 |
+
"name": "k_offset",
|
| 130 |
+
"index": 11,
|
| 131 |
+
"dtype": "float32",
|
| 132 |
+
"format": "ND",
|
| 133 |
+
"paramType": "optional",
|
| 134 |
+
"shape": [
|
| 135 |
+
-2
|
| 136 |
+
],
|
| 137 |
+
"format_match_mode": "FormatAgnostic"
|
| 138 |
+
},
|
| 139 |
+
{
|
| 140 |
+
"name": "v_offset",
|
| 141 |
+
"index": 12,
|
| 142 |
+
"dtype": "float32",
|
| 143 |
+
"format": "ND",
|
| 144 |
+
"paramType": "optional",
|
| 145 |
+
"shape": [
|
| 146 |
+
-2
|
| 147 |
+
],
|
| 148 |
+
"format_match_mode": "FormatAgnostic"
|
| 149 |
+
}
|
| 150 |
+
],
|
| 151 |
+
"outputs": [
|
| 152 |
+
{
|
| 153 |
+
"name": "q_out",
|
| 154 |
+
"index": 0,
|
| 155 |
+
"dtype": "float16",
|
| 156 |
+
"format": "ND",
|
| 157 |
+
"paramType": "required",
|
| 158 |
+
"shape": [
|
| 159 |
+
-2
|
| 160 |
+
],
|
| 161 |
+
"format_match_mode": "FormatAgnostic"
|
| 162 |
+
},
|
| 163 |
+
{
|
| 164 |
+
"name": "k_cache",
|
| 165 |
+
"index": 1,
|
| 166 |
+
"dtype": "float16",
|
| 167 |
+
"format": "ND",
|
| 168 |
+
"paramType": "required",
|
| 169 |
+
"shape": [
|
| 170 |
+
-2
|
| 171 |
+
],
|
| 172 |
+
"format_match_mode": "FormatAgnostic"
|
| 173 |
+
},
|
| 174 |
+
{
|
| 175 |
+
"name": "v_cache",
|
| 176 |
+
"index": 2,
|
| 177 |
+
"dtype": "float16",
|
| 178 |
+
"format": "ND",
|
| 179 |
+
"paramType": "required",
|
| 180 |
+
"shape": [
|
| 181 |
+
-2
|
| 182 |
+
],
|
| 183 |
+
"format_match_mode": "FormatAgnostic"
|
| 184 |
+
},
|
| 185 |
+
{
|
| 186 |
+
"name": "q_out_before_quant",
|
| 187 |
+
"index": 3,
|
| 188 |
+
"dtype": "float16",
|
| 189 |
+
"format": "ND",
|
| 190 |
+
"paramType": "required",
|
| 191 |
+
"shape": [
|
| 192 |
+
-2
|
| 193 |
+
],
|
| 194 |
+
"format_match_mode": "FormatAgnostic"
|
| 195 |
+
},
|
| 196 |
+
{
|
| 197 |
+
"name": "k_out_before_quant",
|
| 198 |
+
"index": 4,
|
| 199 |
+
"dtype": "float16",
|
| 200 |
+
"format": "ND",
|
| 201 |
+
"paramType": "required",
|
| 202 |
+
"shape": [
|
| 203 |
+
-2
|
| 204 |
+
],
|
| 205 |
+
"format_match_mode": "FormatAgnostic"
|
| 206 |
+
},
|
| 207 |
+
{
|
| 208 |
+
"name": "v_out_before_quant",
|
| 209 |
+
"index": 5,
|
| 210 |
+
"dtype": "float16",
|
| 211 |
+
"format": "ND",
|
| 212 |
+
"paramType": "required",
|
| 213 |
+
"shape": [
|
| 214 |
+
-2
|
| 215 |
+
],
|
| 216 |
+
"format_match_mode": "FormatAgnostic"
|
| 217 |
+
}
|
| 218 |
+
],
|
| 219 |
+
"attrs": [
|
| 220 |
+
{
|
| 221 |
+
"name": "qkv_size",
|
| 222 |
+
"dtype": "list_int",
|
| 223 |
+
"value": []
|
| 224 |
+
},
|
| 225 |
+
{
|
| 226 |
+
"name": "head_nums",
|
| 227 |
+
"dtype": "list_int",
|
| 228 |
+
"value": []
|
| 229 |
+
},
|
| 230 |
+
{
|
| 231 |
+
"name": "epsilon",
|
| 232 |
+
"dtype": "float",
|
| 233 |
+
"value": 0.000001
|
| 234 |
+
},
|
| 235 |
+
{
|
| 236 |
+
"name": "cache_mode",
|
| 237 |
+
"dtype": "string",
|
| 238 |
+
"value": "PA_NZ"
|
| 239 |
+
},
|
| 240 |
+
{
|
| 241 |
+
"name": "is_output_qkv",
|
| 242 |
+
"dtype": "bool",
|
| 243 |
+
"value": false
|
| 244 |
+
}
|
| 245 |
+
]
|
| 246 |
+
},
|
| 247 |
+
{
|
| 248 |
+
"bin_filename": "QkvRmsNormRopeCache_bf16",
|
| 249 |
+
"inputs": [
|
| 250 |
+
{
|
| 251 |
+
"name": "qkv",
|
| 252 |
+
"index": 0,
|
| 253 |
+
"dtype": "bfloat16",
|
| 254 |
+
"format": "ND",
|
| 255 |
+
"paramType": "required",
|
| 256 |
+
"shape": [
|
| 257 |
+
-2
|
| 258 |
+
],
|
| 259 |
+
"format_match_mode": "FormatAgnostic"
|
| 260 |
+
},
|
| 261 |
+
{
|
| 262 |
+
"name": "q_gamma",
|
| 263 |
+
"index": 1,
|
| 264 |
+
"dtype": "bfloat16",
|
| 265 |
+
"format": "ND",
|
| 266 |
+
"paramType": "required",
|
| 267 |
+
"shape": [
|
| 268 |
+
-2
|
| 269 |
+
],
|
| 270 |
+
"format_match_mode": "FormatAgnostic"
|
| 271 |
+
},
|
| 272 |
+
{
|
| 273 |
+
"name": "k_gamma",
|
| 274 |
+
"index": 2,
|
| 275 |
+
"dtype": "bfloat16",
|
| 276 |
+
"format": "ND",
|
| 277 |
+
"paramType": "required",
|
| 278 |
+
"shape": [
|
| 279 |
+
-2
|
| 280 |
+
],
|
| 281 |
+
"format_match_mode": "FormatAgnostic"
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"name": "cos",
|
| 285 |
+
"index": 3,
|
| 286 |
+
"dtype": "bfloat16",
|
| 287 |
+
"format": "ND",
|
| 288 |
+
"paramType": "required",
|
| 289 |
+
"shape": [
|
| 290 |
+
-2
|
| 291 |
+
],
|
| 292 |
+
"format_match_mode": "FormatAgnostic"
|
| 293 |
+
},
|
| 294 |
+
{
|
| 295 |
+
"name": "sin",
|
| 296 |
+
"index": 4,
|
| 297 |
+
"dtype": "bfloat16",
|
| 298 |
+
"format": "ND",
|
| 299 |
+
"paramType": "required",
|
| 300 |
+
"shape": [
|
| 301 |
+
-2
|
| 302 |
+
],
|
| 303 |
+
"format_match_mode": "FormatAgnostic"
|
| 304 |
+
},
|
| 305 |
+
{
|
| 306 |
+
"name": "index",
|
| 307 |
+
"index": 5,
|
| 308 |
+
"dtype": "int64",
|
| 309 |
+
"format": "ND",
|
| 310 |
+
"paramType": "required",
|
| 311 |
+
"shape": [
|
| 312 |
+
-2
|
| 313 |
+
],
|
| 314 |
+
"format_match_mode": "FormatAgnostic"
|
| 315 |
+
},
|
| 316 |
+
{
|
| 317 |
+
"name": "q_out",
|
| 318 |
+
"index": 6,
|
| 319 |
+
"dtype": "bfloat16",
|
| 320 |
+
"format": "ND",
|
| 321 |
+
"paramType": "required",
|
| 322 |
+
"shape": [
|
| 323 |
+
-2
|
| 324 |
+
],
|
| 325 |
+
"format_match_mode": "FormatAgnostic"
|
| 326 |
+
},
|
| 327 |
+
{
|
| 328 |
+
"name": "k_cache",
|
| 329 |
+
"index": 7,
|
| 330 |
+
"dtype": "bfloat16",
|
| 331 |
+
"format": "ND",
|
| 332 |
+
"paramType": "required",
|
| 333 |
+
"shape": [
|
| 334 |
+
-2
|
| 335 |
+
],
|
| 336 |
+
"format_match_mode": "FormatAgnostic"
|
| 337 |
+
},
|
| 338 |
+
{
|
| 339 |
+
"name": "v_cache",
|
| 340 |
+
"index": 8,
|
| 341 |
+
"dtype": "bfloat16",
|
| 342 |
+
"format": "ND",
|
| 343 |
+
"paramType": "required",
|
| 344 |
+
"shape": [
|
| 345 |
+
-2
|
| 346 |
+
],
|
| 347 |
+
"format_match_mode": "FormatAgnostic"
|
| 348 |
+
},
|
| 349 |
+
{
|
| 350 |
+
"name": "k_scale",
|
| 351 |
+
"index": 9,
|
| 352 |
+
"dtype": "float32",
|
| 353 |
+
"format": "ND",
|
| 354 |
+
"paramType": "optional",
|
| 355 |
+
"shape": [
|
| 356 |
+
-2
|
| 357 |
+
],
|
| 358 |
+
"format_match_mode": "FormatAgnostic"
|
| 359 |
+
},
|
| 360 |
+
{
|
| 361 |
+
"name": "v_scale",
|
| 362 |
+
"index": 10,
|
| 363 |
+
"dtype": "float32",
|
| 364 |
+
"format": "ND",
|
| 365 |
+
"paramType": "optional",
|
| 366 |
+
"shape": [
|
| 367 |
+
-2
|
| 368 |
+
],
|
| 369 |
+
"format_match_mode": "FormatAgnostic"
|
| 370 |
+
},
|
| 371 |
+
{
|
| 372 |
+
"name": "k_offset",
|
| 373 |
+
"index": 11,
|
| 374 |
+
"dtype": "float32",
|
| 375 |
+
"format": "ND",
|
| 376 |
+
"paramType": "optional",
|
| 377 |
+
"shape": [
|
| 378 |
+
-2
|
| 379 |
+
],
|
| 380 |
+
"format_match_mode": "FormatAgnostic"
|
| 381 |
+
},
|
| 382 |
+
{
|
| 383 |
+
"name": "v_offset",
|
| 384 |
+
"index": 12,
|
| 385 |
+
"dtype": "float32",
|
| 386 |
+
"format": "ND",
|
| 387 |
+
"paramType": "optional",
|
| 388 |
+
"shape": [
|
| 389 |
+
-2
|
| 390 |
+
],
|
| 391 |
+
"format_match_mode": "FormatAgnostic"
|
| 392 |
+
}
|
| 393 |
+
],
|
| 394 |
+
"outputs": [
|
| 395 |
+
{
|
| 396 |
+
"name": "q_out",
|
| 397 |
+
"index": 0,
|
| 398 |
+
"dtype": "bfloat16",
|
| 399 |
+
"format": "ND",
|
| 400 |
+
"paramType": "required",
|
| 401 |
+
"shape": [
|
| 402 |
+
-2
|
| 403 |
+
],
|
| 404 |
+
"format_match_mode": "FormatAgnostic"
|
| 405 |
+
},
|
| 406 |
+
{
|
| 407 |
+
"name": "k_cache",
|
| 408 |
+
"index": 1,
|
| 409 |
+
"dtype": "bfloat16",
|
| 410 |
+
"format": "ND",
|
| 411 |
+
"paramType": "required",
|
| 412 |
+
"shape": [
|
| 413 |
+
-2
|
| 414 |
+
],
|
| 415 |
+
"format_match_mode": "FormatAgnostic"
|
| 416 |
+
},
|
| 417 |
+
{
|
| 418 |
+
"name": "v_cache",
|
| 419 |
+
"index": 2,
|
| 420 |
+
"dtype": "bfloat16",
|
| 421 |
+
"format": "ND",
|
| 422 |
+
"paramType": "required",
|
| 423 |
+
"shape": [
|
| 424 |
+
-2
|
| 425 |
+
],
|
| 426 |
+
"format_match_mode": "FormatAgnostic"
|
| 427 |
+
},
|
| 428 |
+
{
|
| 429 |
+
"name": "q_out_before_quant",
|
| 430 |
+
"index": 3,
|
| 431 |
+
"dtype": "bfloat16",
|
| 432 |
+
"format": "ND",
|
| 433 |
+
"paramType": "required",
|
| 434 |
+
"shape": [
|
| 435 |
+
-2
|
| 436 |
+
],
|
| 437 |
+
"format_match_mode": "FormatAgnostic"
|
| 438 |
+
},
|
| 439 |
+
{
|
| 440 |
+
"name": "k_out_before_quant",
|
| 441 |
+
"index": 4,
|
| 442 |
+
"dtype": "bfloat16",
|
| 443 |
+
"format": "ND",
|
| 444 |
+
"paramType": "required",
|
| 445 |
+
"shape": [
|
| 446 |
+
-2
|
| 447 |
+
],
|
| 448 |
+
"format_match_mode": "FormatAgnostic"
|
| 449 |
+
},
|
| 450 |
+
{
|
| 451 |
+
"name": "v_out_before_quant",
|
| 452 |
+
"index": 5,
|
| 453 |
+
"dtype": "bfloat16",
|
| 454 |
+
"format": "ND",
|
| 455 |
+
"paramType": "required",
|
| 456 |
+
"shape": [
|
| 457 |
+
-2
|
| 458 |
+
],
|
| 459 |
+
"format_match_mode": "FormatAgnostic"
|
| 460 |
+
}
|
| 461 |
+
],
|
| 462 |
+
"attrs": [
|
| 463 |
+
{
|
| 464 |
+
"name": "qkv_size",
|
| 465 |
+
"dtype": "list_int",
|
| 466 |
+
"value": []
|
| 467 |
+
},
|
| 468 |
+
{
|
| 469 |
+
"name": "head_nums",
|
| 470 |
+
"dtype": "list_int",
|
| 471 |
+
"value": []
|
| 472 |
+
},
|
| 473 |
+
{
|
| 474 |
+
"name": "epsilon",
|
| 475 |
+
"dtype": "float",
|
| 476 |
+
"value": 0.000001
|
| 477 |
+
},
|
| 478 |
+
{
|
| 479 |
+
"name": "cache_mode",
|
| 480 |
+
"dtype": "string",
|
| 481 |
+
"value": "PA_NZ"
|
| 482 |
+
},
|
| 483 |
+
{
|
| 484 |
+
"name": "is_output_qkv",
|
| 485 |
+
"dtype": "bool",
|
| 486 |
+
"value": false
|
| 487 |
+
}
|
| 488 |
+
]
|
| 489 |
+
},
|
| 490 |
+
{
|
| 491 |
+
"bin_filename": "QkvRmsNormRopeCache_fp16_Kquant_Vquant",
|
| 492 |
+
"inputs": [
|
| 493 |
+
{
|
| 494 |
+
"name": "qkv",
|
| 495 |
+
"index": 0,
|
| 496 |
+
"dtype": "float16",
|
| 497 |
+
"format": "ND",
|
| 498 |
+
"paramType": "required",
|
| 499 |
+
"shape": [
|
| 500 |
+
-2
|
| 501 |
+
],
|
| 502 |
+
"format_match_mode": "FormatAgnostic"
|
| 503 |
+
},
|
| 504 |
+
{
|
| 505 |
+
"name": "q_gamma",
|
| 506 |
+
"index": 1,
|
| 507 |
+
"dtype": "float16",
|
| 508 |
+
"format": "ND",
|
| 509 |
+
"paramType": "required",
|
| 510 |
+
"shape": [
|
| 511 |
+
-2
|
| 512 |
+
],
|
| 513 |
+
"format_match_mode": "FormatAgnostic"
|
| 514 |
+
},
|
| 515 |
+
{
|
| 516 |
+
"name": "k_gamma",
|
| 517 |
+
"index": 2,
|
| 518 |
+
"dtype": "float16",
|
| 519 |
+
"format": "ND",
|
| 520 |
+
"paramType": "required",
|
| 521 |
+
"shape": [
|
| 522 |
+
-2
|
| 523 |
+
],
|
| 524 |
+
"format_match_mode": "FormatAgnostic"
|
| 525 |
+
},
|
| 526 |
+
{
|
| 527 |
+
"name": "cos",
|
| 528 |
+
"index": 3,
|
| 529 |
+
"dtype": "float16",
|
| 530 |
+
"format": "ND",
|
| 531 |
+
"paramType": "required",
|
| 532 |
+
"shape": [
|
| 533 |
+
-2
|
| 534 |
+
],
|
| 535 |
+
"format_match_mode": "FormatAgnostic"
|
| 536 |
+
},
|
| 537 |
+
{
|
| 538 |
+
"name": "sin",
|
| 539 |
+
"index": 4,
|
| 540 |
+
"dtype": "float16",
|
| 541 |
+
"format": "ND",
|
| 542 |
+
"paramType": "required",
|
| 543 |
+
"shape": [
|
| 544 |
+
-2
|
| 545 |
+
],
|
| 546 |
+
"format_match_mode": "FormatAgnostic"
|
| 547 |
+
},
|
| 548 |
+
{
|
| 549 |
+
"name": "index",
|
| 550 |
+
"index": 5,
|
| 551 |
+
"dtype": "int64",
|
| 552 |
+
"format": "ND",
|
| 553 |
+
"paramType": "required",
|
| 554 |
+
"shape": [
|
| 555 |
+
-2
|
| 556 |
+
],
|
| 557 |
+
"format_match_mode": "FormatAgnostic"
|
| 558 |
+
},
|
| 559 |
+
{
|
| 560 |
+
"name": "q_out",
|
| 561 |
+
"index": 6,
|
| 562 |
+
"dtype": "float16",
|
| 563 |
+
"format": "ND",
|
| 564 |
+
"paramType": "required",
|
| 565 |
+
"shape": [
|
| 566 |
+
-2
|
| 567 |
+
],
|
| 568 |
+
"format_match_mode": "FormatAgnostic"
|
| 569 |
+
},
|
| 570 |
+
{
|
| 571 |
+
"name": "k_cache",
|
| 572 |
+
"index": 7,
|
| 573 |
+
"dtype": "int8",
|
| 574 |
+
"format": "ND",
|
| 575 |
+
"paramType": "required",
|
| 576 |
+
"shape": [
|
| 577 |
+
-2
|
| 578 |
+
],
|
| 579 |
+
"format_match_mode": "FormatAgnostic"
|
| 580 |
+
},
|
| 581 |
+
{
|
| 582 |
+
"name": "v_cache",
|
| 583 |
+
"index": 8,
|
| 584 |
+
"dtype": "int8",
|
| 585 |
+
"format": "ND",
|
| 586 |
+
"paramType": "required",
|
| 587 |
+
"shape": [
|
| 588 |
+
-2
|
| 589 |
+
],
|
| 590 |
+
"format_match_mode": "FormatAgnostic"
|
| 591 |
+
},
|
| 592 |
+
{
|
| 593 |
+
"name": "k_scale",
|
| 594 |
+
"index": 9,
|
| 595 |
+
"dtype": "float32",
|
| 596 |
+
"format": "ND",
|
| 597 |
+
"paramType": "optional",
|
| 598 |
+
"shape": [
|
| 599 |
+
-2
|
| 600 |
+
],
|
| 601 |
+
"format_match_mode": "FormatAgnostic"
|
| 602 |
+
},
|
| 603 |
+
{
|
| 604 |
+
"name": "v_scale",
|
| 605 |
+
"index": 10,
|
| 606 |
+
"dtype": "float32",
|
| 607 |
+
"format": "ND",
|
| 608 |
+
"paramType": "optional",
|
| 609 |
+
"shape": [
|
| 610 |
+
-2
|
| 611 |
+
],
|
| 612 |
+
"format_match_mode": "FormatAgnostic"
|
| 613 |
+
},
|
| 614 |
+
{
|
| 615 |
+
"name": "k_offset",
|
| 616 |
+
"index": 11,
|
| 617 |
+
"dtype": "float32",
|
| 618 |
+
"format": "ND",
|
| 619 |
+
"paramType": "optional",
|
| 620 |
+
"shape": [
|
| 621 |
+
-2
|
| 622 |
+
],
|
| 623 |
+
"format_match_mode": "FormatAgnostic"
|
| 624 |
+
},
|
| 625 |
+
{
|
| 626 |
+
"name": "v_offset",
|
| 627 |
+
"index": 12,
|
| 628 |
+
"dtype": "float32",
|
| 629 |
+
"format": "ND",
|
| 630 |
+
"paramType": "optional",
|
| 631 |
+
"shape": [
|
| 632 |
+
-2
|
| 633 |
+
],
|
| 634 |
+
"format_match_mode": "FormatAgnostic"
|
| 635 |
+
}
|
| 636 |
+
],
|
| 637 |
+
"outputs": [
|
| 638 |
+
{
|
| 639 |
+
"name": "q_out",
|
| 640 |
+
"index": 0,
|
| 641 |
+
"dtype": "float16",
|
| 642 |
+
"format": "ND",
|
| 643 |
+
"paramType": "required",
|
| 644 |
+
"shape": [
|
| 645 |
+
-2
|
| 646 |
+
],
|
| 647 |
+
"format_match_mode": "FormatAgnostic"
|
| 648 |
+
},
|
| 649 |
+
{
|
| 650 |
+
"name": "k_cache",
|
| 651 |
+
"index": 1,
|
| 652 |
+
"dtype": "int8",
|
| 653 |
+
"format": "ND",
|
| 654 |
+
"paramType": "required",
|
| 655 |
+
"shape": [
|
| 656 |
+
-2
|
| 657 |
+
],
|
| 658 |
+
"format_match_mode": "FormatAgnostic"
|
| 659 |
+
},
|
| 660 |
+
{
|
| 661 |
+
"name": "v_cache",
|
| 662 |
+
"index": 2,
|
| 663 |
+
"dtype": "int8",
|
| 664 |
+
"format": "ND",
|
| 665 |
+
"paramType": "required",
|
| 666 |
+
"shape": [
|
| 667 |
+
-2
|
| 668 |
+
],
|
| 669 |
+
"format_match_mode": "FormatAgnostic"
|
| 670 |
+
},
|
| 671 |
+
{
|
| 672 |
+
"name": "q_out_before_quant",
|
| 673 |
+
"index": 3,
|
| 674 |
+
"dtype": "float16",
|
| 675 |
+
"format": "ND",
|
| 676 |
+
"paramType": "required",
|
| 677 |
+
"shape": [
|
| 678 |
+
-2
|
| 679 |
+
],
|
| 680 |
+
"format_match_mode": "FormatAgnostic"
|
| 681 |
+
},
|
| 682 |
+
{
|
| 683 |
+
"name": "k_out_before_quant",
|
| 684 |
+
"index": 4,
|
| 685 |
+
"dtype": "float16",
|
| 686 |
+
"format": "ND",
|
| 687 |
+
"paramType": "required",
|
| 688 |
+
"shape": [
|
| 689 |
+
-2
|
| 690 |
+
],
|
| 691 |
+
"format_match_mode": "FormatAgnostic"
|
| 692 |
+
},
|
| 693 |
+
{
|
| 694 |
+
"name": "v_out_before_quant",
|
| 695 |
+
"index": 5,
|
| 696 |
+
"dtype": "float16",
|
| 697 |
+
"format": "ND",
|
| 698 |
+
"paramType": "required",
|
| 699 |
+
"shape": [
|
| 700 |
+
-2
|
| 701 |
+
],
|
| 702 |
+
"format_match_mode": "FormatAgnostic"
|
| 703 |
+
}
|
| 704 |
+
],
|
| 705 |
+
"attrs": [
|
| 706 |
+
{
|
| 707 |
+
"name": "qkv_size",
|
| 708 |
+
"dtype": "list_int",
|
| 709 |
+
"value": []
|
| 710 |
+
},
|
| 711 |
+
{
|
| 712 |
+
"name": "head_nums",
|
| 713 |
+
"dtype": "list_int",
|
| 714 |
+
"value": []
|
| 715 |
+
},
|
| 716 |
+
{
|
| 717 |
+
"name": "epsilon",
|
| 718 |
+
"dtype": "float",
|
| 719 |
+
"value": 0.000001
|
| 720 |
+
},
|
| 721 |
+
{
|
| 722 |
+
"name": "cache_mode",
|
| 723 |
+
"dtype": "string",
|
| 724 |
+
"value": "PA_NZ"
|
| 725 |
+
},
|
| 726 |
+
{
|
| 727 |
+
"name": "is_output_qkv",
|
| 728 |
+
"dtype": "bool",
|
| 729 |
+
"value": false
|
| 730 |
+
}
|
| 731 |
+
]
|
| 732 |
+
},
|
| 733 |
+
{
|
| 734 |
+
"bin_filename": "QkvRmsNormRopeCache_bf16_Kquant_Vquant",
|
| 735 |
+
"inputs": [
|
| 736 |
+
{
|
| 737 |
+
"name": "qkv",
|
| 738 |
+
"index": 0,
|
| 739 |
+
"dtype": "bfloat16",
|
| 740 |
+
"format": "ND",
|
| 741 |
+
"paramType": "required",
|
| 742 |
+
"shape": [
|
| 743 |
+
-2
|
| 744 |
+
],
|
| 745 |
+
"format_match_mode": "FormatAgnostic"
|
| 746 |
+
},
|
| 747 |
+
{
|
| 748 |
+
"name": "q_gamma",
|
| 749 |
+
"index": 1,
|
| 750 |
+
"dtype": "bfloat16",
|
| 751 |
+
"format": "ND",
|
| 752 |
+
"paramType": "required",
|
| 753 |
+
"shape": [
|
| 754 |
+
-2
|
| 755 |
+
],
|
| 756 |
+
"format_match_mode": "FormatAgnostic"
|
| 757 |
+
},
|
| 758 |
+
{
|
| 759 |
+
"name": "k_gamma",
|
| 760 |
+
"index": 2,
|
| 761 |
+
"dtype": "bfloat16",
|
| 762 |
+
"format": "ND",
|
| 763 |
+
"paramType": "required",
|
| 764 |
+
"shape": [
|
| 765 |
+
-2
|
| 766 |
+
],
|
| 767 |
+
"format_match_mode": "FormatAgnostic"
|
| 768 |
+
},
|
| 769 |
+
{
|
| 770 |
+
"name": "cos",
|
| 771 |
+
"index": 3,
|
| 772 |
+
"dtype": "bfloat16",
|
| 773 |
+
"format": "ND",
|
| 774 |
+
"paramType": "required",
|
| 775 |
+
"shape": [
|
| 776 |
+
-2
|
| 777 |
+
],
|
| 778 |
+
"format_match_mode": "FormatAgnostic"
|
| 779 |
+
},
|
| 780 |
+
{
|
| 781 |
+
"name": "sin",
|
| 782 |
+
"index": 4,
|
| 783 |
+
"dtype": "bfloat16",
|
| 784 |
+
"format": "ND",
|
| 785 |
+
"paramType": "required",
|
| 786 |
+
"shape": [
|
| 787 |
+
-2
|
| 788 |
+
],
|
| 789 |
+
"format_match_mode": "FormatAgnostic"
|
| 790 |
+
},
|
| 791 |
+
{
|
| 792 |
+
"name": "index",
|
| 793 |
+
"index": 5,
|
| 794 |
+
"dtype": "int64",
|
| 795 |
+
"format": "ND",
|
| 796 |
+
"paramType": "required",
|
| 797 |
+
"shape": [
|
| 798 |
+
-2
|
| 799 |
+
],
|
| 800 |
+
"format_match_mode": "FormatAgnostic"
|
| 801 |
+
},
|
| 802 |
+
{
|
| 803 |
+
"name": "q_out",
|
| 804 |
+
"index": 6,
|
| 805 |
+
"dtype": "bfloat16",
|
| 806 |
+
"format": "ND",
|
| 807 |
+
"paramType": "required",
|
| 808 |
+
"shape": [
|
| 809 |
+
-2
|
| 810 |
+
],
|
| 811 |
+
"format_match_mode": "FormatAgnostic"
|
| 812 |
+
},
|
| 813 |
+
{
|
| 814 |
+
"name": "k_cache",
|
| 815 |
+
"index": 7,
|
| 816 |
+
"dtype": "int8",
|
| 817 |
+
"format": "ND",
|
| 818 |
+
"paramType": "required",
|
| 819 |
+
"shape": [
|
| 820 |
+
-2
|
| 821 |
+
],
|
| 822 |
+
"format_match_mode": "FormatAgnostic"
|
| 823 |
+
},
|
| 824 |
+
{
|
| 825 |
+
"name": "v_cache",
|
| 826 |
+
"index": 8,
|
| 827 |
+
"dtype": "int8",
|
| 828 |
+
"format": "ND",
|
| 829 |
+
"paramType": "required",
|
| 830 |
+
"shape": [
|
| 831 |
+
-2
|
| 832 |
+
],
|
| 833 |
+
"format_match_mode": "FormatAgnostic"
|
| 834 |
+
},
|
| 835 |
+
{
|
| 836 |
+
"name": "k_scale",
|
| 837 |
+
"index": 9,
|
| 838 |
+
"dtype": "float32",
|
| 839 |
+
"format": "ND",
|
| 840 |
+
"paramType": "optional",
|
| 841 |
+
"shape": [
|
| 842 |
+
-2
|
| 843 |
+
],
|
| 844 |
+
"format_match_mode": "FormatAgnostic"
|
| 845 |
+
},
|
| 846 |
+
{
|
| 847 |
+
"name": "v_scale",
|
| 848 |
+
"index": 10,
|
| 849 |
+
"dtype": "float32",
|
| 850 |
+
"format": "ND",
|
| 851 |
+
"paramType": "optional",
|
| 852 |
+
"shape": [
|
| 853 |
+
-2
|
| 854 |
+
],
|
| 855 |
+
"format_match_mode": "FormatAgnostic"
|
| 856 |
+
},
|
| 857 |
+
{
|
| 858 |
+
"name": "k_offset",
|
| 859 |
+
"index": 11,
|
| 860 |
+
"dtype": "float32",
|
| 861 |
+
"format": "ND",
|
| 862 |
+
"paramType": "optional",
|
| 863 |
+
"shape": [
|
| 864 |
+
-2
|
| 865 |
+
],
|
| 866 |
+
"format_match_mode": "FormatAgnostic"
|
| 867 |
+
},
|
| 868 |
+
{
|
| 869 |
+
"name": "v_offset",
|
| 870 |
+
"index": 12,
|
| 871 |
+
"dtype": "float32",
|
| 872 |
+
"format": "ND",
|
| 873 |
+
"paramType": "optional",
|
| 874 |
+
"shape": [
|
| 875 |
+
-2
|
| 876 |
+
],
|
| 877 |
+
"format_match_mode": "FormatAgnostic"
|
| 878 |
+
}
|
| 879 |
+
],
|
| 880 |
+
"outputs": [
|
| 881 |
+
{
|
| 882 |
+
"name": "q_out",
|
| 883 |
+
"index": 0,
|
| 884 |
+
"dtype": "bfloat16",
|
| 885 |
+
"format": "ND",
|
| 886 |
+
"paramType": "required",
|
| 887 |
+
"shape": [
|
| 888 |
+
-2
|
| 889 |
+
],
|
| 890 |
+
"format_match_mode": "FormatAgnostic"
|
| 891 |
+
},
|
| 892 |
+
{
|
| 893 |
+
"name": "k_cache",
|
| 894 |
+
"index": 1,
|
| 895 |
+
"dtype": "int8",
|
| 896 |
+
"format": "ND",
|
| 897 |
+
"paramType": "required",
|
| 898 |
+
"shape": [
|
| 899 |
+
-2
|
| 900 |
+
],
|
| 901 |
+
"format_match_mode": "FormatAgnostic"
|
| 902 |
+
},
|
| 903 |
+
{
|
| 904 |
+
"name": "v_cache",
|
| 905 |
+
"index": 2,
|
| 906 |
+
"dtype": "int8",
|
| 907 |
+
"format": "ND",
|
| 908 |
+
"paramType": "required",
|
| 909 |
+
"shape": [
|
| 910 |
+
-2
|
| 911 |
+
],
|
| 912 |
+
"format_match_mode": "FormatAgnostic"
|
| 913 |
+
},
|
| 914 |
+
{
|
| 915 |
+
"name": "q_out_before_quant",
|
| 916 |
+
"index": 3,
|
| 917 |
+
"dtype": "bfloat16",
|
| 918 |
+
"format": "ND",
|
| 919 |
+
"paramType": "required",
|
| 920 |
+
"shape": [
|
| 921 |
+
-2
|
| 922 |
+
],
|
| 923 |
+
"format_match_mode": "FormatAgnostic"
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
"name": "k_out_before_quant",
|
| 927 |
+
"index": 4,
|
| 928 |
+
"dtype": "bfloat16",
|
| 929 |
+
"format": "ND",
|
| 930 |
+
"paramType": "required",
|
| 931 |
+
"shape": [
|
| 932 |
+
-2
|
| 933 |
+
],
|
| 934 |
+
"format_match_mode": "FormatAgnostic"
|
| 935 |
+
},
|
| 936 |
+
{
|
| 937 |
+
"name": "v_out_before_quant",
|
| 938 |
+
"index": 5,
|
| 939 |
+
"dtype": "bfloat16",
|
| 940 |
+
"format": "ND",
|
| 941 |
+
"paramType": "required",
|
| 942 |
+
"shape": [
|
| 943 |
+
-2
|
| 944 |
+
],
|
| 945 |
+
"format_match_mode": "FormatAgnostic"
|
| 946 |
+
}
|
| 947 |
+
],
|
| 948 |
+
"attrs": [
|
| 949 |
+
{
|
| 950 |
+
"name": "qkv_size",
|
| 951 |
+
"dtype": "list_int",
|
| 952 |
+
"value": []
|
| 953 |
+
},
|
| 954 |
+
{
|
| 955 |
+
"name": "head_nums",
|
| 956 |
+
"dtype": "list_int",
|
| 957 |
+
"value": []
|
| 958 |
+
},
|
| 959 |
+
{
|
| 960 |
+
"name": "epsilon",
|
| 961 |
+
"dtype": "float",
|
| 962 |
+
"value": 0.000001
|
| 963 |
+
},
|
| 964 |
+
{
|
| 965 |
+
"name": "cache_mode",
|
| 966 |
+
"dtype": "string",
|
| 967 |
+
"value": "PA_NZ"
|
| 968 |
+
},
|
| 969 |
+
{
|
| 970 |
+
"name": "is_output_qkv",
|
| 971 |
+
"dtype": "bool",
|
| 972 |
+
"value": false
|
| 973 |
+
}
|
| 974 |
+
]
|
| 975 |
+
},
|
| 976 |
+
{
|
| 977 |
+
"bin_filename": "QkvRmsNormRopeCache_fp16_Kquant",
|
| 978 |
+
"inputs": [
|
| 979 |
+
{
|
| 980 |
+
"name": "qkv",
|
| 981 |
+
"index": 0,
|
| 982 |
+
"dtype": "float16",
|
| 983 |
+
"format": "ND",
|
| 984 |
+
"paramType": "required",
|
| 985 |
+
"shape": [
|
| 986 |
+
-2
|
| 987 |
+
],
|
| 988 |
+
"format_match_mode": "FormatAgnostic"
|
| 989 |
+
},
|
| 990 |
+
{
|
| 991 |
+
"name": "q_gamma",
|
| 992 |
+
"index": 1,
|
| 993 |
+
"dtype": "float16",
|
| 994 |
+
"format": "ND",
|
| 995 |
+
"paramType": "required",
|
| 996 |
+
"shape": [
|
| 997 |
+
-2
|
| 998 |
+
],
|
| 999 |
+
"format_match_mode": "FormatAgnostic"
|
| 1000 |
+
},
|
| 1001 |
+
{
|
| 1002 |
+
"name": "k_gamma",
|
| 1003 |
+
"index": 2,
|
| 1004 |
+
"dtype": "float16",
|
| 1005 |
+
"format": "ND",
|
| 1006 |
+
"paramType": "required",
|
| 1007 |
+
"shape": [
|
| 1008 |
+
-2
|
| 1009 |
+
],
|
| 1010 |
+
"format_match_mode": "FormatAgnostic"
|
| 1011 |
+
},
|
| 1012 |
+
{
|
| 1013 |
+
"name": "cos",
|
| 1014 |
+
"index": 3,
|
| 1015 |
+
"dtype": "float16",
|
| 1016 |
+
"format": "ND",
|
| 1017 |
+
"paramType": "required",
|
| 1018 |
+
"shape": [
|
| 1019 |
+
-2
|
| 1020 |
+
],
|
| 1021 |
+
"format_match_mode": "FormatAgnostic"
|
| 1022 |
+
},
|
| 1023 |
+
{
|
| 1024 |
+
"name": "sin",
|
| 1025 |
+
"index": 4,
|
| 1026 |
+
"dtype": "float16",
|
| 1027 |
+
"format": "ND",
|
| 1028 |
+
"paramType": "required",
|
| 1029 |
+
"shape": [
|
| 1030 |
+
-2
|
| 1031 |
+
],
|
| 1032 |
+
"format_match_mode": "FormatAgnostic"
|
| 1033 |
+
},
|
| 1034 |
+
{
|
| 1035 |
+
"name": "index",
|
| 1036 |
+
"index": 5,
|
| 1037 |
+
"dtype": "int64",
|
| 1038 |
+
"format": "ND",
|
| 1039 |
+
"paramType": "required",
|
| 1040 |
+
"shape": [
|
| 1041 |
+
-2
|
| 1042 |
+
],
|
| 1043 |
+
"format_match_mode": "FormatAgnostic"
|
| 1044 |
+
},
|
| 1045 |
+
{
|
| 1046 |
+
"name": "q_out",
|
| 1047 |
+
"index": 6,
|
| 1048 |
+
"dtype": "float16",
|
| 1049 |
+
"format": "ND",
|
| 1050 |
+
"paramType": "required",
|
| 1051 |
+
"shape": [
|
| 1052 |
+
-2
|
| 1053 |
+
],
|
| 1054 |
+
"format_match_mode": "FormatAgnostic"
|
| 1055 |
+
},
|
| 1056 |
+
{
|
| 1057 |
+
"name": "k_cache",
|
| 1058 |
+
"index": 7,
|
| 1059 |
+
"dtype": "int8",
|
| 1060 |
+
"format": "ND",
|
| 1061 |
+
"paramType": "required",
|
| 1062 |
+
"shape": [
|
| 1063 |
+
-2
|
| 1064 |
+
],
|
| 1065 |
+
"format_match_mode": "FormatAgnostic"
|
| 1066 |
+
},
|
| 1067 |
+
{
|
| 1068 |
+
"name": "v_cache",
|
| 1069 |
+
"index": 8,
|
| 1070 |
+
"dtype": "float16",
|
| 1071 |
+
"format": "ND",
|
| 1072 |
+
"paramType": "required",
|
| 1073 |
+
"shape": [
|
| 1074 |
+
-2
|
| 1075 |
+
],
|
| 1076 |
+
"format_match_mode": "FormatAgnostic"
|
| 1077 |
+
},
|
| 1078 |
+
{
|
| 1079 |
+
"name": "k_scale",
|
| 1080 |
+
"index": 9,
|
| 1081 |
+
"dtype": "float32",
|
| 1082 |
+
"format": "ND",
|
| 1083 |
+
"paramType": "optional",
|
| 1084 |
+
"shape": [
|
| 1085 |
+
-2
|
| 1086 |
+
],
|
| 1087 |
+
"format_match_mode": "FormatAgnostic"
|
| 1088 |
+
},
|
| 1089 |
+
{
|
| 1090 |
+
"name": "v_scale",
|
| 1091 |
+
"index": 10,
|
| 1092 |
+
"dtype": "float32",
|
| 1093 |
+
"format": "ND",
|
| 1094 |
+
"paramType": "optional",
|
| 1095 |
+
"shape": [
|
| 1096 |
+
-2
|
| 1097 |
+
],
|
| 1098 |
+
"format_match_mode": "FormatAgnostic"
|
| 1099 |
+
},
|
| 1100 |
+
{
|
| 1101 |
+
"name": "k_offset",
|
| 1102 |
+
"index": 11,
|
| 1103 |
+
"dtype": "float32",
|
| 1104 |
+
"format": "ND",
|
| 1105 |
+
"paramType": "optional",
|
| 1106 |
+
"shape": [
|
| 1107 |
+
-2
|
| 1108 |
+
],
|
| 1109 |
+
"format_match_mode": "FormatAgnostic"
|
| 1110 |
+
},
|
| 1111 |
+
{
|
| 1112 |
+
"name": "v_offset",
|
| 1113 |
+
"index": 12,
|
| 1114 |
+
"dtype": "float32",
|
| 1115 |
+
"format": "ND",
|
| 1116 |
+
"paramType": "optional",
|
| 1117 |
+
"shape": [
|
| 1118 |
+
-2
|
| 1119 |
+
],
|
| 1120 |
+
"format_match_mode": "FormatAgnostic"
|
| 1121 |
+
}
|
| 1122 |
+
],
|
| 1123 |
+
"outputs": [
|
| 1124 |
+
{
|
| 1125 |
+
"name": "q_out",
|
| 1126 |
+
"index": 0,
|
| 1127 |
+
"dtype": "float16",
|
| 1128 |
+
"format": "ND",
|
| 1129 |
+
"paramType": "required",
|
| 1130 |
+
"shape": [
|
| 1131 |
+
-2
|
| 1132 |
+
],
|
| 1133 |
+
"format_match_mode": "FormatAgnostic"
|
| 1134 |
+
},
|
| 1135 |
+
{
|
| 1136 |
+
"name": "k_cache",
|
| 1137 |
+
"index": 1,
|
| 1138 |
+
"dtype": "int8",
|
| 1139 |
+
"format": "ND",
|
| 1140 |
+
"paramType": "required",
|
| 1141 |
+
"shape": [
|
| 1142 |
+
-2
|
| 1143 |
+
],
|
| 1144 |
+
"format_match_mode": "FormatAgnostic"
|
| 1145 |
+
},
|
| 1146 |
+
{
|
| 1147 |
+
"name": "v_cache",
|
| 1148 |
+
"index": 2,
|
| 1149 |
+
"dtype": "float16",
|
| 1150 |
+
"format": "ND",
|
| 1151 |
+
"paramType": "required",
|
| 1152 |
+
"shape": [
|
| 1153 |
+
-2
|
| 1154 |
+
],
|
| 1155 |
+
"format_match_mode": "FormatAgnostic"
|
| 1156 |
+
},
|
| 1157 |
+
{
|
| 1158 |
+
"name": "q_out_before_quant",
|
| 1159 |
+
"index": 3,
|
| 1160 |
+
"dtype": "float16",
|
| 1161 |
+
"format": "ND",
|
| 1162 |
+
"paramType": "required",
|
| 1163 |
+
"shape": [
|
| 1164 |
+
-2
|
| 1165 |
+
],
|
| 1166 |
+
"format_match_mode": "FormatAgnostic"
|
| 1167 |
+
},
|
| 1168 |
+
{
|
| 1169 |
+
"name": "k_out_before_quant",
|
| 1170 |
+
"index": 4,
|
| 1171 |
+
"dtype": "float16",
|
| 1172 |
+
"format": "ND",
|
| 1173 |
+
"paramType": "required",
|
| 1174 |
+
"shape": [
|
| 1175 |
+
-2
|
| 1176 |
+
],
|
| 1177 |
+
"format_match_mode": "FormatAgnostic"
|
| 1178 |
+
},
|
| 1179 |
+
{
|
| 1180 |
+
"name": "v_out_before_quant",
|
| 1181 |
+
"index": 5,
|
| 1182 |
+
"dtype": "float16",
|
| 1183 |
+
"format": "ND",
|
| 1184 |
+
"paramType": "required",
|
| 1185 |
+
"shape": [
|
| 1186 |
+
-2
|
| 1187 |
+
],
|
| 1188 |
+
"format_match_mode": "FormatAgnostic"
|
| 1189 |
+
}
|
| 1190 |
+
],
|
| 1191 |
+
"attrs": [
|
| 1192 |
+
{
|
| 1193 |
+
"name": "qkv_size",
|
| 1194 |
+
"dtype": "list_int",
|
| 1195 |
+
"value": []
|
| 1196 |
+
},
|
| 1197 |
+
{
|
| 1198 |
+
"name": "head_nums",
|
| 1199 |
+
"dtype": "list_int",
|
| 1200 |
+
"value": []
|
| 1201 |
+
},
|
| 1202 |
+
{
|
| 1203 |
+
"name": "epsilon",
|
| 1204 |
+
"dtype": "float",
|
| 1205 |
+
"value": 0.000001
|
| 1206 |
+
},
|
| 1207 |
+
{
|
| 1208 |
+
"name": "cache_mode",
|
| 1209 |
+
"dtype": "string",
|
| 1210 |
+
"value": "PA_NZ"
|
| 1211 |
+
},
|
| 1212 |
+
{
|
| 1213 |
+
"name": "is_output_qkv",
|
| 1214 |
+
"dtype": "bool",
|
| 1215 |
+
"value": false
|
| 1216 |
+
}
|
| 1217 |
+
]
|
| 1218 |
+
},
|
| 1219 |
+
{
|
| 1220 |
+
"bin_filename": "QkvRmsNormRopeCache_bf16_Kquant",
|
| 1221 |
+
"inputs": [
|
| 1222 |
+
{
|
| 1223 |
+
"name": "qkv",
|
| 1224 |
+
"index": 0,
|
| 1225 |
+
"dtype": "bfloat16",
|
| 1226 |
+
"format": "ND",
|
| 1227 |
+
"paramType": "required",
|
| 1228 |
+
"shape": [
|
| 1229 |
+
-2
|
| 1230 |
+
],
|
| 1231 |
+
"format_match_mode": "FormatAgnostic"
|
| 1232 |
+
},
|
| 1233 |
+
{
|
| 1234 |
+
"name": "q_gamma",
|
| 1235 |
+
"index": 1,
|
| 1236 |
+
"dtype": "bfloat16",
|
| 1237 |
+
"format": "ND",
|
| 1238 |
+
"paramType": "required",
|
| 1239 |
+
"shape": [
|
| 1240 |
+
-2
|
| 1241 |
+
],
|
| 1242 |
+
"format_match_mode": "FormatAgnostic"
|
| 1243 |
+
},
|
| 1244 |
+
{
|
| 1245 |
+
"name": "k_gamma",
|
| 1246 |
+
"index": 2,
|
| 1247 |
+
"dtype": "bfloat16",
|
| 1248 |
+
"format": "ND",
|
| 1249 |
+
"paramType": "required",
|
| 1250 |
+
"shape": [
|
| 1251 |
+
-2
|
| 1252 |
+
],
|
| 1253 |
+
"format_match_mode": "FormatAgnostic"
|
| 1254 |
+
},
|
| 1255 |
+
{
|
| 1256 |
+
"name": "cos",
|
| 1257 |
+
"index": 3,
|
| 1258 |
+
"dtype": "bfloat16",
|
| 1259 |
+
"format": "ND",
|
| 1260 |
+
"paramType": "required",
|
| 1261 |
+
"shape": [
|
| 1262 |
+
-2
|
| 1263 |
+
],
|
| 1264 |
+
"format_match_mode": "FormatAgnostic"
|
| 1265 |
+
},
|
| 1266 |
+
{
|
| 1267 |
+
"name": "sin",
|
| 1268 |
+
"index": 4,
|
| 1269 |
+
"dtype": "bfloat16",
|
| 1270 |
+
"format": "ND",
|
| 1271 |
+
"paramType": "required",
|
| 1272 |
+
"shape": [
|
| 1273 |
+
-2
|
| 1274 |
+
],
|
| 1275 |
+
"format_match_mode": "FormatAgnostic"
|
| 1276 |
+
},
|
| 1277 |
+
{
|
| 1278 |
+
"name": "index",
|
| 1279 |
+
"index": 5,
|
| 1280 |
+
"dtype": "int64",
|
| 1281 |
+
"format": "ND",
|
| 1282 |
+
"paramType": "required",
|
| 1283 |
+
"shape": [
|
| 1284 |
+
-2
|
| 1285 |
+
],
|
| 1286 |
+
"format_match_mode": "FormatAgnostic"
|
| 1287 |
+
},
|
| 1288 |
+
{
|
| 1289 |
+
"name": "q_out",
|
| 1290 |
+
"index": 6,
|
| 1291 |
+
"dtype": "bfloat16",
|
| 1292 |
+
"format": "ND",
|
| 1293 |
+
"paramType": "required",
|
| 1294 |
+
"shape": [
|
| 1295 |
+
-2
|
| 1296 |
+
],
|
| 1297 |
+
"format_match_mode": "FormatAgnostic"
|
| 1298 |
+
},
|
| 1299 |
+
{
|
| 1300 |
+
"name": "k_cache",
|
| 1301 |
+
"index": 7,
|
| 1302 |
+
"dtype": "int8",
|
| 1303 |
+
"format": "ND",
|
| 1304 |
+
"paramType": "required",
|
| 1305 |
+
"shape": [
|
| 1306 |
+
-2
|
| 1307 |
+
],
|
| 1308 |
+
"format_match_mode": "FormatAgnostic"
|
| 1309 |
+
},
|
| 1310 |
+
{
|
| 1311 |
+
"name": "v_cache",
|
| 1312 |
+
"index": 8,
|
| 1313 |
+
"dtype": "bfloat16",
|
| 1314 |
+
"format": "ND",
|
| 1315 |
+
"paramType": "required",
|
| 1316 |
+
"shape": [
|
| 1317 |
+
-2
|
| 1318 |
+
],
|
| 1319 |
+
"format_match_mode": "FormatAgnostic"
|
| 1320 |
+
},
|
| 1321 |
+
{
|
| 1322 |
+
"name": "k_scale",
|
| 1323 |
+
"index": 9,
|
| 1324 |
+
"dtype": "float32",
|
| 1325 |
+
"format": "ND",
|
| 1326 |
+
"paramType": "optional",
|
| 1327 |
+
"shape": [
|
| 1328 |
+
-2
|
| 1329 |
+
],
|
| 1330 |
+
"format_match_mode": "FormatAgnostic"
|
| 1331 |
+
},
|
| 1332 |
+
{
|
| 1333 |
+
"name": "v_scale",
|
| 1334 |
+
"index": 10,
|
| 1335 |
+
"dtype": "float32",
|
| 1336 |
+
"format": "ND",
|
| 1337 |
+
"paramType": "optional",
|
| 1338 |
+
"shape": [
|
| 1339 |
+
-2
|
| 1340 |
+
],
|
| 1341 |
+
"format_match_mode": "FormatAgnostic"
|
| 1342 |
+
},
|
| 1343 |
+
{
|
| 1344 |
+
"name": "k_offset",
|
| 1345 |
+
"index": 11,
|
| 1346 |
+
"dtype": "float32",
|
| 1347 |
+
"format": "ND",
|
| 1348 |
+
"paramType": "optional",
|
| 1349 |
+
"shape": [
|
| 1350 |
+
-2
|
| 1351 |
+
],
|
| 1352 |
+
"format_match_mode": "FormatAgnostic"
|
| 1353 |
+
},
|
| 1354 |
+
{
|
| 1355 |
+
"name": "v_offset",
|
| 1356 |
+
"index": 12,
|
| 1357 |
+
"dtype": "float32",
|
| 1358 |
+
"format": "ND",
|
| 1359 |
+
"paramType": "optional",
|
| 1360 |
+
"shape": [
|
| 1361 |
+
-2
|
| 1362 |
+
],
|
| 1363 |
+
"format_match_mode": "FormatAgnostic"
|
| 1364 |
+
}
|
| 1365 |
+
],
|
| 1366 |
+
"outputs": [
|
| 1367 |
+
{
|
| 1368 |
+
"name": "q_out",
|
| 1369 |
+
"index": 0,
|
| 1370 |
+
"dtype": "bfloat16",
|
| 1371 |
+
"format": "ND",
|
| 1372 |
+
"paramType": "required",
|
| 1373 |
+
"shape": [
|
| 1374 |
+
-2
|
| 1375 |
+
],
|
| 1376 |
+
"format_match_mode": "FormatAgnostic"
|
| 1377 |
+
},
|
| 1378 |
+
{
|
| 1379 |
+
"name": "k_cache",
|
| 1380 |
+
"index": 1,
|
| 1381 |
+
"dtype": "int8",
|
| 1382 |
+
"format": "ND",
|
| 1383 |
+
"paramType": "required",
|
| 1384 |
+
"shape": [
|
| 1385 |
+
-2
|
| 1386 |
+
],
|
| 1387 |
+
"format_match_mode": "FormatAgnostic"
|
| 1388 |
+
},
|
| 1389 |
+
{
|
| 1390 |
+
"name": "v_cache",
|
| 1391 |
+
"index": 2,
|
| 1392 |
+
"dtype": "bfloat16",
|
| 1393 |
+
"format": "ND",
|
| 1394 |
+
"paramType": "required",
|
| 1395 |
+
"shape": [
|
| 1396 |
+
-2
|
| 1397 |
+
],
|
| 1398 |
+
"format_match_mode": "FormatAgnostic"
|
| 1399 |
+
},
|
| 1400 |
+
{
|
| 1401 |
+
"name": "q_out_before_quant",
|
| 1402 |
+
"index": 3,
|
| 1403 |
+
"dtype": "bfloat16",
|
| 1404 |
+
"format": "ND",
|
| 1405 |
+
"paramType": "required",
|
| 1406 |
+
"shape": [
|
| 1407 |
+
-2
|
| 1408 |
+
],
|
| 1409 |
+
"format_match_mode": "FormatAgnostic"
|
| 1410 |
+
},
|
| 1411 |
+
{
|
| 1412 |
+
"name": "k_out_before_quant",
|
| 1413 |
+
"index": 4,
|
| 1414 |
+
"dtype": "bfloat16",
|
| 1415 |
+
"format": "ND",
|
| 1416 |
+
"paramType": "required",
|
| 1417 |
+
"shape": [
|
| 1418 |
+
-2
|
| 1419 |
+
],
|
| 1420 |
+
"format_match_mode": "FormatAgnostic"
|
| 1421 |
+
},
|
| 1422 |
+
{
|
| 1423 |
+
"name": "v_out_before_quant",
|
| 1424 |
+
"index": 5,
|
| 1425 |
+
"dtype": "bfloat16",
|
| 1426 |
+
"format": "ND",
|
| 1427 |
+
"paramType": "required",
|
| 1428 |
+
"shape": [
|
| 1429 |
+
-2
|
| 1430 |
+
],
|
| 1431 |
+
"format_match_mode": "FormatAgnostic"
|
| 1432 |
+
}
|
| 1433 |
+
],
|
| 1434 |
+
"attrs": [
|
| 1435 |
+
{
|
| 1436 |
+
"name": "qkv_size",
|
| 1437 |
+
"dtype": "list_int",
|
| 1438 |
+
"value": []
|
| 1439 |
+
},
|
| 1440 |
+
{
|
| 1441 |
+
"name": "head_nums",
|
| 1442 |
+
"dtype": "list_int",
|
| 1443 |
+
"value": []
|
| 1444 |
+
},
|
| 1445 |
+
{
|
| 1446 |
+
"name": "epsilon",
|
| 1447 |
+
"dtype": "float",
|
| 1448 |
+
"value": 0.000001
|
| 1449 |
+
},
|
| 1450 |
+
{
|
| 1451 |
+
"name": "cache_mode",
|
| 1452 |
+
"dtype": "string",
|
| 1453 |
+
"value": "PA_NZ"
|
| 1454 |
+
},
|
| 1455 |
+
{
|
| 1456 |
+
"name": "is_output_qkv",
|
| 1457 |
+
"dtype": "bool",
|
| 1458 |
+
"value": false
|
| 1459 |
+
}
|
| 1460 |
+
]
|
| 1461 |
+
},
|
| 1462 |
+
{
|
| 1463 |
+
"bin_filename": "QkvRmsNormRopeCache_fp16_Vquant",
|
| 1464 |
+
"inputs": [
|
| 1465 |
+
{
|
| 1466 |
+
"name": "qkv",
|
| 1467 |
+
"index": 0,
|
| 1468 |
+
"dtype": "float16",
|
| 1469 |
+
"format": "ND",
|
| 1470 |
+
"paramType": "required",
|
| 1471 |
+
"shape": [
|
| 1472 |
+
-2
|
| 1473 |
+
],
|
| 1474 |
+
"format_match_mode": "FormatAgnostic"
|
| 1475 |
+
},
|
| 1476 |
+
{
|
| 1477 |
+
"name": "q_gamma",
|
| 1478 |
+
"index": 1,
|
| 1479 |
+
"dtype": "float16",
|
| 1480 |
+
"format": "ND",
|
| 1481 |
+
"paramType": "required",
|
| 1482 |
+
"shape": [
|
| 1483 |
+
-2
|
| 1484 |
+
],
|
| 1485 |
+
"format_match_mode": "FormatAgnostic"
|
| 1486 |
+
},
|
| 1487 |
+
{
|
| 1488 |
+
"name": "k_gamma",
|
| 1489 |
+
"index": 2,
|
| 1490 |
+
"dtype": "float16",
|
| 1491 |
+
"format": "ND",
|
| 1492 |
+
"paramType": "required",
|
| 1493 |
+
"shape": [
|
| 1494 |
+
-2
|
| 1495 |
+
],
|
| 1496 |
+
"format_match_mode": "FormatAgnostic"
|
| 1497 |
+
},
|
| 1498 |
+
{
|
| 1499 |
+
"name": "cos",
|
| 1500 |
+
"index": 3,
|
| 1501 |
+
"dtype": "float16",
|
| 1502 |
+
"format": "ND",
|
| 1503 |
+
"paramType": "required",
|
| 1504 |
+
"shape": [
|
| 1505 |
+
-2
|
| 1506 |
+
],
|
| 1507 |
+
"format_match_mode": "FormatAgnostic"
|
| 1508 |
+
},
|
| 1509 |
+
{
|
| 1510 |
+
"name": "sin",
|
| 1511 |
+
"index": 4,
|
| 1512 |
+
"dtype": "float16",
|
| 1513 |
+
"format": "ND",
|
| 1514 |
+
"paramType": "required",
|
| 1515 |
+
"shape": [
|
| 1516 |
+
-2
|
| 1517 |
+
],
|
| 1518 |
+
"format_match_mode": "FormatAgnostic"
|
| 1519 |
+
},
|
| 1520 |
+
{
|
| 1521 |
+
"name": "index",
|
| 1522 |
+
"index": 5,
|
| 1523 |
+
"dtype": "int64",
|
| 1524 |
+
"format": "ND",
|
| 1525 |
+
"paramType": "required",
|
| 1526 |
+
"shape": [
|
| 1527 |
+
-2
|
| 1528 |
+
],
|
| 1529 |
+
"format_match_mode": "FormatAgnostic"
|
| 1530 |
+
},
|
| 1531 |
+
{
|
| 1532 |
+
"name": "q_out",
|
| 1533 |
+
"index": 6,
|
| 1534 |
+
"dtype": "float16",
|
| 1535 |
+
"format": "ND",
|
| 1536 |
+
"paramType": "required",
|
| 1537 |
+
"shape": [
|
| 1538 |
+
-2
|
| 1539 |
+
],
|
| 1540 |
+
"format_match_mode": "FormatAgnostic"
|
| 1541 |
+
},
|
| 1542 |
+
{
|
| 1543 |
+
"name": "k_cache",
|
| 1544 |
+
"index": 7,
|
| 1545 |
+
"dtype": "float16",
|
| 1546 |
+
"format": "ND",
|
| 1547 |
+
"paramType": "required",
|
| 1548 |
+
"shape": [
|
| 1549 |
+
-2
|
| 1550 |
+
],
|
| 1551 |
+
"format_match_mode": "FormatAgnostic"
|
| 1552 |
+
},
|
| 1553 |
+
{
|
| 1554 |
+
"name": "v_cache",
|
| 1555 |
+
"index": 8,
|
| 1556 |
+
"dtype": "int8",
|
| 1557 |
+
"format": "ND",
|
| 1558 |
+
"paramType": "required",
|
| 1559 |
+
"shape": [
|
| 1560 |
+
-2
|
| 1561 |
+
],
|
| 1562 |
+
"format_match_mode": "FormatAgnostic"
|
| 1563 |
+
},
|
| 1564 |
+
{
|
| 1565 |
+
"name": "k_scale",
|
| 1566 |
+
"index": 9,
|
| 1567 |
+
"dtype": "float32",
|
| 1568 |
+
"format": "ND",
|
| 1569 |
+
"paramType": "optional",
|
| 1570 |
+
"shape": [
|
| 1571 |
+
-2
|
| 1572 |
+
],
|
| 1573 |
+
"format_match_mode": "FormatAgnostic"
|
| 1574 |
+
},
|
| 1575 |
+
{
|
| 1576 |
+
"name": "v_scale",
|
| 1577 |
+
"index": 10,
|
| 1578 |
+
"dtype": "float32",
|
| 1579 |
+
"format": "ND",
|
| 1580 |
+
"paramType": "optional",
|
| 1581 |
+
"shape": [
|
| 1582 |
+
-2
|
| 1583 |
+
],
|
| 1584 |
+
"format_match_mode": "FormatAgnostic"
|
| 1585 |
+
},
|
| 1586 |
+
{
|
| 1587 |
+
"name": "k_offset",
|
| 1588 |
+
"index": 11,
|
| 1589 |
+
"dtype": "float32",
|
| 1590 |
+
"format": "ND",
|
| 1591 |
+
"paramType": "optional",
|
| 1592 |
+
"shape": [
|
| 1593 |
+
-2
|
| 1594 |
+
],
|
| 1595 |
+
"format_match_mode": "FormatAgnostic"
|
| 1596 |
+
},
|
| 1597 |
+
{
|
| 1598 |
+
"name": "v_offset",
|
| 1599 |
+
"index": 12,
|
| 1600 |
+
"dtype": "float32",
|
| 1601 |
+
"format": "ND",
|
| 1602 |
+
"paramType": "optional",
|
| 1603 |
+
"shape": [
|
| 1604 |
+
-2
|
| 1605 |
+
],
|
| 1606 |
+
"format_match_mode": "FormatAgnostic"
|
| 1607 |
+
}
|
| 1608 |
+
],
|
| 1609 |
+
"outputs": [
|
| 1610 |
+
{
|
| 1611 |
+
"name": "q_out",
|
| 1612 |
+
"index": 0,
|
| 1613 |
+
"dtype": "float16",
|
| 1614 |
+
"format": "ND",
|
| 1615 |
+
"paramType": "required",
|
| 1616 |
+
"shape": [
|
| 1617 |
+
-2
|
| 1618 |
+
],
|
| 1619 |
+
"format_match_mode": "FormatAgnostic"
|
| 1620 |
+
},
|
| 1621 |
+
{
|
| 1622 |
+
"name": "k_cache",
|
| 1623 |
+
"index": 1,
|
| 1624 |
+
"dtype": "float16",
|
| 1625 |
+
"format": "ND",
|
| 1626 |
+
"paramType": "required",
|
| 1627 |
+
"shape": [
|
| 1628 |
+
-2
|
| 1629 |
+
],
|
| 1630 |
+
"format_match_mode": "FormatAgnostic"
|
| 1631 |
+
},
|
| 1632 |
+
{
|
| 1633 |
+
"name": "v_cache",
|
| 1634 |
+
"index": 2,
|
| 1635 |
+
"dtype": "int8",
|
| 1636 |
+
"format": "ND",
|
| 1637 |
+
"paramType": "required",
|
| 1638 |
+
"shape": [
|
| 1639 |
+
-2
|
| 1640 |
+
],
|
| 1641 |
+
"format_match_mode": "FormatAgnostic"
|
| 1642 |
+
},
|
| 1643 |
+
{
|
| 1644 |
+
"name": "q_out_before_quant",
|
| 1645 |
+
"index": 3,
|
| 1646 |
+
"dtype": "float16",
|
| 1647 |
+
"format": "ND",
|
| 1648 |
+
"paramType": "required",
|
| 1649 |
+
"shape": [
|
| 1650 |
+
-2
|
| 1651 |
+
],
|
| 1652 |
+
"format_match_mode": "FormatAgnostic"
|
| 1653 |
+
},
|
| 1654 |
+
{
|
| 1655 |
+
"name": "k_out_before_quant",
|
| 1656 |
+
"index": 4,
|
| 1657 |
+
"dtype": "float16",
|
| 1658 |
+
"format": "ND",
|
| 1659 |
+
"paramType": "required",
|
| 1660 |
+
"shape": [
|
| 1661 |
+
-2
|
| 1662 |
+
],
|
| 1663 |
+
"format_match_mode": "FormatAgnostic"
|
| 1664 |
+
},
|
| 1665 |
+
{
|
| 1666 |
+
"name": "v_out_before_quant",
|
| 1667 |
+
"index": 5,
|
| 1668 |
+
"dtype": "float16",
|
| 1669 |
+
"format": "ND",
|
| 1670 |
+
"paramType": "required",
|
| 1671 |
+
"shape": [
|
| 1672 |
+
-2
|
| 1673 |
+
],
|
| 1674 |
+
"format_match_mode": "FormatAgnostic"
|
| 1675 |
+
}
|
| 1676 |
+
],
|
| 1677 |
+
"attrs": [
|
| 1678 |
+
{
|
| 1679 |
+
"name": "qkv_size",
|
| 1680 |
+
"dtype": "list_int",
|
| 1681 |
+
"value": []
|
| 1682 |
+
},
|
| 1683 |
+
{
|
| 1684 |
+
"name": "head_nums",
|
| 1685 |
+
"dtype": "list_int",
|
| 1686 |
+
"value": []
|
| 1687 |
+
},
|
| 1688 |
+
{
|
| 1689 |
+
"name": "epsilon",
|
| 1690 |
+
"dtype": "float",
|
| 1691 |
+
"value": 0.000001
|
| 1692 |
+
},
|
| 1693 |
+
{
|
| 1694 |
+
"name": "cache_mode",
|
| 1695 |
+
"dtype": "string",
|
| 1696 |
+
"value": "PA_NZ"
|
| 1697 |
+
},
|
| 1698 |
+
{
|
| 1699 |
+
"name": "is_output_qkv",
|
| 1700 |
+
"dtype": "bool",
|
| 1701 |
+
"value": false
|
| 1702 |
+
}
|
| 1703 |
+
]
|
| 1704 |
+
},
|
| 1705 |
+
{
|
| 1706 |
+
"bin_filename": "QkvRmsNormRopeCache_bf16_Vquant",
|
| 1707 |
+
"inputs": [
|
| 1708 |
+
{
|
| 1709 |
+
"name": "qkv",
|
| 1710 |
+
"index": 0,
|
| 1711 |
+
"dtype": "bfloat16",
|
| 1712 |
+
"format": "ND",
|
| 1713 |
+
"paramType": "required",
|
| 1714 |
+
"shape": [
|
| 1715 |
+
-2
|
| 1716 |
+
],
|
| 1717 |
+
"format_match_mode": "FormatAgnostic"
|
| 1718 |
+
},
|
| 1719 |
+
{
|
| 1720 |
+
"name": "q_gamma",
|
| 1721 |
+
"index": 1,
|
| 1722 |
+
"dtype": "bfloat16",
|
| 1723 |
+
"format": "ND",
|
| 1724 |
+
"paramType": "required",
|
| 1725 |
+
"shape": [
|
| 1726 |
+
-2
|
| 1727 |
+
],
|
| 1728 |
+
"format_match_mode": "FormatAgnostic"
|
| 1729 |
+
},
|
| 1730 |
+
{
|
| 1731 |
+
"name": "k_gamma",
|
| 1732 |
+
"index": 2,
|
| 1733 |
+
"dtype": "bfloat16",
|
| 1734 |
+
"format": "ND",
|
| 1735 |
+
"paramType": "required",
|
| 1736 |
+
"shape": [
|
| 1737 |
+
-2
|
| 1738 |
+
],
|
| 1739 |
+
"format_match_mode": "FormatAgnostic"
|
| 1740 |
+
},
|
| 1741 |
+
{
|
| 1742 |
+
"name": "cos",
|
| 1743 |
+
"index": 3,
|
| 1744 |
+
"dtype": "bfloat16",
|
| 1745 |
+
"format": "ND",
|
| 1746 |
+
"paramType": "required",
|
| 1747 |
+
"shape": [
|
| 1748 |
+
-2
|
| 1749 |
+
],
|
| 1750 |
+
"format_match_mode": "FormatAgnostic"
|
| 1751 |
+
},
|
| 1752 |
+
{
|
| 1753 |
+
"name": "sin",
|
| 1754 |
+
"index": 4,
|
| 1755 |
+
"dtype": "bfloat16",
|
| 1756 |
+
"format": "ND",
|
| 1757 |
+
"paramType": "required",
|
| 1758 |
+
"shape": [
|
| 1759 |
+
-2
|
| 1760 |
+
],
|
| 1761 |
+
"format_match_mode": "FormatAgnostic"
|
| 1762 |
+
},
|
| 1763 |
+
{
|
| 1764 |
+
"name": "index",
|
| 1765 |
+
"index": 5,
|
| 1766 |
+
"dtype": "int64",
|
| 1767 |
+
"format": "ND",
|
| 1768 |
+
"paramType": "required",
|
| 1769 |
+
"shape": [
|
| 1770 |
+
-2
|
| 1771 |
+
],
|
| 1772 |
+
"format_match_mode": "FormatAgnostic"
|
| 1773 |
+
},
|
| 1774 |
+
{
|
| 1775 |
+
"name": "q_out",
|
| 1776 |
+
"index": 6,
|
| 1777 |
+
"dtype": "bfloat16",
|
| 1778 |
+
"format": "ND",
|
| 1779 |
+
"paramType": "required",
|
| 1780 |
+
"shape": [
|
| 1781 |
+
-2
|
| 1782 |
+
],
|
| 1783 |
+
"format_match_mode": "FormatAgnostic"
|
| 1784 |
+
},
|
| 1785 |
+
{
|
| 1786 |
+
"name": "k_cache",
|
| 1787 |
+
"index": 7,
|
| 1788 |
+
"dtype": "bfloat16",
|
| 1789 |
+
"format": "ND",
|
| 1790 |
+
"paramType": "required",
|
| 1791 |
+
"shape": [
|
| 1792 |
+
-2
|
| 1793 |
+
],
|
| 1794 |
+
"format_match_mode": "FormatAgnostic"
|
| 1795 |
+
},
|
| 1796 |
+
{
|
| 1797 |
+
"name": "v_cache",
|
| 1798 |
+
"index": 8,
|
| 1799 |
+
"dtype": "int8",
|
| 1800 |
+
"format": "ND",
|
| 1801 |
+
"paramType": "required",
|
| 1802 |
+
"shape": [
|
| 1803 |
+
-2
|
| 1804 |
+
],
|
| 1805 |
+
"format_match_mode": "FormatAgnostic"
|
| 1806 |
+
},
|
| 1807 |
+
{
|
| 1808 |
+
"name": "k_scale",
|
| 1809 |
+
"index": 9,
|
| 1810 |
+
"dtype": "float32",
|
| 1811 |
+
"format": "ND",
|
| 1812 |
+
"paramType": "optional",
|
| 1813 |
+
"shape": [
|
| 1814 |
+
-2
|
| 1815 |
+
],
|
| 1816 |
+
"format_match_mode": "FormatAgnostic"
|
| 1817 |
+
},
|
| 1818 |
+
{
|
| 1819 |
+
"name": "v_scale",
|
| 1820 |
+
"index": 10,
|
| 1821 |
+
"dtype": "float32",
|
| 1822 |
+
"format": "ND",
|
| 1823 |
+
"paramType": "optional",
|
| 1824 |
+
"shape": [
|
| 1825 |
+
-2
|
| 1826 |
+
],
|
| 1827 |
+
"format_match_mode": "FormatAgnostic"
|
| 1828 |
+
},
|
| 1829 |
+
{
|
| 1830 |
+
"name": "k_offset",
|
| 1831 |
+
"index": 11,
|
| 1832 |
+
"dtype": "float32",
|
| 1833 |
+
"format": "ND",
|
| 1834 |
+
"paramType": "optional",
|
| 1835 |
+
"shape": [
|
| 1836 |
+
-2
|
| 1837 |
+
],
|
| 1838 |
+
"format_match_mode": "FormatAgnostic"
|
| 1839 |
+
},
|
| 1840 |
+
{
|
| 1841 |
+
"name": "v_offset",
|
| 1842 |
+
"index": 12,
|
| 1843 |
+
"dtype": "float32",
|
| 1844 |
+
"format": "ND",
|
| 1845 |
+
"paramType": "optional",
|
| 1846 |
+
"shape": [
|
| 1847 |
+
-2
|
| 1848 |
+
],
|
| 1849 |
+
"format_match_mode": "FormatAgnostic"
|
| 1850 |
+
}
|
| 1851 |
+
],
|
| 1852 |
+
"outputs": [
|
| 1853 |
+
{
|
| 1854 |
+
"name": "q_out",
|
| 1855 |
+
"index": 0,
|
| 1856 |
+
"dtype": "bfloat16",
|
| 1857 |
+
"format": "ND",
|
| 1858 |
+
"paramType": "required",
|
| 1859 |
+
"shape": [
|
| 1860 |
+
-2
|
| 1861 |
+
],
|
| 1862 |
+
"format_match_mode": "FormatAgnostic"
|
| 1863 |
+
},
|
| 1864 |
+
{
|
| 1865 |
+
"name": "k_cache",
|
| 1866 |
+
"index": 1,
|
| 1867 |
+
"dtype": "bfloat16",
|
| 1868 |
+
"format": "ND",
|
| 1869 |
+
"paramType": "required",
|
| 1870 |
+
"shape": [
|
| 1871 |
+
-2
|
| 1872 |
+
],
|
| 1873 |
+
"format_match_mode": "FormatAgnostic"
|
| 1874 |
+
},
|
| 1875 |
+
{
|
| 1876 |
+
"name": "v_cache",
|
| 1877 |
+
"index": 2,
|
| 1878 |
+
"dtype": "int8",
|
| 1879 |
+
"format": "ND",
|
| 1880 |
+
"paramType": "required",
|
| 1881 |
+
"shape": [
|
| 1882 |
+
-2
|
| 1883 |
+
],
|
| 1884 |
+
"format_match_mode": "FormatAgnostic"
|
| 1885 |
+
},
|
| 1886 |
+
{
|
| 1887 |
+
"name": "q_out_before_quant",
|
| 1888 |
+
"index": 3,
|
| 1889 |
+
"dtype": "bfloat16",
|
| 1890 |
+
"format": "ND",
|
| 1891 |
+
"paramType": "required",
|
| 1892 |
+
"shape": [
|
| 1893 |
+
-2
|
| 1894 |
+
],
|
| 1895 |
+
"format_match_mode": "FormatAgnostic"
|
| 1896 |
+
},
|
| 1897 |
+
{
|
| 1898 |
+
"name": "k_out_before_quant",
|
| 1899 |
+
"index": 4,
|
| 1900 |
+
"dtype": "bfloat16",
|
| 1901 |
+
"format": "ND",
|
| 1902 |
+
"paramType": "required",
|
| 1903 |
+
"shape": [
|
| 1904 |
+
-2
|
| 1905 |
+
],
|
| 1906 |
+
"format_match_mode": "FormatAgnostic"
|
| 1907 |
+
},
|
| 1908 |
+
{
|
| 1909 |
+
"name": "v_out_before_quant",
|
| 1910 |
+
"index": 5,
|
| 1911 |
+
"dtype": "bfloat16",
|
| 1912 |
+
"format": "ND",
|
| 1913 |
+
"paramType": "required",
|
| 1914 |
+
"shape": [
|
| 1915 |
+
-2
|
| 1916 |
+
],
|
| 1917 |
+
"format_match_mode": "FormatAgnostic"
|
| 1918 |
+
}
|
| 1919 |
+
],
|
| 1920 |
+
"attrs": [
|
| 1921 |
+
{
|
| 1922 |
+
"name": "qkv_size",
|
| 1923 |
+
"dtype": "list_int",
|
| 1924 |
+
"value": []
|
| 1925 |
+
},
|
| 1926 |
+
{
|
| 1927 |
+
"name": "head_nums",
|
| 1928 |
+
"dtype": "list_int",
|
| 1929 |
+
"value": []
|
| 1930 |
+
},
|
| 1931 |
+
{
|
| 1932 |
+
"name": "epsilon",
|
| 1933 |
+
"dtype": "float",
|
| 1934 |
+
"value": 0.000001
|
| 1935 |
+
},
|
| 1936 |
+
{
|
| 1937 |
+
"name": "cache_mode",
|
| 1938 |
+
"dtype": "string",
|
| 1939 |
+
"value": "PA_NZ"
|
| 1940 |
+
},
|
| 1941 |
+
{
|
| 1942 |
+
"name": "is_output_qkv",
|
| 1943 |
+
"dtype": "bool",
|
| 1944 |
+
"value": false
|
| 1945 |
+
}
|
| 1946 |
+
]
|
| 1947 |
+
}
|
| 1948 |
+
]
|
| 1949 |
+
}
|