Halide
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 "Util.h" // for all_are_convertible
8 
9 /** \file
10  *
11  * Defines Realization - a vector of Buffer for use in pipelines with multiple outputs.
12  */
13 
14 namespace Halide {
15 
16 template<typename T>
17 class Buffer;
18 
19 /** A Realization is a vector of references to existing Buffer objects.
20  * A pipeline with multiple outputs realize to a Realization. */
21 class Realization {
22 private:
23  std::vector<Buffer<void>> images;
24 
25 public:
26  /** The number of images in the Realization. */
27  size_t size() const;
28 
29  /** Get a const reference to one of the images. */
30  const Buffer<void> &operator[](size_t x) const;
31 
32  /** Get a reference to one of the images. */
33  Buffer<void> &operator[](size_t x);
34 
35  /** Single-element realizations are implicitly castable to Buffers. */
36  template<typename T>
37  operator Buffer<T>() const {
38  return images[0];
39  }
40 
41  /** Construct a Realization that acts as a reference to some
42  * existing Buffers. The element type of the Buffers may not be
43  * const. */
44  template<typename T,
45  typename... Args,
46  typename = typename std::enable_if<Internal::all_are_convertible<Buffer<void>, Args...>::value>::type>
47  Realization(Buffer<T> &a, Args &&... args) {
48  images = std::vector<Buffer<void>>({a, args...});
49  }
50 
51  /** Construct a Realization that refers to the buffers in an
52  * existing vector of Buffer<> */
53  explicit Realization(std::vector<Buffer<void>> &e);
54 
55  /** Call device_sync() for all Buffers in the Realization.
56  * If one of the calls returns an error, subsequent Buffers won't have
57  * device_sync called; thus callers should consider a nonzero return
58  * code to mean that potentially all of the Buffers are in an indeterminate
59  * state of sync.
60  * Calling this explicitly should rarely be necessary, except for profiling. */
61  int device_sync(void *ctx = nullptr);
62 };
63 
64 } // namespace Halide
65 
66 #endif
Halide::Internal::IOKind::Buffer
@ Buffer
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::Buffer< void >
Halide::Realization::Realization
Realization(Buffer< T > &a, Args &&... args)
Construct a Realization that acts as a reference to some existing Buffers.
Definition: Realization.h:47
Halide::Realization::size
size_t size() const
The number of images in the Realization.
Halide::Realization::operator[]
const Buffer< void > & operator[](size_t x) const
Get a const reference to one of the images.
Halide::Realization
A Realization is a vector of references to existing Buffer objects.
Definition: Realization.h:21
Util.h
Halide::Realization::device_sync
int device_sync(void *ctx=nullptr)
Call device_sync() for all Buffers in the Realization.