https://github.com/halide/Halide
Raw File
Tip revision: 1f1b241879e4cc60babf4c644e434f4e4af6635b authored by Z Stern on 01 December 2018, 19:20:19 UTC
Change generated code from the C++ backend to not use native vector
Tip revision: 1f1b241
main.cpp
#include <cmath>
#include <cstdio>

#include "HalideBuffer.h"
#include "bazeldemo.h"  // Generated by Bazel via halide_library() rule

int main(int argc, char **argv) {
    constexpr int kEdge = 30;
    constexpr float kMax = kEdge * kEdge;

    Halide::Runtime::Buffer<float> input(kEdge, kEdge);
    for (int x = 0; x < kEdge; ++x) {
        for (int y = 0; y < kEdge; ++y) {
            input(x, y) = static_cast<float>(x + y) / kMax;
        }
    }

    const float kScale = 0.5f;
    Halide::Runtime::Buffer<float> output(kEdge, kEdge);
    int result = bazeldemo(input, kScale, output);
    if (result != 0) {
      fprintf(stderr, "Failure: %d\n", result);
      return -1;
    }

    for (int x = 0; x < kEdge; ++x) {
        for (int y = 0; y < kEdge; ++y) {
            const float expected = input(x, y) * kScale;
            constexpr float kEpsilon = 0.00001f;
            if (fabs(expected - output(x, y)) > kEpsilon) {
              fprintf(stderr, "Expected %f, Got %f\n", expected, output(x, y));
              return -1;
            }
        }
    }

    printf("Success!\n");
    return 0;
}
back to top