halide / Halide

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

Adjoints from Generators with Scalar Parameters #4599

Open clutzweiler opened 4 years ago

clutzweiler commented 4 years ago

Hello Halide-Team,

(thanks for putting your efforts in such a neat to tool for more application oriented programmers and scientists!)

I have started to play around with the rather recent feature of auto-diff and the -d 1 option to generators. Although maybe not the primary concern for prototypical DL applications, generators with scalar input parameters Input<scalar_type> seem currently not supported and running the generator fails:

$ bin/host/lens_blur.generator -g lens_blur -e static_library,h,registration,stmt,assembly -o bin/host -f lens_blur target=host auto_schedule=true -d 1
Internal Error at /home/cl/workspace/halide/Halide/src/Generator.cpp:1490 triggered by user code at :
Condition failed: input->parameters_.size() == input->funcs_.size():
>>CORE DUMP<<

I wondered if there is a fundamental obstacle for supporting scalar inputs, if this feature has just been postponed, or if a bug made it into the implementation. Alas, I did not have the chance for a deep dive to see what's going on under the hood yet. As a work-around, one might pass a scalar Func which is likely not the stylistically preferred alternative in the long run.

Best, Christian

ps. One little thing. Knowing about the recent make doc target, the online documentation currently seems not to reflect the latest API changes, e.g. _Func::setestimates().

clutzweiler commented 4 years ago

Ping.

abadams commented 4 years ago

@BachiLi May have thoughts on derivatives of scalar inputs - he was the one to implement all of this.

BachiLi commented 4 years ago

We do support derivatives w.r.t. scalar Parameters. I think the assertion there was being too paranoid. I can look at this in my free time (which is becoming very scarce) or @steven-johnson might also know how to fix this.

steven-johnson commented 4 years ago

Seems like a scalar input could just be treated as a zero-dimensional buffer (because, really, that's all it is).

alexreinking commented 3 years ago

This was raised again in #5406.