I am trying to change the buffer layout of a realization. I understand that the aim of Halide is to allow to define the algorithm "once", and then be able to change things like schedule and storage layout separately.
I have tried my_output_function.reorder_storage(x,y,c)
(and permuting x,y,c
); yet for any storage order the realization buffer strides remain the same (i.e. the layout does not change).
If I change the dimensions ordering when calling my_output_function.realize(width, height, channels)
, then the code does not compile since some boundary conditions are violated. I would need to change the algorithm definition, defeating the halide purpose.
What should I do to change the output layout ?
Why does reorder_storage
not affect the output ?
Thanks for your help.
The order of the output is defined not by reorder_storage
(which we should probably disable or warn about on output functions), but by the layout of the output buffer, as given by its strides. You can't control this using the simplest Func::realize
methods which take dimension arguments and return a system-allocated Image
, but you can in the ahead-of-time compiled interface or with the other realize methods which take user-allocated structures:
http://halide-lang.org/docs/class_halide_1_1_func.html#a1f749d8761a6cf35a6f2f3c319d66729
In particular, if you construct a Buffer
, and modify the stride
fields of its raw_buffer
:
http://halide-lang.org/docs/structbuffer__t.html#af60461463c076afe9dd5909e6daf4536
Swapping the strides changes the implied interleaving of the storage of this output buffer.
In general, this is not as well exposed through the JIT APIs (realize
, etc.) as through the AOT calling convention (manually passing in buffer_t
s). We could add, for example, set_stride
methods on Buffer
/Image
/etc. To learn more about the AOT model, check out tutorial 10:
https://github.com/halide/Halide/blob/master/tutorial/lesson_10_aot_compilation_generate.cpp
https://github.com/halide/Halide/blob/master/tutorial/lesson_10_aot_compilation_run.cpp
I hope that helps. Also, feel free to ask on the mailing list, which is very active.