Repository navigation
core: remove raw SSE2/NEON implementation from matmul.cpp - #9753
Conversation
7b8b780 to
b904775
Compare
|
@tomoaki0705, thank you very much! Did you compare performance of the original and the new implementation? As I see, there are some minor differences, it's not exactly 1:1 rewrite. |
|
Thank you for your comment.Indeed, I forgot to measure the performance. |
|
I'm now back with the measurement result, but the number doesn't look that well. I used the test
So, basically as @vpisarev concerned, |
|
@tomoaki0705, thank you! So, let's pause the patch integration until 8u performance degradation is fixed. |
|
@tomoaki0705 @vpisarev I think we should implement the following intrinsics Left and right shifts 128bits Multiply splat b and add |
|
It almost took 2 weeks but now I'm back with some results. To be sure about the performance, I added For this moment, I'll dump the result on Windows ( Compiler Visual Studio 2013 update 5
|
|
Now, there are many things to be solved before the merge. I'll write them down not to miss any of them.
|
|
I believe you can skip these things in this order:
|
|
@tomoaki0705 BTW, You could use #9922 patch to generate reports in markdown-like format. |
|
@tomoaki0705 leave implementation of new universal intrinsic for powerpc to me, I'm going to implement it into #9907 |
|
@alalek No need to guard new intrinsics unless this patch is going to be merged first. |
|
@alalek , Thanks for the help. @seiko2plus It's a very kind offer. thank you very much! |
2cbd6bc to
c91874c
Compare
|
Here's performance test from some ARM devices ODROID-X2
ODROID-C2
Jetson-TK1
Jetson-TX1
Jetson-TX2
|
|
merge with opencv/opencv_extra#400 |
5ea32ec to
0f652cc
Compare
0f652cc to
727e154
Compare
|
So, after all this work, I had to give up Using the current |
727e154 to
fd5e632
Compare
|
Now this PR is ready for review |
fd5e632 to
6353b93
Compare
|
Something is wrong with Debug and The problem is the Probably It's better to sleep and re-check tomorrow.. |
|
Error message:
This usually means that check condition is wrong - it uses absolute diff value instead of relative. -SANITY_CHECK(dst, 1e-6);
+SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE); |
8a4ba62 to
830a998
Compare
|
|
||
| OCL_TEST_CYCLE() cv::transform(src, dst, mtx); | ||
|
|
||
| SANITY_CHECK(dst, 1e-6); |
There was a problem hiding this comment.
Probably this check should be changed too.
There was a problem hiding this comment.
Thank you !
Fixed and pushed
830a998 to
b258c9a
Compare
alalek
left a comment
There was a problem hiding this comment.
Could you please add separate commit with new perf tests without implementation changes (to measure performance with old and new implementation)?
| randu(mtx, 0, 1); | ||
| if (CV_MAT_DEPTH(type) < CV_32F) | ||
| { | ||
| src &= mask; |
There was a problem hiding this comment.
On some situation, the sanity check was raising error.
It seems that the final result was larger than the maximum of int
The RNG was filling all 32bits of the input, so in some cases, the transform ends in following process,
0x8fffffff * 1 + 0x8fffffff * 1 + 1
which is clearly larger than the maximum of int.
If there's a way to restrict the range of the input matrix, that would be great, but this was the best way I know.
Does this make sense ?
There was a problem hiding this comment.
Thanks!
randu(src, 0, 0xffffff); // need to adjust max value for different types 8U/8S, 16U/16S, 32S
// perhaps 30 would work for all types (30*1+30*1+30*1+1)
declare.in(src).out(dst); // without WARMUP_RNG (default is WARMUP_READ)
Perhaps we should use fixed values of transform matrix instead of random.
b258c9a to
48de2b7
Compare
|
@alalek , thank you for the review. Best. |
* add performance tests for transform and dotProduct * add test Core_TransformLargeTest for 8u version of transform
* use universal intrinsic instead of raw intrinsic * remove unused templated function * add v_matmuladd which multiply 3x3 matrix and add 3x1 vector * add v_rotate_left/right in universal intrinsic * suppress intrinsic on some function and platform * add pure SW implementation of new universal intrinsics * add test for new universal intrinsics
48de2b7 to
c75cff7
Compare
| { | ||
| // load 4 pixels | ||
| v_uint16x8 v0_16 = v_load(src + x); // b0 g0 r0 b1 g1 r1 b2 g2 | ||
| v_uint16x8 v2_16 = v_load(src + x + cWidth * 2); // r2 b3 g3 r3 0 0 0 0 |
There was a problem hiding this comment.
There is no 0,0,0,0 values - it is out of buffer reading.
We currently don't have v_load_low (similar to v_store_low) intrinsic to use it here (see #10083).
Something like this should work somehow:
// load 4 pixels
v_uint16x8 v0_16 = v_load(src + x); // b0 g0 r0 b1 g1 r1 b2 g2
v_uint16x8 v2_16 = v_load(src + x + cWidth * 3 - 8); // g1 r1 b2 g2 r2 b3 g3 r3
// expand to 4 vectors
v_uint32x4 v0_32, v1_32, v2_32, v3_32, dummy_32;
v_expand(v_rotate_right<3>(v0_16), v1_32, dummy_32); // b1 g1 r1
v_expand(v_rotate_right<5>(v2_16), v3_32, dummy_32); // b3 g3 r3
v_expand(v_rotate_right<2>(v2_16), v2_32, dummy_32); // b2 g2 r2
v_expand(v0_16, v0_32, dummy_32); // b0 g0 r0
BTW, Did you try to use this function?
void v_load_deinterleave(const ushort* ptr, v_uint16x8& a, v_uint16x8& b, v_uint16x8& c)
(but it loads 8 pixels instead of 4)
9e020df to
17ecd46
Compare
| { | ||
| #if CV_SSE2 | ||
| if( USE_SSE2 && scn == 3 && dcn == 3 ) | ||
| #if CV_SIMD128 && !defined(__aarch64__) |
There was a problem hiding this comment.
@tomoaki0705 Just for clarification, why code is disabled for __aarch64__? performance regressions?
There was a problem hiding this comment.
Yes I disabled on __aarch64__ for performance reason.
Auto optimization of compiler matched well for 16U on 64bit ARM
An example of measurement from Mat_Transform::Size_MatType::(1920x1080, 16UC3) on several __aarch64__ platform.
The column "after" stands for universal intrinsic and "before" stands for pure C++ code with compiler optimization.
The x-factor had similar value on every size.
| platform | before | after | x-factor |
|---|---|---|---|
| Jetson-TX1 | 64.104 ms | 117.306 ms | 0.55 |
| Jetson-TX2 | 47.393 ms | 102.986 ms | 0.46 |
| ODROID-C2 | 145.647 ms | 176.398 ms | 0.83 |
* add accuracy test and performance check for matmul * add performance tests for transform and dotProduct * add test Core_TransformLargeTest for 8u version of transform * remove raw SSE2/NEON implementation from matmul.cpp * use universal intrinsic instead of raw intrinsic * remove unused templated function * add v_matmuladd which multiply 3x3 matrix and add 3x1 vector * add v_rotate_left/right in universal intrinsic * suppress intrinsic on some function and platform * add pure SW implementation of new universal intrinsics * add test for new universal intrinsics * core: prevent memory access after the end of buffer * fix perf tests
Merge with extra: opencv/opencv_extra#400
This pullrequest changes
Core_TransformLargeTestfor 8u version of transform