Elffuss BraidHub

kikocis/ncnn public

d7a5f98c0f60 · 2.2 KiBRawPermalink
1#include <stdio.h>
2
3#include "cpu.h"
4
5#if defined __ANDROID__ || defined __linux__ || defined __APPLE__
6
7static int test_cpu_set()
8{
9 ncnn::CpuSet set;
10
11 if (set.num_enabled() != 0)
12 {
13 fprintf(stderr, "By default all cpus should be disabled\n");
14 return 1;
15 }
16
17 set.enable(0);
18 if (!set.is_enabled(0))
19 {
20 fprintf(stderr, "CpuSet enable doesn't work\n");
21 return 1;
22 }
23
24 if (set.num_enabled() != 1)
25 {
26 fprintf(stderr, "Only one cpu should be enabled\n");
27 return 1;
28 }
29
30 set.disable(0);
31 if (set.is_enabled(0))
32 {
33 fprintf(stderr, "CpuSet disable doesn't work\n");
34 return 1;
35 }
36
37 return 0;
38}
39
40#else
41
42static int test_cpu_set()
43{
44 return 0;
45}
46
47#endif
48
49#if defined __ANDROID__ || defined __linux__
50
51static int test_cpu_info()
52{
53 if (ncnn::get_cpu_count() >= 0 && ncnn::get_little_cpu_count() >= 0 && ncnn::get_big_cpu_count() >= 0)
54 {
55 return 0;
56 }
57 else
58 {
59 fprintf(stderr, "The system cannot have a negative number of processors\n");
60 return 1;
61 }
62}
63
64static int test_cpu_omp()
65{
66 if (ncnn::get_omp_num_threads() >= 0 && ncnn::get_omp_thread_num() >= 0 && ncnn::get_omp_dynamic() >= 0)
67 {
68 return 0;
69 }
70 else
71 {
72 fprintf(stderr, "The OMP cannot have a negative number of processors\n");
73 return 1;
74 }
75
76 ncnn::set_omp_num_threads(1);
77
78 ncnn::set_omp_dynamic(1);
79}
80
81static int test_cpu_powersave()
82{
83 if (ncnn::get_cpu_powersave() >= 0)
84 {
85 return 0;
86 }
87 else
88 {
89 fprintf(stderr, "By default powersave must be zero\n");
90 return 1;
91 }
92
93 if (ncnn::set_cpu_powersave(-1) == -1 && ncnn::set_cpu_powersave(3) == -1)
94 {
95 return 0;
96 }
97 else
98 {
99 fprintf(stderr, "Set cpu powersave for `-1 < argument < 2` works incorrectly.\n");
100 return 1;
101 }
102}
103
104#else
105
106static int test_cpu_info()
107{
108 return 0;
109}
110
111static int test_cpu_omp()
112{
113 return 0;
114}
115
116static int test_cpu_powersave()
117{
118 return 0;
119}
120
121#endif
122
123int main()
124{
125 return 0
126 || test_cpu_set()
127 || test_cpu_info()
128 || test_cpu_omp()
129 || test_cpu_powersave();
130}