<commit_before>#ifndef HALIDE_PARAM_H
#define HALIDE_PARAM_H

/** \file
 * 
 * Classes for declaring scalar and image parameters to halide pipelines
 */

#include "IR.h"
#include "Var.h"
#include <sstream>
#include <vector>

namespace Halide {

/** A scalar parameter to a halide pipeline. If you're jitting, this
 * should be bound to an actual value of type T using the set method
 * before you realize the function uses this. If you're statically
 * compiling, this param should appear in the argument list. */
template<typename T>
class Param {
    /** A reference-counted handle on the internal parameter object */
    Internal::Parameter param;
public:
    /** Construct a scalar parameter of type T with a unique
     * auto-generated name */
    Param() : param(type_of<T>(), false) {}

    /** Construct a scalar parameter of type T with the given name */
    Param(const std::string &n) : param(type_of<T>(), false, n) {}

    /** Get the name of this parameter */
    const std::string &name() const {
        return param.name();
    }

    /** Get the current value of this parameter. Only meaningful when jitting. */
    T get() const {
        return param.get_scalar<T>();
    }

    /** Set the current value of this parameter. Only meaningful when jitting */
    void set(T val) {
        param.set_scalar<T>(val);
    }

    /** Get the halide type of T */
    Type type() const {
        return type_of<T>();
    }

    /** You can use this parameter as an expression in a halide
     * function definition */
    operator Expr() const {
        return new Internal::Variable(type_of<T>(), name(), param);
    }

    /** Construct the appropriate argument matching this parameter,
     * for the purpose of generating the right type signature when
     * statically compiling halide pipelines. */
    operator Argument() const {
        return Argument(name(), false, type());
    }
};

/** An Image parameter to a halide pipeline. E.g., the input image. */
class ImageParam {
    /** A reference-counted handle on the internal parameter object */
    Internal::Parameter param;

    /** The dimensionality of this image. We need to know in order to
     * inject the right number of implicit vars when calling
     * operator() */
    int dims;
public:

    /** Construct a NULL image parameter handle. */
    ImageParam() {}

    /** Construct an image parameter of the given type and
     * dimensionality, with an auto-generated unique name. */
    ImageParam(Type t, int d) : param(t, true), dims(d) {}

    /** Construct an image parameter of the given type and
     * dimensionality, with the given name */
    ImageParam(Type t, int d, const std::string &n) : param(t, true, n), dims(d) {}

    /** Get the name of this ImageParam */
    const std::string &name() const {
        return param.name();
    }

    /** Get the type of the image data this ImageParam refers to */
    Type type() const {
        return param.type();
    }

    /** Bind a buffer or image to this ImageParam. Only relevant for jitting */
    void set(Buffer b) {
        if (b.defined()) assert(b.type() == type() && "Setting buffer of incorrect type");
        param.set_buffer(b);
    }
    
    /** Get the buffer bound to this ImageParam. Only relevant for jitting */
    Buffer get() const {
        return param.get_buffer();
    }

    /** Is this handle non-NULL */
    bool defined() const {
        return param.defined();
    }

    /** Get an expression representing the extent of this image
     * parameter in the given dimension */
    Expr extent(int x) const {
        std::ostringstream s;
        s << name() << ".extent." << x;
        return new Internal::Variable(Int(32), s.str(), param);
    }

