You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

arrangement.h 2.2 kB

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