-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.py
218 lines (183 loc) · 6.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
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
# Copyright (c) 2021 Jisang Yoon
# All rights reserved.
#
# This source code is licensed under the Apache 2.0 license found in the
# LICENSE file in the root directory of this source tree.
# pylint: disable=fixme,too-few-public-methods
# reference: https://github.com/kakao/buffalo/blob/
# 5f571c2c7d8227e6625c6e538da929e4db11b66d/setup.py
"""cusim
"""
import os
import sys
import glob
import pathlib
import platform
import sysconfig
import subprocess
from setuptools import setup, Extension
import pybind11
import numpy as np
from cuda_setup import CUDA, BUILDEXT
DOCLINES = __doc__.split("\n")
# TODO: Python3 Support
if sys.version_info[:3] < (3, 6):
raise RuntimeError("Python version 3.6 or later required.")
assert platform.system() == 'Linux' # TODO: MacOS
with open("requirements.txt", "r") as fin:
INSTALL_REQUIRES = [line.strip() for line in fin]
MAJOR = 0
MINOR = 0
MICRO = 2
RELEASE = True
STAGE = {True: '', False: 'b'}.get(RELEASE)
VERSION = f'{MAJOR}.{MINOR}.{MICRO}{STAGE}'
STATUS = {False: 'Development Status :: 4 - Beta',
True: 'Development Status :: 5 - Production/Stable'}
CLASSIFIERS = """{status}
Programming Language :: C++
Programming Language :: Python :: 3.6
Operating System :: POSIX :: Linux
Operating System :: Unix
Operating System :: MacOS
License :: OSI Approved :: Apache Software License""".format( \
status=STATUS.get(RELEASE))
CLIB_DIR = os.path.join(sysconfig.get_path('purelib'), 'cusim')
LIBRARY_DIRS = [CLIB_DIR]
def get_extend_compile_flags():
flags = ['-march=native']
return flags
class CMakeExtension(Extension):
extension_type = 'cmake'
def __init__(self, name):
super().__init__(name, sources=[])
extend_compile_flags = get_extend_compile_flags()
extra_compile_args = ['-fopenmp', '-std=c++14', '-ggdb', '-O3'] + \
extend_compile_flags
util_srcs = glob.glob("cpp/src/utils/*.cc")
extensions = [
Extension("cusim.ioutils.ioutils_bind",
sources = util_srcs + [ \
"cusim/ioutils/bindings.cc",
"3rd/json11/json11.cpp"],
language="c++",
extra_compile_args=extra_compile_args,
extra_link_args=["-fopenmp"],
extra_objects=[],
include_dirs=[ \
"cpp/include/", np.get_include(), pybind11.get_include(),
pybind11.get_include(True),
"3rd/json11", "3rd/spdlog/include"]),
Extension("cusim.culda.culda_bind",
sources= util_srcs + [ \
"cpp/src/culda/culda.cu",
"cusim/culda/bindings.cc",
"3rd/json11/json11.cpp"],
language="c++",
extra_compile_args=extra_compile_args,
extra_link_args=["-fopenmp"],
library_dirs=[CUDA['lib64']],
libraries=['cudart', 'curand'],
extra_objects=[],
include_dirs=[ \
"cpp/include/", np.get_include(), pybind11.get_include(),
pybind11.get_include(True), CUDA['include'],
"3rd/json11", "3rd/spdlog/include"]),
Extension("cusim.cuw2v.cuw2v_bind",
sources= util_srcs + [ \
"cpp/src/cuw2v/cuw2v.cu",
"cusim/cuw2v/bindings.cc",
"3rd/json11/json11.cpp"],
language="c++",
extra_compile_args=extra_compile_args,
extra_link_args=["-fopenmp"],
library_dirs=[CUDA['lib64']],
libraries=['cudart', 'curand'],
extra_objects=[],
include_dirs=[ \
"cpp/include/", np.get_include(), pybind11.get_include(),
pybind11.get_include(True), CUDA['include'],
"3rd/json11", "3rd/spdlog/include"]),
]
# Return the git revision as a string
def git_version():
def _minimal_ext_cmd(cmd):
# construct minimal environment
env = {}
for k in ['SYSTEMROOT', 'PATH']:
val = os.environ.get(k)
if val is not None:
env[k] = val
out = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=env). \
communicate()[0]
return out
try:
out = _minimal_ext_cmd(['git', 'rev-parse', 'HEAD'])
git_revision = out.strip().decode('ascii')
except OSError:
git_revision = "Unknown"
return git_revision
def write_version_py(filename='cusim/version.py'):
cnt = """
short_version = '%(version)s'
git_revision = '%(git_revision)s'
"""
git_revision = git_version()
with open(filename, 'w') as fout:
fout.write(cnt % {'version': VERSION,
'git_revision': git_revision})
class BuildExtension(BUILDEXT):
def run(self):
for ext in self.extensions:
print(ext.name)
if hasattr(ext, 'extension_type') and ext.extension_type == 'cmake':
self.cmake()
super().run()
def cmake(self):
cwd = pathlib.Path().absolute()
build_temp = pathlib.Path(self.build_temp)
build_temp.mkdir(parents=True, exist_ok=True)
build_type = 'Debug' if self.debug else 'Release'
cmake_args = [
'-DCMAKE_BUILD_TYPE=' + build_type,
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + CLIB_DIR,
]
build_args = []
os.chdir(str(build_temp))
self.spawn(['cmake', str(cwd)] + cmake_args)
if not self.dry_run:
self.spawn(['cmake', '--build', '.'] + build_args)
os.chdir(str(cwd))
def setup_package():
write_version_py()
cmdclass = {
'build_ext': BuildExtension
}
metadata = dict(
name='cusim',
maintainer="Jisang Yoon",
maintainer_email="[email protected]",
author="Jisang Yoon",
author_email="[email protected]",
description=DOCLINES[0],
long_description="\n".join(DOCLINES[2:]),
url="https://github.com/js1010/cusim",
download_url="https://github.com/js1010/cusim/releases",
include_package_data=False,
license='Apache2',
packages=['cusim/', "cusim/ioutils/", "cusim/culda/", "cusim/cuw2v/"],
install_requires=INSTALL_REQUIRES,
cmdclass=cmdclass,
classifiers=[_f for _f in CLASSIFIERS.split('\n') if _f],
platforms=['Linux', 'Mac OSX', 'Unix'],
ext_modules=extensions,
entry_points={
'console_scripts': [
]
},
python_requires='>=3.6',
)
metadata['version'] = VERSION
setup(**metadata)
if __name__ == '__main__':
setup_package()