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.

label_switch.cc 3.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "kernel/mng/label_switch.h"
  17. #include <asm-generic/param.h>
  18. #include <memory>
  19. #include "runtime/stream.h"
  20. #include "framework/ge_runtime/task_info.h"
  21. #include "session/anf_runtime_algorithm.h"
  22. #include "common/utils.h"
  23. using ge::model_runner::LabelSwitchTaskInfo;
  24. using LabelSwitchTaskInfoPtr = std::shared_ptr<LabelSwitchTaskInfo>;
  25. namespace mindspore {
  26. namespace kernel {
  27. LabelSwitchKernel::LabelSwitchKernel() {
  28. label_list_ = {};
  29. cond_ = nullptr;
  30. label_size_ = 0;
  31. }
  32. LabelSwitchKernel::~LabelSwitchKernel() {}
  33. bool LabelSwitchKernel::Init(const AnfNodePtr &anf_node) {
  34. MS_EXCEPTION_IF_NULL(anf_node);
  35. MS_LOG(INFO) << "LabelSwitchKernel init";
  36. auto cnode = anf_node->cast<CNodePtr>();
  37. if (!AnfAlgo::HasNodeAttr(kAttrLabelSwitchList, cnode)) {
  38. MS_LOG(EXCEPTION) << "LabelSwitchKernel has no attr label_switch_list";
  39. }
  40. auto primitive = AnfAlgo::GetCNodePrimitive(anf_node);
  41. MS_EXCEPTION_IF_NULL(primitive);
  42. label_list_ = GetValue<std::vector<uint32_t>>(primitive->GetAttr(kAttrLabelSwitchList));
  43. label_size_ = label_list_.size();
  44. MS_LOG(INFO) << "LabelSwitchKernel get attr label size:" << label_size_;
  45. for (auto label : label_list_) {
  46. MS_LOG(INFO) << "label: " << label;
  47. }
  48. return true;
  49. }
  50. bool LabelSwitchKernel::Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
  51. const std::vector<AddressPtr> &outputs, uintptr_t stream_ptr) {
  52. MS_LOG(INFO) << "LabelSwitchKernel launch";
  53. return true;
  54. }
  55. std::vector<TaskInfoPtr> LabelSwitchKernel::GenTask(const std::vector<AddressPtr> &inputs,
  56. const std::vector<AddressPtr> &workspace,
  57. const std::vector<AddressPtr> &outputs, uint32_t stream_id) {
  58. MS_LOG(INFO) << "LabelSwitchKernel GenTask label size:" << label_size_ << ", stream id:" << stream_id;
  59. std::vector<TaskInfoPtr> task_info_list;
  60. cond_ = inputs[0]->addr;
  61. // std::shared_ptr<LabelSwitchTaskInfo> task_info_ptr =
  62. // std::make_shared<LabelSwitchTaskInfo>(stream_id, label_size_, &label_list_, cond_);
  63. // need updata ge task info define
  64. std::shared_ptr<LabelSwitchTaskInfo> task_info_ptr = std::make_shared<LabelSwitchTaskInfo>(stream_id, label_size_);
  65. MS_EXCEPTION_IF_NULL(task_info_ptr);
  66. task_info_list.emplace_back(task_info_ptr);
  67. return task_info_list;
  68. }
  69. } // namespace kernel
  70. } // namespace mindspore