| 9 | |
| 10 | |
| 11 | class FPQuantizerBuilder(CUDAOpBuilder): |
| 12 | BUILD_VAR = "DS_BUILD_FP_QUANTIZER" |
| 13 | NAME = "fp_quantizer" |
| 14 | |
| 15 | def __init__(self, name=None): |
| 16 | name = self.NAME if name is None else name |
| 17 | super().__init__(name=name) |
| 18 | |
| 19 | def absolute_name(self): |
| 20 | return f'deepspeed.ops.fp_quantizer.{self.NAME}_op' |
| 21 | |
| 22 | def is_compatible(self, verbose=False): |
| 23 | try: |
| 24 | import torch |
| 25 | except ImportError: |
| 26 | if verbose: |
| 27 | self.warning("Please install torch if trying to pre-compile inference kernels") |
| 28 | return False |
| 29 | |
| 30 | cuda_okay = True |
| 31 | if not os.environ.get("DS_IGNORE_CUDA_DETECTION"): |
| 32 | if not self.is_rocm_pytorch() and torch.cuda.is_available(): #ignore-cuda |
| 33 | sys_cuda_major, _ = installed_cuda_version() |
| 34 | torch_cuda_major = int(torch.version.cuda.split('.')[0]) |
| 35 | cuda_capability = self.cuda_capability_major() |
| 36 | if cuda_capability is not None and cuda_capability < 8: |
| 37 | if verbose: |
| 38 | self.warning("NVIDIA Inference is only supported on Ampere and newer architectures") |
| 39 | cuda_okay = False |
| 40 | if cuda_capability is not None and cuda_capability >= 8: |
| 41 | if torch_cuda_major < 11 or sys_cuda_major < 11: |
| 42 | if verbose: |
| 43 | self.warning("On Ampere and higher architectures please use CUDA 11+") |
| 44 | cuda_okay = False |
| 45 | |
| 46 | return super().is_compatible(verbose) and cuda_okay |
| 47 | |
| 48 | def filter_ccs(self, ccs): |
| 49 | ccs_retained = [] |
| 50 | ccs_pruned = [] |
| 51 | for cc in [cc.split('.') for cc in ccs]: |
| 52 | if int(cc[0]) >= 8: |
| 53 | ccs_retained.append(cc) |
| 54 | else: |
| 55 | ccs_pruned.append(cc) |
| 56 | if len(ccs_pruned) > 0: |
| 57 | self.warning(f"Filtered compute capabilities {ccs_pruned}") |
| 58 | return ccs_retained |
| 59 | |
| 60 | def sources(self): |
| 61 | return [ |
| 62 | "csrc/fp_quantizer/fp_quantize_impl.cu", |
| 63 | "csrc/fp_quantizer/fp_quantize.cpp", |
| 64 | ] |
| 65 | |
| 66 | def extra_ldflags(self): |
| 67 | if not self.is_rocm_pytorch(): |
| 68 | return ['-lcurand'] |