ops-tune-workbench-plugin 0.0.0-stage → 0.0.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/NOTICE.md +14 -0
  2. package/README.md +39 -2
  3. package/cordis.patch.yml +20 -0
  4. package/lib/client.js +4253 -0
  5. package/lib/host.js +2518 -0
  6. package/package.json +53 -4
  7. package/skills/tool-ops-tune/INSTALL.md +52 -0
  8. package/skills/tool-ops-tune/README.md +167 -0
  9. package/skills/tool-ops-tune/SKILL.md +93 -0
  10. package/skills/tool-ops-tune/agent/AGENTS.md +195 -0
  11. package/skills/tool-ops-tune/agent/agents/perf-implementer.md +68 -0
  12. package/skills/tool-ops-tune/agent/agents/perf-reviewer.md +86 -0
  13. package/skills/tool-ops-tune/agent/workflows/task-prompts.md +362 -0
  14. package/skills/tool-ops-tune/agent/workflows/troubleshooting.md +43 -0
  15. package/skills/tool-ops-tune/docs/figures/opstune-architecture.png +0 -0
  16. package/skills/tool-ops-tune/docs/figures/opstune-architecture.svg +253 -0
  17. package/skills/tool-ops-tune/docs/ops-tune-design.md +404 -0
  18. package/skills/tool-ops-tune/docs//347/224/250/344/276/213/346/236/204/345/273/272.md +714 -0
  19. package/skills/tool-ops-tune/docs//347/237/245/350/257/206/345/272/223/350/247/204/350/214/203.md +103 -0
  20. package/skills/tool-ops-tune/evals/evals.json +242 -0
  21. package/skills/tool-ops-tune/ops-collect/SKILL.md +146 -0
  22. package/skills/tool-ops-tune/ops-collect/references/tool-routing.md +86 -0
  23. package/skills/tool-ops-tune/ops-collect/scripts/collect_board.sh +444 -0
  24. package/skills/tool-ops-tune/ops-collect/scripts/collect_cases.py +368 -0
  25. package/skills/tool-ops-tune/ops-collect/scripts/collect_sim.sh +134 -0
  26. package/skills/tool-ops-tune/ops-collect/scripts/csv_to_db.py +314 -0
  27. package/skills/tool-ops-tune/ops-collect/scripts/db_bench.py +545 -0
  28. package/skills/tool-ops-tune/ops-collect/scripts/facts_bridge.py +1063 -0
  29. package/skills/tool-ops-tune/ops-collect/scripts/isolation_test.py +454 -0
  30. package/skills/tool-ops-tune/ops-collect/scripts/jsonl_to_cases.py +163 -0
  31. package/skills/tool-ops-tune/ops-family/SKILL.md +76 -0
  32. package/skills/tool-ops-tune/ops-family/references/broadcast/advanced_tiling.md +92 -0
  33. package/skills/tool-ops-tune/ops-family/references/broadcast/broadcast_design.md +160 -0
  34. package/skills/tool-ops-tune/ops-family/references/broadcast/code/broadcast_add_kernel.cpp +126 -0
  35. package/skills/tool-ops-tune/ops-family/references/broadcast/code/broadcast_add_tiling.cpp +144 -0
  36. package/skills/tool-ops-tune/ops-family/references/broadcast/code/broadcast_tiling_common.h +401 -0
  37. package/skills/tool-ops-tune/ops-family/references/broadcast/code/onedim_add_kernel.cpp +107 -0
  38. package/skills/tool-ops-tune/ops-family/references/broadcast/code/onedim_add_tiling.cpp +64 -0
  39. package/skills/tool-ops-tune/ops-family/references/broadcast/datacopypad_design.md +46 -0
  40. package/skills/tool-ops-tune/ops-family/references/broadcast/guide.md +14 -0
  41. package/skills/tool-ops-tune/ops-family/references/broadcast/nddma_design.md +53 -0
  42. package/skills/tool-ops-tune/ops-family/references/broadcast/onedim_design.md +114 -0
  43. package/skills/tool-ops-tune/ops-family/references/broadcast/ub_broadcast_design.md +67 -0
  44. package/skills/tool-ops-tune/ops-family/references/common/datacopy_optimization_design.md +351 -0
  45. package/skills/tool-ops-tune/ops-family/references/common/index.md +9 -0
  46. package/skills/tool-ops-tune/ops-family/references/common/tail_block_design.md +268 -0
  47. package/skills/tool-ops-tune/ops-family/references/common/timing_harness/index.md +38 -0
  48. package/skills/tool-ops-tune/ops-family/references/common/timing_harness/timing_harness_aclrt_event.cpp +199 -0
  49. package/skills/tool-ops-tune/ops-family/references/common/timing_harness/timing_harness_torch_event.py +130 -0
  50. package/skills/tool-ops-tune/ops-family/references/common/ub_resident_design.md +342 -0
  51. package/skills/tool-ops-tune/ops-family/references/conversion/guide.md +69 -0
  52. package/skills/tool-ops-tune/ops-family/references/conversion/index.md +4 -0
  53. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_base.template +81 -0
  54. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_big_dim.template +217 -0
  55. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_cut_one_axis.template +336 -0
  56. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_cut_two_axis.template +781 -0
  57. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_n_last.template +340 -0
  58. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_small_shape.template +321 -0
  59. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_tensor_move.template +102 -0
  60. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_transdata_5hd.template +480 -0
  61. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_transdata_5hd_021axis.template +533 -0
  62. package/skills/tool-ops-tune/ops-family/references/conversion/templates/dav3510/transpose_with_gather.template +688 -0
  63. package/skills/tool-ops-tune/ops-family/references/conversion/templates/transpose_tiling_data.template +192 -0
  64. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_big_dim.md +220 -0
  65. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_cut_one_axis.md +175 -0
  66. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_cut_two_axis.md +177 -0
  67. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_fusion_design.md +398 -0
  68. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_gather.md +191 -0
  69. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_n_last.md +276 -0
  70. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_small_shape.md +315 -0
  71. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_tensor_move.md +203 -0
  72. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_tiling_data.md +176 -0
  73. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_vconv_021.md +206 -0
  74. package/skills/tool-ops-tune/ops-family/references/conversion/transpose_vconv_5hd.md +179 -0
  75. package/skills/tool-ops-tune/ops-family/references/elementwise/double_buffer_design.md +288 -0
  76. package/skills/tool-ops-tune/ops-family/references/elementwise/guide.md +46 -0
  77. package/skills/tool-ops-tune/ops-family/references/elementwise/index.md +10 -0
  78. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/CMakeLists.txt +131 -0
  79. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/README.md +55 -0
  80. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/add_custom_torch.cpp +80 -0
  81. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/ops.h +23 -0
  82. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_extension/register.cpp +30 -0
  83. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_host/add_custom.asc +149 -0
  84. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_host/data_utils.h +97 -0
  85. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_kernel/add_custom_kernel.asc +136 -0
  86. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/op_kernel/add_custom_tiling.h +31 -0
  87. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/run.sh +86 -0
  88. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/gen_data.py +70 -0
  89. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/golden.py +34 -0
  90. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/test_torch.py +99 -0
  91. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/add_custom/scripts/verify_result.py +56 -0
  92. package/skills/tool-ops-tune/ops-family/references/elementwise/templates/usage_guide.md +61 -0
  93. package/skills/tool-ops-tune/ops-family/references/elementwise/vector_efficiency_design.md +203 -0
  94. package/skills/tool-ops-tune/ops-family/references/fa/fa_mixed_kernel_design.md +174 -0
  95. package/skills/tool-ops-tune/ops-family/references/fa/fa_roofline_design.md +141 -0
  96. package/skills/tool-ops-tune/ops-family/references/fa/guide.md +87 -0
  97. package/skills/tool-ops-tune/ops-family/references/knowledge_gaps.json +56 -0
  98. package/skills/tool-ops-tune/ops-family/references/matmul/best-practices-guide.md +14 -0
  99. package/skills/tool-ops-tune/ops-family/references/matmul/fullload_design.md +344 -0
  100. package/skills/tool-ops-tune/ops-family/references/matmul/guide.md +52 -0
  101. package/skills/tool-ops-tune/ops-family/references/matmul/mte2_preload_design.md +320 -0
  102. package/skills/tool-ops-tune/ops-family/references/matmul/pingpong_design.md +254 -0
  103. package/skills/tool-ops-tune/ops-family/references/matmul/scale_coalescing_design.md +282 -0
  104. package/skills/tool-ops-tune/ops-family/references/matmul/streamk_design.md +374 -0
  105. package/skills/tool-ops-tune/ops-family/references/matmul/swat_design.md +423 -0
  106. package/skills/tool-ops-tune/ops-family/references/matmul/templates/matmul_basic_blaze.template +165 -0
  107. package/skills/tool-ops-tune/ops-family/references/matmul/templates/usage_guide.md +29 -0
  108. package/skills/tool-ops-tune/ops-family/references/mc2/best-practices-guide.md +43 -0
  109. package/skills/tool-ops-tune/ops-family/references/mc2/guide.md +42 -0
  110. package/skills/tool-ops-tune/ops-family/references/mc2/local_matmul_design.md +130 -0
  111. package/skills/tool-ops-tune/ops-family/references/mc2/pipeline_balancing_design.md +502 -0
  112. package/skills/tool-ops-tune/ops-family/references/reduce/guide.md +178 -0
  113. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/kernel_utils.template +75 -0
  114. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_full_load.template +429 -0
  115. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_recompute.template +485 -0
  116. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ar_small_r.template +348 -0
  117. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_full_load.template +574 -0
  118. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_online.template +324 -0
  119. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_ara_recompute.template +436 -0
  120. package/skills/tool-ops-tune/ops-family/references/reduce/templates/dav310/softmax_v2_base.template +950 -0
  121. package/skills/tool-ops-tune/ops-family/references/reduce/templates/fused_attention_online_softmax_design.md +428 -0
  122. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_full_load.md +137 -0
  123. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_recompute.md +135 -0
  124. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ar_small_r.md +122 -0
  125. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_full_load.md +144 -0
  126. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_online.md +185 -0
  127. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_ara_recompute.md +163 -0
  128. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_tiling.template +460 -0
  129. package/skills/tool-ops-tune/ops-family/references/reduce/templates/softmax_v2_tiling_data.template +278 -0
  130. package/skills/tool-ops-tune/ops-family/references/reduce/templates/state_resident_design.md +337 -0
  131. package/skills/tool-ops-tune/ops-family/references/reduce/templates/usage_guide.md +253 -0
  132. package/skills/tool-ops-tune/ops-family/references/scalar/coding_principles.md +476 -0
  133. package/skills/tool-ops-tune/ops-family/references/scalar/conv_scalar.md +163 -0
  134. package/skills/tool-ops-tune/ops-family/references/scalar/guide.md +30 -0
  135. package/skills/tool-ops-tune/ops-family/references/simt/guide.md +91 -0
  136. package/skills/tool-ops-tune/ops-family/references/simt/optimization-guide.md +110 -0
  137. package/skills/tool-ops-tune/ops-family/references/sort/guide.md +83 -0
  138. package/skills/tool-ops-tune/ops-family/references/sort/radix_sort.md +354 -0
  139. package/skills/tool-ops-tune/ops-family/scripts/family_asset_audit.py +68 -0
  140. package/skills/tool-ops-tune/ops-family/scripts/tiling_candidates.py +419 -0
  141. package/skills/tool-ops-tune/ops-mechanism/SKILL.md +23 -0
  142. package/skills/tool-ops-tune/ops-mechanism/cases/ascendc/case_groupedmatmul_pipeline.md +23 -0
  143. package/skills/tool-ops-tune/ops-mechanism/cases/ascendc/case_triton_atomic_revert.md +19 -0
  144. package/skills/tool-ops-tune/ops-mechanism/cases/mc2/case_mc2_fusion.md +19 -0
  145. package/skills/tool-ops-tune/ops-mechanism/references/optimize/api-usage.md +70 -0
  146. package/skills/tool-ops-tune/ops-mechanism/references/optimize/ascendc-regbase-vf.md +45 -0
  147. package/skills/tool-ops-tune/ops-mechanism/references/optimize/ascendc-tiling.md +51 -0
  148. package/skills/tool-ops-tune/ops-mechanism/references/optimize/data-copy.md +67 -0
  149. package/skills/tool-ops-tune/ops-mechanism/references/optimize/index.md +45 -0
  150. package/skills/tool-ops-tune/ops-mechanism/references/optimize/mc2-balancing.md +77 -0
  151. package/skills/tool-ops-tune/ops-mechanism/references/optimize/mc2.md +103 -0
  152. package/skills/tool-ops-tune/ops-mechanism/references/optimize/memory-hierarchy.md +40 -0
  153. package/skills/tool-ops-tune/ops-mechanism/references/optimize/pipeline.md +95 -0
  154. package/skills/tool-ops-tune/ops-mechanism/scripts/case_backfill.py +170 -0
  155. package/skills/tool-ops-tune/ops-mechanism/scripts/log_gap.py +145 -0
  156. package/skills/tool-ops-tune/ops-mechanism/scripts/mc2_search.py +367 -0
  157. package/skills/tool-ops-tune/ops-report/SKILL.md +77 -0
  158. package/skills/tool-ops-tune/ops-verdict/evals/run_evals.py +837 -0
  159. package/skills/tool-ops-tune/ops-verdict/evals/smoke/install-hooks.sh +65 -0
  160. package/skills/tool-ops-tune/ops-verdict/evals/smoke/run_smoke.sh +405 -0
  161. package/skills/tool-ops-tune/ops-verdict/fixtures/core_tail_a5.csv +25 -0
  162. package/skills/tool-ops-tune/ops-verdict/fixtures/few_cores_a5.csv +5 -0
  163. package/skills/tool-ops-tune/ops-verdict/fixtures/mte2_bound_a2.csv +17 -0
  164. package/skills/tool-ops-tune/ops-verdict/fixtures/multi_kernel_mix_a5.csv +7 -0
  165. package/skills/tool-ops-tune/ops-verdict/fixtures/no_bound_a5.csv +9 -0
  166. package/skills/tool-ops-tune/ops-verdict/fixtures/serial_no_overlap_a2.csv +9 -0
  167. package/skills/tool-ops-tune/ops-verdict/fixtures/vec_bound_a5.csv +9 -0
  168. package/skills/tool-ops-tune/ops-verdict/references/io-contracts.md +94 -0
  169. package/skills/tool-ops-tune/ops-verdict/references/rule-schema.md +130 -0
  170. package/skills/tool-ops-tune/ops-verdict/references/scope-schema.md +61 -0
  171. package/skills/tool-ops-tune/ops-verdict/references/soc-spec.yaml +140 -0
  172. package/skills/tool-ops-tune/ops-verdict/rules/L0-instruction.yaml +67 -0
  173. package/skills/tool-ops-tune/ops-verdict/rules/L1-single-core.yaml +316 -0
  174. package/skills/tool-ops-tune/ops-verdict/rules/L2-inter-core.yaml +173 -0
  175. package/skills/tool-ops-tune/ops-verdict/rules/L3-inter-card.yaml +156 -0
  176. package/skills/tool-ops-tune/ops-verdict/scripts/batch_pipeline.py +444 -0
  177. package/skills/tool-ops-tune/ops-verdict/scripts/calibrate.py +249 -0
  178. package/skills/tool-ops-tune/ops-verdict/scripts/delta_compare.py +244 -0
  179. package/skills/tool-ops-tune/ops-verdict/scripts/render_html.py +274 -0
  180. package/skills/tool-ops-tune/ops-verdict/scripts/snapshot.py +200 -0
  181. package/skills/tool-ops-tune/ops-verdict/scripts/trace_bubble.py +331 -0
  182. package/skills/tool-ops-tune/ops-verdict/scripts/verdict.py +1072 -0
  183. package/skills/tool-ops-tune/scripts/diff_audit.py +281 -0
