Giter Club home page Giter Club logo

rewriter's Introduction

Work-in-process

Code Rewriter for OpenCV Universal Intrinsic

The API of OpenCV Universal Intrinsic is introduced some compatibility-breaking changes, in order to support variable-length backends including RVV. Most code blocks written using Universal Intrinsic will need to be rewritten. However, there are more than 400 code blocks that need to be rewritten, distributed in about 50 different files. This will be a horrible work if done by manually, so we decided to develop an automatic rewriter.

We are going to create a clang-tidy plugin to match and fix the Universal Intrinsic API that needs to be rewritten.

Example

void vadd(float *a, float *b, float *c, size_t n) {
-   for (size_t i = 0; i < n; i +=  v_float32::nlanes) {
+   for (size_t i = 0; i < n; i +=  Vtraits<v_float32>::vlanes()) {
            v_float32 va = v_load(a + i);
            v_float32 vb = v_load(b + i);
-           v_float32 vc = va + vb;
+           v_float32 vc = v_add(va, vb);
            v_store(c, vc);
    }
}

Capability

Code usage Match and Fix Checks
v_type::nlanes opencv-dev-intrin-nlanes
v_type::nlanes (constant) only as array size opencv-dev-intrin-nlanes
overloaded operator opencv-dev-intrin-operator
v_type::lane_type opencv-dev-intrin-lanetype
get0() opencv-dev-intrin-get0
v_extract_n opencv-dev-intrin-nlanes
v_broadcast_element opencv-dev-intrin-nlanes
...

Usage

Need to compile OpenCV (with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON) and LLVM (enable clang and clang-tools-extra) firstly,

and then:

# build
mkdir build && cd build
cmake .. -G Ninja -DClang_DIR=<LLVM build directory>/lib/cmake/clang
ninja

# run
<LLVM build directory>/bin/clang-tidy --load ./build/libocv_intrinsic_tidy.so opencv-dev-intrin-'--checks=-*,opencv-dev-intrin-*' -p <OpenCV build directory> ../examples/nlanes.cpp

# run and rewrite
<LLVM build directory>/bin/clang-tidy --load ./build/libocv_intrinsic_tidy.so opencv-dev-intrin-'--checks=-*,opencv-dev-intrin-*' -p <OpenCV build directory> ../examples/nlanes.cpp -fix

rewriter's People

Contributors

hanliutong avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

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.