Look up GPU spec from dbgpu database. Returns GPUSpecification or None.
(name: str)
| 152 | |
| 153 | |
| 154 | def _lookup_dbgpu(name: str) -> GPUSpecification | None: |
| 155 | """Look up GPU spec from dbgpu database. Returns GPUSpecification or None.""" |
| 156 | from dbgpu import GPUDatabase |
| 157 | |
| 158 | db = GPUDatabase.default() |
| 159 | |
| 160 | # Normalize input: "GTX1080" → "GTX 1080" |
| 161 | normalized = _normalize_gpu_name(name) |
| 162 | compact = re.sub(r"\s+", "", normalized.lower()) |
| 163 | names_to_try = [name] if normalized == name else [name, normalized] |
| 164 | alias_hits = _COMMON_GPU_ALIASES.get(compact) |
| 165 | if alias_hits: |
| 166 | names_to_try.extend(alias_hits) |
| 167 | |
| 168 | for n in names_to_try: |
| 169 | # 1) Exact key lookup |
| 170 | try: |
| 171 | return db[n] |
| 172 | except KeyError: |
| 173 | pass |
| 174 | |
| 175 | # 2) Try with common manufacturer prefixes |
| 176 | for prefix in _MANUFACTURER_PREFIXES: |
| 177 | try: |
| 178 | return db[prefix + n] |
| 179 | except KeyError: |
| 180 | pass |
| 181 | |
| 182 | # 3) Substring match with word-boundary filtering |
| 183 | result = _substring_search(db, n) |
| 184 | if result is not None: |
| 185 | return result |
| 186 | |
| 187 | # 4) Fuzzy search as last resort (use normalized name + token_set_ratio) |
| 188 | try: |
| 189 | from thefuzz import fuzz, process |
| 190 | |
| 191 | results = process.extract( |
| 192 | normalized, db.names, limit=3, scorer=fuzz.token_set_ratio |
| 193 | ) |
| 194 | if results and results[0][1] >= 90: |
| 195 | return db[results[0][0]] |
| 196 | # Store top suggestions for error messages |
| 197 | if results: |
| 198 | _last_suggestions[:] = [(n, s) for n, s in results if s >= 70] |
| 199 | except ImportError: |
| 200 | pass |
| 201 | return None |
| 202 | |
| 203 | |
| 204 | # Mutable list to pass suggestions from lookup to error message |
no test coverage detected