Buffer#

template<typename T, int Dims>
class Buffer#

A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.

A Buffer<T1, D> can refer to a Buffer<T2, D> if T1 is const whenever T2 is const, and either T1 = T2 or T1 is void. A Buffer<void, D> can refer to any Buffer of any non-const type, and the default template parameter is T = void.

A Buffer<T, D1> can refer to a Buffer<T, D2> if D1 == D2, or if D1 is AnyDims (meaning “dimensionality is checked at runtime, not compile time”).

Public Functions

Buffer() = default#

Make a null Buffer, which points to no Runtime::Buffer.

Buffer(const Buffer &that) = default#

Trivial copy constructor.

Buffer &operator=(const Buffer &that) = default#

Trivial copy assignment operator.

Buffer &operator=(Buffer&&) noexcept = default#

Trivial move assignment operator.

template<typename T2, int D2>
inline Buffer(const Buffer<T2, D2> &other)#

Make a Buffer from a Buffer of a different type.

template<typename T2, int D2>
inline Buffer(Buffer<T2, D2> &&other) noexcept#

Move construct from a Buffer of a different type.

template<int D2>
inline Buffer(Runtime::Buffer<T, D2> &&buf, const std::string &name = "")#

Construct a Buffer that captures and owns an rvalue Runtime::Buffer.

template<typename ...Args, typename = std::enable_if_t<Internal::all_ints_and_optional_name<Args...>::value>>
inline explicit Buffer(Type t, int first, Args... rest)#

Constructors that match Runtime::Buffer with two differences: 1) They take a Type instead of a halide_type_t 2) There is an optional last string argument that gives the buffer a specific name.

inline void set_name(const std::string &n)#

Buffers are optionally named.

template<typename T2, int D2>
inline bool same_as(const Buffer<T2, D2> &other) const#

Check if two Buffer objects point to the same underlying Buffer.

inline bool defined() const#

Check if this Buffer refers to an existing Buffer.

Default-constructed Buffer objects do not refer to any existing Buffer.

inline Runtime::Buffer<T, Dims> *get()#

Get a pointer to the underlying Runtime::Buffer.

template<typename Fn, typename ...Args>
inline Buffer<T, Dims> &for_each_value(Fn &&f, Args... other_buffers)#

Does the same thing as the equivalent Halide::Runtime::Buffer method.

template<typename ...Args>
inline const Expr operator()(const Expr &first, const Args&... rest) const#

Make an Expr that loads from this concrete buffer at a computed coordinate.

Returned Expr is const so that it’s not possible to accidentally treat a buffer like a Func and try to assign an Expr to a given symbolic coordinate.

inline int copy_to_device(const Target &t = get_jit_target_from_environment(), JITUserContext *context = nullptr)#

Copy to the GPU, using the device API that is the default for the given Target.

inline int copy_to_device(const DeviceAPI &d, const Target &t = get_jit_target_from_environment(), JITUserContext *context = nullptr)#

Copy to the GPU, using the given device API.

inline int device_malloc(const Target &t = get_jit_target_from_environment(), JITUserContext *context = nullptr)#

Allocate on the GPU, using the device API that is the default for the given Target.

inline int device_malloc(const DeviceAPI &d, const Target &t = get_jit_target_from_environment(), JITUserContext *context = nullptr)#

Allocate storage on the GPU, using the given device API.

inline int device_wrap_native(const DeviceAPI &d, uint64_t handle, const Target &t = get_jit_target_from_environment(), JITUserContext *context = nullptr)#

Wrap a native handle, using the given device API.

It is a bad idea to pass DeviceAPI::Default_GPU to this routine as the handle argument must match the API that the default resolves to and it is clearer and more reliable to pass the resolved DeviceAPI explicitly.