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.

send.cc 2.4 kB

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