• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019-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_IR_DTYPE_REF_H_
18 #define MINDSPORE_CORE_IR_DTYPE_REF_H_
19 
20 #include <memory>
21 #include <string>
22 #include "base/base.h"
23 #include "ir/named.h"
24 #include "ir/dtype/type.h"
25 #include "ir/dtype/tensor_type.h"
26 
27 namespace mindspore {
28 // TypeRefKey type
29 /// \brief RefKeyType defines an Object class whose type is RefKey.
30 class MS_CORE_API RefKeyType final : public Object {
31  public:
32   /// \brief Default constructor for RefKeyType.
RefKeyType()33   RefKeyType() : Object(kObjectTypeRefKey) {}
34 
35   /// \brief Destructor of RefKeyType.
~RefKeyType()36   ~RefKeyType() override {}
MS_DECLARE_PARENT(RefKeyType,Object)37   MS_DECLARE_PARENT(RefKeyType, Object)
38 
39   TypeId generic_type_id() const override { return kObjectTypeRefKey; }
DeepCopy()40   TypePtr DeepCopy() const override { return std::make_shared<RefKeyType>(); }
ToReprString()41   std::string ToReprString() const override { return "type_refkey"; }
DumpText()42   std::string DumpText() const override { return "RefKeyType"; }
43 };
44 
45 // TypeRef type
46 /// \brief RefType defines a TensorType class whose type is Ref.
47 class MS_CORE_API RefType final : public TensorType {
48  public:
49   /// \brief Default constructor for RefType.
RefType()50   RefType() : TensorType() {}
51 
52   /// \brief Constructor for RefType.
53   ///
54   /// \param[in] subtype Define the TensorType for RefType object to refer to.
RefType(const TensorTypePtr & subtype)55   explicit RefType(const TensorTypePtr &subtype) : TensorType(subtype->element()) {}
56 
57   /// \brief Constructor for RefType.
58   ///
59   /// \param[in] subtype Define the TensorType for RefType object to refer to.
RefType(const TensorType * subtype)60   explicit RefType(const TensorType *subtype) : TensorType(subtype->element()) {}
61 
62   /// \brief Destructor of RefType.
~RefType()63   ~RefType() override {}
64   MS_DECLARE_PARENT(RefType, TensorType)
65 
66   TypePtr DeepCopy() const override;
67   std::string ToString() const override;
68   std::string DumpText() const override;
69 };
70 using RefTypePtr = std::shared_ptr<RefType>;
71 
72 GVAR_DEF(TypePtr, kRefKeyType, std::make_shared<RefKeyType>());
73 GVAR_DEF(TypePtr, kRefType, std::make_shared<RefType>());
74 }  // namespace mindspore
75 
76 #endif  // MINDSPORE_CORE_IR_DTYPE_REF_H_
77