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 "coll_comm_aicpu_mgr.h"
12 : #include <shared_mutex>
13 : #include "kernel_entrance.h"
14 :
15 : namespace hccl {
16 7 : CollCommAicpuDestroyFunc& CollCommAicpuDestroyFunc::GetInstance()
17 : {
18 7 : static CollCommAicpuDestroyFunc func;
19 7 : 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(CollCommAicpuMgr::GetInstance().GetMutex());
40 :
41 3 : std::vector<std::pair<std::string, CollCommAicpu*>> aicpuCommInfo;
42 3 : CHK_RET(CollCommAicpuMgr::GetInstance().GetAllComms(aicpuCommInfo));
43 :
44 8 : for (auto& commInfo : aicpuCommInfo) {
45 5 : CollCommAicpu* aicpuComm = commInfo.second;
46 5 : CHK_PTR_NULL(aicpuComm);
47 :
48 5 : if (aicpuComm->GetCommmStatus() == HcclCommStatus::HCCL_COMM_STATUS_INVALID) {
49 5 : 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(
69 : "[%s]group[%s] Recv DESTROY_AICPU_COMM cmd and set DESTROY_AICPU_COMM_DONE", __func__,
70 : aicpuComm->GetIdentifier().c_str());
71 : }
72 3 : }
73 :
74 3 : for (std::string& groupName : destroyComm) {
75 0 : (void)(CollCommAicpuMgr::GetInstance().DestroyComm(groupName));
76 : }
77 3 : return HCCL_SUCCESS;
78 3 : }
79 : } // namespace hccl
|