Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 HCOMM_CCU_RES_TYPE_CONVERTER_H
12 : #define HCOMM_CCU_RES_TYPE_CONVERTER_H
13 :
14 : #include <array>
15 : #include <cstddef>
16 :
17 : #include "ccu_res_defs.h"
18 : #include "ccu_types.h"
19 : #include "unified_platform/ccu/ccu_device/ccu_device_manager.h"
20 :
21 : namespace hcomm {
22 :
23 827 : inline CcuResult ConvertHcommCcuResTypeToHcclResType(HcommCcuResType ccuResType, ResType& hcclResType)
24 : {
25 : static constexpr auto RES_TYPE_MAP = std::array{
26 : ResType::LOOP, // <- HCOMM_CCU_RES_TYPE_LOOP
27 : ResType::MS, // <- HCOMM_CCU_RES_TYPE_CCU_BUF
28 : ResType::XN, // <- HCOMM_CCU_RES_TYPE_VARIABLE
29 : ResType::GSA, // <- HCOMM_CCU_RES_TYPE_ADDRESS
30 : ResType::CKE, // <- HCOMM_CCU_RES_TYPE_EVENT
31 : ResType::MISSION, // <- HCOMM_CCU_RES_TYPE_CCU_THREAD
32 : ResType::INS // <- HCOMM_CCU_RES_TYPE_INSTRUCTION
33 : };
34 827 : const int32_t resTypeIndex = static_cast<int32_t>(ccuResType);
35 1652 : if ((resTypeIndex < 0) || (static_cast<std::size_t>(resTypeIndex) >= RES_TYPE_MAP.size())) {
36 2 : return CcuResult::CCU_E_PARA;
37 : }
38 825 : hcclResType = RES_TYPE_MAP[static_cast<std::size_t>(resTypeIndex)];
39 825 : return CcuResult::CCU_SUCCESS;
40 : }
41 :
42 : inline CcuResult ConvertHcclResTypeToHcommCcuResType(ResType hcclResType, HcommCcuResType& ccuResType)
43 : {
44 : static constexpr std::array<HcommCcuResType, static_cast<std::size_t>(ResType::__COUNT__)> RES_TYPE_MAP = {
45 : HCOMM_CCU_RES_TYPE_LOOP, // <- ResType::LOOP
46 : HCOMM_CCU_RES_TYPE_CCU_BUF, // <- ResType::MS
47 : HCOMM_CCU_RES_TYPE_EVENT, // <- ResType::CKE
48 : HCOMM_CCU_RES_TYPE_VARIABLE, // <- ResType::XN
49 : HCOMM_CCU_RES_TYPE_INVALID, // <- ResType::COUNT_XN
50 : HCOMM_CCU_RES_TYPE_ADDRESS, // <- ResType::GSA
51 : HCOMM_CCU_RES_TYPE_INSTRUCTION, // <- ResType::INS
52 : HCOMM_CCU_RES_TYPE_CCU_THREAD // <- ResType::MISSION
53 : };
54 : const auto resTypeIndex = static_cast<std::size_t>(static_cast<ResType::Value>(hcclResType));
55 : if ((resTypeIndex >= RES_TYPE_MAP.size()) || (RES_TYPE_MAP[resTypeIndex] == HCOMM_CCU_RES_TYPE_INVALID)) {
56 : return CcuResult::CCU_E_PARA;
57 : }
58 : ccuResType = RES_TYPE_MAP[resTypeIndex];
59 : return CcuResult::CCU_SUCCESS;
60 : }
61 :
62 : } // namespace hcomm
63 :
64 : #endif // HCOMM_CCU_RES_TYPE_CONVERTER_H
|