Skip to content

Commit 9c01f22

Browse files
Add Benchmark set methods, such as set_stopping_criterion, set_timeout, etc
Add - State.get_stopping_criterion() -> str - Benchmark.set_stopping_criterion(criterion: str) -> Self - Benchmark.set_criterion_param_int64(name: str, value: int) -> Self - Benchmark.set_criterion_param_float64(name: str, value: float) -> Self - Benchmark.set_criterion_param_string(name: str, value: str) -> Self - Benchmark.set_timeout(duration: float) -> Self - Benchmark.set_skip_time(skip_time: float) -> Self - Benchmark.set_throttle_threshold(frac: float) -> Self - Benchmark.set_throttle_recovery_delay(duration: float) -> Self - Benchmark.set_min_samples(count: int) -> Self
1 parent 6b9050e commit 9c01f22

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

python/cuda/nvbench/__init__.pyi

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,33 @@ class Benchmark:
9292
def set_run_once(self, v: bool) -> Self:
9393
"Set whether all benchmark configurations are executed only once"
9494
...
95+
def set_skip_time(self, duration_seconds: float) -> Self:
96+
"Set run durations, in seconds, that should be skipped"
97+
...
98+
def set_throttle_recovery_delay(self, delay_seconds: float) -> Self:
99+
"Set throttle recovery delay, in seconds"
100+
...
101+
def set_throttle_threshold(self, threshold: float) -> Self:
102+
"Set throttle threshold, as a fraction of maximal GPU frequency"
103+
...
104+
def set_timeout(self, duration_seconds: float) -> Self:
105+
"Set benchmark run duration timeout value, in seconds"
106+
...
107+
def set_stopping_criterion(self, criterion: str) -> Self:
108+
"Set stopping criterion to be used"
109+
...
110+
def set_criterion_param_float64(self, name: str, value: float) -> Self:
111+
"Set stopping criterion floating point parameter value"
112+
...
113+
def set_criterion_param_int64(self, name: str, value: int) -> Self:
114+
"Set stopping criterion integer parameter value"
115+
...
116+
def set_criterion_param_string(self, name: str, value: str) -> Self:
117+
"Set stopping criterion string parameter value"
118+
...
119+
def set_min_samples(self, count: int) -> Self:
120+
"Set minimal samples count before stopping criterion applies"
121+
...
95122

96123
class Launch:
97124
"""Configuration object for function launch.
@@ -247,6 +274,9 @@ class State:
247274
def get_axis_values_as_string(self) -> str:
248275
"Get string of space-separated name=value pairs for this configuration"
249276
...
277+
def get_stopping_criterion(self) -> str:
278+
"Get string name of stopping criterion used"
279+
...
250280

251281
def register(fn: Callable[[State], None]) -> Benchmark:
252282
"""

python/src/py_nvbench.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,24 @@ PYBIND11_MODULE(_nvbench, m)
269269

270270
// == STEP 4
271271
// Define Benchmark class
272+
// ATTN: nvbench::benchmark_base is move-only class
273+
// Methods:
274+
// nvbench::benchmark_base::get_name
275+
// nvbench::benchmark_base::add_int64_axis
276+
// nvbench::benchmark_base::add_int64_power_of_two_axis
277+
// nvbench::benchmark_base::add_float64_axis
278+
// nvbench::benchmark_base::add_string_axis
279+
// nvbench::benchmark_base::set_name
280+
// nvbench::benchmark_base::set_is_cpu_only
281+
// nvbench::benchmark_base::set_skip_time
282+
// nvbench::benchmark_base::set_timeout
283+
// nvbench::benchmark_base::set_throttle_threshold
284+
// nvbench::benchmark_base::set_throttle_recovery_delay
285+
// nvbench::benchmark_base::set_stopping_criterion
286+
// nvbench::benchmark_base::set_criterion_param_int64
287+
// nvbench::benchmark_base::set_criterion_param_float64
288+
// nvbench::benchmark_base::set_criterion_param_string
289+
// nvbench::benchmark_base::set_min_samples
272290

