以tvm.graph_runtime.create为例
宏展开
- #define TVM_REGISTER_GLOBAL(OpName) TVM_STR_CONCAT(TVM_FUNC_REG_VAR_DEF, __COUNTER__) = ::tvm::runtime::Registry::Register(OpName)
- 扩展到:
- TVM_STR_CONCAT(TVM_FUNC_REG_VAR_DEF, __COUNTER__) = ::tvm::runtime::Registry::Register("tvm.graph_runtime.create")
- 扩展到:
- #define TVM_FUNC_REG_VAR_DEF static TVM_ATTRIBUTE_UNUSED ::tvm::runtime::Registry& __mk_##TVM
- #define TVM_ATTRIBUTE_UNUSED __attribute__((unused))
- __COUNTER__ 为编译器递增计数器,
- #define TVM_STR_CONCAT_(__x, __y) __x##__y //字符串拼接
- #define TVM_STR_CONCAT(__x, __y) TVM_STR_CONCAT_(__x, __y)
- 所以彻底展开后为:
- ::tvm::runtime::Registry& __mk_0 = ::tvm::runtime::Registry::Register("tvm.graph_runtime.create").set_body()
- set_body中为一个注册函数,lambda表达式而已
- Register类的构造函数,TVM_DLL static Registry& Register(const std::string& name, bool override = false); // NOLINT(*)
- 函数简介为Register a function with given name,参数cna_override为是否覆盖原来的注册函数贴实现如下:
- Manager里边函数一个静态函数Global,获取单示例inst,属性fmap保存所有name,及registry示例
- 函数简介为Register a function with given name,参数cna_override为是否覆盖原来的注册函数贴实现如下:
- set_body函数对构造函数返回的registry示例设置function,示例function为一lambda表达式,调用了c函数,GraphRuntimeCreate
获取注册函数,获取注册函数通过get方法,如下代码片段:
-
_LIB 通过调用 ctypes.CDLL模块得到,
- TVMFuncGetGlobal实现如下:
- Get方法如下:
- func_即为set_body设置进去的函数,