Ask Your Question

How to use SIMD feature of OpenCV as third-party library

asked 2019-04-22 08:04:07 -0500

Zeng gravatar image

I want to accelerate my code using SSE or NEON, opencv has uniform interface for different device, so I'd like to use the SIMD feature of OpenCV. But I find the macro CV_SIMD128 is not defined outside opencv, so is there any way to use the v_int16x8 or v_reduce_sum structure or function safely?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-04-23 05:15:26 -0500

mshabunin gravatar image

The easiest way is to create OpenCV module. But you can also try to include intrin.hpp in your build (copy files if needed) and define some macros, e.g CV_SSE2.

// @file myapp.cpp
#define CV_SSE2
// #define CV_NEON // uncomment for ARM
#include <opencv2/core/hal/intrin.hpp>

And your app should have corresponding compiler options enabled, e.g. -mfpu=neon for GCC/Clang

edit flag offensive delete link more



Thank you for your help! Your solution is good, it works. But in this way I should detect whether the device support SSE or neon myself, I want to know if there is some way to get this information from OpenCV. I tried to include both <opencv2/core/cv_cpu_helper.h> and <opencv2/core/hal/intrin.hpp>, and I did not need to add any macros myself, it just worked. I want to know if this operation is normal.

Zeng gravatar imageZeng ( 2019-04-23 07:00:51 -0500 )edit

If you wonn't declare any macro (e.g. CV_SSE2), default non-optimized implementation will be used:

Universal intrinsics are header-only library, so they should not depend on OpenCV build options.

mshabunin gravatar imagemshabunin ( 2019-04-24 01:58:28 -0500 )edit

Question Tools



Asked: 2019-04-22 08:04:07 -0500

Seen: 917 times

Last updated: Apr 23 '19