|
| 1 | +/*! |
| 2 | + * Copyright (c) 2017 by Contributors |
| 3 | + * \file op_attr_types.h |
| 4 | + * \brief The Expr and related elements in DataFlow construction. |
| 5 | + */ |
| 6 | +#ifndef NNVM_COMPILER_OP_ATTR_TYPES_H_ |
| 7 | +#define NNVM_COMPILER_OP_ATTR_TYPES_H_ |
| 8 | + |
| 9 | +#include <tvm/expr.h> |
| 10 | +#include <tvm/tensor.h> |
| 11 | +#include <tvm/schedule.h> |
| 12 | +#include <tvm/packed_func_ext.h> |
| 13 | +#include <tvm/runtime/registry.h> |
| 14 | +#include <nnvm/op_attr_types.h> |
| 15 | +#include <nnvm/graph_attr_types.h> |
| 16 | +#include <nnvm/graph.h> |
| 17 | +#include <vector> |
| 18 | +#include <string> |
| 19 | + |
| 20 | +namespace nnvm { |
| 21 | +namespace compiler { |
| 22 | + |
| 23 | +using ::tvm::Array; |
| 24 | +using ::tvm::Tensor; |
| 25 | +using ::tvm::Schedule; |
| 26 | + |
| 27 | +/*! \brief operator pattern used in graph fusion */ |
| 28 | +enum OpPatternKind : int { |
| 29 | + // Elementwise operation |
| 30 | + kElemWise = 0, |
| 31 | + // Broadcast operation |
| 32 | + kBroadcast = 1, |
| 33 | + // Complex operation, can fuse bcast in input/outputs |
| 34 | + // but cannot chain another complex op |
| 35 | + kComplex = 2, |
| 36 | + // Extern operation, cannot fuse anything. |
| 37 | + kExtern = 3 |
| 38 | +}; |
| 39 | + |
| 40 | +/*! \brief the operator pattern */ |
| 41 | +using TOpPattern = int; |
| 42 | + |
| 43 | +/*! |
| 44 | + * \brief Computation description interface |
| 45 | + * \param attrs The attribute of the node. |
| 46 | + * \param inputs The input tensors(placeholders) |
| 47 | + * \return The output description of the tensor. |
| 48 | + */ |
| 49 | +using FTVMCompute = std::function< |
| 50 | + Array<Tensor> |
| 51 | + (const NodeAttrs& attrs, const Array<Tensor>& inputs)>; |
| 52 | + |
| 53 | +/*! |
| 54 | + * \brief Build the computation schedule for |
| 55 | + * op whose root is at current op. |
| 56 | + * \param attrs The attribute of the node. |
| 57 | + * \param outs The output tensors. |
| 58 | + * \param target The build target. |
| 59 | + * \return schedule The computation schedule. |
| 60 | + */ |
| 61 | +using FTVMSchedule = std::function< |
| 62 | + Schedule(const NodeAttrs& attrs, |
| 63 | + const Array<Tensor>& outs, |
| 64 | + const std::string& target)>; |
| 65 | + |
| 66 | +/*! \brief Layout Information about an entry */ |
| 67 | +using TLayoutInfo = std::string; |
| 68 | + |
| 69 | +/*! |
| 70 | + * \brief The producer consumer function of node layout |
| 71 | + * \param attrs The attribute of the node. |
| 72 | + * \param ilayouts The input layouts that the node request. |
| 73 | + * \param olayouts The output layouts that the node produce. |
| 74 | + * \return bool The success flag. |
| 75 | + */ |
| 76 | +using FTVMLayoutRequest = std::function<bool (const NodeAttrs& attrs, |
| 77 | + std::vector<TLayoutInfo> *ilayouts, |
| 78 | + std::vector<TLayoutInfo> *olayouts)>; |
| 79 | + |
| 80 | +/*! |
| 81 | + * \brief Transform from normal operator to vectorized operator |
| 82 | + * \param node The source node. |
| 83 | + * \return Transformed vectorized op. |
| 84 | + */ |
| 85 | +using FTVMVectorizedOp = std::function<nnvm::NodePtr (const nnvm::Node* node)>; |
| 86 | + |
| 87 | +} // namespace compiler |
| 88 | +} // namespace nnvm |
| 89 | +#endif // NNVM_COMPILER_OP_ATTR_TYPES_H_ |
0 commit comments