Skip to content

support cpu count > 64 #6189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

JaredforReal
Copy link

Fix: #6142 support cpu count > 64


对于Win平台:
使用多组掩码方案,每组默认为64。根据Windows系统版本设置最大CPU支持数
生产环境中,group = 1(cpu count <= 64)的情况下,使用legacy mode,保留原始逻辑

缺憾:在group > 1(cpu count > 64)的情况下,假定了每组的性能以及功能相同,未区分大小核

新增单元测试:test_multicpu,在测试环境中,屏蔽 legacy mode 强制使用 group 逻辑,验证多组掩码的逻辑功能

对于Linux/Android平台:
未作修改。
cpu_set_t 的大小,在现代主流实现(如 glibc)默认通过 CPU_SETSIZE 定义为 ​1024。即原生支持 cpu count > 64 如想支持 > 1024,可使用 cpu_set_t* 加上带有_S POSIX指令实现

对于Apple平台:
未作修改。
unsigned int 最高支持32核,考虑到Apple目前没有超过32核的芯片,为了面向未来的健壮性,可改用 uint64_t以支持64 cpu

其余单元测试结果与主分支一致

修改文件
src/cpu.cpp
src/cpu.h
tests/CMakeList.txt

新增文件
tests/test_multicpu.cpp

support cpu count > 64

对于Win平台:
使用多组掩码方案,每组默认为64。根据Windows系统版本设置最大CPU支持数
生产环境中,group = 1(cpu count <= 64)的情况下,使用legacy mode,保留原始逻辑

缺憾:在group > 1(cpu count > 64)的情况下,假定了每组的性能以及功能相同,未区分大小核
新增单元测试:test_multicpu,在测试环境中,屏蔽 legacy mode 强制使用 group 逻辑,验证多组掩码的逻辑功能

对于Linux/Android平台:
未作修改。
cpu_set_t 的大小,在现代主流实现(如 glibc)默认通过 CPU_SETSIZE 定义为 ​1024。即原生支持 cpu count > 64
如想支持 > 1024,可使用 cpu_set_t* 加上带有_S POSIX指令实现

对于Apple平台:
未作修改。
unsigned int最高支持32核,考虑到Apple目前没有超过32核的芯片,为了面向未来的健壮性,可改用uint64_t以支持64 cpu

其余单元测试结果与主分支一致

修改文件
src/cpu.cpp
src/cpu.h
tests/CMakeList.txt

新增文件
tests/test_multicpu.cpp
@tencent-adm
Copy link
Member

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

github-actions bot commented Jul 14, 2025

The binary size change of libncnn.so (bytes)

architecture base size pr size difference
x86_64 15631136 15631136 0 😘
armhf 6635836 6635836 0 😘
aarch64 9987672 9987672 0 😘

Copy link

Please enable github action in YOUR FORKED REPO to make code-format workflow work

* support win group mask

* reconstruct CpuSet class of _WIN32

* adapt the rest part to Group Mask CpuSet

* fix rebase conflict in cpu.h

* pair if endif and delete unused function

* delete unused function

* add NCNN_TEST_FORCE_MULTI_GROUP to test

* get rid of legacy_mode in cpu.cpp

* delete duplicate code
@JaredforReal
Copy link
Author

JaredforReal commented Jul 16, 2025

get rid of legacy mode to keep consistency and reduce compelxity. Functionality remains unchanged, and unit test results are consistent with the master branch
去掉了 legacy mode 来保证一致性和降低复杂度。功能不变,单元测试结果与master branch一致

* support win group mask

* reconstruct CpuSet class of _WIN32

* adapt the rest part to Group Mask CpuSet

* fix merge error

* fix rebase conflict in cpu.h

* pair if endif and delete unused function

* delete unused function

* get rid of legacy_mode in cpu.cpp

* delete duplicate code

* try fix cross-platform compilation error
@JaredforReal
Copy link
Author

try fix cross-platform compilation error
尝试解决跨平台编译错误问题

@codecov-commenter
Copy link

codecov-commenter commented Jul 22, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.05%. Comparing base (6c44404) to head (d8d0d38).
Report is 4 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #6189       +/-   ##
===========================================
- Coverage   95.78%   94.05%    -1.74%     
===========================================
  Files         835      417      -418     
  Lines      252528   120537   -131991     
===========================================
- Hits       241887   113371   -128516     
+ Misses      10641     7166     -3475     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

【多人竞赛】support cpu count > 64
3 participants