simd_intrinsics.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #ifndef OPENCV_CORE_SIMD_INTRINSICS_HPP
  5. #define OPENCV_CORE_SIMD_INTRINSICS_HPP
  6. /**
  7. Helper header to support SIMD intrinsics (universal intrinsics) in user code.
  8. Intrinsics documentation: https://docs.opencv.org/3.4/df/d91/group__core__hal__intrin.html
  9. Checks of target CPU instruction set based on compiler definitions don't work well enough.
  10. More reliable solutions require utilization of configuration systems (like CMake).
  11. So, probably you need to specify your own configuration.
  12. You can do that via CMake in this way:
  13. add_definitions(/DOPENCV_SIMD_CONFIG_HEADER=opencv_simd_config_custom.hpp)
  14. or
  15. add_definitions(/DOPENCV_SIMD_CONFIG_INCLUDE_DIR=1)
  16. Additionally you may need to add include directory to your files:
  17. include_directories("${CMAKE_CURRENT_LIST_DIR}/opencv_config_${MYTARGET}")
  18. These files can be pre-generated for target configurations of your application
  19. or generated by CMake on the fly (use CMAKE_BINARY_DIR for that).
  20. Notes:
  21. - H/W capability checks are still responsibility of your applcation
  22. - runtime dispatching is not covered by this helper header
  23. */
  24. #ifdef __OPENCV_BUILD
  25. #error "Use core/hal/intrin.hpp during OpenCV build"
  26. #endif
  27. #ifdef OPENCV_HAL_INTRIN_HPP
  28. #error "core/simd_intrinsics.hpp must be included before core/hal/intrin.hpp"
  29. #endif
  30. #include "opencv2/core/cvdef.h"
  31. #include "opencv2/core/version.hpp"
  32. #ifdef OPENCV_SIMD_CONFIG_HEADER
  33. #include CVAUX_STR(OPENCV_SIMD_CONFIG_HEADER)
  34. #elif defined(OPENCV_SIMD_CONFIG_INCLUDE_DIR)
  35. #include "opencv_simd_config.hpp" // corresponding directory should be added via -I compiler parameter
  36. #else // custom config headers
  37. #if (!defined(CV_AVX_512F) || !CV_AVX_512F) && (defined(__AVX512__) || defined(__AVX512F__))
  38. # include <immintrin.h>
  39. # undef CV_AVX_512F
  40. # define CV_AVX_512F 1
  41. # ifndef OPENCV_SIMD_DONT_ASSUME_SKX // Skylake-X with AVX-512F/CD/BW/DQ/VL
  42. # undef CV_AVX512_SKX
  43. # define CV_AVX512_SKX 1
  44. # undef CV_AVX_512CD
  45. # define CV_AVX_512CD 1
  46. # undef CV_AVX_512BW
  47. # define CV_AVX_512BW 1
  48. # undef CV_AVX_512DQ
  49. # define CV_AVX_512DQ 1
  50. # undef CV_AVX_512VL
  51. # define CV_AVX_512VL 1
  52. # endif
  53. #endif // AVX512
  54. // GCC/Clang: -mavx2
  55. // MSVC: /arch:AVX2
  56. #if defined __AVX2__
  57. # include <immintrin.h>
  58. # undef CV_AVX2
  59. # define CV_AVX2 1
  60. # if defined __F16C__
  61. # undef CV_FP16
  62. # define CV_FP16 1
  63. # endif
  64. #endif
  65. #endif
  66. // SSE / NEON / VSX is handled by cv_cpu_dispatch.h compatibility block
  67. #include "cv_cpu_dispatch.h"
  68. #include "hal/intrin.hpp"
  69. #endif // OPENCV_CORE_SIMD_INTRINSICS_HPP