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
1
vote
1 answer

Halide GPU scheduler slower than CPU

I have written a simple Halide code to compute square of a numbers from 0 to n, however it takes 22x longer on GPU than on CPU. #include"stdafx.h" #include "Halide.h" #include using namespace Halide; #include…
1
vote
1 answer

If Statement equivalent in Halide

Need help implementing if equivalent in Halide if (current_pixel_mag > threshold) { mag = 65535; ed = 0; } I have tried Halide Select, but that is equivalent of ternary operator in C, and does not support multiple statements for given…
1
vote
1 answer

Construct a halide::runtime:buffer from halide::buffer

In lesson_10:AOT compilation part 2, it said that "Halide::Runtime::Buffer also has constructors that wrap existing data instead of allocating new memory", but in the docs of halide::runtime::buffer, I can't find a constructor takes Buffer as its…
Lin.Chen
  • 73
  • 4
1
vote
0 answers

How to insert some calculating in middle level loop?

i am a new guy tring Halide programming. I met an issue when porting some halide code into android via Halide::Generator. Below is my code: #include "Halide.h" #include #include using namespace Halide; using namespace…
walter
  • 11
  • 2
1
vote
1 answer

Is there a way to stack two input images into a single 4 dimensional buffer in a Halide Generator?

I have two input images(rgb) in my generator pipeline. Each go through a custom crop and get resized to an NxNx3 image. The output of the generator Output> {"batch", 4}; // (N, N, 3 ,2) and I set batch(x, y, c, batch_size) =…
1
vote
2 answers

Pthread and introspection library linking with Halide generators fails

I tried to setup a three layer convolution generator pipeline. Build is failing at linking step. Example followed in apps/wavelet running make in build directory results in the following error: [ 87%] Linking CXX executable…
Arnab Mitra
  • 127
  • 1
  • 6
1
vote
1 answer

how can i use pixel position 'x'(Halide::Var) value as a limit of a for loop?

I am new in Halide. I am trying to do some calculation where pixel position 'x' should be set as the limit of the for loop. For that, I wrote the following code but it seems i can not use halide variable as a limit of a for loop. Is there a…
1
vote
1 answer

Halide external function call from generator

I want to implement simple image processing routine quite similar to Auto Levels, so need to precalculate thresholds, make LUT and then make histogram stretching/normalization applying LUT. But my question is not about algorithm side, it is about…
silver_rocket
  • 418
  • 1
  • 4
  • 15
1
vote
0 answers

Halide - any way to interpret Buffer as Func? [Edit: self-solved]

I am just wondering if there is any way in Halide to interpret a Buffer as a Func (i.e. a better identity function). Also, a lot of my code seems very redundant, so if it is possible to write it in a better style, what would that look like? Here is…
Agent 008
  • 141
  • 8
1
vote
0 answers

Behavior of Derivatives and propagate_adjoints in Halide: it works in a capricious and unpredictable

There are two problems. First problem. The code below gives wrong answers. Rosenbrock function is causing problems again. What is more important - if we define function as a linear f(t1, t2) = 2 * x(t1, t2) + y(t1, t2), it will work correctly. Why…
Serge Kim
  • 11
  • 4
1
vote
2 answers

Wouldn't this pseudocode give some image values greater than 255?

I'm implementing the sobel filter according to the following pseudocode taken from Wikipedia: function sobel(A : as two dimensional image array) Gx=[-1 0 1; -2 0 2; -1 0 1] Gy=[-1 -2 -1; 0 0 0; 1 2 1] rows = size(A,1) columns =…
zengod
  • 1,114
  • 13
  • 26
1
vote
1 answer

Halide for tile metric and scheduling on GPU

I'm trying to implement a metric working on squared tiles (8x8) of a gray scale image producing 3 outputs (accumulation of gradient, max and min of a tile): each output is an image having a dimension of (IMG_WIDTH/8; IMG_HEIGHT/8). In the following…
lorenzov
  • 11
  • 3
1
vote
2 answers

halide total size for allocation func is constant but larger than 2^31-1

I'm working on a Halide project processing bursts of images. My initial data set is 9 bursts of images of 4208*3120 pixel, in format uint16_t. I got the constant_allocation_size error during run time: "Error: Total size for allocation layer_0 is…
shuyun
  • 11
  • 4
1
vote
2 answers

Halide reduction over 2D domain boundary

In the filter I am implementing there is a step doing some reduction over the boundary of square domain RDom r(0, filter_size, 0, filter_size); r.where( (r.x == 0 || r.x == filter_size - 1) || (r.y == 0 || r.y == filter_size - 1)); However…
Slava
  • 1,528
  • 1
  • 15
  • 23
1
vote
0 answers

Why is Halide::minimum, autoschedule or no, extremely slow on CPU, but not GPU but still not good?

Trying to a simple regional min filter, and my results compare accuracy wise to a non-Halide reference implementation that I am using. BUT... this Halide code runs extremely slow on CPU (like 1 minute) and more than 60x faster than that on GPU.…