<commit_before>#include "Halide.h"
#include <stdio.h>

using namespace Halide;

struct event {
    char func;
    int parent_id;
    int event_type;
    int type_code, bits, width, value_index;
    int num_int_args;
    int int_args[4];
    float value[4];
};

event trace[1024];
int n_trace = 0;

// Print an event in a human-readable way
void print_event(event e) {
    assert(e.num_int_args <= 4 && e.width <= 4);

    const char *event_types[] = {"Load",
                                 "Store",
                                 "Begin realization",
                                 "End realization",
                                 "Produce",
                                 "End Produce",
                                 "Consume",
                                 "End consume",
                                 "Begin pipeline",
                                 "End pipeline"};
    assert(e.event_type >= 0 && e.event_type <= 9);
    printf("%d %s ", e.event_type, event_types[e.event_type]);

    printf("%c.%d[", e.func, e.value_index);
    for (int i = 0; i < e.num_int_args; i++) {
        if (i > 0) printf(", ");
        printf("%d", e.int_args[i]);
    }
    printf("] [");
    for (int i = 0; i < e.width; i++) {
        if (i > 0) printf(", ");
        printf("%f", e.value[i]);
    }
    printf("]\n");
}

// Print an event in a way suitable for inclusion in source code
void print_event_source(event e) {
    printf("{%d, %d, %d, %d, %d, %d, %d, %d, {%d, %d, %d, %d}, {%f, %f, %f, %f}},\n",
           e.func, e.parent_id, e.event_type, e.type_code, e.bits, e.width, e.value_index,
           e.num_int_args, e.int_args[0], e.int_args[1], e.int_args[2], e.int_args[3],
           e.value[0], e.value[1], e.value[2], e.value[3]);
}

// Are two floats nearly equal?
bool float_match(float a, float b) {
    return ((a - 0.001f) < b) && ((a + 0.001f) > b);
}

// Are two events equal?
bool events_match(event a, event b) {
    return (a.func == b.func &&
            a.parent_id == b.parent_id &&
            a.event_type == b.event_type &&
            a.type_code == b.type_code &&
            a.bits == b.bits &&
            a.width == b.width &&
            a.value_index == b.value_index &&
            a.num_int_args == b.num_int_args &&
            a.int_args[0] == b.int_args[0] &&
            a.int_args[1] == b.int_args[1] &&
            a.int_args[2] == b.int_args[2] &&
            a.int_args[3] == b.int_args[3] &&
            float_match(a.value[0], b.value[0]) &&
            float_match(a.value[1], b.value[1]) &&
            float_match(a.value[2], b.value[2]) &&
            float_match(a.value[3], b.value[3]));
}

int my_trace(void *user_context, const halide_trace_event_t *ev) {
    assert(ev->dimensions <= 4 && ev->type.lanes <= 4);

    // Record this event in the trace array
    event e = {0};
    e.func = ev->func[0];
    e.parent_id = ev->parent_id;
    e.event_type = ev->event;
    e.type_code = ev->type.code;
    e.bits = ev->type.bits;
    e.width = ev->type.lanes;
    e.value_index = ev->value_index;
    e.num_int_args = ev->dimensions;
    for (int i = 0; i < ev->dimensions; i++) {
        e.int_args[i] = ev->coordinates[i];
    }
    for (int i = 0; i < ev->type.lanes; i++) {
        e.value[i] = ((const float *)(ev->value))[i];
    }
    trace[n_trace++] = e;
    return n_trace;
}

