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

**URL:** <https://discuss.tvm.apache.org/t/what-target-to-use-export-compiled-target-or-c-code/17492>\
**Category:** Questions\
**Created:** [July 19, 2024, 9:34am UTC](https://discuss.tvm.apache.org/t/what-target-to-use-export-compiled-target-or-c-code/17492 "2024-07-19T09:34:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomhepworth](https://discuss.tvm.apache.org/user_avatar/discuss.tvm.apache.org/tomhepworth/32/5592_2.png) [@tomhepworth](https://discuss.tvm.apache.org/u/tomhepworth)\
**Post date:** [July 19, 2024, 9:34am UTC](https://discuss.tvm.apache.org/t/what-target-to-use-export-compiled-target-or-c-code/17492/1 "2024-07-19T09:34:23Z")

</div>

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")`:

```auto
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 🙂
