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_set.cc 2.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/rts/label_set.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::LabelSetTaskInfo;
  24. using LabelSetTaskInfoPtr = std::shared_ptr<LabelSetTaskInfo>;
  25. namespace mindspore {
  26. namespace kernel {
  27. LabelSetKernel::LabelSetKernel() { label_ = 0; }
  28. LabelSetKernel::~LabelSetKernel() {}
  29. bool LabelSetKernel::Init(const AnfNodePtr &anf_node) {
  30. MS_EXCEPTION_IF_NULL(anf_node);
  31. MS_LOG(INFO) << "LabelSetKernel init";
  32. auto cnode = anf_node->cast<CNodePtr>();
  33. if (!AnfAlgo::HasNodeAttr(kAttrLabelIndex, cnode)) {
  34. MS_LOG(EXCEPTION) << "LabelSetKernel has no attr label_index";
  35. }
  36. auto primitive = AnfAlgo::GetCNodePrimitive(anf_node);
  37. MS_EXCEPTION_IF_NULL(primitive);
  38. label_ = GetValue<uint32_t>(primitive->GetAttr(kAttrLabelIndex));
  39. MS_LOG(INFO) << "LabelSetKernel get attr label:" << label_;
  40. return true;
  41. }
  42. bool LabelSetKernel::Launch(const std::vector<AddressPtr> & /*inputs*/, const std::vector<AddressPtr> & /*workspace*/,
  43. const std::vector<AddressPtr> & /*outputs*/, void * /*stream_ptr*/) {
  44. MS_LOG(INFO) << "LabelSetKernel launch";
  45. return true;
  46. }
  47. std::vector<TaskInfoPtr> LabelSetKernel::GenTask(const std::vector<AddressPtr> &, const std::vector<AddressPtr> &,
  48. const std::vector<AddressPtr> &, uint32_t stream_id) {
  49. MS_LOG(INFO) << "LabelSetKernel GenTask label:" << label_ << ", stream id:" << stream_id;
  50. std::vector<TaskInfoPtr> task_info_list;
  51. std::shared_ptr<LabelSetTaskInfo> task_info_ptr = std::make_shared<LabelSetTaskInfo>(stream_id, label_);
  52. MS_EXCEPTION_IF_NULL(task_info_ptr);
  53. task_info_list.emplace_back(task_info_ptr);
  54. return task_info_list;
  55. }
  56. } // namespace kernel
  57. } // namespace mindspore