Skip to content

Optimize 2 opencv 2 files (merge.cpp/split.cpp) with PowerPC VSX intrinsics. - #10371

Closed
justdoitqd wants to merge 3 commits into
opencv:masterfrom
justdoitqd:master
Closed

justdoitqd wants to merge 3 commits into
opencv:masterfrom
justdoitqd:master

Conversation

@justdoitqd

@justdoitqd justdoitqd commented Dec 21, 2017 •

Copy link
Copy Markdown
Contributor

This pullrequest changes

Optimize powerpc opencv 2 files (merge.cpp/split.cpp) with VSX intrinsics.

force_builders=Custom
docker_image:Custom=powerpc64le

@alalek

alalek commented Dec 21, 2017

Copy link
Copy Markdown
Member

Thank you for contribution!
Adding direct usage of raw intrinsics in "processing" code is not allowed anymore.
This code should be ported on OpenCV's universal intrinsics (SIMD128): see this: #9753
Missing intrinsics should be added for C++, x86, ARM, VSX backends (with tests).

@vpisarev

Copy link
Copy Markdown
Contributor

@justdoitqd, I agree with @alalek, PowerPC is quite exotic for us and many other people platform, so those platform-specific branches are at the high risk to become abandoned and poorly tested. We extensively use and promote universal intrinsics nowadays, which is the right way to write vectorized code once and then compile and run it everywhere.

@seiko2plus

Copy link
Copy Markdown
Contributor

@alalek I still remember that day when I removed hundreds of lines from #9763, I was covered all missing intrinsics in core module using VSX raw :xD but later I found that was a good decision from @vpisarev.

Can we use universal intrinsics only for VSX without remove NEON or SSE raw intrinsics, just like my review?

Adding direct usage of raw intrinsics in "processing" code is not allowed anymore.

Note: @justdoitqd uses universal intrinsics :

#define _MERGE_CPP_VSX_VEC_LD v_load
#define _MERGE_CPP_VSX_VEC_ST v_store_interleave
----
#define _SPLIT_CPP_VSX_VEC_LD v_load_deinterleave
#define _SPLIT_CPP_VSX_VEC_ST v_store

And the build failure caused by v_load_deinterleave and v_store_interleave since it missing int64 support

/build/precommit_custom_linux/opencv/modules/core/src/merge.cpp: In member function 'void cv::hal::VMerge2<long int>::operator()(const int64*, const int64*, int64*)':
/build/precommit_custom_linux/opencv/modules/core/src/merge.cpp:120:35: error: no matching function for call to 'v_store_interleave(int64*&, cv::hal_baseline::v_int64x2&, cv::hal_baseline::v_int64x2&)'
             store_func(dst, r1, r2);                                                         \
                                   ^
/build/precommit_custom_linux/opencv/modules/core/src/merge.cpp:157:1: note: in expansion of macro 'MERGE2_KERNEL_TEMPLATE'
 MERGE2_KERNEL_TEMPLATE(VMerge2, int64,  v_int64x2,  _MERGE_CPP_VSX_VEC_LD, _MERGE_CPP_VSX_VEC_ST);
 ^~~~~~~~~~~~~~~~~~~~~~
In file included from /build/precommit_custom_linux/opencv/modules/core/include/opencv2/core/hal/intrin.hpp:324:0,
                 from /build/precommit_custom_linux/opencv/modules/core/src/precomp.hpp:85,
                 from /build/precommit_custom_linux/opencv/modules/core/src/merge.cpp:44:
/build/precommit_custom_linux/opencv/modules/core/include/opencv2/core/hal/intrin_vsx.hpp:320:13: note: candidate: void cv::hal_baseline::v_store_interleave(uchar*, const cv::hal_baseline::v_uint8x16&, const cv::hal_baseline::v_uint8x16&)
 inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, const _Tpvec& b)   \
             ^
/build/precommit_custom_linux/opencv/modules/core/include/opencv2/core/hal/intrin_vsx.hpp:329:1: note: in expansion of macro 'OPENCV_HAL_IMPL_VSX_INTERLEAVE'
 OPENCV_HAL_IMPL_VSX_INTERLEAVE(uchar, v_uint8x16)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/precommit_custom_linux/opencv/modules/core/include/opencv2/core/hal/intrin_vsx.hpp:320:13: note:   no known conversion for argument 1 from 'int64* {aka long int*}' to 'uchar* {aka unsigned char*}'
 inline void v_store_interleave(_Tp* ptr, const _Tpvec& a, const _Tpvec& b)   \
             ^
