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.

recv.cc 2.5 kB

5 years ago
4 years ago
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 "backend/kernel_compiler/rts/recv.h"
  17. #include "runtime/stream.h"
  18. #include "utils/ms_context.h"
  19. #include "runtime/device/ascend/ge_runtime/task_info.h"
  20. #include "backend/session/anf_runtime_algorithm.h"
  21. namespace mindspore {
  22. namespace kernel {
  23. using mindspore::ge::model_runner::EventWaitTaskInfo;
  24. using EventWaitTaskInfoPtr = std::shared_ptr<EventWaitTaskInfo>;
  25. RecvKernel::RecvKernel() { event_id_ = 0; }
  26. RecvKernel::~RecvKernel() {}
  27. bool RecvKernel::Init(const AnfNodePtr &anf_node) {
  28. MS_EXCEPTION_IF_NULL(anf_node);
  29. auto primitive = AnfAlgo::GetCNodePrimitive(anf_node);
  30. MS_EXCEPTION_IF_NULL(primitive);
  31. if (!AnfAlgo::HasNodeAttr(kAttrEventId, anf_node->cast<CNodePtr>())) {
  32. MS_LOG(EXCEPTION) << "RecvKernel has no attr kAttrEventId";
  33. }
  34. event_id_ = GetValue<uint32_t>(primitive->GetAttr(kAttrEventId));
  35. MS_LOG(INFO) << "recv op event_id_:" << event_id_;
  36. return true;
  37. }
  38. bool RecvKernel::Launch(const std::vector<AddressPtr> &, const std::vector<AddressPtr> &,
  39. const std::vector<AddressPtr> &, void *stream_ptr) {
  40. rtEvent_t stream_event{};
  41. auto status = rtStreamWaitEvent(stream_ptr, stream_event);
  42. if (status != RT_ERROR_NONE) {
  43. MS_LOG(ERROR) << "Recv rtStreamWaitEvent failed!";
  44. return false;
  45. }
  46. return true;
  47. }
  48. std::vector<TaskInfoPtr> RecvKernel::GenTask(const std::vector<AddressPtr> &, const std::vector<AddressPtr> &,
  49. const std::vector<AddressPtr> &, uint32_t stream_id) {
  50. MS_LOG(INFO) << "RecvKernel GenTask event_id_:" << event_id_ << ", stream_id_:" << stream_id;
  51. stream_id_ = stream_id;
  52. EventWaitTaskInfoPtr task_info_ptr = std::make_shared<EventWaitTaskInfo>(unique_name_, stream_id, event_id_);
  53. MS_EXCEPTION_IF_NULL(task_info_ptr);
  54. return {task_info_ptr};
  55. }
  56. } // namespace kernel
  57. } // namespace mindspore