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 1.5 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <stdio.h>
  2. #include "cpu.h"
  3. #if defined __ANDROID__ || defined __linux__
  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. static int test_cpu_info()
  32. {
  33. if (ncnn::get_cpu_count() >= 0 && ncnn::get_little_cpu_count() >= 0 && ncnn::get_big_cpu_count() >= 0)
  34. {
  35. return 0;
  36. }
  37. else
  38. {
  39. fprintf(stderr, "The system cannot have a negative number of processors\n");
  40. return 1;
  41. }
  42. }
  43. static int test_cpu_omp()
  44. {
  45. if (ncnn::get_omp_num_threads() >= 0 && ncnn::get_omp_thread_num() >= 0 && ncnn::get_omp_dynamic() >= 0)
  46. {
  47. return 0;
  48. }
  49. else
  50. {
  51. fprintf(stderr, "The OMP cannot have a negative number of processors\n");
  52. return 1;
  53. }
  54. }
  55. #else
  56. static int test_cpu_set()
  57. {
  58. return 0;
  59. }
  60. static int test_cpu_info()
  61. {
  62. return 0;
  63. }
  64. static int test_cpu_omp()
  65. {
  66. return 0;
  67. }
  68. #endif
  69. int main()
  70. {
  71. return 0
  72. || test_cpu_set()
  73. || test_cpu_info()
  74. || test_cpu_omp();
  75. }