Continuing the discussion from Lower function crash in C++ API:
Thanks a lot, it’s really useful, I use the following code, it’s also worked.
// define shape
auto n = tvm::var("n");
tvm::Array<tvm::Expr> shape;
shape.push_back(n);
// define algorithm
auto A = tvm::placeholder(shape, tvm::Float(32), "A");
auto B = tvm::placeholder(shape, tvm::Float(32), "B");
tvm::Tensor C = tvm::compute(A->shape, [&A, &B](tvm::Expr i) { return A[i] + B[i]; }, "C");
// set schedule
tvm::Schedule s = tvm::create_schedule({ C->op });
// tvm::BuildConfig config(tvm::BuildConfigNode());
tvm::BuildConfig config(std::make_shared<tvm::BuildConfigNode>());
auto target = tvm::Target::create("llvm");
auto target_host = tvm::Target::create("llvm");
auto args = tvm::Array<tvm::Tensor>({ A, B, C });
// it doesn't work, what's going on??
std::unordered_map<tvm::Tensor, tvm::Buffer> binds;
tvm::Array<tvm::LoweredFunc> lowered = tvm::lower(s, args, "fadd", binds, config);
tvm::runtime::Module mod = tvm::build(lowered, target, target_host, config);
auto fadd = mod.GetFunction("fadd", true);
std::vector<tvm::runtime::Module> imported_modules = mod->imports();
if (imported_modules.empty())
{
std::cout << "Import mode failed" << std::endl;
}
else
{
std::cout << imported_modules[0]->GetSource() << std::endl;
}
return 0;