Skip to content

Commit 2ba8acd

Browse files
committed
Add example that demonstrates how to add/remove columns from the markdown table.
1 parent 94fde77 commit 2ba8acd

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ various NVBench features and usecases:
7373
- [Reporting item/sec and byte/sec throughput statistics](examples/throughput.cu)
7474
- [Skipping benchmark configurations](examples/skip.cu)
7575
- [Benchmarking on a specific stream](examples/stream.cu)
76+
- [Adding / hiding columns (summaries) in markdown output](examples/summaries.cu)
7677
- [Benchmarks that sync CUDA devices: `nvbench::exec_tag::sync`](examples/exec_tag_sync.cu)
7778
- [Manual timing: `nvbench::exec_tag::timer`](examples/exec_tag_timer.cu)
7879

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(example_srcs
88
exec_tag_timer.cu
99
skip.cu
1010
stream.cu
11+
summaries.cu
1112
throughput.cu
1213
)
1314

examples/summaries.cu

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2025 NVIDIA Corporation
3+
*
4+
* Licensed under the Apache License, Version 2.0 with the LLVM exception
5+
* (the "License"); you may not use this file except in compliance with
6+
* the License.
7+
*
8+
* You may obtain a copy of the License at
9+
*
10+
* http://llvm.org/foundation/relicensing/LICENSE.txt
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#include <nvbench/nvbench.cuh>
20+
21+
// Grab some testing kernels from NVBench:
22+
#include <nvbench/test_kernels.cuh>
23+
24+
// #define PRINT_DEFAULT_SUMMARY_TAGS
25+
26+
void summary_example(nvbench::state &state)
27+
{
28+
// Fetch parameters and compute duration in seconds:
29+
const auto ms = static_cast<nvbench::float64_t>(state.get_int64("ms"));
30+
const auto us = static_cast<nvbench::float64_t>(state.get_int64("us"));
31+
const auto duration = ms * 1e-3 + us * 1e-6;
32+
33+
// Add a new column to the summary table with the derived duration used by the benchmark.
34+
// See the documentation in nvbench/summary.cuh for more details.
35+
{
36+
nvbench::summary &summary = state.add_summary("duration");
37+
summary.set_string("name", "Duration (s)");
38+
summary.set_string("description", "The duration of the kernel execution.");
39+
summary.set_string("hint", "duration");
40+
summary.set_float64("value", duration);
41+
}
42+
43+
// Run the measurements:
44+
state.exec([duration](nvbench::launch &launch) {
45+
nvbench::sleep_kernel<<<1, 1, 0, launch.get_stream()>>>(duration);
46+
});
47+
48+
#ifdef PRINT_DEFAULT_SUMMARY_TAGS
49+
// The default summary tags can be found by inspecting the state after calling
50+
// state.exec.
51+
// They can also be found by looking at the json output (--json <filename>)
52+
for (const auto &summary : state.get_summaries())
53+
{
54+
std::cout << summary.get_tag() << std::endl;
55+
}
56+
#endif
57+
58+
// Default summary columns can be shown/hidden in the markdown output tables by adding/removing
59+
// the "hide" key. Modify this benchmark to show the minimum and maximum times, but hide the
60+
// means.
61+
state.get_summary("nv/cold/time/gpu/min").remove_value("hide");
62+
state.get_summary("nv/cold/time/gpu/max").remove_value("hide");
63+
state.get_summary("nv/cold/time/gpu/mean").set_string("hide", "");
64+
state.get_summary("nv/cold/time/cpu/min").remove_value("hide");
65+
state.get_summary("nv/cold/time/cpu/max").remove_value("hide");
66+
state.get_summary("nv/cold/time/cpu/mean").set_string("hide", "");
67+
}
68+
NVBENCH_BENCH(summary_example)
69+
.add_int64_axis("ms", nvbench::range(10, 50, 20))
70+
.add_int64_axis("us", nvbench::range(100, 500, 200));

0 commit comments

Comments
 (0)