setup.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import os
  2. from setuptools import setup
  3. from torch.utils.cpp_extension import BuildExtension, CUDAExtension
  4. _src_path = os.path.dirname(os.path.abspath(__file__))
  5. nvcc_flags = [
  6. '-O3', '-std=c++14',
  7. # '-lineinfo', # to debug illegal memory access
  8. '-U__CUDA_NO_HALF_OPERATORS__', '-U__CUDA_NO_HALF_CONVERSIONS__', '-U__CUDA_NO_HALF2_OPERATORS__',
  9. ]
  10. if os.name == "posix":
  11. c_flags = ['-O3', '-std=c++14']
  12. elif os.name == "nt":
  13. c_flags = ['/O2', '/std:c++17']
  14. # find cl.exe
  15. def find_cl_path():
  16. import glob
  17. for edition in ["Enterprise", "Professional", "BuildTools", "Community"]:
  18. paths = sorted(glob.glob(r"C:\\Program Files (x86)\\Microsoft Visual Studio\\*\\%s\\VC\\Tools\\MSVC\\*\\bin\\Hostx64\\x64" % edition), reverse=True)
  19. if paths:
  20. return paths[0]
  21. # If cl.exe is not on path, try to find it.
  22. if os.system("where cl.exe >nul 2>nul") != 0:
  23. cl_path = find_cl_path()
  24. if cl_path is None:
  25. raise RuntimeError("Could not locate a supported Microsoft Visual C++ installation")
  26. os.environ["PATH"] += ";" + cl_path
  27. '''
  28. Usage:
  29. python setup.py build_ext --inplace # build extensions locally, do not install (only can be used from the parent directory)
  30. python setup.py install # build extensions and install (copy) to PATH.
  31. pip install . # ditto but better (e.g., dependency & metadata handling)
  32. python setup.py develop # build extensions and install (symbolic) to PATH.
  33. pip install -e . # ditto but better (e.g., dependency & metadata handling)
  34. '''
  35. setup(
  36. name='raymarching_face', # package name, import this to use python API
  37. ext_modules=[
  38. CUDAExtension(
  39. name='_raymarching_face', # extension name, import this to use CUDA API
  40. sources=[os.path.join(_src_path, 'src', f) for f in [
  41. 'raymarching.cu',
  42. 'bindings.cpp',
  43. ]],
  44. extra_compile_args={
  45. 'cxx': c_flags,
  46. 'nvcc': nvcc_flags,
  47. }
  48. ),
  49. ],
  50. cmdclass={
  51. 'build_ext': BuildExtension,
  52. }
  53. )