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/stream_active_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 {
StreamActiveTask(const ModelContext & model_context,const std::shared_ptr<StreamActiveTaskInfo> & task_info)22 StreamActiveTask::StreamActiveTask(const ModelContext &model_context,
23 const std::shared_ptr<StreamActiveTaskInfo> &task_info)
24 : TaskRepeater<StreamActiveTaskInfo>(model_context, task_info),
25 task_info_(task_info),
26 stream_(nullptr),
27 active_stream_(nullptr) {
28 MS_EXCEPTION_IF_NULL(task_info);
29 auto stream_list = model_context.stream_list();
30 uint32_t stream_id = task_info->stream_id();
31 uint32_t active_stream_id = task_info->active_stream_id();
32 MS_LOG(INFO) << "Stream list size: " << stream_list.size() << ", stream id: " << stream_id
33 << ", active stream id: " << active_stream_id;
34 if (stream_id >= stream_list.size() || active_stream_id >= stream_list.size()) {
35 MS_LOG(EXCEPTION) << "Stream id invalid";
36 }
37 stream_ = stream_list[stream_id];
38 active_stream_ = stream_list[active_stream_id];
39 }
40
~StreamActiveTask()41 StreamActiveTask::~StreamActiveTask() {}
42
Distribute()43 void StreamActiveTask::Distribute() {
44 MS_LOG(INFO) << "Distribute start";
45 MS_LOG(INFO) << "Stream " << task_info_->stream_id() << " active " << task_info_->active_stream_id();
46 MS_EXCEPTION_IF_NULL(stream_);
47 MS_EXCEPTION_IF_NULL(active_stream_);
48 rtError_t rt_ret = rtStreamActive(active_stream_, stream_);
49 if (rt_ret != RT_ERROR_NONE) {
50 MS_LOG(EXCEPTION) << "Call rt api rtStreamActive failed, ret: " << rt_ret;
51 }
52 MS_LOG(INFO) << "DistributeTask end.";
53 }
54
55 REGISTER_TASK(TaskInfoType::STREAM_ACTIVE, StreamActiveTask, StreamActiveTaskInfo);
56 } // namespace mindspore::ge::model_runner
57