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

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