Parses "scheme2:<fp64|int8>[:bits=B][:moduli=N][:provider=P]
[:library=PATH][:device=D][:device_min=W][:threads=T][:block_rows=R]
[:block_cols=C]". provider=cuda multiplies on INT8 tensor cores through libgpr_scheme2_cuda.so (CudaEngine.h) and returns the bits of the CPU providers: residues are prepared on the host, every product and reconstruction of a run happens on the device. Throws std::invalid_argument.
461{
463 throw std::invalid_argument("not a Scheme II specification");
465 std::vector<std::string> parts;
466 std::size_t start = 0;
467 while (start <= spec.size()) {
468 const std::size_t end = std::min(spec.find(':', start), spec.size());
469 parts.emplace_back(spec.substr(start, end - start));
470 start = end + 1;
471 }
472 if (parts.front() != "scheme2")
473 throw std::invalid_argument(
474 "Scheme II specification must start with scheme2");
475 bool engine_seen = false;
476 const auto integer = [](const std::string& text, const char* what) {
477 std::size_t used = 0;
478 const long value = std::stol(text, &used);
479 if (used != text.size() || value < 0)
480 throw std::invalid_argument(std::string("invalid Scheme II ") +
481 what);
482 return value;
483 };
484 for (std::size_t i = 1; i < parts.size(); ++i) {
485 const std::string& part = parts[i];
486 const std::size_t eq = part.find('=');
487 if (eq == std::string::npos) {
488 if (part == "fp64")
490 else if (part == "int8")
492 else
493 throw std::invalid_argument("unknown Scheme II engine " + part);
494 engine_seen = true;
495 continue;
496 }
497 const std::string key = part.substr(0, eq), value = part.substr(eq + 1);
498 if (key == "bits")
499 options.
bits =
static_cast<int>(integer(value,
"bits"));
500 else if (key == "moduli")
501 options.
moduli =
static_cast<int>(integer(value,
"moduli"));
502 else if (key == "threads")
503 options.
threads =
static_cast<int>(integer(value,
"threads"));
504 else if (key == "library")
506 else if (key == "device")
507 options.
device =
static_cast<int>(integer(value,
"device"));
508 else if (key == "device_min")
510 static_cast<double>(integer(value, "device_min"));
511 else if (key == "block_rows")
512 options.
block_rows = integer(value,
"block_rows");
513 else if (key == "block_cols")
514 options.
block_cols = integer(value,
"block_cols");
515 else if (key == "provider") {
516 if (value == "auto")
518 else if (value == "builtin")
520 else if (value == "mkl")
522 else if (value == "onednn")
524 else if (value == "cuda")
526 else
527 throw std::invalid_argument("unknown INT8 provider " + value);
528 } else
529 throw std::invalid_argument("unknown Scheme II option " + key);
530 }
531 if (!engine_seen && parts.size() > 1 &&
532 parts[1].find('=') != std::string::npos)
535 throw std::invalid_argument("Scheme II bits must lie in [2, 62]");
536 if (options.
moduli > kMaxModuli)
537 throw std::invalid_argument("too many Scheme II moduli");
539 throw std::invalid_argument("invalid Scheme II block size");
540 return options;
541}
bool isSpec(std::string_view spec) noexcept
int threads
Worker threads. Zero asks the thread source at each product.
int moduli
Number of moduli. Zero selects the fewest that support bits.
std::string library
Shared library of the INT8 provider. Empty searches the defaults.