项目作者: loop-fusion

项目描述 :
A header-only C++ 17 library for merging loops
高级语言: C++
项目地址: git://github.com/loop-fusion/loop-fusion.git
创建时间: 2020-02-06T15:48:49Z
项目社区:https://github.com/loop-fusion/loop-fusion

开源协议:MIT License

下载


Loop Fusion

CircleCI

loop_fusion is a header-only library for merging multiple loop bodies of equal or different ranges for more efficient execution that can benefit from CPU caching.

For more detailed information, please refer to the documentation and the presentation slides.

Goal

We try to create a header-only library that allows users to manually
fuse/merge loops.

What is loop fusion?

Assume you have the following code:

  1. for (size_t i = 0; i < a.size(); ++i) {
  2. a[i] = b[i] + c[i];
  3. }
  4. // [...] code that is independent from the loop
  5. for (size_t i = 0; i < a.size(); ++i) {
  6. d[i] = a[i] + f[i];
  7. }

We see that both loops are independent. The compiler could fuse those two loops
to a single one to save one pass. However it most likely will not because there
may be side effects that the compiler is not able to detect.

By using this library, users can merge the loops above by wrapping their contents
in lambdas like the following examples shows:

  1. #include <loop_fusion/loop_fusion.hpp>
  2. int main(int argc, char** argv) {
  3. using namespace loop_fusion::main_range;
  4. // a, b, c, d and f are arrays declared outside of this example
  5. auto loop_body_1 = [&](size_t i) { a[i] = b[i] + c[i]; };
  6. auto loop_body_2 = [&](size_t i) { d[i] = a[i] + f[i]; };
  7. // The following line merges and executes the two loop bodies
  8. // so that they are executed after another in just one loop.
  9. (loop_to(a.size()) | loop_body_1 | loop_body_2).run();
  10. return 0;
  11. }

Compiler Support

We require a C++17 compliant compiler. Our CI checks this library against the
latest Clang and GCC versions. We therefore support:

  • GCC 9 and higher
  • Clang 9 and higher
  • MSVC 19.24 and higher

Other compilers and versions may work but are not tested against.

Third Party Libraries

This project uses the following libraries for testing only, i.e. no runtime
dependencies besides the standard library are required:

We also use some third-party CMake modules. See cmake/README.md.