Simplify fuzz testing

This implements testing of the amplifier by generating random expressions and verifying that the simplified version of that expression is equal to the original for a random sampling of values. There are also a bunch of fixes for bugs that were found by the testing.

There are a few issues to be aware of:

- It randomizes the seed for the testing, for better coverage. It also prints out the seed it uses to run the tests, so if there is a failure it can be reproduced. I'm uncomfortable with this solution, however, it has found obscure failures that were missed with otherwise very large samplings of expressions (~1 minute of runtime). We might need to move this testing to a separate test, and let it run for a long time (longer than we are willing to wait for the internal tests). It's currently set up to run a few seconds worth of fuzz tests during the internal tests.

- There are still some holes in the types of expressions that get tested. I'm thinking about ways to do more of these, but I decided to send the pull request now because of the large number of changes to the simplifier (bug fixes).
You're absolutely right of course, the only reasonable solution would be to
extract the whole block of if statements into a separate function, but that
doesn't sound like an improvement in readability...


On Mon, Aug 25, 2014 at 5:24 PM, Dillon Sharlet <notifications@github.com>
wrote:

> In src/Simplify.cpp:
>
> > @@ -330,34 +342,34 @@ class Simplify : public IRMutator {
> >                     is_const(cast_a->value) && is_const(cast_b->value)) {
> >              // u8(5) + u8(5) = u8(10)
> >              expr = Cast::make(op->type, Add::make(cast_a->value, cast_b->value));
> > -        } else if (min_a && sub_a_b && equal(sub_a_b->b, b)) {
> > +        } else if (min_a && sub_a_b && no_overflow(op->type) && equal(sub_a_b->b, b)) {
>
> I'd like to, but unless I'm having an embarrassing brain fart, there is no
> way to do so while maintaining the behavior of the else branch. Notice I
> did it here:
> https://github.com/halide/Halide/pull/442/files#diff-77a4cb3680dc3c57a87fa20cfed120e9R1353
> but I had to duplicate the last 2 else cases. Not so bad when it's just two
> simple cases, but these others require duplicating a lot more without
> rearranging the order of the rules, which the simplifier is somewhat
> sensitive to.
>
> Also, the motivation for this pull request is that I'm going to write a
> pattern based rule system for the simplifier, so hopefully a lot of these
> huge numbers of hard-to-read ifs will go away.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/halide/Halide/pull/442/files#r16661123>.
>



-- 


Daniel Heck | Software Engineer | dheck@google.com | +49(451)37089-285

Google Germany GmbH
Maria-Goeppert-Str.3
23560 Lübeck
Deutschland

Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores