• 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/label_switch_task.h"
18 #include "runtime/device/ascend/ge_runtime/task/task_factory.h"
19 
20 namespace mindspore::ge::model_runner {
LabelSwitchTask(const ModelContext & model_context,const std::shared_ptr<LabelSwitchTaskInfo> & task_info)21 LabelSwitchTask::LabelSwitchTask(const ModelContext &model_context,
22                                  const std::shared_ptr<LabelSwitchTaskInfo> &task_info)
23     : TaskRepeater<LabelSwitchTaskInfo>(model_context, task_info),
24       task_info_(task_info),
25       stream_(nullptr),
26       label_info_(nullptr) {
27   MS_EXCEPTION_IF_NULL(task_info);
28 
29   rt_model_handle_ = model_context.rt_model_handle();
30   auto all_label_resource = model_context.label_list();
31   auto stream_list = model_context.stream_list();
32   uint32_t stream_id = task_info->stream_id();
33   MS_LOG(INFO) << "Stream list size: " << stream_list.size() << ", stream id: " << stream_id;
34   if (stream_id >= stream_list.size()) {
35     MS_LOG(EXCEPTION) << "Stream id invalid.";
36   }
37   stream_ = stream_list[stream_id];
38   label_manager_ = LabelManager::GetInstance();
39   MS_EXCEPTION_IF_NULL(label_manager_);
40   label_info_ = label_manager_->GetLabelInfo(rt_model_handle_, task_info_->label_list(), all_label_resource);
41   MS_EXCEPTION_IF_NULL(label_info_);
42 }
43 
~LabelSwitchTask()44 LabelSwitchTask::~LabelSwitchTask() {}
45 
Distribute()46 void LabelSwitchTask::Distribute() {
47   MS_LOG(INFO) << "LabelSwitchTask Distribute start.";
48   CheckParamValid();
49 
50   void *label_info = label_info_->GetLabelInfo();
51   rtError_t rt_ret = rtLabelSwitchByIndex(task_info_->cond(), task_info_->label_size(), label_info, stream_);
52   if (rt_ret != RT_ERROR_NONE) {
53     MS_LOG(EXCEPTION) << "Call rt api rtLabelSwitchByIndex failed, ret: " << rt_ret;
54   }
55 
56   MS_LOG(INFO) << "DistributeTask end.";
57 }
58 
CheckParamValid()59 void LabelSwitchTask::CheckParamValid() {
60   MS_EXCEPTION_IF_NULL(stream_);
61 
62   if (task_info_->label_list().empty()) {
63     MS_LOG(EXCEPTION) << "label_list is empty.";
64   }
65 
66   if (task_info_->label_size() != task_info_->label_list().size()) {
67     MS_LOG(EXCEPTION) << "label_list size " << task_info_->label_list().size() << " but label_size is "
68                       << task_info_->label_size();
69   }
70 
71   if (task_info_->label_size() >= UINT32_MAX / sizeof(rtLabelDevInfo)) {
72     MS_LOG(EXCEPTION) << "label_size " << task_info_->label_size() << " will overflow.";
73   }
74 }
75 
76 REGISTER_TASK(TaskInfoType::LABEL_SWITCH, LabelSwitchTask, LabelSwitchTaskInfo);
77 }  // namespace mindspore::ge::model_runner
78