<commit_before>#ifndef HALIDE_FUNC_H
#define HALIDE_FUNC_H

/** \file
 *
 * Defines Func - the front-end handle on a halide function, and related classes.
 */

#include "IR.h"
#include "Var.h"
#include "Function.h"
#include "Param.h"
#include "Argument.h"
#include "RDom.h"
#include "JITCompiledModule.h"
#include "Image.h"
#include "Target.h"
#include "Tuple.h"
#include "Target.h"

namespace Halide {

enum GPUAPI {
    GPU_Default,
    GPU_CUDA,
    GPU_OpenCL,
    GPU_GLSL
};

/** A class that can represent Vars or RVars. Used for reorder calls
 * which can accept a mix of either. */
struct VarOrRVar {
    VarOrRVar(const std::string &n, bool r) : var(n), rvar(n), is_rvar(r) {}
    VarOrRVar(const Var &v) : var(v), is_rvar(false) {}
    VarOrRVar(const RVar &r) : rvar(r), is_rvar(true) {}
    VarOrRVar(const RDom &r) : rvar(RVar(r)), is_rvar(true) {}

    const std::string &name() const {
        if (is_rvar) return rvar.name();
        else return var.name();
    }

    const Var var;
    const RVar rvar;
    const bool is_rvar;
};

/** A single definition of a Func. May be a pure or update definition. */
class Stage {
    Internal::Schedule schedule;
    void set_dim_type(VarOrRVar var, Internal::For::ForType t);
    void split(const std::string &old, const std::string &outer, const std::string &inner, Expr factor, bool exact);
    std::string dump_argument_list();
public:
    Stage(Internal::Schedule s) : schedule(s) {s.touched();}

    /** Scheduling calls that control how the domain of this stage is
     * traversed. See the documentation for Func for the meanings. */
    // @{

