#include <stdio.h>
#include <cstdlib>
static float h_dx[] = {1.f / 12, -8.f / 12, 0, 8.f / 12, -1.f / 12};
static float h_spread[] = {1.f / 5, 1.f / 5, 1.f / 5, 1.f / 5, 1.f / 5};
static array dx, spread, kernel;
static array full_out, dsep_out, hsep_out;
static void full() { full_out =
convolve2(img, kernel);}
static void dsep() { dsep_out =
convolve(dx, spread, img); }
{
return (max<float>(
abs(left - right)) > 1e-6);
}
int main(int argc, char **argv)
{
try {
int device = argc > 1 ? atoi(argv[1]) : 0;
spread =
array(1, 5, h_spread);
printf(
"full 2D convolution: %.5f seconds\n",
timeit(full));
printf(
"separable, device pointers: %.5f seconds\n",
timeit(dsep));
if (fail(full_out, dsep_out)) {
throw af::exception(
"full != dsep"); }
fprintf(stderr,
"%s\n", e.
what());
}
return 0;
}