Returns nvcc compute capability compile flags. 1. Under ``jit_mode``, the precedence is: a. preserved ``TORCH_CUDA_ARCH_LIST`` captured by ``jit_load()`` b. live ``TORCH_CUDA_ARCH_LIST`` from the environment c. runtime device probing when the proces
(self, cross_compile_archs=None)
| 633 | return torch.cuda.get_device_properties(0).major |
| 634 | |
| 635 | def compute_capability_args(self, cross_compile_archs=None): |
| 636 | """ |
| 637 | Returns nvcc compute capability compile flags. |
| 638 | |
| 639 | 1. Under ``jit_mode``, the precedence is: |
| 640 | a. preserved ``TORCH_CUDA_ARCH_LIST`` captured by ``jit_load()`` |
| 641 | b. live ``TORCH_CUDA_ARCH_LIST`` from the environment |
| 642 | c. runtime device probing when the process is not in a bad-fork context |
| 643 | d. an error when no explicit arch list exists in a bad-fork context |
| 644 | |
| 645 | JIT mode auto-adds ``+PTX`` to the highest compute capability when |
| 646 | no entry already carries it, then sets ``TORCH_CUDA_ARCH_LIST`` so |
| 647 | PyTorch can generate the ``-gencode`` flags itself. |
| 648 | 2. ``TORCH_CUDA_ARCH_LIST`` takes priority over ``cross_compile_archs``. |
| 649 | 3. If neither is set default compute capabilities will be used. |
| 650 | |
| 651 | Format: |
| 652 | |
| 653 | - ``TORCH_CUDA_ARCH_LIST`` may use ; or whitespace separators. Examples: |
| 654 | |
| 655 | TORCH_CUDA_ARCH_LIST="6.1;7.5;8.6;9.0;10.0" pip install ... |
| 656 | TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0 7.5 8.0 8.6 9.0 10.0+PTX" pip install ... |
| 657 | |
| 658 | - ``cross_compile_archs`` uses ; separator. |
| 659 | |
| 660 | """ |
| 661 | ccs = [] |
| 662 | if self.jit_mode: |
| 663 | arch_string = getattr(self, '_jit_arch_list', None) |
| 664 | if arch_string: |
| 665 | arch_string = arch_string.replace(' ', ';') |
| 666 | ccs = [cc.strip() for cc in arch_string.split(';') if cc.strip()] |
| 667 | else: |
| 668 | arch_string = os.environ.get('TORCH_CUDA_ARCH_LIST', '').strip() |
| 669 | if arch_string: |
| 670 | arch_string = arch_string.replace(' ', ';') |
| 671 | ccs = [cc.strip() for cc in arch_string.split(';') if cc.strip()] |
| 672 | else: |
| 673 | if hasattr(torch.cuda, '_is_in_bad_fork') and torch.cuda._is_in_bad_fork(): |
| 674 | raise RuntimeError( |
| 675 | f"DeepSpeed JIT builder for '{self.name}' cannot probe CUDA device capabilities " |
| 676 | "in a forked subprocess where CUDA has already been initialized. Set " |
| 677 | "TORCH_CUDA_ARCH_LIST to specify target architectures explicitly.") |
| 678 | for i in range(torch.cuda.device_count()): |
| 679 | CC_MAJOR, CC_MINOR = torch.cuda.get_device_capability(i) |
| 680 | cc = f"{CC_MAJOR}.{CC_MINOR}" |
| 681 | if cc not in ccs: |
| 682 | ccs.append(cc) |
| 683 | if len(ccs) == 0: |
| 684 | raise RuntimeError(f"DeepSpeed JIT builder for '{self.name}' found no CUDA devices. Set " |
| 685 | "TORCH_CUDA_ARCH_LIST or make GPUs visible.") |
| 686 | |
| 687 | ccs = sorted(ccs, key=lambda cc: tuple(int(part.split('+')[0]) for part in cc.split('.'))) |
| 688 | if not any('+PTX' in cc for cc in ccs): |
| 689 | ccs[-1] += '+PTX' |
| 690 | else: |
| 691 | # Cross-compile mode, compile for various architectures |
| 692 | # env override takes priority |