Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add more common cfg to DefaultOptions #3

Merged
merged 2 commits into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
areusch marked this conversation as resolved.
Show resolved Hide resolved
],
'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')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also update whatever is in tests/micro?


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