Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert back to original smon + blacken and logging #147

Merged
merged 5 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions src/con_duct/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,26 +325,33 @@
uid=uid, memory_total=memory_total, cpu_total=cpu_total
)
# GPU information
if shutil.which("nvidia-smi"):
if shutil.which("nvidia-smi") is not None:
lgr.debug("Checking NVIDIA GPU using nvidia-smi")
try:
gpu_info = (
subprocess.check_output(
[
"nvidia-smi",
"--query-gpu=index,name,pci.bus_id,driver_version,memory.total,compute_mode",
"--format=csv",
],
text=True,
out = subprocess.check_output(
[
"nvidia-smi",
"--query-gpu=index,name,pci.bus_id,driver_version,memory.total,compute_mode",
"--format=csv",
]
).decode("utf-8")
lines = out.strip().split("\n")
_ = lines.pop(0) # header
self.gpus = []
for line in lines:
cols = line.split(", ")
self.gpus.append(
{
"index": cols[0],
"name": cols[1],
"bus_id": cols[2],
"driver_version": cols[3],
"memory.total": cols[4],
"compute_mode": cols[5],
}
)
.strip()
.split("\n")[1:]
)
self.gpus = [
dict(zip(gpu_info[0].split(", "), gpu.split(", ")))
for gpu in gpu_info[1:]
]
except subprocess.CalledProcessError:
except subprocess.CalledProcessError as e:
lgr.warning("Error collecting gpu information: %s", str(e))

Check warning on line 354 in src/con_duct/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/con_duct/__main__.py#L353-L354

Added lines #L353 - L354 were not covered by tests
self.gpus = None

def collect_sample(self) -> Optional[Sample]:
Expand Down
25 changes: 25 additions & 0 deletions test/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,28 @@ def test_execution_summary_formatted(
assert "unknown" in output
# Process did not finish, we didn't set start_time, so remains nan but there
assert "wall clock time: nan" in report.execution_summary_formatted.lower()


@mock.patch("con_duct.__main__.shutil.which")
@mock.patch("con_duct.__main__.subprocess.check_output")
@mock.patch("con_duct.__main__.LogPaths")
def test_gpu_parsing(
mock_log_paths: mock.MagicMock, mock_sp: mock.MagicMock, _mock_which: mock.MagicMock
) -> None:
mock_sp.return_value = (
"index, name, pci.bus_id, driver_version, memory.total [MiB], compute_mode\n"
"0, NVIDIA RTX A5500 Laptop GPU, 00000000:01:00.0, 535.183.01, 16384 MiB, Default"
).encode("utf-8")
report = Report("_cmd", [], mock_log_paths, EXECUTION_SUMMARY_FORMAT, clobber=False)
report.get_system_info()
assert report.gpus is not None
assert report.gpus == [
{
"index": "0",
"name": "NVIDIA RTX A5500 Laptop GPU",
"bus_id": "00000000:01:00.0",
"driver_version": "535.183.01",
"memory.total": "16384 MiB",
"compute_mode": "Default",
}
]
Loading