comm.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (c) Microsoft Corporation.
  2. # SPDX-License-Identifier: Apache-2.0
  3. # DeepSpeed Team
  4. import os
  5. from .builder import CPUOpBuilder
  6. class CCLCommBuilder(CPUOpBuilder):
  7. BUILD_VAR = "DS_BUILD_CCL_COMM"
  8. NAME = "deepspeed_ccl_comm"
  9. def __init__(self, name=None):
  10. name = self.NAME if name is None else name
  11. super().__init__(name=name)
  12. def absolute_name(self):
  13. return f'deepspeed.ops.comm.{self.NAME}_op'
  14. def sources(self):
  15. return ['csrc/cpu/comm/ccl.cpp', 'csrc/cpu/comm/shm.cpp']
  16. def include_paths(self):
  17. includes = ['csrc/cpu/includes']
  18. return includes
  19. def cxx_args(self):
  20. return ['-O2', '-fopenmp']
  21. def is_compatible(self, verbose=False):
  22. # TODO: add soft compatibility check for private binary release.
  23. # a soft check, as in we know it can be trivially changed.
  24. return super().is_compatible(verbose)
  25. def extra_ldflags(self):
  26. ccl_root_path = os.environ.get("CCL_ROOT")
  27. if ccl_root_path is None:
  28. raise ValueError(
  29. "Didn't find CCL_ROOT, install oneCCL from https://github.com/oneapi-src/oneCCL and source its environment variable"
  30. )
  31. return []
  32. else:
  33. return ['-lccl', f'-L{ccl_root_path}/lib']
  34. class ShareMemCommBuilder(CPUOpBuilder):
  35. BUILD_VAR = "DS_BUILD_SHM_COMM"
  36. NAME = "deepspeed_shm_comm"
  37. def __init__(self, name=None):
  38. name = self.NAME if name is None else name
  39. super().__init__(name=name)
  40. def absolute_name(self):
  41. return f'deepspeed.ops.comm.{self.NAME}_op'
  42. def sources(self):
  43. return ['csrc/cpu/comm/shm_interface.cpp', 'csrc/cpu/comm/shm.cpp']
  44. def include_paths(self):
  45. includes = ['csrc/cpu/includes']
  46. return includes
  47. def cxx_args(self):
  48. return ['-O2', '-fopenmp']
  49. def is_compatible(self, verbose=False):
  50. # TODO: add soft compatibility check for private binary release.
  51. # a soft check, as in we know it can be trivially changed.
  52. return super().is_compatible(verbose)