template<typename FType>
class tvm::ObjectFunctor< FType >
A dynamically dispatched functor on the type of the first argument.
Dispatch is based on the runtime type of the first object argument.
ObjectFunctor<std::string(
const ffi::ObjectRef& n, std::string prefix)> tostr;
tostr.SetDispatch<
prim::AddNode>([](
const ffi::ObjectRef& op, std::string prefix) {
return prefix + "Add";
});
tostr.SetDispatch<
IntImmNode>([](
const ffi::ObjectRef& op, std::string prefix) {
return prefix + "IntImm";
});
PrimVar x("x");
PrimExpr y = x + 1;
LOG(INFO) << tostr(y, "My");
Constant integer literals in the program.
Definition expr.h:135
static IntImm Int32(ffi::BigInt value, Location loc=UnknownLoc())
Construct a scalar int32 constant.
Definition expr.h:181
A dynamically dispatched functor on the type of the first argument.
Definition object_functor.h:85
a + b
Definition expr.h:108
A shared table can register dispatch functions during static initialization:
class Printer {
public:
static FType& vtable();
};
Printer::FType& Printer::vtable() {
static FType inst;
return inst;
}
TVM_FFI_STATIC_INIT_BLOCK() {
Printer::vtable()
.SetDispatch<prim::AddNode>([](const ffi::ObjectRef&) { return std::string("Add"); })
.SetDispatch<IntImmNode>([](const ffi::ObjectRef&) { return std::string("IntImm"); });
}
- Template Parameters
-
| FType | Function signature, with const ffi::ObjectRef& or const ffi::Object* as its first argument. |