MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / parse_cpu_range

Function parse_cpu_range

smallthinker/common/common.cpp:277–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

275}
276
277bool parse_cpu_range(const std::string & range, bool (&boolmask)[GGML_MAX_N_THREADS]) {
278 size_t dash_loc = range.find('-');
279 if (dash_loc == std::string::npos) {
280 LOG_ERR("Format of CPU range is invalid! Expected [<start>]-[<end>].\n");
281 return false;
282 }
283
284 size_t start_i;
285 size_t end_i;
286
287 if (dash_loc == 0) {
288 start_i = 0;
289 } else {
290 start_i = std::stoull(range.substr(0, dash_loc));
291 if (start_i >= GGML_MAX_N_THREADS) {
292 LOG_ERR("Start index out of bounds!\n");
293 return false;
294 }
295 }
296
297 if (dash_loc == range.length() - 1) {
298 end_i = GGML_MAX_N_THREADS - 1;
299 } else {
300 end_i = std::stoull(range.substr(dash_loc + 1));
301 if (end_i >= GGML_MAX_N_THREADS) {
302 LOG_ERR("End index out of bounds!\n");
303 return false;
304 }
305 }
306
307 for (size_t i = start_i; i <= end_i; i++) {
308 boolmask[i] = true;
309 }
310
311 return true;
312}
313
314bool parse_cpu_mask(const std::string & mask, bool (&boolmask)[GGML_MAX_N_THREADS]) {
315 // Discard potential 0x prefix

Callers 1

Calls 3

findMethod · 0.80
substrMethod · 0.80
lengthMethod · 0.80

Tested by

no test coverage detected