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_info.h 4.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_DEVICE_KERNEL_INFO_H_
  17. #define MINDSPORE_DEVICE_KERNEL_INFO_H_
  18. #include <vector>
  19. #include <memory>
  20. #include "ir/kernel_info_dev.h"
  21. #include "kernel/kernel_build_info.h"
  22. #include "plugin/device/ascend/hal/device/ascend_device_address.h"
  23. #include "kernel/kernel.h"
  24. namespace mindspore {
  25. const uint32_t kInvalidGraphId = UINT32_MAX;
  26. const uint32_t kInvalidDistincLabel = UINT32_MAX;
  27. namespace device {
  28. class KernelInfo : public KernelInfoDevice {
  29. public:
  30. KernelInfo() {
  31. kernel_mod_ = nullptr;
  32. is_feature_map_ = false;
  33. select_kernel_build_info_ = nullptr;
  34. output_address_list_ = {};
  35. workspace_address_list_ = {};
  36. stream_id_ = UINT32_MAX;
  37. stream_distinction_label_ = kInvalidDistincLabel;
  38. graph_id_ = kInvalidGraphId;
  39. }
  40. virtual ~KernelInfo() = default;
  41. bool has_build_info() const override { return select_kernel_build_info() != nullptr; }
  42. const kernel::KernelBuildInfo *select_kernel_build_info() const;
  43. kernel::KernelBuildInfoPtr GetMutableSelectKernelBuildInfo() const;
  44. void set_select_kernel_build_info(const kernel::KernelBuildInfoPtr &select_kernel_build_info) {
  45. select_kernel_build_info_ = select_kernel_build_info;
  46. }
  47. void set_feature_map_flag(bool flag) { is_feature_map_ = flag; }
  48. const DeviceAddress *GetOutputAddr(size_t index) const;
  49. DeviceAddressPtr GetMutableOutputAddr(size_t index) const;
  50. bool OutputAddrExist(size_t index) const;
  51. bool SetOutputAddr(const DeviceAddressPtr &output_address, size_t index);
  52. DeviceAddress *GetWorkspaceAddr(size_t index) const;
  53. DeviceAddressPtr GetMutableWorkspaceAddr(size_t index) const;
  54. bool WorkspaceAddrExist(size_t index) const;
  55. bool SetWorkspaceAddr(const DeviceAddressPtr &output_address, size_t index);
  56. void set_kernel_mod(const kernel::KernelModPtr &kernel_mod);
  57. kernel::KernelMod *MutableKernelMod() const;
  58. const kernel::KernelMod *kernel_mod() const;
  59. uint32_t stream_id() const { return stream_id_; }
  60. void set_stream_id(uint32_t stream_id) { stream_id_ = stream_id; }
  61. uint32_t stream_distinction_label() const { return stream_distinction_label_; }
  62. void set_stream_distinction_label(uint32_t stream_distinction_label) {
  63. stream_distinction_label_ = stream_distinction_label;
  64. }
  65. void set_graph_id(uint32_t graph_id) { graph_id_ = graph_id; }
  66. uint32_t graph_id() const { return graph_id_; }
  67. bool operator==(const KernelInfo &other) const;
  68. bool is_feature_map() const { return is_feature_map_; }
  69. const std::vector<std::shared_ptr<DeviceAddress>> &output_address_list() const { return output_address_list_; }
  70. const std::vector<std::shared_ptr<DeviceAddress>> &workspace_address_list() const { return workspace_address_list_; }
  71. void set_ref_map(const OutputInputRefMap &ref_map) { out_in_ref_map_ = ref_map; }
  72. const OutputInputRefMap &out_in_ref_map() const { return out_in_ref_map_; }
  73. private:
  74. bool is_feature_map_;
  75. kernel::KernelBuildInfoPtr select_kernel_build_info_;
  76. std::vector<std::shared_ptr<DeviceAddress>> output_address_list_;
  77. std::vector<std::shared_ptr<DeviceAddress>> workspace_address_list_;
  78. kernel::KernelModPtr kernel_mod_;
  79. // stream_id_ is the index of stream object vector
  80. uint32_t stream_id_;
  81. // stream_distinction_label_ is used mark different op in different stream
  82. uint32_t stream_distinction_label_;
  83. // record which graph the node belong to
  84. uint32_t graph_id_;
  85. // The map between kernel's output and input ref relationship.
  86. OutputInputRefMap out_in_ref_map_;
  87. };
  88. } // namespace device
  89. } // namespace mindspore
  90. #endif // MINDSPORE_DEVICE_KERNEL_INFO_H_