Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "mc2_global_mirror_tasks.h"
12 : #include "internal_exception.h"
13 : #include "exception_util.h"
14 :
15 : namespace Hccl {
16 :
17 : using namespace std;
18 :
19 40 : MC2GlobalMirrorTasks& MC2GlobalMirrorTasks::GetInstance()
20 : {
21 40 : static MC2GlobalMirrorTasks instance;
22 40 : return instance;
23 : }
24 :
25 26 : void MC2GlobalMirrorTasks::Clear()
26 : {
27 858 : for (uint32_t i = 0; i < DEVICE_MAX_NUM; ++i) {
28 832 : taskQueues_[i].clear();
29 : }
30 26 : }
31 :
32 8 : void MC2GlobalMirrorTasks::AddTaskInfo(u32 devLogicId, shared_ptr<TaskInfo> taskInfo)
33 : {
34 8 : if (devLogicId >= DEVICE_MAX_NUM) {
35 2 : THROW<InternalException>(StringFormat("MC2GlobalMirrorTasks::AddTaskInfo devId[%u] out of range", devLogicId));
36 : }
37 :
38 7 : if (taskInfo == nullptr) {
39 2 : THROW<InternalException>(StringFormat("MC2GlobalMirrorTasks::AddTaskInfo taskInfo is nullptr"));
40 : }
41 :
42 6 : const auto& ccuPara = taskInfo->taskParam_.taskPara.Ccu;
43 6 : if (GetTaskInfo(devLogicId, ccuPara.dieId, ccuPara.missionId, ccuPara.instrId) != nullptr) {
44 0 : return;
45 : }
46 :
47 6 : taskQueues_[devLogicId].push_back(taskInfo);
48 :
49 18 : HCCL_INFO(
50 : "[MC2GlobalMirrorTasks][%s] deviceId[%u], dieId[%u], missionId[%u], instrId[%u], executeId[%llu]", __func__,
51 : devLogicId, static_cast<u32>(ccuPara.dieId), static_cast<u32>(ccuPara.missionId), ccuPara.instrId,
52 : ccuPara.executeId);
53 : }
54 :
55 12 : shared_ptr<TaskInfo> MC2GlobalMirrorTasks::GetTaskInfo(u32 devLogicId, u8 dieId, u8 missionId, u32 instrId) const
56 : {
57 12 : if (devLogicId >= DEVICE_MAX_NUM) {
58 3 : HCCL_ERROR("MC2GlobalMirrorTasks::GetTaskInfo devId[%u] out of range", devLogicId);
59 1 : return nullptr;
60 : }
61 13 : for (const auto& taskInfoPtr : taskQueues_[devLogicId]) {
62 6 : const auto& ccuPara = taskInfoPtr->taskParam_.taskPara.Ccu;
63 6 : if (ccuPara.dieId == dieId && ccuPara.missionId == missionId && ccuPara.instrId == instrId) {
64 4 : return taskInfoPtr;
65 : }
66 : }
67 7 : return nullptr;
68 : }
69 :
70 : } // namespace Hccl
|