zhiics commented on a change in pull request #4644: [WIP] Relay op strategy
URL: https://github.com/apache/incubator-tvm/pull/4644#discussion_r376144257
##########
File path: include/tvm/relay/op_attr_types.h
##########
@@ -207,13 +216,137 @@ enum AnyCodegenStrategy {
kVariableDimensions
};
-/* \brief A runtime representation of shape. */
+/*! \brief A runtime representation of shape. */
using Shape = Array<IndexExpr>;
using FShapeFunc = runtime::TypedPackedFunc<
Array<te::Tensor>(const Attrs& attrs,
- const Array<te::Tensor>& inputs,
- const Array<IndexExpr>& out_ndims)>;
+ const Array<te::Tensor>& inputs,
+ const Array<IndexExpr>& out_ndims)>;
+
+/*!
+ * \brief Operator implementation in TVM.
+ */
+class OpImplementNode : public Object {
+ public:
+ /*! \brief Compute function */
+ FTVMCompute fcompute;
+ /*! \brief Schedule function */
+ FTVMSchedule fschedule;
+ /*! \brief Name of the implementation */
+ std::string name;
+ /*! \brief Priority level */
+ int plevel;
+
+ void VisitAttrs(tvm::AttrVisitor* v) {
+ v->Visit("name", &name);
+ v->Visit("plevel", &plevel);
+ }
+
+ static constexpr const char* _type_key = "relay.OpImplement";
+ TVM_DECLARE_FINAL_OBJECT_INFO(OpImplementNode, Object);
+};
+
+/*!
+ * \brief Operator implementation class.
+ */
+class OpImplement : public ObjectRef {
+ public:
+ /*!
+ * \brief Invoke the operator compute function.
+ * \param attrs The attribute of the primitive
+ * \param inputs The input tensors.
+ * \param out_type The output type information.
+ * \return The output compute description of the operator.
+ */
+ Array<te::Tensor> Compute(const Attrs& attrs,
+ const Array<te::Tensor>& inputs,
+ const Type& out_type);
+ /*!
+ * \brief Build the computation schedule.
+ * \param attrs The attribute of the node.
+ * \param outs The output tensors.
+ * \param target The build target.
+ * \return The computation schedule.
+ */
+ te::Schedule Schedule(const Attrs& attrs,
+ const Array<te::Tensor>& outs,
+ const Target& target);
+
+ TVM_DEFINE_OBJECT_REF_METHODS(OpImplement, ObjectRef, OpImplementNode);
+};
+
+/*!
+ * \brief Specialized implementations for operators under certain conditions.
+ */
+class OpSpecializationNode : public Object {
+ public:
+ /*! \brief List of implementations. */
+ Array<OpImplement> implements;
+ /*! \brief Condition to enable the specialization.
+ * Could be undefined to represent generic case. */
+ te::SpecializedCondition condition;
+
+ void VisitAttrs(tvm::AttrVisitor* v) {
+ v->Visit("condition", &condition);
+ v->Visit("implements", &implements);
+ }
+
+ static constexpr const char* _type_key = "relay.OpSpecialization";
+ TVM_DECLARE_FINAL_OBJECT_INFO(OpSpecializationNode, ExprNode);
+};
+
+/*!
+ * \brief Operator specialization class.
+ */
+class OpSpecialization : public ObjectRef {
+ public:
+ /*!
+ * \brief Add an implementation.
+ * \param compute Compute function
+ * \param schedule Schedule function
Review comment:
s/schedule/fschedule
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services