1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20/*!
21 * \file src/contrib/ethosu/cascader/block_config.h
22 * \brief BlockConfig object for the NPU cascader
23 */
24#ifndef TVM_CONTRIB_ETHOSU_CASCADER_BLOCK_CONFIG_H_
25#define TVM_CONTRIB_ETHOSU_CASCADER_BLOCK_CONFIG_H_
26
27#include <tvm/node/reflection.h>
28#include <tvm/runtime/object.h>
29
30#include <functional>
31#include <vector>
32
33namespace tvm {
34namespace contrib {
35namespace ethosu {
36namespace cascader {
37
38class BlockConfig;
39
40/*! \brief Node to represent a BlockConfig */
41class BlockConfigNode : public Object {
42 public:
43 void VisitAttrs(AttrVisitor* v);
44
45 /*!
46 * \brief Get the shape of input block.
47 * \return The input shape of the block config.
48 */
49 inline std::vector<int> GetInputBlockShape() const { return input_shape_; }
50
51 /*!
52 * \brief Get the shape of output block.
53 * \return The output shape of the block config.
54 */
55 inline std::vector<int> GetOutputBlockShape() const { return output_shape_; }
56
57 /*!
58 * \brief Get the number of cycles required to output this block
59 * \return The output cycles
60 */
61 inline int GetOutputCycles() const { return output_cycles_; }
62
63 /*!
64 * \brief Get the number of cycles required to compute this block
65 * \return The compute cycles
66 */
67 inline int GetComputeCycles() const { return compute_cycles_; }
68
69 static constexpr const char* _type_key = "contrib.ethosu.cascader.BlockConfig";
70 TVM_DECLARE_FINAL_OBJECT_INFO(BlockConfigNode, Object);
71
72 protected:
73 friend class BlockConfig;
74
75 /*! \brief The shape of the input block */
76 std::vector<int> input_shape_;
77 /*! \brief The shape of the output block */
78 std::vector<int> output_shape_;
79 /*! \brief Cycles required to compute this block */
80 int compute_cycles_;
81 /*! \brief Cycles required to output this block */
82 int output_cycles_;
83};
84
85/*!
86 * \brief An object that contains a an output block shape as well as the output and compute cycles
87 * required to compute this block
88 */
89class BlockConfig : public ObjectRef {
90 public:
91 BlockConfig(const std::vector<int>& input_shape, const std::vector<int>& output_shape,
92 int compute_cycles, int output_cycles);
93
94 TVM_DEFINE_OBJECT_REF_METHODS(BlockConfig, ObjectRef, BlockConfigNode);
95};
96
97} // namespace cascader
98} // namespace ethosu
99} // namespace contrib
100} // namespace tvm
101
102#endif // TVM_CONTRIB_ETHOSU_CASCADER_BLOCK_CONFIG_H_
103