spatial_inference.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. '''
  2. Copyright 2022 The Microsoft DeepSpeed Team
  3. '''
  4. from .builder import CUDAOpBuilder, installed_cuda_version
  5. class SpatialInferenceBuilder(CUDAOpBuilder):
  6. BUILD_VAR = "DS_BUILD_SPATIAL_INFERENCE"
  7. NAME = "spatial_inference"
  8. def __init__(self, name=None):
  9. name = self.NAME if name is None else name
  10. super().__init__(name=name)
  11. def absolute_name(self):
  12. return f'deepspeed.ops.spatial.{self.NAME}_op'
  13. def is_compatible(self, verbose=True):
  14. try:
  15. import torch
  16. except ImportError:
  17. self.warning(
  18. "Please install torch if trying to pre-compile inference kernels")
  19. return False
  20. cuda_okay = True
  21. if not self.is_rocm_pytorch() and torch.cuda.is_available():
  22. sys_cuda_major, _ = installed_cuda_version()
  23. torch_cuda_major = int(torch.version.cuda.split('.')[0])
  24. cuda_capability = torch.cuda.get_device_properties(0).major
  25. if cuda_capability >= 8:
  26. if torch_cuda_major < 11 or sys_cuda_major < 11:
  27. self.warning(
  28. "On Ampere and higher architectures please use CUDA 11+")
  29. cuda_okay = False
  30. return super().is_compatible(verbose) and cuda_okay
  31. def sources(self):
  32. return [
  33. 'csrc/spatial/csrc/opt_bias_add.cu',
  34. 'csrc/spatial/csrc/pt_binding.cpp',
  35. ]
  36. def include_paths(self):
  37. return ['csrc/spatial/includes', 'csrc/includes']