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 : #ifndef STATISTIC_AICPUSD_MODEL_STATISTIC_H
11 : #define STATISTIC_AICPUSD_MODEL_STATISTIC_H
12 : #include <map>
13 : #include <vector>
14 : #include <chrono>
15 : #include "aicpusd_status.h"
16 : #include "aicpusd_common.h"
17 : #include "aicpu_context.h"
18 : #include "aicpusd_util.h"
19 : namespace AicpuSchedule {
20 :
21 : struct ParamStatInfo {
22 : uint64_t curSize;
23 : uint64_t curShape;
24 : ParamStatInfo() : curSize(0UL), curShape(0UL) {}
25 : };
26 : struct InAndOutParamStatInfo {
27 : uint64_t minSize;
28 : uint64_t maxSize;
29 : std::vector<int64_t> minShape;
30 : std::vector<int64_t> maxShape;
31 7 : InAndOutParamStatInfo() : minSize(0UL), maxSize(0UL) {}
32 : };
33 : struct ModelStatInfo {
34 : bool useFlag;
35 : uint64_t minExecTime;
36 : uint64_t maxExecTime;
37 : uint64_t subMaxExecTime;
38 : uint64_t totalTime;
39 : uint64_t totalCnt;
40 : std::vector<InAndOutParamStatInfo> inputStatVec;
41 : std::vector<InAndOutParamStatInfo> outputStatVec;
42 : std::chrono::steady_clock::time_point modelStartTime;
43 : };
44 : class AicpuSdModelStatistic {
45 : public:
46 : static AicpuSdModelStatistic &GetInstance();
47 : void StatNNModelExecTime(const uint32_t modelId);
48 : void StatNNModelInput(const uint32_t modelId, const std::vector<uint64_t> &totalSizeList,
49 : std::vector<ModelConfigTensorDesc> &curStatVec);
50 : void InitModelStatInfo();
51 : void MarNNModelStartTime(const uint32_t modelId);
52 : void PrintOutModelStatInfo();
53 : void StatNNModelOutput(const uint32_t modelId, const RuntimeTensorDesc * const tensorDesc,
54 : const int32_t nextIndex);
55 : private:
56 : void DumpOutModelMetrics(const uint32_t modelId);
57 : void AddNewDataToStatVec(std::vector<InAndOutParamStatInfo> &delVec, const uint64_t totalSize,
58 : const int64_t *shapes) const;
59 : void UpdateStatVecInfo(InAndOutParamStatInfo &dstStat, const uint64_t totalSize,
60 : const int64_t *shapes) const;
61 : std::string FormatShapeToString(const std::vector<int64_t> &shape) const;
62 : std::string GetRangeString(const std::vector<InAndOutParamStatInfo> &statInfos,
63 : size_t startIdx, size_t endIdx) const;
64 : AicpuSdModelStatistic();
65 : virtual ~AicpuSdModelStatistic();
66 : ModelStatInfo modelStatArray_[MAX_MODEL_COUNT];
67 : };
68 : }
69 : #endif
|