[AutoTVM] hexagon Cannot get remote devices from the tracker

I’m running autotvm tests for hexagon device. My code is as follows:


@autotvm.template("demo_template")

def demo_template():

    M, N, K = [1024] * 3

    A = te.placeholder((M, K), dtype="float32")

    B = te.placeholder((N, K), dtype="float32")

    k = te.reduce_axis((0, 1024), name="k")

    C = te.compute((M, N), lambda i, j: te.sum(A[i, k] * B[j, k], axis=[k]))

    s = te.create_schedule(C.op)

    cfg = autotvm.get_config()

    m_iter, n_iter = s[C].op.axis

    (k_iter,) = s[C].op.reduce_axis

    cfg.define_split("k_split", k_iter, num_outputs=2)

    ko, ki = cfg["k_split"].apply(s, C, k_iter)

    return s, [A, B, C]

class HexagonModuleLoader:

    def __init__(self, hexagon_session, pre_load_function=None) -> None:

        self.pre_load_function = pre_load_function

        self.hexagon_session = hexagon_session

    @contextlib.contextmanager

    def __call__(self, remote_kwargs, build_result):

        remote = self.hexagon_session._rpc

        if self.pre_load_function is not None:

            self.pre_load_function(remote, build_result)

        try:

            yield remote, self.hexagon_session.load_module(build_result)

        finally:

            pass

def tune_tasks(

    tasks,

    measure_option,

    tuner="xgb",

    n_trial=2048,

    early_stopping=None,

    log_filename="tuning.log",

    use_transfer_learning=True,

):

    from tvm.autotvm.tuner import XGBTuner

    from tvm.autotvm.tuner import GATuner

    tmp_log_file = log_filename + ".tmp"

    if os.path.exists(tmp_log_file):

        os.remove(tmp_log_file)

    for i, tsk in enumerate(reversed(tasks)):

        prefix = "[Task %2d/%2d] " % (i + 1, len(tasks))

        if tuner == "xgb" or tuner == "xgb-rank":

            tuner_obj = XGBTuner(tsk, loss_type="rank")

        elif tuner == "xgb_knob":

            tuner_obj = XGBTuner(tsk, loss_type="rank", feature_type="knob")

        elif tuner == "ga":

            tuner_obj = GATuner(tsk, pop_size=50)

        else:

            raise ValueError("Invalid tuner: " + tuner)

        if use_transfer_learning:

            if os.path.isfile(tmp_log_file):

                tuner_obj.load_history(

                    autotvm.record.load_from_file(tmp_log_file))

        tsk_trial = min(n_trial, len(tsk.config_space))

        tuner_obj.tune(

            n_trial=tsk_trial,

            early_stopping=early_stopping,

            measure_option=measure_option,

            callbacks=[

                autotvm.callback.progress_bar(tsk_trial, prefix=prefix),

                autotvm.callback.log_to_file(tmp_log_file),

            ],

        )

    autotvm.record.pick_best(tmp_log_file, log_filename)

    os.remove(tmp_log_file)

def test_autotvm(hexagon_session):

    logfilename = "./hexagon.autotvm.log"

    options = {

        "log_filename": logfilename,

        "early_stopping": None,

        "measure_option": autotvm.measure_option(

            builder=autotvm.LocalBuilder(timeout=15),

            runner=autotvm.RPCRunner(

                module_loader=HexagonModuleLoader(hexagon_session),

                key=hexagon_session._remote_kw["key"],

                host=hexagon_session._remote_kw["host"],

                port=hexagon_session._remote_kw["port"],

                number=3,

                timeout=15,

                min_repeat_ms=150,

                # cooldown_interval=150

            ),

        ),

    }

    target_hexagon = tvm.target.hexagon("v68")

    task = autotvm.task.create(

        "demo_template", args=[], target=target_hexagon, target_host=target_hexagon

    )

    tune_tasks([task], **options)

rpc_info = {

    "rpc_tracker_host": '0.0.0.0',

    "rpc_tracker_port": 9190,

    "rpc_server_port": 4490,

    "adb_server_socket": "tcp:5037",

}

launcher = HexagonLauncher(serial_number='ecb873ac', rpc_info=rpc_info)

launcher.start_server()

with launcher.start_session() as session:

    test_autotvm(session)

And I get the following errors:

