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
5 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/send.h"
  17. #include <memory>
  18. #include "runtime/event.h"
  19. #include "framework/ge_runtime/task_info.h"
  20. #include "backend/session/anf_runtime_algorithm.h"
  21. using ge::model_runner::EventRecordTaskInfo;
  22. using EventRecordTaskInfoPtr = std::shared_ptr<EventRecordTaskInfo>;
  23. namespace mindspore {
  24. namespace kernel {
  25. SendKernel::SendKernel() { event_id_ = 0; }
  26. SendKernel::~SendKernel() {}
  27. bool SendKernel::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) << "SendKernel has no attr kAttrEventId";
  33. }
  34. event_id_ = GetValue<uint32_t>(primitive->GetAttr(kAttrEventId));
  35. MS_LOG(INFO) << "send op event id:" << event_id_;
  36. return true;
  37. }
  38. bool SendKernel::Launch(const std::vector<AddressPtr> &inputs, const std::vector<AddressPtr> &workspace,
  39. const std::vector<AddressPtr> &outputs, void *stream_ptr) {
  40. rtEvent_t event{};
  41. rtError_t status = rtEventRecord(event, stream_ptr);
  42. if (status != RT_ERROR_NONE) {
  43. MS_LOG(ERROR) << "Send op rtEventRecord failed!";
  44. return false;
  45. }
  46. return true;
  47. }
  48. std::vector<TaskInfoPtr> SendKernel::GenTask(const std::vector<AddressPtr> &, const std::vector<AddressPtr> &,
  49. const std::vector<AddressPtr> &, uint32_t stream_id) {
  50. MS_LOG(INFO) << "SendKernel GenTask event id:" << event_id_ << ", stream id:" << stream_id;
  51. stream_id_ = stream_id;
  52. EventRecordTaskInfoPtr task_info_ptr = std::make_shared<EventRecordTaskInfo>(kernel_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