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