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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "backend/kernel_compiler/kernel_build_info.h"
  22. #include "runtime/device/ascend/ascend_device_address.h"
  23. #include "backend/kernel_compiler/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. private:
  72. bool is_feature_map_;
  73. kernel::KernelBuildInfoPtr select_kernel_build_info_;
  74. std::vector<std::shared_ptr<DeviceAddress>> output_address_list_;
  75. std::vector<std::shared_ptr<DeviceAddress>> workspace_address_list_;
  76. kernel::KernelModPtr kernel_mod_;
  77. // stream_id_ is the index of stream object vector
  78. uint32_t stream_id_;
  79. // stream_distinction_label_ is used mark different op in different stream
  80. uint32_t stream_distinction_label_;
  81. // record which graph the node belong to
  82. uint32_t graph_id_;
  83. };
  84. } // namespace device
  85. } // namespace mindspore
  86. #endif // MINDSPORE_DEVICE_KERNEL_INFO_H_