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.

kernel_build_info.h 3.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_KERNEL_BUILD_INFO_H_
  17. #define MINDSPORE_CCSRC_KERNEL_KERNEL_BUILD_INFO_H_
  18. #include <iostream>
  19. #include <vector>
  20. #include <memory>
  21. #include <string>
  22. #include <utility>
  23. #include "ir/dtype.h"
  24. #include "kernel/kernel.h"
  25. namespace mindspore {
  26. namespace kernel {
  27. class KernelBuildInfo {
  28. public:
  29. class KernelBuildInfoBuilder;
  30. KernelBuildInfo() {
  31. kernel_type_ = AUTO_DIFF_KERNEL;
  32. fusion_type_ = OPAQUE;
  33. processor_ = AICORE;
  34. input_reshape_type_ = {};
  35. output_reshape_type_ = {};
  36. inputs_format_ = {};
  37. outputs_format_ = {};
  38. inputs_device_type_ = {};
  39. outputs_device_type_ = {};
  40. }
  41. ~KernelBuildInfo() = default;
  42. KernelType kernel_type() const { return kernel_type_; }
  43. std::string GetInputFormat(size_t input_index) const;
  44. std::string GetOutputFormat(size_t output_index) const;
  45. TypeId GetInputDeviceType(size_t input_index) const;
  46. TypeId GetOutputDeviceType(size_t output_index) const;
  47. std::vector<Axis> GetInputReshapeType(size_t input_index) const;
  48. bool IsInputDefaultPadding() const;
  49. bool IsOutputDefaultPadding() const;
  50. std::vector<Axis> GetOutputReshapeType(size_t input_index) const;
  51. std::vector<std::string> GetAllInputFormats() const;
  52. std::vector<std::string> GetAllOutputFormats() const;
  53. std::vector<TypeId> GetAllInputDeviceTypes() const;
  54. std::vector<TypeId> GetAllOutputDeviceTypes() const;
  55. FusionType fusion_type() const { return fusion_type_; }
  56. Processor processor() const { return processor_; }
  57. size_t GetInputNum() const;
  58. size_t GetOutputNum() const;
  59. std::string ToString() const;
  60. bool operator==(const KernelBuildInfo &other) const;
  61. private:
  62. KernelType kernel_type_;
  63. std::vector<std::string> inputs_format_;
  64. std::vector<std::string> outputs_format_;
  65. std::vector<std::vector<Axis>> input_reshape_type_;
  66. std::vector<std::vector<Axis>> output_reshape_type_;
  67. std::vector<TypeId> inputs_device_type_;
  68. std::vector<TypeId> outputs_device_type_;
  69. FusionType fusion_type_;
  70. Processor processor_;
  71. };
  72. using KernelBuildInfoPtr = std::shared_ptr<KernelBuildInfo>;
  73. class KernelBuildInfo::KernelBuildInfoBuilder {
  74. public:
  75. KernelBuildInfoBuilder() { kernel_build_info_ = std::make_shared<KernelBuildInfo>(); }
  76. explicit KernelBuildInfoBuilder(std::shared_ptr<KernelBuildInfo> kernel_build_info)
  77. : kernel_build_info_(std::move(kernel_build_info)) {}
  78. ~KernelBuildInfoBuilder() = default;
  79. void SetKernelType(const KernelType &kernel_type);
  80. void SetInputsFormat(const std::vector<std::string> &inputs_format);
  81. void SetOutputsFormat(const std::vector<std::string> &outputs_format);
  82. void SetInputsDeviceType(const std::vector<TypeId> &inputs_device_type);
  83. void SetOutputsDeviceType(const std::vector<TypeId> &outputs_device_type);
  84. void SetInputReshapeType(const std::vector<std::vector<Axis>> &input_reshape_type);
  85. void SetOutputReshapeType(const std::vector<std::vector<Axis>> &output_reshape_type);
  86. void SetFusionType(FusionType fusion_type);
  87. void SetProcessor(Processor processor);
  88. std::shared_ptr<KernelBuildInfo> Build();
  89. private:
  90. std::shared_ptr<KernelBuildInfo> kernel_build_info_;
  91. };
  92. } // namespace kernel
  93. } // namespace mindspore
  94. #endif // MINDSPORE_CCSRC_KERNEL_KERNEL_BUILD_INFO_H_