This source file includes following definitions.
- count
- main
#include "Halide.h"
#include <stdio.h>
using namespace Halide;
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
int call_counter = 0;
extern "C" DLLEXPORT int count(int x) {
return call_counter++;
}
HalideExtern_1(int, count, int);
int main(int argc, char **argv) {
{
Func f, g;
Var x;
RDom r(0, 10);
RVar ri, ro;
f(x) = count(x);
g(x) = 0;
g(r) = f(r);
g.update().split(r, ro, ri, 2);
f.compute_at(g, ri);
Buffer<int> im = g.realize(10);
for (int i = 0; i < im.width(); i++) {
if (im(i) != i) {
printf("im(%d) = %d instead of %d\n", i, im(i), i);
return -1;
}
}
call_counter = 0;
}
{
Func f, g;
Var x;
RDom r(0, 10);
RVar ri, ro;
f(x) = count(x);
g(x) = 0;
g(r) = f(r);
g.update().split(r, ro, ri, 2);
f.compute_at(g, ro).unroll(x);
Buffer<int> im = g.realize(10);
for (int i = 0; i < im.width(); i++) {
if (im(i) != i) {
printf("im(%d) = %d instead of %d\n", i, im(i), i);
return -1;
}
}
call_counter = 0;
}
{
Func f, g;
Var x;
RDom r(0, 10);
RVar ri, ro;
f(x) = count(x);
g(x) = 0;
g(r) = f(r);
g.update().split(r, ro, ri, 2).unroll(ri);
f.compute_at(g, ri);
Buffer<int> im = g.realize(10);
for (int i = 0; i < im.width(); i++) {
if (im(i) != i) {
printf("im(%d) = %d instead of %d\n", i, im(i), i);
return -1;
}
}
call_counter = 0;
}
{
Func f, g;
Var x;
RDom r(0, 10);
RVar ri, ro;
f(x) = count(x);
g(x) = 0;
g(r) = f(r);
g.update().split(r, ro, ri, 2).reorder(ro, ri);
f.compute_at(g, ro);
Buffer<int> im = g.realize(10);
for (int i = 0; i < im.width(); i++) {
int correct = (i / 2) + ((i % 2 == 0) ? 0 : 5);
if (im(i) != correct) {
printf("im(%d) = %d instead of %d\n", i, im(i), correct);
return -1;
}
}
call_counter = 0;
}
{
Func f, g;
Var x;
RDom r(0, 20);
RVar rio, rii, ri, ro, fused;
f(x) = count(x);
g(x) = 0;
g(r) = f(r);
g.update().split(r, ro, ri, 4).split(ri, rio, rii, 2).fuse(rio, ro, fused);
f.compute_at(g, fused);
Buffer<int> im = g.realize(20);
for (int i = 0; i < im.width(); i++) {
int correct = i;
if (im(i) != correct) {
printf("im(%d) = %d instead of %d\n", i, im(i), correct);
return -1;
}
}
call_counter = 0;
}
printf("Success!\n");
return 0;
}