From 5f37d50888601a5aec600783a1e08da2991b8739 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Mon, 7 Mar 2022 12:58:12 -0800 Subject: [PATCH] Convert most remaining Generators to prefer statically-dimensioned Inputs 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. --- apps/HelloPyTorch/src/add_generator.cpp | 16 ++++++++-------- apps/hexagon_dma/pipeline_yuv_linear_basic.cpp | 8 ++++---- src/autoschedulers/adams2019/demo_generator.cpp | 8 ++++---- .../included_schedule_file_generator.cpp | 8 ++++---- src/autoschedulers/li2018/demo_generator.cpp | 8 ++++---- test/generator/configure_generator.cpp | 8 ++++---- tutorial/lesson_15_generators.cpp | 8 ++++---- tutorial/lesson_16_rgb_generate.cpp | 4 ++-- tutorial/lesson_21_auto_scheduler_generate.cpp | 6 +++--- 9 files changed, 37 insertions(+), 37 deletions(-) diff --git a/apps/HelloPyTorch/src/add_generator.cpp b/apps/HelloPyTorch/src/add_generator.cpp index ab1e46326706..8f2d8f4d6a81 100644 --- a/apps/HelloPyTorch/src/add_generator.cpp +++ b/apps/HelloPyTorch/src/add_generator.cpp @@ -15,9 +15,9 @@ Func add_(const Input &input_a, const Input &input_b) { class AddGenerator : public Generator { public: - Input> input_a{"input_a", 4}; - Input> input_b{"input_b", 4}; - Output> output{"output", 4}; + Input> input_a{"input_a"}; + Input> input_b{"input_b"}; + Output> output{"output"}; void generate() { // Algorithm @@ -52,12 +52,12 @@ class AddGenerator : public Generator { class AddGradGenerator : public Generator { public: - Input> input_a{"input_a", 4}; - Input> input_b{"input_b", 4}; - Input> d_output{"d_output", 4}; + Input> input_a{"input_a"}; + Input> input_b{"input_b"}; + Input> d_output{"d_output"}; - Output> d_input_a{"d_input_a", 4}; - Output> d_input_b{"d_input_b", 4}; + Output> d_input_a{"d_input_a"}; + Output> d_input_b{"d_input_b"}; void generate() { // Algorithm diff --git a/apps/hexagon_dma/pipeline_yuv_linear_basic.cpp b/apps/hexagon_dma/pipeline_yuv_linear_basic.cpp index 279a5b83dabb..00a1ef349ddc 100644 --- a/apps/hexagon_dma/pipeline_yuv_linear_basic.cpp +++ b/apps/hexagon_dma/pipeline_yuv_linear_basic.cpp @@ -7,10 +7,10 @@ using namespace Halide; class DmaPipeline : public Generator { public: // The type must be specified when building the generator, to be either uint8 or uint16. - Input> input_y{"input_y", 2}; - Input> input_uv{"input_uv", 3}; - Output> output_y{"output_y", 2}; - Output> output_uv{"output_uv", 3}; + Input> input_y{"input_y"}; + Input> input_uv{"input_uv"}; + Output> output_y{"output_y"}; + Output> output_uv{"output_uv"}; enum class Schedule { Basic, Fold, diff --git a/src/autoschedulers/adams2019/demo_generator.cpp b/src/autoschedulers/adams2019/demo_generator.cpp index 8c31d68e5e1a..026c2394f3f5 100644 --- a/src/autoschedulers/adams2019/demo_generator.cpp +++ b/src/autoschedulers/adams2019/demo_generator.cpp @@ -6,10 +6,10 @@ using namespace Halide; class ConvRelu : public Halide::Generator { public: - Input> input{"input", 4}; - Input> filter{"filter", 4}; - Input> bias{"bias", 1}; - Output> relu{"relu", 4}; + Input> input{"input"}; + Input> filter{"filter"}; + Input> bias{"bias"}; + Output> relu{"relu"}; void generate() { const int N = 5, CI = 120, CO = 24, W = 100, H = 80; diff --git a/src/autoschedulers/adams2019/included_schedule_file_generator.cpp b/src/autoschedulers/adams2019/included_schedule_file_generator.cpp index 1a5cb99a784f..21ee6ec0918c 100644 --- a/src/autoschedulers/adams2019/included_schedule_file_generator.cpp +++ b/src/autoschedulers/adams2019/included_schedule_file_generator.cpp @@ -13,10 +13,10 @@ namespace { // demo_generator.cpp, but packaged separately to avoid confusion for // newcomers. struct IncludedScheduleFile : public Halide::Generator { - Input> input{"input", 4}; - Input> filter{"filter", 4}; - Input> bias{"bias", 1}; - Output> relu{"relu", 4}; + Input> input{"input"}; + Input> filter{"filter"}; + Input> bias{"bias"}; + Output> relu{"relu"}; void generate() { const int N = 5, CI = 120, CO = 24, W = 100, H = 80; diff --git a/src/autoschedulers/li2018/demo_generator.cpp b/src/autoschedulers/li2018/demo_generator.cpp index 8c31d68e5e1a..026c2394f3f5 100644 --- a/src/autoschedulers/li2018/demo_generator.cpp +++ b/src/autoschedulers/li2018/demo_generator.cpp @@ -6,10 +6,10 @@ using namespace Halide; class ConvRelu : public Halide::Generator { public: - Input> input{"input", 4}; - Input> filter{"filter", 4}; - Input> bias{"bias", 1}; - Output> relu{"relu", 4}; + Input> input{"input"}; + Input> filter{"filter"}; + Input> bias{"bias"}; + Output> relu{"relu"}; void generate() { const int N = 5, CI = 120, CO = 24, W = 100, H = 80; diff --git a/test/generator/configure_generator.cpp b/test/generator/configure_generator.cpp index 3149970df8bb..b5164bbae2f2 100644 --- a/test/generator/configure_generator.cpp +++ b/test/generator/configure_generator.cpp @@ -21,7 +21,7 @@ class Configure : public Halide::Generator { // 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>("extra_" + std::to_string(i), UInt(8), 2); + auto *extra = add_input>("extra_" + std::to_string(i)); extra_buffer_inputs.push_back(extra); } @@ -33,7 +33,7 @@ class Configure : public Halide::Generator { extra_dynamic_scalar_input = add_input("extra_dynamic_scalar_input", Int(8)); - extra_buffer_output = add_output>("extra_buffer_output", Float(32), 3); + extra_buffer_output = add_output>("extra_buffer_output"); extra_func_output = add_output("extra_func_output", Float(64), 2); @@ -94,13 +94,13 @@ class Configure : public Halide::Generator { private: int configure_calls = 0; - std::vector> *> extra_buffer_inputs; + std::vector> *> extra_buffer_inputs; Input> *typed_extra_buffer_input; Input *extra_func_input; Input *extra_scalar_input; Input *extra_dynamic_scalar_input; - Output> *extra_buffer_output; + Output> *extra_buffer_output; Output *extra_func_output; }; diff --git a/tutorial/lesson_15_generators.cpp b/tutorial/lesson_15_generators.cpp index 831e7924d464..969158b4926b 100644 --- a/tutorial/lesson_15_generators.cpp +++ b/tutorial/lesson_15_generators.cpp @@ -32,10 +32,10 @@ class MyFirstGenerator : public Halide::Generator { // member variables. They'll appear in the signature of our generated // function in the same order as we declare them. Input offset{"offset"}; - Input> input{"input", 2}; + Input> input{"input"}; // We also declare the Outputs as public member variables. - Output> brighter{"brighter", 2}; + Output> 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. @@ -97,12 +97,12 @@ class MySecondGenerator : public Halide::Generator { // We'll use the same Inputs as before: Input offset{"offset"}; - Input> input{"input", 2}; + Input> 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> output{"output", 2}; + Output> output{"output"}; // And we'll declare our Vars here as before. Var x, y; diff --git a/tutorial/lesson_16_rgb_generate.cpp b/tutorial/lesson_16_rgb_generate.cpp index 3621a6f9f2ef..e5d2ce98430f 100644 --- a/tutorial/lesson_16_rgb_generate.cpp +++ b/tutorial/lesson_16_rgb_generate.cpp @@ -33,7 +33,7 @@ class Brighten : public Halide::Generator { // 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> input{"input", 3}; + Input> input{"input"}; // We will compile this generator in several ways to accept // several different memory layouts for the input and output. This @@ -56,7 +56,7 @@ class Brighten : public Halide::Generator { Input offset{"offset"}; // Declare our outputs - Output> brighter{"brighter", 3}; + Output> brighter{"brighter"}; // Declare our Vars Var x, y, c; diff --git a/tutorial/lesson_21_auto_scheduler_generate.cpp b/tutorial/lesson_21_auto_scheduler_generate.cpp index 14803799c7b4..44a1bcac6aea 100644 --- a/tutorial/lesson_21_auto_scheduler_generate.cpp +++ b/tutorial/lesson_21_auto_scheduler_generate.cpp @@ -29,11 +29,11 @@ using namespace Halide; // We will define a generator to auto-schedule. class AutoScheduled : public Halide::Generator { public: - Input> input{"input", 3}; + Input> input{"input"}; Input factor{"factor"}; - Output> output1{"output1", 2}; - Output> output2{"output2", 2}; + Output> output1{"output1"}; + Output> 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) +