Unified CSV result writer with metadata header.
| 138 | |
| 139 | |
| 140 | class CSVWriter: |
| 141 | """Unified CSV result writer with metadata header.""" |
| 142 | |
| 143 | def __init__(self, filename, headers, gpu_info=None, benchmark_name=None): |
| 144 | self.filename = filename |
| 145 | self.headers = headers |
| 146 | self.f = open(filename, "w", newline="") |
| 147 | self.writer = csv.writer(self.f) |
| 148 | |
| 149 | # Write metadata as comments |
| 150 | if gpu_info: |
| 151 | self.f.write(f"# GPU: {gpu_info['name']}\n") |
| 152 | self.f.write(f"# SM Count: {gpu_info['sm_count']}\n") |
| 153 | self.f.write(f"# SM Arch: {gpu_info['sm_arch']}\n") |
| 154 | self.f.write(f"# Clock: {gpu_info['clock_mhz']} MHz\n") |
| 155 | if benchmark_name: |
| 156 | self.f.write(f"# Benchmark: {benchmark_name}\n") |
| 157 | self.f.write(f"# Date: {datetime.datetime.now().isoformat()}\n") |
| 158 | |
| 159 | self.writer.writerow(headers) |
| 160 | self.f.flush() |
| 161 | |
| 162 | def writerow(self, row): |
| 163 | self.writer.writerow(row) |
| 164 | self.f.flush() |
| 165 | |
| 166 | def close(self): |
| 167 | self.f.close() |
| 168 | |
| 169 | def __enter__(self): |
| 170 | return self |
| 171 | |
| 172 | def __exit__(self, *args): |
| 173 | self.close() |
| 174 | |
| 175 | |
| 176 | # ============================================================================= |
no outgoing calls
no test coverage detected