Skip to content

Commit 6b8c25e

Browse files
committed
Sanitize outputs on apu-memory-tuner
1 parent dc63e08 commit 6b8c25e

3 files changed

Lines changed: 22 additions & 4 deletions

File tree

skills/apu-memory-tuner/scripts/apply_profile.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
from dataclasses import dataclass
6262
from pathlib import Path
6363

64+
from _sanitize import sanitize_process_output
65+
6466
PAGE_SIZE_BYTES = 4096
6567
MIN_VRAM_GB = 0.5 # Floor most BIOSes allow for the UMA frame buffer.
6668
MIN_GTT_GB = 1.0 # Below this, even routine GPU work fails.
@@ -83,9 +85,13 @@ def _run(cmd: list[str], timeout: float = 60.0) -> tuple[int, str, str]:
8385
r = subprocess.run(
8486
cmd, capture_output=True, text=True, timeout=timeout, check=False,
8587
)
86-
return r.returncode, r.stdout or "", r.stderr or ""
88+
return (
89+
r.returncode,
90+
sanitize_process_output(r.stdout),
91+
sanitize_process_output(r.stderr),
92+
)
8793
except (FileNotFoundError, subprocess.SubprocessError, OSError) as e:
88-
return 127, "", str(e)
94+
return 127, "", sanitize_process_output(str(e))
8995

9096

9197
def _read_text(path: str) -> str:

skills/apu-memory-tuner/scripts/detect_platform.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
from dataclasses import asdict, dataclass, field
3737
from pathlib import Path
3838

39+
from _sanitize import sanitize_process_output
40+
3941
# Mapping from LLVM gfx target to the marketing-friendly generation bucket
4042
# the rest of the skill keys off. RDNA3.5 (gfx115x) is the only generation
4143
# the source ROCm doc describes shared-memory tuning for, so it is the only
@@ -91,7 +93,11 @@ def _run(cmd: list[str], timeout: float = 5.0) -> tuple[int, str, str]:
9193
r = subprocess.run(
9294
cmd, capture_output=True, text=True, timeout=timeout, check=False,
9395
)
94-
return r.returncode, r.stdout or "", r.stderr or ""
96+
return (
97+
r.returncode,
98+
sanitize_process_output(r.stdout),
99+
sanitize_process_output(r.stderr),
100+
)
95101
except (FileNotFoundError, subprocess.SubprocessError, OSError):
96102
return 127, "", ""
97103

skills/apu-memory-tuner/scripts/show_config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
from dataclasses import asdict, dataclass
3737
from pathlib import Path
3838

39+
from _sanitize import sanitize_process_output
40+
3941
# 4 KiB is the page size assumed by the amdgpu/TTM accounting on every
4042
# platform we target. The kernel param is in pages, the user thinks in GB.
4143
PAGE_SIZE_BYTES = 4096
@@ -64,7 +66,11 @@ def _run(cmd: list[str], timeout: float = 10.0) -> tuple[int, str, str]:
6466
r = subprocess.run(
6567
cmd, capture_output=True, text=True, timeout=timeout, check=False,
6668
)
67-
return r.returncode, r.stdout or "", r.stderr or ""
69+
return (
70+
r.returncode,
71+
sanitize_process_output(r.stdout),
72+
sanitize_process_output(r.stderr),
73+
)
6874
except (FileNotFoundError, subprocess.SubprocessError, OSError):
6975
return 127, "", ""
7076

0 commit comments

Comments
 (0)