提交 2e3b2be6 编写于 作者: L Liangliang He

Prefer to select unlocked devices in CI

上级 7d53c473
......@@ -9,3 +9,4 @@ mace/codegen/opencl_bin/
mace/codegen/tuning/
mace/codegen/version/
build/
docs/_build/
......@@ -86,7 +86,12 @@ def main(unused_args):
target_socs = set(FLAGS.target_socs.split(','))
target_devices = sh_commands.adb_devices(target_socs=target_socs)
if FLAGS.target_socs == "random":
target_devices = [random.choice(target_devices)]
unlocked_devices = \
[d for d in target_devices if not sh_commands.is_device_locked(d)]
if len(unlocked_devices) > 0:
target_devices = [random.choice(unlocked_devices)]
else:
target_devices = [random.choice(target_devices)]
target = FLAGS.target
host_bin_path, bin_name = sh_commands.bazel_target_to_bin(target)
......
......@@ -20,6 +20,22 @@ def make_output_processor(buff):
return process_output
def device_lock_path(serialno):
return "/tmp/device-lock-%s" % serialno
def device_lock(serialno, timeout=3600):
return filelock.FileLock(device_lock_path(serialno), timeout=timeout)
def is_device_locked(serialno):
try:
with device_lock(serialno, timeout=0.000001):
return False
except filelock.Timeout:
return True
################################
# adb commands
################################
......@@ -90,12 +106,11 @@ def adb_run(serialno,
print(
"====================================================================="
)
lock_path = "/tmp/device-lock-%s" % serialno
print("Try to lock ", lock_path)
with filelock.FileLock(lock_path, timeout=3600):
print("Run on device: %s, %s, %s" % (serialno,
props["ro.board.platform"],
props["ro.product.model"]))
print("Trying to lock device", serialno)
with device_lock(serialno):
print("Run on device: %s, %s, %s" %
(serialno, props["ro.board.platform"],
props["ro.product.model"]))
sh.adb("-s", serialno, "shell", "rm -rf %s" % device_bin_path)
sh.adb("-s", serialno, "shell", "mkdir -p %s" % device_bin_path)
print("Push %s to %s" % (host_bin_full_path, device_bin_full_path))
......@@ -111,7 +126,7 @@ def adb_run(serialno,
"MACE_OUT_OF_RANGE_CHECK=%d MACE_OPENCL_PROFILING=%d "
"MACE_CPP_MIN_VLOG_LEVEL=%d %s %s" %
(out_of_range_check, opencl_profiling, vlog_level,
device_bin_full_path, args),
device_bin_full_path, args),
_out=process_output,
_bg=True,
_err_to_out=True)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册