[Task  1/ 1]  Current/Best:    0.00/   0.00 GFLOPS | Progress: (0/11) | 0.00 sException in thread Thread-1:
Traceback (most recent call last):
  File "/root/anaconda3/envs/py_3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
    self.run()
  File "/root/anaconda3/envs/py_3.7/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/home/lvsss/Desktop/apache-tvm-src-v0.9.0/python/tvm/autotvm/measure/measure_methods.py", line 829, in _check
    while not dev.exist:  # wait until we get an available device
  File "/home/lvsss/Desktop/apache-tvm-src-v0.9.0/python/tvm/_ffi/runtime_ctypes.py", line 263, in exist
    return self._GetDeviceAttr(self.device_type, self.device_id, 0) != 0
  File "/home/lvsss/Desktop/apache-tvm-src-v0.9.0/python/tvm/_ffi/runtime_ctypes.py", line 247, in _GetDeviceAttr
    return tvm.runtime._ffi_api.GetDeviceAttr(device_type, device_id, attr_id)
  File "/home/lvsss/Desktop/apache-tvm-src-v0.9.0/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
  4: TVMFuncCall
  3: tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<$_4> >::Call(tvm::runtime::PackedFuncObj const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)
  2: tvm::runtime::RPCDeviceAPI::GetAttr(DLDevice, tvm::runtime::DeviceAttrKind, tvm::runtime::TVMRetValue*)
  1: tvm::runtime::RPCClientSession::GetAttr(DLDevice, tvm::runtime::DeviceAttrKind, tvm::runtime::TVMRetValue*)
  0: tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<tvm::runtime::RPCEndpoint::Init()::$_3> >::Call(tvm::runtime::PackedFuncObj const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)
  File "/home/lvsss/Desktop/apache-tvm-src-v0.9.0/src/runtime/rpc/rpc_endpoint.cc", line 681
TVMError: 
---------------------------------------------------------------
An error occurred during the execution of TVM.
For more information, please see: https://tvm.apache.org/docs/errors.html
---------------------------------------------------------------
  Check failed: (code == RPCCode::kReturn) is false: code=1

Traceback (most recent call last):
  File "/home/lvsss/Desktop/work/tvm_lastest/autotvm.py", line 142, in <module>
    test_autotvm(session)
  File "/home/lvsss/Desktop/work/tvm_lastest/autotvm.py", line 131, in test_autotvm
    tune_tasks([task], **options)
  File "/home/lvsss/Desktop/work/tvm_lastest/autotvm.py", line 99, in tune_tasks
    autotvm.callback.log_to_file(tmp_log_file),
  File "/home/lvsss/Desktop/apache-tvm-src-v0.9.0/python/tvm/autotvm/tuner/xgboost_tuner.py", line 105, in tune
    super(XGBTuner, self).tune(*args, **kwargs)
  File "/home/lvsss/Desktop/apache-tvm-src-v0.9.0/python/tvm/autotvm/tuner/tuner.py", line 113, in tune
    measure_batch = create_measure_batch(self.task, measure_option)
  File "/home/lvsss/Desktop/apache-tvm-src-v0.9.0/python/tvm/autotvm/measure/measure.py", line 282, in create_measure_batch
    attach_objects = runner.set_task(task)
  File "/home/lvsss/Desktop/apache-tvm-src-v0.9.0/python/tvm/autotvm/measure/measure_methods.py", line 326, in set_task
    "Cannot get remote devices from the tracker. "
RuntimeError: Cannot get remote devices from the tracker. Please check the status of tracker by 'python -m tvm.exec.query_rpc_tracker --port [THE PORT YOU USE]' and make sure you have free devices on the queue status.
 Done.

It seems like my device is not registered.But I can see my device when querying the tracker.

(base) root@ubuntu:~# python -m tvm.exec.query_rpc_tracker --host=0.0.0.0 --port=9190
Tracker address 0.0.0.0:9190

Server List
------------------------------
server-address           key
------------------------------
       127.0.0.1:4493    server:hexagon-dev
       127.0.0.1:4490    server:hexagon-dev
       127.0.0.1:4491    server:hexagon-dev
       127.0.0.1:4492    server:hexagon-dev
       127.0.0.1:4494    server:hexagon-dev
------------------------------

Queue Status
-----------------------------------
key           total  free  pending
-----------------------------------
hexagon-dev   5      2     0
-----------------------------------

Can someone help me solve this problem?

Hi,

AFAIK, autotvm based tuning isn’t really supported for hexagon target. Instead, metaschedule based tuning is the currently developed route for hexagon and there are a few examples in the tests like this and this that show how to tune a relay/tir module using metaschedule for hexagon.

Hexagon support is still in active development and so some features might not work as expected, but please feel free to post more questions, and I’ll try to answer as much as I can.

Thank you very much! I successfully run these tests on my device.

1 Like