"""Report generation module - export test results to JSON/HTML.""" import json import os from datetime import datetime from pathlib import Path from typing import Optional from rich.console import Console from rich.panel import Panel HTML_TEMPLATE = """ H200 Test Report - {timestamp}

H200 Training Server Test Report

Generated: {timestamp} | Server: {hostname}
{content} """ class ReportGenerator: def __init__(self, config: dict): self.config = config self.console = Console() self.report_cfg = config.get("report", {}) def generate(self, results: dict, fmt: str = None, output: str = None) -> str: fmt = fmt or self.report_cfg.get("format", "json") output_dir = self.report_cfg.get("output_dir", "./reports") os.makedirs(output_dir, exist_ok=True) timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") if not output: output = os.path.join(output_dir, f"h200_report_{timestamp}.{fmt}") if fmt == "json": return self._generate_json(results, output) elif fmt == "html": return self._generate_html(results, output) else: self.console.print(f"[red]Unsupported format: {fmt}[/red]") return "" def _generate_json(self, results: dict, output: str) -> str: with open(output, "w") as f: json.dump(results, f, indent=2, default=str) self.console.print(f"[green]JSON report saved to: {output}[/green]") return output def _generate_html(self, results: dict, output: str) -> str: import socket hostname = socket.gethostname() timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") sections = [] if "gpu_info" in results: gpus = results["gpu_info"].get("gpus", []) rows = "" for g in gpus: rows += f"GPU {g['index']}{g['name']}" rows += f"{g['vram_total_mb']} MB" rows += f"{g['temperature']}°C" rows += f"{g['clock_sm']} MHz" sections.append( f'

GPU Information

' f'

Driver: {results["gpu_info"].get("driver_version", "N/A")} | ' f'CUDA: {results["gpu_info"].get("cuda_version", "N/A")} | ' f'Count: {len(gpus)}

' f'' f'{rows}
GPUModelVRAMTempSM Clock
' ) if "health" in results: h = results["health"] passed = h.get("passed", False) cls = "pass" if passed else "fail" txt = "ALL PASSED" if passed else "SOME CHECKS FAILED" sections.append(f'
{txt}
') if "benchmark" in results and "memory" in results["benchmark"]: mem = results["benchmark"]["memory"] sections.append( f'

Memory Bandwidth

' f'
{mem.get("d2d_bandwidth_gbps", "N/A")} GB/s
' f'
D2D (HBM3e)
' f'
{mem.get("efficiency_pct", "N/A")}%
' f'
Efficiency vs Peak ({mem.get("peak_bandwidth_gbps", 989)} GB/s)
' f'
' ) if "benchmark" in results and "compute" in results["benchmark"]: comp = results["benchmark"]["compute"] dtype_rows = "" per_dtype = comp.get("per_dtype_tflops", {}) eff = comp.get("efficiency_pct", {}) for dt, tflops in per_dtype.items(): ef = eff.get(dt, 0) cls = "pass" if ef >= 80 else ("warn" if ef >= 50 else "fail") if isinstance(tflops, (int, float)): dtype_rows += f'{dt.upper()}{tflops:.1f} TFLOPS' dtype_rows += f'{ef:.1f}%' if dtype_rows: sections.append( f'

Compute Throughput

' f'' f'{dtype_rows}
DTypeAchievedEfficiency
' ) if "training" in results: t = results["training"] sections.append( f'

Training Simulation

' f'
{t.get("throughput_tokens_per_sec", "N/A")}
' f'
Tokens/sec
' f'
{t.get("avg_step_time_ms", "N/A")} ms
' f'
Avg Step Time
' f'
{t.get("peak_memory_gb", "N/A")} GB
' f'
Peak Memory
' f'
' ) content = "\n".join(sections) html = HTML_TEMPLATE.format(timestamp=timestamp, hostname=hostname, content=content) with open(output, "w") as f: f.write(html) self.console.print(f"[green]HTML report saved to: {output}[/green]") return output