halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.83k stars 1.07k forks source link

Channel select definition #3085

Open edubois opened 6 years ago

edubois commented 6 years ago

Hi, As I cannot write this:

out(x, y, 0) = selection[0];
out(x, y, 1) = selection[1];
out(x, y, 2) = selection[2];
out(x, y, 3) = selection[3];

Is there a better way to write this? out(x, y, c) = select(c == 0, selection[0], select(c == 1, selection[1], select(c == 2, selection[2], selection[3])));

abadams commented 6 years ago

Just a change in syntax and formatting, but I usually write it as:

out(x, y, c) = select(c == 0, selection[0],
                      c == 1, selection[1],
                      c == 2, selection[2],
                      selection[3]);
edubois commented 6 years ago

Ok, but this implies a if that has a cost, isn't it?

abadams commented 6 years ago

I would normally couple this with out.reorder(c, x, y).bound(c, 0, 4).unroll(c) to make the select go away.

edubois commented 6 years ago

Ok, I see. Last question: is the auto scheduler doing that automatically?

abadams commented 6 years ago

No, the autoscheduler doesn't know that trick.

edubois commented 6 years ago

Ok, thanks, good to know.

edubois commented 6 years ago

I just remembered something bad that I saw, and is somehow related to this last fact: the autoscheduler vs bounds of the channels: I saw that it is adding a parallelization on the channel dimension, which is not making sense. What do you think?