Parse the --split "A,B" CLI argument and validate it against the device. Returns (long_count, critical_count).
(arg: Optional[str], device: Device)
| 211 | |
| 212 | |
| 213 | def parse_split(arg: Optional[str], device: Device) -> Tuple[int, int]: |
| 214 | """ |
| 215 | Parse the --split "A,B" CLI argument and validate it against the device. |
| 216 | |
| 217 | Returns (long_count, critical_count). |
| 218 | """ |
| 219 | sm = device.resources.sm |
| 220 | total = sm.sm_count |
| 221 | min_part = sm.min_partition_size |
| 222 | |
| 223 | if arg is None: |
| 224 | # Auto: reserve a small aligned slice for the critical kernel and |
| 225 | # hand the rest (also aligned) to the long-running kernel. We |
| 226 | # can't trust `min_partition_size` alone: on some GPUs (e.g. |
| 227 | # 188-SM Blackwell) the driver requires stricter alignment than |
| 228 | # it reports. Escalate the granularity until the driver accepts |
| 229 | # a pair. |
| 230 | prefer_critical = max(min_part, min(16, total // 8)) |
| 231 | found = _find_working_split(sm, prefer_critical=prefer_critical) |
| 232 | if found is None: |
| 233 | print( |
| 234 | "Error: could not find an SM split that the driver accepts " |
| 235 | f"on this device (total SMs={total}, " |
| 236 | f"min_partition_size={min_part})." |
| 237 | ) |
| 238 | print( |
| 239 | " The driver enforces architecture-specific alignment " |
| 240 | "rules beyond min_partition_size; try passing an explicit " |
| 241 | "--split." |
| 242 | ) |
| 243 | sys.exit(1) |
| 244 | long_count, critical_count, granularity = found |
| 245 | if granularity > min_part: |
| 246 | print( |
| 247 | f"Note: driver required stricter alignment than " |
| 248 | f"min_partition_size={min_part}; selected split uses " |
| 249 | f"granularity={granularity} SMs." |
| 250 | ) |
| 251 | return long_count, critical_count |
| 252 | |
| 253 | # User-provided split. |
| 254 | try: |
| 255 | parts = [int(x.strip()) for x in arg.split(",")] |
| 256 | except ValueError: |
| 257 | print(f"Error: --split must look like 'A,B', got: {arg!r}") |
| 258 | sys.exit(1) |
| 259 | if len(parts) != 2: |
| 260 | print( |
| 261 | "Error: --split must contain exactly two comma-separated " |
| 262 | f"integers, got: {arg!r}" |
| 263 | ) |
| 264 | sys.exit(1) |
| 265 | long_count, critical_count = parts |
| 266 | |
| 267 | errors = [] |
| 268 | if long_count <= 0 or critical_count <= 0: |
| 269 | errors.append("both partition sizes must be positive") |
| 270 | if long_count % min_part != 0 or critical_count % min_part != 0: |
no test coverage detected