forked from nnstreamer/nntrainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meson.build
474 lines (414 loc) · 16.4 KB
/
meson.build
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
project('nntrainer', 'c', 'cpp',
version: '0.5.0',
license: ['apache-2.0'],
meson_version: '>=0.50.0',
default_options: [
'werror=true',
'warning_level=1',
'c_std=gnu89',
'cpp_std=c++17',
'buildtype=release'
]
)
# Set version info
nntrainer_version = meson.project_version()
nntrainer_version_split = nntrainer_version.split('.')
add_project_arguments('-DVERSION="' + nntrainer_version + '"', language: ['c', 'cpp'])
add_project_arguments('-DVERSION_MAJOR=' + nntrainer_version_split[0], language: ['c', 'cpp'])
add_project_arguments('-DVERSION_MINOR=' + nntrainer_version_split[1], language: ['c', 'cpp'])
add_project_arguments('-DVERSION_MICRO=' + nntrainer_version_split[2], language: ['c', 'cpp'])
extra_defines = ['-DMIN_CPP_VERSION=201703L']
cc = meson.get_compiler('c')
cxx = meson.get_compiler('cpp')
if get_option('platform') == 'tizen'
# Pass __TIZEN__ to the compiler
add_project_arguments('-D__TIZEN__=1', language:['c','cpp'])
add_project_arguments('-DTIZENVERSION=@0@'.format(get_option('tizen-version-major')), language: ['c', 'cpp'])
add_project_arguments('-DTIZENVERSIONMINOR=@0@'.format(get_option('tizen-version-minor')), language: ['c', 'cpp'])
if get_option('enable-tizen-feature-check')
add_project_arguments('-D__FEATURE_CHECK_SUPPORT__', language: ['c', 'cpp'])
endif
elif get_option('platform') == 'android'
add_project_arguments('-DENABLE_ENCODER=1', language: ['c', 'cpp'])
endif
warning_flags = [
'-Wredundant-decls',
'-Wwrite-strings',
'-Wformat',
'-Wformat-nonliteral',
'-Wformat-security',
'-Winit-self',
'-Waddress',
'-Wvla',
'-Wpointer-arith',
'-Wno-error=varargs',
'-Wdefaulted-function-deleted',
'-ftree-vectorize',
'-Wno-maybe-uninitialized',
'-Wno-unused-variable'
]
warning_c_flags = [
'-Wmissing-declarations',
'-Wmissing-include-dirs',
'-Wmissing-prototypes',
'-Wnested-externs',
'-Waggregate-return',
'-Wold-style-definition',
'-Wdeclaration-after-statement',
'-Wno-error=varargs'
]
if get_option('enable-fp16')
arch = host_machine.cpu_family()
if get_option('platform') == 'android'
add_project_arguments('-mfp16-format=ieee', language: ['c', 'cpp'])
extra_defines += '-DENABLE_FP16=1'
extra_defines += '-DUSE__FP16=1'
extra_defines += '-DUSE_NEON=1'
elif arch == 'aarch64'
## About FP16 in GCC (from GCC-9.1 manual)
# https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Half-Precision.html
# On ARM and AArch64 targets, GCC supports half-precision (16-bit) floating point
# via the __fp16 type defined in the ARM C Language Extensions.
# On ARM systems, you must enable this type explicitly with the -mfp16-format
# command-line option in order to use it.
## About FP16-SIMD in aarch64
# FP16-SIMD is supported since armv8.2. If you enable this forcibly, it won't be
# comaptible with armv8.0 machines.
if cxx.has_argument('-mfp16-format=ieee')
add_project_arguments('-mfp16-format=ieee', language: ['c', 'cpp'])
else
message ('The compiler does not support -mfp16-format=ieee. However, according to https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Half-Precision.html, gcc may use IEEE fp16 anyway. Thus, we will proceed without the option for FP16 support.')
endif
extra_defines += '-DENABLE_FP16=1'
extra_defines += '-DUSE__FP16=1'
extra_defines += '-DUSE_NEON=1'
elif arch == 'arm'
## About FP16-SIMD in arm
# FP16-SIMD is supported since armv8.2.
# Thus, even if fp16 is force-enabled, NEON is off.
if cxx.has_argument('-mfp16-format=ieee')
add_project_arguments('-mfp16-format=ieee', language: ['c', 'cpp'])
extra_defines += '-DENABLE_FP16=1'
extra_defines += '-DUSE__FP16=1'
else
error ('The compiler does not support -mfp16-format=ieee')
endif
elif arch == 'x86_64'
if cc.version().version_compare('>=12.1.0')
message ('Float16 for x86_64 enabled. Modern gcc-x64 generally supports float16 with _Float16.')
extra_defines += '-DENABLE_FP16=1'
if get_option('enable-avx')
extra_defines += '-DUSE_AVX=1'
add_project_arguments(['-march=native'], language: ['c','cpp'])
message('-march=native added for AVX hardware acceleration.')
endif
else
warning ('Float16 for x86_64 enabled. However, software emulation is applied for fp16, making it slower and inconsistent. Use GCC 12+ for FP16 support. This build will probably fail unless you bring a compiler that supports fp16 for x64.')
endif
elif arch == 'riscv64'
error ('RISCV64 RVV support and fp16 support is not yet implemented.')
else
error ('FP16 support for this arch is not yet implemented.')
endif
endif
if get_option('enable-opencl')
message ('OpenCL build is enabled. Will work only if OpenCL supported GPU is available.')
extra_defines += '-DENABLE_OPENCL=1'
endif
if get_option('opencl-kernel-path') != ''
message ('OpenCL kernel path set to: @0@'.format(get_option('opencl-kernel-path')))
extra_defines += '-DOPENCL_KERNEL_PATH=@0@'.format(get_option('opencl-kernel-path'))
endif
foreach extra_arg : warning_flags
if cc.has_argument (extra_arg)
add_project_arguments([extra_arg], language: 'c')
endif
if cxx.has_argument (extra_arg)
add_project_arguments([extra_arg], language: 'cpp')
endif
endforeach
foreach extra_arg : warning_c_flags
if cc.has_argument (extra_arg)
add_project_arguments([extra_arg], language: 'c')
endif
endforeach
# Set install path
nntrainer_prefix = get_option('prefix')
if get_option('platform') != 'android'
nntrainer_libdir = nntrainer_prefix / get_option('libdir')
nntrainer_bindir = nntrainer_prefix / get_option('bindir')
nntrainer_includedir = nntrainer_prefix / get_option('includedir') / 'nntrainer'
nntrainer_confdir = get_option('sysconfdir')
application_install_dir = nntrainer_bindir / 'applications'
nntrainer_swapdir = '/tmp'
else
nntrainer_prefix = meson.build_root() / 'android_build_result'
# @todo arch has to be option
nntrainer_libdir = nntrainer_prefix / 'lib'
nntrainer_includedir = nntrainer_prefix / 'include' / 'nntrainer'
nntrainer_bindir = nntrainer_prefix / 'bin'
nntrainer_confdir = nntrainer_prefix / 'conf'
application_install_dir = nntrainer_prefix / 'examples'
nntrainer_swapdir = '/data/local/tmp'
endif
# handle swap options
if get_option('enable-memory-swap')
nntrainer_enable_swap = 'true'
else
nntrainer_enable_swap = 'false'
endif
if get_option('memory-swap-path') != ''
nntrainer_swapdir = get_option('memory-swap-path')
endif
# handle resources
nntrainer_resdir = meson.build_root() / 'res'
run_command('mkdir', '-p', nntrainer_resdir)
if get_option('install-app')
# add a script to install resources from installs to application_install_dir
meson.add_install_script(
'sh', '-c', 'cp -r @0@ ${DESTDIR}@1@'.format(nntrainer_resdir, application_install_dir)
)
endif
# Set default configuration
nntrainer_conf = configuration_data()
nntrainer_conf.set('VERSION', meson.project_version())
nntrainer_conf.set('PREFIX', nntrainer_prefix)
nntrainer_conf.set('EXEC_PREFIX', nntrainer_bindir)
nntrainer_conf.set('LIB_INSTALL_DIR', nntrainer_libdir)
nntrainer_conf.set('PLUGIN_INSTALL_PREFIX', nntrainer_libdir / 'nntrainer')
nntrainer_conf.set('INCLUDE_INSTALL_DIR', nntrainer_includedir / '..')
nntrainer_conf.set('MEMORY_SWAP', nntrainer_enable_swap)
nntrainer_conf.set('MEMORY_SWAP_PATH', nntrainer_swapdir)
dummy_dep = dependency('', required: false)
found_dummy_dep = declare_dependency() # dummy dep to use if found
ml_api_common_flag = '-DML_API_COMMON=0'
# if ml-api-support is disabled, enable dummy common api interfaces and disable related dependencies.
ml_api_common_dep = dependency(get_option('capi-ml-common-actual'), required : get_option('ml-api-support').enabled())
nnstreamer_capi_dep = dummy_dep
if (ml_api_common_dep.found())
nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required : get_option('ml-api-support').enabled())
if (nnstreamer_capi_dep.found())
nntrainer_conf.set('CAPI_ML_COMMON_DEP', get_option('capi-ml-common-actual'))
extra_defines += '-DML_API_COMMON=1'
ml_api_common_flag = '-DML_API_COMMON=1'
extra_defines += '-DNNSTREAMER_AVAILABLE=1'
# accessing this variable when dep_.not_found() remains hard error on purpose
supported_nnstreamer_capi = nnstreamer_capi_dep.version().version_compare('>=1.7.0')
if not supported_nnstreamer_capi
extra_defines += '-DUNSUPPORTED_NNSTREAMER=1'
warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
endif
else
# if nnstreamer_capi is not there and ml-api-support is "auto", disable it.
message ('ml-api-support is disabled although capi-ml-api-common is found: capi-ml-api-inference is not available and ml-api-support is configured to be auto')
nntrainer_conf.set('CAPI_ML_COMMON_DEP', '')
extra_defines += '-DML_API_COMMON=0'
endif
else
nntrainer_conf.set('CAPI_ML_COMMON_DEP', '')
extra_defines += '-DML_API_COMMON=0'
endif
blas_dep = dummy_dep
# Dependencies
if get_option('enable-cublas')
extra_defines += '-DUSE_CUBLAS=1'
endif
if get_option('enable-blas')
extra_defines += '-DUSE_BLAS=1'
if get_option('platform') == 'android'
message('preparing blas')
run_command(meson.source_root() / 'jni' / 'prepare_openblas.sh', meson.build_root(), check: true)
blas_dep = found_dummy_dep
blas_root = meson.build_root() / 'openblas'
else
blas_dep = dependency('openblas')
endif
if blas_dep.found()
if get_option('openblas-num-threads') > 0
extra_defines += '-DBLAS_NUM_THREADS=@0@'.format(get_option('openblas-num-threads'))
message('set openblas num threads=@0@'.format(get_option('openblas-num-threads')))
endif
endif
endif
extra_defines += '-DNNTR_NUM_THREADS=@0@'.format(get_option('nntr-num-threads'))
message('set nntrainer num threads=@0@'.format(get_option('nntr-num-threads')))
openmp_dep = dummy_dep
if get_option('enable-openmp')
openmp_dep = dependency('openmp')
if get_option('omp-num-threads') > 0
extra_defines += '-DOMP_NUM_THREADS=@0@'.format(get_option('omp-num-threads'))
message('set nntrainer omp threads=@0@'.format(get_option('omp-num-threads')))
endif
endif
if get_option('enable-profile')
extra_defines += '-DPROFILE=1'
endif
if get_option('enable-trace')
extra_defines += '-DTRACE=1'
endif
if get_option('enable-debug')
extra_defines += '-DDEBUG=1'
endif
if get_option('use_gym')
extra_defines += '-DUSE_GYM=1'
endif
if get_option('enable-logging')
extra_defines += '-D__LOGGING__=1'
endif
gmock_dep = dependency('gmock', static: true, main: false, required: false)
gtest_dep = dependency('gtest', static: true, main: false, required: false)
gtest_main_dep = dependency('gtest', static: true, main: true, required: false)
if get_option('enable-test') # and get_option('platform') != 'android'
extra_defines += '-DENABLE_TEST=1'
if gtest_dep.version().version_compare('<1.10.0')
extra_defines += '-DGTEST_BACKPORT=1'
endif
test_timeout = get_option('test-timeout')
endif
if get_option('reduce-tolerance')
extra_defines += '-DREDUCE_TOLERANCE=1'
endif
libm_dep = cxx.find_library('m') # cmath library
libdl_dep = cxx.find_library('dl') # DL library
thread_dep = dependency('threads') # pthread for tensorflow-lite
iniparser_dep = dependency('iniparser', required : false, version : '>=4.1') # iniparser
if get_option('platform') == 'android'
message('preparing iniparser')
run_command(meson.source_root() / 'jni' / 'prepare_iniparser.sh', meson.build_root(), check: true)
iniparser_root = meson.build_root() / 'iniparser'
iniparser_dep = found_dummy_dep
endif
if not iniparser_dep.found()
message('falling back to find libiniparser library and header files')
libiniparser_dep = cxx.find_library('iniparser')
sysroot = run_command(
cxx.cmd_array() + ['-print-sysroot']
).stdout().split('\n')[0]
if sysroot.startswith('/')
sysroot_inc_cflags_template = '-I@0@/usr/include@1@'
sysroot_inc = sysroot_inc_cflags_template.format(sysroot, '')
add_project_arguments(sysroot_inc, language: ['c', 'cpp'])
sysroot_inc_cflags_iniparser = sysroot_inc_cflags_template.format(sysroot,
'/iniparser')
else
sysroot_inc_cflags_iniparser = '-I/usr/include/iniparser'
endif
if libiniparser_dep.found() and cxx.has_header('iniparser.h', \
args : sysroot_inc_cflags_iniparser)
iniparser_dep = declare_dependency (dependencies : libiniparser_dep,
compile_args : sysroot_inc_cflags_iniparser)
else
error('Failed to resolve dependency on iniparser')
endif
endif
if get_option('platform') == 'android'
message('preparing ml api')
run_command(meson.source_root() / 'jni' / 'prepare_ml-api.sh', meson.build_root() / 'ml-api-inference', check: true)
ml_api_common_root = meson.build_root() / 'ml-api-inference'
ml_api_inc = ml_api_common_root / 'include'
meson.add_install_script(
'sh', '-c', 'cp @0@ ${DESTDIR}@1@'.format(ml_api_inc / 'ml-api-common.h', nntrainer_includedir)
)
meson.add_install_script(
'sh', '-c', 'cp @0@ ${DESTDIR}@1@'.format(ml_api_inc / 'tizen_error.h', nntrainer_includedir)
)
ml_api_common_dep = found_dummy_dep
endif
if get_option('enable-nnstreamer-backbone') and get_option('platform') != 'android'
extra_defines += '-DENABLE_NNSTREAMER_BACKBONE=1'
endif
tflite_dep = dummy_dep
if get_option('platform') != 'android'
tflite_dep = dependency('tensorflow2-lite', required: false)
else
if get_option('enable-tflite-backbone') or get_option('enable-tflite-interpreter')
message('preparing tflite, because either tflite backbone or interpreter is enabled')
run_command(meson.source_root() / 'jni' / 'prepare_tflite.sh', '2.3.0', meson.build_root(), check: true)
tflite_root = meson.build_root() / 'tensorflow-2.3.0' / 'tensorflow-lite'
tflite_dep = found_dummy_dep
endif
endif
if get_option('enable-tflite-backbone')
extra_defines += '-DENABLE_TFLITE_BACKBONE=1'
endif
if get_option('enable-tflite-interpreter')
extra_defines += '-DENABLE_TFLITE_INTERPRETER=1'
endif
opencv_dep = dummy_dep
if get_option('platform') != 'android'
opencv_dep = dependency('opencv', required: false)
if not opencv_dep.found()
opencv_dep = dependency('opencv4', required: false)
if not opencv_dep.found()
opencv_dep = dependency('opencv3', required: false)
endif
endif
if opencv_dep.found()
extra_defines += '-DENABLE_DATA_AUGMENTATION_OPENCV=1'
endif
endif
flatc_prog = find_program('flatc', required: false)
# Install .pc
configure_file(input: 'nntrainer.pc.in', output: 'nntrainer.pc',
install_dir: nntrainer_libdir / 'pkgconfig',
configuration: nntrainer_conf
)
# Install conf
configure_file(
input: 'nntrainer.ini.in',
output: 'nntrainer.ini',
install_dir: nntrainer_confdir,
configuration: nntrainer_conf
)
nntrainer_conf_abs_path = get_option('prefix') / nntrainer_confdir / 'nntrainer.ini'
message('NNTRAINER_CONF_PATH=@0@'.format(nntrainer_conf_abs_path))
if get_option('platform') != 'android'
extra_defines += '-DNNTRAINER_CONF_PATH="@0@"'.format(nntrainer_conf_abs_path)
endif
message('extra defines are:' + ' '.join(extra_defines))
foreach defs: extra_defines
add_project_arguments(defs, language: ['c', 'cpp'])
endforeach
# Build nntrainer
subdir('nntrainer')
enable_capi = false
enable_ccapi = false
# Build api
subdir('api')
if get_option('enable-test')
if get_option('platform') == 'android'
warning('test is not supported in android build, test skipped')
else
if gtest_dep.found()
subdir('test')
else
error('test enabled but gtest not found')
endif
endif
endif
if get_option('enable-app')
if get_option('platform') == 'android'
warning('android app is not supported for now, building app skipped')
else
# this is needed for reinforcement application. We can move this to reinforecement app dependency
jsoncpp_dep = dependency('jsoncpp') # jsoncpp
libcurl_dep = dependency('libcurl')
if not tflite_dep.found()
error('Tensorflow-Lite dependency not found')
endif
subdir('Applications')
endif
endif
if get_option('platform') != 'android'
nnstreamer_dep = dependency('nnstreamer')
message('building nnstreamer')
subdir('nnstreamer')
else
warning('android nnstreamer-filter and nnstreamer-trainer are not yet supported, building them is skipped')
endif
if get_option('platform') == 'android'
subdir('jni')
endif
if get_option('platform') != 'none'
message('building for ' + get_option('platform'))
endif