Skip to content

Commit

Permalink
Convert most remaining Generators to prefer statically-dimensioned In…
Browse files Browse the repository at this point in the history
…puts and Output where possible (#6641)

This is the same as #6620, except that it omits autoschedulers/adams2019/cost_model_generator.cpp (which is unusually complex and not yet settled as to whether the changes are welcome). Basically an attempt to land the uncontroversial parts.
  • Loading branch information
steven-johnson authored Mar 7, 2022
1 parent a55ae55 commit 5f37d50
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 37 deletions.
16 changes: 8 additions & 8 deletions apps/HelloPyTorch/src/add_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ Func add_(const Input &input_a, const Input &input_b) {

class AddGenerator : public Generator<AddGenerator> {
public:
Input<Buffer<>> input_a{"input_a", 4};
Input<Buffer<>> input_b{"input_b", 4};
Output<Buffer<>> output{"output", 4};
Input<Buffer<void, 4>> input_a{"input_a"};
Input<Buffer<void, 4>> input_b{"input_b"};
Output<Buffer<void, 4>> output{"output"};

void generate() {
// Algorithm
Expand Down Expand Up @@ -52,12 +52,12 @@ class AddGenerator : public Generator<AddGenerator> {

class AddGradGenerator : public Generator<AddGradGenerator> {
public:
Input<Buffer<>> input_a{"input_a", 4};
Input<Buffer<>> input_b{"input_b", 4};
Input<Buffer<>> d_output{"d_output", 4};
Input<Buffer<void, 4>> input_a{"input_a"};
Input<Buffer<void, 4>> input_b{"input_b"};
Input<Buffer<void, 4>> d_output{"d_output"};

Output<Buffer<>> d_input_a{"d_input_a", 4};
Output<Buffer<>> d_input_b{"d_input_b", 4};
Output<Buffer<void, 4>> d_input_a{"d_input_a"};
Output<Buffer<void, 4>> d_input_b{"d_input_b"};

void generate() {
// Algorithm
Expand Down
8 changes: 4 additions & 4 deletions apps/hexagon_dma/pipeline_yuv_linear_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ using namespace Halide;
class DmaPipeline : public Generator<DmaPipeline> {
public:
// The type must be specified when building the generator, to be either uint8 or uint16.
Input<Buffer<>> input_y{"input_y", 2};
Input<Buffer<>> input_uv{"input_uv", 3};
Output<Buffer<>> output_y{"output_y", 2};
Output<Buffer<>> output_uv{"output_uv", 3};
Input<Buffer<void, 2>> input_y{"input_y"};
Input<Buffer<void, 3>> input_uv{"input_uv"};
Output<Buffer<void, 2>> output_y{"output_y"};
Output<Buffer<void, 3>> output_uv{"output_uv"};

enum class Schedule { Basic,
Fold,
Expand Down
8 changes: 4 additions & 4 deletions src/autoschedulers/adams2019/demo_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ using namespace Halide;

class ConvRelu : public Halide::Generator<ConvRelu> {
public:
Input<Buffer<float>> input{"input", 4};
Input<Buffer<float>> filter{"filter", 4};
Input<Buffer<float>> bias{"bias", 1};
Output<Buffer<float>> relu{"relu", 4};
Input<Buffer<float, 4>> input{"input"};
Input<Buffer<float, 4>> filter{"filter"};
Input<Buffer<float, 1>> bias{"bias"};
Output<Buffer<float, 4>> relu{"relu"};

void generate() {
const int N = 5, CI = 120, CO = 24, W = 100, H = 80;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ namespace {
// demo_generator.cpp, but packaged separately to avoid confusion for
// newcomers.
struct IncludedScheduleFile : public Halide::Generator<IncludedScheduleFile> {
Input<Buffer<float>> input{"input", 4};
Input<Buffer<float>> filter{"filter", 4};
Input<Buffer<float>> bias{"bias", 1};
Output<Buffer<float>> relu{"relu", 4};
Input<Buffer<float, 4>> input{"input"};
Input<Buffer<float, 4>> filter{"filter"};
Input<Buffer<float, 1>> bias{"bias"};
Output<Buffer<float, 4>> relu{"relu"};

void generate() {
const int N = 5, CI = 120, CO = 24, W = 100, H = 80;
Expand Down
8 changes: 4 additions & 4 deletions src/autoschedulers/li2018/demo_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ using namespace Halide;

class ConvRelu : public Halide::Generator<ConvRelu> {
public:
Input<Buffer<float>> input{"input", 4};
Input<Buffer<float>> filter{"filter", 4};
Input<Buffer<float>> bias{"bias", 1};
Output<Buffer<float>> relu{"relu", 4};
Input<Buffer<float, 4>> input{"input"};
Input<Buffer<float, 4>> filter{"filter"};
Input<Buffer<float, 1>> bias{"bias"};
Output<Buffer<float, 4>> relu{"relu"};

void generate() {
const int N = 5, CI = 120, CO = 24, W = 100, H = 80;
Expand Down
8 changes: 4 additions & 4 deletions test/generator/configure_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Configure : public Halide::Generator<Configure> {
// user code must not free them. We can stash them in member variables
// as-is or in containers, like so:
for (int i = 0; i < num_extra_buffer_inputs; ++i) {
auto *extra = add_input<Buffer<>>("extra_" + std::to_string(i), UInt(8), 2);
auto *extra = add_input<Buffer<uint8_t, 2>>("extra_" + std::to_string(i));
extra_buffer_inputs.push_back(extra);
}

Expand All @@ -33,7 +33,7 @@ class Configure : public Halide::Generator<Configure> {

extra_dynamic_scalar_input = add_input<Expr>("extra_dynamic_scalar_input", Int(8));

extra_buffer_output = add_output<Buffer<>>("extra_buffer_output", Float(32), 3);
extra_buffer_output = add_output<Buffer<float, 3>>("extra_buffer_output");

extra_func_output = add_output<Func>("extra_func_output", Float(64), 2);

Expand Down Expand Up @@ -94,13 +94,13 @@ class Configure : public Halide::Generator<Configure> {
private:
int configure_calls = 0;

std::vector<Input<Buffer<>> *> extra_buffer_inputs;
std::vector<Input<Buffer<uint8_t, 2>> *> extra_buffer_inputs;
Input<Buffer<int16_t, 2>> *typed_extra_buffer_input;
Input<Func> *extra_func_input;
Input<int> *extra_scalar_input;
Input<Expr> *extra_dynamic_scalar_input;

Output<Buffer<>> *extra_buffer_output;
Output<Buffer<float, 3>> *extra_buffer_output;
Output<Func> *extra_func_output;
};

Expand Down
8 changes: 4 additions & 4 deletions tutorial/lesson_15_generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class MyFirstGenerator : public Halide::Generator<MyFirstGenerator> {
// member variables. They'll appear in the signature of our generated
// function in the same order as we declare them.
Input<uint8_t> offset{"offset"};
Input<Buffer<uint8_t>> input{"input", 2};
Input<Buffer<uint8_t, 2>> input{"input"};

// We also declare the Outputs as public member variables.
Output<Buffer<uint8_t>> brighter{"brighter", 2};
Output<Buffer<uint8_t, 2>> brighter{"brighter"};

// Typically you declare your Vars at this scope as well, so that
// they can be used in any helper methods you add later.
Expand Down Expand Up @@ -97,12 +97,12 @@ class MySecondGenerator : public Halide::Generator<MySecondGenerator> {

// We'll use the same Inputs as before:
Input<uint8_t> offset{"offset"};
Input<Buffer<uint8_t>> input{"input", 2};
Input<Buffer<uint8_t, 2>> input{"input"};

// And a similar Output. Note that we don't specify a type for the Buffer:
// at compile-time, we must specify an explicit type via the "output.type"
// GeneratorParam (which is implicitly defined for this Output).
Output<Buffer<>> output{"output", 2};
Output<Buffer<void, 2>> output{"output"};

// And we'll declare our Vars here as before.
Var x, y;
Expand Down
4 changes: 2 additions & 2 deletions tutorial/lesson_16_rgb_generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Brighten : public Halide::Generator<Brighten> {
// We declare a three-dimensional input image. The first two
// dimensions will be x, and y, and the third dimension will be
// the color channel.
Input<Buffer<uint8_t>> input{"input", 3};
Input<Buffer<uint8_t, 3>> input{"input"};

// We will compile this generator in several ways to accept
// several different memory layouts for the input and output. This
Expand All @@ -56,7 +56,7 @@ class Brighten : public Halide::Generator<Brighten> {
Input<uint8_t> offset{"offset"};

// Declare our outputs
Output<Buffer<uint8_t>> brighter{"brighter", 3};
Output<Buffer<uint8_t, 3>> brighter{"brighter"};

// Declare our Vars
Var x, y, c;
Expand Down
6 changes: 3 additions & 3 deletions tutorial/lesson_21_auto_scheduler_generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ using namespace Halide;
// We will define a generator to auto-schedule.
class AutoScheduled : public Halide::Generator<AutoScheduled> {
public:
Input<Buffer<float>> input{"input", 3};
Input<Buffer<float, 3>> input{"input"};
Input<float> factor{"factor"};

Output<Buffer<float>> output1{"output1", 2};
Output<Buffer<float>> output2{"output2", 2};
Output<Buffer<float, 2>> output1{"output1"};
Output<Buffer<float, 2>> output2{"output2"};

Expr sum3x3(Func f, Var x, Var y) {
return f(x - 1, y - 1) + f(x - 1, y) + f(x - 1, y + 1) +
Expand Down

0 comments on commit 5f37d50

Please sign in to comment.