Skip to content

Commit 8d45656

Browse files
benchmark/nixlbench: --config_file param supported
This patch introduces config file support to nixlbench. The name of a config file can be specified using the --config_file command-line parameter. The config file is in INI format. Each existing command-line parameter can also be placed in the "[global]" section of the configuration file, so the following invocations: nixlbench --etcd_endpoints http://localhost:2379 --backend POSIX --filepath /mnt/test --posix_api_type AIO and nixlbench --config_file /tmp/nixlbench.config where /tmp/nixlbench.config contains: [global] etcd_endpoints=http://localhost:2379 backend=POSIX filepath=/mnt/test posix_api_type=AIO are identical. If a parameter exists in the config file and is also explicitly specified on the command line, the latter takes precedence. Signed-off-by: Anton Nayshtut <[email protected]>
1 parent 3635078 commit 8d45656

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

benchmark/nixlbench/src/utils/utils.cpp

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct xferBenchParamInfo
7171
* xferBench Config
7272
**********/
7373
const xferBenchParamInfo xbench_params[] = {
74+
NB_ARG_STRING(config_file, "", "Config file (Default: None)")
7475
NB_ARG_STRING(benchmark_group, "default", \
7576
"Name of benchmark group. Use different names to run multiple benchmarks in parallel " \
7677
"(Default: default)")
@@ -165,6 +166,7 @@ NB_ARG_STRING(gusli_device_security, "", \
165166
#undef NB_ARG_BOOL
166167
#undef NB_ARG_STRING
167168

169+
std::string xferBenchConfig::config_file = "";
168170
std::string xferBenchConfig::runtime_type = "";
169171
std::string xferBenchConfig::worker_type = "";
170172
std::string xferBenchConfig::backend = "";
@@ -262,10 +264,42 @@ xferBenchConfig::parseConfig(int argc, char *argv[])
262264
return loadParams(result);
263265
}
264266

267+
// getParamValue() provides a parameter value, giving priority to explicitly passed
268+
// parameters over those specified in the config_file or set as defaults.
269+
template <class T>
270+
T
271+
xferBenchConfig::getParamValue(std::unique_ptr<inih::INIReader> &ini, cxxopts::ParseResult &result, const char *name)
272+
{
273+
if (ini && !result.count(name)) {
274+
// config_file exists and the parameter is not specified explicitly ->
275+
// try to read the value from config_file first
276+
try {
277+
return ini->Get<T>("global", name);
278+
} catch (std::runtime_error&) {
279+
// the parameter is not in the config_file -> fallback to ParseResult
280+
}
281+
}
282+
283+
return result[name].as<T>();
284+
}
285+
265286
int
266287
xferBenchConfig::loadParams(cxxopts::ParseResult &result) {
288+
std::unique_ptr<inih::INIReader> ini;
289+
290+
if (result.count("config_file")) {
291+
/* if config_file parameter specified - try to read the config from file */
292+
config_file = result["config_file"].as<std::string>();
293+
try {
294+
ini = std::make_unique<inih::INIReader>(config_file);
295+
} catch (std::runtime_error& e) {
296+
std::cerr << "Failed to load ini: " << e.what() << std::endl;
297+
return -1;
298+
}
299+
}
300+
267301
#define NB_ARG(name) \
268-
result[#name].as<decltype(name)>()
302+
getParamValue<decltype(name)>(ini, result, #name)
269303

270304
benchmark_group = NB_ARG(benchmark_group);
271305
runtime_type = NB_ARG(runtime_type);

benchmark/nixlbench/src/utils/utils.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <utils/common/nixl_time.h>
3030
#include "runtime/runtime.h"
3131
#include "utils/external/cxxopts.hpp"
32+
#include "utils/external/ini.h"
3233

3334
#if HAVE_CUDA
3435
#include <cuda.h>
@@ -125,6 +126,7 @@
125126
XFERBENCH_MODE_MG == xferBenchConfig::mode)
126127
class xferBenchConfig {
127128
public:
129+
static std::string config_file;
128130
static std::string runtime_type;
129131
static std::string worker_type;
130132
static std::string backend;
@@ -193,7 +195,10 @@ class xferBenchConfig {
193195

194196
protected:
195197
static int
196-
loadParams(cxxopts::ParseResult &options);
198+
loadParams(cxxopts::ParseResult &result);
199+
template <class T>
200+
static T
201+
getParamValue(std::unique_ptr<inih::INIReader> &ini, cxxopts::ParseResult &result, const char *name);
197202
};
198203

199204
// Shared GUSLI device config used by utils and nixl_worker

0 commit comments

Comments
 (0)