@@ -36,7 +36,7 @@ void topk_softmax_asm(torch::Tensor& topk_weights, // [num_tokens, topk]
3636 const uint num_tokens = gating_output.numel () / num_experts;
3737 const uint topk = topk_weights.size (-1 );
3838 const uint out_stride = topk_weights.stride (0 );
39- const uint SUBM = 4 ;
39+ const uint SUBM = num_tokens < 10000 ? 4 : 12 ;
4040
4141 KernelArgs args;
4242 size_t arg_size = sizeof (args);
@@ -53,36 +53,73 @@ void topk_softmax_asm(torch::Tensor& topk_weights, // [num_tokens, topk]
5353 AiterAsmKernel* impl_ptr = nullptr ;
5454 if (num_experts == 128 && topk == 8 )
5555 {
56- static AiterAsmKernel impl_topksoftmax_4x128x8 (" _ZN5aiter19topksoftmax_4x128x8E" ,
57- " /topksoftmax/topksoftmax_4x128x8.co" );
58- impl_ptr = &impl_topksoftmax_4x128x8;
56+ if (SUBM == 4 )
57+ {
58+ static AiterAsmKernel impl_topksoftmax_4x128x8 (" _ZN5aiter19topksoftmax_4x128x8E" ,
59+ " /topksoftmax/topksoftmax_4x128x8.co" );
60+ impl_ptr = &impl_topksoftmax_4x128x8;
61+ }
62+ else
63+ {
64+ static AiterAsmKernel impl_topksoftmax_12x128x8 (" _ZN5aiter20topksoftmax_12x128x8E" ,
65+ " /topksoftmax/topksoftmax_12x128x8.co" );
66+ impl_ptr = &impl_topksoftmax_12x128x8;
67+ }
5968 }
6069 else if (num_experts == 256 && topk == 8 )
6170 {
62- static AiterAsmKernel impl_topksoftmax_4x256x8 (" _ZN5aiter19topksoftmax_4x256x8E" ,
63- " /topksoftmax/topksoftmax_4x256x8.co" );
64- impl_ptr = &impl_topksoftmax_4x256x8;
71+ if (SUBM == 4 )
72+ {
73+ static AiterAsmKernel impl_topksoftmax_4x256x8 (" _ZN5aiter19topksoftmax_4x256x8E" ,
74+ " /topksoftmax/topksoftmax_4x256x8.co" );
75+ impl_ptr = &impl_topksoftmax_4x256x8;
76+ }
77+ else
78+ {
79+ static AiterAsmKernel impl_topksoftmax_12x256x8 (" _ZN5aiter20topksoftmax_12x256x8E" ,
80+ " /topksoftmax/topksoftmax_12x256x8.co" );
81+ impl_ptr = &impl_topksoftmax_12x256x8;
82+ }
6583 }
6684 else if (num_experts == 128 && topk == 6 )
6785 {
68- static AiterAsmKernel impl_topksoftmax_4x128x6 (" _ZN5aiter19topksoftmax_4x128x6E" ,
69- " /topksoftmax/topksoftmax_4x128x6.co" );
70- impl_ptr = &impl_topksoftmax_4x128x6;
86+ if (SUBM == 4 )
87+ {
88+ static AiterAsmKernel impl_topksoftmax_4x128x6 (" _ZN5aiter19topksoftmax_4x128x6E" ,
89+ " /topksoftmax/topksoftmax_4x128x6.co" );
90+ impl_ptr = &impl_topksoftmax_4x128x6;
91+ }
92+ else
93+ {
94+ static AiterAsmKernel impl_topksoftmax_12x128x6 (" _ZN5aiter20topksoftmax_12x128x6E" ,
95+ " /topksoftmax/topksoftmax_12x128x6.co" );
96+ impl_ptr = &impl_topksoftmax_12x128x6;
97+ }
7198 }
7299 else if (num_experts == 256 && topk == 6 )
73100 {
74- static AiterAsmKernel impl_topksoftmax_4x256x6 (" _ZN5aiter19topksoftmax_4x256x6E" ,
75- " /topksoftmax/topksoftmax_4x256x6.co" );
76- impl_ptr = &impl_topksoftmax_4x256x6;
101+ if (SUBM == 4 )
102+ {
103+ static AiterAsmKernel impl_topksoftmax_4x256x6 (" _ZN5aiter19topksoftmax_4x256x6E" ,
104+ " /topksoftmax/topksoftmax_4x256x6.co" );
105+ impl_ptr = &impl_topksoftmax_4x256x6;
106+ }
107+ else
108+ {
109+ static AiterAsmKernel impl_topksoftmax_12x256x6 (" _ZN5aiter20topksoftmax_12x256x6E" ,
110+ " /topksoftmax/topksoftmax_12x256x6.co" );
111+ impl_ptr = &impl_topksoftmax_12x256x6;
112+ }
77113 }
78114 else
79115 {
80- TORCH_CHECK (false ,
81- __func__,
82- " only support num_experts/topk in [128/6, 128/8, 256/6, 256/8], but get num_experts: " ,
83- num_experts,
84- " , topk: " ,
85- topk);
116+ TORCH_CHECK (
117+ false ,
118+ __func__,
119+ " only support num_experts/topk in [128/6, 128/8, 256/6, 256/8], but get num_experts: " ,
120+ num_experts,
121+ " , topk: " ,
122+ topk);
86123 }
87124
88125 const at::cuda::OptionalCUDAGuard device_guard (device_of (gating_output));
0 commit comments