已合并
[Profiling]【fix】:兼容驱动不同分支、不同形态修改aicpu通道采集频率 #3944
[Profiling]【fix】:兼容驱动不同分支、不同形态修改aicpu通道采集频率 #3944
已合并
zhengkai创建于 7月30日
5 个文件变更+36-7
@@ -24,8 +24,11 @@ using namespace analysis::dvvp::common::utils;
24using namespace analysis::dvvp::common::config;24using namespace analysis::dvvp::common::config;
25 25 
26const std::string ASCEND_HAL_LIB = "libascend_hal.so";26const std::string ASCEND_HAL_LIB = "libascend_hal.so";
27-constexpr uint32_t SUPPORT_OSC_FREQ_API_VERSION = 0x071905;27+ 
28-constexpr uint32_t SUPPORT_ADPROF_VERSION = 0x72316;28+bool IsDrvApiVersionSupport(DrvFunctionVersion version)
29+{
30+ return Platform::instance()->DrvGetApiVersion() >= static_cast<uint32_t>(version);
31+}
29 32 
30template <class T>33template <class T>
31inline T LoadDlsymApi(VOID_PTR hanle, const std::string &name)34inline T LoadDlsymApi(VOID_PTR hanle, const std::string &name)
@@ -55,7 +58,7 @@ int32_t Platform::Init()
55 if (ascendHalAdaptor_.Init() != PROFILING_SUCCESS) {58 if (ascendHalAdaptor_.Init() != PROFILING_SUCCESS) {
56 return PROFILING_FAILED;59 return PROFILING_FAILED;
57 }60 }
58- if (DrvGetApiVersion() >= SUPPORT_OSC_FREQ_API_VERSION) {61+ if (IsDrvApiVersionSupport(OSC_FREQ_API_VERSION)) {
59#ifndef CPU_CYCLE_NO_SUPPORT62#ifndef CPU_CYCLE_NO_SUPPORT
60 enableHostOscFreq_ = analysis::dvvp::driver::DrvGetHostFreq(hostOscFreq_);63 enableHostOscFreq_ = analysis::dvvp::driver::DrvGetHostFreq(hostOscFreq_);
61#else64#else
@@ -174,7 +177,7 @@ std::string Platform::PlatformGetDeviceOscFreq(uint32_t deviceId, const std::str
174{177{
175 std::string deviceOscFreq;178 std::string deviceOscFreq;
176 bool enableDeviceOscFreq = false;179 bool enableDeviceOscFreq = false;
177- if (DrvGetApiVersion() >= SUPPORT_OSC_FREQ_API_VERSION) {180+ if (IsDrvApiVersionSupport(OSC_FREQ_API_VERSION)) {
178 enableDeviceOscFreq = analysis::dvvp::driver::DrvGetDeviceFreq(deviceId, deviceOscFreq);181 enableDeviceOscFreq = analysis::dvvp::driver::DrvGetDeviceFreq(deviceId, deviceOscFreq);
179 }182 }
180 183 
@@ -528,7 +531,7 @@ bool Platform::CheckIfSupportAdprof(uint32_t deviceId) const
528 return false;531 return false;
529 }532 }
530 533 
531- if (DrvGetApiVersion() < SUPPORT_ADPROF_VERSION534+ if (!IsDrvApiVersionSupport(ADPROF_API_VERSION)
532#ifndef BUILD_OPEN_PROJECT535#ifndef BUILD_OPEN_PROJECT
533 || GetPlatformType() == CHIP_MINI536 || GetPlatformType() == CHIP_MINI
534#endif // BUILD_OPEN_PROJECT537#endif // BUILD_OPEN_PROJECT
@@ -57,6 +57,24 @@ private:
57 HalEschedCreateGrpExFunc halEschedCreateGrpEx_{nullptr};57 HalEschedCreateGrpExFunc halEschedCreateGrpEx_{nullptr};
58};58};
59 59 
60+// Driver hal API version (__HAL_API_VER_*) in which each feature became available. The value is the
61+// minimum version that supports the feature, so IsDrvApiVersionSupport() is a single ">=" compare.
62+// To gate a new feature on the driver version, add one enumerator here with the version it landed in
63+// -- no new query function is needed.
64+enum DrvFunctionVersion : uint32_t {
65+ // Host/device oscillator frequency query (DrvGetHostFreq / DrvGetDeviceFreq).
66+ OSC_FREQ_API_VERSION = 0x071905,
67+ // adprof driver channel.
68+ ADPROF_API_VERSION = 0x072316,
69+ // aicpu channel.
70+ DAVID_AICPU_SAMPLE_PERIOD = 0x072419
71+};
72+ 
73+// Whether the running driver supports the given feature. Not cached: DrvGetApiVersion() returns 0
74+// while libascend_hal.so is not loaded yet (general-server scenario, or any call before
75+// Platform::Init()), and caching that 0 would disable every feature for the rest of the process.
76+bool IsDrvApiVersionSupport(DrvFunctionVersion version);
77+ 
60constexpr uint16_t QOS_STREAM_NAME_MAX_LENGTH = 256;78constexpr uint16_t QOS_STREAM_NAME_MAX_LENGTH = 256;
61struct QosProfileInfo {79struct QosProfileInfo {
62 uint32_t devId; // hal接口需要的字段80 uint32_t devId; // hal接口需要的字段
@@ -16,11 +16,13 @@
16#include "ascend_inpackage_hal.h"16#include "ascend_inpackage_hal.h"
17#include "json_parser.h"17#include "json_parser.h"
18#include "validation/nts_metrics_validation.h"18#include "validation/nts_metrics_validation.h"
19+#include "platform/platform.h"
19namespace analysis {20namespace analysis {
20namespace dvvp {21namespace dvvp {
21namespace driver {22namespace driver {
22using namespace analysis::dvvp::common::error;23using namespace analysis::dvvp::common::error;
23using namespace Msprofiler::Parser;24using namespace Msprofiler::Parser;
25+using namespace Analysis::Dvvp::Common::Platform;
24// 32 * 1024 * 0.8 is the full threshold of ai_core_sample26// 32 * 1024 * 0.8 is the full threshold of ai_core_sample
25constexpr uint32_t AI_CORE_SAMPLE_FULL_THRESHOLD = static_cast<uint32_t>(32 * 1024 * 0.8);27constexpr uint32_t AI_CORE_SAMPLE_FULL_THRESHOLD = static_cast<uint32_t>(32 * 1024 * 0.8);
26constexpr int32_t DRV_NOT_ENOUGH_SUB_CHANNEL_RESOURCE = -10; // PROF_NOT_ENOUGH_SUB_CHANNEL_RESOURCE28constexpr int32_t DRV_NOT_ENOUGH_SUB_CHANNEL_RESOURCE = -10; // PROF_NOT_ENOUGH_SUB_CHANNEL_RESOURCE
@@ -318,7 +320,11 @@ int32_t DrvAicoreTaskBasedStart(int32_t profDeviceId, AI_DRV_CHANNEL profChannel
318 320 
319int32_t DrvAicpuStart(uint32_t profDeviceId, AI_DRV_CHANNEL profChannel)321int32_t DrvAicpuStart(uint32_t profDeviceId, AI_DRV_CHANNEL profChannel)
320{322{
321- constexpr uint32_t aicpuDrvSamplePeriod = 7U;323+ uint32_t aicpuDrvSamplePeriod = 10U;
324+ if (IsDrvApiVersionSupport(DAVID_AICPU_SAMPLE_PERIOD) &&
325+ Platform::instance()->CheckIfSupport(PLATFORM_AICPU_SAMPLE_PERIOD)) {
326+ aicpuDrvSamplePeriod = 5U;
327+ }
322 struct prof_start_para profStartPara = { .channel_type = PROF_PERIPHERAL_TYPE,328 struct prof_start_para profStartPara = { .channel_type = PROF_PERIPHERAL_TYPE,
323 .sample_period = aicpuDrvSamplePeriod,329 .sample_period = aicpuDrvSamplePeriod,
324 .real_time = PROFILE_REAL_TIME,330 .real_time = PROFILE_REAL_TIME,
atomgit-bot
atomgit-botatomgit-bot7月30日

🔴 Critical

DrvAicpuStart 函数(第 322-328 行)将 constexpr uint32_t aicpuDrvSamplePeriod 声明在 ifelse 代码块内部。在 C++ 中,块内声明的变量其作用域仅限于该块,离开块后即不可见。第 330 行在 if/else 块之外使用 aicpuDrvSamplePeriod 会导致编译错误:use of undeclared identifier 'aicpuDrvSamplePeriod'

证据链

影响:代码无法通过编译,属于 P0 构建失败级别的问题。

建议:将变量声明移到 if/else 块外部,在块内赋值(不能使用 constexpr,改用 const 或普通变量),或使用三元表达式一步完成。

改动建议
330
+ const uint32_t aicpuDrvSamplePeriod = (Analysis::Dvvp::Common::Platform::IsDrvApiVersionSupport(
330
- .real_time = PROFILE_REAL_TIME,
331
+ Analysis::Dvvp::Common::Platform::DAVID_AICPU_SAMPLE_PERIOD) &&
332
+ Analysis::Dvvp::Common::Platform::instance()->CheckIfSupport(PLATFORM_AICPU_SAMPLE_PERIOD)) ? 7U : 10U;
应用建议
likedislike
不准确?
@@ -64,7 +64,8 @@ DavidPlatform::DavidPlatform()
64 PLATFORM_AICSCALE_ACP,64 PLATFORM_AICSCALE_ACP,
65 PLATFORM_STARS_QOS,65 PLATFORM_STARS_QOS,
66 PLATFORM_ACLAPI_SETDEVICE_ENABLE,66 PLATFORM_ACLAPI_SETDEVICE_ENABLE,
67- PLATFORM_API_STATS67+ PLATFORM_API_STATS,
68+ PLATFORM_AICPU_SAMPLE_PERIOD
68 };69 };
69 InsertPmuFeature();70 InsertPmuFeature();
70 InsertSysFeature();71 InsertSysFeature();
@@ -157,6 +157,7 @@ enum PlatformFeature {
157 PLATFORM_ACLAPI_SETDEVICE_ENABLE,157 PLATFORM_ACLAPI_SETDEVICE_ENABLE,
158 PLATFORM_TASK_NTS,158 PLATFORM_TASK_NTS,
159 PLATFORM_API_STATS,159 PLATFORM_API_STATS,
160+ PLATFORM_AICPU_SAMPLE_PERIOD,
160 // MAX161 // MAX
161 PLATFORM_COLLECTOR_TYPES_MAX162 PLATFORM_COLLECTOR_TYPES_MAX
162};163};