-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvert_generator.cpp
More file actions
36 lines (28 loc) · 1.3 KB
/
invert_generator.cpp
File metadata and controls
36 lines (28 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "Halide.h"
namespace {
using namespace Halide;
class InvertGenerator : public Halide::Generator<InvertGenerator> {
public:
// We declare a three-dimensional Inputs to the Halide pipeline as public
// member variables. They'll appear in the signature of our generated
// function in the same order as we declare them.
// The first two dimensions will be x, and y, and the third dimension will be
// the color channel.
Input <Buffer<uint8_t, 3>> input{"input"};
Output <Buffer<uint8_t, 3>> output{"output"};
// Typically you declare your Vars at this scope as well, so that
// they can be used in any helper methods you add later.
Var x{"x"}, y{"y"}, c{"c"}; // "c" is a chanel (red, green, blue)
void generate() {
Func invert("invert");
invert(x, y, c) = 255 - input(x, y, c);
output(x, y, c) = invert(x, y, c);
output.vectorize(x, 16).parallel(y);
}
};
} // namespace
// We compile this file along with tools/GenGen.cpp. That file defines
// an "int main(...)" that provides the command-line interface to use
// your generator class. We need to tell that code about our
// generator. We do this like so:
HALIDE_REGISTER_GENERATOR(InvertGenerator, invert)