tvm
Loading...
Searching...
No Matches
tvm::ObjectFunctor< FType > Class Template Reference

A dynamically dispatched functor on the type of the first argument. More...

Collaboration diagram for tvm::ObjectFunctor< FType >:

Detailed Description

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;
// dispatch to IntImm, outputs "MyIntImm"
LOG(INFO) << tostr(IntImm::Int32(1), "My");
// dispatch to Add, outputs "MyAdd"
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:
using FType = ObjectFunctor<std::string(const ffi::ObjectRef&)>;
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
FTypeFunction signature, with const ffi::ObjectRef& or const ffi::Object* as its first argument.

The documentation for this class was generated from the following file: