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/memcpy_async_task.h"
18 #include "runtime/mem.h"
19 #include "runtime/device/ascend/ge_runtime/task/task_factory.h"
20
21 namespace mindspore::ge::model_runner {
MemcpyAsyncTask(const ModelContext & model_context,const std::shared_ptr<MemcpyAsyncTaskInfo> & task_info)22 MemcpyAsyncTask::MemcpyAsyncTask(const ModelContext &model_context,
23 const std::shared_ptr<MemcpyAsyncTaskInfo> &task_info)
24 : TaskRepeater<MemcpyAsyncTaskInfo>(model_context, task_info), task_info_(task_info), stream_(nullptr) {
25 MS_EXCEPTION_IF_NULL(task_info);
26 auto stream_list = model_context.stream_list();
27 uint32_t stream_id = task_info->stream_id();
28
29 MS_LOG(INFO) << "Stream list size: " << stream_list.size() << ", stream id: " << stream_id;
30 if (stream_id >= stream_list.size()) {
31 MS_LOG(EXCEPTION) << "Index: " << task_info->stream_id() << " >= stream_list.size(): " << stream_list.size();
32 }
33 stream_ = stream_list[stream_id];
34 }
35
~MemcpyAsyncTask()36 MemcpyAsyncTask::~MemcpyAsyncTask() {}
37
Distribute()38 void MemcpyAsyncTask::Distribute() {
39 MS_LOG(INFO) << "MemcpyAsyncTask Distribute start.";
40 MS_LOG(INFO) << "dst_max: " << task_info_->dst_max() << ", count: " << task_info_->count()
41 << ", kind: " << task_info_->kind();
42 rtError_t rt_ret = rtMemcpyAsync(task_info_->dst(), task_info_->dst_max(), task_info_->src(), task_info_->count(),
43 static_cast<rtMemcpyKind_t>(task_info_->kind()), stream_);
44 if (rt_ret != RT_ERROR_NONE) {
45 MS_LOG(EXCEPTION) << "Call rt api rtMemcpyAsync failed, ret: " << rt_ret;
46 }
47 MS_LOG(INFO) << "DistributeTask end";
48 }
49
50 REGISTER_TASK(TaskInfoType::MEMCPY_ASYNC, MemcpyAsyncTask, MemcpyAsyncTaskInfo);
51 } // namespace mindspore::ge::model_runner
52