Skip to content

Commit

Permalink
Optionally add a GPU summary line to reports
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-caron committed Sep 25, 2024
1 parent 02daddd commit dd4713c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Optionally add a GPU summary line to reports

### Changed

- Update skip logic in CPU info table
Expand Down
9 changes: 8 additions & 1 deletion qpbenchmark/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
capitalize_settings,
get_cpu_info_summary,
get_cpu_info_table,
get_gpu_info_summary,
get_solver_versions,
)
from .version import get_version
Expand Down Expand Up @@ -255,6 +256,12 @@ def __write_header(self, fh: io.TextIOWrapper) -> None:
nb_problems = len(set(self.results.df["problem"]))
benchmark_version = get_version()
cpu_info_summary = get_cpu_info_summary()
gpu_info_summary = get_gpu_info_summary()
optional_gpu_line = (
f"\n| GPU | {gpu_info_summary} |"
if gpu_info_summary
else ""
)
date = str(datetime.datetime.now(datetime.timezone.utc))
fh.write(
f"""# {self.test_set.title}
Expand All @@ -263,7 +270,7 @@ def __write_header(self, fh: io.TextIOWrapper) -> None:
|:-------------------|:--------------------|
| Benchmark version | {benchmark_version} |
| Date | {date} |
| CPU | [{cpu_info_summary}](#cpu-info) |
| CPU | [{cpu_info_summary}](#cpu-info) |{optional_gpu_line}
| Run by | [@{self.author}](https://github.com/{self.author}/) |
"""
Expand Down
18 changes: 18 additions & 0 deletions qpbenchmark/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ def get_cpu_info_summary() -> str:
return cpuinfo.get_cpu_info()["brand_raw"]


def get_gpu_info_summary() -> str:
"""Get GPU information summary as a single string.
Note:
This function only works if PyTorch is installed (for instance via
`conda install pytorch`).
Returns:
GPU information string, if available, empty string otherwise.
"""
try:
import torch

return torch.cuda.get_device_name()
except ModuleNotFoundError:
return ""


def get_cpu_info_table() -> str:
"""Get CPU information as a Markdown table.
Expand Down

0 comments on commit dd4713c

Please sign in to comment.