setup.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import os
  15. import glob
  16. from os import path
  17. import torch
  18. from setuptools import setup, find_packages
  19. from codecs import open
  20. from torch.utils.cpp_extension import CUDA_HOME
  21. from torch.utils.cpp_extension import CppExtension
  22. from torch.utils.cpp_extension import CUDAExtension
  23. here = path.abspath(path.dirname(__file__))
  24. def get_extensions():
  25. this_dir = os.path.dirname(os.path.abspath(__file__))
  26. extensions_dir = os.path.join(this_dir, "effdet", "csrc", "nms")
  27. main_file = glob.glob(os.path.join(extensions_dir, "*.cpp"))
  28. source_cpu = glob.glob(os.path.join(extensions_dir, "cpu", "*.cpp"))
  29. source_cuda = glob.glob(os.path.join(extensions_dir, "cuda", "*.cu"))
  30. sources = main_file + source_cpu
  31. extension = CppExtension
  32. extra_compile_args = {"cxx": []}
  33. define_macros = []
  34. if CUDA_HOME is not None:
  35. extension = CUDAExtension
  36. sources += source_cuda
  37. define_macros += [("WITH_CUDA", None)]
  38. extra_compile_args["nvcc"] = [
  39. "-DCUDA_HAS_FP16=1",
  40. "-D__CUDA_NO_HALF_OPERATORS__",
  41. "-D__CUDA_NO_HALF_CONVERSIONS__",
  42. "-D__CUDA_NO_HALF2_OPERATORS__",
  43. ]
  44. sources = [os.path.join(extensions_dir, s) for s in sources]
  45. include_dirs = [extensions_dir]
  46. ext_modules = [
  47. extension(
  48. "effdet_ext._C",
  49. sources,
  50. include_dirs=include_dirs,
  51. define_macros=define_macros,
  52. extra_compile_args=extra_compile_args,
  53. ),
  54. CUDAExtension('focal_loss_cuda', [
  55. 'effdet/csrc/focal_loss/focal_loss_cuda.cpp',
  56. 'effdet/csrc/focal_loss/focal_loss_cuda_kernel.cu',
  57. ],
  58. extra_compile_args={
  59. 'cxx': ['-O3', ],
  60. 'nvcc':['-O3', '-lineinfo', '-res-usage', '--use_fast_math', '--ftz=false']
  61. })
  62. ]
  63. return ext_modules
  64. setup(
  65. name='effdet',
  66. version="0.4.1",
  67. description='EfficientDet for PyTorch',
  68. packages=find_packages(exclude=['data']),
  69. ext_modules=get_extensions(),
  70. cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
  71. )