Repository navigation
Wide univ intrinsics - #11953
Wide univ intrinsics#11953
Conversation
…enCV HAL functions: sqrt, invsqrt, magnitude, phase, exp to the wide universal intrinsics.
…ed v_lut_deinterleave intrinsics.
|
@vpisarev, Please could you combine the last changes that I made on "intrin_avx.hpp"? |
| #ifdef CV_CPU_COMPILE_AVX2 | ||
| # include <immintrin.h> | ||
| # define CV_AVX2 1 | ||
| # define CV_FMA3 1 |
There was a problem hiding this comment.
These changes in this file are not necessary.
Please avoid logic duplication - it is already moved out to configuration stage (CMake).
| #define CV_SIMD 1 | ||
| #endif | ||
| #else | ||
| #define CV_SIMD128 0 |
There was a problem hiding this comment.
Code doesn't look consistent. There mess of CV_SIMD / CV_SIMD128.
Update: It is better (clear) to write in the end:
#if CV_SIMD128 || CV_SIMD256
#define CV_SIMD 1
#else
#define CV_SIMD 0
#endif
| typedef v_float32x8 v_float32; | ||
| #if CV_SIMD256_64F | ||
| typedef v_float64x4 v_float64; | ||
| #endif |
There was a problem hiding this comment.
Fallback ?
#elif CV_SIMD128_64F
typedef v_float64x2 v_float64;
| inline vtyp vx_setall_##short_typ(typ v) { return prefix##_setall_##short_typ(v); } \ | ||
| inline vtyp vx_setzero_##short_typ() { return prefix##_setzero_##short_typ(); } \ | ||
| inline vtyp vx_##loadsfx(const typ* ptr) { return prefix##_##loadsfx(ptr); } \ | ||
| inline vtyp vx_##loadsfx##_aligned(const typ* ptr) { return prefix##_##loadsfx##_aligned(ptr); } \ |
There was a problem hiding this comment.
Looks like loadsfx is always "load".
There was a problem hiding this comment.
nope, sometimes it's load_f16
| template<> struct V_TypeTraits<type> \ | ||
| { \ | ||
| typedef int_type_ int_type; \ | ||
| typedef abs_type_ abs_type; \ |
There was a problem hiding this comment.
For backward compatibility would be nice to keep:
value_typeuint_type(and perhapsreinterpret_uint())
| // 2 | ||
| inline void v_load_deinterleave(const uchar* ptr, v_uint8x32& a, v_uint8x32& b) | ||
| { | ||
| // todo fix it ,, max 16 |
| //! @brief Check CPU capability of SIMD operation | ||
| static inline bool hasSIMD256() | ||
| { | ||
| return (CV_CPU_HAS_SUPPORT_AVX2) ? true : false; |
There was a problem hiding this comment.
-CV_CPU_HAS_SUPPORT_AVX2
+CV_CPU_HAS_SUPPORT_AVX| // scalar code | ||
| if( i == 0 || angle == X || angle == Y ) | ||
| break; | ||
| i = len - VECSZ*2; |
There was a problem hiding this comment.
if it's inplace operation and something is wrong then X/Y are already corrupted.
IMHO, vectorized loops in this file are malformed.
Proper design pattern is:
for( ; i <= len - BLOCK_SIZE; i += BLOCK_SIZE)
{
// no more 'if's
...
}
for( ; i < len; i++ )
{
...
}
| ybuf[j] = (float)Y[i + j]; | ||
| xbuf[j] = (float)X[i + j]; | ||
| } | ||
| fastAtan32f(ybuf, xbuf, abuf, blksz, angleInDegrees); |
There was a problem hiding this comment.
fastAtan32f() is function with CV_INSTRUMENT_REGION() (required for OpenCV entry-points, but using this inside of "per-element" loops should be avoided).
Performance may be terrible, than computation in doubles.
Do we have performance tests for this?
|
|
||
| #endif | ||
|
|
||
| #if CV_AVX2 |
There was a problem hiding this comment.
IMHO, this should support CV_AVX too.
…pencv into wide_univ_intrin - added several more AVX2 implementations of univ. intrinsics
| typedef v_int64x2 reg; | ||
| static v_int64x2 zero() { return v_setzero_s64(); } | ||
| static v_int64x2 all(int64 val) { return v_setall_s64(val); } | ||
| #define CV_INTRIN_DEFINE_WIDE_INTRIN(typ, vtyp, short_typ, prefix, loadsfx) \ |
There was a problem hiding this comment.
It would be nice, for "internal" macros using CV__ prefix (with double underscores).
- ASCII code of '_' is greater than A-Z, so IDE with auto-completion shows normal macros at first.
- These macros are filtered out from Doxygen automatically
| __m256i swapz = _mm256_permute2x128_si256(a.val, a.val, _MM_SHUFFLE(2, 0, 0, 1)); | ||
|
|
||
| if (imm == 0) | ||
| return a; |
There was a problem hiding this comment.
What is about definition of template specialization instead of if? At least we don't need "swapz" in this case.
| CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN | ||
| CV_CPU_OPTIMIZATION_HAL_NAMESPACE_END | ||
| using namespace CV_CPU_OPTIMIZATION_HAL_NAMESPACE; | ||
| CV_CPU_OPTIMIZATION_HAL_NAMESPACE_BEGIN |
There was a problem hiding this comment.
Please restore this code block on this place (exact after "namespace cv {").
All HAL intrinsic types must be guarded, including "V_TypeTraits".
214026f to
2c34769
Compare
|
@seiko2plus, thank you! I've merged your changes |
…s been properly tested
…s been properly tested
* core:OE-27 prepare universal intrinsics to expand (opencv#11022) * core:OE-27 prepare universal intrinsics to expand (opencv#11022) * core: Add universal intrinsics for AVX2 * updated implementation of wide univ. intrinsics; converted several OpenCV HAL functions: sqrt, invsqrt, magnitude, phase, exp to the wide universal intrinsics. * converted log to universal intrinsics; cleaned up the code a bit; added v_lut_deinterleave intrinsics. * core: Add universal intrinsics for AVX2 * fixed multiple compile errors * fixed many more compile errors and hopefully some test failures * fixed some more compile errors * temporarily disabled IPP to debug exp & log; hopefully fixed Doxygen complains * fixed some more compile errors * fixed v_store(short*, v_float16&) signatures * trying to fix the test failures on Linux * fixed some issues found by alalek * restored IPP optimization after the patch with AVX wide intrinsics has been properly tested * restored IPP optimization after the patch with AVX wide intrinsics has been properly tested
this is reworked and updated #10708 by @seiko2plus:
Tasks