halide / Halide

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

Documentation of compile_to_lowered_stmt is insufficient #3924

Open piotrklos-tcl opened 5 years ago

piotrklos-tcl commented 5 years ago

I cannot figure out how to call compile_to_lowered_stmt by reading documentation. I'm annoyed by this for the third time, so I'm submitting an issue. :)

I tried this:

Func(generator_output).compile_to_lowered_stmt("lowered_stmt.html", {}, Halide::HTML);

and I got an error:

Error:                                                                                                                                
Generated code refers to image parameter input, which was not found in the argument list.                                                             

Argument list specified:    

Parameters referenced in generated code: input input1 input2

(parameter names changed for legal reasons).

Then I tried

std::vector<Argument> args;
args.push_back(input); 

but the push_back calls didn't compile. I cant figure out how to construct Argument objects because they have many fields and complicated constructors.

I had to grep halide repo with

grep -rnw . -e compile_to_lowered_stmt

to finally find a clue as to what the solution may look like. Grep was necessary, because google doesn't find those calls for me on github.

The final thing that worked for me was:

Func f = Func(generator_output);
f.compile_to_lowered_stmt("lowered_stmt.html", f.infer_arguments(), Halide::HTML);

I doubt that any beginner will go to such great lengths to find this, so in my opinion the documentation (including the tutorial
https://halide-lang.org/docs/tutorial_2lesson_03_debugging_1_8cpp-example.html) is pretty useless for any non-trivial pipeline.

alexreinking commented 5 years ago

Feel free to submit a PR with a documentation update. Also note that ahead of time compiled generators can have their lowered statements dumped to a file at the command line by passing -e html to the generator executable.

If it's possible, it might not be a bad idea to have an overload that calls infer_arguments internally.