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.3 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 0~" << (output_address_list_.size() - 1);
  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 (kernel_mod_ != nullptr && 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::WorkspaceAddrExist(size_t index) const {
  75. if (index >= workspace_address_list_.size()) {
  76. return false;
  77. }
  78. return workspace_address_list_[index] != nullptr;
  79. }
  80. bool KernelInfo::SetWorkspaceAddr(const DeviceAddressPtr &output_address, size_t index) {
  81. if (workspace_address_list_.empty()) {
  82. // parameter and valuenode
  83. if (kernel_mod_ == nullptr) {
  84. workspace_address_list_.emplace_back(nullptr);
  85. } else {
  86. // set cnode
  87. for (size_t i = 0; i < kernel_mod_->GetWorkspaceSizeList().size(); i++) {
  88. workspace_address_list_.emplace_back(nullptr);
  89. }
  90. }
  91. }
  92. if (index >= workspace_address_list_.size()) {
  93. MS_LOG(ERROR) << "Index [" << index << "] out of range";
  94. return false;
  95. }
  96. workspace_address_list_[index] = output_address;
  97. return true;
  98. }
  99. void KernelInfo::set_kernel_mod(const kernel::KernelModPtr &kernel_mod) { kernel_mod_ = kernel_mod; }
  100. kernel::KernelMod *KernelInfo::MutableKernelMod() const { return kernel_mod_.get(); }
  101. const kernel::KernelMod *KernelInfo::kernel_mod() const { return kernel_mod_.get(); }
  102. bool KernelInfo::operator==(const KernelInfo &other) const {
  103. if (stream_id_ != other.stream_id_ || stream_distinction_label_ != other.stream_distinction_label_ ||
  104. graph_id_ != other.graph_id_) {
  105. return false;
  106. }
  107. if ((select_kernel_build_info_ != nullptr && other.select_kernel_build_info_ == nullptr) ||
  108. (select_kernel_build_info_ == nullptr && other.select_kernel_build_info_ != nullptr)) {
  109. return false;
  110. }
  111. if (select_kernel_build_info_ != nullptr && other.select_kernel_build_info_ != nullptr) {
  112. if (!(*select_kernel_build_info_ == *(other.select_kernel_build_info_))) {
  113. return false;
  114. }
  115. }
  116. // Currently we only check whether both the kernel_mod_ are initialized or uninitialized.
  117. if ((kernel_mod_ == nullptr && other.kernel_mod_ != nullptr) ||
  118. (kernel_mod_ != nullptr && other.kernel_mod_ == nullptr)) {
  119. return false;
  120. }
  121. // Currently we only check whether both the sizes are equal of output_address_list_ and workspace_address_list_ or
  122. // not. We can complete this check in the future.
  123. if (output_address_list_.size() != other.output_address_list_.size() ||
  124. workspace_address_list_.size() != other.workspace_address_list_.size()) {
  125. return false;
  126. }
  127. return true;
  128. }
  129. } // namespace device
  130. } // namespace mindspore