Try to import detect_gpu from bench.py; fall back to standalone.
()
| 168 | |
| 169 | |
| 170 | def detect_gpu() -> GPUSpec: |
| 171 | """Try to import detect_gpu from bench.py; fall back to standalone.""" |
| 172 | try: |
| 173 | bench_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "bench.py") |
| 174 | spec = importlib.util.spec_from_file_location("bench", bench_path) |
| 175 | if spec and spec.loader: |
| 176 | bench_mod = importlib.util.module_from_spec(spec) |
| 177 | spec.loader.exec_module(bench_mod) # type: ignore[union-attr] |
| 178 | gpu = bench_mod.detect_gpu() # type: ignore[attr-defined] |
| 179 | # Convert to our local GPUSpec (fields are identical) |
| 180 | return GPUSpec( |
| 181 | name=gpu.name, |
| 182 | sm_count=gpu.sm_count, |
| 183 | memory_gb=gpu.memory_gb, |
| 184 | peak_tflops_fp16=gpu.peak_tflops_fp16, |
| 185 | peak_tflops_bf16=gpu.peak_tflops_bf16, |
| 186 | peak_tflops_fp32=gpu.peak_tflops_fp32, |
| 187 | peak_bandwidth_gb_s=gpu.peak_bandwidth_gb_s, |
| 188 | l2_cache_mb=gpu.l2_cache_mb, |
| 189 | compute_capability=gpu.compute_capability, |
| 190 | ) |
| 191 | except Exception: |
| 192 | pass |
| 193 | return _fallback_detect_gpu() |
| 194 | |
| 195 | |
| 196 | # --------------------------------------------------------------------------- |
no test coverage detected