已合并
get_sort #56
li_zeran创建于 1月1日
get_sort #56
已合并
li_zeran创建于 1月1日
11 个文件变更+273-1
Adocs/python-api/language/generated/asc.language.basic.get_sort_len.md+32-0
@@ -0,0 +1,32 @@
1+# asc.language.basic.get_sort_len
2+ 
3+### asc.language.basic.get_sort_len(elem_count: int) → int
4+ 
5+获取排序结构中的排序长度。
6+ 
7+**对应的 Ascend C 函数原型**
8+ 
9+```c++
10+namespace AscendC {
11+template <typename T>
12+__aicore__ inline uint32_t GetSortLen(const uint32_t elemCount);
13+} // namespace AscendC
14+```
15+ 
16+**参数说明**
17+ 
18+elem_count: 参与排序的元素个数。
19+ 
20+**返回值说明**
21+ 
22+int: 排序长度。
23+ 
24+**约束说明**
25+ 
26+elem_count 必须为 32 位无符号整数。
27+ 
28+**调用示例**
29+ 
30+```python
31+length = asc.get_sort_len(100)
32+```
Adocs/python-api/language/generated/asc.language.basic.get_sort_offset.md+32-0
@@ -0,0 +1,32 @@
1+# asc.language.basic.get_sort_offset
2+ 
3+### asc.language.basic.get_sort_offset(elem_offset: int) → int
4+ 
5+获取排序结构中的排序偏移量。
6+ 
7+**对应的 Ascend C 函数原型**
8+ 
9+```c++
10+namespace AscendC {
11+template <typename T>
12+__aicore__ inline uint32_t GetSortOffset(const uint32_t elemOffset);
13+} // namespace AscendC
14+```
15+ 
16+**参数说明**
17+ 
18+elem_offset: 元素的偏移量。必须为32位无符号整数。
19+ 
20+**返回值说明**
21+ 
22+int: 排序偏移量
23+ 
24+**约束说明**
25+ 
26+elem_offset 必须为 32 位无符号整数。
27+ 
28+**调用示例**
29+ 
30+```python
31+offset = asc.get_sort_offset(10)
32+```
Mdocs/python-api/rst/language/basic.rst+2-0
@@ -47,6 +47,8 @@ Common operations
47 get_mrg_sort_result47 get_mrg_sort_result
48 get_program_counter48 get_program_counter
49 get_store_atomic_config49 get_store_atomic_config
50+ get_sort_len
51+ get_sort_offset
50 get_sub_block_idx52 get_sub_block_idx
51 get_system_cycle53 get_system_cycle
52 get_sys_workspace54 get_sys_workspace
Minclude/ascir/Dialect/Asc/IR/Basic/OpProposal.td+13-0
@@ -20,6 +20,19 @@ include "mlir/Interfaces/CastInterfaces.td"
20include "mlir/Interfaces/SideEffectInterfaces.td"20include "mlir/Interfaces/SideEffectInterfaces.td"
21include "mlir/IR/OpBase.td"21include "mlir/IR/OpBase.td"
22 22 
23+def AscendC_GetSortOffsetOp : VectorOp<"get_sort_offset", "GetSortOffset<float>", [AscFunc]> {
24+ let description = "Get sort offset in the sorted structure";
25+ let arguments = (ins UI32:$elemOffset);
26+ let results = (outs UI32:$result);
27+}
28+
29+
30+def AscendC_GetSortLenOp : VectorOp<"get_sort_len", "GetSortLen<float>", [AscFunc]> {
31+ let description = "Get sort length in the sorted structure";
32+ let arguments = (ins UI32:$elemCount);
K
Kkong08081月9日

let arguments = (ins UI32:$elemCount); 缩进跟其他行不一致

likedislike
33+ let results = (outs UI32:$result);
34+}
35+ 
23def AscendC_MrgSortSrcListOp : AscendC_Op<"mrg_sort_src_list", [AscConstructor]> {36def AscendC_MrgSortSrcListOp : AscendC_Op<"mrg_sort_src_list", [AscConstructor]> {
24 let summary = "Instantiate MrgSortSrcList";37 let summary = "Instantiate MrgSortSrcList";
25 let results = (outs AscendC_MrgSortSrcList:$params);38 let results = (outs AscendC_MrgSortSrcList:$params);
Mpython/asc/language/__init__.py+2-0
@@ -137,6 +137,8 @@ from .basic.vec_gather_mask import gather_mask, get_gather_mask_remain_count
137from .basic.vec_transpose import transpose, trans_data_to_5hd137from .basic.vec_transpose import transpose, trans_data_to_5hd
138from .basic.proposal import (138from .basic.proposal import (
139 get_mrg_sort_result,139 get_mrg_sort_result,
140+ get_sort_len,
K
Kkong08081月9日

子典序,下面都是

get_sort_len,
get_sort_offset,
likedislike
141+ get_sort_offset,
140 mrg_sort,142 mrg_sort,
141 mrg_sort4,143 mrg_sort4,
142 proposal_concat,144 proposal_concat,
Mpython/asc/language/basic/__init__.py+5-0
@@ -130,6 +130,8 @@ from .vec_gather import (
130from .vec_gather_mask import gather_mask, get_gather_mask_remain_count130from .vec_gather_mask import gather_mask, get_gather_mask_remain_count
131from .proposal import (131from .proposal import (
132 get_mrg_sort_result,132 get_mrg_sort_result,
133+ get_sort_len,
134+ get_sort_offset,
133 mrg_sort,135 mrg_sort,
134 mrg_sort4,136 mrg_sort4,
135 proposal_concat,137 proposal_concat,
@@ -242,6 +244,9 @@ __all__ = [
242 "set_load_data_boundary",244 "set_load_data_boundary",
243 "set_load_data_padding_value",245 "set_load_data_padding_value",
244 "set_load_data_repeat",246 "set_load_data_repeat",
247+ # .proposal
248+ "get_sort_len",
249+ "get_sort_offset",
245 # .scalar250 # .scalar
246 "count_bits_cnt_same_as_sign_bit",251 "count_bits_cnt_same_as_sign_bit",
247 "scalar_cast", 252 "scalar_cast",
Mpython/asc/language/basic/proposal.py+40-0
@@ -14,6 +14,46 @@ from ..core.utils import DefaultValued, require_jit, global_builder, OverloadDis
14from .utils import set_common_docstring14from .utils import set_common_docstring
15 15 
16 16 
17+@overload
18+def get_sort_len(elem_count: int) -> RuntimeInt:
19+ ...
20+ 
21+ 
22+@overload
23+def get_sort_len(elem_count: RuntimeInt) -> RuntimeInt:
24+ ...
25+ 
26+ 
27+@require_jit
28+@set_common_docstring(api_name="get_sort_len")
29+def get_sort_len(elem_count):
30+ builder = global_builder.get_ir_builder()
31+ return builder.create_asc_GetSortLenOp(
32+ builder.get_ui32_type(),
33+ _mat(elem_count, KT.uint32).to_ir()
34+ )
35+ 
36+ 
37+@overload
38+def get_sort_offset(elem_offset: int) -> RuntimeInt:
39+ ...
40+ 
41+ 
42+@overload
43+def get_sort_offset(elem_offset: RuntimeInt) -> RuntimeInt:
44+ ...
45+ 
46+ 
47+@require_jit
48+@set_common_docstring(api_name="get_sort_offset")
49+def get_sort_offset(elem_offset):
50+ builder = global_builder.get_ir_builder()
51+ return builder.create_asc_GetSortOffsetOp(
52+ builder.get_ui32_type(),
53+ _mat(elem_offset, KT.uint32).to_ir()
54+ )
55+ 
56+ 
17@overload57@overload
18def get_mrg_sort_result() -> tuple[int, int, int, int]:58def get_mrg_sort_result() -> tuple[int, int, int, int]:
19 ...59 ...
Mpython/asc/language/basic/utils.py+94-0
@@ -1736,6 +1736,98 @@ def get_program_counter_docstring():
1736 return [func_introduction, cpp_signature, param_list, "", "", py_example]1736 return [func_introduction, cpp_signature, param_list, "", "", py_example]
1737 1737 
1738 1738 
1739+def get_sort_len_docstring():
1740+ func_introduction = """
1741+ Get sort length in the sorted structure.
1742+ """
1743+ 
1744+ cpp_signature = """
1745+ **对应的 Ascend C 函数原型**
1746+ 
1747+ .. code-block:: c++
1748+ 
1749+ namespace AscendC {
1750+ 
1751+ template <typename T>
1752+ __aicore__ inline uint32_t GetSortLen(const uint32_t elemCount);
1753+ 
1754+ } // namespace AscendC
1755+ """
1756+ 
1757+ param_list = """
1758+ **参数说明**
1759+ 
1760+ 无。
1761+ """
1762+ 
1763+ return_list = """
1764+ **返回值说明**
1765+ 
1766+ int: The sort length.
1767+ """
1768+ 
1769+ constraint_list = """
1770+ **约束说明**
1771+ 
1772+ - elem_count must be a 32-bit unsigned integer.
1773+ """
1774+ 
1775+ py_example = """
1776+ **调用示例**
1777+
1778+ .. code-block:: python
1779+ 
1780+ length = asc.get_sort_len(100)
1781+ """
1782+ return [func_introduction, cpp_signature, param_list, return_list, constraint_list, py_example]
1783+ 
1784+ 
1785+def get_sort_offset_docstring():
1786+ func_introduction = """
1787+ Get sort offset in the sorted structure.
1788+ """
1789+ 
1790+ cpp_signature = """
1791+ **对应的 Ascend C 函数原型**
1792+ 
1793+ .. code-block:: c++
1794+ 
1795+ namespace AscendC {
1796+ 
1797+ template <typename T>
1798+ __aicore__ inline uint32_t GetSortOffset(const uint32_t elemOffset);
1799+ 
1800+ } // namespace AscendC
1801+ """
1802+ 
1803+ param_list = """
1804+ **参数说明**
1805+ 
1806+ 无。
1807+ """
1808+ 
1809+ return_list = """
1810+ **返回值说明**
1811+ 
1812+ int: The sort offset.
1813+ """
1814+ 
1815+ constraint_list = """
1816+ **约束说明**
1817+ 
1818+ - elem_offset must be a 32-bit unsigned integer.
1819+ """
1820+ 
1821+ py_example = """
1822+ **调用示例**
1823+ 
1824+ .. code-block:: python
1825+ 
1826+ offset = asc.get_sort_offset(10)
1827+ """
1828+ return [func_introduction, cpp_signature, param_list, return_list, constraint_list, py_example]
1829+ 
1830+ 
1739def get_sub_block_idx_docstring():1831def get_sub_block_idx_docstring():
1740 func_introduction = """1832 func_introduction = """
1741 获取 AI Core 上 Vector 核的 ID。1833 获取 AI Core 上 Vector 核的 ID。
@@ -7855,6 +7947,8 @@ DOC_HANDLES = {
7855 "get_mrg_sort_result": get_mrg_sort_result_docstring, 7947 "get_mrg_sort_result": get_mrg_sort_result_docstring,
7856 "get_program_counter": get_program_counter_docstring,7948 "get_program_counter": get_program_counter_docstring,
7857 "get_store_atomic_config": get_store_atomic_config_docstring,7949 "get_store_atomic_config": get_store_atomic_config_docstring,
7950+ "get_sort_len": get_sort_len_docstring,
7951+ "get_sort_offset": get_sort_offset_docstring,
7858 "get_sub_block_idx": get_sub_block_idx_docstring,7952 "get_sub_block_idx": get_sub_block_idx_docstring,
7859 "get_sys_workspace": get_sys_workspace_docstring,7953 "get_sys_workspace": get_sys_workspace_docstring,
7860 "get_system_cycle": get_system_cycle_docstring,7954 "get_system_cycle": get_system_cycle_docstring,
Mpython/test/unit/language/basic/test_common_api.py+1-1
@@ -338,7 +338,7 @@ def test_get_data_block_size_in_bytes(mock_launcher_run):
338 338 
339 kernel_get_data_block_size_in_bytes[1]()339 kernel_get_data_block_size_in_bytes[1]()
340 assert mock_launcher_run.call_count == 1340 assert mock_launcher_run.call_count == 1
341- 341+ 
342 342 
343def test_get_sub_block_idx(mock_launcher_run):343def test_get_sub_block_idx(mock_launcher_run):
344 344 
Apython/test/unit/language/basic/test_proposal.py+34-0
@@ -0,0 +1,34 @@
1+# Copyright (c) 2025 ISE Group, Harbin Institute of Technology.
2+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
3+# CANN Open Software License Agreement Version 2.0 (the "License").
4+# Please refer to the License for details. You may not use this file except in compliance with the License.
5+# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
6+# 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+import asc
10+from asc.runtime import config
11+ 
12+ 
13+def setup_function():
14+ config.set_platform(config.Backend.Model, check=False)
15+
16+ 
17+def test_get_sort_len(mock_launcher_run):
18+
19+ @asc.jit
20+ def kernel_get_sort_len() -> None:
21+ length = asc.get_sort_len(100)
22+
23+ kernel_get_sort_len[1]()
24+ assert mock_launcher_run.call_count == 1
25+ 
26+ 
27+def test_get_sort_offset(mock_launcher_run):
28+
29+ @asc.jit
30+ def kernel_get_sort_offset() -> None:
31+ offset = asc.get_sort_offset(10)
32+
33+ kernel_get_sort_offset[1]()
34+ assert mock_launcher_run.call_count == 1
Mtest/Target/AscendC/basic/vec_proposal.mlir+18-0
@@ -7,6 +7,24 @@
7// See LICENSE in the root of the software repository for the full text of the License.7// See LICENSE in the root of the software repository for the full text of the License.
8 8 
9// RUN: ascir-translate -mlir-to-ascendc %s | FileCheck %s9// RUN: ascir-translate -mlir-to-ascendc %s | FileCheck %s
10+
11+// CHECK-LABEL: void emit_get_sort_len(uint32_t v1) {
12+// CHECK-NEXT: AscendC::GetSortLen<float>(v1);
13+// CHECK-NEXT: return;
14+// CHECK-NEXT: }
15+func.func @emit_get_sort_len(%arg0: ui32) {
16+ %0 = ascendc.get_sort_len %arg0 : ui32
17+ return
18+}
19+ 
20+// CHECK-LABEL: void emit_get_sort_offset(uint32_t v1) {
21+// CHECK-NEXT: AscendC::GetSortOffset<float>(v1);
22+// CHECK-NEXT: return;
23+// CHECK-NEXT: }
24+func.func @emit_get_sort_offset(%arg0: ui32) {
25+ %0 = ascendc.get_sort_offset %arg0 : ui32
26+ return
27+}
10 28 
11// CHECK-LABEL:void emit_mrg_sort(AscendC::LocalTensor<float> v1, AscendC::LocalTensor<float> v2, AscendC::LocalTensor<float> v3, AscendC::LocalTensor<float> v4, AscendC::LocalTensor<float> v5, uint16_t v6, uint16_t v7, uint16_t v8, uint16_t v9, uint32_t v10, uint32_t v11, uint32_t v12, uint32_t v13, int16_t v14, int32_t v15) {29// CHECK-LABEL:void emit_mrg_sort(AscendC::LocalTensor<float> v1, AscendC::LocalTensor<float> v2, AscendC::LocalTensor<float> v3, AscendC::LocalTensor<float> v4, AscendC::LocalTensor<float> v5, uint16_t v6, uint16_t v7, uint16_t v8, uint16_t v9, uint32_t v10, uint32_t v11, uint32_t v12, uint32_t v13, int16_t v14, int32_t v15) {
12// CHECK-NEXT: AscendC::MrgSortSrcList<float> v16{v2, v3, v4, v5};30// CHECK-NEXT: AscendC::MrgSortSrcList<float> v16{v2, v3, v4, v5};