Halide
InlineReductions.h
Go to the documentation of this file.
1 #ifndef HALIDE_INLINE_REDUCTIONS_H
2 #define HALIDE_INLINE_REDUCTIONS_H
3 
4 #include <string>
5 
6 #include "Expr.h"
7 #include "RDom.h"
8 #include "Tuple.h"
9 
10 /** \file
11  * Defines some inline reductions: sum, product, minimum, maximum.
12  */
13 namespace Halide {
14 
15 /** An inline reduction. This is suitable for convolution-type
16  * operations - the reduction will be computed in the innermost loop
17  * that it is used in. The argument may contain free or implicit
18  * variables, and must refer to some reduction domain. The free
19  * variables are still free in the return value, but the reduction
20  * domain is captured - the result expression does not refer to a
21  * reduction domain and can be used in a pure function definition.
22  *
23  * An example using \ref sum :
24  *
25  \code
26  Func f, g;
27  Var x;
28  RDom r(0, 10);
29  f(x) = x*x;
30  g(x) = sum(f(x + r));
31  \endcode
32  *
33  * Here g computes some blur of x, but g is still a pure function. The
34  * sum is being computed by an anonymous reduction function that is
35  * scheduled innermost within g.
36  */
37 //@{
38 Expr sum(Expr, const std::string &s = "sum");
39 Expr product(Expr, const std::string &s = "product");
40 Expr maximum(Expr, const std::string &s = "maximum");
41 Expr minimum(Expr, const std::string &s = "minimum");
42 //@}
43 
44 /** Variants of the inline reduction in which the RDom is stated
45  * explicitly. The expression can refer to multiple RDoms, and only
46  * the inner one is captured by the reduction. This allows you to
47  * write expressions like:
48  \code
49  RDom r1(0, 10), r2(0, 10), r3(0, 10);
50  Expr e = minimum(r1, product(r2, sum(r3, r1 + r2 + r3)));
51  \endcode
52 */
53 // @{
54 Expr sum(const RDom &, Expr, const std::string &s = "sum");
55 Expr product(const RDom &, Expr, const std::string &s = "product");
56 Expr maximum(const RDom &, Expr, const std::string &s = "maximum");
57 Expr minimum(const RDom &, Expr, const std::string &s = "minimum");
58 // @}
59 
60 /** Returns an Expr or Tuple representing the coordinates of the point
61  * in the RDom which minimizes or maximizes the expression. The
62  * expression must refer to some RDom. Also returns the extreme value
63  * of the expression as the last element of the tuple. */
64 // @{
65 Tuple argmax(Expr, const std::string &s = "argmax");
66 Tuple argmin(Expr, const std::string &s = "argmin");
67 Tuple argmax(const RDom &, Expr, const std::string &s = "argmax");
68 Tuple argmin(const RDom &, Expr, const std::string &s = "argmin");
69 // @}
70 
71 } // namespace Halide
72 
73 #endif
Halide::sum
Expr sum(Expr, const std::string &s="sum")
An inline reduction.
Tuple.h
Halide::maximum
Expr maximum(Expr, const std::string &s="maximum")
Halide::product
Expr product(Expr, const std::string &s="product")
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::argmin
Tuple argmin(Expr, const std::string &s="argmin")
Expr.h
RDom.h
Halide::argmax
Tuple argmax(Expr, const std::string &s="argmax")
Returns an Expr or Tuple representing the coordinates of the point in the RDom which minimizes or max...
Halide::minimum
Expr minimum(Expr, const std::string &s="minimum")