<commit_before>#include "Halide.h"

using namespace Halide;

void blur_float(std::string suffix, ImageParam input8, const int channels) {
    Var x, y, c;
    Func input;
    input(x, y, c) = input8(clamp(x, input8.left(), input8.right()),
                            clamp(y, input8.top(), input8.bottom()), c);

    Func blur_x("blur_x");
    blur_x(x, y, c) = (input(x, y, c) +
        input(x + 1, y, c) +
        input(x + 2, y, c)) / 3;

    Func result("result");
    result(x, y, c) = (blur_x(x, y, c) +
        blur_x(x, y + 1, c) +
        blur_x(x, y + 2, c)) / 3;

    // Unset default constraints so that specialization works.
    result.output_buffer().set_stride(0, Expr());

    result.bound(c, 0, channels);

    Expr interleaved =
        (result.output_buffer().stride(0) == channels &&
         result.output_buffer().stride(2) == 1);
    Expr planar = result.output_buffer().stride(0) == 1;

    if (suffix == "_rs") {
        result.shader(x, y, c, DeviceAPI::Renderscript);
        result.specialize(interleaved).vectorize(c);
        // non-specialized version is planar
    } else {
        Var yi;
        result
            .reorder(c, x, y)
            .unroll(c)
            .split(y, y, yi, 32)
            .parallel(y)
            .vectorize(x, 2);
        result.specialize(interleaved);
        result.specialize(planar);
        // blur_x is compute at result, so it's included in result's
        // specializations.
        blur_x.store_at(result, y)
            .compute_at(result, yi)
            .reorder(c, x, y)
            .unroll(c)
            .vectorize(x, 2);
    }

    std::vector<Argument> args;
    args.push_back(input8);
    std::string filename("generated_blur");
    result.compile_to_file(filename + suffix + "_float", args);
}

void copy_float(std::string suffix, ImageParam input8, const int channels) {
    Var x, y, c;
    Func input;
    input(x, y, c) = input8(clamp(x, input8.left(), input8.right()),
                            clamp(y, input8.top(), input8.bottom()), c);

    Func result("result");
    result(x, y, c) = input(x, y, c);
    result.bound(c, 0, channels);

    // Unset default constraints so that specialization works.
    result.output_buffer().set_stride(0, Expr());

    Expr interleaved =
        (result.output_buffer().stride(0) == channels &&
         result.output_buffer().stride(2) == 1);

    if (suffix == "_rs") {
        result.shader(x, y, c, DeviceAPI::Renderscript);
        result.specialize(interleaved).vectorize(c);
    } else {
        result.reorder(c, x, y)
            .parallel(y)
            .unroll(c)
            .vectorize(x, 2)
            .specialize(interleaved);
    }
    // non-specialized version is planar

    std::vector<Argument> args;
    args.push_back(input8);
    std::string filename("generated_copy");
    result.compile_to_file(filename + suffix + "_float", args);
}

void blur_uint8(std::string suffix, ImageParam input8, const int channels) {
    Var x, y, c;
    Func input;<commit_msg>Adjust vectorization to match natural vector size for ARM NEON<commit_after>#include "Halide.h"

using namespace Halide;

void blur_float(std::string suffix, ImageParam input8, const int channels) {
    Var x, y, c;
    Func input;
    input(x, y, c) = input8(clamp(x, input8.left(), input8.right()),
                            clamp(y, input8.top(), input8.bottom()), c);

    Func blur_x("blur_x");
    blur_x(x, y, c) = (input(x, y, c) +
        input(x + 1, y, c) +
        input(x + 2, y, c)) / 3;

    Func result("result");
    result(x, y, c) = (blur_x(x, y, c) +
        blur_x(x, y + 1, c) +
        blur_x(x, y + 2, c)) / 3;

    // Unset default constraints so that specialization works.
    result.output_buffer().set_stride(0, Expr());

    result.bound(c, 0, channels);

    Expr interleaved =
        (result.output_buffer().stride(0) == channels &&
         result.output_buffer().stride(2) == 1);
    Expr planar = result.output_buffer().stride(0) == 1;

    if (suffix == "_rs") {
        result.shader(x, y, c, DeviceAPI::Renderscript);
        result.specialize(interleaved).vectorize(c);
        // non-specialized version is planar
    } else {
        Var yi;
        result
            .reorder(c, x, y)
            .unroll(c)
            .split(y, y, yi, 32)
            .parallel(y)
            .vectorize(x, 4);
        result.specialize(interleaved);
        result.specialize(planar);
        // blur_x is compute at result, so it's included in result's
        // specializations.
        blur_x.store_at(result, y)
            .compute_at(result, yi)
            .reorder(c, x, y)
            .unroll(c)
            .vectorize(x, 4);
    }

    std::vector<Argument> args;
    args.push_back(input8);
    std::string filename("generated_blur");
    result.compile_to_file(filename + suffix + "_float", args);
}

void copy_float(std::string suffix, ImageParam input8, const int channels) {
    Var x, y, c;
    Func input;
    input(x, y, c) = input8(clamp(x, input8.left(), input8.right()),
                            clamp(y, input8.top(), input8.bottom()), c);

    Func result("result");
    result(x, y, c) = input(x, y, c);
    result.bound(c, 0, channels);

    // Unset default constraints so that specialization works.
    result.output_buffer().set_stride(0, Expr());

    Expr interleaved =
        (result.output_buffer().stride(0) == channels &&
         result.output_buffer().stride(2) == 1);

    if (suffix == "_rs") {
        result.shader(x, y, c, DeviceAPI::Renderscript);
        result.specialize(interleaved).vectorize(c);
    } else {
        result.reorder(c, x, y)
            .parallel(y)
            .unroll(c)
            .vectorize(x, 4)
            .specialize(interleaved);
    }
    // non-specialized version is planar

    std::vector<Argument> args;
    args.push_back(input8);
    std::string filename("generated_copy");
    result.compile_to_file(filename + suffix + "_float", args);
}

void blur_uint8(std::string suffix, ImageParam input8, const int channels) {
    Var x, y, c;
    Func input;
{'fraction_non_alphanumeric': 0.15020542317173377, 'fraction_numerical': 0.012818405916187346, 'mean_word_length': 2.3329682365826945, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2253732', 'n_tokens_mistral': 2104, 'n_tokens_neox': 2004, 'n_words': 484}