channel.h 1.31 KB
Newer Older
Tianqi Chen committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*!
 *  Copyright (c) 2017 by Contributors
 * \file channel.h
 * \brief Channel object for pipeline.
 */
#ifndef TVM_CHANNEL_H_
#define TVM_CHANNEL_H_

#include <tvm/expr.h>

namespace tvm {
// Node container of channel
struct ChannelNode;

/*! \brief The data channel. */
class Channel : public NodeRef {
 public:
  /*! \brief default constructor  */
  Channel() {}
  explicit Channel(std::shared_ptr<Node> n) : NodeRef(n) {}
  /*!
   * \brief access the internal node container
   * \return the pointer to the internal node container
   */
  inline const ChannelNode* operator->() const;
26 27
  // The container type
  using ContainerType = ChannelNode;
Tianqi Chen committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
};

/*!
 * \brief Generalized FIFO channel.
 */
struct ChannelNode : public Node {
  /*! \brief Variable to channel handle */
  Var handle_var;
  /*! \brief default data type in read/write */
  Type dtype;
  // visit all attributes
  void VisitAttrs(AttrVisitor* v) final {
    v->Visit("handle_var", &handle_var);
    v->Visit("dtype", &dtype);
  }

  static Channel make(Var handle_var, Type dtype);
  static constexpr const char* _type_key = "Channel";

  TVM_DECLARE_NODE_TYPE_INFO(ChannelNode, Node);
};

// Inline implementations
inline const ChannelNode* Channel::operator->() const {
  return static_cast<const ChannelNode*>(node_.get());
}
}  // namespace tvm
#endif  // TVM_CHANNEL_H_