Skip to main content

ptx_parser/type/instruction/
red.rs

1//! Original PTX specification:
2//!
3//! // Reduction operation with scalar type:
4//! red.op{.space}{.sem}{.scope}{.level::cache_hint}.type          [a], b{, cache-policy};
5//! red.add{.space}{.sem}{.scope}.noftz{.level::cache_hint}.f16    [a], b{, cache-policy};
6//! red.add{.space}{.sem}{.scope}.noftz{.level::cache_hint}.f16x2  [a], b{, cache-policy};
7//! red.add{.space}{.sem}{.scope}.noftz{.level::cache_hint}.bf16   [a], b{, cache-policy};
8//! red.add{.space}{.sem}{.scope}.noftz{.level::cache_hint}.bf16x2 [a], b{, cache-policy};
9//! .space =              { .global, .shared, .shared::cta, .shared::cluster};
10//! .sem =                {.relaxed, .release};
11//! .scope =              {.cta, .cluster, .gpu, .sys};
12//! .op =                 { .and, .or, .xor, .add, .inc, .dec, .min, .max };
13//! .level::cache_hint =  { .L2::cache_hint };
14//! .type =               { .b32, .b64, .u32, .u64, .s32, .s64, .f32, .f64 };
15//! ------------------------------------------------------------------
16//! // Reduction operation with vector type:
17//! red.add{.space}{.sem}{.scope}{.level::cache_hint}.vec_32_bit.f32 [a], b{, cache-policy};
18//! red.op{.space}{.sem}{.scope}.noftz{.level::cache_hint}. vec_16_bit.half_word_type [a], b{, cache-policy};
19//! red.op{.space}{.sem}{.scope}.noftz{.level::cache_hint}.vec_32_bit.packed_type [a], b {, cache-policy};
20//! .sem =                { .relaxed, .release };
21//! .scope =              { .cta, .cluster, .gpu, .sys };
22//! .op =                 { .add, .min, .max };
23//! .half_word_type =     { .f16, .bf16 };
24//! .packed_type =        { .f16x2,.bf16x2 };
25//! .vec_16_bit =         { .v2, .v4, .v8 };
26//! .vec_32_bit =         { .v2, .v4 };
27//! .level::cache_hint =  { .L2::cache_hint };
28
29#![allow(unused)]
30use crate::r#type::common::*;
31
32pub mod section_0 {
33    use crate::Spanned;
34    use crate::parser::Span;
35    use crate::r#type::common::*;
36
37    use serde::Serialize;
38
39    #[derive(Debug, Clone, PartialEq, Serialize)]
40    pub enum Op {
41        And, // .and
42        Xor, // .xor
43        Add, // .add
44        Inc, // .inc
45        Dec, // .dec
46        Min, // .min
47        Max, // .max
48        Or,  // .or
49    }
50
51    #[derive(Debug, Clone, PartialEq, Serialize)]
52    pub enum Space {
53        SharedCluster, // .shared::cluster
54        SharedCta,     // .shared::cta
55        Global,        // .global
56        Shared,        // .shared
57    }
58
59    #[derive(Debug, Clone, PartialEq, Serialize)]
60    pub enum Sem {
61        Relaxed, // .relaxed
62        Release, // .release
63    }
64
65    #[derive(Debug, Clone, PartialEq, Serialize)]
66    pub enum Scope {
67        Cluster, // .cluster
68        Cta,     // .cta
69        Gpu,     // .gpu
70        Sys,     // .sys
71    }
72
73    #[derive(Debug, Clone, PartialEq, Serialize)]
74    pub enum LevelCacheHint {
75        L2CacheHint, // .L2::cache_hint
76    }
77
78    #[derive(Debug, Clone, PartialEq, Serialize)]
79    pub enum Type {
80        B32, // .b32
81        B64, // .b64
82        U32, // .u32
83        U64, // .u64
84        S32, // .s32
85        S64, // .s64
86        F32, // .f32
87        F64, // .f64
88    }
89
90    #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
91    pub struct RedOpSpaceSemScopeLevelCacheHintType {
92        pub op: Op,                                   // .op
93        pub space: Option<Space>,                     // {.space}
94        pub sem: Option<Sem>,                         // {.sem}
95        pub scope: Option<Scope>,                     // {.scope}
96        pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
97        pub type_: Type,                              // .type
98        pub a: AddressOperand,                        // [a]
99        pub b: GeneralOperand,                        // b
100        pub cache_policy: Option<GeneralOperand>,     // {, cache-policy}
101        pub span: Span,
102    }
103
104    #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
105    pub struct RedAddSpaceSemScopeNoftzLevelCacheHintF16 {
106        pub add: (),                                  // .add
107        pub space: Option<Space>,                     // {.space}
108        pub sem: Option<Sem>,                         // {.sem}
109        pub scope: Option<Scope>,                     // {.scope}
110        pub noftz: (),                                // .noftz
111        pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
112        pub f16: (),                                  // .f16
113        pub a: AddressOperand,                        // [a]
114        pub b: GeneralOperand,                        // b
115        pub cache_policy: Option<GeneralOperand>,     // {, cache-policy}
116        pub span: Span,
117    }
118
119    #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
120    pub struct RedAddSpaceSemScopeNoftzLevelCacheHintF16x2 {
121        pub add: (),                                  // .add
122        pub space: Option<Space>,                     // {.space}
123        pub sem: Option<Sem>,                         // {.sem}
124        pub scope: Option<Scope>,                     // {.scope}
125        pub noftz: (),                                // .noftz
126        pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
127        pub f16x2: (),                                // .f16x2
128        pub a: AddressOperand,                        // [a]
129        pub b: GeneralOperand,                        // b
130        pub cache_policy: Option<GeneralOperand>,     // {, cache-policy}
131        pub span: Span,
132    }
133
134    #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
135    pub struct RedAddSpaceSemScopeNoftzLevelCacheHintBf16 {
136        pub add: (),                                  // .add
137        pub space: Option<Space>,                     // {.space}
138        pub sem: Option<Sem>,                         // {.sem}
139        pub scope: Option<Scope>,                     // {.scope}
140        pub noftz: (),                                // .noftz
141        pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
142        pub bf16: (),                                 // .bf16
143        pub a: AddressOperand,                        // [a]
144        pub b: GeneralOperand,                        // b
145        pub cache_policy: Option<GeneralOperand>,     // {, cache-policy}
146        pub span: Span,
147    }
148
149    #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
150    pub struct RedAddSpaceSemScopeNoftzLevelCacheHintBf16x2 {
151        pub add: (),                                  // .add
152        pub space: Option<Space>,                     // {.space}
153        pub sem: Option<Sem>,                         // {.sem}
154        pub scope: Option<Scope>,                     // {.scope}
155        pub noftz: (),                                // .noftz
156        pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
157        pub bf16x2: (),                               // .bf16x2
158        pub a: AddressOperand,                        // [a]
159        pub b: GeneralOperand,                        // b
160        pub cache_policy: Option<GeneralOperand>,     // {, cache-policy}
161        pub span: Span,
162    }
163}
164
165pub mod section_1 {
166    use crate::Spanned;
167    use crate::parser::Span;
168    use crate::r#type::common::*;
169
170    use serde::Serialize;
171
172    #[derive(Debug, Clone, PartialEq, Serialize)]
173    pub enum Space {
174        SharedCluster, // .shared::cluster
175        SharedCta,     // .shared::cta
176        Global,        // .global
177        Shared,        // .shared
178    }
179
180    #[derive(Debug, Clone, PartialEq, Serialize)]
181    pub enum Sem {
182        Relaxed, // .relaxed
183        Release, // .release
184    }
185
186    #[derive(Debug, Clone, PartialEq, Serialize)]
187    pub enum Scope {
188        Cluster, // .cluster
189        Cta,     // .cta
190        Gpu,     // .gpu
191        Sys,     // .sys
192    }
193
194    #[derive(Debug, Clone, PartialEq, Serialize)]
195    pub enum LevelCacheHint {
196        L2CacheHint, // .L2::cache_hint
197    }
198
199    #[derive(Debug, Clone, PartialEq, Serialize)]
200    pub enum Vec32Bit {
201        V2, // .v2
202        V4, // .v4
203    }
204
205    #[derive(Debug, Clone, PartialEq, Serialize)]
206    pub enum Op {
207        Add, // .add
208        Min, // .min
209        Max, // .max
210    }
211
212    #[derive(Debug, Clone, PartialEq, Serialize)]
213    pub enum Vec16Bit {
214        V2, // .v2
215        V4, // .v4
216        V8, // .v8
217    }
218
219    #[derive(Debug, Clone, PartialEq, Serialize)]
220    pub enum HalfWordType {
221        Bf16, // .bf16
222        F16,  // .f16
223    }
224
225    #[derive(Debug, Clone, PartialEq, Serialize)]
226    pub enum PackedType {
227        Bf16x2, // .bf16x2
228        F16x2,  // .f16x2
229    }
230
231    #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
232    pub struct RedAddSpaceSemScopeLevelCacheHintVec32BitF32 {
233        pub add: (),                                  // .add
234        pub space: Option<Space>,                     // {.space}
235        pub sem: Option<Sem>,                         // {.sem}
236        pub scope: Option<Scope>,                     // {.scope}
237        pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
238        pub vec_32_bit: Vec32Bit,                     // .vec_32_bit
239        pub f32: (),                                  // .f32
240        pub a: AddressOperand,                        // [a]
241        pub b: GeneralOperand,                        // b
242        pub cache_policy: Option<GeneralOperand>,     // {, cache-policy}
243        pub span: Span,
244    }
245
246    #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
247    pub struct RedOpSpaceSemScopeNoftzLevelCacheHintVec16BitHalfWordType {
248        pub op: Op,                                   // .op
249        pub space: Option<Space>,                     // {.space}
250        pub sem: Option<Sem>,                         // {.sem}
251        pub scope: Option<Scope>,                     // {.scope}
252        pub noftz: (),                                // .noftz
253        pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
254        pub vec_16_bit: Vec16Bit,                     // .vec_16_bit
255        pub half_word_type: HalfWordType,             // .half_word_type
256        pub a: AddressOperand,                        // [a]
257        pub b: GeneralOperand,                        // b
258        pub cache_policy: Option<GeneralOperand>,     // {, cache-policy}
259        pub span: Span,
260    }
261
262    #[derive(Debug, Clone, PartialEq, Spanned, Serialize)]
263    pub struct RedOpSpaceSemScopeNoftzLevelCacheHintVec32BitPackedType {
264        pub op: Op,                                   // .op
265        pub space: Option<Space>,                     // {.space}
266        pub sem: Option<Sem>,                         // {.sem}
267        pub scope: Option<Scope>,                     // {.scope}
268        pub noftz: (),                                // .noftz
269        pub level_cache_hint: Option<LevelCacheHint>, // {.level::cache_hint}
270        pub vec_32_bit: Vec32Bit,                     // .vec_32_bit
271        pub packed_type: PackedType,                  // .packed_type
272        pub a: AddressOperand,                        // [a]
273        pub b: GeneralOperand,                        // b
274        pub cache_policy: Option<GeneralOperand>,     // {, cache-policy}
275        pub span: Span,
276    }
277}
278
279// Re-export types with section suffixes to avoid naming conflicts
280// e.g., Type0 for section_0::Type, Type1 for section_1::Type
281pub use section_0::LevelCacheHint as LevelCacheHint0;
282pub use section_0::Op as Op0;
283pub use section_0::RedAddSpaceSemScopeNoftzLevelCacheHintBf16;
284pub use section_0::RedAddSpaceSemScopeNoftzLevelCacheHintBf16x2;
285pub use section_0::RedAddSpaceSemScopeNoftzLevelCacheHintF16;
286pub use section_0::RedAddSpaceSemScopeNoftzLevelCacheHintF16x2;
287pub use section_0::RedOpSpaceSemScopeLevelCacheHintType;
288pub use section_0::Scope as Scope0;
289pub use section_0::Sem as Sem0;
290pub use section_0::Space as Space0;
291pub use section_0::Type as Type0;
292pub use section_1::HalfWordType as HalfWordType1;
293pub use section_1::LevelCacheHint as LevelCacheHint1;
294pub use section_1::Op as Op1;
295pub use section_1::PackedType as PackedType1;
296pub use section_1::RedAddSpaceSemScopeLevelCacheHintVec32BitF32;
297pub use section_1::RedOpSpaceSemScopeNoftzLevelCacheHintVec16BitHalfWordType;
298pub use section_1::RedOpSpaceSemScopeNoftzLevelCacheHintVec32BitPackedType;
299pub use section_1::Scope as Scope1;
300pub use section_1::Sem as Sem1;
301pub use section_1::Space as Space1;
302pub use section_1::Vec16Bit as Vec16Bit1;
303pub use section_1::Vec32Bit as Vec32Bit1;