Skip to content

Commit a33d781

Browse files
committed
Add TMA mbarrier timeline diagrams
1 parent 833b8a1 commit a33d781

6 files changed

Lines changed: 276 additions & 0 deletions

File tree

79.1 KB
Binary file not shown.
56.8 KB
Loading
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
\documentclass[tikz,border=8pt]{standalone}
2+
\usepackage[T1]{fontenc}
3+
\usepackage{lmodern}
4+
\usepackage{tikz}
5+
\usetikzlibrary{arrows.meta,calc,positioning}
6+
7+
\definecolor{ink}{HTML}{172033}
8+
\definecolor{muted}{HTML}{61708A}
9+
\definecolor{grid}{HTML}{D9E0EA}
10+
\definecolor{panel}{HTML}{F7F9FC}
11+
\definecolor{stagezero}{HTML}{2F80ED}
12+
\definecolor{stagezerofill}{HTML}{EAF3FF}
13+
\definecolor{stageone}{HTML}{E79A19}
14+
\definecolor{stageonefill}{HTML}{FFF4DD}
15+
\definecolor{fullbar}{HTML}{8E5CC7}
16+
\definecolor{emptybar}{HTML}{168B6A}
17+
18+
\begin{document}
19+
\sffamily
20+
\begin{tikzpicture}[
21+
x=1cm,
22+
y=1cm,
23+
>={Latex[length=2.1mm,width=1.35mm]},
24+
title/.style={font=\bfseries\fontsize{17}{20}\selectfont, text=ink},
25+
subtitle/.style={font=\fontsize{9}{11}\selectfont, text=muted},
26+
actor/.style={draw=grid!75!ink, fill=white, rounded corners=3pt,
27+
minimum width=3.15cm, minimum height=9mm,
28+
font=\bfseries\fontsize{9}{11}\selectfont, text=ink},
29+
lifeline/.style={densely dashed, line width=.65pt, color=grid!75!ink},
30+
issue0/.style={->, line width=1.1pt, color=stagezero},
31+
issue1/.style={->, line width=1.1pt, color=stageone},
32+
full/.style={->, line width=1.05pt, color=fullbar},
33+
empty/.style={->, line width=1.05pt, color=emptybar},
34+
msg/.style={font=\bfseries\fontsize{8}{9.5}\selectfont, fill=panel, inner sep=2pt},
35+
action0/.style={draw=stagezero, fill=stagezerofill, rounded corners=2pt,
36+
minimum width=1.15cm, minimum height=9mm},
37+
action1/.style={draw=stageone, fill=stageonefill, rounded corners=2pt,
38+
minimum width=1.15cm, minimum height=9mm},
39+
actionn/.style={draw=grid!75!ink, fill=white, rounded corners=2pt,
40+
minimum width=1.15cm, minimum height=7mm},
41+
phase/.style={font=\bfseries\fontsize{8}{10}\selectfont, text=muted,
42+
fill=panel, inner xsep=5pt},
43+
]
44+
45+
\node[title, anchor=west] at (0,1.1) {TMA mbarrier sequence};
46+
\node[subtitle, anchor=west] at (0,0.68) {time $\downarrow$};
47+
48+
\fill[panel, rounded corners=4pt] (-0.25,0.2) rectangle (14.25,-17.1);
49+
\draw[grid, rounded corners=4pt] (-0.25,0.2) rectangle (14.25,-17.1);
50+
51+
\node[actor] (producer) at (1.6,-0.45) {producer};
52+
\node[actor] (tma) at (7,-0.45) {TMA};
53+
\node[actor] (consumer) at (12.4,-0.45) {compute};
54+
55+
\draw[lifeline] (producer.south) -- (1.6,-16.5);
56+
\draw[lifeline] (tma.south) -- (7,-16.5);
57+
\draw[lifeline] (consumer.south) -- (12.4,-16.5);
58+
59+
% Prologue and first refill: S1 is issued before S0 is consumed.
60+
\node[action0] at (1.6,-1.65) {};
61+
\draw[issue0] (1.6,-1.65) -- node[msg, text=stagezero, above] {$k_0\,/\,S_0$} (7,-1.65);
62+
\node[action0] at (7,-2.05) {};
63+
64+
\node[action1] at (1.6,-2.9) {};
65+
\draw[issue1] (1.6,-2.9) -- node[msg, text=stageone, above] {$k_1\,/\,S_1$} (7,-2.9);
66+
\node[action1] at (7,-3.3) {};
67+
68+
\draw[full] (7,-4.0) -- node[msg, text=fullbar, above] {$F_0$} (12.4,-4.0);
69+
\node[action0] at (12.4,-4.75) {};
70+
\node[msg, text=stagezero] at (12.4,-4.75) {read $k_0$};
71+
\draw[empty] (12.4,-5.5) -- node[msg, text=emptybar, above] {$E_0$} (1.6,-5.5);
72+
73+
% Reuse S0 only after E0; producer phase wraps here.
74+
\draw[grid!85!ink, densely dotted] (0.3,-6.25) -- (13.7,-6.25);
75+
\node[phase] at (7,-6.25) {ring wraps};
76+
\node[action0] at (1.6,-7.0) {};
77+
\draw[issue0] (1.6,-7.0) -- node[msg, text=stagezero, above] {$k_2\,/\,S_0$} (7,-7.0);
78+
\node[action0] at (7,-7.4) {};
79+
80+
\draw[full] (7,-8.1) -- node[msg, text=fullbar, above] {$F_1$} (12.4,-8.1);
81+
\node[action1] at (12.4,-8.85) {};
82+
\node[msg, text=stageone] at (12.4,-8.85) {read $k_1$};
83+
\draw[empty] (12.4,-9.6) -- node[msg, text=emptybar, above] {$E_1$} (1.6,-9.6);
84+
85+
\node[action1] at (1.6,-10.4) {};
86+
\draw[issue1] (1.6,-10.4) -- node[msg, text=stageone, above] {$k_3\,/\,S_1$} (7,-10.4);
87+
\node[action1] at (7,-10.8) {};
88+
89+
\draw[full] (7,-11.5) -- node[msg, text=fullbar, above] {$F_0$} (12.4,-11.5);
90+
\node[action0] at (12.4,-12.25) {};
91+
\node[msg, text=stagezero] at (12.4,-12.25) {read $k_2$};
92+
\draw[empty] (12.4,-13.0) -- node[msg, text=emptybar, above] {$E_0$} (1.6,-13.0);
93+
94+
\draw[full] (7,-14.15) -- node[msg, text=fullbar, above] {$F_1$} (12.4,-14.15);
95+
\node[action1] at (12.4,-14.9) {};
96+
\node[msg, text=stageone] at (12.4,-14.9) {read $k_3$};
97+
\draw[empty] (12.4,-15.65) -- node[msg, text=emptybar, above] {$E_1$} (1.6,-15.65);
98+
99+
\node[subtitle, anchor=west, text=fullbar] at (0,-17.55) {$F_i$: data ready};
100+
\node[subtitle, anchor=west, text=emptybar] at (4.35,-17.55) {$E_i$: stage free};
101+
\node[subtitle, anchor=west] at (9.05,-17.55) {fence $\to$ sync $\to E_i$};
102+
103+
\end{tikzpicture}
104+
\end{document}
223 KB
Binary file not shown.
268 KB
Loading
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
\documentclass[tikz,border=8pt]{standalone}
2+
\usepackage[T1]{fontenc}
3+
\usepackage{lmodern}
4+
\usepackage{amsmath}
5+
\usepackage{tikz}
6+
\usetikzlibrary{arrows.meta,calc,fit,positioning,backgrounds}
7+
8+
\definecolor{ink}{HTML}{172033}
9+
\definecolor{muted}{HTML}{61708A}
10+
\definecolor{grid}{HTML}{D9E0EA}
11+
\definecolor{panel}{HTML}{F7F9FC}
12+
\definecolor{stagezero}{HTML}{2F80ED}
13+
\definecolor{stagezerofill}{HTML}{EAF3FF}
14+
\definecolor{stageone}{HTML}{E79A19}
15+
\definecolor{stageonefill}{HTML}{FFF4DD}
16+
\definecolor{fullbar}{HTML}{8E5CC7}
17+
\definecolor{emptybar}{HTML}{168B6A}
18+
\definecolor{danger}{HTML}{C94F5C}
19+
20+
\begin{document}
21+
\sffamily
22+
\begin{tikzpicture}[
23+
x=1.12cm,
24+
y=1cm,
25+
>={Latex[length=2.1mm,width=1.35mm]},
26+
title/.style={font=\bfseries\fontsize{17}{20}\selectfont, text=ink},
27+
subtitle/.style={font=\fontsize{9}{11}\selectfont, text=muted},
28+
lane label/.style={font=\bfseries\fontsize{9}{11}\selectfont, text=ink, align=right},
29+
tick/.style={font=\bfseries\fontsize{8}{10}\selectfont, text=muted},
30+
bar/.style={rounded corners=2pt, minimum height=8mm, text width=2.15cm, inner xsep=4pt,
31+
font=\fontsize{8}{9.5}\selectfont, align=center, line width=.75pt},
32+
s0/.style={bar, draw=stagezero, fill=stagezerofill, text=ink},
33+
s1/.style={bar, draw=stageone, fill=stageonefill, text=ink},
34+
neutral/.style={bar, draw=grid!90!ink, fill=white, text=ink},
35+
note/.style={draw=grid!90!ink, fill=white, rounded corners=3pt, inner sep=6pt,
36+
font=\fontsize{8}{10}\selectfont, text=ink, align=left},
37+
callout/.style={font=\fontsize{7.2}{8.8}\selectfont, text=muted, align=center},
38+
flow/.style={->, line width=.7pt, color=muted},
39+
dependency/.style={->, densely dashed, line width=.7pt, color=muted},
40+
full marker/.style={circle, draw=fullbar, fill=fullbar!12, line width=.8pt,
41+
minimum size=5.2mm, inner sep=0pt,
42+
font=\bfseries\fontsize{6.6}{7}\selectfont, text=fullbar},
43+
empty marker/.style={circle, draw=emptybar, fill=emptybar!12, line width=.8pt,
44+
minimum size=5.2mm, inner sep=0pt,
45+
font=\bfseries\fontsize{6.6}{7}\selectfont, text=emptybar},
46+
]
47+
48+
% Header
49+
\node[title, anchor=west] at (0,8.25) {Blockscaled TMA pipeline: how the mbarriers hand off each stage};
50+
\node[subtitle, anchor=west] at (0,7.82)
51+
{Two-stage main TMA path from \texttt{BlockscaledTmaGemv}; optional input-scale pipeline omitted; not cycle-accurate};
52+
53+
% Legend
54+
\node[s0, minimum width=1.45cm, minimum height=5.5mm, text width=1.15cm, anchor=west] at (12.2,7.25) {stage 0};
55+
\node[s1, minimum width=1.45cm, minimum height=5.5mm, text width=1.15cm, anchor=west] at (13.85,7.25) {stage 1};
56+
\node[full marker] (legend-full) at (15.75,7.25) {F};
57+
\node[callout, anchor=west] at (16.05,7.25) {full};
58+
\node[empty marker] (legend-empty) at (17.05,7.25) {E};
59+
\node[callout, anchor=west] at (17.35,7.25) {empty};
60+
61+
% Timeline panel and lanes
62+
\fill[panel, rounded corners=4pt] (0,1.15) rectangle (18.7,6.85);
63+
\draw[grid, rounded corners=4pt] (0,1.15) rectangle (18.7,6.85);
64+
65+
\foreach \x/\label in {2.3/setup,4.6/prologue,7.2/$k_0$,10.0/$k_1$,12.8/$k_2$,15.6/drain} {
66+
\draw[grid, densely dashed] (\x,1.35) -- (\x,6.55);
67+
\node[tick] at (\x,6.7) {\label};
68+
}
69+
70+
\node[lane label, anchor=east] at (2.05,5.95) {producer warp\\\scriptsize control path};
71+
\node[lane label, anchor=east] at (2.05,4.15) {TMA engine\\\scriptsize async proxy};
72+
\node[lane label, anchor=east] at (2.05,2.35) {compute warps\\\scriptsize generic proxy};
73+
74+
\draw[grid!80] (2.3,5.35) -- (18.35,5.35);
75+
\draw[grid!80] (2.3,3.55) -- (18.35,3.55);
76+
77+
% Producer lane
78+
\node[neutral, minimum width=1.75cm] (init) at (3.25,5.95)
79+
{initialize\\$2S$ barriers};
80+
\node[s0, minimum width=2.05cm] (p0) at (5.35,5.95)
81+
{acquire $S_0$\\issue tile $k_0$};
82+
\node[s1, minimum width=2.15cm] (p1) at (7.85,5.95)
83+
{acquire $S_1$\\issue tile $k_1$};
84+
\node[s0, minimum width=2.3cm] (p2) at (10.65,5.95)
85+
{wait $E_0$; re-arm\\issue tile $k_2$};
86+
\node[s1, minimum width=2.3cm] (p3) at (13.55,5.95)
87+
{wait $E_1$; re-arm\\issue tile $k_3$};
88+
\node[neutral, minimum width=1.55cm] (tail) at (16.45,5.95)
89+
{producer\\tail};
90+
91+
% TMA lane
92+
\node[s0, minimum width=2.25cm] (t0) at (6.0,4.15)
93+
{copy $W+X(+S_{FW})$\\into $S_0$};
94+
\node[s1, minimum width=2.25cm] (t1) at (8.6,4.15)
95+
{copy $W+X(+S_{FW})$\\into $S_1$};
96+
\node[s0, minimum width=2.25cm] (t2) at (11.4,4.15)
97+
{copy next tile\\into reused $S_0$};
98+
\node[s1, minimum width=2.25cm] (t3) at (14.3,4.15)
99+
{copy next tile\\into reused $S_1$};
100+
101+
\node[full marker] (f0a) at (7.05,4.15) {F$_0$};
102+
\node[full marker] (f1a) at (9.65,4.15) {F$_1$};
103+
\node[full marker] (f0b) at (12.45,4.15) {F$_0$};
104+
\node[full marker] (f1b) at (15.35,4.15) {F$_1$};
105+
106+
% Consumer lane
107+
\node[s0, minimum width=2.35cm] (c0) at (7.45,2.35)
108+
{wait $F_0$\\load + accumulate $k_0$};
109+
\node[s1, minimum width=2.35cm] (c1) at (10.15,2.35)
110+
{wait $F_1$\\load + accumulate $k_1$};
111+
\node[s0, minimum width=2.35cm] (c2) at (12.95,2.35)
112+
{wait $F_0$\\load + accumulate $k_2$};
113+
\node[s1, minimum width=2.35cm] (c3) at (15.85,2.35)
114+
{wait $F_1$\\load + accumulate $k_3$};
115+
116+
\node[empty marker] (e0a) at (8.55,2.35) {E$_0$};
117+
\node[empty marker] (e1a) at (11.25,2.35) {E$_1$};
118+
\node[empty marker] (e0b) at (14.05,2.35) {E$_0$};
119+
\node[empty marker] (e1b) at (16.95,2.35) {E$_1$};
120+
121+
% Issue/completion/reuse dependencies
122+
\draw[dependency] (p0.south) -- node[callout, left] {barrier ptr} (t0.north west);
123+
\draw[dependency] (p1.south) -- (t1.north west);
124+
\draw[dependency] (p2.south) -- (t2.north west);
125+
\draw[dependency] (p3.south) -- (t3.north west);
126+
127+
\draw[dependency, color=fullbar] (f0a.south) -- (c0.north);
128+
\draw[dependency, color=fullbar] (f1a.south) -- (c1.north);
129+
\draw[dependency, color=fullbar] (f0b.south) -- (c2.north);
130+
\draw[dependency, color=fullbar] (f1b.south) -- (c3.north);
131+
132+
\draw[dependency, color=emptybar] (e0a.north) to[out=90,in=-90] (p2.south);
133+
\draw[dependency, color=emptybar] (e1a.north) to[out=90,in=-90] (p3.south);
134+
135+
\node[callout, text width=2.4cm] at (17.45,4.15)
136+
{TMA completion performs\\\texttt{complete\_tx} against $F_i$};
137+
\node[callout, text width=2.6cm] at (17.35,1.55)
138+
{before $E_i$: async-shared fence, warp sync, then release};
139+
140+
% Lower explanatory panels
141+
\node[note, anchor=north west, text width=5.35cm] (contract) at (0,0.72) {
142+
\textbf{One circular stage owns two 64-bit mbarriers}\\[2pt]
143+
$F_i$ tracks ``data has arrived''; $E_i$ tracks ``consumers are done.''
144+
The kernel allocates \texttt{num\_stages * 2} \texttt{Int64} entries.
145+
};
146+
147+
\node[note, anchor=north west, text width=6.0cm] (api) at (6.05,0.72) {
148+
\textbf{CuTe pipeline API mapping}\\[2pt]
149+
\texttt{acquire\_and\_advance()} waits $E_i$ and arms $F_i$ with expected bytes.
150+
Each \texttt{cute.copy(..., tma\_bar\_ptr=...)} reports completion to $F_i$;
151+
TMA \texttt{commit()} is therefore a no-op.
152+
};
153+
154+
\node[note, anchor=north west, text width=5.75cm] (phase) at (12.75,0.72) {
155+
\textbf{Index/phase prevents stale completion}\\[2pt]
156+
For $S=2$: producer $(0,1)\!\to\!(1,1)\!\to\!(0,0)$; consumer
157+
$(0,0)\!\to\!(1,0)\!\to\!(0,1)$. The phase flips whenever the ring wraps.
158+
};
159+
160+
% Footer formula and source mapping
161+
\node[subtitle, anchor=north west, text width=18.4cm] at (0,-1.75) {
162+
\textbf{Expected transaction bytes in this kernel:}
163+
$\texttt{tx\_count}=(\texttt{block\_n}+m)\,\texttt{tile\_k\_u32}\!\times\!4
164+
+ \text{optional staged weight-scale bytes}$.
165+
Source anchors: barrier allocation and pipeline creation in
166+
\texttt{transformer\_nuggets/cute/blockscaled\_tma.py}; producer load in
167+
\texttt{tma\_producer\_load\_stage}; consumer handoff in
168+
\texttt{compute\_warp\_consume\_stage}.
169+
};
170+
171+
\end{tikzpicture}
172+
\end{document}

0 commit comments

Comments
 (0)