Skip to content

Commit

Permalink
address logan and liangfu comments
Browse files Browse the repository at this point in the history
  • Loading branch information
areusch committed Apr 27, 2020
1 parent d351b9c commit 4d426ab
Show file tree
Hide file tree
Showing 22 changed files with 288 additions and 290 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ build/libtvm_web_runtime.js: build/libtvm_web_runtime.bc
cpplint:
python3 3rdparty/dmlc-core/scripts/lint.py vta cpp vta/include vta/src
python3 3rdparty/dmlc-core/scripts/lint.py topi cpp topi/include;
# Note: exclude src/runtime/micro/host_driven becuase it contains C99 files.
python3 3rdparty/dmlc-core/scripts/lint.py tvm cpp \
--exclude_path=src/runtime/micro/host_driven \
include src \
examples/extension/src examples/graph_executor/src

Expand Down
4 changes: 2 additions & 2 deletions python/tvm/autotvm/tuner/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def __del__(self):
def _callback(tuner, inputs, results):
ctx.ct += len(inputs)

flops = 0
flops = float("inf")
for inp, res in zip(inputs, results):
if res.error_no == 0:
flops = inp.task.flop / np.mean(res.costs)
flops = min(inp.task.flop / np.mean(res.costs), flops)

if logger.level > logging.DEBUG: # only print progress bar in non-debug mode
ctx.cur_flops = flops
Expand Down
80 changes: 40 additions & 40 deletions python/tvm/contrib/binutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ def tvm_callback_get_section_size(binary_path, section_name, toolchain_prefix):
size of the section in bytes
"""
if not os.path.isfile(binary_path):
raise RuntimeError('no such file \"{}\"'.format(binary_path))
raise RuntimeError('no such file "{}"'.format(binary_path))
# We use the "-A" flag here to get the ".rodata" section's size, which is
# not included by default.
size_output = run_cmd(['{}size'.format(toolchain_prefix), '-A', binary_path])
size_output = run_cmd(["{}size".format(toolchain_prefix), "-A", binary_path])

# TODO(weberlo): Refactor this method and `*relocate_binary` so they are
# both aware of [".bss", ".sbss", ".sdata"] being relocated to ".bss".
section_mapping = {
'.text': ['.text'],
'.rodata': ['.rodata'],
'.data': ['.data', '.sdata'],
'.bss': ['.bss', '.sbss'],
".text": [".text"],
".rodata": [".rodata"],
".data": [".data", ".sdata"],
".bss": [".bss", ".sbss"],
}
sections_to_sum = section_mapping["." + section_name]
section_size = 0
Expand All @@ -150,7 +150,7 @@ def tvm_callback_get_section_size(binary_path, section_name, toolchain_prefix):
# NOTE: For some reason, the size of the BSS section on the RISC-V
# GCC is sometimes reported to be smaller than it is, so we need to adjust
# for this.
if 'riscv' in toolchain_prefix and section_name == 'bss':
if "riscv" in toolchain_prefix and section_name == "bss":
# TODO(weberlo): Figure out why 32 is the minimum constant that works.
#
# The current hypothesis is that the last symbols in the ".bss" and
Expand Down Expand Up @@ -214,10 +214,10 @@ def tvm_callback_relocate_binary(
"""
assert text_start < rodata_start < data_start < bss_start < stack_end
stack_pointer_init = stack_end - word_size
ld_script_contents = ''
ld_script_contents = ""
# TODO(weberlo): There should be a better way to configure this for different archs.
# TODO is this line even necessary?
if 'riscv' in toolchain_prefix:
if "riscv" in toolchain_prefix:
ld_script_contents += 'OUTPUT_ARCH( "riscv" )\n\n'
ld_script_contents += RELOCATION_LD_SCRIPT_TEMPLATE.format(
word_size=word_size,
Expand All @@ -228,31 +228,31 @@ def tvm_callback_relocate_binary(
stack_pointer_init=stack_pointer_init)

tmp_dir = util.tempdir()
rel_obj_path = tmp_dir.relpath('relocated.obj')
rel_ld_script_path = tmp_dir.relpath('relocate.lds')
with open(rel_ld_script_path, 'w') as f:
rel_obj_path = tmp_dir.relpath("relocated.obj")
rel_ld_script_path = tmp_dir.relpath("relocate.lds")
with open(rel_ld_script_path, "w") as f:
f.write(ld_script_contents)
run_cmd([
'{}ld'.format(toolchain_prefix),
"{}ld".format(toolchain_prefix),
binary_path,
'-T', rel_ld_script_path,
'-o', rel_obj_path])
"-T", rel_ld_script_path,
"-o", rel_obj_path])

