From de83ef154cd07fcedbad3575a6906f9429e4c2ff Mon Sep 17 00:00:00 2001 From: Logan Weber Date: Fri, 31 Jul 2020 17:40:50 -0700 Subject: [PATCH 1/2] add more common cfg to DefaultOptions --- python/tvm/micro/build.py | 17 ++++++++++++++--- tests/python/unittest/test_crt.py | 28 ++++++++++------------------ 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/python/tvm/micro/build.py b/python/tvm/micro/build.py index 7cb6d83801d5..c2ec928dcd09 100644 --- a/python/tvm/micro/build.py +++ b/python/tvm/micro/build.py @@ -91,15 +91,26 @@ def _generate_mod_wrapper(src_path): _CRT_DEFAULT_OPTIONS = { 'ccflags': ['-std=c++11'], + 'ldflags': ['-std=gnu++14'], 'include_dirs': [f'{TVM_ROOT_DIR}/include', f'{TVM_ROOT_DIR}/3rdparty/dlpack/include', f'{TVM_ROOT_DIR}/3rdparty/mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/libraries/crc16/', - f'{TVM_ROOT_DIR}/3rdparty/dmlc-core/include'], + f'{TVM_ROOT_DIR}/3rdparty/dmlc-core/include', + f'{CRT_ROOT_DIR}/include' + ], + 'profile': { + 'common': ['-Wno-unused-variable'] + } } -def DefaultOptions(): - return copy.deepcopy(_CRT_DEFAULT_OPTIONS) +def DefaultOptions(target_include_dir): + bin_opts = copy.deepcopy(_CRT_DEFAULT_OPTIONS) + bin_opts['include_dirs'].append(target_include_dir) + lib_opts = copy.deepcopy(bin_opts) + lib_opts['profile']['common'].append('-Werror') + lib_opts['cflags'] = ['-Wno-error=incompatible-pointer-types'] + return {'bin_opts': bin_opts, 'lib_opts': lib_opts} def build_static_runtime(workspace, compiler, module, lib_opts=None, bin_opts=None): diff --git a/tests/python/unittest/test_crt.py b/tests/python/unittest/test_crt.py index 10918c2a9a12..4f603dc4849e 100644 --- a/tests/python/unittest/test_crt.py +++ b/tests/python/unittest/test_crt.py @@ -43,13 +43,14 @@ def _make_x86_64_sess(mod): workspace = tvm.micro.Workspace(debug=True) compiler = tvm.micro.DefaultCompiler(target=TARGET) - opts = tvm.micro.DefaultOptions() - opts['include_dirs'].append( - os.path.join(tvm.micro.CRT_ROOT_DIR, 'host')) - opts['include_dirs'].append( - os.path.join(tvm.micro.CRT_ROOT_DIR, 'include')) + opts = tvm.micro.DefaultOptions(os.path.join(tvm.micro.CRT_ROOT_DIR, 'host')) - micro_binary = tvm.micro.build_static_runtime(workspace, compiler, mod, opts, opts) + micro_binary = tvm.micro.build_static_runtime( + # the x86 compiler *expects* you to give the exact same dictionary for both + # lib_opts and bin_opts. so the library compiler is mutating lib_opts and + # the binary compiler is expecting those mutations to be in bin_opts. + # TODO(weberlo) fix this very bizarre behavior + workspace, compiler, mod, lib_opts=opts['bin_opts'], bin_opts=opts['bin_opts']) flasher_kw = { 'debug': DEBUG, @@ -69,20 +70,11 @@ def _make_cortex_m33_sess(mod): env_vars={'GNUARMEMB_TOOLCHAIN_PATH': '~/ws/gcc-arm-none-eabi-9-2020-q2-update'}, ) - bin_opts = tvm.micro.DefaultOptions() - bin_opts.setdefault('profile', {})['common'] = ['-Wno-unused-variable'] - bin_opts.setdefault('ldflags', []).append('-std=gnu++14') - bin_opts.setdefault('include_dirs', []).append(f'{project_dir}/crt') - crt_include_dir = os.path.realpath(os.path.join(tvm.micro.CRT_ROOT_DIR, 'include')) - bin_opts.setdefault('include_dirs', []).append(crt_include_dir) - - lib_opts = copy.deepcopy(bin_opts) - lib_opts['profile']['common'].append('-Werror') - lib_opts['cflags'] = ['-Wno-error=incompatible-pointer-types'] + opts = tvm.micro.DefaultOptions(f'{project_dir}/crt') if BUILD: - micro_binary = tvm.micro.build_static_runtime(workspace, compiler, mod, lib_opts, bin_opts) - lib_opts['cflags'].pop() + micro_binary = tvm.micro.build_static_runtime( + workspace, compiler, mod, lib_opts=opts['lib_opts'], bin_opts=opts['bin_opts']) # debug_rpc_session = tvm.rpc.connect('127.0.0.1', 9090) debug_rpc_session = None From b6956d21652cd14a31ddf3c44da984004cc1297a Mon Sep 17 00:00:00 2001 From: Logan Weber Date: Tue, 4 Aug 2020 15:20:34 -0700 Subject: [PATCH 2/2] address comments --- tests/micro/test_mbed.py | 15 +++++---------- tests/python/unittest/test_crt.py | 2 +- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/micro/test_mbed.py b/tests/micro/test_mbed.py index 538ec8a073ad..ca86f635f594 100644 --- a/tests/micro/test_mbed.py +++ b/tests/micro/test_mbed.py @@ -40,18 +40,13 @@ def test_compile_runtime(): ) root_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', '..')) - bin_opts = tvm.micro.DefaultOptions() - bin_opts.setdefault('profile', {})['common'] = ['-Wno-unused-variable'] - bin_opts.setdefault('ccflags', []).append('-std=gnu++14') - bin_opts.setdefault('ldflags', []).append('-std=gnu++14') - bin_opts.setdefault('include_dirs', []).append(f'{project_dir}/crt') - - lib_opts = copy.deepcopy(bin_opts) - lib_opts['profile']['common'].append('-Werror') - lib_opts['cflags'] = ['-Wno-error=incompatible-pointer-types'] + opts = tvm.micro.DefaultOptions(f'{project_dir}/crt') + # TODO(weberlo) verify this is necessary + opts['bin_opts']['ccflags'] = ['-std=gnu++14'] + opts['lib_opts']['ccflags'] = ['-std=gnu++14'] if BUILD: - micro_binary = tvm.micro.build_static_runtime(workspace, compiler, mod, lib_opts, bin_opts) + micro_binary = tvm.micro.build_static_runtime(workspace, compiler, mod, **opts) lib_opts['cflags'].pop() device_transport = device_util.DeviceTransportLauncher({ diff --git a/tests/python/unittest/test_crt.py b/tests/python/unittest/test_crt.py index 4f603dc4849e..8c10a1f848ae 100644 --- a/tests/python/unittest/test_crt.py +++ b/tests/python/unittest/test_crt.py @@ -74,7 +74,7 @@ def _make_cortex_m33_sess(mod): if BUILD: micro_binary = tvm.micro.build_static_runtime( - workspace, compiler, mod, lib_opts=opts['lib_opts'], bin_opts=opts['bin_opts']) + workspace, compiler, mod, **opts) # debug_rpc_session = tvm.rpc.connect('127.0.0.1', 9090) debug_rpc_session = None