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.

hcom_util.h 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_KERNEL_HCCL_HCOM_UTILS_H_
  17. #define MINDSPORE_CCSRC_KERNEL_HCCL_HCOM_UTILS_H_
  18. #include <string>
  19. #include <map>
  20. #include <vector>
  21. #include <memory>
  22. #include "ir/dtype.h"
  23. #include "hccl/base.h"
  24. #include "utils/contract.h"
  25. namespace mindspore {
  26. using std::map;
  27. using std::string;
  28. using std::vector;
  29. constexpr auto kAllGather = "AllGather";
  30. constexpr auto kAllReduce = "AllReduce";
  31. constexpr auto kBroadcast = "Broadcast";
  32. constexpr auto kReduceScatter = "ReduceScatter";
  33. /* Correspondence between data_type and hcom data type in Ascend */
  34. static map<int64_t, hcclDataType_t> CONST_OP_HCOM_DATA_TYPE_MAP = {
  35. {TypeId::kNumberTypeFloat32, HCCL_DATA_TYPE_FLOAT},
  36. {TypeId::kNumberTypeFloat16, HCCL_DATA_TYPE_HALF},
  37. {TypeId::kNumberTypeInt8, HCCL_DATA_TYPE_INT8},
  38. {TypeId::kNumberTypeInt32, HCCL_DATA_TYPE_INT},
  39. };
  40. /* Correspondence between data_type and occupied byte size in hcom */
  41. static map<hcclDataType_t, uint32_t> CONST_OP_HCOM_DATA_TYPE_SIZE_MAP = {
  42. {HCCL_DATA_TYPE_FLOAT, sizeof(float)},
  43. {HCCL_DATA_TYPE_HALF, sizeof(float) / 2},
  44. {HCCL_DATA_TYPE_INT8, sizeof(int8_t)},
  45. {HCCL_DATA_TYPE_INT, sizeof(int32_t)},
  46. };
  47. class HcomUtil {
  48. public:
  49. static bool GetKernelInputShape(const AnfNodePtr &anf_node, vector<vector<size_t>> *hccl_kernel_shape_list);
  50. static bool GetKernelOutputShape(const AnfNodePtr &anf_node, vector<vector<size_t>> *hccl_kernel_shape_list);
  51. static bool GetHcomDataType(const AnfNodePtr &anf_node, vector<hcclDataType_t> *data_type_list);
  52. static bool GetHcclOpSize(const hcclDataType_t &data_type, const vector<size_t> &shape, size_t *size);
  53. static bool GetHcomTypeSize(const hcclDataType_t &data_type, uint32_t *size);
  54. static bool GetHcomCount(const AnfNodePtr &anf_node, const vector<hcclDataType_t> &data_type_list,
  55. const vector<vector<size_t>> &shape_list, uint64_t *total_count);
  56. static bool GetHcomOperationType(const AnfNodePtr &anf_node, hcclRedOp_t *op_type);
  57. static bool GetHcomRootId(const AnfNodePtr &anf_node, uint32_t *root_id);
  58. static void GetHcomGroup(NotNull<const AnfNodePtr &> anf_node, NotNull<std::string *> group);
  59. };
  60. } // namespace mindspore
  61. #endif