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