Skip to content

Reworked v_popcount implementation - #14232

Merged
opencv-pushbot merged 3 commits into
opencv:3.4from
terfendail:popcount_rework
May 15, 2019
Merged

opencv-pushbot merged 3 commits into
opencv:3.4from
terfendail:popcount_rework

Conversation

@terfendail

@terfendail terfendail commented Apr 2, 2019 •

Copy link
Copy Markdown
Contributor

This pullrequest changes

Reworked v_popcount implementation to provide number of bits in a single lane

TODO:

  • Perf results
allow_multiple_commits=1
force_builders=Linux AVX2,Custom
buildworker:Custom=linux-1,linux-2,linux-4
docker_image:Custom=powerpc64le

@terfendail
terfendail force-pushed the popcount_rework branch 4 times, most recently from 9ed727e to a0efeb5 Compare April 3, 2019 12:26
@terfendail

Copy link
Copy Markdown
Contributor Author
Performance for SSE2 baseline
Performance test Reference time PR time Speedup
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.039 0.031 1.26
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.255 0.194 1.32
norm::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.037 0.028 1.29
norm::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.238 0.180 1.32
Performance for SSE3 baseline
Performance test Reference time PR time Speedup
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.039 0.031 1.26
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.259 0.197 1.32
norm::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.036 0.028 1.29
norm::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.242 0.188 1.29
Performance for SSE4_2 baseline
Performance test Reference time PR time Speedup
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.021 0.021 0.99
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.155 0.166 0.94
norm::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.015 0.015 1.00
norm::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.100 0.109 0.92
Performance for AVX2 baseline
Performance test Reference time PR time Speedup
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.012 0.012 0.96
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.159 0.149 1.06
norm::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.010 0.010 1.03
norm::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.094 0.076 1.23

Comment thread modules/core/src/stat.simd.hpp Outdated
result += v_reduce_sum(t);
v_uint64 t = vx_setzero_u64();
for(; i <= n - v_uint8::nlanes; i += v_uint8::nlanes)
t += v_popcount(v_reinterpret_as_u64(vx_load(a + i)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u64

Does u32 slower?

@terfendail terfendail Apr 3, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, u64 could use _mm_sad_epu8 intrinsic that produce u64 results(technically it produce 16-bit results but scatter them as u64)
That's the actual reason of performance gain for SSE2/SSE3, but it doesn't affect SSE42 for some reason. AVX2 isn't affected because it actually already use this intrinsic thus producing slightly incorrect result

@seiko2plus seiko2plus Apr 4, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using CV_POPCNT_U64 should increase performance when SSE4.2 is enabled

@terfendail
terfendail force-pushed the popcount_rework branch 3 times, most recently from eb6d74b to 49f0b53 Compare May 15, 2019 07:07
@terfendail

Copy link
Copy Markdown
Contributor Author
Performance for SSE2 baseline
Performance test Reference time PR time Speedup
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.039 0.031 1.24
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.255 0.204 1.25
norm::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.037 0.028 1.32
norm::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.238 0.188 1.27
Performance for SSE3 baseline
Performance test Reference time PR time Speedup
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.039 0.030 1.29
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.259 0.193 1.34
norm::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.036 0.027 1.34
norm::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.242 0.186 1.30
Performance for SSE4_2 baseline
Performance test Reference time PR time Speedup
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.021 0.021 1.01
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.155 0.164 0.94
norm::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.015 0.015 1.00
norm::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.100 0.112 0.90
Performance for AVX2 baseline
Performance test Reference time PR time Speedup
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.012 0.012 1.00
norm2::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.159 0.152 1.04
norm::PerfHamming::(NORM_HAMMING, 8UC1, 640x480) 0.010 0.010 1.00
norm::PerfHamming::(NORM_HAMMING, 8UC1, 1920x1080) 0.094 0.079 1.19

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Thank you 👍

@opencv-pushbot
opencv-pushbot merged commit 7a55f2a into opencv:3.4 May 15, 2019
@alalek alalek mentioned this pull request May 15, 2019
@terfendail
terfendail deleted the popcount_rework branch May 16, 2019 07:49
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
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.

4 participants