[BYOC] Failed to find the codegen tool for

Hi,

I am trying to follow the BYOC example following the doc and blog post.

The step I followed are:

  1. Writing C codegen (basically just copying the codegen C example)
  2. Adding a cmake (and removing previous codegen C since it was registering the same codegen name, i.e. ccompiler)
  3. Adding python registration of operators in python/tvm/relay/op/contrib/ccompiler.py, also providing partition_for_ccompiler which annotate using ccompiler name and partition graph.

Now I am using this snippet as a test for my codegen:

target = "llvm"
mod, params = build_test_relay()

from tvm.relay.op.contrib.ccompiler import partition_for_ccompiler
pmod = partition_for_ccompiler(mod)
print(f'PMOD\n{pmod}')
# with tvm.transform.PassContext(opt_level=0):
#     lib = R.build(mod, target, params=params)
lib = R.build(pmod, target, params=params)

# Generate graph executor
dev = tvm.device(target, 0)
m = graph_executor.GraphModule(lib["default"](dev))

dtype = 'float32'
x = np.array([
                 [1, 1],
                 [1, 1]
             ], dtype=dtype)
y = np.array([
                 [2, 2],
                 [2, 2]
             ], dtype=dtype)

m.set_input('x', tvm.nd.array(x))
m.set_input('y', tvm.nd.array(y))
m.run()
output = m.get_output(0)

print(f'Output:\n{output}')

And the error:

Traceback (most recent call last):
  File "/Users/.../tvm/tests/slai/relay_multiply.py", line 30, in <module>
    lib = R.build(pmod, target)
  File "/Users/.../tvm/python/tvm/relay/build_module.py", line 471, in build
    graph_json, runtime_mod, params = bld_mod.build(
  File "/Users/.../tvm/python/tvm/relay/build_module.py", line 199, in build
    self._build(mod, target, target_host, executor, runtime, workspace_memory_pools, mod_name)
  File "/Users/.../tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 237, in __call__
    raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
  [bt] (8) 9   libtvm.dylib                        0x0000000129b55574 tvm::transform::Pass::operator()(tvm::IRModule) const + 184
  [bt] (7) 8   libtvm.dylib                        0x0000000129b557c0 tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const + 244
  [bt] (6) 7   libtvm.dylib                        0x0000000129b582ec tvm::transform::SequentialNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const + 872
  [bt] (5) 6   libtvm.dylib                        0x0000000129b557c0 tvm::transform::Pass::operator()(tvm::IRModule, tvm::transform::PassContext const&) const + 244
  [bt] (4) 5   libtvm.dylib                        0x0000000129b56504 tvm::transform::ModulePassNode::operator()(tvm::IRModule, tvm::transform::PassContext const&) const + 1956
  [bt] (3) 4   libtvm.dylib                        0x000000012ae45350 tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<void tvm::runtime::TypedPackedFunc<tvm::IRModule (tvm::IRModule, tvm::transform::PassContext)>::AssignTypedLambda<tvm::relay::tec::LowerTEPass(tvm::runtime::String const&, std::__1::function<void (tvm::BaseFunc)>, tvm::VirtualDevice)::$_8>(tvm::relay::tec::LowerTEPass(tvm::runtime::String const&, std::__1::function<void (tvm::BaseFunc)>, tvm::VirtualDevice)::$_8)::'lambda'(tvm::runtime::TVMArgs const&, tvm::runtime::TVMRetValue*)> >::Call(tvm::runtime::PackedFuncObj const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) + 888
  [bt] (2) 3   libtvm.dylib                        0x000000012ae250cc tvm::relay::tec::LowerTE(tvm::IRModule const&, tvm::runtime::String const&, std::__1::function<void (tvm::BaseFunc)>, tvm::VirtualDevice) + 2480
  [bt] (1) 2   libtvm.dylib                        0x000000012ae2c874 tvm::relay::tec::TECompilerImpl::LowerExternalFunctions() + 2388
  [bt] (0) 1   libtvm.dylib                        0x00000001298036a0 tvm::runtime::detail::LogFatal::Entry::Finalize() + 84
  File "/Users/.../tvm/src/relay/backend/te_compiler.cc", line 206
TVMError:
---------------------------------------------------------------
An error occurred during the execution of TVM.
For more information, please see: https://tvm.apache.org/docs/errors.html
---------------------------------------------------------------
  Check failed: (pf) is false: Failed to find the codegen tool for relay.ext.ccompiler
1 Like

You should probably double check that you do not have a typo in:

TVM_REGISTER_GLOBAL("relay.ext.ccompiler").set_body_typed(CCompiler);

And that your changes to the cmake files actually compile and link your modified .cc files.

1 Like

Seems like the cmake was not executing. I have other issues to figure out now though… Thank you!

Hey i am also facing the same issue, can you tell me how you rectify this. Thanks