Giter Club home page Giter Club logo

hello_halide's Introduction

hello_halide

Objectives

The objective of this project is to demonstrate a realistic production-ready implementation of an image processing algorithm using Halide. This includes:

  • Use state-of-the-art auto-scheduler for optimal performance
  • Create fully compiled code with no runtime dependencies
  • Check Halide implementation correctness against baseline C++ implementation
  • Compare performance between Halide and baseline C++ implementation

Setup

I used a Mac. The code should be easy to port to any Linux by adjusting the cmake file.

  • Install XCode command-line tools (for clang/llvm)
  • Install Halide and cmake: brew install halide cmake

Build and run

mkdir build && cd build
cmake ..
make
./contrastAdjustTest 

Example output

./contrastAdjustTest 
Output pixel value range: [0:255], time: 0.008957 s
Halide Output pixel value range: [0:255], time: 0.000332 s

In this case, we achieved 27x speedup over optimized C++ code

Algorithm

The algorithm is a basic contrast adjustment of a grayscale image. For a given image, the pixel values are linearly scaled to maximize the dynamic range of [0-255] pixel values.

Code organization

Halide code is split into two generated functions: one to calculate the minimum and maximum of the pixel values, and another to apply the scaling.

Build process

We first compile the Halide code into a generator. Then we run the generator to create a static library for a specific platform target. Finally, we compile a test app that links in the Halide generated binary. This test app we can run to benchmark performance and check correctness.

Checking runtime dependencies

otool -L contrastAdjustTest

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.