Created
November 1, 2017 17:11
-
-
Save shoaibkamil/29a6fe2f4f9ca8401658f793e7165ef4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Halide.h" | |
#include <stdio.h> | |
#include "testing.h" | |
using namespace Halide; | |
// This test verifies that the result of and Rdom summation is the same as | |
// a manually-unrolled loop. | |
#define WIDTH 8 | |
#define HEIGHT 8 | |
Var x("x"); | |
Var y("y"); | |
Var c("c"); | |
Buffer<uint8_t> run(Func func, const Target target) { | |
Buffer<uint8_t> output(WIDTH, HEIGHT, 3); | |
func.bound(c, 0, 3); | |
func.glsl(x, y, c); | |
func.realize(output, target); | |
output.copy_to_host(); | |
return output; | |
} | |
int main() { | |
// This test must be run with an OpenGL target. | |
const Target target = get_jit_target_from_environment().with_feature(Target::OpenGL); | |
Buffer<uint8_t> input(WIDTH, HEIGHT, 3); | |
input.fill([](int x, int y, int c) { return x + y + c; }); | |
Func unroll("unroll"); | |
unroll(x, y, c) = input(x, y, 0) + input(x, y, 1) + input(x, y, 2); | |
RDom rc(0, 3, "r"); | |
Func rdom("rdom"); | |
rdom(x, y, c) = sum(input(x, y, rc), "sum"); | |
auto unroll_output = run(unroll, target); | |
auto rdom_output = run(rdom, target); | |
if (!Testing::check_result<uint8_t>(rdom_output, [&](int x, int y, int c) { | |
return unroll_output(x, y, c); | |
})) { | |
return 1; | |
} | |
printf("Success!\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment