I have a Halide::Runtime::Buffer
and would like to remove elements that match a criteria, ideally such that the operation occurs in-place and that the function can be defined in a Halide::Generator
.
I have looked into using reductions, but it seems to me that I cannot output a vector of a different length -- I can only set certain elements to a value of my choice.
So far, the only way I got it to work was by using a extern "C"
call and passing the Buffer I wanted to filter, along with a boolean Buffer (1's and 0's as ints). I read the Buffers into vectors of another library (Armadillo), conducted my desired filter, then read the filtered vector back into Halide.
This seems quite messy and also, with this code, I'm passing a Halide::Buffer
object, and not a Halide::Runtime::Buffer
object, so I don't know how to implement this within a Halide::Generator
.
So my question is twofold:
- Can this kind of filtering be achieved in pure Halide, preferably in-place?
- Is there an example of using
extern "C"
functions within Generators?