1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include "HalideBuffer.h"
#include "HalideRuntime.h"
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include "blur2x2.h"
#define RUN_BENCHMARKS 0
#if RUN_BENCHMARKS
#include "halide_benchmark.h"
#endif
using namespace Halide::Runtime;
const int W = 80, H = 80;
Buffer<float, 3> buffer_factory_planar(int w, int h, int c) {
return Buffer<float, 3>(w, h, c);
}
Buffer<float, 3> buffer_factory_interleaved(int w, int h, int c) {
return Buffer<float, 3>::make_interleaved(w, h, c);
}
void test(Buffer<float, 3> (*factory)(int w, int h, int c)) {
Buffer<float, 3> input = factory(W, H, 3);
input.for_each_element([&](int x, int y, int c) {
// Just an arbitrary color pattern with enough variation to notice the blur
if (c == 0) {
input(x, y, c) = ((x % 7) + (y % 3)) / 255.f;
} else if (c == 1) {
input(x, y, c) = (x + y) / 255.f;
} else {
input(x, y, c) = ((x * 5) + (y * 2)) / 255.f;
}
});
Buffer<float, 3> output = factory(W, H, 3);
printf("Evaluating output over %d x %d\n", W, H);
blur2x2(input, W, H, output);
#if RUN_BENCHMARKS
double t = Halide::Tools::benchmark(10, 100, [&]() {
blur2x2(input, W, H, output);
});
const float megapixels = (W * H) / (1024.f * 1024.f);
printf("Benchmark: %d %d -> %f mpix/s\n", W, H, megapixels / t);
#endif
}
int main(int argc, char **argv) {
printf("Testing planar buffer...\n");
test(buffer_factory_planar);
printf("Testing interleaved buffer...\n");
test(buffer_factory_interleaved);
printf("Success!\n");
return 0;
}
|