-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.py
67 lines (58 loc) · 2.3 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os, sys
import os.path as osp
from glob import glob
from setuptools import setup, find_packages
import torch
from torch.__config__ import parallel_info
from torch.utils.cpp_extension import BuildExtension
from torch.utils.cpp_extension import CUDAExtension
# check machine exists gpu
if not torch.cuda.is_available():
raise Exception("Machine must have cuda device!")
# check cuda samples include dir
cuda_samples_include_dir = os.getenv("CUDA_SAMPLES_INCLUDE_DIR", "/usr/local/cuda/samples/common/inc")
if not osp.exists(cuda_samples_include_dir):
raise Exception(f"Cuda samples include dir: {cuda_samples_include_dir} doesn't exist! You may specify environment variable `CUDA_SAMPLES_INCLUDE_DIR` to resolve this problem.")
# must compile with openmp
info = parallel_info()
if ("backend: OpenMP" not in info) or ("OpenMP not found" in info):
raise Exception("Must compile with openmp!")
def get_extension():
extra_compile_args = dict(cxx=["-O3",
"-DAT_PARALLEL_OPENMP",
"-fopenmp" if sys.platform == "win32" else "/openmp",
],
nvcc=["-O3",
"-w",
"-Xptxas=-w",
"-Xcompiler=-fopenmp,-funroll-loops",
],
)
return CUDAExtension(
name="torch_kdtree",
sources=glob("src/*.cu"),
include_dirs=["src", cuda_samples_include_dir],
define_macros=[("TORCH_EXTENSION_NAME", "torch_kdtree")],
extra_compile_args=extra_compile_args,
extra_link_args=[],
)
setup(
name="torch_kdtree",
version="0.0",
author="Jiabao Lei",
author_email="[email protected]",
url="https://github.com/Karbo123/torch_kdtree",
description="A CUDA implementation of KDTree in PyTorch",
keywords=["pytorch", "kdtree", "cuda", "search"],
license="MIT",
python_requires=">=3.7",
install_requires=[],
setup_requires=[],
tests_require=[],
extras_require=dict(),
ext_modules=[get_extension()],
cmdclass={
"build_ext": BuildExtension.with_options(no_python_abi_suffix=True, use_ninja=False)
},
packages=find_packages(),
)