setup.py 940 B

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. import glob
  3. import paddle
  4. from paddle.utils.cpp_extension import CppExtension, CUDAExtension, setup
  5. def get_extensions():
  6. root_dir = os.path.dirname(os.path.abspath(__file__))
  7. ext_root_dir = os.path.join(root_dir, 'csrc')
  8. sources = []
  9. for ext_name in os.listdir(ext_root_dir):
  10. ext_dir = os.path.join(ext_root_dir, ext_name)
  11. source = glob.glob(os.path.join(ext_dir, '*.cc'))
  12. kwargs = dict()
  13. if paddle.device.is_compiled_with_cuda():
  14. source += glob.glob(os.path.join(ext_dir, '*.cu'))
  15. if not source:
  16. continue
  17. sources += source
  18. if paddle.device.is_compiled_with_cuda():
  19. extension = CUDAExtension(
  20. sources, extra_compile_args={'cxx': ['-DPADDLE_WITH_CUDA']})
  21. else:
  22. extension = CppExtension(sources)
  23. return extension
  24. if __name__ == "__main__":
  25. setup(name='ext_op', ext_modules=get_extensions())