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            push_opcode(tokens, "fence");
39            if let Some(sem_0) = self.sem.as_ref() {
40                match sem_0 {
41                    Sem::AcqRel => {
42                        push_directive(tokens, "acq_rel");
43                    }
44                    Sem::Acquire => {
45                        push_directive(tokens, "acquire");
46                    }
47                    Sem::Release => {
48                        push_directive(tokens, "release");
49                    }
50                    Sem::Sc => {
51                        push_directive(tokens, "sc");
52                    }
53                }
54            }
55            match &self.scope {
56                Scope::Cluster => {
57                    push_directive(tokens, "cluster");
58                }
59                Scope::Cta => {
60                    push_directive(tokens, "cta");
61                }
62                Scope::Gpu => {
63                    push_directive(tokens, "gpu");
64                }
65                Scope::Sys => {
66                    push_directive(tokens, "sys");
67                }
68            }
69            tokens.push(PtxToken::Semicolon);
70        }
71    }
72
73    impl PtxUnparser for FenceAcquireSyncRestrictSharedClusterCluster {
74        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
75            push_opcode(tokens, "fence");
76            push_directive(tokens, "acquire");
77            push_directive(tokens, "sync_restrict::shared::cluster");
78            push_directive(tokens, "cluster");
79            tokens.push(PtxToken::Semicolon);
80        }
81    }
82
83    impl PtxUnparser for FenceReleaseSyncRestrictSharedCtaCluster {
84        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
85            push_opcode(tokens, "fence");
86            push_directive(tokens, "release");
87            push_directive(tokens, "sync_restrict::shared::cta");
88            push_directive(tokens, "cluster");
89            tokens.push(PtxToken::Semicolon);
90        }
91    }
92
93    impl PtxUnparser for FenceOpRestrictReleaseCluster {
94        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
95            push_opcode(tokens, "fence");
96            match &self.op_restrict {
97                OpRestrict::MbarrierInit => {
98                    push_directive(tokens, "mbarrier_init");
99                }
100            }
101            push_directive(tokens, "release");
102            push_directive(tokens, "cluster");
103            tokens.push(PtxToken::Semicolon);
104        }
105    }
106
107    impl PtxUnparser for FenceProxyProxykind {
108        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
109            push_opcode(tokens, "fence");
110            push_directive(tokens, "proxy");
111            match &self.proxykind {
112                Proxykind::AsyncSharedCluster => {
113                    push_directive(tokens, "async.shared::cluster");
114                }
115                Proxykind::AsyncSharedCta => {
116                    push_directive(tokens, "async.shared::cta");
117                }
118                Proxykind::AsyncGlobal => {
119                    push_directive(tokens, "async.global");
120                }
121                Proxykind::Alias => {
122                    push_directive(tokens, "alias");
123                }
124                Proxykind::Async => {
125                    push_directive(tokens, "async");
126                }
127            }
128            tokens.push(PtxToken::Semicolon);
129        }
130    }
131
132    impl PtxUnparser for FenceProxyToProxykindFromProxykindReleaseScope {
133        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
134            push_opcode(tokens, "fence");
135            push_directive(tokens, "proxy");
136            match &self.to_proxykind_from_proxykind {
137                ToProxykindFromProxykind::TensormapGeneric => {
138                    push_directive(tokens, "tensormap::generic");
139                }
140            }
141            push_directive(tokens, "release");
142            match &self.scope {
143                Scope::Cluster => {
144                    push_directive(tokens, "cluster");
145                }
146                Scope::Cta => {
147                    push_directive(tokens, "cta");
148                }
149                Scope::Gpu => {
150                    push_directive(tokens, "gpu");
151                }
152                Scope::Sys => {
153                    push_directive(tokens, "sys");
154                }
155            }
156            tokens.push(PtxToken::Semicolon);
157        }
158    }
159
160    impl PtxUnparser for FenceProxyToProxykindFromProxykindAcquireScope {
161        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
162            push_opcode(tokens, "fence");
163            push_directive(tokens, "proxy");
164            match &self.to_proxykind_from_proxykind {
165                ToProxykindFromProxykind::TensormapGeneric => {
166                    push_directive(tokens, "tensormap::generic");
167                }
168            }
169            push_directive(tokens, "acquire");
170            match &self.scope {
171                Scope::Cluster => {
172                    push_directive(tokens, "cluster");
173                }
174                Scope::Cta => {
175                    push_directive(tokens, "cta");
176                }
177                Scope::Gpu => {
178                    push_directive(tokens, "gpu");
179                }
180                Scope::Sys => {
181                    push_directive(tokens, "sys");
182                }
183            }
184            self.addr.unparse_tokens(tokens);
185            tokens.push(PtxToken::Comma);
186            self.size.unparse_tokens(tokens);
187            tokens.push(PtxToken::Semicolon);
188        }
189    }
190
191    impl PtxUnparser for FenceProxyAsyncGenericAcquireSyncRestrictSharedClusterCluster {
192        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
193            push_opcode(tokens, "fence");
194            push_directive(tokens, "proxy");
195            push_directive(tokens, "async::generic");
196            push_directive(tokens, "acquire");
197            push_directive(tokens, "sync_restrict::shared::cluster");
198            push_directive(tokens, "cluster");
199            tokens.push(PtxToken::Semicolon);
200        }
201    }
202
203    impl PtxUnparser for FenceProxyAsyncGenericReleaseSyncRestrictSharedCtaCluster {
204        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
205            push_opcode(tokens, "fence");
206            push_directive(tokens, "proxy");
207            push_directive(tokens, "async::generic");
208            push_directive(tokens, "release");
209            push_directive(tokens, "sync_restrict::shared::cta");
210            push_directive(tokens, "cluster");
211            tokens.push(PtxToken::Semicolon);
212        }
213    }
214
215    impl PtxUnparser for MembarLevel {
216        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
217            push_opcode(tokens, "membar");
218            match &self.level {
219                Level::Cta => {
220                    push_directive(tokens, "cta");
221                }
222                Level::Sys => {
223                    push_directive(tokens, "sys");
224                }
225                Level::Gl => {
226                    push_directive(tokens, "gl");
227                }
228            }
229            tokens.push(PtxToken::Semicolon);
230        }
231    }
232
233    impl PtxUnparser for MembarProxyProxykind {
234        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
235            push_opcode(tokens, "membar");
236            push_directive(tokens, "proxy");
237            match &self.proxykind {
238                Proxykind::AsyncSharedCluster => {
239                    push_directive(tokens, "async.shared::cluster");
240                }
241                Proxykind::AsyncSharedCta => {
242                    push_directive(tokens, "async.shared::cta");
243                }
244                Proxykind::AsyncGlobal => {
245                    push_directive(tokens, "async.global");
246                }
247                Proxykind::Alias => {
248                    push_directive(tokens, "alias");
249                }
250                Proxykind::Async => {
251                    push_directive(tokens, "async");
252                }
253            }
254            tokens.push(PtxToken::Semicolon);
255        }
256    }
257}