Skip to main content

ptx_parser/unparser/instruction/
createpolicy.rs

1//! Original PTX specification:
2//!
3//! // Range-based policy
4//! createpolicy.range{.global}.level::primary_priority{.level::secondary_priority}.b64
5//! cache-policy, [a], primary-size, total-size;
6//! // Fraction-based policy
7//! createpolicy.fractional.level::primary_priority{.level::secondary_priority}.b64
8//! cache-policy{, fraction};
9//! // Converting the access property from CUDA APIs
10//! createpolicy.cvt.L2.b64            cache-policy, access-property;
11//! .level::primary_priority =   { .L2::evict_last, .L2::evict_normal,
12//! .L2::evict_first, .L2::evict_unchanged };
13//! .level::secondary_priority = { .L2::evict_first, .L2::evict_unchanged };
14
15#![allow(unused)]
16
17use crate::lexer::PtxToken;
18use crate::unparser::{PtxUnparser, common::*};
19
20pub mod section_0 {
21    use super::*;
22    use crate::r#type::instruction::createpolicy::section_0::*;
23
24    impl PtxUnparser for CreatepolicyRangeGlobalLevelPrimaryPriorityLevelSecondaryPriorityB64 {
25        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
26            self.unparse_tokens_mode(tokens, false);
27        }
28        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
29            push_opcode(tokens, "createpolicy");
30            push_directive(tokens, "range");
31            if self.global {
32                push_directive(tokens, "global");
33            }
34            match &self.level_primary_priority {
35                LevelPrimaryPriority::L2EvictUnchanged => {
36                    push_directive(tokens, "L2::evict_unchanged");
37                }
38                LevelPrimaryPriority::L2EvictNormal => {
39                    push_directive(tokens, "L2::evict_normal");
40                }
41                LevelPrimaryPriority::L2EvictFirst => {
42                    push_directive(tokens, "L2::evict_first");
43                }
44                LevelPrimaryPriority::L2EvictLast => {
45                    push_directive(tokens, "L2::evict_last");
46                }
47            }
48            if let Some(level_secondary_priority_0) = self.level_secondary_priority.as_ref() {
49                match level_secondary_priority_0 {
50                    LevelSecondaryPriority::L2EvictUnchanged => {
51                        push_directive(tokens, "L2::evict_unchanged");
52                    }
53                    LevelSecondaryPriority::L2EvictFirst => {
54                        push_directive(tokens, "L2::evict_first");
55                    }
56                }
57            }
58            push_directive(tokens, "b64");
59            if spaced {
60                tokens.push(PtxToken::Space);
61            }
62            self.cache_policy.unparse_tokens_mode(tokens, spaced);
63            tokens.push(PtxToken::Comma);
64            if spaced {
65                tokens.push(PtxToken::Space);
66            }
67            self.a.unparse_tokens_mode(tokens, spaced);
68            tokens.push(PtxToken::Comma);
69            if spaced {
70                tokens.push(PtxToken::Space);
71            }
72            self.primary_size.unparse_tokens_mode(tokens, spaced);
73            tokens.push(PtxToken::Comma);
74            if spaced {
75                tokens.push(PtxToken::Space);
76            }
77            self.total_size.unparse_tokens_mode(tokens, spaced);
78            tokens.push(PtxToken::Semicolon);
79            if spaced {
80                tokens.push(PtxToken::Newline);
81            }
82        }
83    }
84
85    impl PtxUnparser for CreatepolicyFractionalLevelPrimaryPriorityLevelSecondaryPriorityB64 {
86        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
87            self.unparse_tokens_mode(tokens, false);
88        }
89        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
90            push_opcode(tokens, "createpolicy");
91            push_directive(tokens, "fractional");
92            match &self.level_primary_priority {
93                LevelPrimaryPriority::L2EvictUnchanged => {
94                    push_directive(tokens, "L2::evict_unchanged");
95                }
96                LevelPrimaryPriority::L2EvictNormal => {
97                    push_directive(tokens, "L2::evict_normal");
98                }
99                LevelPrimaryPriority::L2EvictFirst => {
100                    push_directive(tokens, "L2::evict_first");
101                }
102                LevelPrimaryPriority::L2EvictLast => {
103                    push_directive(tokens, "L2::evict_last");
104                }
105            }
106            if let Some(level_secondary_priority_1) = self.level_secondary_priority.as_ref() {
107                match level_secondary_priority_1 {
108                    LevelSecondaryPriority::L2EvictUnchanged => {
109                        push_directive(tokens, "L2::evict_unchanged");
110                    }
111                    LevelSecondaryPriority::L2EvictFirst => {
112                        push_directive(tokens, "L2::evict_first");
113                    }
114                }
115            }
116            push_directive(tokens, "b64");
117            if spaced {
118                tokens.push(PtxToken::Space);
119            }
120            self.cache_policy.unparse_tokens_mode(tokens, spaced);
121            if self.fraction.is_some() {
122                tokens.push(PtxToken::Comma);
123            }
124            if let Some(opt_2) = self.fraction.as_ref() {
125                if spaced {
126                    tokens.push(PtxToken::Space);
127                }
128                opt_2.unparse_tokens_mode(tokens, spaced);
129            }
130            tokens.push(PtxToken::Semicolon);
131            if spaced {
132                tokens.push(PtxToken::Newline);
133            }
134        }
135    }
136
137    impl PtxUnparser for CreatepolicyCvtL2B64 {
138        fn unparse_tokens(&self, tokens: &mut ::std::vec::Vec<PtxToken>) {
139            self.unparse_tokens_mode(tokens, false);
140        }
141        fn unparse_tokens_mode(&self, tokens: &mut ::std::vec::Vec<PtxToken>, spaced: bool) {
142            push_opcode(tokens, "createpolicy");
143            push_directive(tokens, "cvt");
144            push_directive(tokens, "L2");
145            push_directive(tokens, "b64");
146            if spaced {
147                tokens.push(PtxToken::Space);
148            }
149            self.cache_policy.unparse_tokens_mode(tokens, spaced);
150            tokens.push(PtxToken::Comma);
151            if spaced {
152                tokens.push(PtxToken::Space);
153            }
154            self.access_property.unparse_tokens_mode(tokens, spaced);
155            tokens.push(PtxToken::Semicolon);
156            if spaced {
157                tokens.push(PtxToken::Newline);
158            }
159        }
160    }
161}