• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021-2022 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_CORE_MINDAPI_IR_ABSTRACT_H_
18 #define MINDSPORE_CORE_MINDAPI_IR_ABSTRACT_H_
19 
20 #include <cstdint>
21 #include <string>
22 #include "mindapi/base/base.h"
23 #include "mindapi/ir/common.h"
24 #include "mindapi/ir/shape.h"
25 #include "mindapi/ir/type.h"
26 #include "mindapi/ir/value.h"
27 
28 namespace mindspore::api {
29 /// \brief AbstractBase defines base interfaces for abstract of an anf node.
30 class MIND_API AbstractBase : public Base {
31  public:
32   MIND_API_BASE_MEMBER(AbstractBase);
33 
34   /// \brief Clone an abstract from this abstract.
35   ///
36   /// \return A pointer to the cloned abstract.
37   AbstractBasePtr Clone() const;
38 
39   /// \brief Get the abstract type.
40   ///
41   /// \return A pointer to the Type.
42   TypePtr type() const;
43 
44   /// \brief Get the abstract value.
45   ///
46   /// \return A pointer to the Value.
47   ValuePtr value() const;
48 
49   /// \brief Get the shape of the abstract.
50   ///
51   /// \return A pointer to the shape.
52   ShapePtr shape() const;
53 
54   /// \brief Set the type for this abstract.
55   ///
56   /// \param[in] type The type to be set.
57   void set_type(const TypePtr &type);
58 
59   /// \brief Set the value for this abstract.
60   ///
61   /// \param[in] value The value to be set.
62   void set_value(const ValuePtr &value);
63 
64   /// \brief Set the shape for this abstract.
65   ///
66   /// \param[in] shape The shape to be set.
67   void set_shape(const ShapePtr &shape);
68 };
69 
70 /// \brief AbstractScalar describes a scalar's type and value.
71 class MIND_API AbstractScalar : public AbstractBase {
72  public:
73   MIND_API_BASE_MEMBER(AbstractScalar);
74 
75   /// \brief Constructs an AbstractScalar with the given value and type.
76   ///
77   /// \param[in] value The value.
78   /// \param[in] type The type.
79   AbstractScalar(const ValuePtr &value, const TypePtr &type);
80 
81   /// \brief Constructs an AbstractScalar with the given type.
82   ///
83   /// \param[in] type The type.
84   explicit AbstractScalar(const TypePtr &type);
85 
86   /// \brief Constructs an AbstractScalar with the given value.
87   ///
88   /// \param[in] value The value.
89   explicit AbstractScalar(const ValuePtr &value);
90 
91   /// \brief Constructs an AbstractScalar with an int64 value.
92   ///
93   /// \param[in] value The int64 value.
94   explicit AbstractScalar(int64_t value);
95 
96   /// \brief Constructs an AbstractScalar with a float value.
97   ///
98   /// \param[in] value The float value.
99   explicit AbstractScalar(float value);
100 
101   /// \brief Constructs an AbstractScalar with a bool value.
102   ///
103   /// \param[in] value The boolean value.
104   explicit AbstractScalar(bool value);
105 
106   /// \brief Constructs an AbstractScalar with a string value.
107   ///
108   /// \param[in] value The string value.
109   explicit AbstractScalar(const std::string &value);
110 };
111 
112 using AbstractScalarPtr = SharedPtr<AbstractScalar>;
113 
114 /// \brief AbstractTensor describes a tensor's type, shape and value.
115 class MIND_API AbstractTensor : public AbstractBase {
116  public:
117   MIND_API_BASE_MEMBER(AbstractTensor);
118 
119   /// \brief Create AbstractTensor from the given type and shape.
120   ///
121   /// \param[in] type The data type id of the tensor.
122   /// \param[in] shape The shape of the tensor.
123   AbstractTensor(TypeId type, const ShapeVector &shape);
124 
125   /// \brief Get the element abstract.
126   ///
127   /// \return A pointer to the element abstract.
128   AbstractBasePtr element() const;
129 };
130 
131 using AbstractTensorPtr = SharedPtr<AbstractTensor>;
132 
133 /// \brief AbstractSequence describes the abstract for a tuple or list.
134 class MIND_API AbstractSequence : public AbstractBase {
135  public:
136   MIND_API_BASE_MEMBER(AbstractSequence);
137 
138   /// \brief Get element abstracts.
139   ///
140   /// \return A vector of element abstracts.
141   AbstractBasePtrList elements() const;
142 };
143 
144 using AbstractSequencePtr = SharedPtr<AbstractSequence>;
145 
146 /// \brief AbstractTuple describes the abstract for a tuple.
147 class MIND_API AbstractTuple : public AbstractSequence {
148  public:
149   MIND_API_BASE_MEMBER(AbstractTuple);
150 
151   /// \brief Create AbstractTuple from a list of element abstracts.
152   ///
153   /// \param[in] elements A list of abstracts.
154   explicit AbstractTuple(const AbstractBasePtrList &elements);
155 };
156 
157 using AbstractTuplePtr = SharedPtr<AbstractTuple>;
158 }  // namespace mindspore::api
159 #endif  // MINDSPORE_CORE_MINDAPI_IR_ABSTRACT_H_
160