forked from Maratyszcza/NNPACK
-
Notifications
You must be signed in to change notification settings - Fork 1
/
configure.py
executable file
·694 lines (612 loc) · 37.1 KB
/
configure.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
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import glob
import argparse
import ninja_syntax
class Configuration:
def __init__(self, options, ninja_build_file=os.path.join(os.path.dirname(os.path.abspath(__file__)), "build.ninja")):
self.output = open(ninja_build_file, "w")
self.writer = ninja_syntax.Writer(self.output)
self.source_dir = None
self.build_dir = None
self.artifact_dir = None
self.include_dirs = []
# Variables
self.build, self.host = Configuration.detect_system(options.host)
if self.host == "pnacl-nacl-newlib":
self.object_ext = ".bc"
self.executable_ext = ".pexe"
elif self.host in ["x86_64-nacl-glibc", "x86_64-nacl-newlib"]:
self.object_ext = ".o"
self.executable_ext = ".nexe"
else:
self.object_ext = ".o"
self.executable_ext = ""
cflags = ["-g", "-std=gnu11"]
if options.use_psimd or self.host == "pnacl-nacl-newlib":
cflags += ["-DNNP_ARCH_PSIMD"]
cxxflags = ["-g", "-std=gnu++11"]
ldflags = ["-g"]
if self.host in ["x86_64-linux-gnu", "x86_64-nacl-glibc", "x86_64-nacl-newlib", "pnacl-nacl-newlib"]:
cflags.append("-pthread")
cxxflags.append("-pthread")
ldflags.append("-pthread")
if self.host == "x86_64-linux-gnu":
self.writer.variable("imageformat", "elf")
self.writer.variable("abi", "sysv")
self.writer.variable("ar", "ar")
self.writer.variable("cc", "gcc")
self.writer.variable("cxx", "g++")
ldflags.append("-Wl,-fuse-ld=gold")
elif self.host == "x86_64-windows-msvc":
import _winreg
with _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, r"SOFTWARE\Microsoft\VisualStudio\14.0_Config") as vs_key:
vs_tools_dir, _ = _winreg.QueryValueEx(vs_key, "InstallDir")
vs_dir = os.path.abspath(os.path.join(vs_tools_dir, "..", ".."))
self.writer.variable("imageformat", "ms-coff")
self.writer.variable("abi", "ms")
self.writer.variable("ar", "lib")
self.writer.variable("visual_studio_dir", vs_dir)
self.writer.variable("cc", "\"" + os.path.join("$visual_studio_dir", "VC", "Clang 3.7", "bin", "x86", "clang.exe") + "\"")
self.writer.variable("cxx", "\"" + os.path.join("$visual_studio_dir", "VC", "Clang 3.7", "bin", "x86", "clang.exe") + "\"")
elif self.host in ["x86_64-nacl-newlib", "x86_64-nacl-glibc", "pnacl-nacl-newlib"]:
if self.host.startswith("x86_64-"):
self.writer.variable("imageformat", "elf")
self.writer.variable("abi", "nacl")
self.writer.variable("nacl_sdk_dir", os.getenv("NACL_SDK_ROOT"))
self.writer.variable("pepper_include_dir", os.path.join("$nacl_sdk_dir", "include"))
toolchain_library_subdir_map = {
("x86_64-linux-gnu", "x86_64-nacl-glibc"): ("linux_x86_glibc", "glibc_x86_64"),
("x86_64-linux-gnu", "x86_64-nacl-newlib"): ("linux_pnacl", "clang-newlib_x86_64"),
("x86_64-linux-gnu", "pnacl-nacl-newlib"): ("linux_pnacl", "pnacl"),
("x86_64-osx", "x86_64-nacl-glibc"): ("mac_x86_glibc", "glibc_x86_64"),
("x86_64-osx", "x86_64-nacl-newlib"): ("mac_pnacl", "clang-newlib_x86_64"),
("x86_64-osx", "pnacl-nacl-newlib"): ("mac_pnacl", "pnacl"),
}
if (self.build, self.host) in toolchain_library_subdir_map:
toolchain_subdir, library_subdir = toolchain_library_subdir_map.get((self.build, self.host))
self.writer.variable("nacl_toolchain_dir", os.path.join("$nacl_sdk_dir", "toolchain", toolchain_subdir))
self.writer.variable("pepper_lib_dir", os.path.join("$nacl_sdk_dir", "lib", library_subdir, "Release"))
else:
print("Error: cross-compilation for %s is not supported on %s" % (self.host, self.build))
sys.exit(1)
toolchain_compiler_map = {
"x86_64-nacl-glibc": ("x86_64-nacl-gcc", "x86_64-nacl-g++", "x86_64-nacl-ar"),
"x86_64-nacl-newlib": ("x86_64-nacl-clang", "x86_64-nacl-clang++", "x86_64-nacl-ar"),
"pnacl-nacl-newlib": ("pnacl-clang", "pnacl-clang++", "pnacl-ar"),
}
toolchain_cc, toolchain_cxx, toolchain_ar = toolchain_compiler_map[self.host]
self.writer.variable("ar", os.path.join("$nacl_toolchain_dir", "bin", toolchain_ar))
self.writer.variable("cc", os.path.join("$nacl_toolchain_dir", "bin", toolchain_cc))
self.writer.variable("cxx", os.path.join("$nacl_toolchain_dir", "bin", toolchain_cxx))
if self.host == "pnacl-nacl-newlib":
self.writer.variable("finalize", os.path.join("$nacl_toolchain_dir", "bin", "pnacl-finalize"))
self.writer.variable("translate", os.path.join("$nacl_toolchain_dir", "bin", "pnacl-translate"))
if self.build in ["x86_64-linux-gnu", "x86_64-osx"]:
self.writer.variable("sel_ldr", os.path.join("$nacl_sdk_dir", "tools", "sel_ldr.py"))
elif self.host == "x86_64-osx":
self.writer.variable("imageformat", "mach-o")
self.writer.variable("abi", "sysv")
self.writer.variable("ar", "ar")
self.writer.variable("cc", "clang")
self.writer.variable("cxx", "clang++")
else:
print("Unsupported platform: %s" % sys.platform, file=sys.stdout)
sys.exit(1)
self.writer.variable("cflags", " ".join(cflags))
self.writer.variable("cxxflags", " ".join(cxxflags))
self.writer.variable("ldflags", " ".join(ldflags))
self.writer.variable("optflags", "-O3")
self.writer.variable("python2", "python")
# Rules
self.writer.rule("lib", "$ar rcs $out $in",
description="LIB $descpath")
self.writer.rule("cc", "$cc -o $out -c $in -MMD -MF $out.d $optflags $cflags $includes",
deps="gcc", depfile="$out.d",
description="CC $descpath")
self.writer.rule("cxx", "$cxx -o $out -c $in -MMD -MF $out.d $optflags $cxxflags $includes",
deps="gcc", depfile="$out.d",
description="CXX $descpath")
self.writer.rule("ccld", "$cc $ldflags $libdirs -o $out $in $libs",
description="CCLD $descpath")
self.writer.rule("cxxld", "$cxx $ldflags $libdirs -o $out $in $libs",
description="CXXLD $descpath")
if self.host.startswith("x86_64-"):
self.writer.rule("peachpy", "$python2 -m peachpy.x86_64 -mabi=$abi -g4 -mimage-format=$imageformat -MMD -MF $object.d -emit-c-header $header -o $object $in",
deps="gcc", depfile="$object.d",
description="PEACHPY[x86-64] $descpath")
if self.host == "pnacl-nacl-newlib":
self.writer.rule("finalize", "$finalize --compress -o $out $in",
description="FINALIZE $descpath")
self.writer.rule("translate", "$translate --allow-llvm-bitcode-input -O3 -threads=auto -arch x86-64 $in -o $out",
description="TRANSLATE $descpath")
if self.host in ["x86_64-nacl-newlib", "x86_64-nacl-glibc", "pnacl-nacl-newlib"]:
self.writer.rule("run", "$sel_ldr -- $in $args",
description="RUN $descpath", pool="console")
else:
self.writer.rule("run", "$in $args",
description="RUN $descpath", pool="console")
@staticmethod
def detect_system(host):
if sys.platform.startswith("linux"):
build = "x86_64-linux-gnu"
elif sys.platform == "darwin":
build = "x86_64-osx"
elif sys.platform == "win32":
build = "x86_64-windows-msvc"
else:
print("Error: failed to detect build platform: sys.platform = %s" % sys.platform, file=sys.stdout)
sys.exit(1)
if host is not None:
if os.getenv("NACL_SDK_ROOT") is None:
print("Error: failed to find NaCl SDK: NACL_SDK_ROOT environment variable is not set", file=sys.stdout)
sys.exit(1)
return build, host
else:
return build, build
def _compile(self, rule, source_file, object_file, header_file=None, extra_flags={}):
if not os.path.isabs(source_file):
source_file = os.path.join(self.source_dir, source_file)
if object_file is None:
object_file = os.path.join(self.build_dir, os.path.relpath(source_file, self.source_dir)) + self.object_ext
elif not os.path.isabs(object_file):
object_file = os.path.join(self.build_dir, object_file)
variables = {
"descpath": os.path.relpath(source_file, self.source_dir)
}
for key, values in extra_flags.items():
if values:
if isinstance(values, str):
values = [values]
variables[key] = "$" + key + " " + " ".join(values)
if rule != "peachpy":
if self.include_dirs:
variables["includes"] = " ".join(["-I" + i for i in self.include_dirs])
else:
variables["object"] = object_file
if header_file is None:
header_file = os.path.join(self.build_dir, os.path.relpath(source_file, self.source_dir)) + ".h"
variables["header"] = header_file
self.writer.build(object_file, rule, source_file, variables=variables)
return object_file
def cc(self, source_file, object_file=None, extra_cflags=[]):
return self._compile("cc", source_file, object_file, extra_flags={"cflags": extra_cflags})
def peachpy(self, source_file, object_file=None, header_file=None):
return self._compile("peachpy", source_file, object_file)
def cxx(self, source_file, object_file=None, extra_cxxflags=[]):
return self._compile("cxx", source_file, object_file, extra_flags={"cxxflags": extra_cxxflags})
def _link(self, rule, object_files, binary_file, binary_dir, lib_dirs, libs, extra_ldflags):
if not os.path.isabs(binary_file):
binary_file = os.path.join(binary_dir, binary_file)
variables = {
"descpath": os.path.relpath(binary_file, binary_dir)
}
if lib_dirs:
variables["libdirs"] = " ".join(["-L" + l for l in lib_dirs])
if libs:
variables["libs"] = " ".join(["-l" + l for l in libs])
if extra_ldflags:
if isinstance(extra_ldflags, str):
extra_ldflags = [extra_ldflags]
variables["ldflags"] = "$ldflags " + " ".join(extra_ldflags)
self.writer.build(binary_file, rule, object_files, variables=variables)
return binary_file
def ccld_executable(self, object_files, binary_file, lib_dirs=[], libs=[], extra_ldflags=[]):
if self.host == "pnacl-nacl-newlib":
bytecode_file = self._link("ccld", object_files, binary_file + ".bc", self.build_dir, lib_dirs, libs, extra_ldflags)
portable_file = self.finalize(bytecode_file, os.path.join(self.build_dir, binary_file + ".pexe"))
native_file = self.translate(portable_file, os.path.join(self.artifact_dir, binary_file + ".nexe"))
return native_file
else:
return self._link("ccld", object_files, binary_file, self.artifact_dir, lib_dirs, libs, extra_ldflags)
def module(self, object_files, module_file, lib_dirs=[], libs=[], extra_ldflags=[]):
assert self.host in ["pnacl-nacl-newlib", "x86_64-nacl-newlib", "x86_64-nacl-glibc"]
if self.host == "pnacl-nacl-newlib":
bytecode_file = self._link("ccld", object_files, module_file + ".bc", self.build_dir, lib_dirs, libs, extra_ldflags)
portable_file = self.finalize(bytecode_file, os.path.join(self.artifact_dir, module_file + ".pexe"))
return portable_file
else:
return self._link("ccld", object_files, module_file + ".x86_64.nexe", self.artifact_dir, lib_dirs, libs, extra_ldflags)
def unittest(self, object_files, test_name):
if self.host == "pnacl-nacl-newlib":
bytecode_file = self._link("cxxld", object_files, test_name + ".bc", self.build_dir, lib_dirs=[], libs=["m"], extra_ldflags=[])
native_file = self.translate(bytecode_file, os.path.join(self.artifact_dir, test_name + ".nexe"))
else:
native_file = self._link("cxxld", object_files, test_name + self.executable_ext, self.artifact_dir, lib_dirs=[], libs=["m"], extra_ldflags=[])
self.run(native_file, test_name)
self.default(native_file)
return test_name
def translate(self, portable_file, native_file):
assert self.host == "pnacl-nacl-newlib"
assert os.path.isabs(portable_file)
if not os.path.isabs(native_file):
native_file = os.path.join(self.artifact_dir, native_file)
variables = {
"descpath": os.path.relpath(native_file, self.artifact_dir)
}
self.writer.build(native_file, "translate", portable_file, variables=variables)
return native_file
def finalize(self, bytecode_file, portable_file):
assert self.host == "pnacl-nacl-newlib"
if not os.path.isabs(portable_file):
portable_file = os.path.join(self.build_dir, portable_file)
if os.path.splitext(portable_file)[1] != ".pexe":
portable_file = portable_file + ".pexe"
variables = {
"descpath": os.path.relpath(portable_file, self.artifact_dir)
}
self.writer.build(portable_file, "finalize", bytecode_file, variables=variables)
return portable_file
def lib(self, object_files, library_file):
library_basename = os.path.basename(library_file)
if not library_basename.startswith("lib"):
library_basename = "lib" + library_basename
if not library_basename.endswith(".a"):
library_basename = library_basename + ".a"
library_file = os.path.join(os.path.dirname(library_file), library_basename)
if not os.path.isabs(library_file):
library_file = os.path.join(self.artifact_dir, library_file)
variables = {
"descpath": os.path.relpath(library_file, self.artifact_dir)
}
self.writer.build(library_file, "lib", object_files, variables=variables)
return library_file
def run(self, executable_file, target, args=""):
variables = {
"descpath": os.path.relpath(executable_file, self.artifact_dir)
}
if args:
variables["args"] = args
self.writer.build(target, "run", executable_file, variables=variables)
def default(self, targets):
if not isinstance(targets, list):
targets = [targets]
self.writer.default([ninja_syntax.escape(target).replace(":", "$:") for target in targets])
def phony(self, target, deps):
self.writer.build(target, "phony", deps)
parser = argparse.ArgumentParser(description="NNPACK configuration script")
parser.add_argument("--host", dest="host", choices=("x86_64-linux-gnu", "x86_64-osx", "x86_64-nacl-newlib", "x86_64-nacl-glibc", "pnacl-nacl-newlib"))
parser.add_argument("--enable-mkl", dest="use_mkl", action="store_true")
parser.add_argument("--enable-openblas", dest="use_openblas", action="store_true")
parser.add_argument("--enable-blis", dest="use_blis", action="store_true")
parser.add_argument("--enable-psimd", dest="use_psimd", action="store_true")
def main():
options = parser.parse_args()
config = Configuration(options)
root_dir = os.path.dirname(os.path.abspath(__file__))
# Build gtest
gtest_dir = os.path.join(root_dir, "third-party", "gtest-1.7.0")
config.source_dir = os.path.join(gtest_dir, "src")
config.build_dir = os.path.join(gtest_dir, "lib")
config.include_dirs = [os.path.join(gtest_dir, "include"), gtest_dir]
gtest_objects = [config.cxx("gtest-all.cc")]
# Build pthreadpool
pthreadpool_dir = os.path.join(root_dir, "third-party", "pthreadpool")
config.source_dir = os.path.join(pthreadpool_dir, "src")
config.build_dir = os.path.join(pthreadpool_dir, "lib")
config.include_dirs = [os.path.join(pthreadpool_dir, "include")]
pthreadpool_objects = [config.cc("pthreadpool.c")]
# Build the library
config.source_dir = os.path.join(root_dir, "src")
config.build_dir = os.path.join(root_dir, "build")
config.include_dirs = [os.path.join(root_dir, "include"), os.path.join(root_dir, "src"), os.path.join(root_dir, "src", "ref"), os.path.join(pthreadpool_dir, "include")]
nnpack_objects = [
config.cc("init.c"),
config.cc("convolution-output.c"),
config.cc("convolution-input-gradient.c"),
config.cc("convolution-kernel.c"),
config.cc("convolution-inference.c"),
config.cc("fully-connected-output.c"),
config.cc("fully-connected-inference.c"),
config.cc("pooling-output.c"),
config.cc("relu-output.c"),
config.cc("relu-input-gradient.c"),
]
if config.host.startswith("x86_64-") and not options.use_psimd:
arch_nnpack_objects = [
# Transformations
config.peachpy("x86_64-fma/2d-fft-8x8.py"),
config.peachpy("x86_64-fma/2d-fft-16x16.py"),
config.peachpy("x86_64-fma/2d-wt-8x8-3x3.py"),
# Pooling
config.peachpy("x86_64-fma/max-pooling.py"),
# ReLU
config.peachpy("x86_64-fma/relu.py"),
# FFT block accumulation
config.peachpy("x86_64-fma/fft-block-mac.py"),
# Tuple GEMM
config.peachpy("x86_64-fma/c8gemm.py"),
config.peachpy("x86_64-fma/s8gemm.py"),
# BLAS microkernels
config.peachpy("x86_64-fma/sgemm.py"),
config.peachpy("x86_64-fma/sdotxf.py"),
]
else:
arch_nnpack_objects = [
# Transformations
config.cc("psimd/2d-fourier-8x8.c"),
config.cc("psimd/2d-fourier-16x16.c"),
config.cc("psimd/2d-wt-8x8-3x3.c"),
# ReLU
config.cc("psimd/relu.c"),
# Tuple GEMM
config.cc("psimd/blas/s4gemm.c"),
config.cc("psimd/blas/c4gemm.c"),
config.cc("psimd/blas/s4c2gemm.c"),
config.cc("psimd/blas/c4gemmcb.c"),
config.cc("psimd/blas/s4c2gemmcb.c"),
config.cc("psimd/blas/c4gemmca.c"),
config.cc("psimd/blas/s4c2gemmca.c"),
config.cc("psimd/blas/sdotxf.c"),
]
reference_layer_objects = [
config.cc("ref/convolution-output.c"),
config.cc("ref/convolution-input-gradient.c"),
config.cc("ref/convolution-kernel.c"),
config.cc("ref/fully-connected-output.c"),
config.cc("ref/pooling-output.c"),
config.cc("ref/softmax-output.c"),
config.cc("ref/relu-output.c"),
config.cc("ref/relu-input-gradient.c"),
]
reference_fft_objects = [
config.cc("ref/fft/aos.c"),
config.cc("ref/fft/soa.c"),
config.cc("ref/fft/forward-real.c"),
config.cc("ref/fft/forward-dualreal.c"),
config.cc("ref/fft/inverse-real.c"),
config.cc("ref/fft/inverse-dualreal.c"),
]
if config.host.startswith("x86_64-") and not options.use_psimd:
arch_fft_stub_objects = [
config.peachpy("x86_64-fma/fft-soa.py"),
config.peachpy("x86_64-fma/fft-aos.py"),
config.peachpy("x86_64-fma/fft-dualreal.py"),
config.peachpy("x86_64-fma/ifft-dualreal.py"),
config.peachpy("x86_64-fma/fft-real.py"),
config.peachpy("x86_64-fma/ifft-real.py"),
]
else:
arch_fft_stub_objects = [
config.cc("psimd/fft-aos.c"),
config.cc("psimd/fft-soa.c"),
config.cc("psimd/fft-real.c"),
config.cc("psimd/fft-dualreal.c"),
]
if config.host.startswith("x86_64-") and not options.use_psimd:
arch_winograd_stub_objects = [
config.peachpy("x86_64-fma/winograd-f6k3.py"),
]
else:
arch_winograd_stub_objects = [
config.cc("psimd/winograd-f6k3.c"),
]
fft_objects = reference_fft_objects + arch_fft_stub_objects
reference_blockmac_objects = [
config.cc("ref/fft/block-mac.c"),
]
nnpack_objects = nnpack_objects + arch_nnpack_objects + pthreadpool_objects
# Build the library
config.artifact_dir = os.path.join(root_dir, "lib")
config.default(config.lib(nnpack_objects, "nnpack"))
# Build Native Client module
if config.host in ["x86_64-nacl-glibc", "x86_64-nacl-newlib", "pnacl-nacl-newlib"]:
config.source_dir = os.path.join(root_dir, "src")
config.build_dir = os.path.join(root_dir, "build")
config.include_dirs = [os.path.join(root_dir, "include"), os.path.join(root_dir, "src"), os.path.join(pthreadpool_dir, "include")]
config.artifact_dir = os.path.join(root_dir, "web")
module_source_files = ["nacl/entry.c", "nacl/instance.c", "nacl/interfaces.c", "nacl/messaging.c", "nacl/stringvars.c", "nacl/benchmark.c"]
nacl_module_objects = [config.cc(source_file, extra_cflags="-I$pepper_include_dir") for source_file in module_source_files]
nacl_module_binary = \
config.module(nnpack_objects + nacl_module_objects, "nnpack", lib_dirs=["$pepper_lib_dir"], libs=["m", "ppapi"])
config.default(nacl_module_binary)
# Build unit tests
if config.host not in ["x86_64-nacl-glibc"]:
config.source_dir = os.path.join(root_dir, "test")
config.build_dir = os.path.join(root_dir, "build", "test")
config.artifact_dir = os.path.join(root_dir, "bin")
config.include_dirs = [os.path.join(root_dir, "include"), os.path.join(pthreadpool_dir, "include"), os.path.join(root_dir, "test"), os.path.join(gtest_dir, "include")]
fourier_reference_test = \
config.unittest(reference_fft_objects + [config.cxx("fourier/reference.cc")] + gtest_objects,
"fourier-reference-test")
if config.host.startswith("x86_64-") and not options.use_psimd:
fourier_x86_64_avx2_test = \
config.unittest(reference_fft_objects + arch_fft_stub_objects + [config.cxx("fourier/x86_64-avx2.cc")] + gtest_objects,
"fourier-x86_64-avx2-test")
winograd_x86_64_fma3_test = \
config.unittest(arch_winograd_stub_objects + nnpack_objects + [config.cxx("winograd/x86_64-fma3.cc")] + gtest_objects,
"winograd-x86_64-fma3-test")
if config.host.startswith("pnacl-") or options.use_psimd:
fourier_psimd_test = \
config.unittest(reference_fft_objects + arch_fft_stub_objects + [config.cxx("fourier/psimd.cc")] + gtest_objects,
"fourier-psimd-test")
winograd_psimd_test = \
config.unittest(arch_winograd_stub_objects + nnpack_objects + [config.cxx("winograd/psimd.cc")] + gtest_objects,
"winograd-psimd-test")
convolution_output_smoke_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-output/smoke.cc")] + gtest_objects,
"convolution-output-smoketest")
convolution_output_alexnet_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-output/alexnet.cc")] + gtest_objects,
"convolution-output-alexnet-test")
convolution_output_vgg_a_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-output/vgg-a.cc")] + gtest_objects,
"convolution-output-vgg-a-test")
convolution_output_overfeat_fast_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-output/overfeat-fast.cc")] + gtest_objects,
"convolution-output-overfeat-fast-test")
config.phony("convolution-output-test",
[convolution_output_smoke_test, convolution_output_alexnet_test, convolution_output_vgg_a_test, convolution_output_overfeat_fast_test])
convolution_input_gradient_smoke_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-input-gradient/smoke.cc")] + gtest_objects,
"convolution-input-gradient-smoketest")
convolution_input_gradient_alexnet_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-input-gradient/alexnet.cc")] + gtest_objects,
"convolution-input-gradient-alexnet-test")
convolution_input_gradient_vgg_a_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-input-gradient/vgg-a.cc")] + gtest_objects,
"convolution-input-gradient-vgg-a-test")
convolution_input_gradient_overfeat_fast_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-input-gradient/overfeat-fast.cc")] + gtest_objects,
"convolution-input-gradient-overfeat-fast-test")
config.phony("convolution-input-gradient-test",
[convolution_input_gradient_smoke_test, convolution_input_gradient_alexnet_test, convolution_input_gradient_vgg_a_test, convolution_input_gradient_overfeat_fast_test])
convolution_kernel_gradient_smoke_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-kernel-gradient/smoke.cc")] + gtest_objects,
"convolution-kernel-gradient-smoketest")
convolution_kernel_gradient_alexnet_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-kernel-gradient/alexnet.cc")] + gtest_objects,
"convolution-kernel-gradient-alexnet-test")
convolution_kernel_gradient_vgg_a_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-kernel-gradient/vgg-a.cc")] + gtest_objects,
"convolution-kernel-gradient-vgg-a-test")
convolution_kernel_gradient_overfeat_fast_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-kernel-gradient/overfeat-fast.cc")] + gtest_objects,
"convolution-kernel-gradient-overfeat-fast-test")
config.phony("convolution-kernel-gradient-test",
[convolution_kernel_gradient_smoke_test, convolution_kernel_gradient_alexnet_test, convolution_kernel_gradient_vgg_a_test, convolution_kernel_gradient_overfeat_fast_test])
convolution_inference_smoke_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-inference/smoke.cc")] + gtest_objects,
"convolution-inference-smoketest")
convolution_inference_alexnet_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-inference/alexnet.cc")] + gtest_objects,
"convolution-inference-alexnet-test")
convolution_inference_vgg_a_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-inference/vgg-a.cc")] + gtest_objects,
"convolution-inference-vgg-a-test")
convolution_inference_overfeat_fast_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("convolution-inference/overfeat-fast.cc")] + gtest_objects,
"convolution-inference-overfeat-fast-test")
config.phony("convolution-inference-test",
[convolution_inference_smoke_test, convolution_inference_alexnet_test, convolution_inference_vgg_a_test, convolution_inference_overfeat_fast_test])
fully_connected_output_smoke_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("fully-connected-output/smoke.cc")] + gtest_objects,
"fully-connected-output-smoketest")
fully_connected_output_alexnet_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("fully-connected-output/alexnet.cc")] + gtest_objects,
"fully-connected-output-alexnet-test")
fully_connected_output_vgg_a_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("fully-connected-output/vgg-a.cc")] + gtest_objects,
"fully-connected-output-vgg-a-test")
fully_connected_output_overfeat_fast_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("fully-connected-output/overfeat-fast.cc")] + gtest_objects,
"fully-connected-output-overfeat-fast-test")
config.phony("fully-connected-output-test",
[fully_connected_output_smoke_test, fully_connected_output_alexnet_test, fully_connected_output_vgg_a_test, fully_connected_output_overfeat_fast_test])
fully_connected_inference_alexnet_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("fully-connected-inference/alexnet.cc")] + gtest_objects,
"fully-connected-inference-alexnet-test")
fully_connected_inference_vgg_a_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("fully-connected-inference/vgg-a.cc")] + gtest_objects,
"fully-connected-inference-vgg-a-test")
fully_connected_inference_overfeat_fast_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("fully-connected-inference/overfeat-fast.cc")] + gtest_objects,
"fully-connected-inference-overfeat-fast-test")
config.phony("fully-connected-inference-test",
[fully_connected_inference_alexnet_test, fully_connected_inference_vgg_a_test, fully_connected_inference_overfeat_fast_test])
pooling_output_smoke_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("pooling-output/smoke.cc")] + gtest_objects,
"pooling-output-smoketest")
pooling_output_vgg_a_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("pooling-output/vgg-a.cc")] + gtest_objects,
"pooling-output-vgg-a-test")
pooling_output_overfeat_fast_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("pooling-output/overfeat-fast.cc")] + gtest_objects,
"pooling-output-overfeat-fast")
config.phony("pooling-output-test",
[pooling_output_smoke_test, pooling_output_vgg_a_test, pooling_output_overfeat_fast_test])
relu_output_alexnet_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("relu-output/alexnet.cc")] + gtest_objects,
"relu-output-alexnet-test")
relu_output_vgg_a_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("relu-output/vgg-a.cc")] + gtest_objects,
"relu-output-vgg-a-test")
relu_output_overfeat_fast_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("relu-output/overfeat-fast.cc")] + gtest_objects,
"relu-output-overfeat-fast-test")
config.phony("relu-output-test",
[relu_output_alexnet_test, relu_output_vgg_a_test, relu_output_overfeat_fast_test])
relu_input_gradient_alexnet_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("relu-input-gradient/alexnet.cc")] + gtest_objects,
"relu-input-gradient-alexnet-test")
relu_input_gradient_vgg_a_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("relu-input-gradient/vgg-a.cc")] + gtest_objects,
"relu-input-gradient-vgg-a-test")
relu_input_gradient_overfeat_fast_test = \
config.unittest(nnpack_objects + reference_layer_objects + [config.cxx("relu-input-gradient/overfeat-fast.cc")] + gtest_objects,
"relu-input-gradient-overfeat-fast-test")
config.phony("relu-input-gradient-test",
[relu_input_gradient_alexnet_test, relu_input_gradient_vgg_a_test, relu_input_gradient_overfeat_fast_test])
config.phony("test", [
"convolution-output-test", "convolution-input-gradient-test", "convolution-kernel-gradient-test", "convolution-inference-test",
"fully-connected-output-test", "fully-connected-inference-test",
"pooling-output-test",
"relu-output-test", "relu-input-gradient-test"])
config.phony("smoketest", [
convolution_output_smoke_test, convolution_input_gradient_smoke_test, convolution_kernel_gradient_smoke_test, convolution_inference_smoke_test,
fully_connected_output_smoke_test,
pooling_output_smoke_test])
# Build benchmarks
config.source_dir = os.path.join(root_dir, "bench")
config.build_dir = os.path.join(root_dir, "build", "bench")
config.artifact_dir = os.path.join(root_dir, "bin")
config.include_dirs = [os.path.join(root_dir, "include"), os.path.join(pthreadpool_dir, "include"), os.path.join(root_dir, "bench")]
bench_support_objects = [config.cc("median.c")]
if config.host.startswith("x86_64-"):
bench_support_objects.append(config.peachpy("memread.py"))
if config.host == "x86_64-linux-gnu":
bench_support_objects.append(config.cc("perf_counter.c"))
extra_cflags = []
extra_lib_dirs = []
extra_libs = ["m"]
extra_ldflags = []
if options.use_mkl:
extra_cflags.append("-DUSE_MKL")
extra_cflags.append("-I/opt/intel/mkl/include")
extra_lib_dirs.append("/opt/intel/mkl/lib/intel64")
extra_libs = ["mkl_intel_lp64", "mkl_core", "mkl_sequential", "m"]
extra_ldflags.append("-Wl,--no-as-needed")
transform_bench_binary = config.ccld_executable([config.cc("transform.c", extra_cflags=extra_cflags)] + nnpack_objects + bench_support_objects, "transform-bench",
lib_dirs=extra_lib_dirs, libs=extra_libs, extra_ldflags=extra_ldflags)
config.phony("transform-bench", transform_bench_binary)
config.default(transform_bench_binary)
convolution_bench_binary = config.ccld_executable([config.cc("convolution.c")] + nnpack_objects + bench_support_objects,
"convolution-benchmark", libs=["m"])
config.phony("convolution-bench", convolution_bench_binary)
fully_connected_bench_binary = config.ccld_executable([config.cc("fully-connected.c")] + nnpack_objects + bench_support_objects,
"fully-connected-benchmark", libs=["m"])
config.phony("fully-connected-bench", fully_connected_bench_binary)
pooling_bench_binary = config.ccld_executable([config.cc("pooling.c")] + nnpack_objects + bench_support_objects,
"pooling-benchmark", libs=["m"])
config.phony("pooling-bench", pooling_bench_binary)
relu_bench_binary = config.ccld_executable([config.cc("relu.c")] + nnpack_objects + bench_support_objects,
"relu-benchmark", libs=["m"])
config.phony("relu-bench", relu_bench_binary)
config.default([convolution_bench_binary, fully_connected_bench_binary, pooling_bench_binary, relu_bench_binary])
if config.host.startswith("x86_64-") and not options.use_psimd:
ugemm_bench_binary = config.ccld_executable([config.cc("ugemm.c")] + arch_nnpack_objects + bench_support_objects, "ugemm-bench", libs=["m"])
if options.use_mkl:
extra_cflags = ["-DUSE_MKL", "-I/opt/intel/mkl/include", "-pthread"]
extra_lib_dirs = ["/opt/intel/mkl/lib/intel64"]
extra_libs = ["mkl_intel_lp64", "mkl_core", "mkl_gnu_thread", "m", "pthread"]
extra_ldflags = ["-Wl,--no-as-needed", "-pthread", "-fopenmp"]
mkl_gemm_bench_binary = config.ccld_executable([config.cc("gemm.c", "mkl-gemm.o", extra_cflags=extra_cflags)] + bench_support_objects, "mkl-gemm-bench", lib_dirs=extra_lib_dirs, libs=extra_libs, extra_ldflags=extra_ldflags)
config.default(mkl_gemm_bench_binary)
if options.use_openblas:
extra_cflags = ["-DUSE_OPENBLAS", "-I/opt/OpenBLAS/include", "-pthread"]
extra_lib_dirs = ["/opt/OpenBLAS/lib"]
extra_libs = ["openblas", "m", "pthread"]
extra_ldflags = []
openblas_gemm_bench_binary = config.ccld_executable([config.cc("gemm.c", "openblas-gemm.o", extra_cflags=extra_cflags)] + bench_support_objects, "openblas-gemm-bench", lib_dirs=extra_lib_dirs, libs=extra_libs, extra_ldflags=extra_ldflags)
config.default(openblas_gemm_bench_binary)
if options.use_blis:
extra_cflags = ["-DUSE_BLIS", "-I/opt/BLIS/include", "-pthread", "-fopenmp"]
extra_libs = ["m", "pthread"]
extra_ldflags = ["-fopenmp"]
blis_gemm_bench_binary = config.ccld_executable([config.cc("gemm.c", "blis-gemm.o", extra_cflags=extra_cflags), "/opt/BLIS/lib/libblis.a"] + bench_support_objects, "blis-gemm-bench", lib_dirs=extra_lib_dirs, libs=extra_libs, extra_ldflags=extra_ldflags)
config.default(blis_gemm_bench_binary)
config.default(ugemm_bench_binary)
if __name__ == "__main__":
sys.exit(main())