You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_cpu.cpp 2.2 kB

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