Halide 22.0.0 Halide compiler and libraries

Realization.h
Go to the documentation of this file.
1#ifndef HALIDE_REALIZATION_H
2#define HALIDE_REALIZATION_H
3
4#include <cstdint>
5#include <vector>
6
7#include "Buffer.h"
8#include "Util.h" // for all_are_convertible
9
10/** \file
11 *
12 * Defines Realization - a vector of Buffer for use in pipelines with multiple outputs.
13 */
14
15namespace Halide {
16
17/** A Realization is a vector of references to existing Buffer objects.
18 * A pipeline with multiple outputs realize to a Realization. */
19 class Realization {
20private:
21 std::vector<Buffer<void>> images;
22
23public:
24 /** The number of images in the Realization. */
25 size_t size() const;
26
27 /** Get a const reference to one of the images. */
28 const Buffer<void> &operator[](size_t x) const;
29
30 /** Get a reference to one of the images. */
31 Buffer<void> &operator[](size_t x);
32
33 /** Single-element realizations are implicitly castable to Buffers. */
34 template<typename T, int Dims>
35 operator Buffer<T, Dims>() const {
36 user_assert(images.size() == 1) << "Cannot cast Realization with "
37 << images.size() << " elements to a Buffer";
38 return images[0];
39 }
40
41 /** Construct a Realization that acts as a reference to a single
42 * existing Buffer. The element type of the Buffer may not be
43 * const. */
44 // @{
45 explicit Realization(const Buffer<void> &e);
46 explicit Realization(Buffer<void> &&e);
47 // @}
48
49 /** Construct a Realization that refers to the buffers in an
50 * existing vector of Buffer<>. The element type of the Buffer(s) may not be
51 * const */
52 // @{
53 explicit Realization(const std::vector<Buffer<void>> &e);
54 explicit Realization(std::vector<Buffer<void>> &&e);
55 // This ctor allows us to avoid ambiguity when the vector is specified as
56 // a braced literal, e.g. `Realization({first, second})`
57 explicit Realization(std::initializer_list<Buffer<void>> e)
58 : Realization(std::vector<Buffer<void>>{e}) {
59 }
60 // @}
61
62 /** Call device_sync() for all Buffers in the Realization.
63 * If one of the calls returns an error, subsequent Buffers won't have
64 * device_sync called; thus callers should consider a nonzero return
65 * code to mean that potentially all of the Buffers are in an indeterminate
66 * state of sync.
67 * Calling this explicitly should rarely be necessary, except for profiling. */
68 int device_sync(void *ctx = nullptr);
69};
70
71} // namespace Halide
72
73#endif
Buffer.h
user_assert
#define user_assert(c)
Definition: Error.h:233
Util.h
Various utility functions used internally Halide.
Halide::Buffer< void >
Halide::Realization
A Realization is a vector of references to existing Buffer objects.
Definition: Realization.h:19
Halide::Realization::Realization
Realization(const Buffer< void > &e)
Construct a Realization that acts as a reference to a single existing Buffer.
Halide::Realization::Realization
Realization(std::vector< Buffer< void > > &&e)
Halide::Realization::Realization
Realization(std::initializer_list< Buffer< void > > e)
Definition: Realization.h:57
Halide::Realization::size
size_t size() const
The number of images in the Realization.
Halide::Realization::Realization
Realization(Buffer< void > &&e)
Halide::Realization::Realization
Realization(const std::vector< Buffer< void > > &e)
Construct a Realization that refers to the buffers in an existing vector of Buffer<>.
Halide::Realization::device_sync
int device_sync(void *ctx=nullptr)
Call device_sync() for all Buffers in the Realization.
Halide::Realization::operator[]
Buffer< void > & operator[](size_t x)
Get a reference to one of the images.
Halide::Realization::operator[]
const Buffer< void > & operator[](size_t x) const
Get a const reference to one of the images.
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19