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