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,
36 : const std::string &specKey) noexcept
37 3 : : readableAttrName(attrName), socSpecLabel(specLabel), socSpecKey(specKey),
38 3 : minimumRuntimeVersion(UNKNOWN_VERSION), isAvailable(0)
39 3 : {}
40 : };
41 :
42 : class CannInfoUtils {
43 : public:
44 : static aclError GetAttributeList(const aclCannAttr **cannAttr, size_t *num);
45 : static aclError GetAttribute(aclCannAttr cannAttr, int32_t *value);
46 : static aclError ParseVersionValue(const std::string &str, int32_t *value);
47 :
48 : private:
49 : static aclError Initialize();
50 : static aclError GetConfigInstallPath();
51 : static aclError ParseVersionInfo(const std::string &path, int32_t *version);
52 : static bool MatchVersionInfo(const CannInfo &configCannInfo);
53 : static bool CheckNPUFeatures(const CannInfo &configInfo);
54 : static void CheckAndUpdateAttrAvailability();
55 :
56 : static std::mutex mutex_;
57 : static bool initFlag_;
58 : static int32_t currentRuntimeVersion_;
59 : static std::string swConfigPath_;
60 : static std::string defaultInstallPath_;
61 : static aclCannAttr attrArray_[MAX_CANN_ATTR_SIZE];
62 : static size_t attrNum_;
63 : static std::map<aclCannAttr, CannInfo> attrToCannInfo_;
64 : };
65 : } // namespace acl
66 :
67 : #endif // ASCEND_CANN_INFO_UTILS_H
|