    /** Set the extent in a given dimension to equal the given
     * expression. Images passed in that fail this check will generate
     * a runtime error. Returns a reference to the ImageParam so that
     * these calls may be chained.  
     * 
     * This may help the compiler generate better
     * code. E.g:
     \code
     im.set_extent(0, 100);
     \endcode
     * tells the compiler that dimension zero must be of extent 100,
     * which may result in simplification of boundary checks. The
     * value can be an arbitrary expression:
     \code
     im.set_extent(0, im.extent(1));
     \endcode
     * declares that im is a square image (of unknown size), whereas:
     \code
     im.set_extent(0, (im.extent(0)/32)*32);
     \endcode
     * tells the compiler that the extent is a multiple of 32. */
    ImageParam &set_extent(int dim, Expr extent) {<commit_msg>Added access to the stride of image params<commit_after>#ifndef HALIDE_PARAM_H
#define HALIDE_PARAM_H

/** \file
 * 
 * Classes for declaring scalar and image parameters to halide pipelines
 */

#include "IR.h"
#include "Var.h"
#include <sstream>
#include <vector>

namespace Halide {

/** A scalar parameter to a halide pipeline. If you're jitting, this
 * should be bound to an actual value of type T using the set method
 * before you realize the function uses this. If you're statically
 * compiling, this param should appear in the argument list. */
template<typename T>
class Param {
    /** A reference-counted handle on the internal parameter object */
    Internal::Parameter param;
public:
    /** Construct a scalar parameter of type T with a unique
     * auto-generated name */
    Param() : param(type_of<T>(), false) {}

    /** Construct a scalar parameter of type T with the given name */
    Param(const std::string &n) : param(type_of<T>(), false, n) {}

    /** Get the name of this parameter */
    const std::string &name() const {
        return param.name();
    }

    /** Get the current value of this parameter. Only meaningful when jitting. */
    T get() const {
        return param.get_scalar<T>();
    }

    /** Set the current value of this parameter. Only meaningful when jitting */
    void set(T val) {
        param.set_scalar<T>(val);
    }

    /** Get the halide type of T */
    Type type() const {
        return type_of<T>();
    }

    /** You can use this parameter as an expression in a halide
     * function definition */
    operator Expr() const {
        return new Internal::Variable(type_of<T>(), name(), param);
    }

    /** Construct the appropriate argument matching this parameter,
     * for the purpose of generating the right type signature when
     * statically compiling halide pipelines. */
    operator Argument() const {
        return Argument(name(), false, type());
    }
};

/** An Image parameter to a halide pipeline. E.g., the input image. */
class ImageParam {
    /** A reference-counted handle on the internal parameter object */
    Internal::Parameter param;

    /** The dimensionality of this image. We need to know in order to
     * inject the right number of implicit vars when calling
     * operator() */
    int dims;
public:

    /** Construct a NULL image parameter handle. */
    ImageParam() {}

    /** Construct an image parameter of the given type and
     * dimensionality, with an auto-generated unique name. */
    ImageParam(Type t, int d) : param(t, true), dims(d) {}

    /** Construct an image parameter of the given type and
     * dimensionality, with the given name */
    ImageParam(Type t, int d, const std::string &n) : param(t, true, n), dims(d) {}

    /** Get the name of this ImageParam */
    const std::string &name() const {
        return param.name();
    }

    /** Get the type of the image data this ImageParam refers to */
    Type type() const {
        return param.type();
    }

    /** Bind a buffer or image to this ImageParam. Only relevant for jitting */
    void set(Buffer b) {
        if (b.defined()) assert(b.type() == type() && "Setting buffer of incorrect type");
        param.set_buffer(b);
    }
    
    /** Get the buffer bound to this ImageParam. Only relevant for jitting */
    Buffer get() const {
        return param.get_buffer();
    }

    /** Is this handle non-NULL */
    bool defined() const {
        return param.defined();
    }

    /** Get an expression representing the extent of this image
     * parameter in the given dimension */
    Expr extent(int x) const {
        std::ostringstream s;
        s << name() << ".extent." << x;
        return new Internal::Variable(Int(32), s.str(), param);
    }

    /** Get an expression representing the stride of this image in the
     * given dimension */
    Expr stride(int x) const {
        std::ostringstream s;
        s << name() << ".stride." << x;
        return new Internal::Variable(Int(32), s.str(), param);        
    }

    /** Set the extent in a given dimension to equal the given
     * expression. Images passed in that fail this check will generate
     * a runtime error. Returns a reference to the ImageParam so that
     * these calls may be chained.  
     * 
     * This may help the compiler generate better
     * code. E.g:
     \code
     im.set_extent(0, 100);
     \endcode
     * tells the compiler that dimension zero must be of extent 100,
     * which may result in simplification of boundary checks. The
     * value can be an arbitrary expression:
     \code
     im.set_extent(0, im.extent(1));
     \endcode
     * declares that im is a square image (of unknown size), whereas:
     \code
     im.set_extent(0, (im.extent(0)/32)*32);
     \endcode
     * tells the compiler that the extent is a multiple of 32. */
    ImageParam &set_extent(int dim, Expr extent) {
{'fraction_non_alphanumeric': 0.10634720470786045, 'fraction_numerical': 0.004203446826397646, 'mean_word_length': 2.5899660505469635, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 21, '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': '1404549', 'n_tokens_mistral': 2661, 'n_tokens_neox': 2579, 'n_words': 1113}