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>
48 static constexpr bool has_static_type = !std::is_void<T>::value;
52 static Type static_type() {
62 static_assert(has_static_type,
"Cannot use this ctor without an explicit type.");
64 explicit Param(
Type t)
66 static_assert(!has_static_type,
"Cannot use this ctor with an explicit type.");
72 explicit Param(
const std::string &n)
74 static_assert(has_static_type,
"Cannot use this ctor without an explicit type.");
77 explicit Param(
const char *n)
79 static_assert(has_static_type,
"Cannot use this ctor without an explicit type.");
82 Param(
Type t,
const std::string &n)
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>
92 explicit Param(not_void_T val)
94 static_assert(has_static_type,
"Cannot use this ctor without an explicit type.");
100 Param(
const std::string &n, not_void_T val)
103 static_assert(has_static_type,
"Cannot use this ctor without an explicit type.");
104 set<not_void_T>(val);
111 static_assert(has_static_type,
"Cannot use this ctor without an explicit type.");
113 set<not_void_T>(val);
118 Param(
const std::string &n, not_void_T val,
const Expr &
min,
const Expr &
max)
120 static_assert(has_static_type,
"Cannot use this ctor without an explicit type.");
123 set<not_void_T>(val);
127 template<typename OTHER_TYPE, typename T2 = T, typename std::enable_if<std::is_void<T2>::value>::type * =
nullptr>
128 Param(
const Param<OTHER_TYPE> &other)
129 : param(other.param) {
135 template<typename OTHER_TYPE, typename T2 = T, typename std::enable_if<!std::is_void<T2>::value>::type * =
nullptr>
136 Param(
const Param<OTHER_TYPE> &other)
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>
144 Param<T> &operator=(
const Param<OTHER_TYPE> &other) {
151 template<typename OTHER_TYPE, typename T2 = T, typename std::enable_if<!std::is_void<T2>::value>::type * =
nullptr>
152 Param<T> &operator=(
const Param<OTHER_TYPE> &other) {
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();
178 param.set_scalar<T>(val);
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)); \
193 const Type type = param.type();
208 internal_error <<
"Unsupported type in Param::set<" << type <<
">\n";
211 #undef HALIDE_HANDLE_TYPE_DISPATCH
231 if (
min.defined() &&
min.type() != param.type()) {
234 param.set_min_value(
min);
238 if (
max.defined() &&
max.type() != param.type()) {
241 param.set_max_value(
max);
244 Expr min_value()
const {
245 return param.min_value();
248 Expr max_value()
const {
249 return param.max_value();
253 template<
typename SOME_TYPE>
255 if constexpr (!std::is_void<T>::value) {
257 <<
"The value " << val <<
" cannot be losslessly converted to type " << type();
258 param.set_estimate(
Expr(val));
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))); \
273 const Type type = param.type();
288 internal_error <<
"Unsupported type in Param::set<" << type <<
">\n";
291 #undef HALIDE_HANDLE_TYPE_DISPATCH
299 operator Expr()
const {
314 param.get_argument_estimates());
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 reference-counted handle to a parameter to a halide pipeline.
const std::string & name() const
Get the name of this parameter.
std::string unique_name(char prefix)
Generate a unique name starting with the given prefix.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Type type_of()
Construct the halide equivalent of a C type.
Expr min(const FuncRef &a, const FuncRef &b)
Explicit overloads of min and max for FuncRef.
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).
Expr max(const FuncRef &a, const FuncRef &b)
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 constexpr bool value(const FROM &from)
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.