builder.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (c) 2023 Habana Labs, Ltd. an Intel Company
  2. # Copyright (c) Microsoft Corporation.
  3. # SPDX-License-Identifier: Apache-2.0
  4. # DeepSpeed Team
  5. try:
  6. # is op_builder from deepspeed or a 3p version? this should only succeed if it's deepspeed
  7. # if successful this also means we're doing a local install and not JIT compile path
  8. from op_builder import __deepspeed__ # noqa: F401 # type: ignore
  9. from op_builder.builder import OpBuilder
  10. except ImportError:
  11. from deepspeed.ops.op_builder.builder import OpBuilder
  12. class CPUOpBuilder(OpBuilder):
  13. def builder(self):
  14. from torch.utils.cpp_extension import CppExtension as ExtensionBuilder
  15. compile_args = {'cxx': self.strip_empty_entries(self.cxx_args())}
  16. cpp_ext = ExtensionBuilder(name=self.absolute_name(),
  17. sources=self.strip_empty_entries(self.sources()),
  18. include_dirs=self.strip_empty_entries(self.include_paths()),
  19. libraries=self.strip_empty_entries(self.libraries_args()),
  20. extra_compile_args=compile_args)
  21. return cpp_ext
  22. def cxx_args(self):
  23. return ['-O3', '-g', '-Wno-reorder']
  24. def libraries_args(self):
  25. return []