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.7 kB

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