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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include "Halide.h"
#include <stdio.h>
using namespace Halide;
bool error_occurred;
void my_error_handler(JITUserContext *user_context, const char *msg) {
error_occurred = true;
}
int main(int argc, char **argv) {
// Use explicit set_range() calls
{
Func f, g;
Var x, y;
Param<float> p;
Buffer<float> input(100, 100);
p.set_range(1, 10);
g(x, y) = input(x, y) + 1.0f;
g.compute_root();
f(x, y) = g(cast<int>(x / p), y);
f.jit_handlers().custom_error = my_error_handler;
error_occurred = false;
p.set(2);
f.realize({100, 100});
if (error_occurred) {
printf("Error incorrectly raised\n");
return 1;
}
p.set(0);
error_occurred = false;
f.realize({100, 100});
if (!error_occurred) {
printf("Error should have been raised\n");
return 1;
}
}
// Use ctor arguments
{
Func f, g;
Var x, y;
// initial value: 2, min: 1, max: 10
Param<float> p(2, 1, 10);
Buffer<float> input(100, 100);
g(x, y) = input(x, y) + 1.0f;
g.compute_root();
f(x, y) = g(cast<int>(x / p), y);
f.jit_handlers().custom_error = my_error_handler;
error_occurred = false;
f.realize({100, 100});
if (error_occurred) {
printf("Error incorrectly raised\n");
return 1;
}
p.set(0);
error_occurred = false;
f.realize({100, 100});
if (!error_occurred) {
printf("Error should have been raised\n");
return 1;
}
}
printf("Success!\n");
return 0;
}
|