Skip to content

Commit

Permalink
Convert apps/hannk/Elementwise to use generate() (#6543)
Browse files Browse the repository at this point in the history
It's the only Generator in Halide that uses build() instead of generate() (aside from tests designed specifically to test build()); convert it to keep things nice and consistent.
  • Loading branch information
steven-johnson authored Jan 6, 2022
1 parent 6f7d5ce commit daa5b7c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions apps/hannk/halide/elementwise_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ class Elementwise : public Generator<Elementwise> {
// this buffer.
Input<Buffer<int16_t>> program_{"program", 2};

Func build() {
// Type is determined by the GeneratorParams specified.
Output<Buffer<>> output_{"output", 2};

void generate() {
Var x("x"), y("y"), u("u");

Type intermediate_type = intermediate_type_;
Expand Down Expand Up @@ -175,7 +178,6 @@ class Elementwise : public Generator<Elementwise> {
r.where(r.x == op);
scratch(x, y, slot) = mux(r.x, instructions);

Func output("output");
std::vector<Type> output_types;
if (((Type)output1_type_).bits() > 0) {
output_types.push_back(output1_type_);
Expand All @@ -195,10 +197,10 @@ class Elementwise : public Generator<Elementwise> {
output_i = saturating_cast(output_types[i], output_i);
outputs.push_back(output_i);
}
output(x, y) = Tuple(outputs);
output_(x, y) = Tuple(outputs);

// Schedule.
output.compute_root()
output_.compute_root()
.vectorize(x, natural_vector_size<uint8_t>(), TailStrategy::Predicate);

// Only allow this many instructions per input, so we can store scratch
Expand All @@ -222,8 +224,6 @@ class Elementwise : public Generator<Elementwise> {

program_.dim(0).set_min(0).set_extent(ElementwiseAssembler::InstructionSize).set_stride(1);
program_.dim(1).set_min(0).set_stride(ElementwiseAssembler::InstructionSize);

return output;
}
};

Expand Down

0 comments on commit daa5b7c

Please sign in to comment.