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 ASCEND_CANN_INFO_UTILS_H
12 : #define ASCEND_CANN_INFO_UTILS_H
13 :
14 : #include <limits>
15 : #include <mutex>
16 : #include <vector>
17 : #include <string>
18 : #include <map>
19 :
20 : #include "runtime/base.h"
21 : #include "acl/acl_base.h"
22 :
23 : namespace acl {
24 : constexpr const size_t MAX_CANN_ATTR_SIZE = 128U;
25 : // if version info is not set in swFeatureList.json, use UNKNOWN_VERSION as default value
26 : constexpr const int32_t UNKNOWN_VERSION = -1;
27 : constexpr const char_t* const SW_CONFIG_RUNTIME = "runtimeVersion";
28 :
29 : struct CannInfo {
30 : std::string readableAttrName;
31 : std::string socSpecLabel;
32 : std::string socSpecKey;
33 : int32_t minimumRuntimeVersion;
34 : int32_t isAvailable;
35 3 : explicit CannInfo(const std::string& attrName, const std::string& specLabel, const std::string& specKey) noexcept
36 3 : : readableAttrName(attrName),
37 3 : socSpecLabel(specLabel),
38 3 : socSpecKey(specKey),
39 3 : minimumRuntimeVersion(UNKNOWN_VERSION),
40 3 : isAvailable(0)
41 3 : {}
42 : };
43 :
44 : class CannInfoUtils {
45 : public:
46 : static aclError GetAttributeList(const aclCannAttr** cannAttr, size_t* num);
47 : static aclError GetAttribute(aclCannAttr cannAttr, int32_t* value);
48 : static aclError ParseVersionValue(const std::string& str, int32_t* value);
49 :
50 : private:
51 : static aclError Initialize();
52 : static aclError GetConfigInstallPath();
53 : static aclError ParseVersionInfo(const std::string& path, int32_t* version);
54 : static bool MatchVersionInfo(const CannInfo& configCannInfo);
55 : static bool CheckNPUFeatures(const CannInfo& configInfo);
56 : static void CheckAndUpdateAttrAvailability();
57 :
58 : static std::mutex mutex_;
59 : static bool initFlag_;
60 : static int32_t currentRuntimeVersion_;
61 : static std::string swConfigPath_;
62 : static std::string defaultInstallPath_;
63 : static aclCannAttr attrArray_[MAX_CANN_ATTR_SIZE];
64 : static size_t attrNum_;
65 : static std::map<aclCannAttr, CannInfo> attrToCannInfo_;
66 : };
67 : } // namespace acl
68 :
69 : #endif // ASCEND_CANN_INFO_UTILS_H
|