with open(rel_obj_path, 'rb') as f:
with open(rel_obj_path, "rb") as f:
rel_bin = bytearray(f.read())

gdb_init_dir = os.environ.get('MICRO_GDB_INIT_DIR')
gdb_init_dir = os.environ.get("MICRO_GDB_INIT_DIR")
if gdb_init_dir is not None:
gdb_init_path = f'{gdb_init_dir}/.gdbinit'
with open(gdb_init_path, 'r') as f:
gdbinit_contents = f.read().split('\n')
gdb_init_path = f"{gdb_init_dir}/.gdbinit"
with open(gdb_init_path, "r") as f:
gdbinit_contents = f.read().split("\n")
new_contents = []
for line in gdbinit_contents:
new_contents.append(line)
if line.startswith('target'):
new_contents.append(f'add-symbol-file {rel_obj_path}')
with open(gdb_init_path, 'w') as f:
f.write('\n'.join(new_contents))
if line.startswith("target"):
new_contents.append(f"add-symbol-file {rel_obj_path}")
with open(gdb_init_path, "w") as f:
f.write("\n".join(new_contents))

return rel_bin

Expand All @@ -278,22 +278,22 @@ def tvm_callback_read_binary_section(binary, section, toolchain_prefix):
contents of the read section
"""
tmp_dir = util.tempdir()
tmp_bin = tmp_dir.relpath('temp.bin')
tmp_section = tmp_dir.relpath('tmp_section.bin')
with open(tmp_bin, 'wb') as out_file:
tmp_bin = tmp_dir.relpath("temp.bin")
tmp_section = tmp_dir.relpath("tmp_section.bin")
with open(tmp_bin, "wb") as out_file:
out_file.write(bytes(binary))
run_cmd([
'{}objcopy'.format(toolchain_prefix),
'--dump-section',
'.{}={}'.format(section, tmp_section),
"{}objcopy".format(toolchain_prefix),
"--dump-section",
".{}={}".format(section, tmp_section),
tmp_bin])
if os.path.isfile(tmp_section):
# Get section content if it exists.
with open(tmp_section, 'rb') as f:
with open(tmp_section, "rb") as f:
section_bin = bytearray(f.read())
else:
# Return empty bytearray if the section does not exist.
section_bin = bytearray('', 'utf-8')
section_bin = bytearray("", "utf-8")
return section_bin


Expand All @@ -316,18 +316,18 @@ def tvm_callback_get_symbol_map(binary, toolchain_prefix):
alternating newline-separated keys and values
"""
tmp_dir = util.tempdir()
tmp_obj = tmp_dir.relpath('tmp_obj.bin')
with open(tmp_obj, 'wb') as out_file:
tmp_obj = tmp_dir.relpath("tmp_obj.bin")
with open(tmp_obj, "wb") as out_file:
out_file.write(bytes(binary))
nm_output = run_cmd([
'{}nm'.format(toolchain_prefix),
'-C',
'--defined-only',
"{}nm".format(toolchain_prefix),
"-C",
"--defined-only",
tmp_obj])
nm_output = nm_output.splitlines()
map_str = ''
map_str = ""
for line in nm_output:
line = line.split()
map_str += line[2] + '\n'
map_str += line[0] + '\n'
map_str += line[2] + "\n"
map_str += line[0] + "\n"
return map_str
1 change: 0 additions & 1 deletion python/tvm/contrib/debugger/debug_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ def _run_debug(self):
"""
self.debug_datum._time_list = [
[float(t) * 1e-6] for t in self.run_individual(10, 1, 1)
#[float(t) * 1e-6] for t in self.run_individual(1, 1, 1)
]
for i, node in enumerate(self.debug_datum.get_graph_nodes()):
num_outputs = self.debug_datum.get_graph_node_output_num(node)
Expand Down
2 changes: 1 addition & 1 deletion python/tvm/exec/rpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def main(args):
tracker_addr = (url, port)
if not args.key:
raise RuntimeError(
"Need key to present type of resource when tracker is available")
'Need key to present type of resource when tracker is available')
else:
tracker_addr = None

Expand Down
Loading

0 comments on commit 4d426ab

Please sign in to comment.