1 /** 2 * Copyright 2019 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_RESHAPE_LAYOUT_TRANSFER_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_RESHAPE_LAYOUT_TRANSFER_H_ 19 20 #include <memory> 21 #include "frontend/parallel/status.h" 22 #include "frontend/parallel/tensor_layout/layout_transfer.h" 23 24 namespace mindspore { 25 namespace parallel { 26 class ReshapeLayoutTransfer : public LayoutTransfer { 27 public: 28 ReshapeLayoutTransfer() = default; 29 ~ReshapeLayoutTransfer() override = default; 30 std::shared_ptr<ReshapeLayoutTransfer> UnifyDeviceArrangementAndTensorShape() const; 31 std::shared_ptr<ReshapeLayoutTransfer> ExtendFromTensorShapeByTo() const; 32 std::shared_ptr<ReshapeLayoutTransfer> ExtendToTensorShapeByFrom() const; 33 std::shared_ptr<ReshapeLayoutTransfer> ExtendFromTensorShapeByExpandedTensorShape() const; 34 std::shared_ptr<ReshapeLayoutTransfer> ExtendToTensorShapeByExpandedTensorShape() const; 35 std::shared_ptr<ReshapeLayoutTransfer> ExpandFromTensorShapeAndExpandToDeviceArrangement( 36 const Arrangement &expand_shape) const; 37 std::shared_ptr<ReshapeLayoutTransfer> ExchangeFromAndTo() const; ExpandAble()38 bool ExpandAble() const { return is_expand_able_; } 39 bool FromTensorShapeCanBeExpandByTo() const; 40 bool ToTensorShapeCanBeExpandByFrom() const; SetExpandAble(const bool is_expand_able)41 void SetExpandAble(const bool is_expand_able) { is_expand_able_ = is_expand_able; } 42 43 private: 44 Status CheckValidTransfer() override; 45 std::shared_ptr<Arrangement> ComputeExpandedFromTensorShapeByTo() const; 46 bool is_expand_able_ = true; 47 }; 48 } // namespace parallel 49 } // namespace mindspore 50 51 #endif // MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_RESHAPE_LAYOUT_TRANSFER_H_ 52