Tune a RISC-V model

Hello,

I want to tune my model that should finally run on a RISC-V, but unfortunately it cannot find any valid schedule. I get always following output of the tuning process:

...
[[Task  3/ 3]  Current/Best:    0.00/   0.00 GFLOPS | Progress: (16/20) | 33.15 s[20:35:04]     /home/joschi/Documents/Repos/tvm/src/target/llvm/codegen_llvm.cc:168: Warning: Set native vector bits to be 128 for riscv64
[20:35:04] /home/joschi/Documents/Repos/tvm/src/target/llvm/codegen_llvm.cc:168: Warning: Set native vector bits to be 128 for riscv64
[20:35:04] /home/joschi/Documents/Repos/tvm/src/target/llvm/codegen_llvm.cc:168: Warning: Set native vector bits to be 128 for riscv64
[20:35:04] /home/joschi/Documents/Repos/tvm/src/target/llvm/codegen_llvm.cc:168: Warning: Set native vector bits to be 128 for riscv64
[Task  3/ 3]  Current/Best:    0.00/   0.00 GFLOPS | Progress: (20/20) | 42.36 s Done.
...

I have following setup:

On my risc-v the tvm_rpc server is running.

./tvm_rpc server --tracker=192.168.0.57:9190 --key=nexys

On my host machine a rpc_tracker is running:

python -m tvm.exec.rpc_tracker --host=0.0.0.0 --port=9190

The tuning process is similar to the one in the documentation:

device_key ="nexys"
runner = autotvm.RPCRunner(
    device_key,
    host="0.0.0.0",
    port=9190,
    number=5,
    timeout=timeout,
)
tuning_option = {
    "tuner": "xgb",
    "trials": 20,
    "early_stopping": None,
    "measure_option": autotvm.measure_option(
        builder=autotvm.LocalBuilder(build_func="default"),
        runner=runner
    ),
    "tuning_records": "autotuning.json",
}
tasks = autotvm.task.extract_from_program(mod["main"], target=target, params=params)
# Tune the extracted tasks sequentially.
for i, task in enumerate(tasks):
    prefix = "[Task %2d/%2d] " % (i + 1, len(tasks))
    tuner_obj = XGBTuner(task, loss_type="rank")
    tuner_obj.tune(
        n_trial=min(tuning_option["trials"], len(task.config_space)),
        early_stopping=tuning_option["early_stopping"],
        measure_option=tuning_option["measure_option"],
        callbacks=[
            autotvm.callback.progress_bar(tuning_option["trials"], prefix=prefix),
            autotvm.callback.log_to_file(tuning_option["tuning_records"]),
        ],
    )
with autotvm.apply_history_best(tuning_option["tuning_records"]):
    with tvm.transform.PassContext(opt_level=3, config={}):
        lib = relay.build(mod, target=target, params=params)

It seems that something is happening between those three components. At least I am getting an output on the riscv (tvm_rpc server) image

I also notices that in /tmp an error log file was created. Maybe this will help you as well somehow.

Thank you very much.

BR Josef

Hey Josef,

It looks like from this error that g++ isn’t installed on the target device. Possible to install that there, or is the footprint too small?

You might also try changing build_func to cc.cross_compile or cc.create_shared if it’s not possible to add g++ to the target.

Andrew

Yeah you were right, g++ was not installed. Took some time to install it on my slow platform :wink: It definitely helped, because I got now more useful output. Additionally the g++ error in the tvm_tuning_error file is gone.

But still there is an error in the tvm_tuning_errors file, but maybe I can fix this with your second approach. I didn’t had time yet to try this out. I will inform you if this will work or not.

Thanks BR Josef

PS: For your interests: This is the current issue, but as mentioned, maybe this will be gone when I try your approach.

I can’t quite tell what the error is you’re seeing, but since it’s inside RPCTimeEvaluator and then AsycCallFunc on the server, it’s likely that the operator implementation is throwing some kind of exception or causing a crash.

Hello,

it seems it is working now, but I am not 100 percent sure why it is now working.

Either it is working now because I’ve updated tvm to the latest master commit (previously I was using some commit hash from summer), or because I’ve did a minor adaption in the target.

I am using now lp64d instead of lp64 as mabi

target = tvm.target.Target("llvm -mtriple=riscv64-unknown-linux-gnu -mcpu=rocket-rv64 -mabi=lp64d -mattr=+64bit,+m,+a,+f,+d,+c")

Anyway thank you very much for your fast response.

BR Josef