<commit_before>#include <fstream>

#include "Halide.h"

#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

using namespace Halide;

// This tests that we can correctly generate all the simd ops
using std::vector;
using std::string;

bool failed = false;
Var x("x"), y("y");

bool use_ssse3, use_sse41, use_sse42, use_avx, use_avx2;

string filter = "";

Target target;

int num_processes = 16;
int my_process_id = 0;

void check(string op, int vector_width, Expr e) {
    static int counter = 0;
    counter++;

    // Make a name for the test by uniquing then sanitizing the op name
    string name = op;
    for (size_t i = 0; i < name.size(); i++) {
        if (!isalnum(name[i])) name[i] = '_';
    }
    name += "_" + std::to_string(counter);

    // Bail out after generating the unique_name, so that names are
    // unique across different processes and don't depend on filter
    // settings.
    if ((!filter.empty()) && (op.find(filter) == string::npos)) return;
    if (counter % num_processes != my_process_id) return;

    const int W = 256*3, H = 100;

    // Define a vectorized Func that uses the pattern.
    Func f(name);
    f(x, y) = e;
    f.bound(x, 0, W).vectorize(x, vector_width);
    f.compute_root();

    // Include a scalar version
    Func f_scalar("scalar_" + name);
    f_scalar(x, y) = e;
    f_scalar.bound(x, 0, W);
    f_scalar.compute_root();

    // The output to the pipeline is the maximum absolute difference as a double.
    RDom r(0, W, 0, H);
    Func error("error_" + name);
    error() = maximum(abs(cast<double>(f(r.x, r.y)) - f_scalar(r.x, r.y)));

    vector<Argument> arg_types;
    arg_types.push_back(Argument("in_f32", Argument::InputBuffer, Float(32), 1));
    arg_types.push_back(Argument("in_f64", Argument::InputBuffer, Float(64), 1));
    arg_types.push_back(Argument("in_i8",  Argument::InputBuffer, Int(8),    1));
    arg_types.push_back(Argument("in_u8",  Argument::InputBuffer, UInt(8),   1));
    arg_types.push_back(Argument("in_i16", Argument::InputBuffer, Int(16),   1));
    arg_types.push_back(Argument("in_u16", Argument::InputBuffer, UInt(16),  1));
    arg_types.push_back(Argument("in_i32", Argument::InputBuffer, Int(32),   1));
    arg_types.push_back(Argument("in_u32", Argument::InputBuffer, UInt(32),  1));
    arg_types.push_back(Argument("in_i64", Argument::InputBuffer, Int(64),   1));
    arg_types.push_back(Argument("in_u64", Argument::InputBuffer, UInt(64),  1));

    {
        // Compile just the vector Func to assembly
        string asm_filename = "check_" + name + ".s";
        f.compile_to_assembly(asm_filename, arg_types, target);

        std::ifstream asm_file;
        asm_file.open(asm_filename);

        // Skip lines until we hit "for test_*y"

        string end("end for*x.x");
        string the_op("^_" + op);
        string line;
        while (getline(asm_file, line)) {
            if (line.find("for ") != string::npos &&
                line.find("s0.y") != string::npos &&
                line.find("preheader") == string::npos) break;
        }

        bool found_it = false;

        std::ostringstream msg;
        msg << op << " did not generate. Instead we got:\n";

        // Accumulate lines until we hit "end for*x.x"
        while (getline(asm_file, line)) {
            if (line.find("end for") != string::npos &&
                Halide::Internal::ends_with(line, ".x.x")) break;

            msg << line << "\n";

            // Check for the op in question
            found_it |= (line.find(op) != string::npos &&
                         line.find("_" + op) == string::npos);
        }

        if (!found_it) {
            failed = true;
            std::cerr << msg.str();
        }<commit_msg>Make simd op check work without assembly comments<commit_after>#include <fstream>

#include "Halide.h"

#include <stdarg.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

using namespace Halide;

// This tests that we can correctly generate all the simd ops
using std::vector;
using std::string;

bool failed = false;
Var x("x"), y("y");

bool use_ssse3, use_sse41, use_sse42, use_avx, use_avx2;

string filter = "";

Target target;

int num_processes = 16;
int my_process_id = 0;

void check(string op, int vector_width, Expr e) {
    static int counter = 0;
    counter++;

    // Make a name for the test by uniquing then sanitizing the op name
    string name = "op_" + op;
    for (size_t i = 0; i < name.size(); i++) {
        if (!isalnum(name[i])) name[i] = '_';
    }
    name += "_" + std::to_string(counter);

    // Bail out after generating the unique_name, so that names are
    // unique across different processes and don't depend on filter
    // settings.
    if ((!filter.empty()) && (op.find(filter) == string::npos)) return;
    if (counter % num_processes != my_process_id) return;

    const int W = 256*3, H = 100;

    // Define a vectorized Func that uses the pattern.
    Func f(name);
    f(x, y) = e;
    f.bound(x, 0, W).vectorize(x, vector_width);
    f.compute_root();

    // Include a scalar version
    Func f_scalar("scalar_" + name);
    f_scalar(x, y) = e;
    f_scalar.bound(x, 0, W);
    f_scalar.compute_root();

    // The output to the pipeline is the maximum absolute difference as a double.
    RDom r(0, W, 0, H);
    Func error("error_" + name);
    error() = maximum(abs(cast<double>(f(r.x, r.y)) - f_scalar(r.x, r.y)));

    vector<Argument> arg_types;
    arg_types.push_back(Argument("in_f32", Argument::InputBuffer, Float(32), 1));
    arg_types.push_back(Argument("in_f64", Argument::InputBuffer, Float(64), 1));
    arg_types.push_back(Argument("in_i8",  Argument::InputBuffer, Int(8),    1));
    arg_types.push_back(Argument("in_u8",  Argument::InputBuffer, UInt(8),   1));
    arg_types.push_back(Argument("in_i16", Argument::InputBuffer, Int(16),   1));
    arg_types.push_back(Argument("in_u16", Argument::InputBuffer, UInt(16),  1));
    arg_types.push_back(Argument("in_i32", Argument::InputBuffer, Int(32),   1));
    arg_types.push_back(Argument("in_u32", Argument::InputBuffer, UInt(32),  1));
    arg_types.push_back(Argument("in_i64", Argument::InputBuffer, Int(64),   1));
    arg_types.push_back(Argument("in_u64", Argument::InputBuffer, UInt(64),  1));

    {
        // Compile just the vector Func to assembly
        string asm_filename = "check_" + name + ".s";
        f.compile_to_assembly(asm_filename, arg_types, target);

        std::ifstream asm_file;
        asm_file.open(asm_filename);

        bool found_it = false;

        std::ostringstream msg;
        msg << op << " did not generate. Instead we got:\n";

        string line;
        while (getline(asm_file, line)) {
            msg << line << "\n";

            // Check for the op in question
            found_it |= (line.find(op) != string::npos &&
                         line.find("_" + op) == string::npos);
        }

        if (!found_it) {
            failed = true;
            std::cerr << msg.str();
        }
{'fraction_non_alphanumeric': 0.15246573406810796, 'fraction_numerical': 0.019358485233856155, 'mean_word_length': 2.9344080044469147, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 19, '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': '5697079', 'n_tokens_mistral': 2505, 'n_tokens_neox': 2373, 'n_words': 620}