areusch commented on a change in pull request #5417: URL: https://github.com/apache/incubator-tvm/pull/5417#discussion_r415958851
########## File path: python/tvm/micro/device/base.py ########## @@ -92,71 +95,142 @@ def create_micro_lib_base( options : List[str] additional options to pass to GCC + + lib_src_paths : Optional[List[str]] + paths to additional source files to be compiled into the library """ + # look at these (specifically `strip`): + # https://stackoverflow.com/questions/15314581/g-compiler-flag-to-minimize-binary-size base_compile_cmd = [ - f"{toolchain_prefix}gcc", - "-std=c11", - "-Wall", - "-Wextra", - "--pedantic", - "-c", - "-O0", - "-g", - "-nostartfiles", - "-nodefaultlibs", - "-nostdlib", - "-fdata-sections", - "-ffunction-sections", + f'{toolchain_prefix}gcc', + '-std=c11', + '-Wall', + '-Wextra', + '--pedantic', + '-c', + '-g', + '-nostartfiles', + '-nodefaultlibs', + '-nostdlib', + '-fdata-sections', + '-ffunction-sections', ] if options is not None: base_compile_cmd += options src_paths = [] include_paths = find_include_path() + [get_micro_host_driven_dir()] tmp_dir = _util.tempdir() - # we might transform the src path in one of the branches below + # we need to create a new src file in the operator branch new_in_src_path = in_src_path if lib_type == LibType.RUNTIME: dev_dir = _get_device_source_dir(device_id) - dev_src_paths = glob.glob(f"{dev_dir}/*.[csS]") + + dev_src_paths = glob.glob(f'{dev_dir}/*.[csS]') # there needs to at least be a utvm_timer.c file assert dev_src_paths - assert "utvm_timer.c" in map(os.path.basename, dev_src_paths) + assert 'utvm_timer.c' in map(os.path.basename, dev_src_paths) + src_paths += dev_src_paths elif lib_type == LibType.OPERATOR: - # create a temporary copy of the source, so we can inject the dev lib + # create a temporary copy of the operator source, so we can inject the dev lib # header without modifying the original. - temp_src_path = tmp_dir.relpath("temp.c") - with open(in_src_path, "r") as f: + temp_src_path = tmp_dir.relpath('temp.c') + with open(in_src_path, 'r') as f: src_lines = f.read().splitlines() - src_lines.insert(0, "#include \"utvm_device_dylib_redirect.c\"") - with open(temp_src_path, "w") as f: - f.write("\n".join(src_lines)) + src_lines.insert(0, '#include "utvm_device_dylib_redirect.c"') + with open(temp_src_path, 'w') as f: + f.write('\n'.join(src_lines)) new_in_src_path = temp_src_path - base_compile_cmd += ["-c"] else: - raise RuntimeError("unknown lib type") + raise RuntimeError('unknown lib type') src_paths += [new_in_src_path] + # add any src paths required by the operator + if lib_src_paths is not None: + src_paths += lib_src_paths + + # print(f'include paths: {include_paths}') for path in include_paths: - base_compile_cmd += ["-I", path] + base_compile_cmd += ['-I', path] Review comment: done ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org