1 /**
2 * Copyright 2019-2020 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
17 #include "runtime/device/ascend/ge_runtime/task/event_wait_task.h"
18 #include "runtime/kernel.h"
19 #include "runtime/device/ascend/ge_runtime/task/task_factory.h"
20
21 namespace mindspore::ge::model_runner {
EventWaitTask(const ModelContext & model_context,const std::shared_ptr<EventWaitTaskInfo> & task_info)22 EventWaitTask::EventWaitTask(const ModelContext &model_context, const std::shared_ptr<EventWaitTaskInfo> &task_info)
23 : TaskRepeater<EventWaitTaskInfo>(model_context, task_info),
24 task_info_(task_info),
25 stream_(nullptr),
26 event_(nullptr) {
27 MS_EXCEPTION_IF_NULL(task_info_);
28 auto stream_list = model_context.stream_list();
29 auto event_list = model_context.event_list();
30 uint32_t stream_id = task_info_->stream_id();
31 uint32_t event_id = task_info_->event_id();
32 if (stream_id >= stream_list.size() || event_id >= event_list.size()) {
33 MS_LOG(EXCEPTION) << "stream_list size: " << stream_list.size() << ", stream_id: " << stream_id
34 << ", event_list size: " << event_list.size() << ", event_id: " << event_id;
35 }
36 stream_ = stream_list[stream_id];
37 event_ = event_list[event_id];
38 }
39
~EventWaitTask()40 EventWaitTask::~EventWaitTask() {}
41
Distribute()42 void EventWaitTask::Distribute() {
43 MS_LOG(INFO) << "EventWaitTask Distribute start, stream: " << stream_ << ", event: " << event_
44 << ", stream_id: " << task_info_->stream_id() << ", event_id: " << task_info_->event_id();
45
46 rtError_t rt_ret = rtStreamWaitEvent(stream_, event_);
47 if (rt_ret != RT_ERROR_NONE) {
48 MS_LOG(EXCEPTION) << "Call rt api rtStreamWaitEvent failed, ret: " << rt_ret;
49 }
50
51 rt_ret = rtEventReset(event_, stream_);
52 if (rt_ret != RT_ERROR_NONE) {
53 MS_LOG(EXCEPTION) << "Call rt api rtEventReset failed, ret: " << rt_ret;
54 }
55 MS_LOG(INFO) << "Distribute end.";
56 }
57
58 REGISTER_TASK(TaskInfoType::EVENT_WAIT, EventWaitTask, EventWaitTaskInfo);
59 } // namespace mindspore::ge::model_runner
60