Loading...
Searching...
No Matches
Argument.h
Go to the documentation of this file.
#ifndef HALIDE_ARGUMENT_H
#define HALIDE_ARGUMENT_H
/** \file
* Defines a type used for expressing the type signature of a
* generated halide pipeline
*/
#include "Expr.h"
#include "Type.h"
#include "runtime/HalideRuntime.h"
namespace Halide {
template<typename T, int Dims>
class Buffer;
struct ArgumentEstimates {
/** If this is a scalar argument, then these are its default, min, max, and estimated values.
* For buffer arguments, all should be undefined. */
Expr scalar_def, scalar_min, scalar_max, scalar_estimate;
/** If this is a buffer argument, these are the estimated min and
* extent for each dimension. If there are no estimates,
* buffer_estimates.size() can be zero; otherwise, it must always
* equal the dimensions */
Region buffer_estimates;
bool operator==(const ArgumentEstimates &rhs) const;
};
/**
* A struct representing an argument to a halide-generated
* function. Used for specifying the function signature of
* generated code.
*/
struct Argument {
/** The name of the argument */
std::string name;
/** An argument is either a primitive type (for parameters), or a
* buffer pointer.
*
* If kind == InputScalar, then type fully encodes the expected type
* of the scalar argument.
*
* If kind == InputBuffer|OutputBuffer, then type.bytes() should be used
* to determine* elem_size of the buffer; additionally, type.code *should*
* reflect the expected interpretation of the buffer data (e.g. float vs int),
* but there is no runtime enforcement of this at present.
*/
enum Kind {
InputScalar = halide_argument_kind_input_scalar,
InputBuffer = halide_argument_kind_input_buffer,
OutputBuffer = halide_argument_kind_output_buffer
};
Kind kind = InputScalar;
/** If kind == InputBuffer|OutputBuffer, this is the dimensionality of the buffer.
* If kind == InputScalar, this value is ignored (and should always be set to zero) */
uint8_t dimensions = 0;
/** If this is a scalar parameter, then this is its type.
*
* If this is a buffer parameter, this this is the type of its
* elements.
*
* Note that type.lanes should always be 1 here. */
Type type;
/* The estimates (if any) and default/min/max values (if any) for this Argument. */
ArgumentEstimates argument_estimates;
Argument() = default;
Argument(const std::string &_name, Kind _kind, const Type &_type, int _dimensions,
const ArgumentEstimates &argument_estimates);
// Not explicit, so that you can put Buffer in an argument list,
// to indicate that it shouldn't be baked into the object file,
// but instead received as an argument at runtime
template<typename T, int Dims>
Argument(Buffer<T, Dims> im)
: name(im.name()),
kind(InputBuffer),
dimensions(im.dimensions()),
type(im.type()) {
}
bool is_buffer() const {
return kind == InputBuffer || kind == OutputBuffer;
}
bool is_scalar() const {
return kind == InputScalar;
}
bool is_input() const {
return kind == InputScalar || kind == InputBuffer;
}
bool is_output() const {
return kind == OutputBuffer;
}
bool operator==(const Argument &rhs) const {
return name == rhs.name &&
kind == rhs.kind &&
dimensions == rhs.dimensions &&
type == rhs.type &&
argument_estimates == rhs.argument_estimates;
}
};
} // namespace Halide
#endif
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt).
HalideRuntime.h
This file declares the routines used by Halide internally in its runtime.
halide_argument_kind_output_buffer
@ halide_argument_kind_output_buffer
Definition HalideRuntime.h:1766
halide_argument_kind_input_scalar
@ halide_argument_kind_input_scalar
Definition HalideRuntime.h:1764
halide_argument_kind_input_buffer
@ halide_argument_kind_input_buffer
Definition HalideRuntime.h:1765
Type.h
Defines halide types.
Halide::Buffer
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
Definition Buffer.h:122
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
Halide::Region
std::vector< Range > Region
A multi-dimensional box.
Definition Expr.h:350
uint8_t
unsigned __INT8_TYPE__ uint8_t
Definition runtime_internal.h:29
Halide::ArgumentEstimates
Definition Argument.h:18
Halide::ArgumentEstimates::buffer_estimates
Region buffer_estimates
If this is a buffer argument, these are the estimated min and extent for each dimension.
Definition Argument.h:27
Halide::ArgumentEstimates::operator==
bool operator==(const ArgumentEstimates &rhs) const
Halide::ArgumentEstimates::scalar_min
Expr scalar_min
Definition Argument.h:21
Halide::ArgumentEstimates::scalar_def
Expr scalar_def
If this is a scalar argument, then these are its default, min, max, and estimated values.
Definition Argument.h:21
Halide::ArgumentEstimates::scalar_estimate
Expr scalar_estimate
Definition Argument.h:21
Halide::ArgumentEstimates::scalar_max
Expr scalar_max
Definition Argument.h:21
Halide::Argument::is_input
bool is_input() const
Definition Argument.h:96
Halide::Argument::is_buffer
bool is_buffer() const
Definition Argument.h:89
Halide::Argument::is_scalar
bool is_scalar() const
Definition Argument.h:92
Halide::Argument::Argument
Argument(Buffer< T, Dims > im)
Definition Argument.h:82
Halide::Argument::Argument
Argument(const std::string &_name, Kind _kind, const Type &_type, int _dimensions, const ArgumentEstimates &argument_estimates)
Halide::Argument::kind
Kind kind
Definition Argument.h:57
Halide::Argument::Argument
Argument()=default
Halide::Argument::is_output
bool is_output() const
Definition Argument.h:99
Halide::Argument::name
std::string name
The name of the argument.
Definition Argument.h:39
Halide::Argument::type
Type type
If this is a scalar parameter, then this is its type.
Definition Argument.h:69
Halide::Argument::operator==
bool operator==(const Argument &rhs) const
Definition Argument.h:103
Halide::Argument::Kind
Kind
An argument is either a primitive type (for parameters), or a buffer pointer.
Definition Argument.h:52
Halide::Argument::InputBuffer
@ InputBuffer
Definition Argument.h:54
Halide::Argument::InputScalar
@ InputScalar
Definition Argument.h:53
Halide::Argument::OutputBuffer
@ OutputBuffer
Definition Argument.h:55
Halide::Argument::dimensions
uint8_t dimensions
If kind == InputBuffer|OutputBuffer, this is the dimensionality of the buffer.
Definition Argument.h:61
Halide::Argument::argument_estimates
ArgumentEstimates argument_estimates
Definition Argument.h:72
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::Type
Types in the halide type system.
Definition Type.h:283