/build/precommit_custom_linux/opencv/modules/core/include/opencv2/core/hal/intrin_vsx.hpp:329:1: note: in expansion of macro 'OPENCV_HAL_IMPL_VSX_INTERLEAVE'
 OPENCV_HAL_IMPL_VSX_INTERLEAVE(uchar, v_uint8x16)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/precommit_custom_linux/opencv/modules/core/include/opencv2/core/hal/intrin_vsx.hpp:322:13: note: candidate: void cv::hal_baseline::v_store_interleave(uchar*, const cv::hal_baseline::v_uint8x16&, const cv::hal_baseline::v_uint8x16&, const cv::hal_baseline::v_uint8x16&)
 inline void v_store_interleave(_Tp* ptr, const _Tpvec& a,                    \
             ^
/build/precommit_custom_linux/opencv/modules/core/include/opencv2/core/hal/intrin_vsx.hpp:329:1: note: in expansion of macro 'OPENCV_HAL_IMPL_VSX_INTERLEAVE'
 OPENCV_HAL_IMPL_VSX_INTERLEAVE(uchar, v_uint8x16)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/build/precommit_custom_linux/opencv/modules/core/include/opencv2/core/hal/intrin_vsx.hpp:322:13: note:   candidate expects 4 arguments, 3 provided
 inline void v_store_interleave(_Tp* ptr, const _Tpvec& a,                    \
             ^
/build/precommit_custom_linux/opencv/modules/core/include/opencv2/core/hal/intrin_vsx.hpp:329:1: note: in expansion of macro 'OPENCV_HAL_IMPL_VSX_INTERLEAVE'
 OPENCV_HAL_IMPL_VSX_INTERLEAVE(uchar, v_uint8x16)

Currently uint64/int64 version interleave load/store is missed.
This patch adds the related API in.

Signed-off-by: Simon Guo <[email protected]>
Optimize modules/core/src/merge.cpp with v_load/vec_st_interleave.

Signed-off-by: Simon Guo <[email protected]>
@justdoitqd

Copy link
Copy Markdown
Contributor Author

@seiko2plus Ah.. My bad... I forgot to pull the related change regarding "OPENCV_HAL_IMPL_VSX_INTERLEAVE(int64, v_int64x2)" in my branch in. And I should rebuilt on the commit branch. Thanks for pointing it out. I added the missing commit.

@alalek @vpisarev
As seiko2plus mentioned, the change is already using general intrinsics v_store_interleave/v_load_deinterleave/v_load/v_store. They are already implemented for SSE/NEON.

Please let me know if I still miss anything.

@vpisarev

vpisarev commented Dec 22, 2017 •

Copy link
Copy Markdown
Contributor

@justdoitqd, @seiko2plus, most of the time when we add branches with universal intrinsics, the corresponding native NEON/SSE branches can be removed. Of course, in some rare cases that may result in some performance degradation, but I would rather solve it by introducing new, higher-level universal intrinsics, or even by introducing small chunks of SSE/NEON-specific code (like here: https://github.com/opencv/opencv/blob/master/modules/dnn/src/layers/pooling_layer.cpp#L418). But while the latter approach might be fine for x86-specific code, because we and our users test it all the time, it may be not a good solution for PPC, because of the much smaller user base.

Ultimately, there should be just universal intrinsics and that's the direction we should go to.

@seiko2plus

Copy link
Copy Markdown
Contributor

@alalek, @vpisarev, Thank you for the clarification.

@vpisarev

Copy link
Copy Markdown
Contributor

@justdoitqd, as I see, the latest version still uses the macro CV_VSX, that is, even if the actual code is using universal intrinsics, the branches are not included into the regular x86/x64/ARM builds. To make those branches universally available, I suggest to use CV_SIMD128 macro instead.

@justdoitqd

Copy link
Copy Markdown
Contributor Author

@vpisarev. I see. I will try to find some timeslot to get this done to use CV_SIMD128 covering NEON/VSX. However my problem is that I don't have a ARM server to test whether ARM will work. Is it OK for me to only test PowerPC since the code will be common?

@vpisarev

Copy link
Copy Markdown
Contributor

@justdoitqd, yes, it's ok. Also, you likely have x86/x64 machine somewhere, e.g. your laptop, so you can test it as well. Then, as soon as you switch from CV_VSX to CV_SIMD128, our buildbot will automatically test the code on Intel/AMD and ARM CPUs that we have in our battery of test machines.

@edelsohn

Copy link
Copy Markdown

@vpisarev What is the procedure to add a VM at OSUOSL to the OpenCV buildbot?

@vpisarev

vpisarev commented Apr 9, 2018

Copy link
Copy Markdown
Contributor

sorry for a long delay with reply; there is no well-defined procedure of adding new build slaves to our buildbot, because each new build slave will take extra resources from the OpenCV core team to support it. For now you may use the "Custom" build slave with special magic commands, see the top-most comment:

force_builders=Custom
docker_image:Custom=powerpc64le

@vpisarev

vpisarev commented Apr 9, 2018

Copy link
Copy Markdown
Contributor

as we agreed to go the universal intrinsics route, let's close this PR

@vpisarev vpisarev closed this Apr 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants