I am simply mapping addition operation to a library using the BYOC here is my test code
Blockquote
from tvm.contrib import cc, utils, graph_executor from tvm.contrib.download import download_testdata import tvm from tvm.relay.op.contrib.register import register_pattern_table from tvm.relay.dataflow_pattern import is_op, wildcard from tvm import runtime from tvm import relay from tvm.relay import transform from collections import OrderedDict import numpy as np
def update_lib(lib): test_dir = os.path.dirname(os.path.realpath(os.path.expanduser(file))) source_dir = os.path.join(test_dir, “…”, “…”, “…”) contrib_path = os.path.join(source_dir, “src”, “runtime”, “contrib”)
# Setup the gcc flag to compile DNNL code.
kwargs = {}
kwargs["options"] = ["-O2", "-std=c++14", "-I" + contrib_path]
lib_path="/home/irfan/customTarget/C_imp_latest/tvm/compiled/lib.so"
lib.export_library(lib_path, fcompile=False, **kwargs)
return lib
num_r=2
num_c=5
a_np = np.random.choice(10, num_r*num_c).astype(“int32”).reshape((num_r, num_c))
b_np = np.random.choice(10, num_r*num_c).astype(“int32”).reshape((num_r, num_c))
c_np = np.random.choice(10, num_r*num_c).astype(“int32”).reshape((num_r, num_c))
d_np = np.add(a_np, b_np)
e_np = np.multiply(c_np, d_np)
w = relay.var(“w”, shape=a_np.shape, dtype=“int32”) x = relay.var(“x”, shape=b_np.shape, dtype=“int32”)
z = relay.add(w, x) func = relay.Function([w, x], z)
mod = tvm.IRModule.from_expr(func)
print(mod)
mod = transform.MergeComposite(pattern_table())(mod)
mod = relay.transform.AnnotateTarget([“imp”])(mod)
print(mod)
mod = relay.transform.InferType()(mod)
print(mod)
mod = relay.transform.PartitionGraph()(mod)
print(mod)
with tvm.transform.PassContext(opt_level=3, disabled_pass=[“AlterOpLayout”]):
lib = relay.build(mod, target=target, params=None)
print(lib.ir_mod)
update_lib(lib)
Blockquote
Here the C code generted by TVM for library
Blockquote #include
#include
#include
#include
#include <tvm/runtime/c_runtime_api.h>
#include <tvm/runtime/packed_func.h>
#include <dlpack/dlpack.h>
#include “/home/irfan/customTarget/C_imp_latest/tvm/src/runtime/contrib/imp/imp_kernel.h”
using namespace tvm::runtime;
using namespace tvm::runtime::contrib;
void tvmgen_default_imp_main_0_(int* imp_0_i0, int* imp_0_i1, int* out0) {
int * buf_0 = (int *)std::malloc(4 * 10);
imp_binary_op(imp_0_i0, imp_0_i1, buf_0, 0);
memcpy(out0, buf_0, 4 * 10);
free(buf_0);
}
int tvmgen_default_imp_main_0_wrapper_(DLTensor* arg0,
DLTensor* arg1,
DLTensor* out0) {
tvmgen_default_imp_main_0_((int*)(arg0->data),
(int*)(arg1->data),
(int*)(out0->data));
return 0;
}
#ifdef __cplusplus
extern “C” {
#endif
TVM_DLL int32_t tvmgen_default_imp_main_0(TVMValue* args, int* type_code, int num_args, TVMValue* out_value, int* out_type_code) {
DLTensor* arg0 = (DLTensor*)(((TVMValue*)args)[0].v_handle);
DLTensor* arg1 = (DLTensor*)(((TVMValue*)args)[1].v_handle);
DLTensor* ret2 = (DLTensor*)(((TVMValue*)args)[2].v_handle);
tvmgen_default_imp_main_0_wrapper_(arg0,arg1,ret2);
return 0;
}
#ifdef __cplusplus
}
#endif
Blockquote
Now I am continuously getting the no known conversion error here in the screenshot Would be grateful if anyone could suggest any help or guideline Thank you