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.

hccl_kernel_metadata.cc 2.6 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. #include "kernel/hccl/hccl_kernel_metadata.h"
  17. #include <memory>
  18. #include "utils/utils.h"
  19. #include "kernel/hccl/hcom_util.h"
  20. #include "session/anf_runtime_algorithm.h"
  21. namespace mindspore {
  22. namespace kernel {
  23. void HcclMetadataInfo(const CNodePtr &kernel_node, std::vector<std::shared_ptr<KernelBuildInfo>> *kernel_info_list) {
  24. const std::vector<TypeId> kHcclSupportTypes = {kNumberTypeInt8, kNumberTypeInt32, kNumberTypeFloat16,
  25. kNumberTypeFloat32, kNumberTypeInt16};
  26. MS_EXCEPTION_IF_NULL(kernel_info_list);
  27. MS_EXCEPTION_IF_NULL(kernel_node);
  28. std::string op_name = AnfAlgo::GetCNodeName(kernel_node);
  29. if (op_name != kAllGather && op_name != kAllReduce && op_name != kBroadcast && op_name != kReduceScatter) {
  30. MS_LOG(DEBUG) << "Hccl does not have op [" << op_name << "]";
  31. return;
  32. }
  33. for (const auto &type : kHcclSupportTypes) {
  34. std::vector<std::string> inputs_format{};
  35. std::vector<TypeId> inputs_type{};
  36. for (size_t input_index = 0; input_index < AnfAlgo::GetInputTensorNum(kernel_node); ++input_index) {
  37. inputs_format.emplace_back(AnfAlgo::GetPrevNodeOutputFormat(kernel_node, input_index));
  38. inputs_type.push_back(type);
  39. }
  40. std::vector<std::string> outputs_format;
  41. std::vector<TypeId> outputs_type;
  42. for (size_t output_index = 0; output_index < AnfAlgo::GetOutputTensorNum(kernel_node); ++output_index) {
  43. outputs_format.emplace_back(AnfAlgo::GetPrevNodeOutputFormat(kernel_node, output_index));
  44. outputs_type.push_back(type);
  45. }
  46. auto builder = KernelBuildInfo::KernelBuildInfoBuilder();
  47. builder.SetInputsFormat(inputs_format);
  48. builder.SetInputsDeviceType(inputs_type);
  49. builder.SetOutputsFormat(outputs_format);
  50. builder.SetOutputsDeviceType(outputs_type);
  51. builder.SetKernelType(HCCL_KERNEL);
  52. kernel_info_list->push_back(builder.Build());
  53. }
  54. }
  55. } // namespace kernel
  56. } // namespace mindspore