Questions tagged [halide]

For question related to the Halide domain-specific language including scheduling, and computations. Halide supports different languages such as C, C++, Matlab/octave and Python. Please consider a language tag as well.

Overview

Halide is an open-source domain-specific language which allows flexibility in iterating over dimensions to apply computations.

There are two basic parts to Halide code. One describes the computations and the second is the schedule. The schedule allows trade-offs between redundant computations, cache locality and parallelism as the computations iterate over the data space.

Halide is principally used for image processing and computational photography, but it can be applied to audio, encryption, machine vision, and physical simulation. In some ways, Halide is an aspect oriented framework; it separates the description of the algorithm from the definition of how that algorithm is to be implemented via a schedule.

Halide is embedded within C++ and uses the LLVM plug-in mechanics to generate code. Two modes are supported:

  1. JIT (just in time) - in this mode, the code is created at run time. The generated code is available to be called. The Halide code consists of templates and classes which may be updated at runtime. This mode is very flexible for iterating over different design choices.
  2. AOT (ahead of time) - this is like a more traditional compilation mode. Two executeables are built. One is a generator which creates an object file with several functions. The object file take parameters (buffers, etc) and produces outputs (buffers, constants). The generates object can be linked to many languages that are ABI compliant, such as even thought the primary language used to code Halide is C++.

It can be helpful to specify which mode you are targeting when asking questions.

Resources/References

The Halide tutorials give a gentle introduction to topics and concepts related to the framework.

More information can be found on the website: http://halide-lang.org

Much of the information here is taken from a CppCon 2020 video by Alex Reinking.

253 questions
6
votes
1 answer

Halide - while loop equivalent

I'm trying to implement Meijster distance transform algorithm in Halide. I've already rewritten this code to C++ (using openCV) and it's working fine. The paper about this algorithm is here. Right now my halide code is 50% complete - first phase is…
cyriel
  • 3,522
  • 17
  • 34
5
votes
0 answers

Load image on Android and process it using halide

I am going to load an image by provided file_path and then downsample it then save it. The whole thing should be done on android device. I am in trouble to load an image on device and convert to halide::buffer. Halide::Tools::load_image didn't work…
Lin.Chen
  • 73
  • 4
5
votes
2 answers

Recommended way to distribute Halide generated functions?

I am currently experimenting with Halide, the initial tests show quite promising performance improvements. I am now wondering about what is the best strategy to distribute Halide code. Requiring users to install Halide seems like a heavy barrier at…
rodrigob
  • 2,891
  • 3
  • 30
  • 34
4
votes
2 answers

Why is opencv dnn slower if I use Halide?

I am testing the performance of some samples in the opencv source tree depending on if halide is used or not. Surprisingly, the performance is worse if halide is used for the computation: squeezenet_halide: ~24ms with halide and ~16ms without…
goe
  • 2,272
  • 1
  • 19
  • 34
4
votes
0 answers

Halide CUDA GPU SGEMM implementation

I am trying to build Halide-based image processing algorithm that require SGEMM function at one of its stages. I have found that Halide has two matrix multiplication implementations: linear algebra algorithms (apps/linear_algebra folder) CUDA…
Evgeniy
  • 2,481
  • 14
  • 24
4
votes
1 answer

Why is my performance bad? (Noob scheduling)

I'm mainly a very high level programmer so thinking about things like CPU locality is very new to me. I'm working on a basic bilinear demosaic (for RGGB sensor data) and I've got the algorithm right (judging by the results) but it's not performing…
user478250
  • 259
  • 2
  • 9
4
votes
1 answer

Halide: OpenCL code generation

Is it possible in Halide to produce a file which contains generated OpenCL code? I have tried to produce a c file from a Halide program which target would be opencl, but I don't see any opencl specfic code there. Edit 1: I would like to see…
jussijii
  • 41
  • 4
3
votes
0 answers

Efficient Image Normalization in Halide

I've discover Halide (the language), a few weeks ago and I actually enjoy trying to optimize some parts of my code with it, nonetheless, I struggle to find an optimized implementation of a very basic image processing task: Normalization Basically,…
priseJack
  • 396
  • 2
  • 14
3
votes
0 answers

How to prevent Halide 'select' from evaluating both branches

The select expression in Halide is similar to if or switch statement in C. That is to say, the expression select(cond, a, b) will evaluate to a if cond is true, otherwise it evaluates to b. So, I thought select evaluates only one branch between a…
VictorBian
  • 675
  • 1
  • 4
  • 17
3
votes
1 answer

Halide with CUDA targets not working

I am new to Halide and have written a simple code to compute max(127, pix(x,y)) for every pixel in an image. Though the code runs fine on CPU, it gives me wrong outputs when I set Target::CUDA. I'm not able to find the issue. The following is a part…
3
votes
1 answer

Halide: Passing a C++ function into a Halide Func

I have a binary image and would like to find the first non-zero pixel for each column, starting from the top of the image, using Halide. In c++, it would look like something like this, given the image called mask: vector
zanbri
  • 5,958
  • 2
  • 31
  • 41
3
votes
2 answers

Cholesky decomposition in Halide

I'm trying to implement a Cholesky decomposition in Halide. Part of common algorithm such as crout consists of an iteration over a triangular matrix. In a way that, the diagonal elements of the decomposition are computed by subtracting a partial…
Pablo R.
  • 31
  • 3
3
votes
2 answers

Performance counter for Halide?

Is there a performance counter available for code written in the Halide language? I would like to know how many loads, stores, and ALU operations are performed by my code. The Halide tutorial for scheduling multi-stage pipelines compares different…
Kantthpel
  • 149
  • 10
3
votes
2 answers

Running Halide generators from cmake with the most optimal compiler flags and configurations

OK, so: I have successfully integrated the first working Halide generator into the cmake build system for my little image-processing project. The generator implements an image-resizing and -resampling algorithm, based on the example code from the…
fish2000
  • 4,289
  • 2
  • 37
  • 76
3
votes
2 answers

Halide with C layout numpy arrays

I am starting to use Halide and use it from a Python environment. Within that Python environment data is passed around as Numpy arrays which actually are an alias to a C++ array defined elsewhere. However, when I use call the Halide function I get…
Klamer Schutte
  • 1,063
  • 9
  • 18
1
2 3
16 17