Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert apps/ to use static Buffer dims where useful #6585

Merged
merged 15 commits into from
Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/HelloAndroid/jni/hello_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace {

class Hello : public Generator<Hello> {
public:
Input<Buffer<uint8_t>> input{"input", 2};
Output<Buffer<uint8_t>> result{"result", 2};
Input<Buffer<uint8_t, 2>> input{"input"};
Output<Buffer<uint8_t, 2>> result{"result"};

void generate() {
tone_curve(x) = cast<int16_t>(pow(cast<float>(x) / 256.0f, 1.8f) * 256.0f);
Expand Down
2 changes: 1 addition & 1 deletion apps/HelloAndroidCamera2/jni/deinterleave_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace {

class Deinterleave : public Halide::Generator<Deinterleave> {
public:
Input<Buffer<uint8_t>> uvInterleaved{"uvInterleaved", 2};
Input<Buffer<uint8_t, 2>> uvInterleaved{"uvInterleaved"};
// There is no way to declare a Buffer<Tuple>, so we must use Output<Func> instead
Output<Func> result{"result", {UInt(8), UInt(8)}, 2};

Expand Down
4 changes: 2 additions & 2 deletions apps/HelloAndroidCamera2/jni/edge_detect_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace {

class EdgeDetect : public Halide::Generator<EdgeDetect> {
public:
Input<Buffer<uint8_t>> input{"input", 2};
Output<Buffer<uint8_t>> result{"result", 2};
Input<Buffer<uint8_t, 2>> input{"input"};
Output<Buffer<uint8_t, 2>> result{"result"};

void generate() {
Var x, y;
Expand Down
4 changes: 2 additions & 2 deletions apps/HelloMatlab/iir_blur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ class IirBlur : public Generator<IirBlur> {
public:
// This is the input image: a 3D (color) image with 32 bit float
// pixels.
Input<Buffer<float>> input{"input", 3};
Input<Buffer<float, 3>> input{"input"};
// The filter coefficient, alpha is the weight of the input to the
// filter.
Input<float> alpha{"alpha"};

Output<Buffer<float>> output{"output", 3};
Output<Buffer<float, 3>> output{"output"};

void generate() {
Expr width = input.width();
Expand Down
2 changes: 1 addition & 1 deletion apps/HelloWasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ include ../support/Makefile.inc

# The emscripten compiler
EMCC ?= emcc
EMCC_FLAGS ?= -s WASM=1 -s USE_SDL=2 -s TOTAL_MEMORY=512MB -O3 -I $(HALIDE_DISTRIB_PATH)/include
EMCC_FLAGS ?= -std=c++17 -s WASM=1 -s USE_SDL=2 -s TOTAL_MEMORY=512MB -O3 -I $(HALIDE_DISTRIB_PATH)/include
EMCC_THREADS_FLAGS ?= $(EMCC_FLAGS) -pthread -matomics

# the output dir for the .js products must be fixed, because that's what index.html looks for
Expand Down
12 changes: 6 additions & 6 deletions apps/HelloWasm/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ struct Context {
double smoothed_blit_time = 0;
double last_frame_time = 0;

Halide::Runtime::Buffer<float> buf1;
Halide::Runtime::Buffer<float> buf2;
Halide::Runtime::Buffer<uint32_t> pixel_buf;
Halide::Runtime::Buffer<float, 3> buf1;
Halide::Runtime::Buffer<float, 3> buf2;
Halide::Runtime::Buffer<uint32_t, 2> pixel_buf;
};

void mainloop(void *arg) {
Expand Down Expand Up @@ -102,9 +102,9 @@ int main() {

Context ctx;
ctx.renderer = renderer;
ctx.buf1 = Halide::Runtime::Buffer<float>(W, H, 3);
ctx.buf2 = Halide::Runtime::Buffer<float>(W, H, 3);
ctx.pixel_buf = Halide::Runtime::Buffer<uint32_t>(W, H);
ctx.buf1 = Halide::Runtime::Buffer<float, 3>(W, H, 3);
ctx.buf2 = Halide::Runtime::Buffer<float, 3>(W, H, 3);
ctx.pixel_buf = Halide::Runtime::Buffer<uint32_t, 2>(W, H);

ctx.tex = SDL_CreateTexture(renderer,
SDL_PIXELFORMAT_ARGB8888,
Expand Down
10 changes: 5 additions & 5 deletions apps/HelloWasm/reaction_diffusion_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace {

class ReactionDiffusionInit : public Halide::Generator<ReactionDiffusionInit> {
public:
Output<Buffer<float>> output{"output", 3};
Output<Buffer<float, 3>> output{"output"};
GeneratorParam<bool> threads{"threads", true};

void generate() {
Expand All @@ -24,11 +24,11 @@ class ReactionDiffusionInit : public Halide::Generator<ReactionDiffusionInit> {

class ReactionDiffusionUpdate : public Halide::Generator<ReactionDiffusionUpdate> {
public:
Input<Buffer<float>> state{"state", 3};
Input<Buffer<float, 3>> state{"state"};
Input<int> mouse_x{"mouse_x"};
Input<int> mouse_y{"mouse_y"};
Input<int> frame{"frame"};
Output<Buffer<float>> new_state{"new_state", 3};
Output<Buffer<float, 3>> new_state{"new_state"};
GeneratorParam<bool> threads{"threads", false};

void generate() {
Expand Down Expand Up @@ -139,8 +139,8 @@ class ReactionDiffusionUpdate : public Halide::Generator<ReactionDiffusionUpdate

class ReactionDiffusionRender : public Halide::Generator<ReactionDiffusionRender> {
public:
Input<Buffer<float>> state{"state", 3};
Output<Buffer<uint32_t>> render{"render", 2};
Input<Buffer<float, 3>> state{"state"};
Output<Buffer<uint32_t, 2>> render{"render"};
GeneratorParam<bool> threads{"threads", false};

void generate() {
Expand Down
10 changes: 5 additions & 5 deletions apps/HelloiOS/HelloiOS/reaction_diffusion_2_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace {

class ReactionDiffusion2Init : public Halide::Generator<ReactionDiffusion2Init> {
public:
Output<Buffer<float>> output{"output", 3};
Output<Buffer<float, 3>> output{"output"};

void generate() {
output(x, y, c) = Halide::random_float();
Expand All @@ -28,11 +28,11 @@ class ReactionDiffusion2Init : public Halide::Generator<ReactionDiffusion2Init>

class ReactionDiffusion2Update : public Halide::Generator<ReactionDiffusion2Update> {
public:
Input<Buffer<float>> state{"state", 3};
Input<Buffer<float, 3>> state{"state"};
Input<int> mouse_x{"mouse_x"};
Input<int> mouse_y{"mouse_y"};
Input<int> frame{"frame"};
Output<Buffer<float>> new_state{"new_state", 3};
Output<Buffer<float, 3>> new_state{"new_state"};

void generate() {
clamped = Halide::BoundaryConditions::repeat_edge(state);
Expand Down Expand Up @@ -163,10 +163,10 @@ class ReactionDiffusion2Update : public Halide::Generator<ReactionDiffusion2Upda

class ReactionDiffusion2Render : public Halide::Generator<ReactionDiffusion2Render> {
public:
Input<Buffer<float>> state{"state", 3};
Input<Buffer<float, 3>> state{"state"};
// TODO(srj): should be Input<bool>; using Input<int> to work around Issue #1760
Input<int> output_bgra{"output_bgra", 0, 0, 1};
Output<Buffer<uint8_t>> render{"render", 3};
Output<Buffer<uint8_t, 3>> render{"render"};

void generate() {
Func contour;
Expand Down
4 changes: 2 additions & 2 deletions apps/auto_viz/auto_viz_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ void parse_commandline(int argc, char **argv) {
int main(int argc, char **argv) {
parse_commandline(argc, argv);

Halide::Runtime::Buffer<float> in = Halide::Tools::load_and_convert_image(infile);
Halide::Runtime::Buffer<float, 3> in = Halide::Tools::load_and_convert_image(infile);
int out_width = in.width() * scale_factor;
int out_height = in.height() * scale_factor;
Halide::Runtime::Buffer<float> out(out_width, out_height, 3);
Halide::Runtime::Buffer<float, 3> out(out_width, out_height, 3);

decltype(&auto_viz_demo_naive_up) variants[2][3] =
{
Expand Down
4 changes: 2 additions & 2 deletions apps/auto_viz/auto_viz_demo_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class AutoVizDemo : public Halide::Generator<AutoVizDemo> {
// resample in x and in y).
GeneratorParam<bool> upsample{"upsample", false};

Input<Buffer<float>> input{"input", 3};
Input<Buffer<float, 3>> input{"input"};
Input<float> scale_factor{"scale_factor"};
Output<Buffer<float>> output{"output", 3};
Output<Buffer<float, 3>> output{"output"};

// Common Vars
Var x, y, c, k;
Expand Down
8 changes: 4 additions & 4 deletions apps/bgu/bgu_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,11 @@ class BGU : public Generator<BGU> {
// Size of each spatial bin in the grid. Typically 16.
Input<int> s_sigma{"s_sigma"};

Input<Buffer<float>> splat_loc{"splat_loc", 3};
Input<Buffer<float>> values{"values", 3};
Input<Buffer<float>> slice_loc{"slice_loc", 3};
Input<Buffer<float, 3>> splat_loc{"splat_loc"};
Input<Buffer<float, 3>> values{"values"};
Input<Buffer<float, 3>> slice_loc{"slice_loc"};

Output<Buffer<float>> output{"output", 3};
Output<Buffer<float, 3>> output{"output"};

void generate() {
// Algorithm
Expand Down
8 changes: 4 additions & 4 deletions apps/bgu/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ int main(int argc, char **argv) {
// BGU will be good at capturing the contrast enhancement and
// vignette, and bad at capturing the high-frequency sharpening.

Halide::Runtime::Buffer<float> high_res_in = load_and_convert_image(argv[1]);
Halide::Runtime::Buffer<float, 3> high_res_in = load_and_convert_image(argv[1]);
const int W = high_res_in.width();
const int H = high_res_in.height();
const int C = high_res_in.channels();

Halide::Runtime::Buffer<float> high_res_out(W, H, C);
Halide::Runtime::Buffer<float> low_res_in(W / 8, H / 8, C);
Halide::Runtime::Buffer<float> low_res_out(W / 8, H / 8, C);
Halide::Runtime::Buffer<float, 3> high_res_out(W, H, C);
Halide::Runtime::Buffer<float, 3> low_res_in(W / 8, H / 8, C);
Halide::Runtime::Buffer<float, 3> low_res_out(W / 8, H / 8, C);

// Downsample the input with a box filter
low_res_in.fill(0.0f);
Expand Down
5 changes: 2 additions & 3 deletions apps/bilateral_grid/bilateral_grid_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ class BilateralGrid : public Halide::Generator<BilateralGrid> {
public:
GeneratorParam<int> s_sigma{"s_sigma", 8};

Input<Buffer<float>> input{"input", 2};
Input<Buffer<float, 2>> input{"input"};
Input<float> r_sigma{"r_sigma"};

Output<Buffer<float>> bilateral_grid{"bilateral_grid", 2};
Output<Buffer<float, 2>> bilateral_grid{"bilateral_grid"};

void generate() {
Var x("x"), y("y"), z("z"), c("c");
Expand Down
4 changes: 2 additions & 2 deletions apps/bilateral_grid/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ int main(int argc, char **argv) {
float r_sigma = (float)atof(argv[3]);
int timing_iterations = atoi(argv[4]);

Buffer<float> input = load_and_convert_image(argv[1]);
Buffer<float> output(input.width(), input.height());
Buffer<float, 2> input = load_and_convert_image(argv[1]);
Buffer<float, 2> output(input.width(), input.height());

bilateral_grid(input, r_sigma, output);

Expand Down
4 changes: 2 additions & 2 deletions apps/blur/halide_blur_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class HalideBlur : public Halide::Generator<HalideBlur> {
GeneratorParam<int> tile_x{"tile_x", 32}; // X tile.
GeneratorParam<int> tile_y{"tile_y", 8}; // Y tile.

Input<Buffer<uint16_t>> input{"input", 2};
Output<Buffer<uint16_t>> blur_y{"blur_y", 2};
Input<Buffer<uint16_t, 2>> input{"input"};
Output<Buffer<uint16_t, 2>> blur_y{"blur_y"};

void generate() {
Func blur_x("blur_x");
Expand Down
22 changes: 11 additions & 11 deletions apps/blur/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ using namespace Halide::Tools;

double t;

Buffer<uint16_t> blur(Buffer<uint16_t> in) {
Buffer<uint16_t> tmp(in.width() - 8, in.height());
Buffer<uint16_t> out(in.width() - 8, in.height() - 2);
Buffer<uint16_t, 2> blur(Buffer<uint16_t, 2> in) {
Buffer<uint16_t, 2> tmp(in.width() - 8, in.height());
Buffer<uint16_t, 2> out(in.width() - 8, in.height() - 2);

t = benchmark(10, 1, [&]() {
for (int y = 0; y < tmp.height(); y++)
Expand All @@ -32,8 +32,8 @@ Buffer<uint16_t> blur(Buffer<uint16_t> in) {
return out;
}

Buffer<uint16_t> blur_fast(Buffer<uint16_t> in) {
Buffer<uint16_t> out(in.width() - 8, in.height() - 2);
Buffer<uint16_t, 2> blur_fast(Buffer<uint16_t, 2> in) {
Buffer<uint16_t, 2> out(in.width() - 8, in.height() - 2);

t = benchmark(10, 1, [&]() {
#ifdef __SSE2__
Expand Down Expand Up @@ -133,8 +133,8 @@ Buffer<uint16_t> blur_fast(Buffer<uint16_t> in) {

#include "halide_blur.h"

Buffer<uint16_t> blur_halide(Buffer<uint16_t> in) {
Buffer<uint16_t> out(in.width() - 8, in.height() - 2);
Buffer<uint16_t, 2> blur_halide(Buffer<uint16_t, 2> in) {
Buffer<uint16_t, 2> out(in.width() - 8, in.height() - 2);

// Call it once to initialize the halide runtime stuff
halide_blur(in, out);
Expand Down Expand Up @@ -162,21 +162,21 @@ int main(int argc, char **argv) {
const int width = is_hexagon ? 648 : 2568;
const int height = is_hexagon ? 482 : 1922;

Buffer<uint16_t> input(width, height);
Buffer<uint16_t, 2> input(width, height);

for (int y = 0; y < input.height(); y++) {
for (int x = 0; x < input.width(); x++) {
input(x, y) = rand() & 0xfff;
}
}

Buffer<uint16_t> blurry = blur(input);
Buffer<uint16_t, 2> blurry = blur(input);
double slow_time = t;

Buffer<uint16_t> speedy = blur_fast(input);
Buffer<uint16_t, 2> speedy = blur_fast(input);
double fast_time = t;

Buffer<uint16_t> halide = blur_halide(input);
Buffer<uint16_t, 2> halide = blur_halide(input);
double halide_time = t;

printf("times: %f %f %f\n", slow_time, fast_time, halide_time);
Expand Down
4 changes: 2 additions & 2 deletions apps/c_backend/pipeline_cpp_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ HalideExtern_2(int, an_extern_c_func, int, float);

class PipelineCpp : public Halide::Generator<PipelineCpp> {
public:
Input<Buffer<uint16_t>> input{"input", 2};
Output<Buffer<uint16_t>> output{"output", 2};
Input<Buffer<uint16_t, 2>> input{"input"};
Output<Buffer<uint16_t, 2>> output{"output"};

void generate() {
Var x, y;
Expand Down
4 changes: 2 additions & 2 deletions apps/c_backend/pipeline_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ HalideExtern_2(int, an_extern_func, int, int);

class Pipeline : public Halide::Generator<Pipeline> {
public:
Input<Buffer<uint16_t>> input{"input", 2};
Output<Buffer<uint16_t>> output{"output", 2};
Input<Buffer<uint16_t, 2>> input{"input"};
Output<Buffer<uint16_t, 2>> output{"output"};

void generate() {
Var x, y;
Expand Down
6 changes: 3 additions & 3 deletions apps/c_backend/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ extern "C" int an_extern_stage(halide_buffer_t *in, halide_buffer_t *out) {
}

int main(int argc, char **argv) {
Buffer<uint16_t> in(1432, 324);
Buffer<uint16_t, 2> in(1432, 324);

for (int y = 0; y < in.height(); y++) {
for (int x = 0; x < in.width(); x++) {
in(x, y) = (uint16_t)rand();
}
}

Buffer<uint16_t> out_native(423, 633);
Buffer<uint16_t> out_c(423, 633);
Buffer<uint16_t, 2> out_native(423, 633);
Buffer<uint16_t, 2> out_c(423, 633);

pipeline_native(in, out_native);

Expand Down
6 changes: 3 additions & 3 deletions apps/c_backend/run_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ int cpp_extern_2(int a1, float a2) {
} // namespace namespace_shared_outer

int main(int argc, char **argv) {
Buffer<uint16_t> in(100, 100);
Buffer<uint16_t, 2> in(100, 100);

for (int y = 0; y < in.height(); y++) {
for (int x = 0; x < in.width(); x++) {
in(x, y) = (uint16_t)rand();
}
}

Buffer<uint16_t> out_native(100, 100);
Buffer<uint16_t> out_c(100, 100);
Buffer<uint16_t, 2> out_native(100, 100);
Buffer<uint16_t, 2> out_c(100, 100);

pipeline_cpp_native(in, out_native);

Expand Down
9 changes: 4 additions & 5 deletions apps/camera_pipe/camera_pipe_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,16 @@ class CameraPipe : public Halide::Generator<CameraPipe> {
// currently allow 8-bit computations
GeneratorParam<Type> result_type{"result_type", UInt(8)};

Input<Buffer<uint16_t>> input{"input", 2};
Input<Buffer<float>> matrix_3200{"matrix_3200", 2};
Input<Buffer<float>> matrix_7000{"matrix_7000", 2};
Input<Buffer<uint16_t, 2>> input{"input"};
Input<Buffer<float, 2>> matrix_3200{"matrix_3200"};
Input<Buffer<float, 2>> matrix_7000{"matrix_7000"};
Input<float> color_temp{"color_temp"};
Input<float> gamma{"gamma"};
Input<float> contrast{"contrast"};
Input<float> sharpen_strength{"sharpen_strength"};
Input<int> blackLevel{"blackLevel"};
Input<int> whiteLevel{"whiteLevel"};

Output<Buffer<uint8_t>> processed{"processed", 3};
Output<Buffer<uint8_t, 3>> processed{"processed"};

void generate();

Expand Down
Loading