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_ARRANGEMENT_H_ 18 #define MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_ARRANGEMENT_H_ 19 20 #include <cstdint> 21 #include <map> 22 #include <memory> 23 #include <string> 24 #include <vector> 25 #include <utility> 26 #include "frontend/parallel/status.h" 27 #include "frontend/parallel/tensor_layout/array.h" 28 29 namespace mindspore { 30 namespace parallel { 31 class Arrangement : public Array { 32 public: Arrangement()33 Arrangement() : size_(1) {} 34 ~Arrangement() override = default; 35 Status Init(const Shape &array) override; 36 Status UpdateTensorShape(size_t index, int64_t update_value); size()37 int64_t size() const { return size_; } 38 Shape GetFrontElementByValue(int64_t value) const; 39 std::shared_ptr<std::vector<Arrangement>> GetExpandShapeList(const Arrangement &expand_shape) const; 40 Shape ComputeReverseAccumulateSumInReverseOrder() const; 41 std::shared_ptr<Arrangement> GetExpandedShapeByExpandListReserveLeft( 42 const std::vector<Arrangement> &expand_list) const; 43 std::shared_ptr<Arrangement> GetExpandedShapeByExpandListRemoveLeft( 44 const std::vector<Arrangement> &expand_list) const; 45 std::shared_ptr<std::pair<std::vector<Arrangement>, Arrangement>> GetExpandShapeListPair( 46 const Arrangement &expand_shape) const; 47 std::shared_ptr<Arrangement> GetUnifiedShape(const Arrangement &in2) const; 48 std::vector<size_t> GetSqueezeIdx() const; 49 Arrangement GetSqueezeArrangement() const; 50 51 private: 52 bool IsValidArrangement(); 53 void ComputeSize(); 54 int64_t size_; 55 }; 56 } // namespace parallel 57 } // namespace mindspore 58 59 #endif // MINDSPORE_CCSRC_FRONTEND_PARALLEL_TENSOR_LAYOUT_ARRANGEMENT_H_ 60