What target to use? Export compiled target or C code?

Hello,

I am generally confused about the best methods for using tvm/microTVM

My overall goal is:

  • Import an ONNX model
  • Optimize and compile to a RISC-V target (baremetal is fine)
  • Eventually include my own implementations of certain operators

So far I can:

  • Import and optimize an onnx model
  • Export C code

What are the best steps from here?

I understand that to implement my own operators I need to write a codegen for TVM to use. However, is there any point in generating C code or is it possible to go straight to a compiled binary for a RISC-V target? I cannot see how to do this.

I followed some tutorials and got to here, my target is tvm.target.Target("c -march=riscv64-unknown-linux-gnu"):

model_tar_path = "./model.tar"
export_model_library_format(module, model_tar_path)
with tarfile.open(model_tar_path, "r:*") as tar_f:
    print("\n".join(f" - {m.name}" for m in tar_f.getmembers()))


template_project_path = pathlib.Path(tvm.micro.get_microtvm_template_projects("crt"))
project_options = {}

# Create a temporary directory
temp_dir = tvm.contrib.utils.tempdir()
generated_project_dir = temp_dir / "generated-project"
generated_project = tvm.micro.generate_project(
    template_project_path, module, generated_project_dir, project_options
)

generated_project.build()
generated_project.flash()

with tvm.micro.Session(generated_project.transport()) as session:
    aot_executor = tvm.runtime.executor.aot_executor.AotModule(session.create_aot_executor())
    sample = np.array([[[0.5] * 10]])
    aot_executor.get_input("onnx__MatMul_0").copyfrom(sample)
    aot_executor.run()
    result = aot_executor.get_output(0).numpy()
    print(result)

The generated_project.build() compiles a binary bit I can’t figure out how to capture it from the temp directory. Despite my target I am also doubtful that this is compiled for risc-v.

Would be grateful for any assistance :slight_smile: