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.3 kB

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