Return True if ``monai._C`` (the compiled C extension providing ``grid_pull``) is not compiled with support for the given CUDA device's compute capability. Args: device: The torch device to check for compiled extension support. Returns: True if the device is CUDA w
(device: torch.device)
| 55 | |
| 56 | |
| 57 | def _compiled_unsupported(device: torch.device) -> bool: |
| 58 | """ |
| 59 | Return True if ``monai._C`` (the compiled C extension providing ``grid_pull``) is not |
| 60 | compiled with support for the given CUDA device's compute capability. |
| 61 | |
| 62 | Args: |
| 63 | device: The torch device to check for compiled extension support. |
| 64 | |
| 65 | Returns: |
| 66 | True if the device is CUDA with compute capability major >= 12 (Blackwell+), |
| 67 | False otherwise. Always returns False for CPU devices. |
| 68 | |
| 69 | Note: |
| 70 | ``monai._C`` is built at install time against a fixed set of CUDA architectures. |
| 71 | NVIDIA Blackwell GPUs (sm_120, compute capability 12.x) and newer were not included in |
| 72 | the default ``TORCH_CUDA_ARCH_LIST`` when the MONAI slim image was originally built, |
| 73 | so executing ``grid_pull`` on those devices produces incorrect results. Falling back to |
| 74 | the PyTorch-native ``affine_grid`` + ``grid_sample`` path (``USE_COMPILED=False``) gives |
| 75 | correct output on all architectures. |
| 76 | |
| 77 | The threshold (``major >= 12``) matches the first architecture family (Blackwell, sm_120) |
| 78 | that shipped after the highest sm supported in the current default build list (sm_90, |
| 79 | Hopper). Adjust this constant when ``monai._C`` is rebuilt with sm_120+ support. |
| 80 | """ |
| 81 | if device.type != "cuda": |
| 82 | return False |
| 83 | try: |
| 84 | from monai._C import max_compute_capability as _max_cc_func |
| 85 | |
| 86 | max_cc = _max_cc_func() |
| 87 | if max_cc == 0: |
| 88 | # No architecture info embedded (older build), fall back to heuristic |
| 89 | return bool(torch.cuda.get_device_properties(device).major >= 12) |
| 90 | device_cc = ( |
| 91 | torch.cuda.get_device_properties(device).major * 100 + torch.cuda.get_device_properties(device).minor |
| 92 | ) |
| 93 | return bool(device_cc > max_cc) |
| 94 | except (ImportError, AttributeError): |
| 95 | return bool(torch.cuda.get_device_properties(device).major >= 12) |
| 96 | |
| 97 | |
| 98 | def _maybe_new_metatensor(img, dtype=None, device=None): |
no outgoing calls
searching dependent graphs…