Skip to content

[Bug] Target not available while compiling ONNX model to MIPS #17578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
RajS999 opened this issue Dec 30, 2024 · 2 comments
Closed

[Bug] Target not available while compiling ONNX model to MIPS #17578

RajS999 opened this issue Dec 30, 2024 · 2 comments
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug

Comments

@RajS999
Copy link

RajS999 commented Dec 30, 2024

I am trying to compile ONNX model using Apache TVM to target MIPS platform. Here is how my code looks like:

import tvm
from tvm import relay
from tvm.contrib import graph_executor
import torch
import onnx

input_shape = (1, 200, 10)  
onnx_model = onnx.load("model.onnx")

# Convert to Relay
input_name = "input0"
shape_dict = {input_name: input_shape}

mod, params = relay.frontend.from_onnx(onnx_model, shape_dict)

# Target MIPS
target = "llvm -mtriple=mips-linux-gcc"

# Compile the model
with tvm.transform.PassContext(opt_level=3):
    lib = relay.build(mod, target=target, params=params)

# Save the model artifacts
lib.export_library("deployable_model.so")
with open("deploy_graph.json", "w") as f:
    f.write(lib.get_graph_json())
with open("deploy_params.params", "wb") as f:
    f.write(relay.save_param_dict(lib.get_params()))

However, it gives me following exception:

$ python onnx2tvm.py 
[00:33:25] /workspace/tvm/src/runtime/threading_backend.cc:338: Warning: more than two frequencies detected!
One or more operators have not been tuned. Please tune your model for better performance. Use DEBUG logging level to see more details.
Traceback (most recent call last):
  File "/home//workspace/my-project/onnx2tvm.py", line 28, in <module>
    lib = relay.build(mod, target=target, params=params)
  File "/home//.local/lib/python3.10/site-packages/tvm/relay/build_module.py", line 364, in build
    graph_json, runtime_mod, params = bld_mod.build(
  File "/home//.local/lib/python3.10/site-packages/tvm/relay/build_module.py", line 161, in build
    self._build(
  File "tvm/_ffi/_cython/./packed_func.pxi", line 331, in tvm._ffi._cy3.core.PackedFuncBase.__call__
  File "tvm/_ffi/_cython/./packed_func.pxi", line 276, in tvm._ffi._cy3.core.FuncCall
  File "tvm/_ffi/_cython/./base.pxi", line 181, in tvm._ffi._cy3.core.CHECK_CALL
tvm._ffi.base.TVMError: Traceback (most recent call last):
  7: TVMFuncCall
  6: tvm::relay::backend::RelayBuildModule::GetFunction(std::string const&, tvm::runtime::ObjectPtr<tvm::runtime::Object> const&)::{lambda(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)#3}::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const
  5: tvm::relay::backend::RelayBuildModule::BuildRelay(tvm::IRModule, tvm::runtime::String const&)
  4: tvm::TIRToRuntime(tvm::runtime::Map<tvm::Target, tvm::IRModule, void, void> const&, tvm::Target const&)
  3: tvm::codegen::Build(tvm::IRModule, tvm::Target)
  2: tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<tvm::runtime::TypedPackedFunc<tvm::runtime::Module (tvm::IRModule, tvm::Target)>::AssignTypedLambda<tvm::codegen::{lambda(tvm::IRModule, tvm::Target)#1}>(tvm::codegen::{lambda(tvm::IRModule, tvm::Target)#1}, std::string)::{lambda(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)#1}> >::Call(tvm::runtime::PackedFuncObj const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)
  1: tvm::codegen::LLVMModuleNode::Init(tvm::IRModule const&, tvm::Target const&)
  0: tvm::codegen::LLVMTargetInfo::GetOrCreateTargetMachine(bool)
  File "/workspace/tvm/src/target/llvm/llvm_instance.cc", line 302
TVMError: 
---------------------------------------------------------------
An error occurred during the execution of TVM.
For more information, please see: https://tvm.apache.org/docs/errors.html
---------------------------------------------------------------
  Check failed: (target_machine_ != nullptr) is false: No available targets are compatible with triple "mips-linux-gcc"

It seems that mips-linux-gcc target is not supported. I also tried mips-linux-gnu, which also did not work.
What is target string for mips target?

@RajS999 RajS999 added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug labels Dec 30, 2024
@mshr-h
Copy link
Contributor

mshr-h commented Jan 24, 2025

Which LLVM version are you using? It works fine on my machine with LLVM 18.

@cbalint13
Copy link
Contributor

cbalint13 commented Feb 9, 2025

@RajS999

Check failed: (target_machine_ != nullptr) is false: No available targets are compatible with triple "mips-linux-gcc"

Based on this error, it seems you don't have mips support compiled in your LLVM.


  • You can use to check mips presence like this here:
     $ python3 -c "import tvm; print(tvm.target.codegen.llvm_get_targets())"
     ["arm", "armeb", "aarch64", "aarch64_be", "aarch64_32", "avr", "bpfel", "bpfeb",
       "hexagon", "loongarch32", "loongarch64",  "mips", "mipsel", "mips64", "mips64el",
       "msp430", "powerpc", "powerpcle", "powerpc64", "powerpc64le", "r600", "amdgcn", 
       "riscv32", "riscv64", "sparc", "sparcv9", "sparcel", "s390x", "thumb", "thumbeb", "i386",
       "x86_64", "xcore", "nvptx", "nvptx64", "lanai", "wasm32", "wasm64"]
    
     $ python3 -c "import tvm; print(tvm.target.codegen.llvm_version_major())"
     20
    

If mips is present in your LLVM library, then llvm -mtriple=mips-linux-gcc or even llvm -mtriple=mips--- is fine.


  • Please not that if you want a "deployable" library you need:

    lib.export_library("deployable_model.so", fcompile=tvm.contrib.cc.cross_compiler("mips-linux-gnu-gcc"))
    

    OR, if you don't have a cross compiler, a non-standalone library:

    lib.export_library("lib.tar") # python rpc
    
  • I've checked the program you provided and it works:

    $ tar -xf lib.tar
    $ file lib0.o 
    lib0.o: ELF 32-bit MSB relocatable, MIPS, MIPS32 version 1 (SYSV), with debug_info, not stripped
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug
Projects
None yet
Development

No branches or pull requests

3 participants