已合并
[performance]enhanced the process of ccu max delay to lowered the time complexity from o(mn) to o(m+n) #343
xieanran创建于 7月7日
[performance]enhanced the process of ccu max delay to lowered the time complexity from o(mn) to o(m+n) #343
已合并
xieanran创建于 7月7日
xieanran
xieanran成员
7月7日

PR 合入模板

注:经过自检不涉及的可标注“不涉及”或直接打勾,特殊情况请文字备注。不符合规范的 PR 不允许合入,请(后备)commit 注意。


1. 修改描述

  • 修改原因: ccu 寻找max delay慢,需要优化
  • 修改内容: 优化了 CCU 最大延迟通道查找算法,从 O(mn) 降至 O(m+n),新增一条 channelId=4 的测试数据
    后续优化方向:看看能不能压缩channel id,目前看虽然算法是o(m+n),已降至线性,其次可以看下能否优化匹配算法本身。

2. 功能验证


3. 分支合并要求


3. 代码检视

  • 要求:

    • 合入代码超过 200 行,需三人以上会议检视。
    • 检视密度≥1个/100行。
    • 检视缺陷密度未达要求需提供说明。
    • 大于 1000 行代码原则上不允许合入,需进行备案。
  • 检视意见数:____ 条 (请填写本次检视的意见总数,用于commit合入前审视)


4. 安全自检

Python、C++

C++


5. 变更知会


likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 xieanran 的贡献)
atomgit-bot
atomgit-bot
7月7日 评论:

变更摘要

此 PR 优化了 CCU 最大延迟通道查找算法,将时间复杂度从 O(m×n) 降至 O(m+n)。核心思路是通过预构建前缀最大值索引(BuildChannelIndex),将原来每次查询时遍历全部通道数据改为对预排序数组进行二分查找。C++ 端新增 CCUChannelPrefixInfo 结构和 BuildChannelIndex 函数,并重构 GetMaxDelayChannel;Python 端同样采用按 channel_id 预分类字典替代原有的列表过滤方式,使查找操作从线性扫描优化为 O(1) 索引。

主要改动

  • 新增 CCUChannelPrefixInfo 结构与 BuildChannelIndex 函数:在 ccu_mission_processor.cpp 中引入前缀最大值索引结构,按 channelId 分组、按时间戳排序后,为每条记录预计算当前最大延迟(prefix max);BuildChannelIndexFormatWaitTimelineData 中仅调用一次,后续所有 GetMaxDelayChannel 查询共享该索引。
  • 重构 GetMaxDelayChannel 使用二分查找:将原来的两层嵌套遍历(hostData × channelData)改为对 CCUChannelIndexstd::lower_bound 二分查找,通过 recordIter->maxDelay 直接获取当前时间点前的最大延迟通道,避免了原先对全体 channel 数据的重复扫描。
  • Python 端 get_max_delay_channel_and_channel_delay 采用预分类字典channel_data 参数类型从 list 改为 dict,在 get_formatted_wait_data 中通过 defaultdict(list)channel_id 预分类通道数据,使最大延迟通道查找从 O(n) 过滤降为 O(1) 直接索引。
  • 单元测试补充边界用例:在 ccu_mission_processor_utest.cppBuildChannelData 中新增一条 channelId=4 的测试数据 {4, 9000, 0, 0, 999},用于覆盖同一 channelId 存在多条记录时前缀索引的正确性。
likedislike
atomgit-bot
atomgit-bot
7月7日 评论:

代码审查

All findings have been reported. Let me provide the closing summary.


审查总结

各文件审查结论

文件 审查结果
analysis/csrc/domain/data_process/ai_task/ccu_mission_processor.cpp 发现 1 个问题(P3)
analysis/viewer/ccu/ccu_mission_viewer.py 发现 1 个问题(P3)
test/msprof_cpp/analysis_ut/domain/data_process/test/ccu_mission_processor_utest.cpp 无问题

按优先级统计

  • P0: 0
  • P1: 0
  • P2: 0
  • P3: 2

整体风险评估

低风险。此次变更的核心逻辑(C++ 端通过前缀数组 + 二分查找将 CCU 最大延迟计算从 O(mn) 优化到 O(m+n),Python 端通过预建 dict 索引优化查找)在语义上与原有代码等价,未发现正确性或安全性的回归问题。发现的两个 P3 问题均为次要问题:一处 Python 变量名拼写错误,一处 C++ unordered_map::reserve 参数使用不当,均不影响运行正确性。建议合入前修正这两处 P3 问题以提升代码质量。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
ascend-robotascend-robot成员
7月7日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
7月7日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-Ascend/msprof 张伟, Seanesmhxocism (2/2) 张伟 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

SoraAzzz, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了73条消息 查看更多
ascend-robot
ascend-robot成员
7月9日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
chenhao_1209成员7月9日进行代码检视1
analysis/viewer/ccu/ccu_mission_viewer.py
@@ -85,2 +95,4 @@
95+ 
96+ seq_channel = [channel for channel in within_channel if channel.timestamp < mission_data.end_time]
8597 if seq_channel:
8698 max_delay_channel = max(seq_channel, key=lambda x: x.avg_bw)
chenhao_12097月9日评论:

【review】【设计】Python 端的 get_max_delay_channel_and_channel_delay 仍使用 max(seq_channel, key=lambda x: x.avg_bw) 计算最大延迟通道,但 avg_bw 是平均带宽,不是延迟(delay)。字段名 avg_bw 与语义 max_delay_channel 不符。,建议修改:应该使用 avg_delay 而非 avg_bw 来计算最大延迟通道

likedislike
chenhao_1209成员7月9日进行代码检视1
analysis/csrc/domain/data_process/ai_task/ccu_mission_processor.cpp
@@ -116,1 +126,3 @@
116- maxDelay.channelDelay = channel.avgDelay;
126+ continue;
127+ }
128+ --recordIter;
chenhao_12097月9日评论:

【review】【编码】调用位置对--recordIter的取值,是对 lower_bound 返回的前一个元素取值,但 lower_bound 返回的是 >= missionData.endTime 的第一个元素,因此 --recordIter 是 timestamp < endTime 的最大元素。但当 channelRecords 中有多个相同 timestamp 的记录,lower_bound 可能返回第一个 >= endTime 的元素,而 prefix 中该位置的 maxDelay 可能不是该 timestamp 下所有记录合并后的最大值。建议在 BuildChannelIndex 中处理相同 timestamp 的情况。

likedislike
xieanranxieanran成员
7月9日 解决了最后一个问题
ascend-robot
ascend-robot成员
7月9日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike