Halide
Argument.h
Go to the documentation of this file.
1 #ifndef HALIDE_ARGUMENT_H
2 #define HALIDE_ARGUMENT_H
3 
4 /** \file
5  * Defines a type used for expressing the type signature of a
6  * generated halide pipeline
7  */
8 
9 #include "Expr.h"
10 #include "Type.h"
11 #include "runtime/HalideRuntime.h"
12 
13 namespace Halide {
14 
15 template<typename T>
16 class Buffer;
17 
19  /** If this is a scalar argument, then these are its default, min, max, and estimated values.
20  * For buffer arguments, all should be undefined. */
22 
23  /** If this is a buffer argument, these are the estimated min and
24  * extent for each dimension. If there are no estimates,
25  * buffer_estimates.size() can be zero; otherwise, it must always
26  * equal the dimensions */
28 
29  bool operator==(const ArgumentEstimates &rhs) const;
30 };
31 
32 /**
33  * A struct representing an argument to a halide-generated
34  * function. Used for specifying the function signature of
35  * generated code.
36  */
37 struct Argument {
38  /** The name of the argument */
39  std::string name;
40 
41  /** An argument is either a primitive type (for parameters), or a
42  * buffer pointer.
43  *
44  * If kind == InputScalar, then type fully encodes the expected type
45  * of the scalar argument.
46  *
47  * If kind == InputBuffer|OutputBuffer, then type.bytes() should be used
48  * to determine* elem_size of the buffer; additionally, type.code *should*
49  * reflect the expected interpretation of the buffer data (e.g. float vs int),
50  * but there is no runtime enforcement of this at present.
51  */
52  enum Kind {
56  };
58 
59  /** If kind == InputBuffer|OutputBuffer, this is the dimensionality of the buffer.
60  * If kind == InputScalar, this value is ignored (and should always be set to zero) */
62 
63  /** If this is a scalar parameter, then this is its type.
64  *
65  * If this is a buffer parameter, this this is the type of its
66  * elements.
67  *
68  * Note that type.lanes should always be 1 here. */
70 
71  /* The estimates (if any) and default/min/max values (if any) for this Argument. */
73 
74  Argument() = default;
75  Argument(const std::string &_name, Kind _kind, const Type &_type, int _dimensions,
77 
78  // Not explicit, so that you can put Buffer in an argument list,
79  // to indicate that it shouldn't be baked into the object file,
80  // but instead received as an argument at runtime
81  template<typename T>
83  : name(im.name()),
85  dimensions(im.dimensions()),
86  type(im.type()) {
87  }
88 
89  bool is_buffer() const {
90  return kind == InputBuffer || kind == OutputBuffer;
91  }
92  bool is_scalar() const {
93  return kind == InputScalar;
94  }
95 
96  bool is_input() const {
97  return kind == InputScalar || kind == InputBuffer;
98  }
99  bool is_output() const {
100  return kind == OutputBuffer;
101  }
102 
103  bool operator==(const Argument &rhs) const {
104  return name == rhs.name &&
105  kind == rhs.kind &&
106  dimensions == rhs.dimensions &&
107  type == rhs.type &&
109  }
110 };
111 
112 } // namespace Halide
113 
114 #endif
Halide::Region
std::vector< Range > Region
A multi-dimensional box.
Definition: Expr.h:343
Halide::Argument::InputScalar
@ InputScalar
Definition: Argument.h:53
Halide::ArgumentEstimates::scalar_min
Expr scalar_min
Definition: Argument.h:21
halide_argument_kind_output_buffer
@ halide_argument_kind_output_buffer
Definition: HalideRuntime.h:1582
Halide::ArgumentEstimates::scalar_max
Expr scalar_max
Definition: Argument.h:21
Halide::Argument::is_output
bool is_output() const
Definition: Argument.h:99
uint8_t
unsigned __INT8_TYPE__ uint8_t
Definition: runtime_internal.h:25
Halide::Argument::InputBuffer
@ InputBuffer
Definition: Argument.h:54
Halide::Argument
A struct representing an argument to a halide-generated function.
Definition: Argument.h:37
Halide::Argument::operator==
bool operator==(const Argument &rhs) const
Definition: Argument.h:103
Halide::Type
Types in the halide type system.
Definition: Type.h:269
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::Argument::kind
Kind kind
Definition: Argument.h:57
Halide::Buffer
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
Definition: Argument.h:16
Halide::Argument::Kind
Kind
An argument is either a primitive type (for parameters), or a buffer pointer.
Definition: Argument.h:52
Halide::Argument::OutputBuffer
@ OutputBuffer
Definition: Argument.h:55
halide_argument_kind_input_scalar
@ halide_argument_kind_input_scalar
Definition: HalideRuntime.h:1580
Halide::Argument::name
std::string name
The name of the argument.
Definition: Argument.h:39
Halide::Argument::Argument
Argument(Buffer< T > im)
Definition: Argument.h:82
halide_argument_kind_input_buffer
@ halide_argument_kind_input_buffer
Definition: HalideRuntime.h:1581
Halide::ArgumentEstimates::scalar_estimate
Expr scalar_estimate
Definition: Argument.h:21
Type.h
Expr.h
Halide::Argument::type
Type type
If this is a scalar parameter, then this is its type.
Definition: Argument.h:69
HalideRuntime.h
Halide::Argument::dimensions
uint8_t dimensions
If kind == InputBuffer|OutputBuffer, this is the dimensionality of the buffer.
Definition: Argument.h:61
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::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
Halide::Argument::is_scalar
bool is_scalar() const
Definition: Argument.h:92
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::Argument::is_buffer
bool is_buffer() const
Definition: Argument.h:89
Halide::Argument::Argument
Argument()=default
Halide::ArgumentEstimates::operator==
bool operator==(const ArgumentEstimates &rhs) const
Halide::Argument::is_input
bool is_input() const
Definition: Argument.h:96
Halide::ArgumentEstimates
Definition: Argument.h:18
Halide::Argument::argument_estimates
ArgumentEstimates argument_estimates
Definition: Argument.h:72