https://github.com/JuliaLang/julia
Revision 1535e2928e7fff6f5e4c0372794b2f33624f57a7 authored by Keno Fischer on 17 October 2021, 23:54:44 UTC, committed by Keno Fischer on 18 October 2021, 00:07:01 UTC
I thought I needed this, but turns out I probably don't.
I still think it could be useful in the future, so I'm putting
it here, in case somebody (maybe me in the future) ever needs this.
There are three algorithms implemented here, as well as a selection
heuristic for switching between them. The three algorithms are:

1. Out-of-place with a stack buffer
2. Batched Cycle-chasing in place
3. The Knuth Triple-Reverse trick

Of these, the cycle chasing algorithm has optimal memory complexity
(by doing `N` loads and stores), but conventional wisdom is that it
is slower than triple-reverse (which does 2N memory operations)
because of cache inefficiencies. I found this to be true for non-batched
cycle chasing, but not for batched cycle chasing once the batching
factor was about a cache line or so.

As such, the polyalgorithm does the following:
a. For small arrays, use the on-stack copy
b. Then, compute the GCD. If the problem admits large batching factors,
   do the batched cycle chasing algorithm.
c. If not, use the triple reverse trick, which is less memory efficent,
   but has consistent performance (unlike cycle chasing whose performance
   depends on the batching factor).

There are additional algorithms listed at https://github.com/scandum/rotate
that could be investigated to replace the reversal fallback.

There are variations that compute the GCD from the first cycle, but
I found that to be unnecessary. For arrays small enough for the GCD
computation cost to matter, we're using the on-stack copy anyway,
and for anything larger, the GCD is negligible and we use it to
make the polyalgorithm decision anyway.

I think to finish this, all we'd need is
- [] Some tests to make sure all the cases are covered (and fix cases that
     may be broken, I did some refactoring, without retesting those)
- [] Ideally, a little more benchmarking to more carefully select the
     algorithmic cutovers.
1 parent 4805d54
History
Tip revision: 1535e2928e7fff6f5e4c0372794b2f33624f57a7 authored by Keno Fischer on 17 October 2021, 23:54:44 UTC
WIP: Fast 1-d in-place circshift!
Tip revision: 1535e29
File Mode Size
.buildkite
.devcontainer
.github
base
cli
contrib
deps
doc
etc
src
stdlib
test
.clang-format -rw-r--r-- 3.3 KB
.codecov.yml -rw-r--r-- 52 bytes
.gitattributes -rw-r--r-- 65 bytes
.gitignore -rw-r--r-- 291 bytes
.mailmap -rw-r--r-- 11.1 KB
CITATION.bib -rw-r--r-- 513 bytes
CITATION.cff -rw-r--r-- 942 bytes
CONTRIBUTING.md -rw-r--r-- 19.8 KB
HISTORY.md -rw-r--r-- 333.2 KB
LICENSE.md -rw-r--r-- 1.3 KB
Make.inc -rw-r--r-- 49.2 KB
Makefile -rw-r--r-- 25.5 KB
NEWS.md -rw-r--r-- 3.7 KB
README.md -rw-r--r-- 8.0 KB
THIRDPARTY.md -rw-r--r-- 3.7 KB
VERSION -rw-r--r-- 10 bytes
sysimage.mk -rw-r--r-- 4.0 KB

README.md

back to top