Skip to content

Commit d67cd15

Browse files
Hansersdoggithub-actions[bot]
authored andcommitted
apply code-format changes
1 parent 37c8f48 commit d67cd15

File tree

2 files changed

+65
-46
lines changed

2 files changed

+65
-46
lines changed

src/cpu.cpp

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#endif
5454

5555
#if defined __ANDROID__ || defined __OHOS__ || __linux__
56-
#include <cstring>
56+
#include <cstring>
5757
#if defined __ANDROID__
5858
#if __ANDROID_API__ >= 18
5959
#include <sys/auxv.h> // getauxval()
@@ -879,39 +879,46 @@ static int get_cpucount()
879879
else
880880
count = 1;
881881
#elif defined _WIN32
882-
typedef BOOL(WINAPI *LPFN_GLPIEX)(LOGICAL_PROCESSOR_RELATIONSHIP, PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, PDWORD);
882+
typedef BOOL(WINAPI * LPFN_GLPIEX)(LOGICAL_PROCESSOR_RELATIONSHIP, PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX, PDWORD);
883883
LPFN_GLPIEX glpiex = (LPFN_GLPIEX)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetLogicalProcessorInformationEx");
884-
if (glpiex != NULL) {
884+
if (glpiex != NULL)
885+
{
885886
DWORD length = 0;
886887
glpiex(RelationAll, NULL, &length);
887-
888-
if (length > 0) {
889-
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX buffer =
890-
(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)malloc(length);
891-
892-
if (buffer && glpiex(RelationAll, buffer, &length)) {
888+
889+
if (length > 0)
890+
{
891+
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)malloc(length);
892+
893+
if (buffer && glpiex(RelationAll, buffer, &length))
894+
{
893895
count = 0;
894896
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX ptr = buffer;
895897
DWORD offset = 0;
896-
897-
while (offset < length) {
898-
if (ptr->Relationship == RelationProcessorCore) {
899-
for (WORD i = 0; i < ptr->Processor.GroupCount; i++) {
898+
899+
while (offset < length)
900+
{
901+
if (ptr->Relationship == RelationProcessorCore)
902+
{
903+
for (WORD i = 0; i < ptr->Processor.GroupCount; i++)
904+
{
900905
count += __popcnt64(ptr->Processor.GroupMask[i].Mask);
901906
}
902907
}
903908
offset += ptr->Size;
904909
ptr = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)((char*)ptr + ptr->Size);
905910
}
906911
}
907-
908-
if (buffer) {
912+
913+
if (buffer)
914+
{
909915
free(buffer);
910916
}
911917
}
912918
}
913919
//If cpu's count <= 64, use the previouse version.
914-
if (count == 0) {
920+
if (count == 0)
921+
{
915922
SYSTEM_INFO system_info;
916923
GetSystemInfo(&system_info);
917924
count = system_info.dwNumberOfProcessors;
@@ -1396,14 +1403,14 @@ static ncnn::CpuSet get_smt_cpu_mask()
13961403
{
13971404
DWORD length = 0;
13981405
glpiex(RelationProcessorCore, NULL, &length);
1399-
1406+
14001407
if (length > 0)
14011408
{
14021409
std::vector<char> buffer(length);
14031410
if (glpiex(RelationProcessorCore, (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)buffer.data(), &length))
14041411
{
14051412
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX current = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)buffer.data();
1406-
1413+
14071414
while ((char*)current < buffer.data() + length)
14081415
{
14091416
if (current->Relationship == RelationProcessorCore)
@@ -1413,7 +1420,7 @@ static ncnn::CpuSet get_smt_cpu_mask()
14131420
{
14141421
total_logical_count += __popcnt64(current->Processor.GroupMask[group].Mask);
14151422
}
1416-
1423+
14171424
if (total_logical_count > 1)
14181425
{
14191426
for (WORD group = 0; group < current->Processor.GroupCount; group++)
@@ -1431,15 +1438,15 @@ static ncnn::CpuSet get_smt_cpu_mask()
14311438
}
14321439
}
14331440
}
1434-
1441+
14351442
current = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX)((char*)current + current->Size);
14361443
}
1437-
1444+
14381445
return smt_cpu_mask;
14391446
}
14401447
}
14411448
}
1442-
1449+
14431450
// Under 64, use the old API
14441451
typedef BOOL(WINAPI * LPFN_GLPI)(PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD);
14451452
LPFN_GLPI glpi = (LPFN_GLPI)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetLogicalProcessorInformation");
@@ -1465,8 +1472,10 @@ static ncnn::CpuSet get_smt_cpu_mask()
14651472
if (logical_count > 1)
14661473
{
14671474
ULONG_PTR mask = ptr->ProcessorMask;
1468-
for (int cpu = 0; cpu < 64 && mask; cpu++) {
1469-
if (mask & (1ULL << cpu)) {
1475+
for (int cpu = 0; cpu < 64 && mask; cpu++)
1476+
{
1477+
if (mask & (1ULL << cpu))
1478+
{
14701479
smt_cpu_mask.enable(cpu);
14711480
mask &= ~(1ULL << cpu);
14721481
}
@@ -1534,13 +1543,13 @@ static int set_sched_affinity(const ncnn::CpuSet& thread_affinity_mask)
15341543
groupAffinity.Reserved[0] = 0;
15351544
groupAffinity.Reserved[1] = 0;
15361545
groupAffinity.Reserved[2] = 0;
1537-
1546+
15381547
if (!SetThreadGroupAffinity(GetCurrentThread(), &groupAffinity, NULL))
15391548
{
15401549
NCNN_LOGE("SetThreadGroupAffinity failed %d", GetLastError());
15411550
return -1;
15421551
}
1543-
break;
1552+
break;
15441553
}
15451554
}
15461555
return 0;
@@ -1711,7 +1720,6 @@ static int set_sched_affinity(const ncnn::CpuSet& thread_affinity_mask)
17111720
}
17121721
#endif // __APPLE__
17131722

1714-
17151723
static void initialize_cpu_thread_affinity_mask(ncnn::CpuSet& mask_all, ncnn::CpuSet& mask_little, ncnn::CpuSet& mask_big)
17161724
{
17171725
mask_all.disable_all();
@@ -2254,7 +2262,7 @@ static void initialize_global_cpu_info()
22542262

22552263
g_cpucount = get_cpucount();
22562264
g_physical_cpucount = get_physical_cpucount();
2257-
g_powersave = 0;
2265+
g_powersave = 0;
22582266
initialize_cpu_thread_affinity_mask(g_cpu_affinity_mask_all, g_cpu_affinity_mask_little, g_cpu_affinity_mask_big);
22592267

22602268
#if (defined _WIN32 && (__aarch64__ || __arm__)) || ((defined __ANDROID__ || defined __linux__) && __riscv)
@@ -2380,42 +2388,46 @@ CpuSet::CpuSet()
23802388
void CpuSet::enable(int cpu)
23812389
{
23822390
if (cpu < 0 || cpu >= max_cpus) return;
2383-
2391+
23842392
int group = cpu / 64;
23852393
int bit = cpu % 64;
2386-
2387-
if (group < MAX_CPU_GROUPS) {
2394+
2395+
if (group < MAX_CPU_GROUPS)
2396+
{
23882397
masks[group] |= (1ULL << bit);
23892398
}
23902399
}
23912400

23922401
void CpuSet::disable(int cpu)
23932402
{
23942403
if (cpu < 0 || cpu >= max_cpus) return;
2395-
2404+
23962405
int group = cpu / 64;
23972406
int bit = cpu % 64;
2398-
2399-
if (group < MAX_CPU_GROUPS) {
2407+
2408+
if (group < MAX_CPU_GROUPS)
2409+
{
24002410
masks[group] &= ~(1ULL << bit);
24012411
}
24022412
}
24032413

24042414
void CpuSet::disable_all()
24052415
{
2406-
for (int i = 0; i < MAX_CPU_GROUPS; i++) {
2416+
for (int i = 0; i < MAX_CPU_GROUPS; i++)
2417+
{
24072418
masks[i] = 0;
24082419
}
24092420
}
24102421

24112422
bool CpuSet::is_enabled(int cpu) const
24122423
{
24132424
if (cpu < 0 || cpu >= max_cpus) return false;
2414-
2425+
24152426
int group = cpu / 64;
24162427
int bit = cpu % 64;
2417-
2418-
if (group < MAX_CPU_GROUPS) {
2428+
2429+
if (group < MAX_CPU_GROUPS)
2430+
{
24192431
return (masks[group] & (1ULL << bit)) != 0;
24202432
}
24212433
return false;
@@ -2424,15 +2436,17 @@ bool CpuSet::is_enabled(int cpu) const
24242436
int CpuSet::num_enabled() const
24252437
{
24262438
int count = 0;
2427-
for (int i = 0; i < MAX_CPU_GROUPS; i++) {
2439+
for (int i = 0; i < MAX_CPU_GROUPS; i++)
2440+
{
24282441
count += __builtin_popcountll(masks[i]);
24292442
}
24302443
return count;
24312444
}
24322445

24332446
ULONG_PTR CpuSet::get_group_mask(int group) const
24342447
{
2435-
if (group < 0 || group >= MAX_CPU_GROUPS) {
2448+
if (group < 0 || group >= MAX_CPU_GROUPS)
2449+
{
24362450
return 0;
24372451
}
24382452
return masks[group];
@@ -2441,8 +2455,10 @@ ULONG_PTR CpuSet::get_group_mask(int group) const
24412455
int CpuSet::get_active_group_count() const
24422456
{
24432457
int count = 0;
2444-
for (int i = 0; i < MAX_CPU_GROUPS; i++) {
2445-
if (masks[i] != 0) {
2458+
for (int i = 0; i < MAX_CPU_GROUPS; i++)
2459+
{
2460+
if (masks[i] != 0)
2461+
{
24462462
count++;
24472463
}
24482464
}

src/cpu.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ class NCNN_EXPORT CpuSet
3838
void disable_all();
3939
bool is_enabled(int cpu) const;
4040
int num_enabled() const;
41-
41+
4242
#if defined _WIN32
43-
int get_max_cpus() const { return max_cpus; }
43+
int get_max_cpus() const
44+
{
45+
return max_cpus;
46+
}
4447
ULONG_PTR get_group_mask(int group) const;
4548
int get_active_group_count() const;
4649
#endif
@@ -146,7 +149,7 @@ NCNN_EXPORT int get_physical_cpu_count();
146149
NCNN_EXPORT int get_physical_little_cpu_count();
147150
NCNN_EXPORT int get_physical_big_cpu_count();
148151

149-
// cpu l2 varies from 64k to 1M, but l3 can be zero
152+
// cpu l2 varies from 64k to 1M, but l3 can be zero
150153
NCNN_EXPORT int get_cpu_level2_cache_size();
151154
NCNN_EXPORT int get_cpu_level3_cache_size();
152155

@@ -161,7 +164,7 @@ NCNN_EXPORT int get_cpu_level3_cache_size();
161164
NCNN_EXPORT int get_cpu_powersave();
162165
NCNN_EXPORT int set_cpu_powersave(int powersave);
163166

164-
// convenient wrapper
167+
// convenient wrapper
165168
NCNN_EXPORT const CpuSet& get_cpu_thread_affinity_mask(int powersave);
166169

167170
// set explicit thread affinity

0 commit comments

Comments
 (0)