@@ -72,151 +72,35 @@ DisjointPoolAllConfigs::DisjointPoolAllConfigs(int trace) {
72
72
73
73
DisjointPoolAllConfigs parseDisjointPoolConfig (const std::string &config,
74
74
int trace) {
75
+ // TODO: avoid creating a copy of 'config'
75
76
DisjointPoolAllConfigs AllConfigs;
76
77
77
- // TODO: replace with UR ENV var parser and avoid creating a copy of 'config'
78
- auto GetValue = [](std::string &Param, size_t Length, size_t &Setting) {
79
- size_t Multiplier = 1 ;
80
- if (tolower (Param[Length - 1 ]) == ' k' ) {
81
- Length--;
82
- Multiplier = 1_KB;
83
- }
84
- if (tolower (Param[Length - 1 ]) == ' m' ) {
85
- Length--;
86
- Multiplier = 1_MB;
87
- }
88
- if (tolower (Param[Length - 1 ]) == ' g' ) {
89
- Length--;
90
- Multiplier = 1_GB;
91
- }
92
- std::string TheNumber = Param.substr (0 , Length);
93
- if (TheNumber.find_first_not_of (" 0123456789" ) == std::string::npos) {
94
- Setting = std::stoi (TheNumber) * Multiplier;
95
- }
96
- };
78
+ size_t MaxSize = (std::numeric_limits<size_t >::max)();
79
+ size_t EnableBuffers = 1 ;
97
80
98
- auto ParamParser = [GetValue](std::string &Params, size_t &Setting,
99
- bool &ParamWasSet) {
100
- bool More;
101
- if (Params.size () == 0 ) {
102
- ParamWasSet = false ;
103
- return false ;
104
- }
105
- size_t Pos = Params.find (' ,' );
106
- if (Pos != std::string::npos) {
107
- if (Pos > 0 ) {
108
- GetValue (Params, Pos, Setting);
109
- ParamWasSet = true ;
110
- }
111
- Params.erase (0 , Pos + 1 );
112
- More = true ;
81
+ // Update pool settings if specified in environment.
82
+ bool EnableBuffersSet = false ;
83
+ bool MaxSizeSet = false ;
84
+ size_t Start = 0 ;
85
+ size_t End = config.find (' ;' );
86
+ while (true ) {
87
+ std::string Param = config.substr (Start, End - Start);
88
+ if (!EnableBuffersSet && isdigit (Param[0 ])) {
89
+ GetValue (Param, Param.size (), EnableBuffers);
90
+ EnableBuffersSet = true ;
91
+ } else if (!MaxSizeSet && isdigit (Param[0 ])) {
92
+ GetValue (Param, Param.size (), MaxSize);
93
+ MaxSizeSet = true ;
113
94
} else {
114
- GetValue (Params, Params.size (), Setting);
115
- ParamWasSet = true ;
116
- More = false ;
95
+ EnvVarMap map = string_to_map
117
96
}
118
- return More;
119
- };
120
97
121
- auto MemParser = [&AllConfigs, ParamParser](std::string &Params,
122
- DisjointPoolMemType memType =
123
- DisjointPoolMemType::All) {
124
- bool ParamWasSet;
125
- DisjointPoolMemType LM = memType;
126
- if (memType == DisjointPoolMemType::All) {
127
- LM = DisjointPoolMemType::Host;
98
+ if (End == std::string::npos) {
99
+ break ;
128
100
}
129
101
130
- bool More = ParamParser (Params, AllConfigs.Configs [LM].MaxPoolableSize ,
131
- ParamWasSet);
132
- if (ParamWasSet && memType == DisjointPoolMemType::All) {
133
- for (auto &Config : AllConfigs.Configs ) {
134
- Config.MaxPoolableSize = AllConfigs.Configs [LM].MaxPoolableSize ;
135
- }
136
- }
137
- if (More) {
138
- More = ParamParser (Params, AllConfigs.Configs [LM].Capacity ,
139
- ParamWasSet);
140
- if (ParamWasSet && memType == DisjointPoolMemType::All) {
141
- for (auto &Config : AllConfigs.Configs ) {
142
- Config.Capacity = AllConfigs.Configs [LM].Capacity ;
143
- }
144
- }
145
- }
146
- if (More) {
147
- ParamParser (Params, AllConfigs.Configs [LM].SlabMinSize ,
148
- ParamWasSet);
149
- if (ParamWasSet && memType == DisjointPoolMemType::All) {
150
- for (auto &Config : AllConfigs.Configs ) {
151
- Config.SlabMinSize = AllConfigs.Configs [LM].SlabMinSize ;
152
- }
153
- }
154
- }
155
- };
156
-
157
- auto MemTypeParser = [MemParser](std::string &Params) {
158
- int Pos = 0 ;
159
- DisjointPoolMemType M (DisjointPoolMemType::All);
160
- if (Params.compare (0 , 5 , " host:" ) == 0 ) {
161
- Pos = 5 ;
162
- M = DisjointPoolMemType::Host;
163
- } else if (Params.compare (0 , 7 , " device:" ) == 0 ) {
164
- Pos = 7 ;
165
- M = DisjointPoolMemType::Device;
166
- } else if (Params.compare (0 , 7 , " shared:" ) == 0 ) {
167
- Pos = 7 ;
168
- M = DisjointPoolMemType::Shared;
169
- } else if (Params.compare (0 , 17 , " read_only_shared:" ) == 0 ) {
170
- Pos = 17 ;
171
- M = DisjointPoolMemType::SharedReadOnly;
172
- }
173
- if (Pos > 0 ) {
174
- Params.erase (0 , Pos);
175
- }
176
- MemParser (Params, M);
177
- };
178
-
179
- size_t MaxSize = (std::numeric_limits<size_t >::max)();
180
-
181
- // Update pool settings if specified in environment.
182
- size_t EnableBuffers = 1 ;
183
- if (config != " " ) {
184
- std::string Params = config;
185
- size_t Pos = Params.find (' ;' );
186
- if (Pos != std::string::npos) {
187
- if (Pos > 0 ) {
188
- GetValue (Params, Pos, EnableBuffers);
189
- }
190
- Params.erase (0 , Pos + 1 );
191
- size_t Pos = Params.find (' ;' );
192
- if (Pos != std::string::npos) {
193
- if (Pos > 0 ) {
194
- GetValue (Params, Pos, MaxSize);
195
- }
196
- Params.erase (0 , Pos + 1 );
197
- do {
198
- size_t Pos = Params.find (' ;' );
199
- if (Pos != std::string::npos) {
200
- if (Pos > 0 ) {
201
- std::string MemParams = Params.substr (0 , Pos);
202
- MemTypeParser (MemParams);
203
- }
204
- Params.erase (0 , Pos + 1 );
205
- if (Params.size () == 0 ) {
206
- break ;
207
- }
208
- } else {
209
- MemTypeParser (Params);
210
- break ;
211
- }
212
- } while (true );
213
- } else {
214
- // set MaxPoolSize for all configs
215
- GetValue (Params, Params.size (), MaxSize);
216
- }
217
- } else {
218
- GetValue (Params, Params.size (), EnableBuffers);
219
- }
102
+ Start = End + 1 ;
103
+ End = config.find (' ;' , Start);
220
104
}
221
105
222
106
AllConfigs.EnableBuffers = EnableBuffers;
0 commit comments