• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019-2024 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_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_LAYOUT_TRANSFER_H_
18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_LAYOUT_TRANSFER_H_
19 
20 #include <string>
21 #include <map>
22 #include "frontend/parallel/status.h"
23 #include "frontend/parallel/tensor_layout/tensor_layout.h"
24 
25 namespace mindspore {
26 namespace parallel {
27 using ReplacementMemo = std::map<size_t, int64_t>;
28 
29 class LayoutTransfer {
30  public:
31   LayoutTransfer() = default;
32   virtual ~LayoutTransfer() = 0;
33   std::string ToString() const;
34   Status Init(const TensorLayout &from_in, const TensorLayout &to_in);
from_in()35   TensorLayout from_in() const { return from_in_; }
to_in()36   TensorLayout to_in() const { return to_in_; }
37 
38  protected:
IsSameTensorShape()39   bool IsSameTensorShape() const { return from_in_.IsSameTensorShape(to_in_); }
IsSameDeviceArrangement()40   bool IsSameDeviceArrangement() const { return from_in_.IsSameDeviceArrangement(to_in_); }
41 
42   TensorLayout from_in_;
43   TensorLayout to_in_;
44 
45  private:
46   virtual Status CheckValidTransfer() = 0;
47 };
48 }  // namespace parallel
49 }  // namespace mindspore
50 
51 #endif  // MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_LAYOUT_TRANSFER_H_
52