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 : #include "hcomm_adapter_runtime.h"
12 :
13 : #include "adapter_rts_common.h"
14 :
15 : namespace hcomm {
16 :
17 : constexpr uint32_t kDefaultResourceId = 0U;
18 :
19 290 : HcclResult ResolveRuntimeDevicePhyId(uint32_t &devicePhyId, bool &noDevice)
20 : {
21 290 : uint32_t deviceCount = 0;
22 290 : HcclResult ret = hrtGetDeviceCount(&deviceCount);
23 290 : if (ret != HCCL_SUCCESS) {
24 0 : HCCL_WARNING("[HcommAdapterRuntime][%s] get device count failed, ret[%d], use resource id[%u].",
25 : __func__, ret, kDefaultResourceId);
26 0 : devicePhyId = kDefaultResourceId;
27 0 : noDevice = true;
28 0 : return HCCL_SUCCESS;
29 : }
30 :
31 290 : if (deviceCount == 0) {
32 2 : devicePhyId = kDefaultResourceId;
33 2 : noDevice = true;
34 2 : return HCCL_SUCCESS;
35 : }
36 :
37 288 : int32_t devLogicId = 0;
38 288 : CHK_RET(hrtGetDevice(&devLogicId));
39 288 : CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<uint32_t>(devLogicId), devicePhyId));
40 288 : noDevice = false;
41 288 : HCCL_INFO("[HcommAdapterRuntime][%s] deviceCount[%u], devLogicId[%d], devicePhyId[%u].",
42 : __func__, deviceCount, devLogicId, devicePhyId);
43 288 : return HCCL_SUCCESS;
44 : }
45 :
46 : } // namespace hcomm
|