Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
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 */
13namespace Halide {
14
15class Func;
16
17/** An inline reduction. This is suitable for convolution-type
18 * operations - the reduction will be computed in the innermost loop
19 * that it is used in. The argument may contain free or implicit
20 * variables, and must refer to some reduction domain. The free
21 * variables are still free in the return value, but the reduction
22 * domain is captured - the result expression does not refer to a
23 * reduction domain and can be used in a pure function definition.
24 *
25 * An example using \ref sum :
26 *
27 \code
28 Func f, g;
29 Var x;
30 RDom r(0, 10);
31 f(x) = x*x;
32 g(x) = sum(f(x + r));
33 \endcode
34 *
35 * Here g computes some blur of x, but g is still a pure function. The
36 * sum is being computed by an anonymous reduction function that is
37 * scheduled innermost within g.
38 */
39//@{
40Expr sum(Expr, const std::string &s = "sum");
41Expr saturating_sum(Expr, const std::string &s = "saturating_sum");
42Expr product(Expr, const std::string &s = "product");
43Expr maximum(Expr, const std::string &s = "maximum");
44Expr minimum(Expr, const std::string &s = "minimum");
45//@}
46
47/** Variants of the inline reduction in which the RDom is stated
48 * explicitly. The expression can refer to multiple RDoms, and only
49 * the inner one is captured by the reduction. This allows you to
50 * write expressions like:
51 \code
52 RDom r1(0, 10), r2(0, 10), r3(0, 10);
53 Expr e = minimum(r1, product(r2, sum(r3, r1 + r2 + r3)));
54 \endcode
55*/
56// @{
57Expr sum(const RDom &, Expr, const std::string &s = "sum");
58Expr saturating_sum(const RDom &r, Expr e, const std::string &s = "saturating_sum");
59Expr product(const RDom &, Expr, const std::string &s = "product");
60Expr maximum(const RDom &, Expr, const std::string &s = "maximum");
61Expr minimum(const RDom &, Expr, const std::string &s = "minimum");
62// @}
63
64/** Returns an Expr or Tuple representing the coordinates of the point
65 * in the RDom which minimizes or maximizes the expression. The
66 * expression must refer to some RDom. Also returns the extreme value
67 * of the expression as the last element of the tuple. */
68// @{
69Tuple argmax(Expr, const std::string &s = "argmax");
70Tuple argmin(Expr, const std::string &s = "argmin");
71Tuple argmax(const RDom &, Expr, const std::string &s = "argmax");
72Tuple argmin(const RDom &, Expr, const std::string &s = "argmin");
73// @}
74
75/** Inline reductions create an anonymous helper Func to do the
76 * work. The variants below instead take a named Func object to use,
77 * so that it is no longer anonymous and can be scheduled
78 * (e.g. unrolled across the reduction domain). The Func passed must
79 * not have any existing definition. */
80//@{
81Expr sum(Expr, const Func &);
86Expr sum(const RDom &, Expr, const Func &);
87Expr saturating_sum(const RDom &r, Expr e, const Func &);
88Expr product(const RDom &, Expr, const Func &);
89Expr maximum(const RDom &, Expr, const Func &);
90Expr minimum(const RDom &, Expr, const Func &);
93Tuple argmax(const RDom &, Expr, const Func &);
94Tuple argmin(const RDom &, Expr, const Func &);
95//@}
96
97} // namespace Halide
98
99#endif
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Defines the front-end syntax for reduction domains and reduction variables.
Defines Tuple - the front-end handle on small arrays of expressions.
A halide function.
Definition Func.h:700
A multi-dimensional domain over which to iterate.
Definition RDom.h:193
Create a small array of Exprs for defining and calling functions with multiple outputs.
Definition Tuple.h:18
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
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...
Tuple argmin(Expr, const std::string &s="argmin")
Expr maximum(Expr, const std::string &s="maximum")
Expr sum(Expr, const std::string &s="sum")
An inline reduction.
Expr product(Expr, const std::string &s="product")
Expr saturating_sum(Expr, const std::string &s="saturating_sum")
Expr minimum(Expr, const std::string &s="minimum")
A fragment of Halide syntax.
Definition Expr.h:258