Repository navigation
core: Remove raw intrinsics from arithmetic operations - #12064
Conversation
|
@seiko2plus, big thanks for the patch! May I ask you to make it a bit less cryptic? :) Frankly speaking, the proposed implementation is almost impossible to read, therefore its long term support is very difficult. |
|
@vpisarev, My apologies :), I'm going to rebase this patch into multiple commits and also improve readability. |
|
@seiko2plus, thank you! To be more specific, I would like to ask you to avoid macros as much as possible. I know, we use them sometimes, e.g. for universal intrinsic implementation (which is difficult to avoid, because we map many different instructions to overloaded variants of the same inline function), but overall in the code we should try to use templates mostly for a generic code. For example, see the recently modified |
| /** @brief Saturating absolute difference | ||
|
|
||
| Returns \f$ saturate(|a - b|) \f$ . | ||
| For 8-, 16-bit signed integer source types. */ |
There was a problem hiding this comment.
Could you please add tests for new common functions (test_intrin.cpp)?
There was a problem hiding this comment.
done but I had to remove absdiff[s](signed int) and reuse absdiff(signed int) by recasting it to handle overflow which gives the same result as removed code for all archs.
| //======================================= | ||
|
|
||
| #if (ARITHM_USE_IPP == 1) | ||
| static inline void fixSteps(int width, int height, size_t elemSize, size_t& step1, size_t& step2, size_t& step) |
There was a problem hiding this comment.
This massive code migration to another file "arithm.dispatch.cpp" is not required.
"dispatch.cpp" file is not required to enable "dispatched" optimizations.
Please move this part of code back (with added changes).
|
Im not very familiar with raw intrinsics/universal intrinsics, but does the switch improve the overall performance or whats the benefits? |
79d6152 to
aec52ec
Compare
|
@vpisarev, please help me out, I don't know any other way to avoid using the current macros. I know macros are considered by many as pure evil but I think in my case in here It's a necessary evil or maybe It just possess me :). Please take the following into consideration :
Thanks ! |
|
@tompollok, Sorry for the delayed response,
I'm not sure yet I still have to run performance tests over several archs but definitely this patch going to increase performance for Power8/VSX since VSX intrinsics wasn't implemented before only X86/IPP/SSE/AVX, ARM/NEON. |
|
@seiko2plus, I've just noticed your question; let me think a bit. Using macros to define the set of very similar dispatcher functions is fine, I think. The main problem is arithm_helper.hpp, where I cannot just follow the logic. I'm sure, in a few months from now you will have hard time following it too. Since we now have universal intrinsics that use overloaded functions and operators, I suggest to start with defining template classes/functions that just do the whole thing in one loop without using any macros, something like: template<typename T, typename VecT> vecadd(const T* src1, const T* src2, T* dst, int n)
{
int i = 0;
#if CV_SIMD
const int VECSZ = VecT::nlanes;
for( ; i <= n - VECSZ; i += VECSZ ) {
VecT a = vx_load(src1 + i), b = vx_load(src2 + i);
v_store(dst + i, a + b);
}
#endif
for( ; i < n; i++ ) dst[i] = saturate_cast<T>(src1[i] + src2[i]);
}
(well, perhaps, those kernels should be made 2-dimensional to avoid the overhead on calling the 1D functions repeatedly for each single row). add, subtract, multiply, divide, absdiff, min, max, and, or, xor, not Also, a very big advantage of such a simple approach is that if you need some custom implementation of a kernel for a particular datatype, you can always create a template specialization. Then you can define higher-level dispatcher functions using macros. |
7f36e88 to
0e3dddf
Compare
450c596 to
d7f01ae
Compare
d7f01ae to
ecf6cb5
Compare
39bef02 to
7db72d6
Compare
|
@vpisarev, I'm sorry for delayed response :), I'm almost done from this patch currently I'm going to final step which is analyses compiled objects and running performance tests. Maybe I didn't literally follow your suggestions, I'm not sure if I did the right thing but I just tried to keep it simple without duplicating the same code as much as possible and without using macros only at "higher-level dispatcher functions " just like you said. Please could you give me your final review? I have free time and I'm ready to accept any radical changes even I have to rewrite this patch from scratch!. |
|
@vpisarev, please take into consideration that #12516 is required to merge first in order to successfully build this patch, also I combined the two patches at this repo /seiko2plus/opencv/coreUnvintrinArithm2_test for test purposes. |
7db72d6 to
201ebf8
Compare
6170c3e to
12fb937
Compare
…to wide universal intrinsics
- initialize arithmetic dispatcher
- add new universal intrinsic v_absdiffs
- add new universal intrinsic v_pack_b
- add accumulate version of universal intrinsic v_round
- fix sse/avx2:uint8 multiplication overflow
- reimplement arithmetic, logic and comparison operations into wide universal intrinsics
with full support for all types
- reimplement IPP arithmetic, logic and comparison operations in a sperate file arithm_ipp.hpp
- avoid scalar multiplication if scaling factor eq 1 and use integer multiplication
- move C arithmetic operations to precomp.hpp and delete [arithm_simd|arithm_core].hpp
- add compatibility with new opencv4 divide policy
12fb937 to
93ffebc
Compare
Uh oh!
There was an error while loading. Please reload this page.