Skip to content

Commit

Permalink
Merge pull request apache#3 from weberlo/tutorial-3
Browse files Browse the repository at this point in the history
add more common cfg to DefaultOptions
  • Loading branch information
areusch authored Aug 4, 2020
2 parents f9642e8 + b6956d2 commit ca88b36
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
17 changes: 14 additions & 3 deletions python/tvm/micro/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 5 additions & 10 deletions tests/micro/test_mbed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
28 changes: 10 additions & 18 deletions tests/python/unittest/test_crt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, **opts)

# debug_rpc_session = tvm.rpc.connect('127.0.0.1', 9090)
debug_rpc_session = None
Expand Down

0 comments on commit ca88b36

Please sign in to comment.