Halide 22.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 */
13 namespace Halide {
14
15 class 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//@{
40 Expr sum(Expr, const std::string &s = "sum");
41 Expr saturating_sum(Expr, const std::string &s = "saturating_sum");
42 Expr product(Expr, const std::string &s = "product");
43 Expr maximum(Expr, const std::string &s = "maximum");
44 Expr 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// @{
57 Expr sum(const RDom &, Expr, const std::string &s = "sum");
58 Expr saturating_sum(const RDom &r, Expr e, const std::string &s = "saturating_sum");
59 Expr product(const RDom &, Expr, const std::string &s = "product");
60 Expr maximum(const RDom &, Expr, const std::string &s = "maximum");
61 Expr 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// @{
69 Tuple argmax(Expr, const std::string &s = "argmax");
70 Tuple argmin(Expr, const std::string &s = "argmin");
71 Tuple argmax(const RDom &, Expr, const std::string &s = "argmax");
72 Tuple 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//@{
81 Expr sum(Expr, const Func &);
82 Expr saturating_sum(Expr, const Func &);
83 Expr product(Expr, const Func &);
84 Expr maximum(Expr, const Func &);
85 Expr minimum(Expr, const Func &);
86 Expr sum(const RDom &, Expr, const Func &);
87 Expr saturating_sum(const RDom &r, Expr e, const Func &);
88 Expr product(const RDom &, Expr, const Func &);
89 Expr maximum(const RDom &, Expr, const Func &);
90 Expr minimum(const RDom &, Expr, const Func &);
91 Tuple argmax(Expr, const Func &);
92 Tuple argmin(Expr, const Func &);
93 Tuple argmax(const RDom &, Expr, const Func &);
94 Tuple argmin(const RDom &, Expr, const Func &);
95//@}
96
97} // namespace Halide
98
99#endif
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
RDom.h
Defines the front-end syntax for reduction domains and reduction variables.
Tuple.h
Defines Tuple - the front-end handle on small arrays of expressions.
Halide::Func
A halide function.
Definition Func.h:714
Halide::RDom
A multi-dimensional domain over which to iterate.
Definition RDom.h:193
Halide::Tuple
Create a small array of Exprs for defining and calling functions with multiple outputs.
Definition Tuple.h:18
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
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::argmin
Tuple argmin(Expr, const std::string &s="argmin")
Halide::maximum
Expr maximum(Expr, const std::string &s="maximum")
Halide::sum
Expr sum(Expr, const std::string &s="sum")
An inline reduction.
Halide::product
Expr product(Expr, const std::string &s="product")
Halide::saturating_sum
Expr saturating_sum(Expr, const std::string &s="saturating_sum")
Halide::minimum
Expr minimum(Expr, const std::string &s="minimum")
Halide::cast
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258