• 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_IR_DTYPE_MONAD_H_
18 #define MINDSPORE_CORE_IR_DTYPE_MONAD_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include "base/base.h"
24 #include "ir/dtype/type.h"
25 
26 namespace mindspore {
27 class MonadType : public Object {
28  public:
29   ~MonadType() override = default;
MS_DECLARE_PARENT(MonadType,Object)30   MS_DECLARE_PARENT(MonadType, Object)
31 
32   TypeId generic_type_id() const override { return kObjectTypeMonad; }
33   TypePtr DeepCopy() const override = 0;
34 
35  protected:
MonadType(const TypeId type_id)36   explicit MonadType(const TypeId type_id) : Object(type_id) {}
37 };
38 using MonadTypePtr = std::shared_ptr<MonadType>;
39 
40 // UniversalMonad type
41 class UMonadType : public MonadType {
42  public:
UMonadType()43   UMonadType() : MonadType(kObjectTypeUMonad) {}
~UMonadType()44   ~UMonadType() override {}
MS_DECLARE_PARENT(UMonadType,MonadType)45   MS_DECLARE_PARENT(UMonadType, MonadType)
46 
47   TypeId generic_type_id() const override { return kObjectTypeUMonad; }
DeepCopy()48   TypePtr DeepCopy() const override { return std::make_shared<UMonadType>(); }
ToString()49   std::string ToString() const override { return "UMonad"; }
50 };
51 using UMonadTypePtr = std::shared_ptr<UMonadType>;
52 
53 // IOMonad type
54 class IOMonadType : public MonadType {
55  public:
IOMonadType()56   IOMonadType() : MonadType(kObjectTypeIOMonad) {}
~IOMonadType()57   ~IOMonadType() override {}
MS_DECLARE_PARENT(IOMonadType,MonadType)58   MS_DECLARE_PARENT(IOMonadType, MonadType)
59 
60   TypeId generic_type_id() const override { return kObjectTypeIOMonad; }
DeepCopy()61   TypePtr DeepCopy() const override { return std::make_shared<IOMonadType>(); }
ToString()62   std::string ToString() const override { return "IOMonad"; }
63 };
64 using IOMonadTypePtr = std::shared_ptr<IOMonadType>;
65 
66 MS_CORE_API extern const TypePtr kIOMonadType;
67 MS_CORE_API extern const TypePtr kUMonadType;
68 }  // namespace mindspore
69 
70 #endif  // MINDSPORE_CORE_IR_DTYPE_MONDA_H_
71