-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup.py
107 lines (91 loc) · 3.1 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from setuptools import setup
import subprocess
import os
import os.path as osp
import warnings
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
ROOT_DIR = osp.dirname(osp.abspath(__file__))
__version__ = "0.0.1"
INSTALL_REQUIREMENTS = ["wandb", "configargparse"]
include_dirs = [
osp.join(ROOT_DIR, "src"),
]
CC_FLAGS = ["-std=c++17", "-Wunused-local-typedefs"]
NVCC_FLAGS = ["-std=c++17"]
CC_FLAGS += ["-O3", "-fPIC"]
NVCC_FLAGS += ["-O3", "-Xcompiler=-fno-gnu-unique,-fPIC"]
# Build dependency with Cmake
stdgpu_dir = osp.join(ROOT_DIR, "ext", "stdgpu")
stdgpu_build_dir = osp.join(stdgpu_dir, "build")
stdgpu_install_dir = osp.join(stdgpu_dir, "install")
cmake_flags = [
f"-DCMAKE_INSTALL_PREFIX={stdgpu_install_dir}",
"-DSTDGPU_BUILD_SHARED_LIBS=OFF",
"-DSTDGPU_BUILD_EXAMPLES=OFF",
"-DSTDGPU_BUILD_TESTS=OFF",
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON",
]
print("Building external project ...")
subprocess.run(["cmake", "-S", stdgpu_dir, "-B", stdgpu_build_dir] + cmake_flags)
subprocess.run(["cmake", "--build", stdgpu_build_dir, "-t", "install"])
include_dirs.append(osp.join(stdgpu_install_dir, "include/"))
library_dirs = [osp.join(stdgpu_install_dir, "lib")]
libraries = ["stdgpu"]
# From PyTorch3D
cub_home = os.environ.get("CUB_HOME", None)
if cub_home is None:
prefix = os.environ.get("CONDA_PREFIX", None)
if prefix is not None and os.path.isdir(prefix + "/include/cub"):
cub_home = prefix + "/include"
if cub_home is None:
warnings.warn(
"The environment variable `CUB_HOME` was not found."
"Installation will fail if your system CUDA toolkit version is less than 11."
"NVIDIA CUB can be downloaded "
"from `https://github.com/NVIDIA/cub/releases`. You can unpack "
"it to a location of your choice and set the environment variable "
"`CUB_HOME` to the folder containing the `CMakeListst.txt` file."
)
else:
include_dirs.append(os.path.realpath(cub_home).replace("\\ ", " "))
try:
ext_modules = [
CUDAExtension(
"__ash",
[
"ash/src/pybind.cpp",
"ash/src/hashmap.cpp",
"ash/src/hashmap_gpu.cu",
"ash/src/hashmap_cpu.cpp",
"ash/src/sampler.cu",
"ash/src/grid.cu"
],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args={
"cxx": CC_FLAGS,
"nvcc": NVCC_FLAGS,
},
optional=False,
),
]
except:
import warnings
warnings.warn("Failed to build CUDA extension")
ext_modules = []
# shutil.copy(osp.join(library_dirs[0], 'libstdgpu.so'),
# osp.join('/home', 'wei', 'libstdgpu.so'))
setup(
name="ash",
version=__version__,
author="Wei Dong",
author_email="[email protected]",
description="",
long_description="",
ext_modules=ext_modules,
setup_requires=["pybind11>=2.5.0"],
packages=["ash"], # Directory name
cmdclass={"build_ext": BuildExtension},
zip_safe=False,
)