1 /** 2 * Copyright 2021 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_TYPE_H_ 18 #define MINDSPORE_CORE_MINDAPI_IR_TYPE_H_ 19 20 #include "mindapi/base/base.h" 21 #include "mindapi/base/type_id.h" 22 #include "mindapi/ir/common.h" 23 #include "mindapi/ir/value.h" 24 25 namespace mindspore::api { 26 /// \brief Type defines the type of a value. 27 class MIND_API Type : public Value { 28 public: 29 MIND_API_BASE_MEMBER(Type); 30 31 /// \brief Get the id of the Type object. 32 /// 33 /// \return The id of the Type object. 34 TypeId type_id() const; 35 36 /// \brief Get the number type of the Type object. 37 /// 38 /// \return The number type of this Type object, kTypeUnknown if this is not a number type. 39 TypeId number_type() const; 40 41 /// \brief Get the Type according to a TypeId. 42 /// 43 /// \param[in] id The id of the type. 44 /// 45 /// \return The pointer to the Type. 46 static TypePtr GetType(TypeId id); 47 48 /// \brief Get data size in bytes for the type according to a TypeId. 49 /// 50 /// \param[in] id The id of the type. 51 /// 52 /// \return The data size in bytes for the Type. 53 static size_t GetSize(TypeId id); 54 }; 55 56 /// \brief TensorType defines the type of a tensor. 57 class MIND_API TensorType : public Type { 58 public: 59 MIND_API_BASE_MEMBER(TensorType); 60 61 /// \brief Construct TensorType from the given element type. 62 /// 63 /// \param[in] element_type The element type of the TensorType. 64 explicit TensorType(const TypePtr &element_type); 65 66 /// \brief Get the element type of this TensorType. 67 /// 68 /// \return The element type of this TensorType. 69 TypePtr element() const; 70 }; 71 72 using TensorTypePtr = SharedPtr<TensorType>; 73 } // namespace mindspore::api 74 75 #endif // MINDSPORE_CORE_MINDAPI_IR_TYPE_H_ 76