Halide
Buffer.h
Go to the documentation of this file.
1 #ifndef HALIDE_BUFFER_H
2 #define HALIDE_BUFFER_H
3 
4 #include "runtime/HalideBuffer.h"
5 #include "IntrusivePtr.h"
6 #include "Expr.h"
7 #include "Util.h"
8 #include "DeviceInterface.h"
9 
10 namespace Halide {
11 
12 template<typename T = void> class Buffer;
13 
14 namespace Internal {
15 
18  std::string name;
20 };
21 
22 EXPORT Expr buffer_accessor(const Buffer<> &buf, const std::vector<Expr> &args);
23 
24 template<typename ...Args>
25 struct all_ints_and_optional_name : std::false_type {};
26 
27 template<typename First, typename ...Rest>
28 struct all_ints_and_optional_name<First, Rest...> :
29  meta_and<std::is_convertible<First, int>,
30  all_ints_and_optional_name<Rest...>> {};
31 
32 template<typename T> struct all_ints_and_optional_name<T> :
33  meta_or<std::is_convertible<T, std::string>,
34  std::is_convertible<T, int>> {};
35 
36 template<> struct all_ints_and_optional_name<> : std::true_type {};
37 
38 template<typename T,
39  typename = typename std::enable_if<!std::is_convertible<T, std::string>::value>::type>
41  return "";
42 }
43 
44 inline std::string get_name_from_end_of_parameter_pack(const std::string &n) {
45  return n;
46 }
47 
49  return "";
50 }
51 
52 template<typename First,
53  typename Second,
54  typename ...Args>
55 std::string get_name_from_end_of_parameter_pack(First first, Second second, Args&&... rest) {
56  return get_name_from_end_of_parameter_pack(second, std::forward<Args>(rest)...);
57 }
58 
59 inline void get_shape_from_start_of_parameter_pack_helper(std::vector<int> &, const std::string &) {
60 }
61 
62 inline void get_shape_from_start_of_parameter_pack_helper(std::vector<int> &) {
63 }
64 
65 template<typename ...Args>
66 void get_shape_from_start_of_parameter_pack_helper(std::vector<int> &result, int x, Args&&... rest) {
67  result.push_back(x);
68  get_shape_from_start_of_parameter_pack_helper(result, std::forward<Args>(rest)...);
69 }
70 
71 
72 template<typename ...Args>
73 std::vector<int> get_shape_from_start_of_parameter_pack(Args&&... args) {
74  std::vector<int> result;
75  get_shape_from_start_of_parameter_pack_helper(result, std::forward<Args>(args)...);
76  return result;
77 }
78 
79 template<typename T, typename T2>
80 using add_const_if_T_is_const = typename std::conditional<std::is_const<T>::value, const T2, T2>::type;
81 
82 }
83 
84 /** A Halide::Buffer is a named shared reference to a
85  * Halide::Runtime::Buffer.
86  *
87  * A Buffer<T1> can refer to a Buffer<T2> if T1 is const whenever T2
88  * is const, and either T1 = T2 or T1 is void. A Buffer<void> can
89  * refer to any Buffer of any non-const type, and the default
90  * template parameter is T = void.
91  */
92 template<typename T>
93 class Buffer {
95 
96  template<typename T2> friend class Buffer;
97 
98  template<typename T2>
99  static void assert_can_convert_from(const Buffer<T2> &other) {
101  }
102 
103 public:
104 
105  typedef T ElemType;
106 
107  /** Make a null Buffer, which points to no Runtime::Buffer */
108  Buffer() {}
109 
110  /** Make a Buffer from a Buffer of a different type */
111  template<typename T2>
112  Buffer(const Buffer<T2> &other) :
113  contents(other.contents) {
114  assert_can_convert_from(other);
115  }
116 
117  /** Move construct from a Buffer of a different type */
118  template<typename T2>
119  Buffer(Buffer<T2> &&other) {
120  assert_can_convert_from(other);
121  contents = std::move(other.contents);
122  }
123 
124  /** Construct a Buffer that captures and owns an rvalue Runtime::Buffer */
125  template<int D>
126  Buffer(Runtime::Buffer<T, D> &&buf, const std::string &name = "") :
127  contents(new Internal::BufferContents) {
128  contents->buf = std::move(buf);
129  if (name.empty()) {
130  contents->name = Internal::make_entity_name(this, "Halide::Buffer<?", 'b');
131  } else {
132  contents->name = name;
133  }
134  }
135 
136  /** Constructors that match Runtime::Buffer with two differences:
137  * 1) They take a Type instead of a halide_type_t
138  * 2) There is an optional last string argument that gives the buffer a specific name
139  */
140  // @{
141  template<typename ...Args,
142  typename = typename std::enable_if<Internal::all_ints_and_optional_name<Args...>::value>::type>
143  explicit Buffer(Type t,
144  int first, Args... rest) :
145  Buffer(Runtime::Buffer<T>(t, Internal::get_shape_from_start_of_parameter_pack(first, rest...)),
146  Internal::get_name_from_end_of_parameter_pack(rest...)) {}
147 
148  explicit Buffer(const halide_buffer_t &buf,
149  const std::string &name = "") :
150  Buffer(Runtime::Buffer<T>(buf), name) {}
151 
152  explicit Buffer(const buffer_t &buf,
153  const std::string &name = "") :
154  Buffer(Runtime::Buffer<T>(buf), name) {}
155 
156  template<typename ...Args,
157  typename = typename std::enable_if<Internal::all_ints_and_optional_name<Args...>::value>::type>
158  explicit Buffer(int first, Args... rest) :
159  Buffer(Runtime::Buffer<T>(Internal::get_shape_from_start_of_parameter_pack(first, rest...)),
160  Internal::get_name_from_end_of_parameter_pack(rest...)) {}
161 
162  explicit Buffer(Type t,
163  const std::vector<int> &sizes,
164  const std::string &name = "") :
165  Buffer(Runtime::Buffer<T>(t, sizes), name) {}
166 
167  explicit Buffer(const std::vector<int> &sizes,
168  const std::string &name = "") :
169  Buffer(Runtime::Buffer<T>(sizes), name) {}
170 
171  template<typename Array, size_t N>
172  explicit Buffer(Array (&vals)[N],
173  const std::string &name = "") :
174  Buffer(Runtime::Buffer<T>(vals), name) {}
175 
176  template<typename ...Args,
177  typename = typename std::enable_if<Internal::all_ints_and_optional_name<Args...>::value>::type>
178  explicit Buffer(Type t,
180  int first, Args&&... rest) :
181  Buffer(Runtime::Buffer<T>(t, data, Internal::get_shape_from_start_of_parameter_pack(first, rest...)),
182  Internal::get_name_from_end_of_parameter_pack(rest...)) {}
183 
184  template<typename ...Args,
185  typename = typename std::enable_if<Internal::all_ints_and_optional_name<Args...>::value>::type>
186  explicit Buffer(T *data,
187  int first, Args&&... rest) :
188  Buffer(Runtime::Buffer<T>(data, Internal::get_shape_from_start_of_parameter_pack(first, rest...)),
189  Internal::get_name_from_end_of_parameter_pack(rest...)) {}
190 
191  explicit Buffer(T *data,
192  const std::vector<int> &sizes,
193  const std::string &name = "") :
194  Buffer(Runtime::Buffer<T>(data, sizes), name) {}
195 
196  explicit Buffer(Type t,
198  const std::vector<int> &sizes,
199  const std::string &name = "") :
200  Buffer(Runtime::Buffer<T>(t, data, sizes), name) {}
201 
202  explicit Buffer(Type t,
204  int d,
205  const halide_dimension_t *shape,
206  const std::string &name = "") :
207  Buffer(Runtime::Buffer<T>(t, data, d, shape), name) {}
208 
209  explicit Buffer(T *data,
210  int d,
211  const halide_dimension_t *shape,
212  const std::string &name = "") :
213  Buffer(Runtime::Buffer<T>(data, d, shape), name) {}
214 
215 
216  static Buffer<T> make_scalar(const std::string &name = "") {
218  }
219 
220  static Buffer<> make_scalar(Type t, const std::string &name = "") {
222  }
223 
224  static Buffer<T> make_interleaved(int width, int height, int channels, const std::string &name = "") {
225  return Buffer<T>(Runtime::Buffer<T>::make_interleaved(width, height, channels),
226  name);
227  }
228 
229  static Buffer<> make_interleaved(Type t, int width, int height, int channels, const std::string &name = "") {
230  return Buffer<>(Runtime::Buffer<>::make_interleaved(t, width, height, channels),
231  name);
232  }
233 
234  static Buffer<T> make_interleaved(T *data, int width, int height, int channels, const std::string &name = "") {
235  return Buffer<T>(Runtime::Buffer<T>::make_interleaved(data, width, height, channels),
236  name);
237  }
238 
240  make_interleaved(Type t, T *data, int width, int height, int channels, const std::string &name = "") {
242  return Buffer<T2>(Runtime::Buffer<T2>::make_interleaved(t, data, width, height, channels),
243  name);
244  }
245 
246  template<typename T2>
248  void *(*allocate_fn)(size_t) = nullptr,
249  void (*deallocate_fn)(void *) = nullptr,
250  const std::string &name = "") {
251  return Buffer<T>(Runtime::Buffer<T>::make_with_shape_of(*src.get(), allocate_fn, deallocate_fn),
252  name);
253  }
254 
255  template<typename T2>
257  void *(*allocate_fn)(size_t) = nullptr,
258  void (*deallocate_fn)(void *) = nullptr,
259  const std::string &name = "") {
260  return Buffer<T>(Runtime::Buffer<T>::make_with_shape_of(src, allocate_fn, deallocate_fn),
261  name);
262  }
263  // @}
264 
265  /** Buffers are optionally named. */
266  // @{
267  void set_name(const std::string &n) {
268  contents->name = n;
269  }
270 
271  const std::string &name() const {
272  return contents->name;
273  }
274  // @}
275 
276  /** Check if two Buffer objects point to the same underlying Buffer */
277  template<typename T2>
278  bool same_as(const Buffer<T2> &other) {
279  return (const void *)(contents.get()) == (const void *)(other.contents.get());
280  }
281 
282  /** Check if this Buffer refers to an existing
283  * Buffer. Default-constructed Buffer objects do not refer to any
284  * existing Buffer. */
285  bool defined() const {
286  return contents.defined();
287  }
288 
289  /** Get a pointer to the underlying Runtime::Buffer */
290  // @{
292  // It's already type-checked, so no need to use as<T>.
293  return (Runtime::Buffer<T> *)(&contents->buf);
294  }
295  const Runtime::Buffer<T> *get() const {
296  return (const Runtime::Buffer<T> *)(&contents->buf);
297  }
298  // @}
299 
300 public:
301 
302  // We forward numerous methods from the underlying Buffer
303 #define HALIDE_BUFFER_FORWARD_CONST(method) \
304  template<typename ...Args> \
305  auto method(Args&&... args) const -> \
306  decltype(std::declval<const Runtime::Buffer<T>>().method(std::forward<Args>(args)...)) { \
307  user_assert(defined()) << "Undefined buffer calling const method " #method "\n"; \
308  return get()->method(std::forward<Args>(args)...); \
309  }
310 
311 #define HALIDE_BUFFER_FORWARD(method) \
312  template<typename ...Args> \
313  auto method(Args&&... args) -> \
314  decltype(std::declval<Runtime::Buffer<T>>().method(std::forward<Args>(args)...)) { \
315  user_assert(defined()) << "Undefined buffer calling method " #method "\n"; \
316  return get()->method(std::forward<Args>(args)...); \
317  }
318 
319  /** Does the same thing as the equivalent Halide::Runtime::Buffer method */
320  // @{
321  HALIDE_BUFFER_FORWARD(raw_buffer)
322  HALIDE_BUFFER_FORWARD_CONST(raw_buffer)
323  HALIDE_BUFFER_FORWARD_CONST(dimensions)
335  HALIDE_BUFFER_FORWARD_CONST(number_of_elements)
336  HALIDE_BUFFER_FORWARD_CONST(size_in_bytes)
343  HALIDE_BUFFER_FORWARD(slice)
345  HALIDE_BUFFER_FORWARD(embed)
347  HALIDE_BUFFER_FORWARD(set_min)
348  HALIDE_BUFFER_FORWARD(translate)
349  HALIDE_BUFFER_FORWARD(transpose)
350  HALIDE_BUFFER_FORWARD(add_dimension)
351  HALIDE_BUFFER_FORWARD(copy_to_host)
352  HALIDE_BUFFER_FORWARD(copy_to_device)
353  HALIDE_BUFFER_FORWARD_CONST(has_device_allocation)
354  HALIDE_BUFFER_FORWARD_CONST(host_dirty)
355  HALIDE_BUFFER_FORWARD_CONST(device_dirty)
356  HALIDE_BUFFER_FORWARD(set_host_dirty)
357  HALIDE_BUFFER_FORWARD(set_device_dirty)
358  HALIDE_BUFFER_FORWARD(device_sync)
359  HALIDE_BUFFER_FORWARD(device_malloc)
360  HALIDE_BUFFER_FORWARD(device_wrap_native)
361  HALIDE_BUFFER_FORWARD(device_detach_native)
362  HALIDE_BUFFER_FORWARD(allocate)
363  HALIDE_BUFFER_FORWARD(deallocate)
364  HALIDE_BUFFER_FORWARD(device_deallocate)
365  HALIDE_BUFFER_FORWARD(device_free)
367  HALIDE_BUFFER_FORWARD_CONST(for_each_element)
368 
369 #undef HALIDE_BUFFER_FORWARD
370 #undef HALIDE_BUFFER_FORWARD_CONST
371 
372  template<typename Fn, typename ...Args>
373  void for_each_value(Fn &&f, Args... other_buffers) {
374  return get()->for_each_value(std::forward<Fn>(f), (*std::forward<Args>(other_buffers).get())...);
375  }
376 
377  static constexpr bool has_static_halide_type = Runtime::Buffer<T>::has_static_halide_type;
378 
381  }
382 
383  template<typename T2>
384  static bool can_convert_from(const Buffer<T2> &other) {
386  }
387 
388  Type type() const {
389  return contents->buf.type();
390  }
391 
392  template<typename T2>
393  Buffer<T2> as() const {
394  return Buffer<T2>(*this);
395  }
396 
397  Buffer<T> copy() const {
398  return Buffer<T>(std::move(contents->buf.copy()));
399  }
400 
401  template<typename T2>
402  void copy_from(const Buffer<T2> &other) {
403  contents->buf.copy_from(*other.get());
404  }
405 
406  template<typename ...Args>
407  auto operator()(int first, Args&&... args) ->
408  decltype(std::declval<Runtime::Buffer<T>>()(first, std::forward<Args>(args)...)) {
409  return (*get())(first, std::forward<Args>(args)...);
410  }
411 
412  template<typename ...Args>
413  auto operator()(int first, Args&&... args) const ->
414  decltype(std::declval<const Runtime::Buffer<T>>()(first, std::forward<Args>(args)...)) {
415  return (*get())(first, std::forward<Args>(args)...);
416  }
417 
418  auto operator()(const int *pos) ->
419  decltype(std::declval<Runtime::Buffer<T>>()(pos)) {
420  return (*get())(pos);
421  }
422 
423  auto operator()(const int *pos) const ->
424  decltype(std::declval<const Runtime::Buffer<T>>()(pos)) {
425  return (*get())(pos);
426  }
427 
428  auto operator()() ->
429  decltype(std::declval<Runtime::Buffer<T>>()()) {
430  return (*get())();
431  }
432 
433  auto operator()() const ->
434  decltype(std::declval<const Runtime::Buffer<T>>()()) {
435  return (*get())();
436  }
437  // @}
438 
439  /** Make an Expr that loads from this concrete buffer at a computed coordinate. */
440  // @{
441  template<typename ...Args>
442  Expr operator()(Expr first, Args... rest) const {
443  std::vector<Expr> args = {first, rest...};
444  return (*this)(args);
445  };
446 
447  template<typename ...Args>
448  Expr operator()(const std::vector<Expr> &args) const {
449  return buffer_accessor(Buffer<>(*this), args);
450  };
451  // @}
452 
453 
454  /** Copy to the GPU, using the device API that is the default for the given Target. */
456  return copy_to_device(DeviceAPI::Default_GPU, t);
457  }
458 
459  /** Copy to the GPU, using the given device API */
461  return contents->buf.copy_to_device(get_device_interface_for_device_api(d, t, "Buffer::copy_to_device"));
462  }
463 
464  /** Allocate on the GPU, using the device API that is the default for the given Target. */
466  return device_malloc(DeviceAPI::Default_GPU, t);
467  }
468 
469  /** Allocate storage on the GPU, using the given device API */
471  return contents->buf.device_malloc(get_device_interface_for_device_api(d, t, "Buffer::device_malloc"));
472  }
473 
474  /** Wrap a native handle, using the given device API.
475  * It is a bad idea to pass DeviceAPI::Default_GPU to this routine
476  * as the handle argument must match the API that the default
477  * resolves to and it is clearer and more reliable to pass the
478  * resolved DeviceAPI explicitly. */
480  return contents->buf.device_wrap_native(get_device_interface_for_device_api(d, t, "Buffer::device_wrap_native"), handle);
481  }
482 
483 };
484 
485 }
486 
487 #endif
Various utility functions used internally Halide.
static halide_type_t static_halide_type()
Get the Halide type of T.
Definition: HalideBuffer.h:144
Type type() const
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:388
static Buffer< T > make_with_shape_of(Buffer< T2 > src, void *(*allocate_fn)(size_t)=nullptr, void(*deallocate_fn)(void *)=nullptr, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:247
A fragment of Halide syntax.
Definition: Expr.h:276
Buffer(T *data, const std::vector< int > &sizes, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:191
EXPORT std::string make_entity_name(void *stack_ptr, const std::string &type, char prefix)
Make a unique name for an object based on the name of the stack variable passed in.
Buffer(int first, Args... rest)
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:158
#define HALIDE_BUFFER_FORWARD_CONST(method)
Definition: Buffer.h:303
Buffer(Buffer< T2 > &&other)
Move construct from a Buffer of a different type.
Definition: Buffer.h:119
static Buffer< T, D > make_with_shape_of(Buffer< T2, D2 > src, void *(*allocate_fn)(size_t)=nullptr, void(*deallocate_fn)(void *)=nullptr)
Make a buffer with the same shape and memory nesting order as another buffer.
typename std::conditional< std::is_const< T >::value, const T2, T2 >::type add_const_if_T_is_const
Definition: Buffer.h:80
Buffer(Type t, Internal::add_const_if_T_is_const< T, void > *data, int first, Args &&... rest)
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:178
Buffer(const halide_buffer_t &buf, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:148
static bool can_convert_from(const Buffer< T2 > &other)
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:384
static Buffer< void, D > make_interleaved(halide_type_t t, int width, int height, int channels)
If you use the (x, y, c) indexing convention, then Halide Buffers are stored planar by default...
Buffer(Type t, Internal::add_const_if_T_is_const< T, void > *data, int d, const halide_dimension_t *shape, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:202
EXPORT Expr buffer_accessor(const Buffer<> &buf, const std::vector< Expr > &args)
static Buffer< T > make_interleaved(int width, int height, int channels, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:224
bool same_as(const Buffer< T2 > &other)
Check if two Buffer objects point to the same underlying Buffer.
Definition: Buffer.h:278
static Buffer< T > make_interleaved(T *data, int width, int height, int channels, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:234
static bool can_convert_from(const Buffer< T2, D2 > &other)
Determine if if an Buffer<T, D> can be constructed from some other Buffer type.
Definition: HalideBuffer.h:517
EXPORT const halide_device_interface_t * get_device_interface_for_device_api(DeviceAPI d, const Target &t=get_jit_target_from_environment(), const char *error_site=nullptr)
Gets the appropriate halide_device_interface_t * for a DeviceAPI.
A struct representing a target machine and os to generate code for.
Definition: Target.h:21
std::vector< int > get_shape_from_start_of_parameter_pack(Args &&... args)
Definition: Buffer.h:73
#define HALIDE_BUFFER_FORWARD(method)
Definition: Buffer.h:311
auto operator()(int first, Args &&... args) -> decltype(std::declval< Runtime::Buffer< T >>()(first, std::forward< Args >(args)...))
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:407
Defines a Buffer type that wraps from buffer_t and adds functionality, and methods for more convenien...
static Buffer< T > make_with_shape_of(const Runtime::Buffer< T2 > &src, void *(*allocate_fn)(size_t)=nullptr, void(*deallocate_fn)(void *)=nullptr, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:256
STL namespace.
static Buffer make_scalar(Type t, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:220
auto operator()(int first, Args &&... args) const -> decltype(std::declval< const Runtime::Buffer< T >>()(first, std::forward< Args >(args)...))
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:413
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
Definition: Buffer.h:12
Intrusive shared pointers have a reference count (a RefCount object) stored in the class itself...
Definition: IntrusivePtr.h:57
Defines methods for manipulating and analyzing boolean expressions.
int device_wrap_native(const DeviceAPI &d, uint64_t handle, const Target &t=get_jit_target_from_environment())
Wrap a native handle, using the given device API.
Definition: Buffer.h:479
Buffer()
Make a null Buffer, which points to no Runtime::Buffer.
Definition: Buffer.h:108
Buffer(const std::vector< int > &sizes, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:167
Expr min(FuncRef a, FuncRef b)
Explicit overloads of min and max for FuncRef.
Definition: Func.h:418
EXPORT Target get_jit_target_from_environment()
Return the target that Halide will use for jit-compilation.
Buffer< T > copy() const
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:397
Runtime::Buffer< T > * get()
Get a pointer to the underlying Runtime::Buffer.
Definition: Buffer.h:291
Buffer< T2 > as() const
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:393
int device_malloc(const DeviceAPI &d, const Target &t=get_jit_target_from_environment())
Allocate storage on the GPU, using the given device API.
Definition: Buffer.h:470
int copy_to_device(const Target &t=get_jit_target_from_environment())
Copy to the GPU, using the device API that is the default for the given Target.
Definition: Buffer.h:455
Methods for managing device allocations when jitting.
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt) ...
int copy_to_device(const DeviceAPI &d, const Target &t=get_jit_target_from_environment())
Copy to the GPU, using the given device API.
Definition: Buffer.h:460
Buffer(Runtime::Buffer< T, D > &&buf, const std::string &name="")
Construct a Buffer that captures and owns an rvalue Runtime::Buffer.
Definition: Buffer.h:126
auto operator()() -> decltype(std::declval< Runtime::Buffer< T >>()())
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:428
char * end
Definition: printer.h:30
A templated Buffer class that wraps halide_buffer_t and adds functionality.
Definition: HalideBuffer.h:35
auto operator()(const int *pos) const -> decltype(std::declval< const Runtime::Buffer< T >>()(pos))
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:423
static Buffer make_interleaved(Type t, int width, int height, int channels, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:229
Buffer(T *data, int first, Args &&... rest)
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:186
Support classes for reference-counting via intrusive shared pointers.
static halide_type_t static_halide_type()
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:379
Buffer(Array(&vals)[N], const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:172
static void assert_can_convert_from(const Buffer< T2, D2 > &other)
Fail an assertion at runtime or compile-time if an Buffer<T, D> cannot be constructed from some other...
Definition: HalideBuffer.h:533
Buffer(Type t, const std::vector< int > &sizes, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:162
Buffer(T *data, int d, const halide_dimension_t *shape, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:209
A runtime tag for a type in the halide type system.
const std::string & name() const
Buffers are optionally named.
Definition: Buffer.h:271
void for_each_value(Fn &&f, Args... other_buffers)
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:373
void copy_from(const Buffer< T2 > &other)
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:402
Types in the halide type system.
Definition: Type.h:285
Buffer(const buffer_t &buf, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:152
Buffer(const Buffer< T2 > &other)
Make a Buffer from a Buffer of a different type.
Definition: Buffer.h:112
T * get() const
Access the raw pointer in a variety of ways.
Definition: IntrusivePtr.h:89
Buffer(Type t, Internal::add_const_if_T_is_const< T, void > *data, const std::vector< int > &sizes, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:196
Buffer(Type t, int first, Args... rest)
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:143
void get_shape_from_start_of_parameter_pack_helper(std::vector< int > &, const std::string &)
Definition: Buffer.h:59
auto operator()() const -> decltype(std::declval< const Runtime::Buffer< T >>()())
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:433
#define EXPORT
Definition: Util.h:30
static Buffer< Internal::add_const_if_T_is_const< T, void > > make_interleaved(Type t, T *data, int width, int height, int channels, const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:240
std::string get_name_from_end_of_parameter_pack(T &&)
Definition: Buffer.h:40
bool defined() const
Check if this Buffer refers to an existing Buffer.
Definition: Buffer.h:285
auto operator()(const int *pos) -> decltype(std::declval< Runtime::Buffer< T >>()(pos))
Does the same thing as the equivalent Halide::Runtime::Buffer method.
Definition: Buffer.h:418
The raw representation of an image passed around by generated Halide code.
unsigned __INT64_TYPE__ uint64_t
static Buffer< T > make_scalar(const std::string &name="")
Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide...
Definition: Buffer.h:216
static Buffer< T, D > make_scalar()
Make a zero-dimensional Buffer.
A class representing a reference count to be used with IntrusivePtr.
Definition: IntrusivePtr.h:19
DeviceAPI
An enum describing a type of device API.
Definition: Expr.h:317
Expr operator()(const std::vector< Expr > &args) const
Make an Expr that loads from this concrete buffer at a computed coordinate.
Definition: Buffer.h:448
Expr operator()(Expr first, Args... rest) const
Make an Expr that loads from this concrete buffer at a computed coordinate.
Definition: Buffer.h:442
int device_malloc(const Target &t=get_jit_target_from_environment())
Allocate on the GPU, using the device API that is the default for the given Target.
Definition: Buffer.h:465
void set_name(const std::string &n)
Buffers are optionally named.
Definition: Buffer.h:267