/* * SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ #pragma once // Configuration helpers shared by the ANN and clustering benchmarks. Unlike benchmark_utils.hpp, // this header does not depend on Google Benchmark, so configuration code can include it alone. #include #include #include #include #include #include #include #include namespace cuvs::bench { using kv_series = std::vector>>; /** * Parse one `--override_kv=:[:...]` argument, whose values are JSON, and * append it to `out`. Throws std::invalid_argument on malformed input. */ inline void parse_override_kv(const std::string& arg, kv_series& out) { std::vector tokens; std::string token; std::istringstream iss(arg); while (std::getline(iss, token, ':')) { if (!token.empty()) { tokens.push_back(token); } } if (tokens.size() < 2) { throw std::invalid_argument("Invalid --override_kv=" + arg + ", expected :[:...]"); } std::vector vals{}; for (std::size_t j = 1; j < tokens.size(); j++) { try { vals.push_back(nlohmann::json::parse(tokens[j])); } catch (const nlohmann::json::parse_error&) { throw std::invalid_argument("Invalid --override_kv value '" + tokens[j] + "', expected JSON (quote strings: '\"" + tokens[j] + "\"')"); } } out.emplace_back(tokens[0], vals); } /** Data type of a dataset file, inferred from its extension; nullopt if it is not recognized. */ inline auto dtype_from_filename(const std::string& filename) -> std::optional { auto ends_with = [&](const std::string& suffix) { return filename.size() > suffix.size() && filename.compare(filename.size() - suffix.size(), suffix.size(), suffix) == 0; }; if (ends_with("f16bin") || ends_with("fp16.fbin")) { return "half"; } if (ends_with("fbin")) { return "float"; } if (ends_with("u8bin")) { return "uint8"; } if (ends_with("i8bin")) { return "int8"; } return std::nullopt; } } // namespace cuvs::bench