-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.py
More file actions
226 lines (198 loc) · 8.68 KB
/
setup.py
File metadata and controls
226 lines (198 loc) · 8.68 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# setup.py
import os, glob
from setuptools import setup, find_packages
from torch.utils.cpp_extension import CUDAExtension, BuildExtension
from setuptools.command.develop import develop as _develop
# Optionally drive arch flags via env:
# os.environ["TORCH_CUDA_ARCH_LIST"] = "5.0;6.0;7.0;7.5;8.0;8.6"
def make_gencode_flags(arch_list):
"""Given "75 86", returns a flat list of NVCC -gencode flags."""
flags = []
# split on whitespace or semicolons
for arch in arch_list.replace(";", " ").split():
flags.extend([
f"-gencode=arch=compute_{arch},code=sm_{arch}",
# f"-gencode=arch=compute_{arch},code=compute_{arch}", # PTX fallback
])
return flags
CUDA_ARCH_LIST = os.environ.get("CUDA_ARCH_LIST", "80;90")
NVCC_GENCODE_FLAGS = make_gencode_flags(CUDA_ARCH_LIST)
# print(NVCC_GENCODE_FLAGS)
# common nvcc flags
nvcc_flags = [
"-O2",
"-lineinfo"
] + NVCC_GENCODE_FLAGS
core_kernel = CUDAExtension(
name="flashTP_e3nn.flashtp_large_core",
sources=[
"flashTP_e3nn/sptp_exp_opt_large/sptp_exp_opt_large.cpp",
"flashTP_e3nn/sptp_exp_opt_large/fwd_sptp_linear_v2_shared_exp.cu",
"flashTP_e3nn/sptp_exp_opt_large/bwd_sptp_linear_shared_exp.cu",
"flashTP_e3nn/sptp_exp_opt_large/bwd_bwd_sptp_linear_v2_shared_exp.cu",
"flashTP_e3nn/sptp_exp_opt_large/fwd_sptp_linear_v2_shared_exp_double.cu",
"flashTP_e3nn/sptp_exp_opt_large/bwd_sptp_linear_shared_exp_double.cu",
"flashTP_e3nn/sptp_exp_opt_large/bwd_bwd_sptp_linear_v2_shared_exp_double.cu",
],
extra_compile_args={
"cxx": ["-O2"],
"nvcc": nvcc_flags,
},
)
# # large kernel python: uses core_kernel
# large_python_impl = CUDAExtension(
# name="flashTP_e3nn.flashtp_large_kernel",
# sources=[
# "flashTP_e3nn/sptp_exp_opt_large/python_pybind.cpp",
# "flashTP_e3nn/sptp_exp_opt_large/sptp_exp_opt_large.cpp",
# "flashTP_e3nn/sptp_exp_opt_large/fwd_sptp_linear_v2_shared_exp.cu",
# "flashTP_e3nn/sptp_exp_opt_large/bwd_sptp_linear_shared_exp.cu",
# "flashTP_e3nn/sptp_exp_opt_large/bwd_bwd_sptp_linear_v2_shared_exp.cu",
# "flashTP_e3nn/sptp_exp_opt_large/fwd_sptp_linear_v2_shared_exp_double.cu",
# "flashTP_e3nn/sptp_exp_opt_large/bwd_sptp_linear_shared_exp_double.cu",
# "flashTP_e3nn/sptp_exp_opt_large/bwd_bwd_sptp_linear_v2_shared_exp_double.cu",
# ],
# extra_compile_args={
# "cxx": ["-O2"],
# "nvcc": nvcc_flags,
# }
# )
# # large kernel lammps: uses core_kernel
# large_lammps_impl = CUDAExtension(
# name="flashTP_e3nn.flashtp_large_kernel_lammps",
# sources=[
# "flashTP_e3nn/sptp_exp_opt_large/torch_register.cpp",
# "flashTP_e3nn/sptp_exp_opt_large/sptp_exp_opt_large.cpp",
# "flashTP_e3nn/sptp_exp_opt_large/fwd_sptp_linear_v2_shared_exp.cu",
# "flashTP_e3nn/sptp_exp_opt_large/bwd_sptp_linear_shared_exp.cu",
# "flashTP_e3nn/sptp_exp_opt_large/bwd_bwd_sptp_linear_v2_shared_exp.cu",
# "flashTP_e3nn/sptp_exp_opt_large/fwd_sptp_linear_v2_shared_exp_double.cu",
# "flashTP_e3nn/sptp_exp_opt_large/bwd_sptp_linear_shared_exp_double.cu",
# "flashTP_e3nn/sptp_exp_opt_large/bwd_bwd_sptp_linear_v2_shared_exp_double.cu",
# ],
# extra_compile_args={
# "cxx": ["-O2"],
# "nvcc": nvcc_flags,
# },
# )
# large kernel python: uses core_kernel
large_python_impl = CUDAExtension(
name="flashTP_e3nn.flashtp_large_kernel",
sources=[
"flashTP_e3nn/sptp_exp_opt_large/python_pybind.cpp",
],
extra_compile_args={
"cxx": ["-O2"],
"nvcc": nvcc_flags,
},
extra_link_args=["-Wl,-rpath,$ORIGIN"],
)
# large kernel lammps: uses core_kernel
large_lammps_impl = CUDAExtension(
name="flashTP_e3nn.flashtp_large_kernel_lammps",
sources=[
"flashTP_e3nn/sptp_exp_opt_large/torch_register.cpp",
],
extra_compile_args={
"cxx": ["-O2"],
"nvcc": nvcc_flags,
},
extra_link_args=["-Wl,-rpath,$ORIGIN"],
)
# extcg kernel
extcg_kernel = CUDAExtension(
name="flashTP_e3nn.flashtp_extcg_kernel",
sources=[
"flashTP_e3nn/sptp_exp_opt_extcg/sptp_exp_opt.cpp",
"flashTP_e3nn/sptp_exp_opt_extcg/fwd_sptp_linear_v2_shared_exp.cu",
"flashTP_e3nn/sptp_exp_opt_extcg/bwd_sptp_linear_shared_exp.cu",
"flashTP_e3nn/sptp_exp_opt_extcg/bwd_bwd_sptp_linear_v2_shared_exp.cu",
"flashTP_e3nn/sptp_exp_opt_extcg/fwd_sptp_linear_v2_shared_exp_double.cu",
"flashTP_e3nn/sptp_exp_opt_extcg/bwd_sptp_linear_shared_exp_double.cu",
"flashTP_e3nn/sptp_exp_opt_extcg/bwd_bwd_sptp_linear_v2_shared_exp_double.cu",
],
extra_compile_args={
"cxx": ["-O2"],
"nvcc": nvcc_flags,
},
)
class CustomBuildExt(BuildExtension):
def build_extensions(self):
# self.build_lib is the real build output dir
pkg_build = os.path.join(self.build_lib, "flashTP_e3nn")
# print("pkg_build", pkg_build)
for ext in self.extensions:
# print("ext.name", ext.name)
if ext.name == "flashTP_e3nn.flashtp_large_core":
self.core_so = str(self.get_ext_filename(ext.name)).split("/")[-1]
# print("core.so", self.core_so)
else:
# only fix the ones that need to see the core.so
if ext.name in ["flashTP_e3nn.flashtp_large_kernel", "flashTP_e3nn.flashtp_large_kernel_lammps"]:
# print("need core", ext.name)
ext.library_dirs.append(str(pkg_build))
ext.libraries.append(f":{self.core_so}")
super().build_extensions()
# class CustomBuildExt(BuildExtension):
# def build_extensions(self):
# # self.build_lib is the real build output dir
# pkg_build = os.path.join(self.build_lib, "flashTP_e3nn")
# print("pkg_build", pkg_build)
# core_name = "flashTP_e3nn.flashtp_large_core"
# core_ext = next(ext for ext in self.extensions if ext.name == core_name)
# remaining = [ext for ext in self.extensions if ext is not core_ext]
# self.extensions = [core_ext]
# super().build_extensions()
# self.core_so = str(self.get_ext_filename(core_ext.name)).split("/")[-1]
# print("core.so", self.core_so)
# self.extensions[:] = remaining
# for ext in self.extensions:
# print("ext.name", ext.name)
# # need to build the core.so first
# if ext.name == "flashTP_e3nn.flashtp_large_core":
# # self.build_extension(ext)
# # self.core_so = str(self.get_ext_filename(ext.name)).split("/")[-1]
# print("core.so", self.core_so)
# else:
# # only fix the ones that need to see the core.so
# if ext.name in ["flashTP_e3nn.flashtp_large_kernel", "flashTP_e3nn.flashtp_large_kernel_lammps"]:
# print("need core", ext.name)
# ext.library_dirs.append(str(pkg_build))
# ext.libraries.append(f":{self.core_so}")
# super().build_extensions()
class CustomDevelop(_develop):
def run(self):
# force the CUDA extensions to build first
self.run_command("build_ext")
super().run()
setup(
name="flashTP_e3nn",
version="0.1.0",
python_requires=">=3.10",
packages=find_packages(include=["flashTP_e3nn*"], exclude=["example*"]),
install_requires=[
"torch>=2.4.1",
"e3nn",
],
package_data={
"flashTP_e3nn": [
"sptp_exp_opt*/*.cpp",
"sptp_exp_opt*/*.cu",
"sptp_exp_opt*/*.hpp",
"sptp_exp_opt*/CMakeLists.txt",
]
},
ext_modules=[
core_kernel,
large_python_impl,
large_lammps_impl,
extcg_kernel,
],
cmdclass={"build_ext": CustomBuildExt,
"develop": CustomDevelop,},
options={
"build_ext": {
"parallel": 1,
}
},
)