Repository navigation
imgproc: remove raw SSE2/NEON implementation from imgwarp.cpp - #11169
Conversation
|
/cc @seiko2plus
|
|
Hmmm, I only payed attention on The situation what is happening is that they are "warp" processing. I'll have a look by loosening some thresholds. |
| CV_PICK_AND_PACK_RGB(S1, iofs0[2], cn, v0); | ||
| CV_PICK_AND_PACK_RGB(S0, iofs0[3], cn, u1); | ||
| CV_PICK_AND_PACK_RGB(S1, iofs0[3], cn, v1); | ||
|
|
There was a problem hiding this comment.
No need for "loosen the threshold", I think you just forget to load next offset of bilinear lookup table.
int offset2 = FXY[x + 2] * 16;
int offset3 = FXY[x + 3] * 16;
w00 = v_load(wtab + offset2);
w01 = v_load(wtab + offset2 + 8);
w10 = v_load(wtab + offset3);
w11 = v_load(wtab + offset3 + 8);
b0bb8ad to
837e6da
Compare
|
Thank you @seiko2plus, indeed that's my mistake. Though we had a nice review from @seiko2plus , still I had to loosen the check on Normal rounding errorLet's think of linear interpolation. It's take a weighted average of 4 pixels. Simply writing and this will have 4 multiply and 3 add in float. Rounding error in this PRNow, image warping is a coordinate computation in float. So now the rounding error happens not only on Though, still this rarely happens, so it's almost impossible to tell the difference just viewing the output image by human eye. solution used in this PRI added a dirty workaround in the My point is, due to the rounding error, we need to loosen the |
837e6da to
d81c6f9
Compare
|
Am I supposed to fix the test failure on Mac machine ? |
|
3/3 Mac builder failures. |
|
Code tries to read after the buffer end. (don't run all tests at once, this patch has huge memory leaks) Details |
* use universal intrinsic instead of raw intrinsic * add 2 channels de-interleave on x86 platform * implement loose verify in performance check
* use universal intrinsic instead of raw intrinsic * add 2 channels de-interleave on x86 platform * implement loose verify in performance check
e4a5f2e to
8edeb5c
Compare
|
I really appreciate your help, @alalek ( I always say this but this time was way difficult to figure out ) I was reading out of the buffer. |
| v_int16x8 xy2ofs = v_reinterpret_as_s16(v_setall_s32(cn + (sstep << 16))); | ||
| int CV_DECL_ALIGNED(16) iofs0[4], iofs1[4]; | ||
|
|
||
| #define CV_PICK_AND_PACK_RGB(ptr, offset, cn, result) \ |
There was a problem hiding this comment.
Right, I'll fix this
| v_uint8x16 rgb1 = v_uint8x16(p[offset+3],p[offset+4],p[offset+5], 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); \ | ||
| v_zip(rgb0, rgb1, rrggbb, dummy); \ | ||
| v_expand(rrggbb, rrggbb8, dummy8); \ | ||
| result = v_reinterpret_as_s16(rrggbb8); \ |
There was a problem hiding this comment.
Do we need here zip/expand vector intrinsics?
result = v_int16x8((short)p[offset+0], (short)p[offset+3], (short)p[offset+1], (short)p[offset+4], (short)p[offset+2], (short)p[offset+5], 0, 0);
There was a problem hiding this comment.
The only reason I implemented this way is that I followed the previous way.
Yeah, your suggestion look better.
Yes, they already implemented on VSX and I'll provide performance comparison for ppc64le later.
You are very welcome and thank you for the clarification. |
| d0 = v_load((int*)(wtab+FXY[x+3]*4)); | ||
| v_transpose4x4(a0, b0, c0, d0, a1, b1, c1, d1); | ||
| v0 = v_dotprod(v_reinterpret_as_s16(v0), v_reinterpret_as_s16(a1)); | ||
| v1 = v_dotprod(v_reinterpret_as_s16(v1), v_reinterpret_as_s16(b1)); |
There was a problem hiding this comment.
Wouldn't it be better if we load the lower 64 bits using "v_load_low" as it was before?
note: wtab has special case for 1 channel
const short* wtab = cn == 1 ? (const short*)_wtab : &BilinearTab_iC4[0][0][0];
There was a problem hiding this comment.
Right, let's keep the v_load_low
858cdda to
f5caadb
Compare
|
Hmm, it's seems that on some modes, this PR degrades the performance. |
|
Yes indeed, I did some performance tests on ppc64le and I got a lot of performance lose.. the comparison has been tested only on Remap(8UC4) for now, since I had to write SIMD code by using raw VSX intrinsics. VSX raw which has been used in comparison// just for 4 channel
#define VSX_PICK_AND_PACK_RGB(ptr, offset, cn, rs) \
do { \
vec_char16 a = vec_char16_c(vec_int4_sp(*(int*)(ptr + offset))); \
vec_char16 b = vec_char16_c(vec_int4_sp(*(int*)(ptr + offset + cn))); \
rs = vec_short8_c(vec_mergeh(vec_mergeh(a, b), vec_char16_z)); \
} while(0)
for( ; x <= width - 4; x += 4, D += 16 )
{
vsx_st(vec_msum(vsx_ld(x * 2, XY), xy2ofs.val, vec_int4_z), 0, iofs0);
vec_short8 u0, v0, u1, v1;
VSX_PICK_AND_PACK_RGB(S0, iofs0[0], cn, u0);
VSX_PICK_AND_PACK_RGB(S1, iofs0[0], cn, v0);
VSX_PICK_AND_PACK_RGB(S0, iofs0[1], cn, u1);
VSX_PICK_AND_PACK_RGB(S1, iofs0[1], cn, v1);
int offset0 = FXY[x] * 16;
int offset1 = FXY[x + 1] * 16;
vec_short8 w00 = vsx_ld(offset0, wtab);
vec_short8 w01 = vsx_ld(offset0 + 8, wtab);
vec_short8 w10 = vsx_ld(offset1, wtab);
vec_short8 w11 = vsx_ld(offset1 + 8, wtab);
vec_int4 u0_4 = vec_msum(u0, w00, vec_msum(v0, w01, delta.val));
vec_int4 u1_4 = vec_msum(u1, w10, vec_msum(v1, w11, delta.val));
const vec_uint4 v_coef_bits = vec_uint4_sp(INTER_REMAP_COEF_BITS);
u0_4 = vec_sra(u0_4, v_coef_bits);
u1_4 = vec_sra(u1_4, v_coef_bits);
u0 = vec_packs(u0_4, u1_4);
vec_st_l8(vec_packsu(u0, u0), D);
int offset2 = FXY[x + 2] * 16;
int offset3 = FXY[x + 3] * 16;
w00 = vsx_ld(offset2, wtab);
w01 = vsx_ld(offset2 + 8, wtab);
w10 = vsx_ld(offset3, wtab);
w11 = vsx_ld(offset3 + 8, wtab);
VSX_PICK_AND_PACK_RGB(S0, iofs0[2], cn, u0);
VSX_PICK_AND_PACK_RGB(S1, iofs0[2], cn, v0);
VSX_PICK_AND_PACK_RGB(S0, iofs0[3], cn, u1);
VSX_PICK_AND_PACK_RGB(S1, iofs0[3], cn, v1);
u0_4 = vec_msum(u0, w00, vec_msum(v0, w01, delta.val));
u1_4 = vec_msum(u1, w10, vec_msum(v1, w11, delta.val));
u0_4 = vec_sra(u0_4, v_coef_bits);
u1_4 = vec_sra(u1_4, v_coef_bits);
u0 = vec_packs(u0_4, u1_4);
vec_st_l8(vec_packsu(u0, u0), D + 8);
}test results
@tomoaki0705, so I think if you could combine this patch bf1852d with yours and improve PACK_RGB to be close to VSX raw then we will get the exact performance on ppc64le by using universal intrinsics , I didn't run any tests on SSE or NEON yet but I'm kinda sure the same needed for them. |
|
So it took very long time to check the performance degrade. Also, The result became so large, I pasted on gist.(To be Updated) Now, I extracted some results here As it's clear in this PR, this access has a chance to access after the buffer, so it's dangerous. Please let me know if there's any modification required. ODROID-X2 Ubuntu 14.04 Cortex A9 Quad-core 1.7GHz
ODROID-C2 Cortex A53 1.5GHz
Windows x86_64 Corei7 7700K Quad-core 4GHz
|
c87fb2e to
d275826
Compare
| v_int16x8 w01 = v_load(wtab + offset0 + 8); | ||
| v_int16x8 w10 = v_load(wtab + offset1); | ||
| v_int16x8 w11 = v_load(wtab + offset1 + 8); | ||
| CV_PICK_AND_PACK_RGB(S0, iofs0[0], u0); |
There was a problem hiding this comment.
There should be separate macro CV_PICK_AND_PACK_RGBA() (not RGB).
Also there is no issue with buffer overrun with 8UC4.
Something like this:
#define CV_PICK_AND_PACK_RGBA(ptr, offset, result) \
{ \
const uchar* const p = ((const uchar*)ptr) + (offset); \
CV_DbgAssert(p <= _src.datalimit - 8); \
v_uint8x16 rrggbb, dummy; \
v_uint16x8 rrggbb8, dummy8; \
v_uint8x16 rgb0 = v_reinterpret_as_u8(v_int32x4(*(int*)(p), 0, 0, 0)); \
v_uint8x16 rgb1 = v_reinterpret_as_u8(v_int32x4(*(int*)(p + 4), 0, 0, 0)); \
v_zip(rgb0, rgb1, rrggbb, dummy); \
v_expand(rrggbb, rrggbb8, dummy8); \
result = v_reinterpret_as_s16(rrggbb8); \
}
There was a problem hiding this comment.
Thank you, I added CV_PICK_AND_PACK_RGBA
| unsigned char* p = (unsigned char*)ptr; \ | ||
| result = v_int16x8((short)p[offset], (short)p[offset+3], /* r0r1 */ \ | ||
| (short)p[offset+1], (short)p[offset+4], /* g0g1 */ \ | ||
| (short)p[offset+2], (short)p[offset+5], /* b0b1 */ 0, 0); \ |
There was a problem hiding this comment.
Buffer overrun is very rare case here, so we can use check here:
#define CV_PICK_AND_PACK_RGB(ptr, offset, result) \
{ \
const uchar* const p = ((const uchar*)ptr) + (offset); \
if (p <= src_limit_8bytes) \
{ \
v_uint8x16 rrggbb, dummy; \
v_uint16x8 rrggbb8, dummy8; \
v_uint8x16 rgb0 = v_reinterpret_as_u8(v_int32x4(*(int*)(p), 0, 0, 0)); \
v_uint8x16 rgb1 = v_reinterpret_as_u8(v_int32x4(*(int*)(p + 3), 0, 0, 0)); \
v_zip(rgb0, rgb1, rrggbb, dummy); \
v_expand(rrggbb, rrggbb8, dummy8); \
result = v_reinterpret_as_s16(rrggbb8); \
} \
else \
{ \
result = v_int16x8((short)p[0], (short)p[3], /* r0r1 */ \
(short)p[1], (short)p[4], /* g0g1 */ \
(short)p[2], (short)p[5], /* b0b1 */ 0, 0); \
} \
}
where
const uchar* src_limit_8bytes = _src.datalimit - 8;
Alternatively we can try reading "int" + "short casted to int".
There was a problem hiding this comment.
Thank you, I followed your comment
| else if( cn == 3 ) | ||
| { | ||
| for( ; x <= width - 5; x += 4, D += 12 ) | ||
| for( ; x <= width - 15; x += 4, D += 12 ) |
There was a problem hiding this comment.
I switched back to "5", but still 5 doesn't look correct either.
Maybe "3" or "cn" stands better
| ERROR_ABSOLUTE = 0, | ||
| ERROR_RELATIVE = 1 | ||
| ERROR_RELATIVE = 1, | ||
| ERROR_LOOSE = 2 |
There was a problem hiding this comment.
Please revert these changes in test framework.
You can use SANITY_CHECK_NOTHING() in perf tests if reliable check is not possible (like these warp operations).
There was a problem hiding this comment.
I reverted ERROR_LOOSE and added SANITY_CHECK_NOTHING in some tests
Thank you
| Implemented only for 16-bit signed source type (v_int16x8). | ||
| */ | ||
|
|
||
| inline v_int32x4 v_dotprod_add(const v_int16x8& a, const v_int16x8& b, const v_int32x4& c) |
There was a problem hiding this comment.
Perhaps we can reuse v_dotprod() name with additonal parameter for initial accumulator value.
/cc @mshabunin ?
There was a problem hiding this comment.
So this part was bit suspicious.
If we combine v_dotprod and v_dotprod_add there might be unnecessary "Plus Zero" operation every where in the source code.
I did some experiments, and at least Visual Studio seems to be good enough to wipe out "Plus Zero" instruction.
I hope GCC is good enough too, so I reverted v_dotprod_add and combined with the existing v_dotprod.
There was a problem hiding this comment.
I mean adding of just v_dotprod() overload with three params. No need to touch old function with 2 parameters.
There was a problem hiding this comment.
Oops, I've missed this comment.
Let me put back the v_dotprod
| @@ -231,7 +231,7 @@ PERF_TEST_P( TestRemap, remap, | |||
| remap(source, destination, map_x, map_y, interpolationType, borderMode); | |||
There was a problem hiding this comment.
8UC3 case is not covered by tests.
Perhaps we need to add test for 8UC3 (to keep perf tests set compact we can remove sz720p (it is highly correlates with 1080p)):
Values(CV_8UC1, CV_8UC3, CV_8UC4, CV_32FC1),
Values(szVGA, sz1080p),
There was a problem hiding this comment.
Updated the test condition
| #include "opencv2/core/openvx/ovx_defs.hpp" | ||
| #include "imgwarp.hpp" | ||
|
|
||
| #include <iostream> |
There was a problem hiding this comment.
Yep, It was the debug use.
I reverted. Thank you
d275826 to
96b83cb
Compare
| #define OVER_EPS(name,eps) (eps < fabs(actual_##name - expect_##name)) | ||
| void Regression::verifyLoose(cv::FileNode node, cv::Mat actual, double eps, std::string argname, ERROR_TYPE err) | ||
| { | ||
| if (!actual.empty() && actual.dims < 2) return; |
There was a problem hiding this comment.
Perhaps these changes are not needed too.
There was a problem hiding this comment.
No more modification left in the ts module
f053403 to
6704080
Compare
2c695a4 to
8268fd7
Compare
|
Just a quick check on If precise check needed, I'll update the check next week. Median
|
|
@tomoaki0705 Performance is fine to me (tested on Linux with i7-6700K). |
| int32x4x2_t cd = vuzpq_s32(c, d); | ||
| int32x4_t _c = vmull_s16(vget_low_s16(a.val), vget_low_s16(b.val)); | ||
| int32x4_t _d = vmull_s16(vget_high_s16(a.val), vget_high_s16(b.val)); | ||
| int32x4x2_t cd = vuzpq_s32(_c, _d); |
There was a problem hiding this comment.
I forgot to revert this part. updated.
| v_reg<w_type, n/2> c; | ||
| v_reg<w_type, n/2> s; | ||
| for( int i = 0; i < (n/2); i++ ) | ||
| c.s[i] = (w_type)a.s[i*2]*b.s[i*2] + (w_type)a.s[i*2+1]*b.s[i*2+1]; |
There was a problem hiding this comment.
Looks like this rename change is not necessary.
| OPENCV_HAL_IMPL_NEON_EXTRACT(float64x2, f64) | ||
| #endif | ||
|
|
||
| #if CV_SIMD128_64F |
There was a problem hiding this comment.
Is fcvtns from AARCH64 only? (#if defined(__aarch64__))
| // of this distribution and at http://opencv.org/license.html. | ||
| #include "perf_precomp.hpp" | ||
|
|
||
| #include "opencv2/ts/ts_perf.hpp" |
There was a problem hiding this comment.
Please remove this unnecessary include, it should be handled by perf_precomp.hpp (via opencv2/ts.hpp).
There was a problem hiding this comment.
I reverted. Thank you for the comment
* use universal intrinsic instead of raw intrinsic * add 2 channels de-interleave on x86 platform * add v_int32x4 version of v_muladd * add accumulate version of v_dotprod based on the commit from seiko2plus on bf1852d * remove some verify check in performance test * avoid the out of boundary access and keep the performance
8268fd7 to
a82e70c
Compare
Uh oh!
There was an error while loading. Please reload this page.