Merged
【PR】: support profiling for mem-api #3644
xiachanglinAdd on Jul 14
【PR】: support profiling for mem-api #3644
Merged
Merged fromxiachanglin/runtime_1727masterintocann/runtimemaster
Total: 9 files changed+1313-2
| @@ -427,6 +427,38 @@ struct MsprofStreamSqInfo { // for MsprofReportCompactInfo buffer data | |||
| 427 | uint16_t tsId; // ts id | 427 | uint16_t tsId; // ts id |
| 428 | }; | 428 | }; |
| 429 | 429 | ||
| 430 | +struct MsprofMemcpyInfo { // for runtime memcpy compact info | ||
| 431 | + uint64_t bytes; | ||
| 432 | + uint16_t copyKind; | ||
| 433 | + uint16_t deviceId; | ||
| 434 | + uint32_t streamId; | ||
| 435 | +}; | ||
| 436 | + | ||
| 437 | +struct MsprofMemsetInfo { // for runtime memset compact info | ||
| 438 | + uint64_t bytes; | ||
| 439 | + int32_t value; | ||
| 440 | + uint32_t streamId; | ||
| 441 | + uint16_t deviceId; | ||
| 442 | + uint16_t rsv[3]; | ||
| 443 | +}; | ||
| 444 | + | ||
| 445 | +typedef enum tagMsprofMemoryType { | ||
| 446 | + MSPROF_MEMORY_TYPE_UNKNOWN = 0, | ||
| 447 | + MSPROF_MEMORY_TYPE_HOST = 1, | ||
| 448 | + MSPROF_MEMORY_TYPE_DEVICE = 2, | ||
| 449 | + MSPROF_MEMORY_TYPE_MANAGED = 3 | ||
| 450 | +} MsprofMemoryType; | ||
| 451 | + | ||
| 452 | +struct MsprofMemMngInfo { // for runtime memory management compact info | ||
| 453 | + uint64_t address; | ||
| 454 | + uint64_t size; | ||
| 455 | + uint32_t memoryType; | ||
| 456 | + uint16_t memMngType; | ||
| 457 | + uint16_t deviceId; | ||
| 458 | + uint32_t streamId; | ||
| 459 | + uint32_t rsv; | ||
| 460 | +}; | ||
| 461 | + | ||
| 430 | struct MsprofDpuTrack { // for MsprofReportCompactInfo buffer data | 462 | struct MsprofDpuTrack { // for MsprofReportCompactInfo buffer data |
| 431 | uint16_t deviceId; // high 4 bits, devType: dpu: 1, low 12 bits device id | 463 | uint16_t deviceId; // high 4 bits, devType: dpu: 1, low 12 bits device id |
| 432 | uint16_t streamId; | 464 | uint16_t streamId; |
| @@ -560,6 +592,9 @@ struct MsprofCompactInfo { // for MsprofReportCompactInfo buffer data | |||
| 560 | struct MsprofHCCLOPInfo hcclopInfo; | 592 | struct MsprofHCCLOPInfo hcclopInfo; |
| 561 | struct MsprofDpuTrack dpuTack; | 593 | struct MsprofDpuTrack dpuTack; |
| 562 | struct MsprofStreamExpandSpecInfo streamExpandInfo; | 594 | struct MsprofStreamExpandSpecInfo streamExpandInfo; |
| 595 | + struct MsprofMemcpyInfo memcpyInfo; | ||
| 596 | + struct MsprofMemsetInfo memsetInfo; | ||
| 597 | + struct MsprofMemMngInfo memMngInfo; | ||
| 563 | } data; | 598 | } data; |
| 564 | }; | 599 | }; |
| 565 | 600 | ||
| @@ -234,6 +234,7 @@ enum rtProfApiType_t : uint32_t { | |||
| 234 | RT_PROF_API_GET_HOST_ATOMIC_CAPABILITIES = 186, | 234 | RT_PROF_API_GET_HOST_ATOMIC_CAPABILITIES = 186, |
| 235 | RT_PROF_API_GET_P2P_ATOMIC_CAPABILITIES = 187, | 235 | RT_PROF_API_GET_P2P_ATOMIC_CAPABILITIES = 187, |
| 236 | RT_PROF_API_CACHE_LAST_TASK_EXTEND_INFO = 188, | 236 | RT_PROF_API_CACHE_LAST_TASK_EXTEND_INFO = 188, |
| 237 | + RT_PROF_API_SET_MEMCPY_DESC = 189, | ||
| 237 | RT_PROF_API_MAX = 200 | 238 | RT_PROF_API_MAX = 200 |
| 238 | }; | 239 | }; |
| 239 | 240 | ||
| @@ -275,19 +276,41 @@ enum rtProfileDataType_t : uint32_t { | |||
| 275 | RT_PROFILE_TYPE_STREAM_SQ_INFO = 807, /* stream sq info */ | 276 | RT_PROFILE_TYPE_STREAM_SQ_INFO = 807, /* stream sq info */ |
| 276 | RT_PROFILE_TYPE_TASK_TRACK_V2 = 808, /* task track v2 */ | 277 | RT_PROFILE_TYPE_TASK_TRACK_V2 = 808, /* task track v2 */ |
| 277 | RT_PROFILE_TYPE_CAPTURE_STREAM_INFO_V2 = 809, | 278 | RT_PROFILE_TYPE_CAPTURE_STREAM_INFO_V2 = 809, |
| 278 | - RT_PROFILE_TYPE_API_BEGIN = 1000, /* regist task type and task name for Parsing task info*/ | 279 | + |
| 280 | + RT_PROFILE_TYPE_MEMCPY_EXT_INFO = 810, /* memcpy extended info */ | ||
| 281 | + RT_PROFILE_TYPE_MEMSET_INFO = 811, /* memset info */ | ||
| 282 | + RT_PROFILE_TYPE_MEMMNG_INFO = 812, /* memory management info */ | ||
| 283 | + RT_PROFILE_TYPE_API_BEGIN = 1000, /* regist task type and task name for Parsing task info*/ | ||
| 279 | RT_PROFILE_TYPE_API_END = 2000, | 284 | RT_PROFILE_TYPE_API_END = 2000, |
| 280 | RT_PROFILE_TYPE_MAX = 2001 | 285 | RT_PROFILE_TYPE_MAX = 2001 |
| 281 | }; | 286 | }; |
| 282 | 287 | ||
| 283 | enum StreamReportStatus : uint16_t { STREAM_STATUS_CREATE = 0U, STREAM_STATUS_DESTROY = 1U }; | 288 | enum StreamReportStatus : uint16_t { STREAM_STATUS_CREATE = 0U, STREAM_STATUS_DESTROY = 1U }; |
| 284 | 289 | ||
| 290 | +enum rtProfMemMngType_t : uint16_t { | ||
| 291 | + RT_PROF_MEM_MNG_TYPE_MALLOC = 0U, | ||
| 292 | + RT_PROF_MEM_MNG_TYPE_FREE = 1U, | ||
| 293 | +}; | ||
| 294 | + | ||
| 285 | struct RuntimeMemcpyInfo { // for memcpy info | 295 | struct RuntimeMemcpyInfo { // for memcpy info |
| 286 | uint64_t dateSize; | 296 | uint64_t dateSize; |
| 287 | uint64_t maxSize; | 297 | uint64_t maxSize; |
| 288 | uint16_t direction; | 298 | uint16_t direction; |
| 289 | }; | 299 | }; |
| 290 | 300 | ||
| 301 | +union RuntimeProfExtInfo { | ||
| 302 | + MsprofMemcpyInfo memcpyInfo; | ||
| 303 | + MsprofMemsetInfo memsetInfo; | ||
| 304 | + MsprofMemMngInfo memMngInfo; | ||
| 305 | +}; | ||
| 306 | + | ||
| 307 | +struct RuntimeProfExtInfoItem { | ||
| 308 | + uint32_t extInfoType; | ||
| 309 | + RuntimeProfExtInfo extInfo; | ||
| 310 | +}; | ||
| 311 | + | ||
| 312 | +constexpr uint32_t RUNTIME_PROF_EXT_INFO_NUM = 10U; | ||
| 313 | + | ||
| 291 | struct ProfTypeRegisterInfo { | 314 | struct ProfTypeRegisterInfo { |
| 292 | uint32_t type; | 315 | uint32_t type; |
| 293 | const char_t* name; | 316 | const char_t* name; |
| @@ -308,6 +331,8 @@ struct RuntimeProfApiData { | |||
| 308 | uint32_t taskId[RUNTIME_TASK_ID_NUM]; | 331 | uint32_t taskId[RUNTIME_TASK_ID_NUM]; |
| 309 | uint16_t memcpyDirection; | 332 | uint16_t memcpyDirection; |
| 310 | uint16_t profileType; | 333 | uint16_t profileType; |
| 334 | + uint32_t extInfoCount; | ||
| 335 | + RuntimeProfExtInfoItem extInfos[RUNTIME_PROF_EXT_INFO_NUM]; | ||
| 311 | }; | 336 | }; |
| 312 | 337 | ||
| 313 | struct RuntimeProfTrackData { | 338 | struct RuntimeProfTrackData { |
| @@ -21,6 +21,66 @@ namespace { | |||
| 21 | constexpr size_t PROF_API_STACK_RESERVE_SIZE = 8U; | 21 | constexpr size_t PROF_API_STACK_RESERVE_SIZE = 8U; |
| 22 | thread_local std::vector<ProfApiContext> g_apiProfStack{}; | 22 | thread_local std::vector<ProfApiContext> g_apiProfStack{}; |
| 23 | thread_local ProfApiContext g_fallbackProfApiContext{}; | 23 | thread_local ProfApiContext g_fallbackProfApiContext{}; |
| 24 | + | ||
| 25 | +uint32_t GetProfExtInfoDataLen(const uint32_t extInfoType) | ||
只在本函数内调用,使用static修饰。请排查 ![]() ![]() | |||
| 26 | +{ | ||
| 27 | + switch (extInfoType) { | ||
| 28 | + case RT_PROFILE_TYPE_MEMCPY_EXT_INFO: | ||
| 29 | + return static_cast<uint32_t>(sizeof(MsprofMemcpyInfo)); | ||
| 30 | + case RT_PROFILE_TYPE_MEMSET_INFO: | ||
| 31 | + return static_cast<uint32_t>(sizeof(MsprofMemsetInfo)); | ||
| 32 | + case RT_PROFILE_TYPE_MEMMNG_INFO: | ||
| 33 | + return static_cast<uint32_t>(sizeof(MsprofMemMngInfo)); | ||
| 34 | + default: | ||
| 35 | + return 0U; | ||
| 36 | + } | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +rtError_t SetProfExtCompactData( | ||
| 40 | + const uint32_t extInfoType, const RuntimeProfExtInfo& extInfo, MsprofCompactInfo& compactInfo) | ||
| 41 | +{ | ||
| 42 | + switch (extInfoType) { | ||
| 43 | + case RT_PROFILE_TYPE_MEMCPY_EXT_INFO: | ||
| 44 | + compactInfo.data.memcpyInfo = extInfo.memcpyInfo; | ||
| 45 | + return RT_ERROR_NONE; | ||
| 46 | + case RT_PROFILE_TYPE_MEMSET_INFO: | ||
| 47 | + compactInfo.data.memsetInfo = extInfo.memsetInfo; | ||
| 48 | + return RT_ERROR_NONE; | ||
| 49 | + case RT_PROFILE_TYPE_MEMMNG_INFO: | ||
| 50 | + compactInfo.data.memMngInfo = extInfo.memMngInfo; | ||
| 51 | + return RT_ERROR_NONE; | ||
| 52 | + default: | ||
| 53 | + return RT_ERROR_INVALID_VALUE; | ||
我们代码一般不这样写,把return RT_ERROR_NONE放在最后,case下面用break;跳出来 ![]() ![]() | |||
| 54 | + } | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +rtError_t ReportProfExtCompactInfo( | ||
| 58 | + const uint32_t extInfoType, const RuntimeProfExtInfo& extInfo, const uint32_t threadId, const uint64_t timeStamp) | ||
| 59 | +{ | ||
| 60 | + const uint32_t dataLen = GetProfExtInfoDataLen(extInfoType); | ||
| 61 | + if (dataLen == 0U) { | ||
| 62 | + RT_LOG(RT_LOG_ERROR, "Invalid runtime profiling ext info type, type=%u.", extInfoType); | ||
| 63 | + return RT_ERROR_INVALID_VALUE; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + MsprofCompactInfo compactInfo{}; | ||
| 67 | + compactInfo.level = MSPROF_REPORT_RUNTIME_LEVEL; | ||
| 68 | + compactInfo.type = extInfoType; | ||
| 69 | + compactInfo.threadId = threadId; | ||
| 70 | + compactInfo.timeStamp = timeStamp; | ||
| 71 | + compactInfo.dataLen = dataLen; | ||
| 72 | + const rtError_t fillRet = SetProfExtCompactData(extInfoType, extInfo, compactInfo); | ||
| 73 | + if (fillRet != RT_ERROR_NONE) { | ||
| 74 | + return fillRet; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + const int32_t res = MsprofReportCompactInfo(true, &compactInfo, static_cast<uint32_t>(sizeof(MsprofCompactInfo))); | ||
| 78 | + if (res != MSPROF_ERROR_NONE) { | ||
| 79 | + RT_LOG_CALL_MSG(ERR_MODULE_PROFILE, "Failed to report profiling ext info, type=%u, ret=%d.", extInfoType, res); | ||
| 80 | + return RT_ERROR_PROF_OPER; | ||
| 81 | + } | ||
| 82 | + return RT_ERROR_NONE; | ||
| 83 | +} | ||
| 24 | } // namespace | 84 | } // namespace |
| 25 | 85 | ||
| 26 | ProfilingAgent& ProfilingAgent::Instance() | 86 | ProfilingAgent& ProfilingAgent::Instance() |
| @@ -133,6 +193,9 @@ rtError_t ProfilingAgent::RegisterProfTypeInfo() const | |||
| 133 | 193 | ||
| 134 | // memcpy info | 194 | // memcpy info |
| 135 | {RT_PROFILE_TYPE_MEMCPY_INFO, "memcpy_info"}, | 195 | {RT_PROFILE_TYPE_MEMCPY_INFO, "memcpy_info"}, |
| 196 | + {RT_PROFILE_TYPE_MEMCPY_EXT_INFO, "memcpy_ext_info"}, | ||
| 197 | + {RT_PROFILE_TYPE_MEMSET_INFO, "memset_info"}, | ||
| 198 | + {RT_PROFILE_TYPE_MEMMNG_INFO, "memmng_info"}, | ||
| 136 | 199 | ||
| 137 | // task track | 200 | // task track |
| 138 | {RT_PROFILE_TYPE_TASK_TRACK, "task_track"}, | 201 | {RT_PROFILE_TYPE_TASK_TRACK, "task_track"}, |
| @@ -448,6 +511,8 @@ rtError_t ProfilingAgent::RegisterProfTypeInfo() const | |||
| 448 | "GetCmoDesc"}, | 511 | "GetCmoDesc"}, |
| 449 | {static_cast<uint32_t>(RT_PROFILE_TYPE_API_BEGIN) + static_cast<uint32_t>(RT_PROF_API_SET_CMO_DESC), | 512 | {static_cast<uint32_t>(RT_PROFILE_TYPE_API_BEGIN) + static_cast<uint32_t>(RT_PROF_API_SET_CMO_DESC), |
| 450 | "SetCmoDesc"}, | 513 | "SetCmoDesc"}, |
| 514 | + {static_cast<uint32_t>(RT_PROFILE_TYPE_API_BEGIN) + static_cast<uint32_t>(RT_PROF_API_SET_MEMCPY_DESC), | ||
| 515 | + "SetMemcpyDesc"}, | ||
| 451 | {static_cast<uint32_t>(RT_PROFILE_TYPE_API_BEGIN) + static_cast<uint32_t>(RT_PROF_API_MODEL_EXECUTE_SYNC), | 516 | {static_cast<uint32_t>(RT_PROFILE_TYPE_API_BEGIN) + static_cast<uint32_t>(RT_PROF_API_MODEL_EXECUTE_SYNC), |
| 452 | "ModelExecuteSync"}, | 517 | "ModelExecuteSync"}, |
| 453 | {static_cast<uint32_t>(RT_PROFILE_TYPE_API_BEGIN) + static_cast<uint32_t>(RT_PROF_API_MODEL_EXECUTE_ASYNC), | 518 | {static_cast<uint32_t>(RT_PROFILE_TYPE_API_BEGIN) + static_cast<uint32_t>(RT_PROF_API_MODEL_EXECUTE_ASYNC), |
| @@ -554,6 +619,15 @@ void ProfilingAgent::ReportProfApi(const uint32_t devId, RuntimeProfApiData& pro | |||
| 554 | return; | 619 | return; |
| 555 | } | 620 | } |
| 556 | } | 621 | } |
| 622 | + | ||
| 623 | + for (uint32_t i = 0U; i < profApiData.extInfoCount; ++i) { | ||
| 624 | + const RuntimeProfExtInfoItem& extInfoItem = profApiData.extInfos[i]; | ||
| 625 | + const rtError_t reportRet = ReportProfExtCompactInfo( | ||
| 626 | + extInfoItem.extInfoType, extInfoItem.extInfo, profApiData.threadId, profApiData.entryTime + 1U + i); | ||
| 627 | + if (reportRet != RT_ERROR_NONE) { | ||
| 628 | + return; | ||
| 629 | + } | ||
| 630 | + } | ||
| 557 | } | 631 | } |
| 558 | 632 | ||
| 559 | ProfApiContext* ProfilerPushProfApiContext(void) | 633 | ProfApiContext* ProfilerPushProfApiContext(void) |
| @@ -32,5 +32,29 @@ const char_t* MemLocationTypeToStr(const rtMemLocationType type) | |||
| 32 | } | 32 | } |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | +uint16_t GetMemcpyBatchCopyKind(const rtMemcpyBatchAttr& attr) | ||
| 36 | +{ | ||
| 37 | + const auto isHostMemoryLocation = [](const rtMemLocationType type) { | ||
| 38 | + return (type == RT_MEMORY_LOC_HOST) || (type == RT_MEMORY_LOC_HOST_NUMA); | ||
| 39 | + }; | ||
| 40 | + const auto isDeviceMemoryLocation = [](const rtMemLocationType type) { return type == RT_MEMORY_LOC_DEVICE; }; | ||
| 41 | + | ||
| 42 | + const rtMemLocationType dstType = attr.dstLoc.type; | ||
| 43 | + const rtMemLocationType srcType = attr.srcLoc.type; | ||
| 44 | + if (isHostMemoryLocation(srcType) && isHostMemoryLocation(dstType)) { | ||
| 45 | + return static_cast<uint16_t>(RT_MEMCPY_KIND_HOST_TO_HOST); | ||
| 46 | + } | ||
| 47 | + if (isHostMemoryLocation(srcType) && isDeviceMemoryLocation(dstType)) { | ||
| 48 | + return static_cast<uint16_t>(RT_MEMCPY_KIND_HOST_TO_DEVICE); | ||
| 49 | + } | ||
| 50 | + if (isDeviceMemoryLocation(srcType) && isHostMemoryLocation(dstType)) { | ||
| 51 | + return static_cast<uint16_t>(RT_MEMCPY_KIND_DEVICE_TO_HOST); | ||
| 52 | + } | ||
| 53 | + if (isDeviceMemoryLocation(srcType) && isDeviceMemoryLocation(dstType)) { | ||
| 54 | + return static_cast<uint16_t>(RT_MEMCPY_KIND_DEVICE_TO_DEVICE); | ||
| 55 | + } | ||
| 56 | + return static_cast<uint16_t>(RT_MEMCPY_KIND_MAX); | ||
| 57 | +} | ||
| 58 | + | ||
| 35 | } // namespace runtime | 59 | } // namespace runtime |
| 36 | -} // namespace cce | 60 | +} // namespace cce |
| @@ -18,6 +18,7 @@ namespace runtime { | |||
| 18 | 18 | ||
| 19 | // memory type to string | 19 | // memory type to string |
| 20 | const char_t* MemLocationTypeToStr(const rtMemLocationType type); | 20 | const char_t* MemLocationTypeToStr(const rtMemLocationType type); |
| 21 | +uint16_t GetMemcpyBatchCopyKind(const rtMemcpyBatchAttr& attr); | ||
| 21 | 22 | ||
| 22 | } // namespace runtime | 23 | } // namespace runtime |
| 23 | } // namespace cce | 24 | } // namespace cce |
| @@ -10,6 +10,7 @@ | |||
| 10 | #include "api_c.h" | 10 | #include "api_c.h" |
| 11 | #include "profiler.hpp" | 11 | #include "profiler.hpp" |
| 12 | #include "api_profile_decorator.hpp" | 12 | #include "api_profile_decorator.hpp" |
| 13 | +#include "mem_type.hpp" | ||
| 13 | 14 | ||
| 14 | namespace cce { | 15 | namespace cce { |
| 15 | namespace runtime { | 16 | namespace runtime { |
| @@ -22,6 +23,7 @@ ProfApiContext* PushProfApiContextWithCheck(Profiler* const profiler) | |||
| 22 | } | 23 | } |
| 23 | return profApiContext; | 24 | return profApiContext; |
| 24 | } | 25 | } |
| 26 | + | ||
| 25 | } // namespace | 27 | } // namespace |
| 26 | 28 | ||
| 27 | ApiProfileDecorator::ApiProfileDecorator(Api* const impl, Profiler* const prof) : ApiDecorator(impl), profiler_(prof) | 29 | ApiProfileDecorator::ApiProfileDecorator(Api* const impl, Profiler* const prof) : ApiDecorator(impl), profiler_(prof) |
| @@ -30,6 +32,140 @@ ApiProfileDecorator::ApiProfileDecorator(Api* const impl, Profiler* const prof) | |||
| 30 | UNUSED(prof); | 32 | UNUSED(prof); |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 35 | +RuntimeProfApiData* ApiProfileDecorator::GetReportProfApiData() const | ||
| 36 | +{ | ||
| 37 | + if (!profiler_->GetApiProfEnable()) { | ||
| 38 | + return nullptr; | ||
| 39 | + } | ||
| 40 | + ProfApiContext* const profApiContext = profiler_->GetTopProfApiContext(); | ||
| 41 | + if ((profApiContext == nullptr) || (!profApiContext->needReport)) { | ||
| 42 | + return nullptr; | ||
| 43 | + } | ||
| 44 | + return &(profApiContext->apiData); | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +void ApiProfileDecorator::FillMemcpyExtInfo( | ||
| 48 | + const uint64_t bytes, const uint16_t copyKind, const Stream* const stm) const | ||
| 49 | +{ | ||
| 50 | + RuntimeProfApiData* const profApiData = GetReportProfApiData(); | ||
| 51 | + if ((profApiData == nullptr) || (profApiData->extInfoCount >= RUNTIME_PROF_EXT_INFO_NUM)) { | ||
| 52 | + return; | ||
| 53 | + } | ||
| 54 | + int32_t curDeviceId = 0; | ||
| 55 | + const rtError_t error = impl_->GetDevice(&curDeviceId); | ||
| 56 | + uint16_t deviceId = static_cast<uint16_t>(UINT16_MAX); | ||
| 57 | + if ((error == RT_ERROR_NONE) && (curDeviceId >= 0) && (curDeviceId <= static_cast<int32_t>(UINT16_MAX))) { | ||
| 58 | + deviceId = static_cast<uint16_t>(curDeviceId); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + RuntimeProfExtInfoItem& extInfoItem = profApiData->extInfos[profApiData->extInfoCount]; | ||
| 62 | + extInfoItem.extInfoType = RT_PROFILE_TYPE_MEMCPY_EXT_INFO; | ||
| 63 | + extInfoItem.extInfo.memcpyInfo.bytes = bytes; | ||
| 64 | + extInfoItem.extInfo.memcpyInfo.copyKind = copyKind; | ||
| 65 | + extInfoItem.extInfo.memcpyInfo.deviceId = deviceId; | ||
| 66 | + extInfoItem.extInfo.memcpyInfo.streamId = | ||
| 67 | + (stm == nullptr) ? static_cast<uint32_t>(UINT32_MAX) : static_cast<uint32_t>(stm->Id_()); | ||
| 68 | + ++profApiData->extInfoCount; | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +void ApiProfileDecorator::FillMemsetExtInfo(const uint64_t bytes, const uint32_t value, const Stream* const stm) const | ||
| 72 | +{ | ||
| 73 | + RuntimeProfApiData* const profApiData = GetReportProfApiData(); | ||
| 74 | + if ((profApiData == nullptr) || (profApiData->extInfoCount >= RUNTIME_PROF_EXT_INFO_NUM)) { | ||
| 75 | + return; | ||
| 76 | + } | ||
| 77 | + int32_t curDeviceId = 0; | ||
| 78 | + const rtError_t error = impl_->GetDevice(&curDeviceId); | ||
| 79 | + uint16_t deviceId = static_cast<uint16_t>(UINT16_MAX); | ||
| 80 | + if ((error == RT_ERROR_NONE) && (curDeviceId >= 0) && (curDeviceId <= static_cast<int32_t>(UINT16_MAX))) { | ||
| 81 | + deviceId = static_cast<uint16_t>(curDeviceId); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + RuntimeProfExtInfoItem& extInfoItem = profApiData->extInfos[profApiData->extInfoCount]; | ||
| 85 | + extInfoItem.extInfoType = RT_PROFILE_TYPE_MEMSET_INFO; | ||
| 86 | + extInfoItem.extInfo.memsetInfo.bytes = bytes; | ||
| 87 | + extInfoItem.extInfo.memsetInfo.value = static_cast<int32_t>(value); | ||
| 88 | + extInfoItem.extInfo.memsetInfo.streamId = | ||
| 89 | + (stm == nullptr) ? static_cast<uint32_t>(UINT32_MAX) : static_cast<uint32_t>(stm->Id_()); | ||
| 90 | + extInfoItem.extInfo.memsetInfo.deviceId = deviceId; | ||
| 91 | + extInfoItem.extInfo.memsetInfo.rsv[0] = 0U; | ||
| 92 | + extInfoItem.extInfo.memsetInfo.rsv[1] = 0U; | ||
| 93 | + extInfoItem.extInfo.memsetInfo.rsv[2] = 0U; | ||
| 94 | + ++profApiData->extInfoCount; | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +void ApiProfileDecorator::FillMemMngExtInfo( | ||
| 98 | + const uint64_t address, const uint64_t size, const uint16_t memMngType, const uint32_t memoryType, | ||
| 99 | + const Stream* const stm) const | ||
| 100 | +{ | ||
| 101 | + RuntimeProfApiData* const profApiData = GetReportProfApiData(); | ||
| 102 | + if ((profApiData == nullptr) || (profApiData->extInfoCount >= RUNTIME_PROF_EXT_INFO_NUM)) { | ||
| 103 | + return; | ||
| 104 | + } | ||
| 105 | + int32_t curDeviceId = 0; | ||
| 106 | + const rtError_t error = impl_->GetDevice(&curDeviceId); | ||
| 107 | + uint16_t deviceId = static_cast<uint16_t>(UINT16_MAX); | ||
| 108 | + if ((error == RT_ERROR_NONE) && (curDeviceId >= 0) && (curDeviceId <= static_cast<int32_t>(UINT16_MAX))) { | ||
| 109 | + deviceId = static_cast<uint16_t>(curDeviceId); | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + RuntimeProfExtInfoItem& extInfoItem = profApiData->extInfos[profApiData->extInfoCount]; | ||
| 113 | + extInfoItem.extInfoType = RT_PROFILE_TYPE_MEMMNG_INFO; | ||
| 114 | + extInfoItem.extInfo.memMngInfo.address = address; | ||
| 115 | + extInfoItem.extInfo.memMngInfo.size = size; | ||
| 116 | + extInfoItem.extInfo.memMngInfo.memoryType = memoryType; | ||
| 117 | + extInfoItem.extInfo.memMngInfo.memMngType = memMngType; | ||
| 118 | + extInfoItem.extInfo.memMngInfo.deviceId = deviceId; | ||
| 119 | + extInfoItem.extInfo.memMngInfo.streamId = | ||
| 120 | + (stm == nullptr) ? static_cast<uint32_t>(UINT32_MAX) : static_cast<uint32_t>(stm->Id_()); | ||
| 121 | + extInfoItem.extInfo.memMngInfo.rsv = 0U; | ||
| 122 | + ++profApiData->extInfoCount; | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | +void ApiProfileDecorator::FillMemcpyBatchExtInfoByCopyKind( | ||
| 126 | + const size_t* const sizes, const size_t count, const rtMemcpyBatchAttr* const attrs, const size_t* const attrsIdxs, | ||
| 127 | + const size_t numAttrs, const Stream* const stm) const | ||
| 128 | +{ | ||
| 129 | + RuntimeProfApiData* const profApiData = GetReportProfApiData(); | ||
| 130 | + if ((profApiData == nullptr) || (sizes == nullptr) || (attrs == nullptr) || (attrsIdxs == nullptr) || | ||
| 131 | + (numAttrs == 0U)) { | ||
| 132 | + return; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + uint64_t bytesByKind[RUNTIME_PROF_EXT_INFO_NUM] = {}; | ||
| 136 | + size_t attrIdx = 0U; | ||
| 137 | + for (size_t i = 0U; i < count; ++i) { | ||
| 138 | + if (((attrIdx + 1U) < numAttrs) && (i >= attrsIdxs[attrIdx + 1U])) { | ||
| 139 | + ++attrIdx; | ||
| 140 | + } | ||
| 141 | + const uint16_t copyKind = GetMemcpyBatchCopyKind(attrs[attrIdx]); | ||
| 142 | + const uint32_t groupIdx = (copyKind < RUNTIME_PROF_EXT_INFO_NUM) ? static_cast<uint32_t>(copyKind) : | ||
| 143 | + static_cast<uint32_t>(RT_MEMCPY_KIND_MAX); | ||
| 144 | + bytesByKind[groupIdx] += static_cast<uint64_t>(sizes[i]); | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + int32_t curDeviceId = 0; | ||
| 148 | + const rtError_t error = impl_->GetDevice(&curDeviceId); | ||
| 149 | + uint16_t deviceId = static_cast<uint16_t>(UINT16_MAX); | ||
| 150 | + if ((error == RT_ERROR_NONE) && (curDeviceId >= 0) && (curDeviceId <= static_cast<int32_t>(UINT16_MAX))) { | ||
| 151 | + deviceId = static_cast<uint16_t>(curDeviceId); | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + const uint32_t streamId = (stm == nullptr) ? static_cast<uint32_t>(UINT32_MAX) : static_cast<uint32_t>(stm->Id_()); | ||
| 155 | + for (uint32_t kind = 0U; kind < RUNTIME_PROF_EXT_INFO_NUM; ++kind) { | ||
| 156 | + if ((bytesByKind[kind] == 0U) || (profApiData->extInfoCount >= RUNTIME_PROF_EXT_INFO_NUM)) { | ||
| 157 | + continue; | ||
| 158 | + } | ||
| 159 | + RuntimeProfExtInfoItem& extInfoItem = profApiData->extInfos[profApiData->extInfoCount]; | ||
| 160 | + extInfoItem.extInfoType = RT_PROFILE_TYPE_MEMCPY_EXT_INFO; | ||
| 161 | + extInfoItem.extInfo.memcpyInfo.bytes = bytesByKind[kind]; | ||
| 162 | + extInfoItem.extInfo.memcpyInfo.copyKind = static_cast<uint16_t>(kind); | ||
| 163 | + extInfoItem.extInfo.memcpyInfo.deviceId = deviceId; | ||
| 164 | + extInfoItem.extInfo.memcpyInfo.streamId = streamId; | ||
| 165 | + ++profApiData->extInfoCount; | ||
| 166 | + } | ||
| 167 | +} | ||
| 168 | + | ||
| 33 | void ApiProfileDecorator::CallApiBegin( | 169 | void ApiProfileDecorator::CallApiBegin( |
| 34 | const uint16_t profileType, const uint64_t dataSize, const uint16_t cpyDirection) const | 170 | const uint16_t profileType, const uint64_t dataSize, const uint16_t cpyDirection) const |
| 35 | { | 171 | { |
| @@ -65,6 +201,7 @@ void ApiProfileDecorator::CallApiBegin( | |||
| 65 | profApiData.streamId = static_cast<uint32_t>(UINT16_MAX); | 201 | profApiData.streamId = static_cast<uint32_t>(UINT16_MAX); |
| 66 | profApiData.taskNum = 0U; | 202 | profApiData.taskNum = 0U; |
| 67 | profApiData.profileType = profileType; | 203 | profApiData.profileType = profileType; |
| 204 | + profApiData.extInfoCount = 0U; | ||
| 68 | 205 | ||
| 69 | RT_LOG(RT_LOG_DEBUG, "profileType=%hu", profApiData.profileType); | 206 | RT_LOG(RT_LOG_DEBUG, "profileType=%hu", profApiData.profileType); |
| 70 | profApiData.entryTime = MsprofSysCycleTime(); | 207 | profApiData.entryTime = MsprofSysCycleTime(); |
| @@ -554,6 +691,11 @@ rtError_t ApiProfileDecorator::DevMalloc( | |||
| 554 | { | 691 | { |
| 555 | CallApiBegin(RT_PROF_API_DEV_MALLOC); | 692 | CallApiBegin(RT_PROF_API_DEV_MALLOC); |
| 556 | const rtError_t error = impl_->DevMalloc(devPtr, size, type, moduleId); | 693 | const rtError_t error = impl_->DevMalloc(devPtr, size, type, moduleId); |
| 694 | + if (error == RT_ERROR_NONE) { | ||
| 695 | + FillMemMngExtInfo( | ||
| 696 | + (devPtr == nullptr) ? 0U : RtPtrToValue(*devPtr), size, RT_PROF_MEM_MNG_TYPE_MALLOC, | ||
| 697 | + MSPROF_MEMORY_TYPE_DEVICE, nullptr); | ||
| 698 | + } | ||
| 557 | CallApiEnd(error); | 699 | CallApiEnd(error); |
| 558 | return error; | 700 | return error; |
| 559 | } | 701 | } |
| @@ -562,6 +704,9 @@ rtError_t ApiProfileDecorator::DevFree(void* const devPtr) | |||
| 562 | { | 704 | { |
| 563 | CallApiBegin(RT_PROF_API_DEV_FREE); | 705 | CallApiBegin(RT_PROF_API_DEV_FREE); |
| 564 | const rtError_t error = impl_->DevFree(devPtr); | 706 | const rtError_t error = impl_->DevFree(devPtr); |
| 707 | + if (error == RT_ERROR_NONE) { | ||
| 708 | + FillMemMngExtInfo(RtPtrToValue(devPtr), 0U, RT_PROF_MEM_MNG_TYPE_FREE, MSPROF_MEMORY_TYPE_DEVICE, nullptr); | ||
| 709 | + } | ||
| 565 | CallApiEnd(error); | 710 | CallApiEnd(error); |
| 566 | return error; | 711 | return error; |
| 567 | } | 712 | } |
| @@ -571,6 +716,11 @@ rtError_t ApiProfileDecorator::DevMallocCached( | |||
| 571 | { | 716 | { |
| 572 | CallApiBegin(RT_PROF_API_CAHCEDMEM_ALLOC); | 717 | CallApiBegin(RT_PROF_API_CAHCEDMEM_ALLOC); |
| 573 | const rtError_t error = impl_->DevMallocCached(devPtr, size, type, moduleId); | 718 | const rtError_t error = impl_->DevMallocCached(devPtr, size, type, moduleId); |
| 719 | + if (error == RT_ERROR_NONE) { | ||
| 720 | + FillMemMngExtInfo( | ||
| 721 | + (devPtr == nullptr) ? 0U : RtPtrToValue(*devPtr), size, RT_PROF_MEM_MNG_TYPE_MALLOC, | ||
| 722 | + MSPROF_MEMORY_TYPE_DEVICE, nullptr); | ||
| 723 | + } | ||
| 574 | CallApiEnd(error); | 724 | CallApiEnd(error); |
| 575 | return error; | 725 | return error; |
| 576 | } | 726 | } |
| @@ -604,6 +754,24 @@ rtError_t ApiProfileDecorator::HostMalloc(void** const hostPtr, const uint64_t s | |||
| 604 | { | 754 | { |
| 605 | CallApiBegin(RT_PROF_API_HOST_MALLOC); | 755 | CallApiBegin(RT_PROF_API_HOST_MALLOC); |
| 606 | const rtError_t error = impl_->HostMalloc(hostPtr, size, moduleId); | 756 | const rtError_t error = impl_->HostMalloc(hostPtr, size, moduleId); |
| 757 | + if (error == RT_ERROR_NONE) { | ||
| 758 | + FillMemMngExtInfo( | ||
| 759 | + (hostPtr == nullptr) ? 0U : RtPtrToValue(*hostPtr), size, RT_PROF_MEM_MNG_TYPE_MALLOC, | ||
| 760 | + MSPROF_MEMORY_TYPE_HOST, nullptr); | ||
| 761 | + } | ||
| 762 | + CallApiEnd(error); | ||
| 763 | + return error; | ||
| 764 | +} | ||
| 765 | + | ||
| 766 | +rtError_t ApiProfileDecorator::HostMallocWithCfg(void** const hostPtr, const uint64_t size, const rtMallocConfig_t* cfg) | ||
| 767 | +{ | ||
| 768 | + CallApiBegin(RT_PROF_API_HOST_MALLOC); | ||
| 769 | + const rtError_t error = impl_->HostMallocWithCfg(hostPtr, size, cfg); | ||
| 770 | + if (error == RT_ERROR_NONE) { | ||
| 771 | + FillMemMngExtInfo( | ||
| 772 | + (hostPtr == nullptr) ? 0U : RtPtrToValue(*hostPtr), size, RT_PROF_MEM_MNG_TYPE_MALLOC, | ||
| 773 | + MSPROF_MEMORY_TYPE_HOST, nullptr); | ||
| 774 | + } | ||
| 607 | CallApiEnd(error); | 775 | CallApiEnd(error); |
| 608 | return error; | 776 | return error; |
| 609 | } | 777 | } |
| @@ -612,6 +780,9 @@ rtError_t ApiProfileDecorator::HostFree(void* const hostPtr) | |||
| 612 | { | 780 | { |
| 613 | CallApiBegin(RT_PROF_API_HOST_FREE); | 781 | CallApiBegin(RT_PROF_API_HOST_FREE); |
| 614 | const rtError_t error = impl_->HostFree(hostPtr); | 782 | const rtError_t error = impl_->HostFree(hostPtr); |
| 783 | + if (error == RT_ERROR_NONE) { | ||
| 784 | + FillMemMngExtInfo(RtPtrToValue(hostPtr), 0U, RT_PROF_MEM_MNG_TYPE_FREE, MSPROF_MEMORY_TYPE_HOST, nullptr); | ||
| 785 | + } | ||
| 615 | CallApiEnd(error); | 786 | CallApiEnd(error); |
| 616 | return error; | 787 | return error; |
| 617 | } | 788 | } |
| @@ -621,6 +792,11 @@ rtError_t ApiProfileDecorator::ManagedMemAlloc( | |||
| 621 | { | 792 | { |
| 622 | CallApiBegin(RT_PROF_API_MANAGEDMEM_ALLOC); | 793 | CallApiBegin(RT_PROF_API_MANAGEDMEM_ALLOC); |
| 623 | const rtError_t error = impl_->ManagedMemAlloc(ptr, size, flag, moduleId); | 794 | const rtError_t error = impl_->ManagedMemAlloc(ptr, size, flag, moduleId); |
| 795 | + if (error == RT_ERROR_NONE) { | ||
| 796 | + FillMemMngExtInfo( | ||
| 797 | + (ptr == nullptr) ? 0U : RtPtrToValue(*ptr), size, RT_PROF_MEM_MNG_TYPE_MALLOC, MSPROF_MEMORY_TYPE_MANAGED, | ||
| 798 | + nullptr); | ||
| 799 | + } | ||
| 624 | CallApiEnd(error); | 800 | CallApiEnd(error); |
| 625 | return error; | 801 | return error; |
| 626 | } | 802 | } |
| @@ -629,6 +805,9 @@ rtError_t ApiProfileDecorator::ManagedMemFree(const void* const ptr) | |||
| 629 | { | 805 | { |
| 630 | CallApiBegin(RT_PROF_API_MANAGEDMEM_FREE); | 806 | CallApiBegin(RT_PROF_API_MANAGEDMEM_FREE); |
| 631 | const rtError_t error = impl_->ManagedMemFree(ptr); | 807 | const rtError_t error = impl_->ManagedMemFree(ptr); |
| 808 | + if (error == RT_ERROR_NONE) { | ||
| 809 | + FillMemMngExtInfo(RtPtrToValue(ptr), 0U, RT_PROF_MEM_MNG_TYPE_FREE, MSPROF_MEMORY_TYPE_MANAGED, nullptr); | ||
| 810 | + } | ||
| 632 | CallApiEnd(error); | 811 | CallApiEnd(error); |
| 633 | return error; | 812 | return error; |
| 634 | } | 813 | } |
| @@ -639,6 +818,9 @@ rtError_t ApiProfileDecorator::MemCopySync( | |||
| 639 | { | 818 | { |
| 640 | CallApiBegin(RT_PROF_API_MEM_CPY, cnt, kind); | 819 | CallApiBegin(RT_PROF_API_MEM_CPY, cnt, kind); |
| 641 | const rtError_t error = impl_->MemCopySync(dst, destMax, src, cnt, kind, checkKind); | 820 | const rtError_t error = impl_->MemCopySync(dst, destMax, src, cnt, kind, checkKind); |
| 821 | + if (error == RT_ERROR_NONE) { | ||
| 822 | + FillMemcpyExtInfo(cnt, static_cast<uint16_t>(kind), nullptr); | ||
| 823 | + } | ||
| 642 | CallApiEnd(error); | 824 | CallApiEnd(error); |
| 643 | return error; | 825 | return error; |
| 644 | } | 826 | } |
| @@ -662,9 +844,36 @@ rtError_t ApiProfileDecorator::MemcpyAsync( | |||
| 662 | 844 | ||
| 663 | CallApiBegin(profileType, cnt, kind); | 845 | CallApiBegin(profileType, cnt, kind); |
| 664 | const rtError_t error = impl_->MemcpyAsync(dst, destMax, src, cnt, kind, stm, cfgInfo, addrCfg); | 846 | const rtError_t error = impl_->MemcpyAsync(dst, destMax, src, cnt, kind, stm, cfgInfo, addrCfg); |
| 847 | + if (error == RT_ERROR_NONE) { | ||
| 848 | + FillMemcpyExtInfo(cnt, static_cast<uint16_t>(kind), stm); | ||
| 849 | + } | ||
| 665 | CallApiEnd(error); | 850 | CallApiEnd(error); |
| 666 | return error; | 851 | return error; |
| 667 | } | 852 | } |
| 853 | +rtError_t ApiProfileDecorator::MemsetD32( | ||
| 854 | + void* const dst, const uint64_t destMax, const uint32_t value, const uint64_t count) | ||
| 855 | +{ | ||
| 856 | + CallApiBegin(RT_PROF_API_Memset); | ||
| 857 | + const rtError_t error = impl_->MemsetD32(dst, destMax, value, count); | ||
| 858 | + if (error == RT_ERROR_NONE) { | ||
| 859 | + FillMemsetExtInfo(count * static_cast<uint64_t>(sizeof(uint32_t)), value, nullptr); | ||
| 860 | + } | ||
| 861 | + CallApiEnd(error); | ||
| 862 | + return error; | ||
| 863 | +} | ||
| 864 | + | ||
| 865 | +rtError_t ApiProfileDecorator::MemsetD32Async( | ||
| 866 | + void* const dst, const uint64_t destMax, const uint32_t value, const uint64_t count, Stream* const stm) | ||
| 867 | +{ | ||
| 868 | + CallApiBegin(RT_PROF_API_MemsetAsync); | ||
| 869 | + const rtError_t error = impl_->MemsetD32Async(dst, destMax, value, count, stm); | ||
| 870 | + if (error == RT_ERROR_NONE) { | ||
| 871 | + FillMemsetExtInfo(count * static_cast<uint64_t>(sizeof(uint32_t)), value, stm); | ||
| 872 | + } | ||
| 873 | + CallApiEnd(error); | ||
| 874 | + return error; | ||
| 875 | +} | ||
| 876 | + | ||
| 668 | rtError_t ApiProfileDecorator::GetDevArgsAddr( | 877 | rtError_t ApiProfileDecorator::GetDevArgsAddr( |
| 669 | Stream* const stm, rtArgsEx_t* const argsInfo, void** const devArgsAddr, void** const argsHandle) | 878 | Stream* const stm, rtArgsEx_t* const argsInfo, void** const devArgsAddr, void** const argsHandle) |
| 670 | { | 879 | { |
| @@ -674,6 +883,30 @@ rtError_t ApiProfileDecorator::GetDevArgsAddr( | |||
| 674 | return error; | 883 | return error; |
| 675 | } | 884 | } |
| 676 | 885 | ||
| 886 | +rtError_t ApiProfileDecorator::MemSetSync( | ||
| 887 | + const void* const devPtr, const uint64_t destMax, const uint32_t val, const uint64_t cnt) | ||
| 888 | +{ | ||
| 889 | + CallApiBegin(RT_PROF_API_Memset); | ||
| 890 | + const rtError_t error = impl_->MemSetSync(devPtr, destMax, val, cnt); | ||
| 891 | + if (error == RT_ERROR_NONE) { | ||
| 892 | + FillMemsetExtInfo(cnt, val, nullptr); | ||
| 893 | + } | ||
| 894 | + CallApiEnd(error); | ||
| 895 | + return error; | ||
| 896 | +} | ||
| 897 | + | ||
| 898 | +rtError_t ApiProfileDecorator::MemsetAsync( | ||
| 899 | + void* const ptr, const uint64_t destMax, const uint32_t val, const uint64_t cnt, Stream* const stm) | ||
| 900 | +{ | ||
| 901 | + CallApiBegin(RT_PROF_API_MemsetAsync); | ||
| 902 | + const rtError_t error = impl_->MemsetAsync(ptr, destMax, val, cnt, stm); | ||
| 903 | + if (error == RT_ERROR_NONE) { | ||
| 904 | + FillMemsetExtInfo(cnt, val, stm); | ||
| 905 | + } | ||
| 906 | + CallApiEnd(error); | ||
| 907 | + return error; | ||
| 908 | +} | ||
| 909 | + | ||
| 677 | rtError_t ApiProfileDecorator::ReduceAsync( | 910 | rtError_t ApiProfileDecorator::ReduceAsync( |
| 678 | void* const dst, const void* const src, const uint64_t cnt, const rtRecudeKind_t kind, const rtDataType_t type, | 911 | void* const dst, const void* const src, const uint64_t cnt, const rtRecudeKind_t kind, const rtDataType_t type, |
| 679 | Stream* const stm, const rtTaskCfgInfo_t* const cfgInfo) | 912 | Stream* const stm, const rtTaskCfgInfo_t* const cfgInfo) |
| @@ -717,6 +950,9 @@ rtError_t ApiProfileDecorator::MemCopy2DSync( | |||
| 717 | { | 950 | { |
| 718 | CallApiBegin(RT_PROF_API_MEM_CPY2D); | 951 | CallApiBegin(RT_PROF_API_MEM_CPY2D); |
| 719 | const rtError_t error = impl_->MemCopy2DSync(dst, dstPitch, src, srcPitch, width, height, kind, newKind); | 952 | const rtError_t error = impl_->MemCopy2DSync(dst, dstPitch, src, srcPitch, width, height, kind, newKind); |
| 953 | + if (error == RT_ERROR_NONE) { | ||
| 954 | + FillMemcpyExtInfo(width * height, static_cast<uint16_t>(kind), nullptr); | ||
| 955 | + } | ||
| 720 | CallApiEnd(error); | 956 | CallApiEnd(error); |
| 721 | return error; | 957 | return error; |
| 722 | } | 958 | } |
| @@ -727,6 +963,9 @@ rtError_t ApiProfileDecorator::MemCopy2DAsync( | |||
| 727 | { | 963 | { |
| 728 | CallApiBegin(RT_PROF_API_MEM_CPY2D_ASYNC, width * height, kind); | 964 | CallApiBegin(RT_PROF_API_MEM_CPY2D_ASYNC, width * height, kind); |
| 729 | const rtError_t error = impl_->MemCopy2DAsync(dst, dstPitch, src, srcPitch, width, height, stm, kind, newKind); | 965 | const rtError_t error = impl_->MemCopy2DAsync(dst, dstPitch, src, srcPitch, width, height, stm, kind, newKind); |
| 966 | + if (error == RT_ERROR_NONE) { | ||
| 967 | + FillMemcpyExtInfo(width * height, static_cast<uint16_t>(kind), stm); | ||
| 968 | + } | ||
| 730 | CallApiEnd(error); | 969 | CallApiEnd(error); |
| 731 | return error; | 970 | return error; |
| 732 | } | 971 | } |
| @@ -741,6 +980,19 @@ rtError_t ApiProfileDecorator::MemcpyAsyncPtr( | |||
| 741 | return error; | 980 | return error; |
| 742 | } | 981 | } |
| 743 | 982 | ||
| 983 | +rtError_t ApiProfileDecorator::SetMemcpyDesc( | ||
| 984 | + rtMemcpyDesc_t desc, const void* const srcAddr, const void* const dstAddr, const size_t count, | ||
| 985 | + const rtMemcpyKind kind, rtMemcpyConfig_t* const config) | ||
| 986 | +{ | ||
| 987 | + CallApiBegin(RT_PROF_API_SET_MEMCPY_DESC); | ||
| 988 | + const rtError_t error = impl_->SetMemcpyDesc(desc, srcAddr, dstAddr, count, kind, config); | ||
| 989 | + if (error == RT_ERROR_NONE) { | ||
| 990 | + FillMemcpyExtInfo(static_cast<uint64_t>(count), static_cast<uint16_t>(kind), nullptr); | ||
| 991 | + } | ||
| 992 | + CallApiEnd(error); | ||
| 993 | + return error; | ||
| 994 | +} | ||
| 995 | + | ||
| 744 | rtError_t ApiProfileDecorator::MemcpyHostTask( | 996 | rtError_t ApiProfileDecorator::MemcpyHostTask( |
| 745 | void* const dst, const uint64_t destMax, const void* const src, const uint64_t cnt, const rtMemcpyKind_t kind, | 997 | void* const dst, const uint64_t destMax, const void* const src, const uint64_t cnt, const rtMemcpyKind_t kind, |
| 746 | Stream* const stm) | 998 | Stream* const stm) |
| @@ -751,6 +1003,55 @@ rtError_t ApiProfileDecorator::MemcpyHostTask( | |||
| 751 | return error; | 1003 | return error; |
| 752 | } | 1004 | } |
| 753 | 1005 | ||
| 1006 | +rtError_t ApiProfileDecorator::ReserveMemAddress( | ||
| 1007 | + void** devPtr, size_t size, size_t alignment, void* devAddr, uint64_t flags) | ||
| 1008 | +{ | ||
| 1009 | + CallApiBegin(RT_PROF_API_DEV_MALLOC); | ||
| 1010 | + const rtError_t error = impl_->ReserveMemAddress(devPtr, size, alignment, devAddr, flags); | ||
| 1011 | + if (error == RT_ERROR_NONE) { | ||
| 1012 | + FillMemMngExtInfo( | ||
| 1013 | + (devPtr == nullptr) ? 0U : RtPtrToValue(*devPtr), static_cast<uint64_t>(size), RT_PROF_MEM_MNG_TYPE_MALLOC, | ||
| 1014 | + MSPROF_MEMORY_TYPE_DEVICE, nullptr); | ||
| 1015 | + } | ||
| 1016 | + CallApiEnd(error); | ||
| 1017 | + return error; | ||
| 1018 | +} | ||
| 1019 | + | ||
| 1020 | +rtError_t ApiProfileDecorator::ReleaseMemAddress(void* devPtr) | ||
| 1021 | +{ | ||
| 1022 | + CallApiBegin(RT_PROF_API_DEV_FREE); | ||
| 1023 | + const rtError_t error = impl_->ReleaseMemAddress(devPtr); | ||
| 1024 | + if (error == RT_ERROR_NONE) { | ||
| 1025 | + FillMemMngExtInfo(RtPtrToValue(devPtr), 0U, RT_PROF_MEM_MNG_TYPE_FREE, MSPROF_MEMORY_TYPE_DEVICE, nullptr); | ||
| 1026 | + } | ||
| 1027 | + CallApiEnd(error); | ||
| 1028 | + return error; | ||
| 1029 | +} | ||
| 1030 | + | ||
| 1031 | +rtError_t ApiProfileDecorator::MallocPhysical(rtDrvMemHandle* handle, size_t size, rtDrvMemProp_t* prop, uint64_t flags) | ||
| 1032 | +{ | ||
| 1033 | + CallApiBegin(RT_PROF_API_DEV_MALLOC); | ||
| 1034 | + const rtError_t error = impl_->MallocPhysical(handle, size, prop, flags); | ||
| 1035 | + if (error == RT_ERROR_NONE) { | ||
| 1036 | + FillMemMngExtInfo( | ||
| 1037 | + (handle == nullptr) ? 0U : RtPtrToValue(*handle), static_cast<uint64_t>(size), RT_PROF_MEM_MNG_TYPE_MALLOC, | ||
| 1038 | + MSPROF_MEMORY_TYPE_DEVICE, nullptr); | ||
| 1039 | + } | ||
| 1040 | + CallApiEnd(error); | ||
| 1041 | + return error; | ||
| 1042 | +} | ||
| 1043 | + | ||
| 1044 | +rtError_t ApiProfileDecorator::FreePhysical(rtDrvMemHandle handle) | ||
| 1045 | +{ | ||
| 1046 | + CallApiBegin(RT_PROF_API_DEV_FREE); | ||
| 1047 | + const rtError_t error = impl_->FreePhysical(handle); | ||
| 1048 | + if (error == RT_ERROR_NONE) { | ||
| 1049 | + FillMemMngExtInfo(RtPtrToValue(handle), 0U, RT_PROF_MEM_MNG_TYPE_FREE, MSPROF_MEMORY_TYPE_DEVICE, nullptr); | ||
| 1050 | + } | ||
| 1051 | + CallApiEnd(error); | ||
| 1052 | + return error; | ||
| 1053 | +} | ||
| 1054 | + | ||
| 754 | rtError_t ApiProfileDecorator::SetDevice(const int32_t devId) | 1055 | rtError_t ApiProfileDecorator::SetDevice(const int32_t devId) |
| 755 | { | 1056 | { |
| 756 | CallApiBegin(RT_PROF_API_SET_DEVICE); | 1057 | CallApiBegin(RT_PROF_API_SET_DEVICE); |
| @@ -1171,6 +1472,11 @@ rtError_t ApiProfileDecorator::DevMalloc( | |||
| 1171 | { | 1472 | { |
| 1172 | CallApiBegin(RT_PROF_API_DEV_MALLOC); | 1473 | CallApiBegin(RT_PROF_API_DEV_MALLOC); |
| 1173 | const rtError_t error = impl_->DevMalloc(devPtr, size, policy, advise, cfg); | 1474 | const rtError_t error = impl_->DevMalloc(devPtr, size, policy, advise, cfg); |
| 1475 | + if (error == RT_ERROR_NONE) { | ||
| 1476 | + FillMemMngExtInfo( | ||
| 1477 | + (devPtr == nullptr) ? 0U : RtPtrToValue(*devPtr), size, RT_PROF_MEM_MNG_TYPE_MALLOC, | ||
| 1478 | + MSPROF_MEMORY_TYPE_DEVICE, nullptr); | ||
| 1479 | + } | ||
| 1174 | CallApiEnd(error); | 1480 | CallApiEnd(error); |
| 1175 | return error; | 1481 | return error; |
| 1176 | } | 1482 | } |
| @@ -1266,6 +1572,9 @@ rtError_t ApiProfileDecorator::MemcpyBatch( | |||
| 1266 | { | 1572 | { |
| 1267 | CallApiBegin(RT_PROF_API_MEMCPY_BATCH); | 1573 | CallApiBegin(RT_PROF_API_MEMCPY_BATCH); |
| 1268 | const rtError_t error = impl_->MemcpyBatch(dsts, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx); | 1574 | const rtError_t error = impl_->MemcpyBatch(dsts, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx); |
| 1575 | + if (error == RT_ERROR_NONE) { | ||
| 1576 | + FillMemcpyBatchExtInfoByCopyKind(sizes, count, attrs, attrsIdxs, numAttrs, nullptr); | ||
| 1577 | + } | ||
| 1269 | CallApiEnd(error); | 1578 | CallApiEnd(error); |
| 1270 | return error; | 1579 | return error; |
| 1271 | } | 1580 | } |
| @@ -1312,6 +1621,9 @@ rtError_t ApiProfileDecorator::MemcpyBatchAsync( | |||
| 1312 | CallApiBegin(RT_PROF_API_MEMCPY_ASYNC_BATCH); | 1621 | CallApiBegin(RT_PROF_API_MEMCPY_ASYNC_BATCH); |
| 1313 | const rtError_t error = | 1622 | const rtError_t error = |
| 1314 | impl_->MemcpyBatchAsync(dsts, destMaxs, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx, stm); | 1623 | impl_->MemcpyBatchAsync(dsts, destMaxs, srcs, sizes, count, attrs, attrsIdxs, numAttrs, failIdx, stm); |
| 1624 | + if (error == RT_ERROR_NONE) { | ||
| 1625 | + FillMemcpyBatchExtInfoByCopyKind(sizes, count, attrs, attrsIdxs, numAttrs, stm); | ||
| 1626 | + } | ||
| 1315 | CallApiEnd(error); | 1627 | CallApiEnd(error); |
| 1316 | return error; | 1628 | return error; |
| 1317 | } | 1629 | } |
| @@ -115,6 +115,8 @@ public: | |||
| 115 | const uint16_t moduleId = MODULEID_RUNTIME) override; | 115 | const uint16_t moduleId = MODULEID_RUNTIME) override; |
| 116 | rtError_t HostMalloc( | 116 | rtError_t HostMalloc( |
| 117 | void** const hostPtr, const uint64_t size, const uint16_t moduleId = MODULEID_RUNTIME) override; | 117 | void** const hostPtr, const uint64_t size, const uint16_t moduleId = MODULEID_RUNTIME) override; |
| 118 | + rtError_t HostMallocWithCfg( | ||
| 119 | + void** const hostPtr, const uint64_t size, const rtMallocConfig_t* cfg = nullptr) override; | ||
| 118 | rtError_t HostFree(void* const hostPtr) override; | 120 | rtError_t HostFree(void* const hostPtr) override; |
| 119 | rtError_t ManagedMemAlloc( | 121 | rtError_t ManagedMemAlloc( |
| 120 | void** const ptr, const uint64_t size, const uint32_t flag, | 122 | void** const ptr, const uint64_t size, const uint32_t flag, |
| @@ -129,6 +131,10 @@ public: | |||
| 129 | Stream* const stm, const rtTaskCfgInfo_t* const cfgInfo = nullptr, | 131 | Stream* const stm, const rtTaskCfgInfo_t* const cfgInfo = nullptr, |
| 130 | const rtD2DAddrCfgInfo_t* const addrCfg = nullptr, bool checkKind = true, | 132 | const rtD2DAddrCfgInfo_t* const addrCfg = nullptr, bool checkKind = true, |
| 131 | const rtMemcpyConfig_t* const memcpyConfig = nullptr) override; | 133 | const rtMemcpyConfig_t* const memcpyConfig = nullptr) override; |
| 134 | + rtError_t MemsetD32(void* const dst, const uint64_t destMax, const uint32_t value, const uint64_t count) override; | ||
| 135 | + rtError_t MemsetD32Async( | ||
| 136 | + void* const dst, const uint64_t destMax, const uint32_t value, const uint64_t count, | ||
| 137 | + Stream* const stm) override; | ||
| 132 | rtError_t MemcpyAsyncPtr( | 138 | rtError_t MemcpyAsyncPtr( |
| 133 | void* const memcpyAddrInfo, const uint64_t destMax, const uint64_t count, Stream* const stm, | 139 | void* const memcpyAddrInfo, const uint64_t destMax, const uint64_t count, Stream* const stm, |
| 134 | const rtTaskCfgInfo_t* const cfgInfo, const bool isMemcpyDesc = false) override; | 140 | const rtTaskCfgInfo_t* const cfgInfo, const bool isMemcpyDesc = false) override; |
| @@ -138,6 +144,10 @@ public: | |||
| 138 | rtError_t ReduceAsyncV2( | 144 | rtError_t ReduceAsyncV2( |
| 139 | void* const dst, const void* const src, const uint64_t cnt, const rtRecudeKind_t kind, const rtDataType_t type, | 145 | void* const dst, const void* const src, const uint64_t cnt, const rtRecudeKind_t kind, const rtDataType_t type, |
| 140 | Stream* const stm, void* const overflowAddr) override; | 146 | Stream* const stm, void* const overflowAddr) override; |
| 147 | + rtError_t MemSetSync( | ||
| 148 | + const void* const devPtr, const uint64_t destMax, const uint32_t val, const uint64_t cnt) override; | ||
| 149 | + rtError_t MemsetAsync( | ||
| 150 | + void* const ptr, const uint64_t destMax, const uint32_t val, const uint64_t cnt, Stream* const stm) override; | ||
| 141 | rtError_t MemCopy2DSync( | 151 | rtError_t MemCopy2DSync( |
| 142 | void* const dst, const uint64_t dstPitch, const void* const src, const uint64_t srcPitch, const uint64_t width, | 152 | void* const dst, const uint64_t dstPitch, const void* const src, const uint64_t srcPitch, const uint64_t width, |
| 143 | const uint64_t height, const rtMemcpyKind_t kind = RT_MEMCPY_RESERVED, | 153 | const uint64_t height, const rtMemcpyKind_t kind = RT_MEMCPY_RESERVED, |
| @@ -158,6 +168,13 @@ public: | |||
| 158 | const void* const devAddr, const uint64_t value, const uint32_t flag, Stream* const stm) override; | 168 | const void* const devAddr, const uint64_t value, const uint32_t flag, Stream* const stm) override; |
| 159 | rtError_t GetDevArgsAddr( | 169 | rtError_t GetDevArgsAddr( |
| 160 | Stream* const stm, rtArgsEx_t* const argsInfo, void** const devArgsAddr, void** const argsHandle) override; | 170 | Stream* const stm, rtArgsEx_t* const argsInfo, void** const devArgsAddr, void** const argsHandle) override; |
| 171 | + rtError_t ReserveMemAddress(void** devPtr, size_t size, size_t alignment, void* devAddr, uint64_t flags) override; | ||
| 172 | + rtError_t ReleaseMemAddress(void* devPtr) override; | ||
| 173 | + rtError_t MallocPhysical(rtDrvMemHandle* handle, size_t size, rtDrvMemProp_t* prop, uint64_t flags) override; | ||
| 174 | + rtError_t FreePhysical(rtDrvMemHandle handle) override; | ||
| 175 | + rtError_t SetMemcpyDesc( | ||
| 176 | + rtMemcpyDesc_t desc, const void* const srcAddr, const void* const dstAddr, const size_t count, | ||
| 177 | + const rtMemcpyKind kind, rtMemcpyConfig_t* const config) override; | ||
| 161 | 178 | ||
| 162 | // new memory api | 179 | // new memory api |
| 163 | rtError_t DevMalloc( | 180 | rtError_t DevMalloc( |
| @@ -291,6 +308,15 @@ public: | |||
| 291 | private: | 308 | private: |
| 292 | void CallApiBegin(const uint16_t profileType, const uint64_t dataSize = 0, const uint16_t cpyDirection = 0) const; | 309 | void CallApiBegin(const uint16_t profileType, const uint64_t dataSize = 0, const uint16_t cpyDirection = 0) const; |
| 293 | void CallApiEnd(const rtError_t retCode, const uint32_t devId = static_cast<uint32_t>(UINT16_MAX)) const; | 310 | void CallApiEnd(const rtError_t retCode, const uint32_t devId = static_cast<uint32_t>(UINT16_MAX)) const; |
| 311 | + RuntimeProfApiData* GetReportProfApiData() const; | ||
| 312 | + void FillMemcpyExtInfo(const uint64_t bytes, const uint16_t copyKind, const Stream* const stm) const; | ||
| 313 | + void FillMemsetExtInfo(const uint64_t bytes, const uint32_t value, const Stream* const stm) const; | ||
| 314 | + void FillMemMngExtInfo( | ||
| 315 | + const uint64_t address, const uint64_t size, const uint16_t memMngType, const uint32_t memoryType, | ||
| 316 | + const Stream* const stm) const; | ||
| 317 | + void FillMemcpyBatchExtInfoByCopyKind( | ||
| 318 | + const size_t* const sizes, const size_t count, const rtMemcpyBatchAttr* const attrs, | ||
| 319 | + const size_t* const attrsIdxs, const size_t numAttrs, const Stream* const stm) const; | ||
| 294 | 320 | ||
| 295 | private: | 321 | private: |
| 296 | Profiler* profiler_; | 322 | Profiler* profiler_; |
| @@ -22,6 +22,9 @@ __THREAD_LOCAL__ uint32_t g_lastType = UINT32_MAX; | |||
| 22 | __THREAD_LOCAL__ uint32_t g_lastLen = UINT32_MAX; | 22 | __THREAD_LOCAL__ uint32_t g_lastLen = UINT32_MAX; |
| 23 | __THREAD_LOCAL__ const void* g_lastDataPtr = nullptr; | 23 | __THREAD_LOCAL__ const void* g_lastDataPtr = nullptr; |
| 24 | __THREAD_LOCAL__ bool g_lastSuccess = false; | 24 | __THREAD_LOCAL__ bool g_lastSuccess = false; |
| 25 | +constexpr uint32_t COMPACT_INFO_CAPTURE_NUM = 4U; | ||
| 26 | +__THREAD_LOCAL__ uint32_t g_compactCount = 0U; | ||
| 27 | +__THREAD_LOCAL__ MsprofCompactInfo g_compactInfos[COMPACT_INFO_CAPTURE_NUM] = {}; | ||
| 25 | 28 | ||
| 26 | class ProfilingAgentTest : public testing::Test { | 29 | class ProfilingAgentTest : public testing::Test { |
| 27 | protected: | 30 | protected: |
| @@ -44,6 +47,10 @@ protected: | |||
| 44 | g_lastLen = 0; | 47 | g_lastLen = 0; |
| 45 | g_lastDataPtr = nullptr; | 48 | g_lastDataPtr = nullptr; |
| 46 | g_lastSuccess = false; | 49 | g_lastSuccess = false; |
| 50 | + g_compactCount = 0U; | ||
| 51 | + for (uint32_t i = 0U; i < COMPACT_INFO_CAPTURE_NUM; ++i) { | ||
| 52 | + g_compactInfos[i] = {}; | ||
| 53 | + } | ||
| 47 | } | 54 | } |
| 48 | }; | 55 | }; |
| 49 | 56 | ||
| @@ -81,6 +88,15 @@ int32_t MsprofReporterCallbackErrorStub(uint32_t moduleId, uint32_t type, void* | |||
| 81 | return MSPROF_ERROR; | 88 | return MSPROF_ERROR; |
| 82 | } | 89 | } |
| 83 | 90 | ||
| 91 | +int32_t MsprofReportCompactInfoCaptureStub(uint32_t agingFlag, const VOID_PTR data, uint32_t length) | ||
| 92 | +{ | ||
| 93 | + if ((data != nullptr) && (length == sizeof(MsprofCompactInfo)) && (g_compactCount < COMPACT_INFO_CAPTURE_NUM)) { | ||
| 94 | + g_compactInfos[g_compactCount] = *static_cast<const MsprofCompactInfo*>(data); | ||
| 95 | + } | ||
| 96 | + ++g_compactCount; | ||
| 97 | + return MSPROF_ERROR_NONE; | ||
| 98 | +} | ||
| 99 | + | ||
| 84 | TEST_F(ProfilingAgentTest, PROF_NULL) | 100 | TEST_F(ProfilingAgentTest, PROF_NULL) |
| 85 | { | 101 | { |
| 86 | ProfilingAgent::Instance().SetMsprofReporterCallback(nullptr); | 102 | ProfilingAgent::Instance().SetMsprofReporterCallback(nullptr); |
| @@ -193,4 +209,139 @@ TEST_F(ProfilingAgentTest, PROF_REPORT_FAIL) | |||
| 193 | ret = ProfilingAgent::Instance().UnInit(); | 209 | ret = ProfilingAgent::Instance().UnInit(); |
| 194 | ASSERT_EQ(ret, RT_ERROR_NONE); | 210 | ASSERT_EQ(ret, RT_ERROR_NONE); |
| 195 | } | 211 | } |
| 212 | + | ||
| 213 | +TEST_F(ProfilingAgentTest, PROF_REPORT_EXT_MEMCPY_INFO) | ||
| 214 | +{ | ||
| 215 | + MOCKER(MsprofReportCompactInfo).stubs().will(invoke(MsprofReportCompactInfoCaptureStub)); | ||
| 216 | + RuntimeProfApiData profData = {}; | ||
| 217 | + profData.threadId = 10U; | ||
| 218 | + profData.entryTime = 100U; | ||
| 219 | + profData.exitTime = 200U; | ||
| 220 | + profData.profileType = RT_PROF_API_MEM_CPY; | ||
| 221 | + profData.extInfoCount = 1U; | ||
| 222 | + profData.extInfos[0].extInfoType = RT_PROFILE_TYPE_MEMCPY_EXT_INFO; | ||
| 223 | + profData.extInfos[0].extInfo.memcpyInfo.bytes = 1024U; | ||
| 224 | + profData.extInfos[0].extInfo.memcpyInfo.copyKind = RT_MEMCPY_HOST_TO_DEVICE; | ||
| 225 | + profData.extInfos[0].extInfo.memcpyInfo.deviceId = 2U; | ||
| 226 | + profData.extInfos[0].extInfo.memcpyInfo.streamId = 3U; | ||
| 227 | + | ||
| 228 | + ProfilingAgent::Instance().ReportProfApi(0, profData); | ||
| 229 | + | ||
| 230 | + ASSERT_EQ(g_compactCount, 1U); | ||
| 231 | + EXPECT_EQ(g_compactInfos[0].type, RT_PROFILE_TYPE_MEMCPY_EXT_INFO); | ||
| 232 | + EXPECT_EQ(g_compactInfos[0].dataLen, sizeof(MsprofMemcpyInfo)); | ||
| 233 | + EXPECT_EQ(g_compactInfos[0].data.memcpyInfo.bytes, 1024U); | ||
| 234 | + EXPECT_EQ(g_compactInfos[0].data.memcpyInfo.copyKind, RT_MEMCPY_HOST_TO_DEVICE); | ||
| 235 | + EXPECT_EQ(g_compactInfos[0].data.memcpyInfo.deviceId, 2U); | ||
| 236 | + EXPECT_EQ(g_compactInfos[0].data.memcpyInfo.streamId, 3U); | ||
| 237 | +} | ||
| 238 | + | ||
| 239 | +TEST_F(ProfilingAgentTest, PROF_REPORT_EXT_MEMSET_INFO) | ||
| 240 | +{ | ||
| 241 | + MOCKER(MsprofReportCompactInfo).stubs().will(invoke(MsprofReportCompactInfoCaptureStub)); | ||
| 242 | + RuntimeProfApiData profData = {}; | ||
| 243 | + profData.threadId = 11U; | ||
| 244 | + profData.entryTime = 100U; | ||
| 245 | + profData.exitTime = 200U; | ||
| 246 | + profData.profileType = RT_PROF_API_Memset; | ||
| 247 | + profData.extInfoCount = 1U; | ||
| 248 | + profData.extInfos[0].extInfoType = RT_PROFILE_TYPE_MEMSET_INFO; | ||
| 249 | + profData.extInfos[0].extInfo.memsetInfo.bytes = 2048U; | ||
| 250 | + profData.extInfos[0].extInfo.memsetInfo.value = -1; | ||
| 251 | + profData.extInfos[0].extInfo.memsetInfo.deviceId = 4U; | ||
| 252 | + profData.extInfos[0].extInfo.memsetInfo.streamId = 5U; | ||
| 253 | + profData.extInfos[0].extInfo.memsetInfo.rsv[0] = 0U; | ||
| 254 | + profData.extInfos[0].extInfo.memsetInfo.rsv[1] = 0U; | ||
| 255 | + profData.extInfos[0].extInfo.memsetInfo.rsv[2] = 0U; | ||
| 256 | + | ||
| 257 | + ProfilingAgent::Instance().ReportProfApi(0, profData); | ||
| 258 | + | ||
| 259 | + ASSERT_EQ(g_compactCount, 1U); | ||
| 260 | + EXPECT_EQ(g_compactInfos[0].type, RT_PROFILE_TYPE_MEMSET_INFO); | ||
| 261 | + EXPECT_EQ(g_compactInfos[0].dataLen, sizeof(MsprofMemsetInfo)); | ||
| 262 | + EXPECT_EQ(g_compactInfos[0].data.memsetInfo.bytes, 2048U); | ||
| 263 | + EXPECT_EQ(g_compactInfos[0].data.memsetInfo.value, -1); | ||
| 264 | + EXPECT_EQ(g_compactInfos[0].data.memsetInfo.deviceId, 4U); | ||
| 265 | + EXPECT_EQ(g_compactInfos[0].data.memsetInfo.streamId, 5U); | ||
| 266 | + EXPECT_EQ(g_compactInfos[0].data.memsetInfo.rsv[0], 0U); | ||
| 267 | + EXPECT_EQ(g_compactInfos[0].data.memsetInfo.rsv[1], 0U); | ||
| 268 | + EXPECT_EQ(g_compactInfos[0].data.memsetInfo.rsv[2], 0U); | ||
| 269 | +} | ||
| 270 | + | ||
| 271 | +TEST_F(ProfilingAgentTest, PROF_REPORT_EXT_MEMMNG_INFO) | ||
| 272 | +{ | ||
| 273 | + MOCKER(MsprofReportCompactInfo).stubs().will(invoke(MsprofReportCompactInfoCaptureStub)); | ||
| 274 | + RuntimeProfApiData profData = {}; | ||
| 275 | + profData.threadId = 12U; | ||
| 276 | + profData.entryTime = 300U; | ||
| 277 | + profData.exitTime = 400U; | ||
| 278 | + profData.profileType = RT_PROF_API_DEV_MALLOC; | ||
| 279 | + profData.extInfoCount = 1U; | ||
| 280 | + profData.extInfos[0].extInfoType = RT_PROFILE_TYPE_MEMMNG_INFO; | ||
| 281 | + profData.extInfos[0].extInfo.memMngInfo.address = 0x1234U; | ||
| 282 | + profData.extInfos[0].extInfo.memMngInfo.size = 4096U; | ||
| 283 | + profData.extInfos[0].extInfo.memMngInfo.memoryType = MSPROF_MEMORY_TYPE_DEVICE; | ||
| 284 | + profData.extInfos[0].extInfo.memMngInfo.memMngType = RT_PROF_MEM_MNG_TYPE_MALLOC; | ||
| 285 | + profData.extInfos[0].extInfo.memMngInfo.deviceId = 6U; | ||
| 286 | + profData.extInfos[0].extInfo.memMngInfo.streamId = 7U; | ||
| 287 | + profData.extInfos[0].extInfo.memMngInfo.rsv = 0U; | ||
| 288 | + | ||
| 289 | + ProfilingAgent::Instance().ReportProfApi(0, profData); | ||
| 290 | + | ||
| 291 | + ASSERT_EQ(g_compactCount, 1U); | ||
| 292 | + EXPECT_EQ(g_compactInfos[0].type, RT_PROFILE_TYPE_MEMMNG_INFO); | ||
| 293 | + EXPECT_EQ(g_compactInfos[0].dataLen, sizeof(MsprofMemMngInfo)); | ||
| 294 | + EXPECT_EQ(g_compactInfos[0].data.memMngInfo.address, 0x1234U); | ||
| 295 | + EXPECT_EQ(g_compactInfos[0].data.memMngInfo.size, 4096U); | ||
| 296 | + EXPECT_EQ(g_compactInfos[0].data.memMngInfo.memoryType, MSPROF_MEMORY_TYPE_DEVICE); | ||
| 297 | + EXPECT_EQ(g_compactInfos[0].data.memMngInfo.memMngType, RT_PROF_MEM_MNG_TYPE_MALLOC); | ||
| 298 | + EXPECT_EQ(g_compactInfos[0].data.memMngInfo.deviceId, 6U); | ||
| 299 | + EXPECT_EQ(g_compactInfos[0].data.memMngInfo.streamId, 7U); | ||
| 300 | + EXPECT_EQ(g_compactInfos[0].data.memMngInfo.rsv, 0U); | ||
| 301 | +} | ||
| 302 | + | ||
| 303 | +TEST_F(ProfilingAgentTest, PROF_REPORT_UNKNOWN_EXT_INFO) | ||
| 304 | +{ | ||
| 305 | + MOCKER(MsprofReportCompactInfo).stubs().will(invoke(MsprofReportCompactInfoCaptureStub)); | ||
| 306 | + RuntimeProfApiData profData = {}; | ||
| 307 | + profData.threadId = 13U; | ||
| 308 | + profData.entryTime = 100U; | ||
| 309 | + profData.exitTime = 200U; | ||
| 310 | + profData.profileType = RT_PROF_API_MEM_CPY; | ||
| 311 | + profData.extInfoCount = 1U; | ||
| 312 | + profData.extInfos[0].extInfoType = RT_PROFILE_TYPE_MAX; | ||
| 313 | + | ||
| 314 | + ProfilingAgent::Instance().ReportProfApi(0, profData); | ||
| 315 | + | ||
| 316 | + EXPECT_EQ(g_compactCount, 0U); | ||
| 317 | +} | ||
| 318 | + | ||
| 319 | +TEST_F(ProfilingAgentTest, PROF_REPORT_BATCH_EXT_MEMCPY_INFO) | ||
| 320 | +{ | ||
| 321 | + MOCKER(MsprofReportCompactInfo).stubs().will(invoke(MsprofReportCompactInfoCaptureStub)); | ||
| 322 | + RuntimeProfApiData profData = {}; | ||
| 323 | + profData.threadId = 14U; | ||
| 324 | + profData.entryTime = 100U; | ||
| 325 | + profData.exitTime = 200U; | ||
| 326 | + profData.profileType = RT_PROF_API_MEMCPY_BATCH; | ||
| 327 | + profData.extInfoCount = 2U; | ||
| 328 | + profData.extInfos[0].extInfoType = RT_PROFILE_TYPE_MEMCPY_EXT_INFO; | ||
| 329 | + profData.extInfos[0].extInfo.memcpyInfo.bytes = 30U; | ||
| 330 | + profData.extInfos[0].extInfo.memcpyInfo.copyKind = RT_MEMCPY_KIND_HOST_TO_DEVICE; | ||
| 331 | + profData.extInfos[1].extInfoType = RT_PROFILE_TYPE_MEMCPY_EXT_INFO; | ||
| 332 | + profData.extInfos[1].extInfo.memcpyInfo.bytes = 40U; | ||
| 333 | + profData.extInfos[1].extInfo.memcpyInfo.copyKind = RT_MEMCPY_KIND_DEVICE_TO_HOST; | ||
| 334 | + | ||
| 335 | + ProfilingAgent::Instance().ReportProfApi(0, profData); | ||
| 336 | + | ||
| 337 | + ASSERT_EQ(g_compactCount, 2U); | ||
| 338 | + EXPECT_EQ(g_compactInfos[0].type, RT_PROFILE_TYPE_MEMCPY_EXT_INFO); | ||
| 339 | + EXPECT_EQ(g_compactInfos[0].data.memcpyInfo.bytes, 30U); | ||
| 340 | + EXPECT_EQ(g_compactInfos[0].data.memcpyInfo.copyKind, RT_MEMCPY_KIND_HOST_TO_DEVICE); | ||
| 341 | + EXPECT_EQ(g_compactInfos[0].timeStamp, 101U); | ||
| 342 | + EXPECT_EQ(g_compactInfos[1].type, RT_PROFILE_TYPE_MEMCPY_EXT_INFO); | ||
| 343 | + EXPECT_EQ(g_compactInfos[1].data.memcpyInfo.bytes, 40U); | ||
| 344 | + EXPECT_EQ(g_compactInfos[1].data.memcpyInfo.copyKind, RT_MEMCPY_KIND_DEVICE_TO_HOST); | ||
| 345 | + EXPECT_EQ(g_compactInfos[1].timeStamp, 102U); | ||
| 346 | +} | ||
| 196 | } // namespace RuntTimeUtest | 347 | } // namespace RuntTimeUtest |
| @@ -175,6 +175,199 @@ void ClearApiProfContextStack(Profiler* profiler) | |||
| 175 | profiler->GetProfTaskTrackData() = TaskTrackInfo{}; | 175 | profiler->GetProfTaskTrackData() = TaskTrackInfo{}; |
| 176 | } | 176 | } |
| 177 | 177 | ||
| 178 | +void PrepareRuntimeProfDecoratorTest(Profiler* profiler) | ||
| 179 | +{ | ||
| 180 | + ClearApiProfContextStack(profiler); | ||
| 181 | + profiler->SetTrackProfEnable(false); | ||
| 182 | + profiler->SetApiProfEnable(true); | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +class RuntimeProfTestApiImpl : public ApiImpl { | ||
| 186 | +public: | ||
| 187 | + explicit RuntimeProfTestApiImpl( | ||
| 188 | + Context* const ctx = nullptr, const rtError_t getDeviceRet = RT_ERROR_INVALID_VALUE, const int32_t deviceId = 0) | ||
| 189 | + : ctx_(ctx), getDeviceRet_(getDeviceRet), deviceId_(deviceId) | ||
| 190 | + {} | ||
| 191 | + | ||
| 192 | + rtError_t ContextGetCurrent(Context** const ctx) override | ||
| 193 | + { | ||
| 194 | + if (ctx == nullptr) { | ||
| 195 | + return RT_ERROR_INVALID_VALUE; | ||
| 196 | + } | ||
| 197 | + *ctx = ctx_; | ||
| 198 | + return (ctx_ == nullptr) ? RT_ERROR_INVALID_VALUE : RT_ERROR_NONE; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + rtError_t GetDevice(int32_t* const devId) override | ||
| 202 | + { | ||
| 203 | + if (devId == nullptr) { | ||
| 204 | + return RT_ERROR_INVALID_VALUE; | ||
| 205 | + } | ||
| 206 | + if (getDeviceRet_ != RT_ERROR_NONE) { | ||
| 207 | + return getDeviceRet_; | ||
| 208 | + } | ||
| 209 | + *devId = deviceId_; | ||
| 210 | + return RT_ERROR_NONE; | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | +private: | ||
| 214 | + Context* ctx_; | ||
| 215 | + rtError_t getDeviceRet_; | ||
| 216 | + int32_t deviceId_; | ||
| 217 | +}; | ||
| 218 | + | ||
| 219 | +class RuntimeProfSuccessApiImpl : public RuntimeProfTestApiImpl { | ||
| 220 | +public: | ||
| 221 | + static constexpr uint64_t DEV_ADDR = 0x1000U; | ||
| 222 | + static constexpr uint64_t DEV_CACHED_ADDR = 0x1100U; | ||
| 223 | + static constexpr uint64_t HOST_ADDR = 0x1200U; | ||
| 224 | + static constexpr uint64_t HOST_CFG_ADDR = 0x1300U; | ||
| 225 | + static constexpr uint64_t MANAGED_ADDR = 0x1400U; | ||
| 226 | + static constexpr uint64_t RESERVED_ADDR = 0x1500U; | ||
| 227 | + static constexpr uint64_t PHYSICAL_HANDLE = 0x1600U; | ||
| 228 | + static constexpr uint64_t NEW_DEV_ADDR = 0x1700U; | ||
| 229 | + | ||
| 230 | + explicit RuntimeProfSuccessApiImpl(Context* const ctx = nullptr) : RuntimeProfTestApiImpl(ctx) {} | ||
| 231 | + | ||
| 232 | + rtError_t DevMalloc(void** const devPtr, const uint64_t, const rtMemType_t, const uint16_t) override | ||
| 233 | + { | ||
| 234 | + if (devPtr != nullptr) { | ||
| 235 | + *devPtr = reinterpret_cast<void*>(DEV_ADDR); | ||
| 236 | + } | ||
| 237 | + return RT_ERROR_NONE; | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + rtError_t DevFree(void* const) override { return RT_ERROR_NONE; } | ||
| 241 | + | ||
| 242 | + rtError_t DevMallocCached(void** const devPtr, const uint64_t, const rtMemType_t, const uint16_t) override | ||
| 243 | + { | ||
| 244 | + if (devPtr != nullptr) { | ||
| 245 | + *devPtr = reinterpret_cast<void*>(DEV_CACHED_ADDR); | ||
| 246 | + } | ||
| 247 | + return RT_ERROR_NONE; | ||
| 248 | + } | ||
| 249 | + | ||
| 250 | + rtError_t HostMalloc(void** const hostPtr, const uint64_t, const uint16_t) override | ||
| 251 | + { | ||
| 252 | + if (hostPtr != nullptr) { | ||
| 253 | + *hostPtr = reinterpret_cast<void*>(HOST_ADDR); | ||
| 254 | + } | ||
| 255 | + return RT_ERROR_NONE; | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | + rtError_t HostMallocWithCfg(void** const hostPtr, const uint64_t, const rtMallocConfig_t*) override | ||
| 259 | + { | ||
| 260 | + if (hostPtr != nullptr) { | ||
| 261 | + *hostPtr = reinterpret_cast<void*>(HOST_CFG_ADDR); | ||
| 262 | + } | ||
| 263 | + return RT_ERROR_NONE; | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + rtError_t HostFree(void* const) override { return RT_ERROR_NONE; } | ||
| 267 | + | ||
| 268 | + rtError_t ManagedMemAlloc(void** const ptr, const uint64_t, const uint32_t, const uint16_t) override | ||
| 269 | + { | ||
| 270 | + if (ptr != nullptr) { | ||
| 271 | + *ptr = reinterpret_cast<void*>(MANAGED_ADDR); | ||
| 272 | + } | ||
| 273 | + return RT_ERROR_NONE; | ||
| 274 | + } | ||


这个不考虑4字节对齐吗