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.cc 5.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "runtime/device/kernel_info.h"
  17. namespace mindspore {
  18. namespace device {
  19. const kernel::KernelBuildInfo *KernelInfo::select_kernel_build_info() const { return select_kernel_build_info_.get(); }
  20. kernel::KernelBuildInfoPtr KernelInfo::GetMutableSelectKernelBuildInfo() const { return select_kernel_build_info_; }
  21. const DeviceAddress *KernelInfo::GetOutputAddr(size_t index) const {
  22. if (index >= output_address_list_.size()) {
  23. MS_LOG(ERROR) << "Index [" << index << "] out of range";
  24. return nullptr;
  25. }
  26. return output_address_list_[index].get();
  27. }
  28. DeviceAddressPtr KernelInfo::GetMutableOutputAddr(size_t index) const {
  29. if (index >= output_address_list_.size()) {
  30. MS_LOG(ERROR) << "Index [" << index << "] out of range";
  31. return nullptr;
  32. }
  33. return output_address_list_[index];
  34. }
  35. bool KernelInfo::OutputAddrExist(size_t index) const {
  36. if (index >= output_address_list_.size()) {
  37. return false;
  38. }
  39. return output_address_list_[index] != nullptr;
  40. }
  41. bool KernelInfo::SetOutputAddr(const DeviceAddressPtr &output_address, size_t index) {
  42. // parameter and valuenode
  43. if (kernel_mod_ == nullptr && index >= output_address_list_.size()) {
  44. for (size_t i = output_address_list_.size(); i <= index; i++) {
  45. output_address_list_.emplace_back(nullptr);
  46. }
  47. } else if (output_address_list_.empty()) {
  48. // set cnode
  49. for (size_t i = 0; i < kernel_mod_->GetOutputSizeList().size(); i++) {
  50. output_address_list_.emplace_back(nullptr);
  51. }
  52. }
  53. if (index >= output_address_list_.size()) {
  54. MS_LOG(ERROR) << "Index [" << index << "] out of range";
  55. return false;
  56. }
  57. output_address_list_[index] = output_address;
  58. return true;
  59. }
  60. DeviceAddress *KernelInfo::GetWorkspaceAddr(size_t index) const {
  61. if (index >= workspace_address_list_.size()) {
  62. MS_LOG(ERROR) << "Index [" << index << "] out of range";
  63. return nullptr;
  64. }
  65. return workspace_address_list_[index].get();
  66. }
  67. DeviceAddressPtr KernelInfo::GetMutableWorkspaceAddr(size_t index) const {
  68. if (index >= workspace_address_list_.size()) {
  69. MS_LOG(ERROR) << "Index [" << index << "] out of range";
  70. return nullptr;
  71. }
  72. return workspace_address_list_[index];
  73. }
  74. bool KernelInfo::SetWorkspaceAddr(const DeviceAddressPtr &output_address, size_t index) {
  75. if (workspace_address_list_.empty()) {
  76. // parameter and valuenode
  77. if (kernel_mod_ == nullptr) {
  78. workspace_address_list_.emplace_back(nullptr);
  79. } else {
  80. // set cnode
  81. for (size_t i = 0; i < kernel_mod_->GetWorkspaceSizeList().size(); i++) {
  82. workspace_address_list_.emplace_back(nullptr);
  83. }
  84. }
  85. }
  86. if (index >= workspace_address_list_.size()) {
  87. MS_LOG(ERROR) << "Index" << index << " out of range";
  88. return false;
  89. }
  90. workspace_address_list_[index] = output_address;
  91. return true;
  92. }
  93. void KernelInfo::set_kernel_mod(const kernel::KernelModPtr &kernel_mod) { kernel_mod_ = kernel_mod; }
  94. kernel::KernelMod *KernelInfo::MutableKernelMod() const { return kernel_mod_.get(); }
  95. const kernel::KernelMod *KernelInfo::kernel_mod() const { return kernel_mod_.get(); }
  96. bool KernelInfo::operator==(const KernelInfo &other) const {
  97. if (stream_id_ != other.stream_id_ || stream_distinction_label_ != other.stream_distinction_label_ ||
  98. graph_id_ != other.graph_id_) {
  99. return false;
  100. }
  101. if ((select_kernel_build_info_ != nullptr && other.select_kernel_build_info_ == nullptr) ||
  102. (select_kernel_build_info_ == nullptr && other.select_kernel_build_info_ != nullptr)) {
  103. return false;
  104. }
  105. if (select_kernel_build_info_ != nullptr && other.select_kernel_build_info_ != nullptr) {
  106. if (!(*select_kernel_build_info_ == *(other.select_kernel_build_info_))) {
  107. return false;
  108. }
  109. }
  110. // Currently we only check whether both the kernel_mod_ are initialized or uninitialized.
  111. if ((kernel_mod_ == nullptr && other.kernel_mod_ != nullptr) ||
  112. (kernel_mod_ != nullptr && other.kernel_mod_ == nullptr)) {
  113. return false;
  114. }
  115. // Currently we only check whether both the sizes are equal of output_address_list_ and workspace_address_list_ or
  116. // not. We can complete this check in the future.
  117. if (output_address_list_.size() != other.output_address_list_.size() ||
  118. workspace_address_list_.size() != other.workspace_address_list_.size()) {
  119. return false;
  120. }
  121. return true;
  122. }
  123. } // namespace device
  124. } // namespace mindspore