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_select_cpu.h 2.1 kB

5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * Copyright 2020 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_DEVICE_CPU_KERNEL_SELECT_CPU_H_
  17. #define MINDSPORE_CCSRC_DEVICE_CPU_KERNEL_SELECT_CPU_H_
  18. #include <utility>
  19. #include <string>
  20. #include <vector>
  21. #include "ir/anf.h"
  22. #include "ir/dtype/type.h"
  23. #include "utils/utils.h"
  24. namespace mindspore {
  25. namespace device {
  26. namespace cpu {
  27. void SetKernelInfo(const CNodePtr &apply_kernel_ptr);
  28. class KernelAttr {
  29. public:
  30. using DataType = std::pair<TypeId, std::string>;
  31. KernelAttr() : all_same_(0) {}
  32. ~KernelAttr() = default;
  33. KernelAttr &AddInputAttr(const TypeId &ms_type, const std::string &format = kOpFormat_DEFAULT) {
  34. input_type_.emplace_back(ms_type, format);
  35. return *this;
  36. }
  37. KernelAttr &AddOutputAttr(const TypeId &ms_type, const std::string &format = kOpFormat_DEFAULT) {
  38. output_type_.emplace_back(ms_type, format);
  39. return *this;
  40. }
  41. KernelAttr &SetAllSameAttr(bool all_same) {
  42. all_same_ = all_same;
  43. return *this;
  44. }
  45. const DataType &GetInputAttr(const size_t index) const { return input_type_[index]; }
  46. const DataType &GetOutputAttr(const size_t index) const { return output_type_[index]; }
  47. bool GetAllSame() const { return all_same_; }
  48. size_t GetInputSize() const { return input_type_.size(); }
  49. size_t GetOutputSize() const { return output_type_.size(); }
  50. private:
  51. std::vector<DataType> input_type_;
  52. std::vector<DataType> output_type_;
  53. bool all_same_;
  54. };
  55. } // namespace cpu
  56. } // namespace device
  57. } // namespace mindspore
  58. #endif // MINDSPORE_CCSRC_DEVICE_CPU_KERNEL_SELECT_CPU_H_