TVM_DLL

  1. #ifndef TVM_DLL
  2. #ifdef _WIN32
  3. #ifdef TVM_EXPORTS
  4. #define TVM_DLL __declspec(dllexport)
  5. #else
  6. #define TVM_DLL __declspec(dllimport)
  7. #endif
  8. #else
  9. #define TVM_DLL __attribute__((visibility("default")))
  10. #endif
  11. #endif

TVM_VERSION

  1. // TVM version
  2. #define TVM_VERSION "0.6.0"

TVM_REGISTER_GLOBAL / TVM_REGISTER_API

注册一个全局宏
例如:

  1. TVM_REGISTER_GLOBAL("MyPrint")
  2. .set_body([](TVMArgs args, TVMRetValue* rv) {
  3. });
  4. static __attribute__((unused)) ::tvm::runtime::Registry& __mk_ ## TVM##__COUNTER__ = ::tvm::runtime::Registry::Register(OpName)

TVM_REGISTER_OBJECT_TYPE
_

TVMREGISTER_NODE_TYPE
_Register a node type to object registry and reflection registry.

TVMDECLARE_INTRIN_UNARY
_Intrinsic operators

TVM_CHECK_TYPE_CODE

RELAY_REGISTER_OP

Register a new operator, or set attribute of the corresponding op.

RELAY_REGISTER_UNARY_OP

RELAY_REGISTER_BINARY_OP

RELAY_REGISTER_CMP_OP

这三个宏是对TVM_REGISTER_API和RELAY_REGISTER_OP的进一步封装,如下:

  1. /*! Quick helper macro
  2. * - Expose a positional make function to construct the node.
  3. * - Register op to the registry.
  4. *
  5. * We make the decision to always only expose positional argument.
  6. * We will do rewrapping in the frontend to support language
  7. * sugars such as keyword arguments and default value.
  8. * \param OpName the name of registry.
  9. */
  10. #define RELAY_REGISTER_UNARY_OP(OpName) \
  11. TVM_REGISTER_API("relay.op._make." OpName) \
  12. .set_body_typed<Expr(Expr)>([](Expr data) { \
  13. static const Op& op = Op::Get(OpName); \
  14. return CallNode::make(op, {data}, Attrs(), {}); \
  15. }); \
  16. RELAY_REGISTER_OP(OpName) \
  17. .set_num_inputs(1) \
  18. .add_argument("data", "Tensor", "The input tensor.") \
  19. .add_type_rel("Identity", IdentityRel) \
  20. .set_attr<TOpPattern>("TOpPattern", kElemWise) \
  21. .set_attr<TOpIsStateful>("TOpIsStateful", false) \
  22. .set_attr<FInferCorrectLayout>("FInferCorrectLayout", \
  23. ElemwiseArbitraryLayout) \
  24. /*! Quick helper macro
  25. * - Expose a positional make function to construct the node.
  26. * - Register op to the registry.
  27. *
  28. * We make the decision to always only expose positional argument.
  29. * We will do rewrapping in the frontend to support language
  30. * sugars such as keyword arguments and default value.
  31. *
  32. * \param OpName the name of registry.
  33. */
  34. #define RELAY_REGISTER_BINARY_OP(OpName) \
  35. TVM_REGISTER_API("relay.op._make." OpName) \
  36. .set_body_typed<Expr(Expr, Expr)>([](Expr lhs, Expr rhs) { \
  37. static const Op& op = Op::Get(OpName); \
  38. return CallNode::make(op, {lhs, rhs}, Attrs(), {}); \
  39. }); \
  40. RELAY_REGISTER_OP(OpName) \
  41. .set_num_inputs(2) \
  42. .add_argument("lhs", "Tensor", "The left hand side tensor.") \
  43. .add_argument("rhs", "Tensor", "The right hand side tensor.") \
  44. .add_type_rel("Broadcast", BroadcastRel) \
  45. .set_attr<TOpPattern>("TOpPattern", kBroadcast) \
  46. .set_attr<TOpIsStateful>("TOpIsStateful", false) \
  47. .set_attr<FInferCorrectLayout>("FInferCorrectLayout", \
  48. BinaryBroadcastLayout)
  49. // Comparisons
  50. #define RELAY_REGISTER_CMP_OP(OpName) \
  51. TVM_REGISTER_API("relay.op._make." OpName) \
  52. .set_body_typed<Expr(Expr, Expr)>([](Expr lhs, Expr rhs) { \
  53. static const Op& op = Op::Get(OpName); \
  54. return CallNode::make(op, {lhs, rhs}, Attrs(), {}); \
  55. }); \
  56. RELAY_REGISTER_OP(OpName) \
  57. .set_num_inputs(2) \
  58. .add_argument("lhs", "Tensor", "The left hand side tensor.") \
  59. .add_argument("rhs", "Tensor", "The right hand side tensor.") \
  60. .add_type_rel("BroadcastComp", BroadcastCompRel) \
  61. .set_attr<TOpPattern>("TOpPattern", kBroadcast) \
  62. .set_attr<TOpIsStateful>("TOpIsStateful", false) \
  63. .set_attr<FInferCorrectLayout>("FInferCorrectLayout", \
  64. BinaryBroadcastLayout)