project('nntrainer', 'c', 'cpp',
- version: '0.0.1',
+ version: '0.4.0',
license: ['apache-2.0'],
meson_version: '>=0.50.0',
default_options: [
'buildtype=release'
]
)
-add_project_arguments('-DMIN_CPP_VERSION=201703L', 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'])
'-Wpointer-arith',
'-Wno-error=varargs',
'-Wdefaulted-function-deleted',
- '-ftree-vectorize'
+ '-ftree-vectorize',
+ '-Wno-unused-variable'
]
warning_c_flags = [
'-Wno-error=varargs'
]
+
foreach extra_arg : warning_flags
if cc.has_argument (extra_arg)
add_project_arguments([extra_arg], language: 'c')
# Set install path
nntrainer_prefix = get_option('prefix')
-nntrainer_libdir = nntrainer_prefix / get_option('libdir')
-nntrainer_bindir = nntrainer_prefix / get_option('bindir')
-nntrainer_includedir = nntrainer_prefix / get_option('includedir')
-nntrainer_confdir = get_option('sysconfdir')
-application_install_dir = nntrainer_bindir / 'applications'
+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'
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('CAPI_ML_COMMON_DEP', get_option('capi-ml-common-actual'))
+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
+
+# 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())
+ nntrainer_conf.set('CAPI_ML_COMMON_DEP', get_option('capi-ml-common-actual'))
+ extra_defines += '-DML_API_COMMON=1'
+ nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required : true)
+ 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
+ nntrainer_conf.set('CAPI_ML_COMMON_DEP', '')
+ extra_defines += '-DML_API_COMMON=0'
+endif
blas_dep = dummy_dep
# Dependencies
if get_option('enable-cublas')
- add_project_arguments('-DUSE_CUBLAS=1', language:['c','cpp'])
+ extra_defines += '-DUSE_CUBLAS=1'
endif
if get_option('enable-blas')
- add_project_arguments('-DUSE_BLAS=1', language:['c','cpp'])
- if get_option('platform') == 'tizen' or get_option('platform') == 'yocto'
- blas_dep = dependency('openblas')
+ 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('blas-openblas', required:false)
- # for Ubuntu 20.04
- if not blas_dep.found()
- blas_dep = dependency('openblas')
+ 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')
+endif
+
if get_option('enable-profile')
- add_project_arguments('-DPROFILE=1', language:['c', 'cpp'])
+ extra_defines += '-DPROFILE=1'
+endif
+
+if get_option('enable-debug')
+ extra_defines += '-DDEBUG=1'
endif
if get_option('use_gym')
- add_project_arguments('-DUSE_GYM=1', language:['c','cpp'])
+ extra_defines += '-DUSE_GYM=1'
endif
if get_option('enable-logging')
- add_project_arguments('-D__LOGGING__=1', language:['c','cpp'])
+ extra_defines += '-D__LOGGING__=1'
endif
-if get_option('enable-test')
- add_project_arguments('-DENABLE_TEST=1', language:['c','cpp'])
+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
endif
if get_option('reduce-tolerance')
- add_project_arguments('-DREDUCE_TOLERANCE=1', language:['c', 'cpp'])
+ extra_defines += '-DREDUCE_TOLERANCE=1'
endif
libm_dep = cxx.find_library('m') # cmath 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')
endif
endif
-nnstreamer_capi_dep = dependency(get_option('capi-ml-inference-actual'), required:false)
-if nnstreamer_capi_dep.found()
- add_project_arguments('-DNNSTREAMER_AVAILABLE=1', language:['c','cpp'])
- # 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
- add_project_arguments('-DUNSUPPORTED_NNSTREAMER=1', language:['c','cpp'])
- warning('capi-nnstreamer version is too old, we do not know if it works with older nnstreamer version')
- 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
-ml_api_common_dep = dependency(get_option('capi-ml-common-actual'), required: true)
+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('enable-nnstreamer-backbone')
- add_project_arguments('-DENABLE_NNSTREAMER_BACKBONE=1', language:['c','cpp'])
+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
-tflite_dep = dependency('tensorflow2-lite', required: false)
if get_option('enable-tflite-backbone')
- add_project_arguments('-DENABLE_TFLITE_BACKBONE=1', language:['c','cpp'])
+ extra_defines += '-DENABLE_TFLITE_BACKBONE=1'
endif
-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-tflite-interpreter')
+ extra_defines += '-DENABLE_TFLITE_INTERPRETER=1'
+endif
-opencv_dep = dependency('opencv', required: false)
-if not opencv_dep.found()
- opencv_dep = dependency('opencv4', required: false)
+opencv_dep = dummy_dep
+
+if get_option('platform') != 'android'
+ opencv_dep = dependency('opencv', required: false)
if not opencv_dep.found()
- opencv_dep = dependency('opencv3', required: false)
+ 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
-if opencv_dep.found()
- add_project_arguments('-DENABLE_DATA_AUGMENTATION_OPENCV=1', language:['c','cpp'])
endif
flatc_prog = find_program('flatc', required: false)
nntrainer_conf_abs_path = get_option('prefix') / nntrainer_confdir / 'nntrainer.ini'
message('NNTRAINER_CONF_PATH=@0@'.format(nntrainer_conf_abs_path))
-add_project_arguments(
- '-DNNTRAINER_CONF_PATH="@0@"'.format(nntrainer_conf_abs_path),
- language: ['c', 'cpp']
-)
+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 gtest_dep.found()
- subdir('test')
+ if get_option('platform') == 'android'
+ warning('test is not supported in android build, test skipped')
else
- error('test enabled but gtest not found')
+ if gtest_dep.found()
+ subdir('test')
+ else
+ error('test enabled but gtest not found')
+ endif
endif
endif
if get_option('enable-app')
- jsoncpp_dep = dependency('jsoncpp') # jsoncpp
- libcurl_dep = dependency('libcurl')
- if not tflite_dep.found()
- error('Tensorflow-Lite dependency not found')
+ 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
- subdir('Applications')
endif
if get_option('enable-nnstreamer-tensor-filter')
- nnstreamer_dep = dependency('nnstreamer', required: true)
- subdir('nnstreamer/tensor_filter')
+ if get_option('platform') == 'android'
+ warning('android nnstreamer-filter is not yet supported, building nnstreamer-filter skipped')
+ else
+ nnstreamer_dep = dependency('nnstreamer', required: true)
+ subdir('nnstreamer/tensor_filter')
+ endif
endif
-if get_option('enable-android')
-
- ndk_build = find_program('ndk-build', required : true)
- jni_root = meson.current_source_dir() / 'jni'
- jni_build_root = meson.current_build_dir() / 'jni'
-
- ndk_args = {
- 'NDK_PROJECT_PATH': jni_root,
- 'APP_BUILD_SCRIPT': jni_root / 'Android.mk',
- 'NDK_APPLICATION_MK': jni_root / 'Application.mk',
- 'NDK_LIBS_OUT': jni_build_root / 'libs',
- 'NDK_OUT': jni_build_root / 'objs',
- 'ENABLE_PROFILE': get_option('enable-profile') ? 1 : 0,
- 'ENABLE_BLAS': get_option('enable-blas') ? 1 : 0,
- }
-
- num_threads = run_command('grep', '-c', '^processor', '/proc/cpuinfo').stdout().strip()
- message('num processor are: ' + num_threads)
-
- thread_opt_flag = '-j' + num_threads
-
- ndk_additional_flags = [thread_opt_flag]
-
- ndk_build_command = [ndk_build]
- foreach key, val : ndk_args
- ndk_build_command += '@0@=@1@'.format(key, val)
- endforeach
- ndk_build_command += ndk_additional_flags
-
- android_build_target = custom_target('android',
- output: 'jni',
- build_by_default: true,
- command: ndk_build_command
- )
+if get_option('platform') == 'android'
+ subdir('jni')
+endif
+if get_option('platform') != 'none'
+ message('building for ' + get_option('platform'))
endif