int main(int argc, char **argv) {

    Func f("f"), g("g");
    Var x;
    g(x) = Tuple(sin(x*0.1f), cos(x*0.1f));
    f(x) = g(x)[0] + g(x+1)[1];

    f.vectorize(x, 4);
    f.trace_stores();
    f.trace_realizations();

    g.vectorize(x, 4);
    g.store_root().compute_at(f, x);
    g.trace_stores().trace_loads().trace_realizations();

    f.set_custom_trace(&my_trace);
    f.realize(10);

    // The golden trace, recorded when this test was written
    event correct_trace[] = {
        {102, 0, 8, 3, 0, 0, 0, 0, {0, 0, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {102, 1, 2, 3, 0, 0, 0, 2, {0, 10, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 1, 2, 3, 0, 0, 0, 2, {0, 11, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {102, 2, 4, 3, 0, 0, 0, 2, {0, 10, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 3, 4, 3, 0, 0, 0, 2, {0, 5, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 5, 1, 2, 32, 4, 0, 4, {0, 1, 2, 3}, {0.000000, 0.099833, 0.198669, 0.295520}},
        {103, 5, 1, 2, 32, 4, 1, 4, {0, 1, 2, 3}, {1.000000, 0.995004, 0.980067, 0.955337}},
        {103, 5, 1, 2, 32, 4, 0, 4, {1, 2, 3, 4}, {0.099833, 0.198669, 0.295520, 0.389418}},
        {103, 5, 1, 2, 32, 4, 1, 4, {1, 2, 3, 4}, {0.995004, 0.980067, 0.955337, 0.921061}},
        {103, 5, 5, 3, 0, 0, 0, 2, {0, 5, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 3, 6, 3, 0, 0, 0, 2, {0, 5, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 11, 0, 2, 32, 4, 1, 4, {1, 2, 3, 4}, {0.995004, 0.980067, 0.955337, 0.921061}},
        {103, 11, 0, 2, 32, 4, 0, 4, {0, 1, 2, 3}, {0.000000, 0.099833, 0.198669, 0.295520}},
        {102, 4, 1, 2, 32, 4, 0, 4, {0, 1, 2, 3}, {0.995004, 1.079900, 1.154006, 1.216581}},
        {103, 11, 7, 3, 0, 0, 0, 2, {0, 5, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 3, 4, 3, 0, 0, 0, 2, {5, 4, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 16, 1, 2, 32, 4, 0, 4, {5, 6, 7, 8}, {0.479426, 0.564642, 0.644218, 0.717356}},
        {103, 16, 1, 2, 32, 4, 1, 4, {5, 6, 7, 8}, {0.877583, 0.825336, 0.764842, 0.696707}},
        {103, 16, 5, 3, 0, 0, 0, 2, {5, 4, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 3, 6, 3, 0, 0, 0, 2, {5, 4, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 20, 0, 2, 32, 4, 1, 4, {5, 6, 7, 8}, {0.877583, 0.825336, 0.764842, 0.696707}},
        {103, 20, 0, 2, 32, 4, 0, 4, {4, 5, 6, 7}, {0.389418, 0.479426, 0.564642, 0.644218}},
        {102, 4, 1, 2, 32, 4, 0, 4, {4, 5, 6, 7}, {1.267001, 1.304761, 1.329485, 1.340924}},
        {103, 20, 7, 3, 0, 0, 0, 2, {5, 4, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 3, 4, 3, 0, 0, 0, 2, {9, 2, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 25, 1, 2, 32, 4, 0, 4, {7, 8, 9, 10}, {0.644218, 0.717356, 0.783327, 0.841471}},
        {103, 25, 1, 2, 32, 4, 1, 4, {7, 8, 9, 10}, {0.764842, 0.696707, 0.621610, 0.540302}},
        {103, 25, 5, 3, 0, 0, 0, 2, {9, 2, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 3, 6, 3, 0, 0, 0, 2, {9, 2, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 29, 0, 2, 32, 4, 1, 4, {7, 8, 9, 10}, {0.764842, 0.696707, 0.621610, 0.540302}},
        {103, 29, 0, 2, 32, 4, 0, 4, {6, 7, 8, 9}, {0.564642, 0.644218, 0.717356, 0.783327}},
        {102, 4, 1, 2, 32, 4, 0, 4, {6, 7, 8, 9}, {1.329485, 1.340924, 1.338966, 1.323629}},
        {103, 29, 7, 3, 0, 0, 0, 2, {9, 2, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {102, 4, 5, 3, 0, 0, 0, 2, {0, 10, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {103, 3, 3, 3, 0, 0, 0, 2, {0, 11, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {102, 2, 3, 3, 0, 0, 0, 2, {0, 10, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}},
        {102, 1, 9, 3, 0, 0, 0, 0, {0, 0, 0, 0}, {0.000000, 0.000000, 0.000000, 0.000000}}
    };

    int correct_trace_length = sizeof(correct_trace)/sizeof(correct_trace[0]);

    int n = n_trace > correct_trace_length ? n_trace : correct_trace_length;
    for (int i = 0; i < n; i++) {
        event recorded = {0};
        if (i < n_trace) recorded = trace[i];
        event correct = {0};
        if (i < correct_trace_length) correct = correct_trace[i];

        if (!events_match(recorded, correct)) {
            // Uh oh. Maybe it's just a reordered load.
            if (i > 0 && events_match(recorded, correct_trace[i-1]) &&
                recorded.event_type == 0 && correct.event_type == 0) {
                // Phew.
                continue;
            }

            if (i < correct_trace_length-1 &&
                events_match(recorded, correct_trace[i+1]) &&
                recorded.event_type == 0 && correct.event_type == 0) {
                // Phew.
                continue;<commit_msg>Add "f" suffixes to float literals to silence warnings<commit_after>#include "Halide.h"
#include <stdio.h>

using namespace Halide;

struct event {
    char func;
    int parent_id;
    int event_type;
    int type_code, bits, width, value_index;
    int num_int_args;
    int int_args[4];
    float value[4];
};

event trace[1024];
int n_trace = 0;

// Print an event in a human-readable way
void print_event(event e) {
    assert(e.num_int_args <= 4 && e.width <= 4);

    const char *event_types[] = {"Load",
                                 "Store",
                                 "Begin realization",
                                 "End realization",
                                 "Produce",
                                 "End Produce",
                                 "Consume",
                                 "End consume",
                                 "Begin pipeline",
                                 "End pipeline"};
    assert(e.event_type >= 0 && e.event_type <= 9);
    printf("%d %s ", e.event_type, event_types[e.event_type]);

    printf("%c.%d[", e.func, e.value_index);
    for (int i = 0; i < e.num_int_args; i++) {
        if (i > 0) printf(", ");
        printf("%d", e.int_args[i]);
    }
    printf("] [");
    for (int i = 0; i < e.width; i++) {
        if (i > 0) printf(", ");
        printf("%f", e.value[i]);
    }
    printf("]\n");
}

// Print an event in a way suitable for inclusion in source code
void print_event_source(event e) {
    printf("{%d, %d, %d, %d, %d, %d, %d, %d, {%d, %d, %d, %d}, {%f, %f, %f, %f}},\n",
           e.func, e.parent_id, e.event_type, e.type_code, e.bits, e.width, e.value_index,
           e.num_int_args, e.int_args[0], e.int_args[1], e.int_args[2], e.int_args[3],
           e.value[0], e.value[1], e.value[2], e.value[3]);
}

// Are two floats nearly equal?
bool float_match(float a, float b) {
    return ((a - 0.001f) < b) && ((a + 0.001f) > b);
}

// Are two events equal?
bool events_match(event a, event b) {
    return (a.func == b.func &&
            a.parent_id == b.parent_id &&
            a.event_type == b.event_type &&
            a.type_code == b.type_code &&
            a.bits == b.bits &&
            a.width == b.width &&
            a.value_index == b.value_index &&
            a.num_int_args == b.num_int_args &&
            a.int_args[0] == b.int_args[0] &&
            a.int_args[1] == b.int_args[1] &&
            a.int_args[2] == b.int_args[2] &&
            a.int_args[3] == b.int_args[3] &&
            float_match(a.value[0], b.value[0]) &&
            float_match(a.value[1], b.value[1]) &&
            float_match(a.value[2], b.value[2]) &&
            float_match(a.value[3], b.value[3]));
}

int my_trace(void *user_context, const halide_trace_event_t *ev) {
    assert(ev->dimensions <= 4 && ev->type.lanes <= 4);

    // Record this event in the trace array
    event e = {0};
    e.func = ev->func[0];
    e.parent_id = ev->parent_id;
    e.event_type = ev->event;
    e.type_code = ev->type.code;
    e.bits = ev->type.bits;
    e.width = ev->type.lanes;
    e.value_index = ev->value_index;
    e.num_int_args = ev->dimensions;
    for (int i = 0; i < ev->dimensions; i++) {
        e.int_args[i] = ev->coordinates[i];
    }
    for (int i = 0; i < ev->type.lanes; i++) {
        e.value[i] = ((const float *)(ev->value))[i];
    }
    trace[n_trace++] = e;
    return n_trace;
}

int main(int argc, char **argv) {

    Func f("f"), g("g");
    Var x;
    g(x) = Tuple(sin(x*0.1f), cos(x*0.1f));
    f(x) = g(x)[0] + g(x+1)[1];

    f.vectorize(x, 4);
    f.trace_stores();
    f.trace_realizations();

    g.vectorize(x, 4);
    g.store_root().compute_at(f, x);
    g.trace_stores().trace_loads().trace_realizations();

    f.set_custom_trace(&my_trace);
    f.realize(10);

    // The golden trace, recorded when this test was written
    event correct_trace[] = {
        {102, 0, 8, 3, 0, 0, 0, 0, {0, 0, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {102, 1, 2, 3, 0, 0, 0, 2, {0, 10, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 1, 2, 3, 0, 0, 0, 2, {0, 11, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {102, 2, 4, 3, 0, 0, 0, 2, {0, 10, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 3, 4, 3, 0, 0, 0, 2, {0, 5, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 5, 1, 2, 32, 4, 0, 4, {0, 1, 2, 3}, {0.000000f, 0.099833f, 0.198669f, 0.295520f}},
        {103, 5, 1, 2, 32, 4, 1, 4, {0, 1, 2, 3}, {1.000000f, 0.995004f, 0.980067f, 0.955337f}},
        {103, 5, 1, 2, 32, 4, 0, 4, {1, 2, 3, 4}, {0.099833f, 0.198669f, 0.295520f, 0.389418f}},
        {103, 5, 1, 2, 32, 4, 1, 4, {1, 2, 3, 4}, {0.995004f, 0.980067f, 0.955337f, 0.921061f}},
        {103, 5, 5, 3, 0, 0, 0, 2, {0, 5, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 3, 6, 3, 0, 0, 0, 2, {0, 5, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 11, 0, 2, 32, 4, 1, 4, {1, 2, 3, 4}, {0.995004f, 0.980067f, 0.955337f, 0.921061f}},
        {103, 11, 0, 2, 32, 4, 0, 4, {0, 1, 2, 3}, {0.000000f, 0.099833f, 0.198669f, 0.295520f}},
        {102, 4, 1, 2, 32, 4, 0, 4, {0, 1, 2, 3}, {0.995004f, 1.079900f, 1.154006f, 1.216581f}},
        {103, 11, 7, 3, 0, 0, 0, 2, {0, 5, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 3, 4, 3, 0, 0, 0, 2, {5, 4, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 16, 1, 2, 32, 4, 0, 4, {5, 6, 7, 8}, {0.479426f, 0.564642f, 0.644218f, 0.717356f}},
        {103, 16, 1, 2, 32, 4, 1, 4, {5, 6, 7, 8}, {0.877583f, 0.825336f, 0.764842f, 0.696707f}},
        {103, 16, 5, 3, 0, 0, 0, 2, {5, 4, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 3, 6, 3, 0, 0, 0, 2, {5, 4, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 20, 0, 2, 32, 4, 1, 4, {5, 6, 7, 8}, {0.877583f, 0.825336f, 0.764842f, 0.696707f}},
        {103, 20, 0, 2, 32, 4, 0, 4, {4, 5, 6, 7}, {0.389418f, 0.479426f, 0.564642f, 0.644218f}},
        {102, 4, 1, 2, 32, 4, 0, 4, {4, 5, 6, 7}, {1.267001f, 1.304761f, 1.329485f, 1.340924f}},
        {103, 20, 7, 3, 0, 0, 0, 2, {5, 4, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 3, 4, 3, 0, 0, 0, 2, {9, 2, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 25, 1, 2, 32, 4, 0, 4, {7, 8, 9, 10}, {0.644218f, 0.717356f, 0.783327f, 0.841471f}},
        {103, 25, 1, 2, 32, 4, 1, 4, {7, 8, 9, 10}, {0.764842f, 0.696707f, 0.621610f, 0.540302f}},
        {103, 25, 5, 3, 0, 0, 0, 2, {9, 2, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 3, 6, 3, 0, 0, 0, 2, {9, 2, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 29, 0, 2, 32, 4, 1, 4, {7, 8, 9, 10}, {0.764842f, 0.696707f, 0.621610f, 0.540302f}},
        {103, 29, 0, 2, 32, 4, 0, 4, {6, 7, 8, 9}, {0.564642f, 0.644218f, 0.717356f, 0.783327f}},
        {102, 4, 1, 2, 32, 4, 0, 4, {6, 7, 8, 9}, {1.329485f, 1.340924f, 1.338966f, 1.323629f}},
        {103, 29, 7, 3, 0, 0, 0, 2, {9, 2, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {102, 4, 5, 3, 0, 0, 0, 2, {0, 10, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {103, 3, 3, 3, 0, 0, 0, 2, {0, 11, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {102, 2, 3, 3, 0, 0, 0, 2, {0, 10, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}},
        {102, 1, 9, 3, 0, 0, 0, 0, {0, 0, 0, 0}, {0.000000f, 0.000000f, 0.000000f, 0.000000f}}
    };

    int correct_trace_length = sizeof(correct_trace)/sizeof(correct_trace[0]);

    int n = n_trace > correct_trace_length ? n_trace : correct_trace_length;
    for (int i = 0; i < n; i++) {
        event recorded = {0};
        if (i < n_trace) recorded = trace[i];
        event correct = {0};
        if (i < correct_trace_length) correct = correct_trace[i];

        if (!events_match(recorded, correct)) {
            // Uh oh. Maybe it's just a reordered load.
            if (i > 0 && events_match(recorded, correct_trace[i-1]) &&
                recorded.event_type == 0 && correct.event_type == 0) {
                // Phew.
                continue;
            }

            if (i < correct_trace_length-1 &&
                events_match(recorded, correct_trace[i+1]) &&
                recorded.event_type == 0 && correct.event_type == 0) {
                // Phew.
                continue;
{'fraction_non_alphanumeric': 0.2127146730943055, 'fraction_numerical': 0.2013859596263935, 'mean_word_length': 2.0853318460680423, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '334118', 'n_tokens_mistral': 9615, 'n_tokens_neox': 7025, 'n_words': 1935}