-
Notifications
You must be signed in to change notification settings - Fork 1
/
wscript
243 lines (214 loc) · 8.73 KB
/
wscript
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/env python
from waflib.extras.test_base import summary
import copy
import site
import os
import re
import sys
from waflib.extras.symwaf2ic import get_toplevel_path
def depends(dep):
dep('hxcomm')
dep('haldls')
dep('grenade')
dep('hate')
dep('calix')
def options(opt):
opt.load('compiler_cxx')
opt.load('gtest')
opt.load('test_base')
opt.load('python')
opt.load('pytest')
opt.load('pylint')
opt.load('pycodestyle')
opt.load('doxygen')
def configure(cfg):
cfg.load('compiler_cxx')
cfg.load('gtest')
cfg.load('test_base')
cfg.load('python')
cfg.check_python_version()
cfg.check_python_headers()
cfg.load('pytest')
cfg.load('doxygen')
cfg.check(
compiler='cxx',
features='cxx pyext',
uselib_store='PYBIND11HXTORCH',
mandatory=True,
header_name='pybind11/pybind11.h',
)
site_packages = site.getsitepackages()
assert isinstance(site_packages, list) and len(site_packages) == 1
includes_torch = [os.path.join(x, 'torch/include') for x in site_packages]
includes_torch_csrc_api = [os.path.join(x, 'torch/include/torch/csrc/api/include') for x in site_packages]
libpath_torch = [os.path.join(x, 'torch/lib') for x in site_packages]
libnames = []
# if torch isn't available via site-packages, try sys.path/PYTHONPATH
if not os.path.exists(libpath_torch[0]):
# find other possible paths
libpath_torch = [os.path.join(x, 'torch/lib') for x in sys.path if 'torch' in x]
# filter on existance of path
libpath_torch = [x for x in libpath_torch if os.path.exists(x)]
if len(libpath_torch) == 0:
cfg.fatal('PyTorch library directory not found')
elif len(libpath_torch) > 1:
cfg.fatal('More than one location for PyTorch libraries found: {}'.format(', '.join(libpath_torch)))
# also use PYTHONPATH-based entries for include paths
includes_torch = [os.path.join(x, 'torch/include') for x in sys.path if 'torch' in x]
includes_torch_csrc_api = [os.path.join(x, 'torch/include/torch/csrc/api/include') for x in sys.path if 'torch' in x]
for fn in os.listdir(libpath_torch[0]):
res = re.match('^lib(.+)\.so$', fn)
libnames.append(res.group(1))
libnames_cpp = copy.copy(libnames)
libnames_cpp.remove('torch_python')
cfg.check_cxx(fragment ='''
#include <torch/torch.h>
#include <torch/csrc/jit/runtime/custom_operator.h>
int main() { return 0; }''',
lib = libnames_cpp,
libpath = libpath_torch,
cxxflags = map(lambda x: '-isystem' + x, (includes_torch_csrc_api + includes_torch)),
uselib_store="TORCH_CPP")
# manually add the torch includes as system includes
cfg.env['CXXFLAGS_TORCH_CPP'] += map(lambda x: '-isystem' + x, (includes_torch_csrc_api + includes_torch))
cfg.check_cxx(fragment ='''
#include <torch/torch.h>
#include <torch/csrc/jit/runtime/custom_operator.h>
int main() { return 0; }''',
lib = libnames,
libpath = libpath_torch,
cxxflags = map(lambda x: '-isystem' + x, (includes_torch_csrc_api + includes_torch)),
uselib_store="TORCH")
# manually add the torch includes as system includes
cfg.env['CXXFLAGS_TORCH'] += map(lambda x: '-isystem' + x, (includes_torch_csrc_api + includes_torch))
def build(bld):
bld.env.BBS_HARDWARE_AVAILABLE = "SLURM_HWDB_YAML" in os.environ
bld(
target = 'hxtorch_inc',
export_includes = 'include',
)
# shared C++ libraries w/o Python linkage (but potentially missing Python symbols)
bld(
features = 'cxx cxxshlib',
source = bld.path.ant_glob('src/hxtorch/core/**/*.cpp'),
target = 'hxtorch_core_cpp',
use = ['hxtorch_inc', 'grenade_vx', 'grenade_vx_serialization', 'hate_inc'],
install_path='${PREFIX}/lib',
uselib = ['PYEXT']
)
bld(
# ECM: no pyext feature, as this changes waf handling of shlibs!
# => instead we add PYEXT below, as we need the Python headers
# (i.e. include path)
features = 'cxx cxxshlib',
source = bld.path.ant_glob('src/hxtorch/perceptron/**/*.cpp'),
target = 'hxtorch_perceptron_cpp',
use = ['hxtorch_inc', 'hxtorch_core_cpp', 'grenade_vx', 'TORCH_CPP', 'grenade_vx_serialization'],
uselib = ['PYEXT'],
)
bld(
features = 'cxx cxxshlib',
source = bld.path.ant_glob('src/hxtorch/spiking/**/*.cpp'),
target = 'hxtorch_spiking_cpp',
use = ['hxtorch_inc', 'hxtorch_core_cpp', 'grenade_vx', 'TORCH_CPP'],
uselib = ['PYEXT'],
)
# shared C++ libraries with pyext semantics
bld(
features = 'cxx cxxshlib pyext',
source = 'src/hxtorch/hxtorch_core.cpp',
target = '_hxtorch_core',
use = ['hxtorch_core_cpp', 'grenade_vx', 'pygrenade_vx', 'stadls_vx_v3', 'PYBIND11HXTORCH'],
)
bld(
features = 'cxx cxxshlib pyext',
source = 'src/hxtorch/hxtorch_perceptron.cpp',
target = '_hxtorch_perceptron',
use = ['hxtorch_perceptron_cpp', 'hxtorch_core_cpp', 'grenade_vx', 'pygrenade_vx', 'stadls_vx_v3', 'PYBIND11HXTORCH', 'TORCH'],
defines = ['TORCH_EXTENSION_NAME=_hxtorch_perceptron'],
rpath = bld.env.LIBPATH_TORCH,
)
bld(
features = 'cxx cxxshlib pyext',
source = 'src/hxtorch/hxtorch_spiking.cpp',
target = '_hxtorch_spiking',
use = ['hxtorch_spiking_cpp', 'hxtorch_core_cpp', 'grenade_vx', 'pygrenade_vx', 'stadls_vx_v3', 'PYBIND11HXTORCH', 'TORCH'],
defines = ['TORCH_EXTENSION_NAME=_hxtorch_spiking'],
rpath = bld.env.LIBPATH_TORCH,
)
bld(
target='hxtorch',
features='py use',
use=['pylogging', '_hxtorch_core', '_hxtorch_spiking', '_hxtorch_perceptron', 'pygrenade_vx', 'dlens_vx_v3', 'calix_pylib'],
relative_trick=True,
source=bld.path.ant_glob('src/pyhxtorch/**/*.py'),
install_from='src/pyhxtorch',
)
bld(
target='hxtorch_linting',
features='use pylint pycodestyle',
use=['pylogging', '_hxtorch_core', '_hxtorch_spiking', '_hxtorch_perceptron', 'pygrenade_vx', 'dlens_vx_v3'],
tests=bld.path.ant_glob('src/pyhxtorch/**/*.py'),
pylint_config=os.path.join(get_toplevel_path(), "code-format", "pylintrc"),
pycodestyle_config=os.path.join(get_toplevel_path(), "code-format", "pycodestyle"),
timeout=60
)
bld(
target='hxtorch_hwtests',
tests=bld.path.ant_glob('tests/hw/*.py'),
features='use pytest',
use=['hxtorch', 'dlens_vx_v3'],
install_path='${PREFIX}/bin/tests/hw',
test_timeout=1200,
skip_run=not bld.env.BBS_HARDWARE_AVAILABLE
)
bld(
target='hxtorch_swtests',
tests=bld.path.ant_glob('tests/sw/*.py'),
features='use pytest',
use=['hxtorch'],
install_path='${PREFIX}/bin/tests/sw',
)
bld(
target = 'hxtorch_cpp_swtests',
features = 'gtest cxx cxxprogram pyembed',
source = bld.path.ant_glob('tests/sw/test-*.cpp'),
use = ['hxtorch_perceptron_cpp', 'hxtorch_core_cpp', 'GTEST'],
linkflags = '-Wl,-z,defs',
rpath = bld.env.LIBPATH_TORCH,
install_path = '${PREFIX}/bin',
)
bld(
name = 'mnist_model_state',
features = 'install_task',
install_to = '${PREFIX}/bin/tests/hw/perceptron',
install_from = bld.path.ant_glob('mnist_model_state.pkl'),
type = 'install_files',
relative_trick=True,
)
bld(
target = 'doxygen_hxtorch',
features = 'doxygen',
doxyfile = bld.root.make_node(os.path.join(get_toplevel_path(), "code-format", "doxyfile")),
doxy_inputs = 'include/hxtorch',
install_path = 'doc/hxtorch',
pars = {
"PROJECT_NAME": "\"hxtorch\"",
"INCLUDE_PATH": os.path.join(get_toplevel_path(), "hxtorch", "include"),
"OUTPUT_DIRECTORY": os.path.join(get_toplevel_path(), "build", "hxtorch", "doc")
},
)
bld(
target = 'doxygen_pyhxtorch',
features = 'doxygen',
doxyfile = bld.root.make_node(os.path.join(get_toplevel_path(), "code-format", "doxyfile")),
doxy_inputs = 'src/pyhxtorch',
install_path = 'doc/pyhxtorch',
pars = {
"PROJECT_NAME": "\"pyhxtorch\"",
"OUTPUT_DIRECTORY": os.path.join(get_toplevel_path(), "build", "pyhxtorch", "doc"),
"PYTHON_DOCSTRING": "NO",
},
)
# Create test summary (to stdout and XML file)
bld.add_post_fun(summary)