Code Monkey home page Code Monkey logo

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:

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

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:

#include <loop_fusion/loop_fusion.hpp>
int main(int argc, char** argv) {
    using namespace loop_fusion::main_range;

    // a, b, c, d and f are arrays declared outside of this example
    auto loop_body_1 = [&](size_t i) { a[i] = b[i] + c[i]; };
    auto loop_body_2 = [&](size_t i) { d[i] = a[i] + f[i]; };

    // The following line merges and executes the two loop bodies
    // so that they are executed after another in just one loop.
    (loop_to(a.size()) | loop_body_1 | loop_body_2).run();

    return 0;
}

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.

loop-fusion's Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.