@@ -0,0 +1,340 @@
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 transpose_n_last.h
13
+ * \brief transpose_n_last
14
+ */
15
+ #ifndef TRANSPOSE_N_LAST_H
16
+ #define TRANSPOSE_N_LAST_H
17
+
18
+ #include "transpose_base.h"
19
+
20
+ namespace Transpose {
21
+ using namespace AscendC;
22
+
23
+ template <typename T>
24
+ class TransposeNLast : public TransposeBase<T> {
25
+ public:
26
+ __aicore__ inline TransposeNLast(){};
27
+ __aicore__ inline void Init(GM_ADDR x, GM_ADDR y, const TransposeOpTilingData* tilingData, TPipe* pipe);
28
+ __aicore__ inline void Process();
29
+
30
+ private:
31
+ __aicore__ inline void ParseTilingData();
32
+ __aicore__ inline void GetBlockLoopNum();
33
+ __aicore__ inline void GetLoopParams(int64_t n);
34
+ __aicore__ inline int64_t GetDstAddressOffset(int64_t loopIdx, int64_t permSize, const int64_t mixedBase[],
35
+ const int64_t loopNum[]);
36
+ __aicore__ inline void ProcessPerCore();
37
+ __aicore__ inline void CopyIn(int64_t loopIdx, int64_t inputBlockLen, int64_t inCutLoopSize, int64_t inUbFactor,
38
+ int64_t inTailFactor, int64_t permSize);
39
+ __aicore__ inline void CopyOut(int64_t loopIdx, int64_t loopSize[], int64_t loopSrcStride[],
40
+ int64_t loopDstStride[], int64_t permSize, const int64_t mixedBase[],
41
+ const int64_t loopNum[]);
42
+
43
+ private:
44
+ int64_t blockIdx_;
45
+
46
+ // buffer
47
+ TQueBind<QuePosition::VECIN, QuePosition::VECOUT, 1> vecQue_;
48
+ GlobalTensor<T> inputGM_;
49
+ GlobalTensor<T> outputGM_;
50
+
51
+ // tiling params
52
+ const TransposeOpTilingData* tiling_;
53
+ int64_t reducedInputShape_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
54
+ int64_t reducedOutputShape_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
55
+ int64_t inUbInputShapeMain_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
56
+ int64_t inUbOutputShapeMain_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
57
+ int64_t inUbInputShapeTail_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
58
+ int64_t inUbOutputShapeTail_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
59
+ int64_t outputBlockLenMain_ = 0;
60
+ int64_t outputBlockLenTail_ = 0;
61
+
62
+ // core params
63
+ int64_t blkProcessNum_ = 0;
64
+ int64_t blkProcessIdxStart_ = 0;
65
+ int64_t blkProcessIdxEnd_ = 0;
66
+
67
+ // addressOffset params
68
+ int64_t dstAddressOffsetMixedBase_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
69
+ int64_t dstLoopNumArray_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
70
+
71
+ // dataCopy params
72
+ int64_t loopSizeMain_[TRANSPOSE_MAX_AXIS_NUM] = {1, 1, 1, 1, 1, 1, 1, 1};
73
+ int64_t loopSrcStrideMain_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
74
+ int64_t loopDstStrideMain_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
75
+ int64_t loopSizeTail_[TRANSPOSE_MAX_AXIS_NUM] = {1, 1, 1, 1, 1, 1, 1, 1};
76
+ int64_t loopSrcStrideTail_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
77
+ int64_t loopDstStrideTail_[TRANSPOSE_MAX_AXIS_NUM] = {0, 0, 0, 0, 0, 0, 0, 0};
78
+ };
79
+
80
+ template <typename T>
81
+ __aicore__ inline void TransposeNLast<T>::Init(GM_ADDR x, GM_ADDR y, const TransposeOpTilingData* tilingData,
82
+ TPipe* pipe)
83
+ {
84
+ blockIdx_ = GetBlockIdx();
85
+ tiling_ = tilingData;
86
+ ParseTilingData();
87
+ inputGM_.SetGlobalBuffer((__gm__ T*)x);
88
+ outputGM_.SetGlobalBuffer((__gm__ T*)y);
89
+ pipe->InitBuffer(vecQue_, BUFFER_NUM, tiling_->ubSize / BUFFER_NUM);
90
+ }
91
+
92
+ template <typename T>
93
+ __aicore__ inline void TransposeNLast<T>::Process()
94
+ {
95
+ if (!ParseMultiCoreRange(blockIdx_, tiling_->realCoreNum, tiling_->blkFactor, tiling_->blkTailFactor,
96
+ blkProcessNum_, blkProcessIdxStart_, blkProcessIdxEnd_)) {
97
+ return;
98
+ }
99
+ ProcessPerCore();
100
+ }
101
+
102
+ template <typename T>
103
+ __aicore__ inline void TransposeNLast<T>::ParseTilingData()
104
+ {
105
+ // input in ub shape main and tail
106
+ for (int64_t i = 0; i < tiling_->permSize; i++) {
107
+ reducedInputShape_[i] = tiling_->inputShape[i];
108
+ if (i > tiling_->inCutIndex) {
109
+ inUbInputShapeMain_[i] = reducedInputShape_[i];
110
+ inUbInputShapeTail_[i] = reducedInputShape_[i];
111
+ } else {
112
+ inUbInputShapeMain_[i] = 1;
113
+ inUbInputShapeTail_[i] = 1;
114
+ }
115
+ }
116
+ inUbInputShapeMain_[tiling_->inCutIndex] = tiling_->inUbFactor;
117
+ inUbInputShapeTail_[tiling_->inCutIndex] = tiling_->inTailFactor;
118
+
119
+ // output in ub shape main and tail
120
+ for (int64_t i = 0; i < tiling_->permSize; i++) {
121
+ reducedOutputShape_[i] = reducedInputShape_[tiling_->perm[i]];
122
+ inUbOutputShapeMain_[i] = inUbInputShapeMain_[tiling_->perm[i]];
123
+ inUbOutputShapeTail_[i] = inUbInputShapeTail_[tiling_->perm[i]];
124
+ }
125
+
126
+ outputBlockLenMain_ = inUbOutputShapeMain_[tiling_->permSize - 1];
127
+ outputBlockLenTail_ = inUbOutputShapeTail_[tiling_->permSize - 1];
128
+ }
129
+
130
+ template <typename T>
131
+ __aicore__ inline void TransposeNLast<T>::GetBlockLoopNum()
132
+ {
133
+ const int64_t permSize = tiling_->permSize;
134
+ int64_t dstLoopNumArrayTmp[TRANSPOSE_MAX_AXIS_NUM];
135
+ int64_t rightProducts[TRANSPOSE_MAX_AXIS_NUM + 1];
136
+ rightProducts[permSize] = 1;
137
+
138
+ for (int64_t i = permSize - 1; i >= 0; i--) {
139
+ rightProducts[i] = rightProducts[i + 1] * reducedOutputShape_[i];
140
+ }
141
+ for (int64_t i = 0; i < permSize; i++) {
142
+ dstAddressOffsetMixedBase_[i] = Ops::Base::CeilDiv(reducedInputShape_[i], inUbInputShapeMain_[i]);
143
+ dstLoopNumArrayTmp[i] = inUbOutputShapeMain_[i] * rightProducts[i + 1];
144
+ }
145
+ for (int64_t i = 0; i < permSize; i++) {
146
+ dstLoopNumArray_[tiling_->perm[i]] = dstLoopNumArrayTmp[i];
147
+ }
148
+ }
149
+
150
+ template <typename T>
151
+ __aicore__ inline void TransposeNLast<T>::GetLoopParams(int64_t n)
152
+ {
153
+ const int64_t permSize = tiling_->permSize;
154
+ const int64_t reverseIdx = permSize - 1 - n;
155
+ // main and tail loopSize
156
+ loopSizeMain_[n] = inUbInputShapeMain_[reverseIdx];
157
+ loopSizeTail_[n] = inUbInputShapeTail_[reverseIdx];
158
+ // main and tail last axis aligned to ub block size
159
+ int64_t alignedStrideMain = Ops::Base::CeilAlign(static_cast<int64_t>(loopSizeMain_[0] * sizeof(T)),
160
+ BLOCK_SIZE_BYTE) /
161
+ sizeof(T);
162
+ int64_t alignedStrideTail = Ops::Base::CeilAlign(static_cast<int64_t>(loopSizeTail_[0] * sizeof(T)),
163
+ BLOCK_SIZE_BYTE) /
164
+ sizeof(T);
165
+ // main loopSrcStride and loopDstStride
166
+ if (loopSizeMain_[n] != 1) {
167
+ loopSrcStrideMain_[n] = alignedStrideMain;
168
+ if (n == 0) {
169
+ loopSrcStrideMain_[n] = 1;
170
+ }
171
+ for (int64_t i = 1; i < n; i++) {
172
+ loopSrcStrideMain_[n] *= inUbInputShapeMain_[permSize - 1 - i];
173
+ }
174
+ loopDstStrideMain_[n] = 1;
175
+ for (int64_t i = permSize - 1; i >= 0; i--) {
176
+ if (tiling_->perm[i] != reverseIdx) {
177
+ loopDstStrideMain_[n] *= reducedOutputShape_[i];
178
+ } else {
179
+ break;
180
+ }
181
+ }
182
+ }
183
+ // tail loopSrcStride and loopDstStride
184
+ if (tiling_->inTailFactor != 0 && loopSizeTail_[n] != 1) {
185
+ loopSrcStrideTail_[n] = alignedStrideTail;
186
+ for (int64_t i = 1; i < n; i++) {
187
+ loopSrcStrideTail_[n] *= inUbInputShapeTail_[permSize - 1 - i];
188
+ }
189
+ loopDstStrideTail_[n] = 1;
190
+ for (int64_t i = permSize - 1; i >= 0; i--) {
191
+ if (tiling_->perm[i] != reverseIdx) {
192
+ loopDstStrideTail_[n] *= reducedOutputShape_[i];
193
+ } else {
194
+ break;
195
+ }
196
+ }
197
+ }
198
+ }
199
+
200
+ template <typename T>
201
+ __aicore__ inline int64_t TransposeNLast<T>::GetDstAddressOffset(int64_t loopIdx, int64_t permSize,
202
+ const int64_t mixedBase[], const int64_t loopNum[])
203
+ {
204
+ // Fuse DecimalToMixed + accumulation: no intermediate array, no zero-init overhead (P9)
205
+ int64_t dstAddressOffset = 0;
206
+ if (loopIdx != 0) {
207
+ int64_t num = loopIdx;
208
+ for (int64_t i = permSize - 1; i >= 0 && num != 0; i--) {
209
+ dstAddressOffset += (num % mixedBase[i]) * loopNum[i];
210
+ num /= mixedBase[i];
211
+ }
212
+ }
213
+ return dstAddressOffset;
214
+ }
215
+
216
+ template <typename T>
217
+ __aicore__ inline void TransposeNLast<T>::CopyIn(int64_t loopIdx, int64_t inputBlockLen, int64_t inCutLoopSize,
218
+ int64_t inUbFactor, int64_t inTailFactor, int64_t permSize)
219
+ {
220
+ int64_t inputBlockLenMain = inputBlockLen * inUbFactor;
221
+ int64_t inputBlockLenTail = inputBlockLen * inTailFactor;
222
+ int64_t srcAddressOffset = loopIdx * inputBlockLenMain;
223
+ if (inTailFactor != 0) {
224
+ srcAddressOffset = (loopIdx - loopIdx / inCutLoopSize) * inputBlockLenMain +
225
+ loopIdx / inCutLoopSize * inputBlockLenTail;
226
+ }
227
+ int64_t blockLen = inputBlockLenMain;
228
+ int64_t lastAxisLen = inUbInputShapeMain_[permSize - 1];
229
+ if (inTailFactor != 0 && (loopIdx + 1) % inCutLoopSize == 0) {
230
+ blockLen = inputBlockLenTail;
231
+ lastAxisLen = inUbInputShapeTail_[permSize - 1];
232
+ }
233
+ LocalTensor<T> bindLocalIn = vecQue_.AllocTensor<T>();
234
+ DataCopyExtParams copyInParams{1, 0, 0, 0, 0};
235
+ DataCopyPadExtParams<T> padParams{false, 0, 0, 0};
236
+
237
+ copyInParams.blockLen = blockLen * sizeof(T);
238
+ copyInParams.blockCount = 1;
239
+ if ((lastAxisLen * sizeof(T)) % BLOCK_SIZE_BYTE != 0) {
240
+ copyInParams.blockLen = lastAxisLen * sizeof(T);
241
+ copyInParams.blockCount = blockLen / lastAxisLen;
242
+ }
243
+ DataCopyPad(bindLocalIn, inputGM_[srcAddressOffset], copyInParams, padParams);
244
+ vecQue_.EnQue(bindLocalIn);
245
+ }
246
+
247
+ template <typename T>
248
+ __aicore__ inline void TransposeNLast<T>::CopyOut(int64_t loopIdx, int64_t loopSize[], int64_t loopSrcStride[],
249
+ int64_t loopDstStride[], int64_t permSize, const int64_t mixedBase[],
250
+ const int64_t loopNum[])
251
+ {
252
+ int64_t dstAddressOffset = GetDstAddressOffset(loopIdx, permSize, mixedBase, loopNum);
253
+
254
+ // P4: cache array elements into locals to avoid alias-induced reload after DataCopyPad stores
255
+ const int64_t ls4 = loopSize[4], ls5 = loopSize[5], ls6 = loopSize[6], ls7 = loopSize[7];
256
+ const int64_t lss4 = loopSrcStride[4], lss5 = loopSrcStride[5];
257
+ const int64_t lss6 = loopSrcStride[6], lss7 = loopSrcStride[7];
258
+ const int64_t lds4 = loopDstStride[4], lds5 = loopDstStride[5];
259
+ const int64_t lds6 = loopDstStride[6], lds7 = loopDstStride[7];
260
+
261
+ DataCopyExtParams copyOutParams{1, 0, 0, 0, 0};
262
+ copyOutParams.blockLen = loopSize[0] * sizeof(T);
263
+ copyOutParams.blockCount = loopSize[1];
264
+ copyOutParams.srcStride = 0;
265
+ copyOutParams.dstStride = copyOutParams.blockCount == 1 ? 0 : (loopDstStride[1] - loopSize[0]) * sizeof(T);
266
+
267
+ LoopModeParams loopParams;
268
+ loopParams.loop1Size = loopSize[2];
269
+ loopParams.loop1SrcStride = loopSrcStride[2] * sizeof(T);
270
+ loopParams.loop1DstStride = loopDstStride[2] * sizeof(T);
271
+ loopParams.loop2Size = loopSize[3];
272
+ loopParams.loop2SrcStride = loopSrcStride[3] * sizeof(T);
273
+ loopParams.loop2DstStride = loopDstStride[3] * sizeof(T);
274
+
275
+ LocalTensor<T> bindLocalOut = vecQue_.DeQue<T>();
276
+ // Move SetLoopModePara outside the loop: loopParams is constant across all iterations
277
+ SetLoopModePara(loopParams, DataCopyMVType::UB_TO_OUT);
278
+ for (int64_t loop7Idx = 0; loop7Idx < ls7; loop7Idx++) {
279
+ for (int64_t loop6Idx = 0; loop6Idx < ls6; loop6Idx++) {
280
+ for (int64_t loop5Idx = 0; loop5Idx < ls5; loop5Idx++) {
281
+ for (int64_t loop4Idx = 0; loop4Idx < ls4; loop4Idx++) {
282
+ DataCopyPad(outputGM_[dstAddressOffset + loop7Idx * lds7 + loop6Idx * lds6 + loop5Idx * lds5 +
283
+ loop4Idx * lds4],
284
+ bindLocalOut[loop7Idx * lss7 + loop6Idx * lss6 + loop5Idx * lss5 + loop4Idx * lss4],
285
+ copyOutParams);
286
+ }
287
+ }
288
+ }
289
+ }
290
+ ResetLoopModePara(DataCopyMVType::UB_TO_OUT);
291
+ vecQue_.FreeTensor(bindLocalOut);
292
+ }
293
+
294
+ template <typename T>
295
+ __aicore__ inline void TransposeNLast<T>::ProcessPerCore()
296
+ {
297
+ // P6: cache tiling pointer fields into local variables to avoid repeated double-Load
298
+ const int64_t permSize = tiling_->permSize;
299
+ const int64_t inUbFactor = tiling_->inUbFactor;
300
+ const int64_t inTailFactor = tiling_->inTailFactor;
301
+ const int64_t inCutIndex = tiling_->inCutIndex;
302
+
303
+ for (int64_t i = 0; i < permSize; i++) {
304
+ GetLoopParams(i);
305
+ }
306
+ GetBlockLoopNum();
307
+ int64_t inputBlockLen = 1;
308
+ for (int64_t i = permSize - 1; i > inCutIndex; i--) {
309
+ inputBlockLen *= reducedInputShape_[i];
310
+ }
311
+ int64_t inCutLoopSize = Ops::Base::CeilDiv(reducedInputShape_[inCutIndex], inUbFactor);
312
+
313
+ // P4: cache member variables used only in this function
314
+ const int64_t loopStart = blkProcessIdxStart_;
315
+ const int64_t loopEnd = blkProcessIdxEnd_;
316
+
317
+ // P1: cache member arrays to stack to break alias pollution from struct dynamic indexing
318
+ int64_t localMixedBase[TRANSPOSE_MAX_AXIS_NUM];
319
+ int64_t localLoopNum[TRANSPOSE_MAX_AXIS_NUM];
320
+ for (int64_t i = 0; i < permSize; i++) {
321
+ localMixedBase[i] = dstAddressOffsetMixedBase_[i];
322
+ localLoopNum[i] = dstLoopNumArray_[i];
323
+ }
324
+
325
+ // P2: main/tail loop separation to eliminate per-iteration branch in hot path
326
+ for (int64_t loopIdx = loopStart; loopIdx < loopEnd; loopIdx++) {
327
+ if (inTailFactor != 0 && (loopIdx + 1) % inCutLoopSize == 0) {
328
+ CopyIn(loopIdx, inputBlockLen, inCutLoopSize, inUbFactor, inTailFactor, permSize);
329
+ CopyOut(loopIdx, loopSizeTail_, loopSrcStrideTail_, loopDstStrideTail_, permSize, localMixedBase,
330
+ localLoopNum);
331
+ } else {
332
+ CopyIn(loopIdx, inputBlockLen, inCutLoopSize, inUbFactor, inTailFactor, permSize);
333
+ CopyOut(loopIdx, loopSizeMain_, loopSrcStrideMain_, loopDstStrideMain_, permSize, localMixedBase,
334
+ localLoopNum);
335
+ }
336
+ }
337
+ }
338
+ } // namespace Transpose
339
+
340
+ #endif // TRANSPOSE_N_LAST_H
@@ -0,0 +1,321 @@
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 transpose_small_shape.h
13
+ * \brief transpose_small_shape
14
+ */
15
+ #ifndef TRANSPOSE_SMALL_SHAPE_H
16
+ #define TRANSPOSE_SMALL_SHAPE_H
17
+
18
+ #include "transpose_base.h"
19
+ #include "simt_api/asc_simt.h"
20
+
21
+ #ifdef __DAV_FPGA__
22
+ constexpr int32_t THREAD_DIM = 512;
23
+ constexpr int32_t HALF_THREAD_DIM = 512;
24
+ constexpr int32_t QUARTER_THREAD_DIM = 512;
25
+ constexpr int32_t AN_EIGHTH_THREAD_DIM = 256;
26
+ #else
27
+ constexpr int32_t THREAD_DIM = 2048;
28
+ constexpr int32_t HALF_THREAD_DIM = 1024;
29
+ constexpr int32_t QUARTER_THREAD_DIM = 512;
30
+ constexpr int32_t AN_EIGHTH_THREAD_DIM = 256;
31
+ #endif
32
+
33
+ namespace Transpose {
34
+ using namespace AscendC;
35
+
36
+ template <typename T>
37
+ class TransposeSmallShape : public TransposeBase<T> {
38
+ public:
39
+ __aicore__ inline TransposeSmallShape(){};
40
+ __aicore__ inline void Init(GM_ADDR x, GM_ADDR y, const TransposeOpTilingData* tilingData);
41
+ __aicore__ inline void Process();
42
+
43
+ private:
44
+ GlobalTensor<T> inputGM_;
45
+ GlobalTensor<T> outputGM_;
46
+ int32_t blockIdx_;
47
+ const TransposeOpTilingData* tilingData_;
48
+ };
49
+
50
+ template <typename T>
51
+ __aicore__ inline void TransposeSmallShape<T>::Init(GM_ADDR x, GM_ADDR y, const TransposeOpTilingData* tilingData)
52
+ {
53
+ blockIdx_ = GetBlockIdx();
54
+ tilingData_ = tilingData;
55
+ inputGM_.SetGlobalBuffer((__gm__ T*)x);
56
+ outputGM_.SetGlobalBuffer((__gm__ T*)y);
57
+ }
58
+
59
+ template <typename T>
60
+ __simt_vf__ LAUNCH_BOUND(THREAD_DIM) __aicore__
61
+ void SimtComputeDimTwo(__gm__ T* inputGM, __gm__ volatile T* outputGM, uint32_t coreFactor, uint32_t coreOffset,
62
+ uint32_t outputShape0, uint32_t outputShape1, uint32_t m0, uint32_t m1, uint32_t s0,
63
+ uint32_t s1)
64
+ {
65
+ for (uint32_t idx = static_cast<uint32_t>(threadIdx.x); idx < coreFactor;
66
+ idx += static_cast<uint32_t>(blockDim.x)) {
67
+ uint32_t yIdx = coreOffset + idx;
68
+ uint32_t inputIndex0 = yIdx - Simt::UintDiv(yIdx, m0, s0) * outputShape0;
69
+ yIdx = Simt::UintDiv(yIdx, m0, s0);
70
+ uint32_t inputIndex1 = yIdx - Simt::UintDiv(yIdx, m1, s1) * outputShape1;
71
+ uint32_t xIdx = inputIndex0 * outputShape1 + inputIndex1;
72
+ outputGM[coreOffset + idx] = inputGM[xIdx];
73
+ }
74
+ }
75
+
76
+ template <typename T>
77
+ __simt_vf__ LAUNCH_BOUND(THREAD_DIM) __aicore__
78
+ void SimtComputeDimThree(__gm__ T* inputGM, __gm__ volatile T* outputGM, uint32_t coreFactor, uint32_t coreOffset,
79
+ uint32_t outputShape0, uint32_t outputShape1, uint32_t outputShape2, uint32_t dstStride0,
80
+ uint32_t dstStride1, uint32_t dstStride2, uint32_t m0, uint32_t m1, uint32_t m2,
81
+ uint32_t s0, uint32_t s1, uint32_t s2)
82
+ {
83
+ for (uint32_t idx = static_cast<uint32_t>(threadIdx.x); idx < coreFactor;
84
+ idx += static_cast<uint32_t>(blockDim.x)) {
85
+ uint32_t yIdx = coreOffset + idx;
86
+ uint32_t inputIndex0 = yIdx - Simt::UintDiv(yIdx, m0, s0) * outputShape0;
87
+ yIdx = Simt::UintDiv(yIdx, m0, s0);
88
+ uint32_t inputIndex1 = yIdx - Simt::UintDiv(yIdx, m1, s1) * outputShape1;
89
+ yIdx = Simt::UintDiv(yIdx, m1, s1);
90
+ uint32_t inputIndex2 = yIdx - Simt::UintDiv(yIdx, m2, s2) * outputShape2;
91
+ uint32_t xIdx = inputIndex0 * dstStride0 + inputIndex1 * dstStride1 + inputIndex2 * dstStride2;
92
+ outputGM[coreOffset + idx] = inputGM[xIdx];
93
+ }
94
+ }
95
+
96
+ template <typename T>
97
+ __simt_vf__ LAUNCH_BOUND(THREAD_DIM) __aicore__
98
+ void SimtComputeDimFour(__gm__ T* inputGM, __gm__ volatile T* outputGM, uint32_t coreFactor, uint32_t coreOffset,
99
+ uint32_t outputShape0, uint32_t outputShape1, uint32_t outputShape2, uint32_t outputShape3,
100
+ uint32_t dstStride0, uint32_t dstStride1, uint32_t dstStride2, uint32_t dstStride3,
101
+ uint32_t m0, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t s0, uint32_t s1, uint32_t s2,
102
+ uint32_t s3)
103
+ {
104
+ for (uint32_t idx = static_cast<uint32_t>(threadIdx.x); idx < coreFactor;
105
+ idx += static_cast<uint32_t>(blockDim.x)) {
106
+ uint32_t yIdx = coreOffset + idx;
107
+ uint32_t inputIndex0 = yIdx - Simt::UintDiv(yIdx, m0, s0) * outputShape0;
108
+ yIdx = Simt::UintDiv(yIdx, m0, s0);
109
+ uint32_t inputIndex1 = yIdx - Simt::UintDiv(yIdx, m1, s1) * outputShape1;
110
+ yIdx = Simt::UintDiv(yIdx, m1, s1);
111
+ uint32_t inputIndex2 = yIdx - Simt::UintDiv(yIdx, m2, s2) * outputShape2;
112
+ yIdx = Simt::UintDiv(yIdx, m2, s2);
113
+ uint32_t inputIndex3 = yIdx - Simt::UintDiv(yIdx, m3, s3) * outputShape3;
114
+ uint32_t xIdx = inputIndex0 * dstStride0 + inputIndex1 * dstStride1 + inputIndex2 * dstStride2 +
115
+ inputIndex3 * dstStride3;
116
+ outputGM[coreOffset + idx] = inputGM[xIdx];
117
+ }
118
+ }
119
+
120
+ template <typename T>
121
+ __simt_vf__ LAUNCH_BOUND(THREAD_DIM) __aicore__
122
+ void SimtComputeDimFive(__gm__ T* inputGM, __gm__ volatile T* outputGM, uint32_t coreFactor, uint32_t coreOffset,
123
+ uint32_t outputShape0, uint32_t outputShape1, uint32_t outputShape2, uint32_t outputShape3,
124
+ uint32_t outputShape4, uint32_t dstStride0, uint32_t dstStride1, uint32_t dstStride2,
125
+ uint32_t dstStride3, uint32_t dstStride4, uint32_t m0, uint32_t m1, uint32_t m2,
126
+ uint32_t m3, uint32_t m4, uint32_t s0, uint32_t s1, uint32_t s2, uint32_t s3, uint32_t s4)
127
+ {
128
+ for (uint32_t idx = static_cast<uint32_t>(threadIdx.x); idx < coreFactor;
129
+ idx += static_cast<uint32_t>(blockDim.x)) {
130
+ uint32_t yIdx = coreOffset + idx;
131
+ uint32_t inputIndex0 = yIdx - Simt::UintDiv(yIdx, m0, s0) * outputShape0;
132
+ yIdx = Simt::UintDiv(yIdx, m0, s0);
133
+ uint32_t inputIndex1 = yIdx - Simt::UintDiv(yIdx, m1, s1) * outputShape1;
134
+ yIdx = Simt::UintDiv(yIdx, m1, s1);
135
+ uint32_t inputIndex2 = yIdx - Simt::UintDiv(yIdx, m2, s2) * outputShape2;
136
+ yIdx = Simt::UintDiv(yIdx, m2, s2);
137
+ uint32_t inputIndex3 = yIdx - Simt::UintDiv(yIdx, m3, s3) * outputShape3;
138
+ yIdx = Simt::UintDiv(yIdx, m3, s3);
139
+ uint32_t inputIndex4 = yIdx - Simt::UintDiv(yIdx, m4, s4) * outputShape4;
140
+ uint32_t xIdx = inputIndex0 * dstStride0 + inputIndex1 * dstStride1 + inputIndex2 * dstStride2 +
141
+ inputIndex3 * dstStride3 + inputIndex4 * dstStride4;
142
+ outputGM[coreOffset + idx] = inputGM[xIdx];
143
+ }
144
+ }
145
+
146
+ template <typename T>
147
+ __simt_vf__ LAUNCH_BOUND(THREAD_DIM) __aicore__
148
+ void SimtComputeDimSix(__gm__ T* inputGM, __gm__ volatile T* outputGM, uint32_t coreFactor, uint32_t coreOffset,
149
+ uint32_t outputShape0, uint32_t outputShape1, uint32_t outputShape2, uint32_t outputShape3,
150
+ uint32_t outputShape4, uint32_t outputShape5, uint32_t dstStride0, uint32_t dstStride1,
151
+ uint32_t dstStride2, uint32_t dstStride3, uint32_t dstStride4, uint32_t dstStride5,
152
+ uint32_t m0, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4, uint32_t m5, uint32_t s0,
153
+ uint32_t s1, uint32_t s2, uint32_t s3, uint32_t s4, uint32_t s5)
154
+ {
155
+ for (uint32_t idx = static_cast<uint32_t>(threadIdx.x); idx < coreFactor;
156
+ idx += static_cast<uint32_t>(blockDim.x)) {
157
+ uint32_t yIdx = coreOffset + idx;
158
+ uint32_t inputIndex0 = yIdx - Simt::UintDiv(yIdx, m0, s0) * outputShape0;
159
+ yIdx = Simt::UintDiv(yIdx, m0, s0);
160
+ uint32_t inputIndex1 = yIdx - Simt::UintDiv(yIdx, m1, s1) * outputShape1;
161
+ yIdx = Simt::UintDiv(yIdx, m1, s1);
162
+ uint32_t inputIndex2 = yIdx - Simt::UintDiv(yIdx, m2, s2) * outputShape2;
163
+ yIdx = Simt::UintDiv(yIdx, m2, s2);
164
+ uint32_t inputIndex3 = yIdx - Simt::UintDiv(yIdx, m3, s3) * outputShape3;
165
+ yIdx = Simt::UintDiv(yIdx, m3, s3);
166
+ uint32_t inputIndex4 = yIdx - Simt::UintDiv(yIdx, m4, s4) * outputShape4;
167
+ yIdx = Simt::UintDiv(yIdx, m4, s4);
168
+ uint32_t inputIndex5 = yIdx - Simt::UintDiv(yIdx, m5, s5) * outputShape5;
169
+ uint32_t xIdx = inputIndex0 * dstStride0 + inputIndex1 * dstStride1 + inputIndex2 * dstStride2 +
170
+ inputIndex3 * dstStride3 + inputIndex4 * dstStride4 + inputIndex5 * dstStride5;
171
+ outputGM[coreOffset + idx] = inputGM[xIdx];
172
+ }
173
+ }
174
+
175
+ template <typename T>
176
+ __simt_vf__ LAUNCH_BOUND(THREAD_DIM) __aicore__
177
+ void SimtComputeDimSeven(__gm__ T* inputGM, __gm__ volatile T* outputGM, uint32_t coreFactor, uint32_t coreOffset,
178
+ uint32_t outputShape0, uint32_t outputShape1, uint32_t outputShape2, uint32_t outputShape3,
179
+ uint32_t outputShape4, uint32_t outputShape5, uint32_t outputShape6, uint32_t dstStride0,
180
+ uint32_t dstStride1, uint32_t dstStride2, uint32_t dstStride3, uint32_t dstStride4,
181
+ uint32_t dstStride5, uint32_t dstStride6, uint32_t m0, uint32_t m1, uint32_t m2,
182
+ uint32_t m3, uint32_t m4, uint32_t m5, uint32_t m6, uint32_t s0, uint32_t s1, uint32_t s2,
183
+ uint32_t s3, uint32_t s4, uint32_t s5, uint32_t s6)
184
+ {
185
+ for (uint32_t idx = static_cast<uint32_t>(threadIdx.x); idx < coreFactor;
186
+ idx += static_cast<uint32_t>(blockDim.x)) {
187
+ uint32_t yIdx = coreOffset + idx;
188
+ uint32_t inputIndex0 = yIdx - Simt::UintDiv(yIdx, m0, s0) * outputShape0;
189
+ yIdx = Simt::UintDiv(yIdx, m0, s0);
190
+ uint32_t inputIndex1 = yIdx - Simt::UintDiv(yIdx, m1, s1) * outputShape1;
191
+ yIdx = Simt::UintDiv(yIdx, m1, s1);
192
+ uint32_t inputIndex2 = yIdx - Simt::UintDiv(yIdx, m2, s2) * outputShape2;
193
+ yIdx = Simt::UintDiv(yIdx, m2, s2);
194
+ uint32_t inputIndex3 = yIdx - Simt::UintDiv(yIdx, m3, s3) * outputShape3;
195
+ yIdx = Simt::UintDiv(yIdx, m3, s3);
196
+ uint32_t inputIndex4 = yIdx - Simt::UintDiv(yIdx, m4, s4) * outputShape4;
197
+ yIdx = Simt::UintDiv(yIdx, m4, s4);
198
+ uint32_t inputIndex5 = yIdx - Simt::UintDiv(yIdx, m5, s5) * outputShape5;
199
+ yIdx = Simt::UintDiv(yIdx, m5, s5);
200
+ uint32_t inputIndex6 = yIdx - Simt::UintDiv(yIdx, m6, s6) * outputShape6;
201
+ uint32_t xIdx = inputIndex0 * dstStride0 + inputIndex1 * dstStride1 + inputIndex2 * dstStride2 +
202
+ inputIndex3 * dstStride3 + inputIndex4 * dstStride4 + inputIndex5 * dstStride5 +
203
+ inputIndex6 * dstStride6;
204
+ outputGM[coreOffset + idx] = inputGM[xIdx];
205
+ }
206
+ }
207
+
208
+ template <typename T>
209
+ __simt_vf__ LAUNCH_BOUND(THREAD_DIM) __aicore__
210
+ void SimtComputeDimEight(__gm__ T* inputGM, __gm__ volatile T* outputGM, uint32_t coreFactor, uint32_t coreOffset,
211
+ uint32_t outputShape0, uint32_t outputShape1, uint32_t outputShape2, uint32_t outputShape3,
212
+ uint32_t outputShape4, uint32_t outputShape5, uint32_t outputShape6, uint32_t outputShape7,
213
+ uint32_t dstStride0, uint32_t dstStride1, uint32_t dstStride2, uint32_t dstStride3,
214
+ uint32_t dstStride4, uint32_t dstStride5, uint32_t dstStride6, uint32_t dstStride7,
215
+ uint32_t m0, uint32_t m1, uint32_t m2, uint32_t m3, uint32_t m4, uint32_t m5, uint32_t m6,
216
+ uint32_t m7, uint32_t s0, uint32_t s1, uint32_t s2, uint32_t s3, uint32_t s4, uint32_t s5,
217
+ uint32_t s6, uint32_t s7)
218
+ {
219
+ for (uint32_t idx = static_cast<uint32_t>(threadIdx.x); idx < coreFactor;
220
+ idx += static_cast<uint32_t>(blockDim.x)) {
221
+ uint32_t yIdx = coreOffset + idx;
222
+ uint32_t inputIndex0 = yIdx - Simt::UintDiv(yIdx, m0, s0) * outputShape0;
223
+ yIdx = Simt::UintDiv(yIdx, m0, s0);
224
+ uint32_t inputIndex1 = yIdx - Simt::UintDiv(yIdx, m1, s1) * outputShape1;
225
+ yIdx = Simt::UintDiv(yIdx, m1, s1);
226
+ uint32_t inputIndex2 = yIdx - Simt::UintDiv(yIdx, m2, s2) * outputShape2;
227
+ yIdx = Simt::UintDiv(yIdx, m2, s2);
228
+ uint32_t inputIndex3 = yIdx - Simt::UintDiv(yIdx, m3, s3) * outputShape3;
229
+ yIdx = Simt::UintDiv(yIdx, m3, s3);
230
+ uint32_t inputIndex4 = yIdx - Simt::UintDiv(yIdx, m4, s4) * outputShape4;
231
+ yIdx = Simt::UintDiv(yIdx, m4, s4);
232
+ uint32_t inputIndex5 = yIdx - Simt::UintDiv(yIdx, m5, s5) * outputShape5;
233
+ yIdx = Simt::UintDiv(yIdx, m5, s5);
234
+ uint32_t inputIndex6 = yIdx - Simt::UintDiv(yIdx, m6, s6) * outputShape6;
235
+ yIdx = Simt::UintDiv(yIdx, m6, s6);
236
+ uint32_t inputIndex7 = yIdx - Simt::UintDiv(yIdx, m7, s7) * outputShape7;
237
+ uint32_t xIdx = inputIndex0 * dstStride0 + inputIndex1 * dstStride1 + inputIndex2 * dstStride2 +
238
+ inputIndex3 * dstStride3 + inputIndex4 * dstStride4 + inputIndex5 * dstStride5 +
239
+ inputIndex6 * dstStride6 + inputIndex7 * dstStride7;
240
+ outputGM[coreOffset + idx] = inputGM[xIdx];
241
+ }
242
+ }
243
+
244
+ template <typename T>
245
+ __aicore__ inline void TransposeSmallShape<T>::Process()
246
+ {
247
+ if (blockIdx_ >= tilingData_->realCoreNum) {
248
+ return;
249
+ }
250
+ uint32_t blkProcessNum = tilingData_->blkFactor;
251
+ uint32_t blkStartOffset = blockIdx_ * tilingData_->blkFactor;
252
+ if (blockIdx_ == tilingData_->realCoreNum - 1 && tilingData_->blkTailFactor != 0) {
253
+ blkProcessNum = tilingData_->blkTailFactor;
254
+ }
255
+
256
+ uint32_t permSize = tilingData_->permSize;
257
+ uint32_t outputShape[8] = {0, 0, 0, 0, 0, 0, 0, 0};
258
+ uint32_t dstStride[8] = {1, 1, 1, 1, 1, 1, 1, 1};
259
+ uint32_t dstStrideTmp[8] = {1, 1, 1, 1, 1, 1, 1, 1};
260
+
261
+ for (uint32_t i = 1; i < permSize; i++) {
262
+ dstStrideTmp[i] = tilingData_->inputShape[permSize - i] * dstStrideTmp[i - 1];
263
+ }
264
+ for (uint32_t i = 0; i < permSize; i++) {
265
+ outputShape[i] = tilingData_->outputShape[permSize - 1 - i];
266
+ dstStride[i] = dstStrideTmp[permSize - 1 - tilingData_->perm[permSize - 1 - i]];
267
+ }
268
+
269
+ uint32_t shift[8];
270
+ uint32_t m[8];
271
+ for (uint32_t i = 0; i < permSize; i++) {
272
+ GetUintDivMagicAndShift(m[i], shift[i], outputShape[i]);
273
+ }
274
+
275
+ if (permSize == DIM_TWO) {
276
+ asc_vf_call<SimtComputeDimTwo<T>>(dim3(THREAD_DIM), (__gm__ T*)(inputGM_.GetPhyAddr()),
277
+ (__gm__ volatile T*)(outputGM_.GetPhyAddr()), blkProcessNum, blkStartOffset,
278
+ outputShape[0], outputShape[1], m[0], m[1], shift[0], shift[1]);
279
+ } else if (permSize == DIM_THREE) {
280
+ asc_vf_call<SimtComputeDimThree<T>>(dim3(THREAD_DIM), (__gm__ T*)(inputGM_.GetPhyAddr()),
281
+ (__gm__ volatile T*)(outputGM_.GetPhyAddr()), blkProcessNum, blkStartOffset,
282
+ outputShape[0], outputShape[1], outputShape[2], dstStride[0], dstStride[1],
283
+ dstStride[2], m[0], m[1], m[2], shift[0], shift[1], shift[2]);
284
+ } else if (permSize == DIM_FOUR) {
285
+ asc_vf_call<SimtComputeDimFour<T>>(
286
+ dim3(THREAD_DIM), (__gm__ T*)(inputGM_.GetPhyAddr()), (__gm__ volatile T*)(outputGM_.GetPhyAddr()),
287
+ blkProcessNum, blkStartOffset, outputShape[0], outputShape[1], outputShape[2], outputShape[3], dstStride[0],
288
+ dstStride[1], dstStride[2], dstStride[3], m[0], m[1], m[2], m[3], shift[0], shift[1], shift[2], shift[3]);
289
+ } else if (permSize == DIM_FIVE) {
290
+ asc_vf_call<SimtComputeDimFive<T>>(
291
+ dim3(THREAD_DIM), (__gm__ T*)(inputGM_.GetPhyAddr()), (__gm__ volatile T*)(outputGM_.GetPhyAddr()),
292
+ blkProcessNum, blkStartOffset, outputShape[0], outputShape[1], outputShape[2], outputShape[3],
293
+ outputShape[4], dstStride[0], dstStride[1], dstStride[2], dstStride[3], dstStride[4], m[0], m[1], m[2],
294
+ m[3], m[4], shift[0], shift[1], shift[2], shift[3], shift[4]);
295
+ } else if (permSize == DIM_SIX) {
296
+ asc_vf_call<SimtComputeDimSix<T>>(dim3(THREAD_DIM), (__gm__ T*)(inputGM_.GetPhyAddr()),
297
+ (__gm__ volatile T*)(outputGM_.GetPhyAddr()), blkProcessNum, blkStartOffset,
298
+ outputShape[0], outputShape[1], outputShape[2], outputShape[3],
299
+ outputShape[4], outputShape[5], dstStride[0], dstStride[1], dstStride[2],
300
+ dstStride[3], dstStride[4], dstStride[5], m[0], m[1], m[2], m[3], m[4], m[5],
301
+ shift[0], shift[1], shift[2], shift[3], shift[4], shift[5]);
302
+ } else if (permSize == DIM_SEVEN) {
303
+ asc_vf_call<SimtComputeDimSeven<T>>(
304
+ dim3(THREAD_DIM), (__gm__ T*)(inputGM_.GetPhyAddr()), (__gm__ volatile T*)(outputGM_.GetPhyAddr()),
305
+ blkProcessNum, blkStartOffset, outputShape[0], outputShape[1], outputShape[2], outputShape[3],
306
+ outputShape[4], outputShape[5], outputShape[6], dstStride[0], dstStride[1], dstStride[2], dstStride[3],
307
+ dstStride[4], dstStride[5], dstStride[6], m[0], m[1], m[2], m[3], m[4], m[5], m[6], shift[0], shift[1],
308
+ shift[2], shift[3], shift[4], shift[5], shift[6]);
309
+ } else if (permSize == DIM_EIGHT) {
310
+ asc_vf_call<SimtComputeDimEight<T>>(
311
+ dim3(THREAD_DIM), (__gm__ T*)(inputGM_.GetPhyAddr()), (__gm__ volatile T*)(outputGM_.GetPhyAddr()),
312
+ blkProcessNum, blkStartOffset, outputShape[0], outputShape[1], outputShape[2], outputShape[3],
313
+ outputShape[4], outputShape[5], outputShape[6], outputShape[7], dstStride[0], dstStride[1], dstStride[2],
314
+ dstStride[3], dstStride[4], dstStride[5], dstStride[6], dstStride[7], m[0], m[1], m[2], m[3], m[4], m[5],
315
+ m[6], m[7], shift[0], shift[1], shift[2], shift[3], shift[4], shift[5], shift[6], shift[7]);
316
+ }
317
+ }
318
+
319
+ } // namespace Transpose
320
+
321
+ #endif // TRANSPOSE_SMALL_SHAPE_H