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 : #ifndef HCCLV2_HCCP_HDC_MANAGER_H
12 : #define HCCLV2_HCCP_HDC_MANAGER_H
13 : #include <set>
14 : #include <mutex>
15 : #include <atomic>
16 : #include "orion_adapter_hccp.h"
17 : namespace Hccl {
18 : class HccpHdcManager {
19 : public:
20 : static HccpHdcManager &GetInstance();
21 : void Init(u32 deviceLogicId);
22 : void DeInit(u32 deviceLogicId);
23 : HccpHdcManager(const HccpHdcManager &hccpHdcManager) = delete;
24 : HccpHdcManager &operator=(const HccpHdcManager &hccpHdcManager) = delete;
25 : // 测试使用,待修改: 添加编译宏,仅在单元测试时提供此接口
26 4 : std::set<u32> GetSet()
27 : {
28 4 : return instances;
29 : }
30 : ~HccpHdcManager();
31 :
32 : private:
33 : std::set<u32> instances; // key: deviceLogicId
34 : std::recursive_mutex managerMutex;
35 : std::atomic<bool> destroyed{false};
36 3 : HccpHdcManager() = default;
37 : void DestroyAll();
38 : void UnregisterDeviceResetCallback() const;
39 : };
40 : } // namespace Hccl
41 : #endif // HCCLV2_HCCP_HDC_MANAGER_H
|