Skip to content

Commit 662e362

Browse files
committed
[KUNLUNXIN] speed up compare ops
1 parent 9dafe3a commit 662e362

6 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/flag_gems/runtime/backend/_kunlunxin/ops/ge.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
True,
1717
prefer_1d_tile=True,
1818
isCloseMemoryAsync=False,
19+
KunlunAtuoGrid=True,
20+
unroll_num=8,
1921
)
2022

2123

src/flag_gems/runtime/backend/_kunlunxin/ops/gt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
True,
1818
prefer_1d_tile=True,
1919
isCloseMemoryAsync=False,
20+
KunlunAtuoGrid=True,
21+
unroll_num=8,
2022
)
2123

2224

src/flag_gems/runtime/backend/_kunlunxin/ops/le.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
True,
1818
prefer_1d_tile=True,
1919
isCloseMemoryAsync=False,
20+
KunlunAtuoGrid=True,
21+
unroll_num=8,
2022
)
2123

2224

src/flag_gems/runtime/backend/_kunlunxin/ops/lt.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
True,
1717
prefer_1d_tile=True,
1818
isCloseMemoryAsync=False,
19+
unroll_num=8,
20+
KunlunAtuoGrid=True,
1921
)
2022

2123

src/flag_gems/runtime/backend/_kunlunxin/utils/codegen_config_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class CodeGenConfig:
4646
isCloseDtypeConvert: bool = False
4747
isCloseMemoryAsync: bool = True
4848
isCloseInterleave: bool = False
49+
KunlunAtuoGrid: bool = False
4950
buffer_size_limit: int = 0
5051
unroll_num: int = 0
5152

src/flag_gems/runtime/backend/_kunlunxin/utils/pointwise_dynamic.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,9 +867,19 @@ def gen_task_partition_1d(self, code: IndentedBuffer):
867867
code.writeline("num_tiles = triton.cdiv(num_tasks, tile_size)")
868868
# max_grid_size0 = self.config.max_grid_size[0]
869869
# code.writeline(f"num_ctas = min({max_grid_size0}, num_tiles)")
870-
871-
code.writeline("num_ctas = 12 # XPU BLOCK_NUM")
872-
code.writeline("num_tiles = 12 # XPU BLOCK_NUM")
870+
determine_num_ctas_and_tiles = [
871+
"if sum(out0.shape) <= 2048*64:",
872+
" num_ctas = 1 # XPU BLOCK_NUM",
873+
" num_tiles = 1 # XPU BLOCK_NUM",
874+
"else:",
875+
" num_ctas = 12 # XPU BLOCK_NUM",
876+
" num_tiles = 12 # XPU BLOCK_NUM",
877+
]
878+
if self.config.KunlunAtuoGrid is True:
879+
code.writelines(determine_num_ctas_and_tiles)
880+
else:
881+
code.writeline("num_ctas = 12 # XPU BLOCK_NUM")
882+
code.writeline("num_tiles = 12 # XPU BLOCK_NUM")
873883
code.writeline(
874884
"tile_size = triton.next_power_of_2(triton.cdiv(num_tasks, num_tiles)) # XPU BLOCK_NUM"
875885
)

0 commit comments

Comments
 (0)