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 : #include "coll_comm_aicpu_destroy_func.h"
11 : #include "aicpu_indop_process.h"
12 : #include <shared_mutex>
13 : #include "kernel_entrance.h"
14 :
15 : namespace hccl {
16 4 : CollCommAicpuDestroyFunc &CollCommAicpuDestroyFunc::GetInstance()
17 : {
18 4 : static CollCommAicpuDestroyFunc func;
19 4 : return func;
20 : }
21 :
22 3 : void CollCommAicpuDestroyFunc::Call()
23 : {
24 3 : if (stopCall_ == true) {
25 1 : return;
26 : }
27 :
28 2 : HcclResult ret = Process();
29 2 : if (ret != HCCL_SUCCESS) {
30 0 : stopCall_ = true;
31 0 : HCCL_ERROR("[%s]Process fail, set stopCall_[%d] ret[%d]", __func__, stopCall_, ret);
32 : }
33 : }
34 :
35 3 : HcclResult CollCommAicpuDestroyFunc::Process()
36 : {
37 3 : std::vector<std::string> destroyComm;
38 : {
39 3 : std::shared_lock<std::shared_mutex> rwlock(AicpuIndopProcess::AicpuGetCommMutex());
40 :
41 3 : std::vector<std::pair<std::string, CollCommAicpuMgr *>> aicpuCommInfo;
42 3 : CHK_RET(AicpuIndopProcess::AicpuGetCommAll(aicpuCommInfo));
43 :
44 5 : for (auto &commInfo : aicpuCommInfo) {
45 2 : CollCommAicpu *aicpuComm = commInfo.second->GetCollCommAicpu();
46 2 : CHK_PTR_NULL(aicpuComm);
47 :
48 2 : if (aicpuComm->GetCommmStatus() == HcclCommStatus::HCCL_COMM_STATUS_INVALID) {
49 2 : continue;
50 : }
51 :
52 0 : Hccl::KfcCommand cmd = Hccl::KfcCommand::NONE;
53 0 : CHK_RET(aicpuComm->BackGroundGetCmd(cmd));
54 0 : if (cmd != Hccl::KfcCommand::DESTROY_AICPU_COMM) {
55 0 : continue;
56 : }
57 0 : destroyComm.push_back(aicpuComm->GetIdentifier());
58 0 : CHK_RET(aicpuComm->BackGroundSetStatus(Hccl::KfcStatus::DESTROY_AICPU_COMM_DONE));
59 :
60 : {
61 0 : std::lock_guard<std::mutex> lock(g_taskExpDevMemMapMutex);
62 0 : auto it = g_taskExpDevMemMap.find(aicpuComm->GetIdentifier());
63 0 : if (it != g_taskExpDevMemMap.end()) {
64 0 : g_taskExpDevMemMap.erase(aicpuComm->GetIdentifier()); // 清理dpu taskexception共享内存
65 : }
66 0 : }
67 :
68 0 : HCCL_RUN_INFO("[%s]group[%s] Recv DESTROY_AICPU_COMM cmd and set DESTROY_AICPU_COMM_DONE",
69 : __func__, aicpuComm->GetIdentifier().c_str());
70 : }
71 3 : }
72 :
73 3 : for (std::string& groupName : destroyComm) {
74 0 : (void)(AicpuIndopProcess::AicpuDestroyCommbyGroup(groupName));
75 : }
76 3 : return HCCL_SUCCESS;
77 3 : }
78 : } // namespace hccl
|