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