    EXPORT Stage &split(VarOrRVar old, VarOrRVar outer, VarOrRVar inner, Expr factor);
    EXPORT Stage &fuse(VarOrRVar inner, VarOrRVar outer, VarOrRVar fused);
    EXPORT Stage &serial(VarOrRVar var);
    EXPORT Stage &parallel(VarOrRVar var);
    EXPORT Stage &vectorize(VarOrRVar var);
    EXPORT Stage &unroll(VarOrRVar var);
    EXPORT Stage &parallel(VarOrRVar var, Expr task_size);
    EXPORT Stage &vectorize(VarOrRVar var, int factor);
    EXPORT Stage &unroll(VarOrRVar var, int factor);
    EXPORT Stage &tile(VarOrRVar x, VarOrRVar y,
                                VarOrRVar xo, VarOrRVar yo,
                                VarOrRVar xi, VarOrRVar yi, Expr
                                xfactor, Expr yfactor);
    EXPORT Stage &tile(VarOrRVar x, VarOrRVar y,
                                VarOrRVar xi, VarOrRVar yi,
                                Expr xfactor, Expr yfactor);
    EXPORT Stage &reorder(const std::vector<VarOrRVar> &vars);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2,
                                   VarOrRVar t3);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2,
                                   VarOrRVar t3, VarOrRVar t4);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2,
                                   VarOrRVar t3, VarOrRVar t4, VarOrRVar t5);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2,
                                   VarOrRVar t3, VarOrRVar t4, VarOrRVar t5,
                                   VarOrRVar t6);
    EXPORT Stage &rename(VarOrRVar old_name, VarOrRVar new_name);
    EXPORT Stage specialize(Expr condition);

    EXPORT Stage &gpu_threads(VarOrRVar thread_x, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_threads(VarOrRVar thread_x, VarOrRVar thread_y, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_threads(VarOrRVar thread_x, VarOrRVar thread_y, VarOrRVar thread_z, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_single_thread(GPUAPI gpu_api = GPU_Default);

    EXPORT Stage &gpu_blocks(VarOrRVar block_x, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_blocks(VarOrRVar block_x, VarOrRVar block_y, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_blocks(VarOrRVar block_x, VarOrRVar block_y, VarOrRVar block_z, GPUAPI gpu_api = GPU_Default);

    EXPORT Stage &gpu(VarOrRVar block_x, VarOrRVar thread_x, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu(VarOrRVar block_x, VarOrRVar block_y,
                               VarOrRVar thread_x, VarOrRVar thread_y,
                               GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu(VarOrRVar block_x, VarOrRVar block_y, VarOrRVar block_z,
                               VarOrRVar thread_x, VarOrRVar thread_y, VarOrRVar thread_z,
                               GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_tile(VarOrRVar x, Expr x_size, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_tile(VarOrRVar x, VarOrRVar y, Expr x_size, Expr y_size,
                                    GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_tile(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                    Expr x_size, Expr y_size, Expr z_size, GPUAPI gpu_api = GPU_Default);

    EXPORT Stage &allow_race_conditions();
    // @}

    // These calls are for legacy compatibility only.
    EXPORT Stage &cuda_threads(VarOrRVar thread_x) {
        return gpu_threads(thread_x);
    }
    EXPORT Stage &cuda_threads(VarOrRVar thread_x, VarOrRVar thread_y) {
        return gpu_threads(thread_x, thread_y);
    }
    EXPORT Stage &cuda_threads(VarOrRVar thread_x, VarOrRVar thread_y, VarOrRVar thread_z) {
        return gpu_threads(thread_x, thread_y, thread_z);
    }

    EXPORT Stage &cuda_blocks(VarOrRVar block_x) {
        return gpu_blocks(block_x);
    }
    EXPORT Stage &cuda_blocks(VarOrRVar block_x, VarOrRVar block_y) {
        return gpu_blocks(block_x, block_y);
    }
    EXPORT Stage &cuda_blocks(VarOrRVar block_x, VarOrRVar block_y, VarOrRVar block_z) {
        return gpu_blocks(block_x, block_y, block_z);
    }

    EXPORT Stage &cuda(VarOrRVar block_x, VarOrRVar thread_x) {
        return gpu(block_x, thread_x);
    }
    EXPORT Stage &cuda(VarOrRVar block_x, VarOrRVar block_y,
                                VarOrRVar thread_x, VarOrRVar thread_y) {
        return gpu(block_x, thread_x, block_y, thread_y);
    }
    EXPORT Stage &cuda(VarOrRVar block_x, VarOrRVar block_y, VarOrRVar block_z,
                                VarOrRVar thread_x, VarOrRVar thread_y, VarOrRVar thread_z) {
        return gpu(block_x, thread_x, block_y, thread_y, block_z, thread_z);
    }
    EXPORT Stage &cuda_tile(VarOrRVar x, int x_size) {
        return gpu_tile(x, x_size);
    }
    EXPORT Stage &cuda_tile(VarOrRVar x, VarOrRVar y, int x_size, int y_size) {
        return gpu_tile(x, y, x_size, y_size);
    }
    EXPORT Stage &cuda_tile(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                     int x_size, int y_size, int z_size) {
        return gpu_tile(x, y, z, x_size, y_size, z_size);
    }
};

/** A fragment of front-end syntax of the form f(x, y, z), where x,
 * y, z are Vars. It could be the left-hand side of a function
 * definition, or it could be a call to a function. We don't know
 * until we see how this object gets used.
 */
class FuncRefExpr;

class FuncRefVar {
    Internal::Function func;
    int implicit_placeholder_pos;
    std::vector<std::string> args;
    std::vector<std::string> args_with_implicit_vars(const std::vector<Expr> &e) const;
public:
    FuncRefVar(Internal::Function, const std::vector<Var> &, int placeholder_pos = -1);

    /**  Use this as the left-hand-side of a definition. */
    EXPORT Stage operator=(Expr);

    /** Use this as the left-hand-side of a definition for a Func with
     * multiple outputs. */
    EXPORT Stage operator=(const Tuple &);

    /** Define this function as a sum reduction over the negative of
     * the given expression. The expression should refer to some RDom
     * to sum over. If the function does not already have a pure
     * definition, this sets it to zero.
     */
    EXPORT Stage operator+=(Expr);
<commit_msg>Added typedef for backwards compatibility with code using ScheduleHandle.<commit_after>#ifndef HALIDE_FUNC_H
#define HALIDE_FUNC_H

/** \file
 *
 * Defines Func - the front-end handle on a halide function, and related classes.
 */

#include "IR.h"
#include "Var.h"
#include "Function.h"
#include "Param.h"
#include "Argument.h"
#include "RDom.h"
#include "JITCompiledModule.h"
#include "Image.h"
#include "Target.h"
#include "Tuple.h"
#include "Target.h"

namespace Halide {

enum GPUAPI {
    GPU_Default,
    GPU_CUDA,
    GPU_OpenCL,
    GPU_GLSL
};

/** A class that can represent Vars or RVars. Used for reorder calls
 * which can accept a mix of either. */
struct VarOrRVar {
    VarOrRVar(const std::string &n, bool r) : var(n), rvar(n), is_rvar(r) {}
    VarOrRVar(const Var &v) : var(v), is_rvar(false) {}
    VarOrRVar(const RVar &r) : rvar(r), is_rvar(true) {}
    VarOrRVar(const RDom &r) : rvar(RVar(r)), is_rvar(true) {}

    const std::string &name() const {
        if (is_rvar) return rvar.name();
        else return var.name();
    }

    const Var var;
    const RVar rvar;
    const bool is_rvar;
};

/** A single definition of a Func. May be a pure or update definition. */
class Stage {
    Internal::Schedule schedule;
    void set_dim_type(VarOrRVar var, Internal::For::ForType t);
    void split(const std::string &old, const std::string &outer, const std::string &inner, Expr factor, bool exact);
    std::string dump_argument_list();
public:
    Stage(Internal::Schedule s) : schedule(s) {s.touched();}

    /** Scheduling calls that control how the domain of this stage is
     * traversed. See the documentation for Func for the meanings. */
    // @{

    EXPORT Stage &split(VarOrRVar old, VarOrRVar outer, VarOrRVar inner, Expr factor);
    EXPORT Stage &fuse(VarOrRVar inner, VarOrRVar outer, VarOrRVar fused);
    EXPORT Stage &serial(VarOrRVar var);
    EXPORT Stage &parallel(VarOrRVar var);
    EXPORT Stage &vectorize(VarOrRVar var);
    EXPORT Stage &unroll(VarOrRVar var);
    EXPORT Stage &parallel(VarOrRVar var, Expr task_size);
    EXPORT Stage &vectorize(VarOrRVar var, int factor);
    EXPORT Stage &unroll(VarOrRVar var, int factor);
    EXPORT Stage &tile(VarOrRVar x, VarOrRVar y,
                                VarOrRVar xo, VarOrRVar yo,
                                VarOrRVar xi, VarOrRVar yi, Expr
                                xfactor, Expr yfactor);
    EXPORT Stage &tile(VarOrRVar x, VarOrRVar y,
                                VarOrRVar xi, VarOrRVar yi,
                                Expr xfactor, Expr yfactor);
    EXPORT Stage &reorder(const std::vector<VarOrRVar> &vars);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2,
                                   VarOrRVar t3);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2,
                                   VarOrRVar t3, VarOrRVar t4);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2,
                                   VarOrRVar t3, VarOrRVar t4, VarOrRVar t5);
    EXPORT Stage &reorder(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                   VarOrRVar w, VarOrRVar t1, VarOrRVar t2,
                                   VarOrRVar t3, VarOrRVar t4, VarOrRVar t5,
                                   VarOrRVar t6);
    EXPORT Stage &rename(VarOrRVar old_name, VarOrRVar new_name);
    EXPORT Stage specialize(Expr condition);

    EXPORT Stage &gpu_threads(VarOrRVar thread_x, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_threads(VarOrRVar thread_x, VarOrRVar thread_y, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_threads(VarOrRVar thread_x, VarOrRVar thread_y, VarOrRVar thread_z, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_single_thread(GPUAPI gpu_api = GPU_Default);

    EXPORT Stage &gpu_blocks(VarOrRVar block_x, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_blocks(VarOrRVar block_x, VarOrRVar block_y, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_blocks(VarOrRVar block_x, VarOrRVar block_y, VarOrRVar block_z, GPUAPI gpu_api = GPU_Default);

    EXPORT Stage &gpu(VarOrRVar block_x, VarOrRVar thread_x, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu(VarOrRVar block_x, VarOrRVar block_y,
                               VarOrRVar thread_x, VarOrRVar thread_y,
                               GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu(VarOrRVar block_x, VarOrRVar block_y, VarOrRVar block_z,
                               VarOrRVar thread_x, VarOrRVar thread_y, VarOrRVar thread_z,
                               GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_tile(VarOrRVar x, Expr x_size, GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_tile(VarOrRVar x, VarOrRVar y, Expr x_size, Expr y_size,
                                    GPUAPI gpu_api = GPU_Default);
    EXPORT Stage &gpu_tile(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                    Expr x_size, Expr y_size, Expr z_size, GPUAPI gpu_api = GPU_Default);

    EXPORT Stage &allow_race_conditions();
    // @}

    // These calls are for legacy compatibility only.
    EXPORT Stage &cuda_threads(VarOrRVar thread_x) {
        return gpu_threads(thread_x);
    }
    EXPORT Stage &cuda_threads(VarOrRVar thread_x, VarOrRVar thread_y) {
        return gpu_threads(thread_x, thread_y);
    }
    EXPORT Stage &cuda_threads(VarOrRVar thread_x, VarOrRVar thread_y, VarOrRVar thread_z) {
        return gpu_threads(thread_x, thread_y, thread_z);
    }

    EXPORT Stage &cuda_blocks(VarOrRVar block_x) {
        return gpu_blocks(block_x);
    }
    EXPORT Stage &cuda_blocks(VarOrRVar block_x, VarOrRVar block_y) {
        return gpu_blocks(block_x, block_y);
    }
    EXPORT Stage &cuda_blocks(VarOrRVar block_x, VarOrRVar block_y, VarOrRVar block_z) {
        return gpu_blocks(block_x, block_y, block_z);
    }

    EXPORT Stage &cuda(VarOrRVar block_x, VarOrRVar thread_x) {
        return gpu(block_x, thread_x);
    }
    EXPORT Stage &cuda(VarOrRVar block_x, VarOrRVar block_y,
                                VarOrRVar thread_x, VarOrRVar thread_y) {
        return gpu(block_x, thread_x, block_y, thread_y);
    }
    EXPORT Stage &cuda(VarOrRVar block_x, VarOrRVar block_y, VarOrRVar block_z,
                                VarOrRVar thread_x, VarOrRVar thread_y, VarOrRVar thread_z) {
        return gpu(block_x, thread_x, block_y, thread_y, block_z, thread_z);
    }
    EXPORT Stage &cuda_tile(VarOrRVar x, int x_size) {
        return gpu_tile(x, x_size);
    }
    EXPORT Stage &cuda_tile(VarOrRVar x, VarOrRVar y, int x_size, int y_size) {
        return gpu_tile(x, y, x_size, y_size);
    }
    EXPORT Stage &cuda_tile(VarOrRVar x, VarOrRVar y, VarOrRVar z,
                                     int x_size, int y_size, int z_size) {
        return gpu_tile(x, y, z, x_size, y_size, z_size);
    }
};

// For backwards compatibility, keep the ScheduleHandle name.
typedef Stage ScheduleHandle;

/** A fragment of front-end syntax of the form f(x, y, z), where x,
 * y, z are Vars. It could be the left-hand side of a function
 * definition, or it could be a call to a function. We don't know
 * until we see how this object gets used.
 */
class FuncRefExpr;

class FuncRefVar {
    Internal::Function func;
    int implicit_placeholder_pos;
    std::vector<std::string> args;
    std::vector<std::string> args_with_implicit_vars(const std::vector<Expr> &e) const;
public:
    FuncRefVar(Internal::Function, const std::vector<Var> &, int placeholder_pos = -1);

    /**  Use this as the left-hand-side of a definition. */
    EXPORT Stage operator=(Expr);

    /** Use this as the left-hand-side of a definition for a Func with
     * multiple outputs. */
    EXPORT Stage operator=(const Tuple &);

    /** Define this function as a sum reduction over the negative of
     * the given expression. The expression should refer to some RDom
     * to sum over. If the function does not already have a pure
     * definition, this sets it to zero.
     */
    EXPORT Stage operator+=(Expr);

{'fraction_non_alphanumeric': 0.08590650336380887, 'fraction_numerical': 0.002415042263239607, 'mean_word_length': 2.5896800825593393, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3157489', 'n_tokens_mistral': 5871, 'n_tokens_neox': 5780, 'n_words': 1678}