• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_record_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 {
EventRecordTask(const ModelContext & model_context,const std::shared_ptr<EventRecordTaskInfo> & task_info)22 EventRecordTask::EventRecordTask(const ModelContext &model_context,
23                                  const std::shared_ptr<EventRecordTaskInfo> &task_info)
24     : TaskRepeater<EventRecordTaskInfo>(model_context, task_info),
25       task_info_(task_info),
26       stream_(nullptr),
27       event_(nullptr) {
28   MS_EXCEPTION_IF_NULL(task_info_);
29   auto stream_list = model_context.stream_list();
30   auto event_list = model_context.event_list();
31   uint32_t stream_id = task_info_->stream_id();
32   uint32_t event_id = task_info_->event_id();
33   if (stream_id >= stream_list.size() || event_id >= event_list.size()) {
34     MS_LOG(EXCEPTION) << "stream_list size: " << stream_list.size() << ", stream_id: " << stream_id
35                       << ", event_list size: " << event_list.size() << ", event_id: " << event_id;
36   }
37   stream_ = stream_list[stream_id];
38   event_ = event_list[event_id];
39 }
40 
~EventRecordTask()41 EventRecordTask::~EventRecordTask() {}
42 
Distribute()43 void EventRecordTask::Distribute() {
44   MS_LOG(INFO) << "EventRecordTask Distribute start, stream: " << stream_ << ", event: " << event_
45                << ", stream_id: " << task_info_->stream_id() << ", event_id: " << task_info_->event_id();
46   rtError_t rt_ret = rtEventRecord(event_, stream_);
47   if (rt_ret != RT_ERROR_NONE) {
48     MS_LOG(EXCEPTION) << "Call rt api rtEventRecord failed, ret: " << rt_ret;
49   }
50   MS_LOG(INFO) << "Distribute end.";
51 }
52 
53 REGISTER_TASK(TaskInfoType::EVENT_RECORD, EventRecordTask, EventRecordTaskInfo);
54 }  // namespace mindspore::ge::model_runner
55