0

I'd like to loop over an image, applying a complex operation to each 8x8 patch. To give an example, say I need to compute the singular value decomposition (SVD) of each patch and store the 3rd singular value in an output image. Is it possible to use a library (e.g. LAPACK for the SVD) in conjunction with Halide? Or should I program an SVD algorithm as part of my halide pipeline?

pariasm
  • 1
  • 1

1 Answers1

2

Yes, you can do exactly this using the define external functionality. There's a simple example you can follow in the tests:

https://github.com/halide/Halide/blob/master/test/correctness/extern_stage.cpp

The basic model is that external stages appear as functions, and can be scheduled in the pipeline accordingly (compute-at). The extern interface function you write is then responsible both for actually computing a block of output given a block of input, and also for responding to queries for how much input it needs to compute a given block of output.

That should get you going quickly for this use case.

That said, given the relatively small constant sized problem you have to solve here, you might get good mileage (in terms of potential optimization, targeting different platforms like GPUs, etc.) from just writing your own simple 8x8 SVD inline in the Halide algorithm.

jrk
  • 2,896
  • 1
  • 22
  • 35