This source file includes following definitions.
- my_halide_error
- check
- main
#include "HalideRuntime.h"
#include <stdio.h>
#include <stdlib.h>
#include "error_codes.h"
void my_halide_error(void *user_context, const char *msg) {
}
void check(int result, int correct) {
if (result != correct) {
printf("The exit status was %d instead of %d\n", result, correct);
exit(-1);
}
}
int main(int argc, char **argv) {
halide_set_error_handler(&my_halide_error);
halide_buffer_t in = {0}, out = {0};
halide_dimension_t shape[] = {{0, 64, 1},
{0, 64, 64}};
in.host = (uint8_t *)malloc(64*64*4);
in.type = halide_type_of<int>();
in.dim = shape;
in.dimensions = 2;
out.host = (uint8_t *)malloc(64*64*4);
out.type = halide_type_of<int>();
out.dim = shape;
out.dimensions = 2;
int result = error_codes(&in, 64, &out);
int correct = halide_error_code_success;
check(result, correct);
result = error_codes(&in, 50, &out);
correct = halide_error_code_explicit_bounds_too_small;
check(result, correct);
halide_dimension_t smaller[] = {{0, 50, 1},
{0, 64, 64}};
in.dim = smaller;
result = error_codes(&in, 64, &out);
correct = halide_error_code_access_out_of_bounds;
check(result, correct);
in.dim = shape;
{
halide_dimension_t bad_shape[] = {{0, 64, 1},
{0, -64, 64}};
halide_buffer_t i = in, o = out;
i.dim = bad_shape;
o.dim = bad_shape;
result = error_codes(&i, 0, &o);
correct = halide_error_code_buffer_extents_negative;
check(result, correct);
}
halide_dimension_t huge[] = {{0, 10000000, 1},
{0, 10000000, 64}};
in.dim = huge;
result = error_codes(&in, 64, &out);
correct = halide_error_code_buffer_extents_too_large;
check(result, correct);
in.dim = shape;
halide_dimension_t huge_stride[] = {{0, 64, 1},
{0, 64, 0x7fffffff}};
in.dim = huge_stride;
result = error_codes(&in, 64, &out);
correct = halide_error_code_buffer_allocation_too_large;
check(result, correct);
in.dim = shape;
halide_dimension_t wrong_stride[] = {{0, 64, 2},
{0, 64, 64}};
in.dim = wrong_stride;
result = error_codes(&in, 64, &out);
correct = halide_error_code_constraint_violated;
check(result, correct);
in.dim = shape;
result = error_codes(&in, -23, &out);
correct = halide_error_code_param_too_small;
check(result, correct);
shape[0].extent = 108;
result = error_codes(&in, 108, &out);
correct = halide_error_code_param_too_large;
check(result, correct);
shape[0].extent = 64;
result = error_codes(nullptr, 64, &out);
correct = halide_error_code_buffer_argument_is_null;
check(result, correct);
printf("Success!\n");
return 0;
}