File: buildmethod_generator.cpp

package info (click to toggle)
halide 14.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 49,124 kB
  • sloc: cpp: 238,722; makefile: 4,303; python: 4,047; java: 1,575; sh: 1,384; pascal: 211; xml: 165; javascript: 43; ansic: 34
file content (46 lines) | stat: -rw-r--r-- 1,384 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
#include "Halide.h"

namespace {

#ifdef HALIDE_ALLOW_GENERATOR_BUILD_METHOD
// This Generator exists solely to test old-style generators (using the
// build() method, rather than generate()/schedule()).
// Do not convert it to new-style until/unless we decide to entirely remove support
// for those Generators.
class BuildMethod : public Halide::Generator<BuildMethod> {
public:
    GeneratorParam<float> compiletime_factor{"compiletime_factor", 1, 0, 100};

    Input<Buffer<float, 3>> input{"input"};
    Input<float> runtime_factor{"runtime_factor", 1.0};

    Func build() {
        Var x, y, c;

        Func g;
        g(x, y, c) = cast<int32_t>(input(x, y, c) * compiletime_factor * runtime_factor);
        return g;
    }
};
#else
// Provide a placeholder here that uses generate(), just to allow this test to
// succeed even if build() is disabled.
class BuildMethod : public Halide::Generator<BuildMethod> {
public:
    GeneratorParam<float> compiletime_factor{"compiletime_factor", 1, 0, 100};

    Input<Buffer<float, 3>> input{"input"};
    Input<float> runtime_factor{"runtime_factor", 1.0};
    Output<Buffer<int32_t, 3>> output{"output"};

    void generate() {
        Var x, y, c;

        output(x, y, c) = cast<int32_t>(input(x, y, c) * compiletime_factor * runtime_factor);
    }
};
#endif

}  // namespace

HALIDE_REGISTER_GENERATOR(BuildMethod, buildmethod)