21template<
typename T =
void>
29 struct DynamicParamType;
32 using not_void_T =
typename std::conditional<std::is_void<T>::value, DynamicParamType *, T>
::type;
34 void check_name()
const {
36 <<
"Param<void*>(\"__user_context\") "
37 <<
"is no longer used to control whether Halide functions take explicit "
38 <<
"user_context arguments. Use set_custom_user_context() when jitting, "
39 <<
"or add Target::UserContext to the Target feature set when compiling ahead of time.";
43 template<
typename OTHER_TYPE>
62 static_assert(
has_static_type,
"Cannot use this ctor without an explicit type.");
65 : param(t, false, 0,
Internal::unique_name(
'p')) {
66 static_assert(!
has_static_type,
"Cannot use this ctor with an explicit type.");
72 explicit Param(
const std::string &n)
73 : param(
type_of<T>(), false, 0, n) {
74 static_assert(
has_static_type,
"Cannot use this ctor without an explicit type.");
78 : param(
type_of<T>(), false, 0, n) {
79 static_assert(
has_static_type,
"Cannot use this ctor without an explicit type.");
83 : param(t, false, 0, n) {
84 static_assert(!
has_static_type,
"Cannot use this ctor with an explicit type.");
91 template<typename T2 = T, typename std::enable_if<!std::is_pointer<T2>::value>
::type * =
nullptr>
94 static_assert(
has_static_type,
"Cannot use this ctor without an explicit type.");
100 Param(
const std::string &n, not_void_T val)
101 : param(
type_of<T>(), false, 0, n) {
103 static_assert(
has_static_type,
"Cannot use this ctor without an explicit type.");
111 static_assert(
has_static_type,
"Cannot use this ctor without an explicit type.");
118 Param(
const std::string &n, not_void_T val,
const Expr &min,
const Expr &max)
119 : param(
type_of<T>(), false, 0, n) {
120 static_assert(
has_static_type,
"Cannot use this ctor without an explicit type.");
127 template<typename OTHER_TYPE, typename T2 = T, typename std::enable_if<std::is_void<T2>::value>
::type * =
nullptr>
129 : param(other.param) {
135 template<typename OTHER_TYPE, typename T2 = T, typename std::enable_if<!std::is_void<T2>::value>
::type * =
nullptr>
137 : param(other.param) {
139 <<
"Param<" <<
type_of<T>() <<
"> cannot be constructed from a Param with type " << other.
type();
143 template<typename OTHER_TYPE, typename T2 = T, typename std::enable_if<std::is_void<T2>::value>
::type * =
nullptr>
151 template<typename OTHER_TYPE, typename T2 = T, typename std::enable_if<!std::is_void<T2>::value>
::type * =
nullptr>
154 <<
"Param<" <<
type_of<T>() <<
"> cannot be copied from a Param with type " << other.
type();
160 const std::string &
name()
const {
166 template<
typename T2 = not_
void_T>
168 return param.
scalar<T2>();
173 template<
typename SOME_TYPE>
175 if constexpr (!std::is_void<T>::value) {
177 <<
"The value " << val <<
" cannot be losslessly converted to type " <<
type();
186 #define HALIDE_HANDLE_TYPE_DISPATCH(CODE, BITS, TYPE) \
187 case halide_type_t(CODE, BITS).as_u32(): \
188 user_assert(Internal::IsRoundtrippable<TYPE>::value(val)) \
189 << "The value " << val << " cannot be losslessly converted to type " << type; \
190 param.set_scalar<TYPE>(Internal::StaticCast<TYPE>::value(val)); \
211 #undef HALIDE_HANDLE_TYPE_DISPATCH
231 if (min.defined() && min.type() != param.
type()) {
238 if (max.defined() && max.type() != param.
type()) {
253 template<
typename SOME_TYPE>
255 if constexpr (!std::is_void<T>::value) {
257 <<
"The value " << val <<
" cannot be losslessly converted to type " <<
type();
266 #define HALIDE_HANDLE_TYPE_DISPATCH(CODE, BITS, TYPE) \
267 case halide_type_t(CODE, BITS).as_u32(): \
268 user_assert(Internal::IsRoundtrippable<TYPE>::value(val)) \
269 << "The value " << val << " cannot be losslessly converted to type " << type; \
270 param.set_estimate(Expr(Internal::StaticCast<TYPE>::value(val))); \
291 #undef HALIDE_HANDLE_TYPE_DISPATCH
Defines a type used for expressing the type signature of a generated halide pipeline.
#define internal_assert(c)
Defines the internal representation of a halide ExternFuncArgument.
@ halide_type_float
IEEE floating point numbers.
@ halide_type_handle
opaque pointer type (void *)
@ halide_type_int
signed integers
@ halide_type_uint
unsigned integers
Subtypes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
#define HALIDE_HANDLE_TYPE_DISPATCH(CODE, BITS, TYPE)
#define HALIDE_NO_USER_CODE_INLINE
A scalar parameter to a halide pipeline.
const std::string & name() const
Get the name of this parameter.
void set_range(const Expr &min, const Expr &max)
Get or set the possible range of this parameter.
HALIDE_NO_USER_CODE_INLINE void set_estimate(const SOME_TYPE &val)
Param(const Param< OTHER_TYPE > &other)
Construct a Param<void> from any other Param.
HALIDE_NO_USER_CODE_INLINE void set(const SOME_TYPE &val)
Set the current value of this parameter.
void set_min_value(Expr min)
Param(not_void_T val)
Construct a scalar parameter of type T an initial value of 'val'.
const Parameter & parameter() const
void set_max_value(Expr max)
Type type() const
Get the halide type of the Param.
Param(Type t, const std::string &n)
static Type static_type()
Get the Halide type of T.
static constexpr bool has_static_type
True if the Halide type is not void (or const void).
Param(not_void_T val, const Expr &min, const Expr &max)
Construct a scalar parameter of type T with an initial value of 'val' and a given min and max.
Param()
Construct a scalar parameter of type T with a unique auto-generated name.
Param(const std::string &n)
Construct a scalar parameter of type T with the given name.
Param(const std::string &n, not_void_T val, const Expr &min, const Expr &max)
Construct a scalar parameter of type T with the given name and an initial value of 'val' and a given ...
Param< T > & operator=(const Param< OTHER_TYPE > &other)
Copy a Param<void> from any other Param.
HALIDE_NO_USER_CODE_INLINE T2 get() const
Get the current value of this parameter.
Param(const std::string &n, not_void_T val)
Construct a scalar parameter of type T with the given name and an initial value of 'val'.
A reference-counted handle to a parameter to a halide pipeline.
void set_max_value(const Expr &e)
const std::string & name() const
Get the name of this parameter.
HALIDE_NO_USER_CODE_INLINE T scalar() const
If the parameter is a scalar parameter, get its currently bound value.
void set_min_value(const Expr &e)
Get and set constraints for scalar parameters.
HALIDE_NO_USER_CODE_INLINE void set_scalar(T val)
If the parameter is a scalar parameter, set its current value.
void set_estimate(Expr e)
Type type() const
Get the type of this parameter.
ArgumentEstimates get_argument_estimates() const
Get the ArgumentEstimates appropriate for this Parameter.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Type type_of()
Construct the halide equivalent of a C type.
Type Handle(int lanes=1, const halide_handle_cplusplus_type *handle_type=nullptr)
Construct a handle type.
Expr user_context_value()
Returns an Expr corresponding to the user context passed to the function (if any).
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
signed __INT32_TYPE__ int32_t
unsigned __INT8_TYPE__ uint8_t
unsigned __INT16_TYPE__ uint16_t
unsigned __INT32_TYPE__ uint32_t
signed __INT16_TYPE__ int16_t
signed __INT8_TYPE__ int8_t
A struct representing an argument to a halide-generated function.
A fragment of Halide syntax.
An argument to an extern-defined Func.
static Expr make(Type t, Expr v)
static Expr make(Type type, const std::string &name)
Types in the halide type system.
A runtime tag for a type in the halide type system.