test_intrin.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #include "test_precomp.hpp"
  5. #include "test_intrin128.simd.hpp"
  6. // see "test_intrin_emulator.cpp"
  7. // see "opencv2/core/private/cv_cpu_include_simd_declarations.hpp"
  8. #define CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY
  9. #undef CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
  10. #undef CV_CPU_OPTIMIZATION_NAMESPACE_END
  11. #define CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN namespace opt_EMULATOR_CPP {
  12. #define CV_CPU_OPTIMIZATION_NAMESPACE_END }
  13. #include "test_intrin128.simd.hpp"
  14. #undef CV_CPU_OPTIMIZATION_NAMESPACE_BEGIN
  15. #undef CV_CPU_OPTIMIZATION_NAMESPACE_END
  16. #undef CV_CPU_OPTIMIZATION_DECLARATIONS_ONLY
  17. #include "test_intrin128.simd_declarations.hpp"
  18. #undef CV_CPU_DISPATCH_MODES_ALL
  19. #include "opencv2/core/cv_cpu_dispatch.h"
  20. #include "test_intrin256.simd.hpp"
  21. #include "test_intrin256.simd_declarations.hpp"
  22. #undef CV_CPU_DISPATCH_MODES_ALL
  23. #include "opencv2/core/cv_cpu_dispatch.h"
  24. #include "test_intrin512.simd.hpp"
  25. #include "test_intrin512.simd_declarations.hpp"
  26. #ifdef _MSC_VER
  27. # pragma warning(disable:4702) // unreachable code
  28. #endif
  29. namespace opencv_test { namespace hal {
  30. #define CV_CPU_CALL_CPP_EMULATOR_(fn, args) return (opt_EMULATOR_CPP::fn args)
  31. #define CV_CPU_CALL_BASELINE_(fn, args) CV_CPU_CALL_BASELINE(fn, args)
  32. #define DISPATCH_SIMD128(fn, cpu_opt) do { \
  33. CV_CPU_CALL_ ## cpu_opt ## _(fn, ()); \
  34. throw SkipTestException("SIMD128 (" #cpu_opt ") is not available or disabled"); \
  35. } while(0)
  36. #define DISPATCH_SIMD256(fn, cpu_opt) do { \
  37. CV_CPU_CALL_ ## cpu_opt ## _(fn, ()); \
  38. throw SkipTestException("SIMD256 (" #cpu_opt ") is not available or disabled"); \
  39. } while(0)
  40. #define DISPATCH_SIMD512(fn, cpu_opt) do { \
  41. CV_CPU_CALL_ ## cpu_opt ## _(fn, ()); \
  42. throw SkipTestException("SIMD512 (" #cpu_opt ") is not available or disabled"); \
  43. } while(0)
  44. #define DEFINE_SIMD_TESTS(simd_size, cpu_opt) \
  45. TEST(hal_intrin ## simd_size, uint8x16_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_uint8, cpu_opt); } \
  46. TEST(hal_intrin ## simd_size, int8x16_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_int8, cpu_opt); } \
  47. TEST(hal_intrin ## simd_size, uint16x8_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_uint16, cpu_opt); } \
  48. TEST(hal_intrin ## simd_size, int16x8_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_int16, cpu_opt); } \
  49. TEST(hal_intrin ## simd_size, int32x4_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_int32, cpu_opt); } \
  50. TEST(hal_intrin ## simd_size, uint32x4_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_uint32, cpu_opt); } \
  51. TEST(hal_intrin ## simd_size, uint64x2_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_uint64, cpu_opt); } \
  52. TEST(hal_intrin ## simd_size, int64x2_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_int64, cpu_opt); } \
  53. TEST(hal_intrin ## simd_size, float32x4_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_float32, cpu_opt); } \
  54. TEST(hal_intrin ## simd_size, float64x2_ ## cpu_opt) { DISPATCH_SIMD ## simd_size(test_hal_intrin_float64, cpu_opt); } \
  55. namespace intrin128 {
  56. DEFINE_SIMD_TESTS(128, CPP_EMULATOR)
  57. DEFINE_SIMD_TESTS(128, BASELINE)
  58. #if defined CV_CPU_DISPATCH_COMPILE_SSE2 || defined CV_CPU_BASELINE_COMPILE_SSE2
  59. DEFINE_SIMD_TESTS(128, SSE2)
  60. #endif
  61. #if defined CV_CPU_DISPATCH_COMPILE_SSE3 || defined CV_CPU_BASELINE_COMPILE_SSE3
  62. DEFINE_SIMD_TESTS(128, SSE3)
  63. #endif
  64. #if defined CV_CPU_DISPATCH_COMPILE_SSSE3 || defined CV_CPU_BASELINE_COMPILE_SSSE3
  65. DEFINE_SIMD_TESTS(128, SSSE3)
  66. #endif
  67. #if defined CV_CPU_DISPATCH_COMPILE_SSE4_1 || defined CV_CPU_BASELINE_COMPILE_SSE4_1
  68. DEFINE_SIMD_TESTS(128, SSE4_1)
  69. #endif
  70. #if defined CV_CPU_DISPATCH_COMPILE_SSE4_2 || defined CV_CPU_BASELINE_COMPILE_SSE4_2
  71. DEFINE_SIMD_TESTS(128, SSE4_2)
  72. #endif
  73. #if defined CV_CPU_DISPATCH_COMPILE_AVX || defined CV_CPU_BASELINE_COMPILE_AVX
  74. DEFINE_SIMD_TESTS(128, AVX)
  75. #endif
  76. #if defined CV_CPU_DISPATCH_COMPILE_AVX2 || defined CV_CPU_BASELINE_COMPILE_AVX2
  77. DEFINE_SIMD_TESTS(128, AVX2)
  78. #endif
  79. #if defined CV_CPU_DISPATCH_COMPILE_AVX512_SKX || defined CV_CPU_BASELINE_COMPILE_AVX512_SKX
  80. DEFINE_SIMD_TESTS(128, AVX512_SKX)
  81. #endif
  82. TEST(hal_intrin128, float16x8_FP16)
  83. {
  84. CV_CPU_CALL_FP16_(test_hal_intrin_float16, ());
  85. throw SkipTestException("Unsupported hardware: FP16 is not available");
  86. }
  87. } // namespace intrin128
  88. namespace intrin256 {
  89. // Not available due missing C++ backend for SIMD256
  90. //DEFINE_SIMD_TESTS(256, BASELINE)
  91. //#if defined CV_CPU_DISPATCH_COMPILE_AVX
  92. //DEFINE_SIMD_TESTS(256, AVX)
  93. //#endif
  94. #if defined CV_CPU_DISPATCH_COMPILE_AVX2 || defined CV_CPU_BASELINE_COMPILE_AVX2
  95. DEFINE_SIMD_TESTS(256, AVX2)
  96. #endif
  97. #if defined CV_CPU_DISPATCH_COMPILE_AVX512_SKX || defined CV_CPU_BASELINE_COMPILE_AVX512_SKX
  98. DEFINE_SIMD_TESTS(256, AVX512_SKX)
  99. #endif
  100. TEST(hal_intrin256, float16x16_FP16)
  101. {
  102. #if CV_TRY_FP16
  103. //CV_CPU_CALL_FP16_(test_hal_intrin_float16, ());
  104. CV_CPU_CALL_AVX2_(test_hal_intrin_float16, ());
  105. #endif
  106. throw SkipTestException("Unsupported: FP16 is not available");
  107. }
  108. } // namespace intrin256
  109. namespace intrin512 {
  110. #if defined CV_CPU_DISPATCH_COMPILE_AVX512_SKX || defined CV_CPU_BASELINE_COMPILE_AVX512_SKX
  111. DEFINE_SIMD_TESTS(512, AVX512_SKX)
  112. #endif
  113. TEST(hal_intrin512, float16x32_FP16)
  114. {
  115. #if CV_TRY_FP16
  116. CV_CPU_CALL_AVX512_SKX_(test_hal_intrin_float16, ());
  117. #endif
  118. throw SkipTestException("Unsupported: FP16 is not available");
  119. }
  120. } // namespace intrin512
  121. }} // namespace