add progress for core compiling

This commit is contained in:
Dun Liang 2020-08-30 21:23:57 +08:00
parent f1a40bc826
commit 3989c7f19a
2 changed files with 21 additions and 4 deletions

View File

@ -77,7 +77,7 @@ def compile(compiler, flags, inputs, output, combind_build=False):
cc = nvcc_path
cmd = f"{cc} {input} {nflags} -c {lto_flags} -o {obj_file}"
cmds.append(cmd)
jit_utils.run_cmds(cmds, cache_path, jittor_path)
jit_utils.run_cmds(cmds, cache_path, jittor_path, "compiling")
cmd = f"{compiler} {' '.join(obj_files)} {flags} {lto_flags} {link} -o {output}"
return do_compile(cmd)
@ -788,7 +788,7 @@ def check_pybt(gdb_path, python_path):
# TODO: prev we use below code to check has py-bt or nor
# but it is too slow, so we comment it,
# find a better way to check py-bt exist
# ret = sp.getoutput(f"{gdb_path} --batch {python_path} -ex 'help py-bt'")
# if 'python frame' in ret:
# LOG.v("py-bt found in gdb.")

View File

@ -60,6 +60,20 @@ class LogWarper:
def e(self, *msg): self._log('e', 0, *msg)
def f(self, *msg): self._log('f', 0, *msg)
class DelayProgress:
def __init__(self, msg, n):
self.msg = msg
self.n = n
self.time = time.time()
def update(self, i):
if LOG.log_silent:
return
used = time.time() - self.time
if used > 2:
eta = used / (i+1) * (self.n-i-1)
print(f"{self.msg}({i+1}/{self.n}) used: {used:.3f}s eta: {eta:.3f}s", end='\r')
# check is in jupyter notebook
def in_ipynb():
try:
@ -134,7 +148,7 @@ def do_compile(args):
pool_size = 0
def run_cmds(cmds, cache_path, jittor_path):
def run_cmds(cmds, cache_path, jittor_path, msg="run_cmds"):
global pool_size
if pool_size == 0:
mem_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
@ -146,7 +160,10 @@ def run_cmds(cmds, cache_path, jittor_path):
mp.current_process()._config['daemon'] = False
try:
with Pool(pool_size) as p:
p.map(do_compile, cmds)
n = len(cmds)
dp = DelayProgress(msg, n)
for i,_ in enumerate(p.imap_unordered(do_compile, cmds)):
dp.update(i)
finally:
mp.current_process()._config['daemon'] = bk