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("[MC2GlobalMirrorTasks][%s] deviceId[%u], dieId[%u], missionId[%u], instrId[%u], executeId[%llu]", __func__,
50 : devLogicId, static_cast<u32>(ccuPara.dieId), static_cast<u32>(ccuPara.missionId), ccuPara.instrId, ccuPara.executeId);
51 : }
52 :
53 12 : shared_ptr<TaskInfo> MC2GlobalMirrorTasks::GetTaskInfo(u32 devLogicId, u8 dieId, u8 missionId, u32 instrId) const
54 : {
55 12 : if (devLogicId >= DEVICE_MAX_NUM) {
56 3 : HCCL_ERROR("MC2GlobalMirrorTasks::GetTaskInfo devId[%u] out of range", devLogicId);
57 1 : return nullptr;
58 : }
59 13 : for (const auto& taskInfoPtr : taskQueues_[devLogicId]) {
60 6 : const auto& ccuPara = taskInfoPtr->taskParam_.taskPara.Ccu;
61 6 : if (ccuPara.dieId == dieId && ccuPara.missionId == missionId && ccuPara.instrId == instrId) {
62 4 : return taskInfoPtr;
63 : }
64 : }
65 7 : return nullptr;
66 : }
67 :
68 : } // namespace Hccl
|