Error while using external codegen

Hi, I have made my own codegen.

  1. Craeting a python file mytarget.py
  2. Making an entry in init.py
  3. Craete a codegen mycodegen.cc , the operators which can be loaded to my hardware
  4. make .cmake file and adding entry

After taking basic convolution 2d really module, After annoying the relay partition is there but while executing with tvm.transform.PassContext(opt_level=2):

graph, lib, params = relay.build(mod, target="c", params=None)

I am getting error as Check failed: (pf) is false: Failed to find the external codegen tool for relay.ext.shakti

I cross checked the registration in mycodegen.cc file relay.ext.shakti

Am I missed out some other steps? Kindly let me know how to solve this error.

And it would be beneficial if someone provide how to produce single executable file after this which can be run on hardware

Thanks

can someone please reply

any updates on this? @comaniac @JosseVanDelm @MartinF @areusch

@shreya i think you need to register a codegen function as well to produce a SourceModule with TVM_REGISTER_GLOBAL() (if implementing in c++) or @tvm.register_func() (Python). the function should be named relay.ext.shakti. if you think you have implemented this in mycodegen.cc, then likely that file hasn’t gotten linked into the TVM build (try editing the CMakeLists.txt).

1 Like

Thanks @areusch

The error I am getting is resolved. But now I am confused after performing all 4 steps mentioned. Now how can I generate C code after relay partitioning?

On calling Graph to annotate on relay it is working. But as I called relay.build(target=c,mod) will I get C code executable?

I am confused about how can I get an executable in C that I can cross-compile to for my machine and run on my machine.

Thanks

then you just need to export it using export_model_library_format to get the C code.

1 Like

But I am getting error at relay.build itself. relay.build(mod, target=“c”, params=None) on this line. I am confused now how tvm knows that it has to use my codegen shakti

Thanks

When you annotate a subgraph with kCompiler = "shakti", tvm.relay.build searches for a PackedFunc named relay.ext.shakti and invokes it to create the CSourceModule for the subgraph. I’d suggest you look at the BYOC tutorial: Bring Your Own Codegen To TVM — tvm 0.13.dev0 documentation

based on the error it seems like TVM is not finding this PackedFunc, so either it’s not registered or your codegen file isn’t getting linked in to libtvm.so.

1 Like

Thanks, I followed the tutorial and got

This error after calling relay.build(mod,targte=“c”,params=None)

I uploaded the screen shot of the error. Thanks

it looks like your codegen is being invoked, but the codegen is accessing an array outside its bounds. i’d suggest you add some LOG(INFO) to debug it further–note you can print out IR like:

Call some_call = ...;
LOG(INFO) << "Call: " << some_call;

I probably won’t be able to provide too much assistance at this level of debugging.