@@ -30,18 +30,17 @@ class WarpRole(IntEnum):
3030 TMA_PRODUCER = 0
3131
3232
33- TAG_TMA_PROLOGUE = 0
34- TAG_TMA_REFILL = 1
35- TAG_TMA_WAIT = 2
36- TAG_TILE_COMPUTE = 3
37- TAG_EPILOGUE = 4
38- MXFP8_TMA_PROFILE_TAGS = (
39- "tma_prologue" ,
40- "tma_refill" ,
41- "tma_wait" ,
42- "tile_compute" ,
43- "epilogue" ,
44- )
33+ class ProfileTag (IntEnum ):
34+ """Labeled regions emitted by the MXFP8 TMA profiler."""
35+
36+ TMA_PROLOGUE = 0
37+ TMA_REFILL = 1
38+ TMA_WAIT = 2
39+ TILE_COMPUTE = 3
40+ EPILOGUE = 4
41+
42+
43+ MXFP8_TMA_PROFILE_TAGS = tuple (tag .name .lower () for tag in ProfileTag )
4544
4645
4746@cute .jit
@@ -119,6 +118,25 @@ def w_smem_layout(self):
119118 (self .block_n , self .tile_k_u32 , self .num_stages ), order = (1 , 0 , 2 )
120119 )
121120
121+ def profile_scope (
122+ self ,
123+ prof_buf : cute .Tensor | None ,
124+ tag : ProfileTag ,
125+ pid_n : cutlass .Int32 ,
126+ event_idx ,
127+ enable_profiling : cutlass .Constexpr ,
128+ ):
129+ """Build a static-slot profiling context for one CTA region."""
130+ return profile_region (
131+ prof_buf ,
132+ cutlass .Int32 (self .max_profile_events_per_cta ),
133+ cutlass .Int32 (tag ),
134+ pid_n ,
135+ event_idx = cutlass .Int32 (event_idx ),
136+ bounds_check = False ,
137+ enabled = enable_profiling ,
138+ )
139+
122140 @cute .jit
123141 def tma_producer_load_stage (
124142 self ,
@@ -167,29 +185,24 @@ def compute_warp_consume_stage(
167185 chunk_layout : cute .Layout ,
168186 scale_layout : cute .Layout ,
169187 prof_buf : cute .Tensor | None ,
170- max_profile_events : cutlass .Int32 ,
171188 enable_profiling : cutlass .Constexpr ,
172189 ) -> tuple [pipeline .PipelineConsumer , list ]:
173190 """Wait for one stage and accumulate the rows owned by this compute warp."""
174- with profile_region (
191+ with self . profile_scope (
175192 prof_buf ,
176- max_profile_events ,
177- cutlass .Int32 (TAG_TMA_WAIT ),
193+ ProfileTag .TMA_WAIT ,
178194 pid_n ,
179- event_idx = cutlass .Int32 (2 + 3 * k_tile ),
180- bounds_check = False ,
181- enabled = enable_profiling ,
195+ 2 + 3 * k_tile ,
196+ enable_profiling ,
182197 ):
183198 full = consumer .wait_and_advance ()
184199
185- with profile_region (
200+ with self . profile_scope (
186201 prof_buf ,
187- max_profile_events ,
188- cutlass .Int32 (TAG_TILE_COMPUTE ),
202+ ProfileTag .TILE_COMPUTE ,
189203 pid_n ,
190- event_idx = cutlass .Int32 (3 + 3 * k_tile ),
191- bounds_check = False ,
192- enabled = enable_profiling ,
204+ 3 + 3 * k_tile ,
205+ enable_profiling ,
193206 ):
194207 # Each lane owns u32s [8*lane, 8*lane+8) (one 32-value scale block) as
195208 # two 16-byte LDS.128 chunks. Loading them low-first for lanes 0-3 and
@@ -316,7 +329,6 @@ def kernel(
316329 lane = tidx % 32
317330 n0 = pid_n * self .block_n
318331 owned_row_start = warp * self .rows_per_warp
319- max_profile_events = cutlass .Int32 (self .max_profile_events_per_cta )
320332 if cutlass .const_expr (enable_profiling ):
321333 assert prof_buf is not None
322334 chunk_layout = cute .make_ordered_layout ((1 , 4 ), order = (1 , 0 ))
@@ -379,14 +391,12 @@ def kernel(
379391 cute .group_modes (gX , 0 , 2 ),
380392 )
381393
382- with profile_region (
394+ with self . profile_scope (
383395 prof_buf ,
384- max_profile_events ,
385- cutlass .Int32 (TAG_TMA_PROLOGUE ),
396+ ProfileTag .TMA_PROLOGUE ,
386397 pid_n ,
387- event_idx = cutlass .Int32 (0 ),
388- bounds_check = False ,
389- enabled = enable_profiling ,
398+ 0 ,
399+ enable_profiling ,
390400 ):
391401 if warp == WarpRole .TMA_PRODUCER :
392402 producer = self .tma_producer_load_stage (
@@ -402,14 +412,12 @@ def kernel(
402412 accumulators = [cutlass .Float32 (0.0 ) for _ in range (self .rows_per_warp )]
403413 for k_tile in cutlass .range_constexpr (self .num_k_tiles ):
404414 if warp == WarpRole .TMA_PRODUCER and k_tile < self .num_k_tiles - 1 :
405- with profile_region (
415+ with self . profile_scope (
406416 prof_buf ,
407- max_profile_events ,
408- cutlass .Int32 (TAG_TMA_REFILL ),
417+ ProfileTag .TMA_REFILL ,
409418 pid_n ,
410- event_idx = cutlass .Int32 (1 + 3 * k_tile ),
411- bounds_check = False ,
412- enabled = enable_profiling ,
419+ 1 + 3 * k_tile ,
420+ enable_profiling ,
413421 ):
414422 producer = self .tma_producer_load_stage (
415423 producer ,
@@ -439,18 +447,15 @@ def kernel(
439447 chunk_layout ,
440448 scale_layout ,
441449 prof_buf ,
442- max_profile_events ,
443450 enable_profiling ,
444451 )
445452
446- with profile_region (
453+ with self . profile_scope (
447454 prof_buf ,
448- max_profile_events ,
449- cutlass .Int32 (TAG_EPILOGUE ),
455+ ProfileTag .EPILOGUE ,
450456 pid_n ,
451- event_idx = cutlass .Int32 (1 + 3 * self .num_k_tiles ),
452- bounds_check = False ,
453- enabled = enable_profiling ,
457+ 1 + 3 * self .num_k_tiles ,
458+ enable_profiling ,
454459 ):
455460 if warp == WarpRole .TMA_PRODUCER :
456461 producer .tail ()
0 commit comments