273291
auto py_benchmark_cls = py::class_<nvbench::benchmark_base>(m, "Benchmark");
274292
py_benchmark_cls.def("get_name", &nvbench::benchmark_base::get_name);
@@ -326,6 +344,7 @@ PYBIND11_MODULE(_nvbench, m)
326344
},
327345
py::return_value_policy::reference,
328346
py::arg("is_cpu_only"));
347+
// TODO: should this be exposed?
329348
py_benchmark_cls.def(
330349
"set_run_once",
331350
[](nvbench::benchmark_base &self, bool run_once) {
@@ -334,6 +353,81 @@ PYBIND11_MODULE(_nvbench, m)
334353
},
335354
py::return_value_policy::reference,
336355
py::arg("run_once"));
356+
py_benchmark_cls.def(
357+
"set_skip_time",
358+
[](nvbench::benchmark_base &self, nvbench::float64_t skip_duration_seconds) {
359+
self.set_skip_time(skip_duration_seconds);
360+
return std::ref(self);
361+
},
362+
py::return_value_policy::reference,
363+
py::arg("duration_seconds"));
364+
py_benchmark_cls.def(
365+
"set_timeout",
366+
[](nvbench::benchmark_base &self, nvbench::float64_t duration_seconds) {
367+
self.set_timeout(duration_seconds);
368+
return std::ref(self);
369+
},
370+
py::return_value_policy::reference,
371+
py::arg("duration_seconds"));
372+
py_benchmark_cls.def(
373+
"set_throttle_threshold",
374+
[](nvbench::benchmark_base &self, nvbench::float64_t threshold) {
375+
self.set_throttle_threshold(threshold);
376+
return std::ref(self);
377+
},
378+
py::return_value_policy::reference,
379+
py::arg("threshold"));
380+
py_benchmark_cls.def(
381+
"set_throttle_recovery_delay",
382+
[](nvbench::benchmark_base &self, nvbench::float64_t delay) {
383+
self.set_throttle_recovery_delay(delay);
384+
return std::ref(self);
385+
},
386+
py::return_value_policy::reference,
387+
py::arg("delay_seconds"));
388+
py_benchmark_cls.def(
389+
"set_stopping_criterion",
390+
[](nvbench::benchmark_base &self, std::string criterion) {
391+
self.set_stopping_criterion(std::move(criterion));
392+
return std::ref(self);
393+
},
394+
py::return_value_policy::reference,
395+
py::arg("criterion"));
396+
py_benchmark_cls.def(
397+
"set_criterion_param_int64",
398+
[](nvbench::benchmark_base &self, std::string name, nvbench::int64_t value) {
399+
self.set_criterion_param_int64(std::move(name), value);
400+
return std::ref(self);
401+
},
402+
py::return_value_policy::reference,
403+
py::arg("name"),
404+
py::arg("value"));
405+
py_benchmark_cls.def(
406+
"set_criterion_param_float64",
407+
[](nvbench::benchmark_base &self, std::string name, nvbench::float64_t value) {
408+
self.set_criterion_param_float64(std::move(name), value);
409+
return std::ref(self);
410+
},
411+
py::return_value_policy::reference,
412+
py::arg("name"),
413+
py::arg("value"));
414+
py_benchmark_cls.def(
415+
"set_criterion_param_string",
416+
[](nvbench::benchmark_base &self, std::string name, std::string value) {
417+
self.set_criterion_param_string(std::move(name), std::move(value));
418+
return std::ref(self);
419+
},
420+
py::return_value_policy::reference,
421+
py::arg("name"),
422+
py::arg("value"));
423+
py_benchmark_cls.def(
424+
"set_min_samples",
425+
[](nvbench::benchmark_base &self, nvbench::int64_t count) {
426+
self.set_min_samples(count);
427+
return std::ref(self);
428+
},
429+
py::return_value_policy::reference,
430+
py::arg("min_samples_count"));
337431

338432
// == STEP 5
339433
// Define PyState class
@@ -594,6 +688,7 @@ PYBIND11_MODULE(_nvbench, m)
594688
pystate_cls.def("get_axis_values_as_string",
595689
[](const nvbench::state &state) { return state.get_axis_values_as_string(); });
596690
pystate_cls.def("get_axis_values", &py_get_axis_values);
691+
pystate_cls.def("get_stopping_criterion", &nvbench::state::get_stopping_criterion);
597692

598693
// Use handle to take a memory leak here, since this object's destructor may be called after
599694
// interpreter has shut down

0 commit comments

Comments
 (0)