Skip to main content

ptx_parser/unparser/instruction/
membar.rs

1//! Original PTX specification:
2//!
3//! // Thread fence:
4//! fence{.sem}.scope;
5//! // Thread fence (uni-directional):
6//! fence.acquire.sync_restrict::shared::cluster.cluster;
7//! fence.release.sync_restrict::shared::cta.cluster;
8//! // Operation fence (uni-directional):
9//! fence.op_restrict.release.cluster;
10//! // Proxy fence (bi-directional):
11//! fence.proxy.proxykind;
12//! // Proxy fence (uni-directional):
13//! fence.proxy.to_proxykind::from_proxykind.release.scope;
14//! fence.proxy.to_proxykind::from_proxykind.acquire.scope  [addr], size;
15//! fence.proxy.async::generic.acquire.sync_restrict::shared::cluster.cluster;
16//! fence.proxy.async::generic.release.sync_restrict::shared::cta.cluster;
17//! // Old style membar:
18//! membar.level;
19//! membar.proxy.proxykind;
20//! .sem       = { .sc, .acq_rel, .acquire, .release };
21//! .scope     = { .cta, .cluster, .gpu, .sys };
22//! .level     = { .cta, .gl, .sys };
23//! .proxykind = { .alias, .async, .async.global, .async.shared::cta, .async.shared::cluster};
24//! .op_restrict = { .mbarrier_init };
25//! .to_proxykind::from_proxykind = {.tensormap::generic};
26
27#![allow(unused)]
28
29use crate::lexer::PtxToken;
30use crate::unparser::{PtxUnparser, common::*};
31
32pub mod section_0 {
33    use super::*;
34    use crate::r#type::instruction::membar::section_0::*;
35
36    impl PtxUnparser for FenceSemScope {
37        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
38            self.unparse_tokens_mode(tokens, false);
39        }
40        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
41            push_opcode(tokens, "fence");
42            if let Some(sem_0) = self.sem.as_ref() {
43                match sem_0 {
44                    Sem::AcqRel => {
45                        push_directive(tokens, "acq_rel");
46                    }
47                    Sem::Acquire => {
48                        push_directive(tokens, "acquire");
49                    }
50                    Sem::Release => {
51                        push_directive(tokens, "release");
52                    }
53                    Sem::Sc => {
54                        push_directive(tokens, "sc");
55                    }
56                }
57            }
58            match &self.scope {
59                Scope::Cluster => {
60                    push_directive(tokens, "cluster");
61                }
62                Scope::Cta => {
63                    push_directive(tokens, "cta");
64                }
65                Scope::Gpu => {
66                    push_directive(tokens, "gpu");
67                }
68                Scope::Sys => {
69                    push_directive(tokens, "sys");
70                }
71            }
72            tokens.push(PtxToken::Semicolon);
73            if spaced {
74                tokens.push(PtxToken::Newline);
75            }
76        }
77    }
78
79    impl PtxUnparser for FenceAcquireSyncRestrictSharedClusterCluster {
80        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
81            self.unparse_tokens_mode(tokens, false);
82        }
83        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
84            push_opcode(tokens, "fence");
85            push_directive(tokens, "acquire");
86            push_directive(tokens, "sync_restrict::shared::cluster");
87            push_directive(tokens, "cluster");
88            tokens.push(PtxToken::Semicolon);
89            if spaced {
90                tokens.push(PtxToken::Newline);
91            }
92        }
93    }
94
95    impl PtxUnparser for FenceReleaseSyncRestrictSharedCtaCluster {
96        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
97            self.unparse_tokens_mode(tokens, false);
98        }
99        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
100            push_opcode(tokens, "fence");
101            push_directive(tokens, "release");
102            push_directive(tokens, "sync_restrict::shared::cta");
103            push_directive(tokens, "cluster");
104            tokens.push(PtxToken::Semicolon);
105            if spaced {
106                tokens.push(PtxToken::Newline);
107            }
108        }
109    }
110
111    impl PtxUnparser for FenceOpRestrictReleaseCluster {
112        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
113            self.unparse_tokens_mode(tokens, false);
114        }
115        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
116            push_opcode(tokens, "fence");
117            match &self.op_restrict {
118                OpRestrict::MbarrierInit => {
119                    push_directive(tokens, "mbarrier_init");
120                }
121            }
122            push_directive(tokens, "release");
123            push_directive(tokens, "cluster");
124            tokens.push(PtxToken::Semicolon);
125            if spaced {
126                tokens.push(PtxToken::Newline);
127            }
128        }
129    }
130
131    impl PtxUnparser for FenceProxyProxykind {
132        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
133            self.unparse_tokens_mode(tokens, false);
134        }
135        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
136            push_opcode(tokens, "fence");
137            push_directive(tokens, "proxy");
138            match &self.proxykind {
139                Proxykind::AsyncSharedCluster => {
140                    push_directive(tokens, "async.shared::cluster");
141                }
142                Proxykind::AsyncSharedCta => {
143                    push_directive(tokens, "async.shared::cta");
144                }
145                Proxykind::AsyncGlobal => {
146                    push_directive(tokens, "async.global");
147                }
148                Proxykind::Alias => {
149                    push_directive(tokens, "alias");
150                }
151                Proxykind::Async => {
152                    push_directive(tokens, "async");
153                }
154            }
155            tokens.push(PtxToken::Semicolon);
156            if spaced {
157                tokens.push(PtxToken::Newline);
158            }
159        }
160    }
161
162    impl PtxUnparser for FenceProxyToProxykindFromProxykindReleaseScope {
163        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
164            self.unparse_tokens_mode(tokens, false);
165        }
166        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
167            push_opcode(tokens, "fence");
168            push_directive(tokens, "proxy");
169            match &self.to_proxykind_from_proxykind {
170                ToProxykindFromProxykind::TensormapGeneric => {
171                    push_directive(tokens, "tensormap::generic");
172                }
173            }
174            push_directive(tokens, "release");
175            match &self.scope {
176                Scope::Cluster => {
177                    push_directive(tokens, "cluster");
178                }
179                Scope::Cta => {
180                    push_directive(tokens, "cta");
181                }
182                Scope::Gpu => {
183                    push_directive(tokens, "gpu");
184                }
185                Scope::Sys => {
186                    push_directive(tokens, "sys");
187                }
188            }
189            tokens.push(PtxToken::Semicolon);
190            if spaced {
191                tokens.push(PtxToken::Newline);
192            }
193        }
194    }
195
196    impl PtxUnparser for FenceProxyToProxykindFromProxykindAcquireScope {
197        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
198            self.unparse_tokens_mode(tokens, false);
199        }
200        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
201            push_opcode(tokens, "fence");
202            push_directive(tokens, "proxy");
203            match &self.to_proxykind_from_proxykind {
204                ToProxykindFromProxykind::TensormapGeneric => {
205                    push_directive(tokens, "tensormap::generic");
206                }
207            }
208            push_directive(tokens, "acquire");
209            match &self.scope {
210                Scope::Cluster => {
211                    push_directive(tokens, "cluster");
212                }
213                Scope::Cta => {
214                    push_directive(tokens, "cta");
215                }
216                Scope::Gpu => {
217                    push_directive(tokens, "gpu");
218                }
219                Scope::Sys => {
220                    push_directive(tokens, "sys");
221                }
222            }
223            if spaced {
224                tokens.push(PtxToken::Space);
225            }
226            self.addr.unparse_tokens_mode(tokens, spaced);
227            tokens.push(PtxToken::Comma);
228            if spaced {
229                tokens.push(PtxToken::Space);
230            }
231            self.size.unparse_tokens_mode(tokens, spaced);
232            tokens.push(PtxToken::Semicolon);
233            if spaced {
234                tokens.push(PtxToken::Newline);
235            }
236        }
237    }
238
239    impl PtxUnparser for FenceProxyAsyncGenericAcquireSyncRestrictSharedClusterCluster {
240        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
241            self.unparse_tokens_mode(tokens, false);
242        }
243        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
244            push_opcode(tokens, "fence");
245            push_directive(tokens, "proxy");
246            push_directive(tokens, "async::generic");
247            push_directive(tokens, "acquire");
248            push_directive(tokens, "sync_restrict::shared::cluster");
249            push_directive(tokens, "cluster");
250            tokens.push(PtxToken::Semicolon);
251            if spaced {
252                tokens.push(PtxToken::Newline);
253            }
254        }
255    }
256
257    impl PtxUnparser for FenceProxyAsyncGenericReleaseSyncRestrictSharedCtaCluster {
258        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
259            self.unparse_tokens_mode(tokens, false);
260        }
261        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
262            push_opcode(tokens, "fence");
263            push_directive(tokens, "proxy");
264            push_directive(tokens, "async::generic");
265            push_directive(tokens, "release");
266            push_directive(tokens, "sync_restrict::shared::cta");
267            push_directive(tokens, "cluster");
268            tokens.push(PtxToken::Semicolon);
269            if spaced {
270                tokens.push(PtxToken::Newline);
271            }
272        }
273    }
274
275    impl PtxUnparser for MembarLevel {
276        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
277            self.unparse_tokens_mode(tokens, false);
278        }
279        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
280            push_opcode(tokens, "membar");
281            match &self.level {
282                Level::Cta => {
283                    push_directive(tokens, "cta");
284                }
285                Level::Sys => {
286                    push_directive(tokens, "sys");
287                }
288                Level::Gl => {
289                    push_directive(tokens, "gl");
290                }
291            }
292            tokens.push(PtxToken::Semicolon);
293            if spaced {
294                tokens.push(PtxToken::Newline);
295            }
296        }
297    }
298
299    impl PtxUnparser for MembarProxyProxykind {
300        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
301            self.unparse_tokens_mode(tokens, false);
302        }
303        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
304            push_opcode(tokens, "membar");
305            push_directive(tokens, "proxy");
306            match &self.proxykind {
307                Proxykind::AsyncSharedCluster => {
308                    push_directive(tokens, "async.shared::cluster");
309                }
310                Proxykind::AsyncSharedCta => {
311                    push_directive(tokens, "async.shared::cta");
312                }
313                Proxykind::AsyncGlobal => {
314                    push_directive(tokens, "async.global");
315                }
316                Proxykind::Alias => {
317                    push_directive(tokens, "alias");
318                }
319                Proxykind::Async => {
320                    push_directive(tokens, "async");
321                }
322            }
323            tokens.push(PtxToken::Semicolon);
324            if spaced {
325                tokens.push(PtxToken::Newline);
326            }
327        }
328    }
329}