Skip to content

Single-threaded performance improvements in forward DWT for 5-3 and 9-7 (and other improvements)#1253

Merged
rouault merged 24 commits intouclouvain:masterfrom
rouault:floating_point_irreversible_encoding
Oct 9, 2020
Merged

Single-threaded performance improvements in forward DWT for 5-3 and 9-7 (and other improvements)#1253
rouault merged 24 commits intouclouvain:masterfrom
rouault:floating_point_irreversible_encoding

Conversation

@rouault
Copy link
Copy Markdown
Collaborator

@rouault rouault commented May 24, 2020

Summary of improvements:

  • Switches forward 9-7 DWT to using 32-bit floating point operations instead of fixed point arithmetic
  • For 5-3 and 9-7 foward DWT, perform the vertical pass on 8 columns at a time for better cache efficiency and to be able to use SSE2 (for 5-3) and SSE (for 9-7)
  • forward DWT: more efficient 5-3 and 9-7 horizontal pass processing (removal of useless bound checking)
  • inverse 9-7 DWT: add multi-threading and operate on 8 columns at a time for vertical pass
  • bench_dwt utility extended to support irreversible wavelet
  • performance improvements in T1 encoder (~ 9%)

Combined effect of those improvements on the bench used in PR 1248 (time bin/opj_compress -threads XXXX -n 5 -c [256,256],[256,256],[256,256],[256,256],[256,256] -t 1024,1024 -PLT -i T36JTT_20160914T074612_B02.tif -o out.jp2 >/dev/null)

PR 1248 Now
Threads = 0 17.9 s 15.3 s
Threads = 4 5.7 s 5.0 s
Threads = 8 4.4 s 4.0 s

(For convenience this PR is based on top of PR 1248, so the first 2 commits "Add multithreading ..." belong to this later one)


Funded by ESA for S2-MPC project

rouault added 24 commits May 20, 2020 20:30
- API wise, opj_codec_set_threads() can be used on the encoding side
- opj_compress has a -threads switch similar to opj_uncompress
Update the bench_dwt utility to have a -decode/-encode switch

Measured performance gains for DWT encoder on a
Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (4 cores, hyper threaded)

Encoding time:
$ ./bin/bench_dwt -encode -num_threads 1
time for dwt_encode: total = 8.348 s, wallclock = 8.352 s

$ ./bin/bench_dwt -encode -num_threads 2
time for dwt_encode: total = 9.776 s, wallclock = 4.904 s

$ ./bin/bench_dwt -encode -num_threads 4
time for dwt_encode: total = 13.188 s, wallclock = 3.310 s

$ ./bin/bench_dwt -encode -num_threads 8
time for dwt_encode: total = 30.024 s, wallclock = 4.064 s

Scaling is probably limited by memory access patterns causing
memory access to be the bottleneck.
The slightly worse results with threads==8 than with thread==4
is due to hyperthreading being not appropriate here.
…id messing up with stepsize (no functional change)
…tandard

The previous constant opj_c13318 was mysteriously equal to 2/K , and in
the DWT, we had to divide K and opj_c13318 by 2... The issue was that the
band->stepsize computation in tcd.c didn't take into account the log2gain of
the band.

The effect of this change is expected to be mostly equivalent to the previous
situation, except some difference in rounding. But it leads to a dramatic
reduction of the mean square error and peak error in the irreversible encoding
of issue141.tif !
"bench_dwt -I" time goes from 2.8s to 2.2s
Nothing in code analysis nor test suite shows that this margin is
needed.
It dates back to commit dbeebe7
where vector 9x7 decoding was introduced.
"bench_dwt -I" time goes from 2.2s to 1.5s
`bench_dwt -encode` times goes from 7.9s to 1.7s
`bench_dwt -I -encode` times goes from 8.6s to 2.1s
…ata organization

~ 9% speed improvement seen on 10980x10980 uint16 image, T36JTT_20160914T074612_B02.tif
opj_compress time from 17.2s to 15.8s
@rouault
Copy link
Copy Markdown
Collaborator Author

rouault commented May 24, 2020

CC @savmickael This is ready for your review

@rouault
Copy link
Copy Markdown
Collaborator Author

rouault commented Oct 5, 2020

@savmickael I'll merge this soon (before end of week), unless you want to have a look before

@rouault rouault merged commit 491299e into uclouvain:master Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant