-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
executable file
·138 lines (118 loc) · 3.96 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import glob
import os
import os.path as osp
import sys
from itertools import product
import torch
from setuptools import find_packages, setup
from torch.__config__ import parallel_info
from torch.utils.cpp_extension import (
CUDA_HOME,
BuildExtension,
CppExtension,
CUDAExtension,
)
WITH_CUDA = torch.cuda.is_available() and CUDA_HOME is not None
suffices = ["cpu", "cuda"] if WITH_CUDA else ["cpu"]
if os.getenv("FORCE_CUDA", "0") == "1":
suffices = ["cuda", "cpu"]
if os.getenv("FORCE_ONLY_CUDA", "0") == "1":
suffices = ["cuda"]
if os.getenv("FORCE_ONLY_CPU", "0") == "1":
suffices = ["cpu"]
def get_extensions():
extensions = []
extensions_dir = osp.join(osp.dirname(osp.abspath(__file__)), "csrc")
main_files = glob.glob(osp.join(extensions_dir, "*.cpp"))
for main, suffix in product(main_files, suffices):
define_macros = []
libraries = []
extra_compile_args = {"cxx": ["-O2"]}
if not os.name == "nt": # Not on Windows:
extra_compile_args["cxx"] += ["-Wno-sign-compare"]
extra_link_args = ["-s"]
info = parallel_info()
if "backend: OpenMP" in info and "OpenMP not found" not in info:
extra_compile_args["cxx"] += ["-DAT_PARALLEL_OPENMP"]
if sys.platform == "win32":
extra_compile_args["cxx"] += ["/openmp"]
else:
extra_compile_args["cxx"] += ["-fopenmp"]
else:
print("Compiling without OpenMP...")
if suffix == "cuda":
define_macros += [("WITH_CUDA", None)]
nvcc_flags = os.getenv("NVCC_FLAGS", "")
nvcc_flags = [] if nvcc_flags == "" else nvcc_flags.split(" ")
nvcc_flags += ["--expt-relaxed-constexpr", "-O2"]
extra_compile_args["nvcc"] = nvcc_flags
if sys.platform == "win32":
extra_link_args += ["cusparse.lib"]
else:
extra_link_args += ["-lcusparse", "-l", "cusparse"]
name = main.split(os.sep)[-1][:-4]
sources = [main]
path = osp.join(extensions_dir, "cpu", f"{name}_cpu.cpp")
if osp.exists(path):
sources += [path]
path = osp.join(extensions_dir, "cuda", f"{name}_cuda.cu")
if suffix == "cuda" and osp.exists(path):
sources += [path]
Extension = CppExtension if suffix == "cpu" else CUDAExtension
extension = Extension(
f"thgsp._{name}_{suffix}",
sources,
include_dirs=[extensions_dir],
define_macros=define_macros,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
libraries=libraries,
)
extensions += [extension]
return extensions
install_requires = [
"torch>=1.7.0",
"torchvision",
"ray",
"scikit-learn",
"scipy",
"networkx",
"numba",
"torch-scatter",
"torch-sparse",
"torch-cluster",
"matplotlib",
"pandas",
"plotly",
"tqdm",
"numpy",
]
tests_require = ["pytest", "pytest-cov", "pytest-pep8"]
setup(
name="thgsp",
version="0.1.0",
author="Bowen Deng",
author_email="[email protected]",
description="A graph signal processing toolbox built on PyTorch",
long_description_content_type="text/markdown",
url="https://github.com/bwdeng20/thgsp",
classifiers=[
"Programming Language :: Python :: 3",
"License :: BSD License",
"Operating System :: Linux",
"Operating System :: Windows",
"Programming Language :: Python",
"Programming Language :: C++",
],
keywords=["pytorch", "graph-signal-processing", "graph-wavelet-filterbank"],
python_requires=">=3.6",
install_requires=install_requires,
tests_require=tests_require,
ext_modules=get_extensions(),
cmdclass={
"build_ext": BuildExtension.with_options(
no_python_abi_suffix=True, use_ninja=False
)
},
packages=find_packages(),
)