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 "ccu_driver_handle.h"
12 : #include "hccp_tlv_hdc_manager.h"
13 : #include "hccp_tlv.h"
14 :
15 : #include "ccu_context_mgr_imp.h"
16 : #include "ccu_res_batch_allocator_legacy.h"
17 : #include "ccu_component.h"
18 : #include "ccu_res_specs_legacy.h"
19 :
20 : namespace Hccl {
21 :
22 2 : CcuDriverHandle::CcuDriverHandle(s32 deviceLogicId) : devLogicId(deviceLogicId) {}
23 :
24 2 : CcuDriverHandle::~CcuDriverHandle()
25 : {
26 6 : HCCL_RUN_INFO("Start destorying CCU, deviceLogicId: %d", devLogicId);
27 :
28 6 : HCCL_INFO("Start destorying CCU, deviceLogicId: %d", devLogicId);
29 :
30 2 : DECTOR_TRY_CATCH("CcuDriverHandle", {
31 : // 清理ccu平台层持有的资源与缓存信息
32 : CtxMgrImp::GetInstance(devLogicId).Deinit();
33 : CcuResBatchAllocator::GetInstance(devLogicId).Deinit();
34 : CcuComponent::GetInstance(devLogicId).Deinit();
35 : CcuResSpecifications::GetInstance(devLogicId).Deinit();
36 : // 关闭ccu驱动通道
37 : auto tlvHandle = HccpTlvHdcManager::GetInstance().GetTlvHandle(devLogicId);
38 : HrtRaTlvRequest(tlvHandle, TLV_MODULE_TYPE_CCU, MSG_TYPE_CCU_UNINIT);
39 : });
40 :
41 6 : HCCL_INFO("Destory CCU success, deviceLogicId: %d", devLogicId);
42 2 : }
43 :
44 0 : HcclResult CcuDriverHandle::Init() const
45 : {
46 0 : HCCL_RUN_INFO("Start initiating CCU, deviceLogicId: %d", devLogicId);
47 :
48 0 : auto tlvHandle = HccpTlvHdcManager::GetInstance().GetTlvHandle(devLogicId);
49 0 : if (HrtRaTlvRequest(tlvHandle, TLV_MODULE_TYPE_CCU, MSG_TYPE_CCU_INIT) == HCCL_E_UNAVAIL) {
50 0 : return HCCL_E_UNAVAIL;
51 : }
52 :
53 0 : CcuResSpecifications::GetInstance(devLogicId).Init();
54 0 : CcuComponent::GetInstance(devLogicId).Init();
55 0 : CcuResBatchAllocator::GetInstance(devLogicId).Init();
56 0 : CtxMgrImp::GetInstance(devLogicId).Init();
57 :
58 0 : HCCL_INFO("Init CCU success, deviceLogicId: %d", devLogicId);
59 0 : return HcclResult::HCCL_SUCCESS;
60 : }
61 :
62 : } // namespace Hccl
|