Halide
Halide::Runtime::Buffer< T, D > Class Template Reference

A templated Buffer class that wraps halide_buffer_t and adds functionality. More...

#include <HalideBuffer.h>

Classes

class  Dimension
 Read-only access to the shape. More...
 

Public Types

typedef T ElemType
 

Public Member Functions

bool owns_host_memory () const
 Does this Buffer own the host memory it refers to? More...
 
HALIDE_ALWAYS_INLINE Dimension dim (int i) const
 Access the shape of the buffer. More...
 
size_t number_of_elements () const
 The total number of elements this buffer represents. More...
 
int dimensions () const
 Get the dimensionality of the buffer. More...
 
halide_type_t type () const
 Get the type of the elements. More...
 
T * begin () const
 A pointer to the element with the lowest address. More...
 
T * end () const
 A pointer to one beyond the element with the highest address. More...
 
size_t size_in_bytes () const
 The total number of bytes spanned by the data in memory. More...
 
 Buffer ()
 
 Buffer (const halide_buffer_t &buf, BufferDeviceOwnership ownership=BufferDeviceOwnership::Unmanaged)
 Make a Buffer from a halide_buffer_t. More...
 
 Buffer (const buffer_t &old_buf)
 Make a Buffer from a legacy buffer_t. More...
 
buffer_t make_legacy_buffer_t () const
 Populate the fields of a legacy buffer_t using this Buffer. More...
 
 Buffer (const Buffer< T, D > &other)
 Copy constructor. More...
 
template<typename T2 , int D2>
 Buffer (const Buffer< T2, D2 > &other)
 Construct a Buffer from a Buffer of different dimensionality and type. More...
 
 Buffer (Buffer< T, D > &&other)
 Move constructor. More...
 
template<typename T2 , int D2>
 Buffer (Buffer< T2, D2 > &&other)
 Move-construct a Buffer from a Buffer of different dimensionality and type. More...
 
template<typename T2 , int D2>
Buffer< T, D > & operator= (const Buffer< T2, D2 > &other)
 Assign from another Buffer of possibly-different dimensionality and type. More...
 
Buffer< T, D > & operator= (const Buffer< T, D > &other)
 Standard assignment operator. More...
 
template<typename T2 , int D2>
Buffer< T, D > & operator= (Buffer< T2, D2 > &&other)
 Move from another Buffer of possibly-different dimensionality and type. More...
 
Buffer< T, D > & operator= (Buffer< T, D > &&other)
 Standard move-assignment operator. More...
 
void check_overflow ()
 Check the product of the extents fits in memory. More...
 
void allocate (void *(*allocate_fn)(size_t)=nullptr, void(*deallocate_fn)(void *)=nullptr)
 Allocate memory for this Buffer. More...
 
void deallocate ()
 Drop reference to any owned host or device memory, possibly freeing it, if this buffer held the last reference to it. More...
 
void device_deallocate ()
 Drop reference to any owned device memory, possibly freeing it if this buffer held the last reference to it. More...
 
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
 Buffer (halide_type_t t, int first, Args... rest)
 Allocate a new image of the given size with a runtime type. More...
 
 Buffer (halide_type_t t, const std::vector< int > &sizes)
 Allocate a new image of unknown type using a vector of ints as the size. More...
 
 Buffer (const std::vector< int > &sizes)
 Allocate a new image of known type using a vector of ints as the size. More...
 
template<typename Array , size_t N>
 Buffer (Array(&vals)[N])
 Make an Buffer that refers to a statically sized array. More...
 
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
 Buffer (halide_type_t t, add_const_if_T_is_const< void > *data, int first, Args &&... rest)
 Initialize an Buffer of runtime type from a pointer and some sizes. More...
 
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
 Buffer (T *data, int first, Args &&... rest)
 Initialize an Buffer from a pointer and some sizes. More...
 
 Buffer (T *data, const std::vector< int > &sizes)
 Initialize an Buffer from a pointer and a vector of sizes. More...
 
 Buffer (halide_type_t t, add_const_if_T_is_const< void > *data, const std::vector< int > &sizes)
 Initialize an Buffer of runtime type from a pointer and a vector of sizes. More...
 
 Buffer (halide_type_t t, add_const_if_T_is_const< void > *data, int d, const halide_dimension_t *shape)
 Initialize an Buffer from a pointer to the min coordinate and an array describing the shape. More...
 
 Buffer (T *data, int d, const halide_dimension_t *shape)
 Initialize an Buffer from a pointer to the min coordinate and an array describing the shape. More...
 
 ~Buffer ()
 Destructor. More...
 
 operator halide_buffer_t * ()
 Provide a cast operator to halide_buffer_t *, so that instances can be passed directly to Halide filters. More...
 
template<typename T2 , int D2 = D>
Buffer< T2, D2 > & as () &
 Return a typed reference to this Buffer. More...
 
template<typename T2 , int D2 = D>
const Buffer< T2, D2 > & as () const &
 Return a const typed reference to this Buffer. More...
 
template<typename T2 , int D2 = D>
Buffer< T2, D2 > as () &&
 Returns this rval Buffer with a different type attached. More...
 
Buffer< T, D > copy (void *(*allocate_fn)(size_t)=nullptr, void(*deallocate_fn)(void *)=nullptr) const
 Make a new image which is a deep copy of this image. More...
 
template<typename T2 , int D2>
void copy_from (const Buffer< T2, D2 > &other)
 Fill a Buffer with the values at the same coordinates in another Buffer. More...
 
Buffer< T, D > cropped (int d, int min, int extent) const
 Make an image that refers to a sub-range of this image along the given dimension. More...
 
void crop (int d, int min, int extent)
 Crop an image in-place along the given dimension. More...
 
Buffer< T, D > cropped (const std::vector< std::pair< int, int >> &rect) const
 Make an image that refers to a sub-rectangle of this image along the first N dimensions. More...
 
void crop (const std::vector< std::pair< int, int >> &rect)
 Crop an image in-place along the first N dimensions. More...
 
Buffer< T, D > translated (int d, int dx) const
 Make an image which refers to the same data with using translated coordinates in the given dimension. More...
 
void translate (int d, int delta)
 Translate an image in-place along one dimension. More...
 
Buffer< T, D > translated (const std::vector< int > &delta)
 Make an image which refers to the same data translated along the first N dimensions. More...
 
void translate (const std::vector< int > &delta)
 Translate an image along the first N dimensions. More...
 
template<typename ... Args>
void set_min (Args... args)
 Set the min coordinate of an image in the first N dimensions. More...
 
template<typename ... Args>
bool contains (Args... args)
 Test if a given coordinate is within the the bounds of an image. More...
 
Buffer< T, D > transposed (int d1, int d2) const
 Make an image which refers to the same data using a different ordering of the dimensions. More...
 
void transpose (int d1, int d2)
 Transpose an image in-place. More...
 
Buffer< T, D > sliced (int d, int pos) const
 Make a lower-dimensional image that refers to one slice of this image. More...
 
void slice (int d, int pos)
 Slice an image in-place. More...
 
Buffer< T, D > embedded (int d, int pos) const
 Make a new image that views this image as a single slice in a higher-dimensional space. More...
 
void embed (int d, int pos)
 Embed an image in-place, increasing the dimensionality. More...
 
void add_dimension ()
 Add a new dimension with a min of zero and an extent of one. More...
 
void add_dimension_with_stride (int s)
 Add a new dimension with a min of zero, an extent of one, and the specified stride. More...
 
void fill (not_void_T val)
 
template<typename Fn , typename ... Args, int N = sizeof...(Args) + 1>
void for_each_value (Fn &&f, Args... other_buffers)
 Call a function on every value in the buffer, and the corresponding values in some number of other buffers of the same size. More...
 
template<typename Fn >
void for_each_element (Fn &&f) const
 Call a function at each site in a buffer. More...
 
template<typename Fn , typename = typename std::enable_if<!std::is_arithmetic<typename std::decay<Fn>::type>::value>::type>
void fill (Fn &&f)
 Fill a buffer by evaluating a callable at every site. More...
 
bool is_bounds_query ()
 Check if an input buffer passed extern stage is a querying bounds. More...
 
int min (int i) const
 Access to the mins, strides, extents. More...
 
int extent (int i) const
 Access to the mins, strides, extents. More...
 
int stride (int i) const
 Access to the mins, strides, extents. More...
 
 Buffer (int first)
 Allocate a new image of the given size. More...
 
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
 Buffer (int first, int second, Args... rest)
 Allocate a new image of the given size. More...
 
halide_buffer_traw_buffer ()
 Get a pointer to the raw halide_buffer_t this wraps. More...
 
const halide_buffer_traw_buffer () const
 Get a pointer to the raw halide_buffer_t this wraps. More...
 
int width () const
 Conventional names for the first three dimensions. More...
 
int height () const
 Conventional names for the first three dimensions. More...
 
int channels () const
 Conventional names for the first three dimensions. More...
 
int left () const
 Conventional names for the min and max value of each dimension. More...
 
int right () const
 Conventional names for the min and max value of each dimension. More...
 
int top () const
 Conventional names for the min and max value of each dimension. More...
 
int bottom () const
 Conventional names for the min and max value of each dimension. More...
 
void set_host_dirty (bool v=true)
 Methods for managing any GPU allocation. More...
 
bool device_dirty () const
 Methods for managing any GPU allocation. More...
 
bool host_dirty () const
 Methods for managing any GPU allocation. More...
 
void set_device_dirty (bool v=true)
 Methods for managing any GPU allocation. More...
 
int copy_to_host (void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
int copy_to_device (const struct halide_device_interface_t *device_interface, void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
int device_malloc (const struct halide_device_interface_t *device_interface, void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
int device_free (void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
int device_wrap_native (const struct halide_device_interface_t *device_interface, uint64_t handle, void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
int device_detach_native (void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
int device_and_host_malloc (const struct halide_device_interface_t *device_interface, void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
int device_and_host_free (const struct halide_device_interface_t *device_interface, void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
int device_sync (void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
bool has_device_allocation () const
 Methods for managing any GPU allocation. More...
 
BufferDeviceOwnership device_ownership () const
 Return the method by which the device field is managed. More...
 
T * data ()
 Get a pointer to the address of the min coordinate. More...
 
const T * data () const
 Get a pointer to the address of the min coordinate. More...
 
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
HALIDE_ALWAYS_INLINE const not_void_T & operator() (int first, Args... rest) const
 Access elements. More...
 
HALIDE_ALWAYS_INLINE const not_void_T & operator() () const
 Access elements. More...
 
HALIDE_ALWAYS_INLINE const not_void_T & operator() (const int *pos) const
 Access elements. More...
 
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
HALIDE_ALWAYS_INLINE not_void_T & operator() (int first, Args... rest)
 Access elements. More...
 
HALIDE_ALWAYS_INLINE not_void_T & operator() ()
 Access elements. More...
 
HALIDE_ALWAYS_INLINE not_void_T & operator() (const int *pos)
 Access elements. More...
 

Static Public Member Functions

static halide_type_t static_halide_type ()
 Get the Halide type of T. More...
 
template<typename T2 , int D2>
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. More...
 
template<typename T2 , int D2>
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 Buffer type. More...
 
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. More...
 
static Buffer< T, D > make_interleaved (int width, int height, int channels)
 If you use the (x, y, c) indexing convention, then Halide Buffers are stored planar by default. More...
 
static Buffer< add_const_if_T_is_const< void >, D > make_interleaved (halide_type_t t, T *data, int width, int height, int channels)
 Wrap an existing interleaved image. More...
 
static Buffer< T, D > make_interleaved (T *data, int width, int height, int channels)
 Wrap an existing interleaved image. More...
 
static Buffer< add_const_if_T_is_const< void >, D > make_scalar (halide_type_t t)
 Make a zero-dimensional Buffer. More...
 
static Buffer< T, D > make_scalar ()
 Make a zero-dimensional Buffer. More...
 
template<typename T2 , int D2>
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. More...
 

Static Public Attributes

static constexpr bool has_static_halide_type = !T_is_void
 True if the Halide type is not void (or const void). More...
 

Detailed Description

template<typename T = void, int D = 4>
class Halide::Runtime::Buffer< T, D >

A templated Buffer class that wraps halide_buffer_t and adds functionality.

When using Halide from C++, this is the preferred way to create input and output buffers. The overhead of using this class relative to a naked halide_buffer_t is minimal - it uses another ~16 bytes on the stack, and does no dynamic allocations when using it to represent existing memory of a known maximum dimensionality.

The template parameter T is the element type. For buffers where the element type is unknown, or may vary, use void or const void.

D is the maximum number of dimensions that can be represented using space inside the class itself. Set it to the maximum dimensionality you expect this buffer to be. If the actual dimensionality exceeds this, heap storage is allocated to track the shape of the buffer. D defaults to 4, which should cover nearly all usage.

The class optionally allocates and owns memory for the image using a shared pointer allocated with the provided allocator. If they are null, malloc and free are used. Any device-side allocation is considered as owned if and only if the host-side allocation is owned.

Examples:
tutorial/lesson_10_aot_compilation_run.cpp.

Definition at line 35 of file HalideBuffer.h.

Member Typedef Documentation

◆ ElemType

template<typename T = void, int D = 4>
typedef T Halide::Runtime::Buffer< T, D >::ElemType

Definition at line 354 of file HalideBuffer.h.

Constructor & Destructor Documentation

◆ Buffer() [1/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( )
inline

Definition at line 464 of file HalideBuffer.h.

◆ Buffer() [2/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( const halide_buffer_t buf,
BufferDeviceOwnership  ownership = BufferDeviceOwnership::Unmanaged 
)
inline

Make a Buffer from a halide_buffer_t.

Definition at line 470 of file HalideBuffer.h.

References halide_buffer_t::type.

◆ Buffer() [3/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( const buffer_t old_buf)
inline

Make a Buffer from a legacy buffer_t.

Definition at line 477 of file HalideBuffer.h.

References buffer_t::dev, buffer_t::elem_size, buffer_t::extent, buffer_t::host, buffer_t::min, and buffer_t::stride.

◆ Buffer() [4/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( const Buffer< T, D > &  other)
inline

Copy constructor.

Does not copy underlying data.

Definition at line 538 of file HalideBuffer.h.

◆ Buffer() [5/19]

template<typename T = void, int D = 4>
template<typename T2 , int D2>
Halide::Runtime::Buffer< T, D >::Buffer ( const Buffer< T2, D2 > &  other)
inline

Construct a Buffer from a Buffer of different dimensionality and type.

Asserts that the type matches (at runtime, if one of the types is void). Note that this constructor is implicit. This, for example, lets you pass things like Buffer<T> or Buffer<const void> to functions expected Buffer<const T>.

Definition at line 552 of file HalideBuffer.h.

◆ Buffer() [6/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( Buffer< T, D > &&  other)
inline

Move constructor.

Definition at line 561 of file HalideBuffer.h.

References halide_buffer_t::device, and halide_buffer_t::device_interface.

◆ Buffer() [7/19]

template<typename T = void, int D = 4>
template<typename T2 , int D2>
Halide::Runtime::Buffer< T, D >::Buffer ( Buffer< T2, D2 > &&  other)
inline

Move-construct a Buffer from a Buffer of different dimensionality and type.

Asserts that the types match (at runtime if one of the types is void).

Definition at line 575 of file HalideBuffer.h.

References halide_buffer_t::device, and halide_buffer_t::device_interface.

◆ Buffer() [8/19]

template<typename T = void, int D = 4>
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
Halide::Runtime::Buffer< T, D >::Buffer ( halide_type_t  t,
int  first,
Args...  rest 
)
inline

Allocate a new image of the given size with a runtime type.

Only used when you do know what size you want but you don't know statically what type the elements are. Pass zeroes to make a buffer suitable for bounds query calls.

Definition at line 714 of file HalideBuffer.h.

◆ Buffer() [9/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( int  first)
inlineexplicit

Allocate a new image of the given size.

Pass zeroes to make a buffer suitable for bounds query calls.

Definition at line 735 of file HalideBuffer.h.

◆ Buffer() [10/19]

template<typename T = void, int D = 4>
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
Halide::Runtime::Buffer< T, D >::Buffer ( int  first,
int  second,
Args...  rest 
)
inline

Allocate a new image of the given size.

Pass zeroes to make a buffer suitable for bounds query calls.

Definition at line 750 of file HalideBuffer.h.

◆ Buffer() [11/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( halide_type_t  t,
const std::vector< int > &  sizes 
)
inline

Allocate a new image of unknown type using a vector of ints as the size.

Definition at line 765 of file HalideBuffer.h.

◆ Buffer() [12/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( const std::vector< int > &  sizes)
inline

Allocate a new image of known type using a vector of ints as the size.

Definition at line 780 of file HalideBuffer.h.

◆ Buffer() [13/19]

template<typename T = void, int D = 4>
template<typename Array , size_t N>
Halide::Runtime::Buffer< T, D >::Buffer ( Array(&)  vals[N])
inlineexplicit

Make an Buffer that refers to a statically sized array.

Does not take ownership of the data, and does not set the host_dirty flag.

Definition at line 794 of file HalideBuffer.h.

◆ Buffer() [14/19]

template<typename T = void, int D = 4>
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
Halide::Runtime::Buffer< T, D >::Buffer ( halide_type_t  t,
add_const_if_T_is_const< void > *  data,
int  first,
Args &&...  rest 
)
inlineexplicit

Initialize an Buffer of runtime type from a pointer and some sizes.

Assumes dense row-major packing and a min coordinate of zero. Does not take ownership of the data and does not set the host_dirty flag.

Definition at line 808 of file HalideBuffer.h.

◆ Buffer() [15/19]

template<typename T = void, int D = 4>
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
Halide::Runtime::Buffer< T, D >::Buffer ( T *  data,
int  first,
Args &&...  rest 
)
inlineexplicit

Initialize an Buffer from a pointer and some sizes.

Assumes dense row-major packing and a min coordinate of zero. Does not take ownership of the data and does not set the host_dirty flag.

Definition at line 824 of file HalideBuffer.h.

◆ Buffer() [16/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( T *  data,
const std::vector< int > &  sizes 
)
inlineexplicit

Initialize an Buffer from a pointer and a vector of sizes.

Assumes dense row-major packing and a min coordinate of zero. Does not take ownership of the data and does not set the host_dirty flag.

Definition at line 836 of file HalideBuffer.h.

◆ Buffer() [17/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( halide_type_t  t,
add_const_if_T_is_const< void > *  data,
const std::vector< int > &  sizes 
)
inlineexplicit

Initialize an Buffer of runtime type from a pointer and a vector of sizes.

Assumes dense row-major packing and a min coordinate of zero. Does not take ownership of the data and does not set the host_dirty flag.

Definition at line 848 of file HalideBuffer.h.

◆ Buffer() [18/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( halide_type_t  t,
add_const_if_T_is_const< void > *  data,
int  d,
const halide_dimension_t shape 
)
inlineexplicit

Initialize an Buffer from a pointer to the min coordinate and an array describing the shape.

Does not take ownership of the data, and does not set the host_dirty flag.

Definition at line 862 of file HalideBuffer.h.

◆ Buffer() [19/19]

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::Buffer ( T *  data,
int  d,
const halide_dimension_t shape 
)
inlineexplicit

Initialize an Buffer from a pointer to the min coordinate and an array describing the shape.

Does not take ownership of the data and does not set the host_dirty flag.

Definition at line 878 of file HalideBuffer.h.

◆ ~Buffer()

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::~Buffer ( )
inline

Destructor.

Will release any underlying owned allocation if this is the last reference to it. Will assert fail if there are weak references to this Buffer outstanding.

Definition at line 891 of file HalideBuffer.h.

Member Function Documentation

◆ static_halide_type()

template<typename T = void, int D = 4>
static halide_type_t Halide::Runtime::Buffer< T, D >::static_halide_type ( )
inlinestatic

Get the Halide type of T.

Callers should not use the result if has_static_halide_type is false.

Definition at line 144 of file HalideBuffer.h.

Referenced by Halide::Buffer<>::static_halide_type().

◆ owns_host_memory()

◆ dim()

template<typename T = void, int D = 4>
HALIDE_ALWAYS_INLINE Dimension Halide::Runtime::Buffer< T, D >::dim ( int  i) const
inline

◆ min()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::min ( int  i) const
inline

Access to the mins, strides, extents.

Will be deprecated. Do not use.

Definition at line 410 of file HalideBuffer.h.

◆ extent()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::extent ( int  i) const
inline

Access to the mins, strides, extents.

Will be deprecated. Do not use.

Definition at line 411 of file HalideBuffer.h.

◆ stride()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::stride ( int  i) const
inline

Access to the mins, strides, extents.

Will be deprecated. Do not use.

Definition at line 412 of file HalideBuffer.h.

◆ number_of_elements()

template<typename T = void, int D = 4>
size_t Halide::Runtime::Buffer< T, D >::number_of_elements ( ) const
inline

The total number of elements this buffer represents.

Equal to the product of the extents

Definition at line 417 of file HalideBuffer.h.

◆ dimensions()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::dimensions ( ) const
inline

◆ type()

template<typename T = void, int D = 4>
halide_type_t Halide::Runtime::Buffer< T, D >::type ( ) const
inline

Get the type of the elements.

Definition at line 431 of file HalideBuffer.h.

Referenced by Halide::Runtime::Buffer< T, D >::can_convert_from().

◆ begin()

template<typename T = void, int D = 4>
T* Halide::Runtime::Buffer< T, D >::begin ( ) const
inline

A pointer to the element with the lowest address.

If all strides are positive, equal to the host pointer.

Definition at line 437 of file HalideBuffer.h.

◆ end()

template<typename T = void, int D = 4>
T* Halide::Runtime::Buffer< T, D >::end ( ) const
inline

A pointer to one beyond the element with the highest address.

Definition at line 448 of file HalideBuffer.h.

◆ size_in_bytes()

template<typename T = void, int D = 4>
size_t Halide::Runtime::Buffer< T, D >::size_in_bytes ( ) const
inline

The total number of bytes spanned by the data in memory.

Definition at line 460 of file HalideBuffer.h.

References end.

◆ make_legacy_buffer_t()

template<typename T = void, int D = 4>
buffer_t Halide::Runtime::Buffer< T, D >::make_legacy_buffer_t ( ) const
inline

Populate the fields of a legacy buffer_t using this Buffer.

Does not copy device metadata.

Definition at line 496 of file HalideBuffer.h.

References buffer_t::elem_size, buffer_t::extent, buffer_t::host, buffer_t::min, and buffer_t::stride.

◆ can_convert_from()

template<typename T = void, int D = 4>
template<typename T2 , int D2>
static bool Halide::Runtime::Buffer< T, D >::can_convert_from ( const Buffer< T2, D2 > &  other)
inlinestatic

Determine if if an Buffer<T, D> can be constructed from some other Buffer type.

If this can be determined at compile time, fail with a static assert; otherwise return a boolean based on runtime typing.

Definition at line 517 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::type().

Referenced by Halide::Buffer<>::can_convert_from().

◆ assert_can_convert_from()

template<typename T = void, int D = 4>
template<typename T2 , int D2>
static void Halide::Runtime::Buffer< T, D >::assert_can_convert_from ( const Buffer< T2, D2 > &  other)
inlinestatic

Fail an assertion at runtime or compile-time if an Buffer<T, D> cannot be constructed from some other Buffer type.

Definition at line 533 of file HalideBuffer.h.

Referenced by Halide::Runtime::Buffer< T, D >::as().

◆ operator=() [1/4]

template<typename T = void, int D = 4>
template<typename T2 , int D2>
Buffer<T, D>& Halide::Runtime::Buffer< T, D >::operator= ( const Buffer< T2, D2 > &  other)
inline

Assign from another Buffer of possibly-different dimensionality and type.

Asserts that the types match (at runtime if one of the types is void).

Definition at line 589 of file HalideBuffer.h.

◆ operator=() [2/4]

template<typename T = void, int D = 4>
Buffer<T, D>& Halide::Runtime::Buffer< T, D >::operator= ( const Buffer< T, D > &  other)
inline

Standard assignment operator.

Definition at line 605 of file HalideBuffer.h.

◆ operator=() [3/4]

template<typename T = void, int D = 4>
template<typename T2 , int D2>
Buffer<T, D>& Halide::Runtime::Buffer< T, D >::operator= ( Buffer< T2, D2 > &&  other)
inline

Move from another Buffer of possibly-different dimensionality and type.

Asserts that the types match (at runtime if one of the types is void).

Definition at line 623 of file HalideBuffer.h.

References halide_buffer_t::device, and halide_buffer_t::device_interface.

◆ operator=() [4/4]

template<typename T = void, int D = 4>
Buffer<T, D>& Halide::Runtime::Buffer< T, D >::operator= ( Buffer< T, D > &&  other)
inline

Standard move-assignment operator.

Definition at line 639 of file HalideBuffer.h.

References halide_buffer_t::device, and halide_buffer_t::device_interface.

◆ check_overflow()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::check_overflow ( )
inline

Check the product of the extents fits in memory.

Definition at line 654 of file HalideBuffer.h.

◆ allocate()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::allocate ( void *(*)(size_t allocate_fn = nullptr,
void(*)(void *)  deallocate_fn = nullptr 
)
inline

Allocate memory for this Buffer.

Drops the reference to any owned memory.

Definition at line 669 of file HalideBuffer.h.

References Halide::Runtime::AllocationHeader::deallocate_fn, free(), malloc(), and Halide::Runtime::AllocationHeader::ref_count.

◆ deallocate()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::deallocate ( )
inline

Drop reference to any owned host or device memory, possibly freeing it, if this buffer held the last reference to it.

Retains the shape of the buffer. Does nothing if this buffer did not allocate its own memory.

Definition at line 697 of file HalideBuffer.h.

◆ device_deallocate()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::device_deallocate ( )
inline

Drop reference to any owned device memory, possibly freeing it if this buffer held the last reference to it.

Asserts that device_dirty is false.

Definition at line 704 of file HalideBuffer.h.

◆ raw_buffer() [1/2]

template<typename T = void, int D = 4>
halide_buffer_t* Halide::Runtime::Buffer< T, D >::raw_buffer ( )
inline

Get a pointer to the raw halide_buffer_t this wraps.

Definition at line 898 of file HalideBuffer.h.

References buf.

◆ raw_buffer() [2/2]

template<typename T = void, int D = 4>
const halide_buffer_t* Halide::Runtime::Buffer< T, D >::raw_buffer ( ) const
inline

Get a pointer to the raw halide_buffer_t this wraps.

Definition at line 902 of file HalideBuffer.h.

References buf.

◆ operator halide_buffer_t *()

template<typename T = void, int D = 4>
Halide::Runtime::Buffer< T, D >::operator halide_buffer_t * ( )
inline

Provide a cast operator to halide_buffer_t *, so that instances can be passed directly to Halide filters.

Definition at line 909 of file HalideBuffer.h.

References buf.

◆ as() [1/3]

template<typename T = void, int D = 4>
template<typename T2 , int D2 = D>
Buffer<T2, D2>& Halide::Runtime::Buffer< T, D >::as ( ) &
inline

Return a typed reference to this Buffer.

Useful for converting a reference to a Buffer<void> to a reference to, for example, a Buffer<const uint8_t>. Does a runtime assert if the source buffer type is void.

Definition at line 919 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::assert_can_convert_from().

◆ as() [2/3]

template<typename T = void, int D = 4>
template<typename T2 , int D2 = D>
const Buffer<T2, D2>& Halide::Runtime::Buffer< T, D >::as ( ) const &
inline

Return a const typed reference to this Buffer.

Useful for converting a conference reference to one Buffer type to a const reference to another Buffer type. Does a runtime assert if the source buffer type is void.

Definition at line 930 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::assert_can_convert_from().

◆ as() [3/3]

template<typename T = void, int D = 4>
template<typename T2 , int D2 = D>
Buffer<T2, D2> Halide::Runtime::Buffer< T, D >::as ( ) &&
inline

Returns this rval Buffer with a different type attached.

Does a dynamic type check if the source type is void.

Definition at line 938 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::assert_can_convert_from().

◆ width()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::width ( ) const
inline

Conventional names for the first three dimensions.

Definition at line 945 of file HalideBuffer.h.

◆ height()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::height ( ) const
inline

Conventional names for the first three dimensions.

Definition at line 948 of file HalideBuffer.h.

◆ channels()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::channels ( ) const
inline

Conventional names for the first three dimensions.

Definition at line 951 of file HalideBuffer.h.

◆ left()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::left ( ) const
inline

Conventional names for the min and max value of each dimension.

Definition at line 958 of file HalideBuffer.h.

◆ right()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::right ( ) const
inline

Conventional names for the min and max value of each dimension.

Definition at line 962 of file HalideBuffer.h.

◆ top()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::top ( ) const
inline

Conventional names for the min and max value of each dimension.

Definition at line 966 of file HalideBuffer.h.

◆ bottom()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::bottom ( ) const
inline

Conventional names for the min and max value of each dimension.

Definition at line 970 of file HalideBuffer.h.

◆ copy()

template<typename T = void, int D = 4>
Buffer<T, D> Halide::Runtime::Buffer< T, D >::copy ( void *(*)(size_t allocate_fn = nullptr,
void(*)(void *)  deallocate_fn = nullptr 
) const
inline

Make a new image which is a deep copy of this image.

Use crop or slice followed by copy to make a copy of only a portion of the image. The new image uses the same memory layout as the original, with holes compacted away.

Definition at line 979 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::copy_from(), and dst.

◆ copy_from()

template<typename T = void, int D = 4>
template<typename T2 , int D2>
void Halide::Runtime::Buffer< T, D >::copy_from ( const Buffer< T2, D2 > &  other)
inline

Fill a Buffer with the values at the same coordinates in another Buffer.

Restricts itself to coordinates contained within the intersection of the two buffers. If the two Buffers are not in the same coordinate system, you will need to translate the argument Buffer first. E.g. if you're blitting a sprite onto a framebuffer, you'll want to translate the sprite to the correct location first like so:

framebuffer.copy_from(sprite.translated({x, y}));

Definition at line 996 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::crop(), Halide::Runtime::Buffer< T, D >::device_dirty(), Halide::Runtime::Buffer< T, D >::dim(), Halide::Runtime::Buffer< T, D >::dimensions(), dst, Halide::Runtime::Buffer< T, D >::for_each_value(), Halide::max(), and Halide::min().

Referenced by Halide::Runtime::Buffer< T, D >::copy().

◆ cropped() [1/2]

template<typename T = void, int D = 4>
Buffer<T, D> Halide::Runtime::Buffer< T, D >::cropped ( int  d,
int  min,
int  extent 
) const
inline

Make an image that refers to a sub-range of this image along the given dimension.

Does not assert the crop region is within the existing bounds. The cropped image drops any device handle.

Definition at line 1050 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::crop().

◆ crop() [1/2]

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::crop ( int  d,
int  min,
int  extent 
)
inline

Crop an image in-place along the given dimension.

Definition at line 1059 of file HalideBuffer.h.

References Halide::min().

Referenced by Halide::Runtime::Buffer< T, D >::copy_from(), and Halide::Runtime::Buffer< T, D >::cropped().

◆ cropped() [2/2]

template<typename T = void, int D = 4>
Buffer<T, D> Halide::Runtime::Buffer< T, D >::cropped ( const std::vector< std::pair< int, int >> &  rect) const
inline

Make an image that refers to a sub-rectangle of this image along the first N dimensions.

Does not assert the crop region is within the existing bounds. The cropped image drops any device handle.

Definition at line 1076 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::crop().

◆ crop() [2/2]

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::crop ( const std::vector< std::pair< int, int >> &  rect)
inline

Crop an image in-place along the first N dimensions.

Definition at line 1085 of file HalideBuffer.h.

References Halide::max().

◆ translated() [1/2]

template<typename T = void, int D = 4>
Buffer<T, D> Halide::Runtime::Buffer< T, D >::translated ( int  d,
int  dx 
) const
inline

Make an image which refers to the same data with using translated coordinates in the given dimension.

Positive values move the image data to the right or down relative to the coordinate system. Drops any device handle.

Definition at line 1098 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::translate().

◆ translate() [1/2]

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::translate ( int  d,
int  delta 
)
inline

Translate an image in-place along one dimension.

Definition at line 1105 of file HalideBuffer.h.

Referenced by Halide::Runtime::Buffer< T, D >::translated().

◆ translated() [2/2]

template<typename T = void, int D = 4>
Buffer<T, D> Halide::Runtime::Buffer< T, D >::translated ( const std::vector< int > &  delta)
inline

Make an image which refers to the same data translated along the first N dimensions.

Definition at line 1112 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::translate().

◆ translate() [2/2]

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::translate ( const std::vector< int > &  delta)
inline

Translate an image along the first N dimensions.

Definition at line 1119 of file HalideBuffer.h.

References Halide::max().

◆ set_min()

template<typename T = void, int D = 4>
template<typename ... Args>
void Halide::Runtime::Buffer< T, D >::set_min ( Args...  args)
inline

Set the min coordinate of an image in the first N dimensions.

Definition at line 1131 of file HalideBuffer.h.

◆ contains()

template<typename T = void, int D = 4>
template<typename ... Args>
bool Halide::Runtime::Buffer< T, D >::contains ( Args...  args)
inline

Test if a given coordinate is within the the bounds of an image.

Definition at line 1142 of file HalideBuffer.h.

◆ transposed()

template<typename T = void, int D = 4>
Buffer<T, D> Halide::Runtime::Buffer< T, D >::transposed ( int  d1,
int  d2 
) const
inline

Make an image which refers to the same data using a different ordering of the dimensions.

Definition at line 1155 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::transpose().

◆ transpose()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::transpose ( int  d1,
int  d2 
)
inline

◆ sliced()

template<typename T = void, int D = 4>
Buffer<T, D> Halide::Runtime::Buffer< T, D >::sliced ( int  d,
int  pos 
) const
inline

Make a lower-dimensional image that refers to one slice of this image.

Definition at line 1168 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::slice().

◆ slice()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::slice ( int  d,
int  pos 
)
inline

Slice an image in-place.

Definition at line 1175 of file HalideBuffer.h.

Referenced by Halide::Runtime::Buffer< T, D >::make_scalar(), and Halide::Runtime::Buffer< T, D >::sliced().

◆ embedded()

template<typename T = void, int D = 4>
Buffer<T, D> Halide::Runtime::Buffer< T, D >::embedded ( int  d,
int  pos 
) const
inline

Make a new image that views this image as a single slice in a higher-dimensional space.

The new dimension has extent one and the given min. This operation is the opposite of slice. As an example, the following condition is true:

im2 = im.embedded(1, 17);
&im(x, y, c) == &im2(x, 17, y, c);

Definition at line 1200 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::embed().

◆ embed()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::embed ( int  d,
int  pos 
)
inline

Embed an image in-place, increasing the dimensionality.

Definition at line 1209 of file HalideBuffer.h.

Referenced by Halide::Runtime::Buffer< T, D >::embedded().

◆ add_dimension()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::add_dimension ( )
inline

Add a new dimension with a min of zero and an extent of one.

The stride is the extent of the outermost dimension times its stride. The new dimension is the last dimension. This is a special case of embed.

Definition at line 1222 of file HalideBuffer.h.

References halide_dimension_t::stride.

◆ add_dimension_with_stride()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::add_dimension_with_stride ( int  s)
inline

Add a new dimension with a min of zero, an extent of one, and the specified stride.

The new dimension is the last dimension. This is a special case of embed.

Definition at line 1253 of file HalideBuffer.h.

◆ set_host_dirty()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::set_host_dirty ( bool  v = true)
inline

Methods for managing any GPU allocation.

Definition at line 1260 of file HalideBuffer.h.

◆ device_dirty()

template<typename T = void, int D = 4>
bool Halide::Runtime::Buffer< T, D >::device_dirty ( ) const
inline

Methods for managing any GPU allocation.

Definition at line 1265 of file HalideBuffer.h.

Referenced by Halide::Runtime::Buffer< T, D >::copy_from().

◆ host_dirty()

template<typename T = void, int D = 4>
bool Halide::Runtime::Buffer< T, D >::host_dirty ( ) const
inline

Methods for managing any GPU allocation.

Definition at line 1269 of file HalideBuffer.h.

◆ set_device_dirty()

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::set_device_dirty ( bool  v = true)
inline

Methods for managing any GPU allocation.

Definition at line 1273 of file HalideBuffer.h.

◆ copy_to_host()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::copy_to_host ( void *  ctx = nullptr)
inline

Methods for managing any GPU allocation.

Definition at line 1278 of file HalideBuffer.h.

◆ copy_to_device()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::copy_to_device ( const struct halide_device_interface_t device_interface,
void *  ctx = nullptr 
)
inline

Methods for managing any GPU allocation.

Definition at line 1285 of file HalideBuffer.h.

References halide_device_interface_t::copy_to_device.

◆ device_malloc()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::device_malloc ( const struct halide_device_interface_t device_interface,
void *  ctx = nullptr 
)
inline

Methods for managing any GPU allocation.

Definition at line 1292 of file HalideBuffer.h.

References halide_device_interface_t::device_malloc.

◆ device_free()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::device_free ( void *  ctx = nullptr)
inline

Methods for managing any GPU allocation.

Definition at line 1296 of file HalideBuffer.h.

References Halide::Runtime::Allocated, Halide::Runtime::DeviceRefCount::count, and Halide::Runtime::DeviceRefCount::ownership.

◆ device_wrap_native()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::device_wrap_native ( const struct halide_device_interface_t device_interface,
uint64_t  handle,
void *  ctx = nullptr 
)
inline

Methods for managing any GPU allocation.

Definition at line 1319 of file HalideBuffer.h.

References Halide::Runtime::DeviceRefCount::ownership, halide_device_interface_t::wrap_native, and Halide::Runtime::WrappedNative.

◆ device_detach_native()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::device_detach_native ( void *  ctx = nullptr)
inline

Methods for managing any GPU allocation.

Definition at line 1327 of file HalideBuffer.h.

References Halide::Runtime::DeviceRefCount::count, Halide::Runtime::DeviceRefCount::ownership, and Halide::Runtime::WrappedNative.

◆ device_and_host_malloc()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::device_and_host_malloc ( const struct halide_device_interface_t device_interface,
void *  ctx = nullptr 
)
inline

Methods for managing any GPU allocation.

Definition at line 1349 of file HalideBuffer.h.

References halide_device_interface_t::device_and_host_malloc.

◆ device_and_host_free()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::device_and_host_free ( const struct halide_device_interface_t device_interface,
void *  ctx = nullptr 
)
inline

Methods for managing any GPU allocation.

Definition at line 1353 of file HalideBuffer.h.

References Halide::Runtime::AllocatedDeviceAndHost, Halide::Runtime::DeviceRefCount::count, and Halide::Runtime::DeviceRefCount::ownership.

◆ device_sync()

template<typename T = void, int D = 4>
int Halide::Runtime::Buffer< T, D >::device_sync ( void *  ctx = nullptr)
inline

Methods for managing any GPU allocation.

Definition at line 1376 of file HalideBuffer.h.

◆ has_device_allocation()

template<typename T = void, int D = 4>
bool Halide::Runtime::Buffer< T, D >::has_device_allocation ( ) const
inline

Methods for managing any GPU allocation.

Definition at line 1384 of file HalideBuffer.h.

◆ device_ownership()

template<typename T = void, int D = 4>
BufferDeviceOwnership Halide::Runtime::Buffer< T, D >::device_ownership ( ) const
inline

Return the method by which the device field is managed.

Definition at line 1389 of file HalideBuffer.h.

References Halide::Runtime::Allocated, and Halide::Runtime::DeviceRefCount::ownership.

◆ make_interleaved() [1/4]

template<typename T = void, int D = 4>
static Buffer<void, D> Halide::Runtime::Buffer< T, D >::make_interleaved ( halide_type_t  t,
int  width,
int  height,
int  channels 
)
inlinestatic

If you use the (x, y, c) indexing convention, then Halide Buffers are stored planar by default.

This function constructs an interleaved RGB or RGBA image that can still be indexed using (x, y, c). Passing it to a generator requires that the generator has been compiled with support for interleaved (also known as packed or chunky) memory layouts.

Definition at line 1403 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::transpose().

Referenced by Halide::Buffer<>::make_interleaved().

◆ make_interleaved() [2/4]

template<typename T = void, int D = 4>
static Buffer<T, D> Halide::Runtime::Buffer< T, D >::make_interleaved ( int  width,
int  height,
int  channels 
)
inlinestatic

If you use the (x, y, c) indexing convention, then Halide Buffers are stored planar by default.

This function constructs an interleaved RGB or RGBA image that can still be indexed using (x, y, c). Passing it to a generator requires that the generator has been compiled with support for interleaved (also known as packed or chunky) memory layouts.

Definition at line 1416 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::transpose().

◆ make_interleaved() [3/4]

template<typename T = void, int D = 4>
static Buffer<add_const_if_T_is_const<void>, D> Halide::Runtime::Buffer< T, D >::make_interleaved ( halide_type_t  t,
T *  data,
int  width,
int  height,
int  channels 
)
inlinestatic

Wrap an existing interleaved image.

Definition at line 1425 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::transpose().

◆ make_interleaved() [4/4]

template<typename T = void, int D = 4>
static Buffer<T, D> Halide::Runtime::Buffer< T, D >::make_interleaved ( T *  data,
int  width,
int  height,
int  channels 
)
inlinestatic

Wrap an existing interleaved image.

Definition at line 1433 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::transpose().

◆ make_scalar() [1/2]

template<typename T = void, int D = 4>
static Buffer<add_const_if_T_is_const<void>, D> Halide::Runtime::Buffer< T, D >::make_scalar ( halide_type_t  t)
inlinestatic

Make a zero-dimensional Buffer.

Definition at line 1441 of file HalideBuffer.h.

References buf, and Halide::Runtime::Buffer< T, D >::slice().

◆ make_scalar() [2/2]

template<typename T = void, int D = 4>
static Buffer<T, D> Halide::Runtime::Buffer< T, D >::make_scalar ( )
inlinestatic

Make a zero-dimensional Buffer.

Definition at line 1448 of file HalideBuffer.h.

References buf, and Halide::Runtime::Buffer< T, D >::slice().

Referenced by Halide::Buffer<>::make_scalar().

◆ make_with_shape_of()

template<typename T = void, int D = 4>
template<typename T2 , int D2>
static Buffer<T, D> Halide::Runtime::Buffer< T, D >::make_with_shape_of ( Buffer< T2, D2 >  src,
void *(*)(size_t allocate_fn = nullptr,
void(*)(void *)  deallocate_fn = nullptr 
)
inlinestatic

Make a buffer with the same shape and memory nesting order as another buffer.

It may have a different type.

Definition at line 1457 of file HalideBuffer.h.

References Halide::Runtime::Buffer< T, D >::dim(), halide_buffer_t::dim, Halide::Runtime::Buffer< T, D >::dimensions(), dst, halide_dimension_t::extent, HALIDE_ALWAYS_INLINE, halide_dimension_t::stride, and Halide::Runtime::Buffer< T, D >::transpose().

Referenced by Halide::Buffer<>::make_with_shape_of().

◆ data() [1/2]

template<typename T = void, int D = 4>
T* Halide::Runtime::Buffer< T, D >::data ( )
inline

Get a pointer to the address of the min coordinate.

Definition at line 1540 of file HalideBuffer.h.

◆ data() [2/2]

template<typename T = void, int D = 4>
const T* Halide::Runtime::Buffer< T, D >::data ( ) const
inline

Get a pointer to the address of the min coordinate.

Definition at line 1544 of file HalideBuffer.h.

References HALIDE_ALWAYS_INLINE.

◆ operator()() [1/6]

template<typename T = void, int D = 4>
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
HALIDE_ALWAYS_INLINE const not_void_T& Halide::Runtime::Buffer< T, D >::operator() ( int  first,
Args...  rest 
) const
inline

Access elements.

Use im(...) to get a reference to an element, and use &im(...) to get the address of an element. If you pass fewer arguments than the buffer has dimensions, the rest are treated as their min coordinate. The non-const versions set the host_dirty flag to true.

Definition at line 1559 of file HalideBuffer.h.

References HALIDE_ALWAYS_INLINE.

◆ operator()() [2/6]

template<typename T = void, int D = 4>
HALIDE_ALWAYS_INLINE const not_void_T& Halide::Runtime::Buffer< T, D >::operator() ( ) const
inline

Access elements.

Use im(...) to get a reference to an element, and use &im(...) to get the address of an element. If you pass fewer arguments than the buffer has dimensions, the rest are treated as their min coordinate. The non-const versions set the host_dirty flag to true.

Definition at line 1568 of file HalideBuffer.h.

References HALIDE_ALWAYS_INLINE.

◆ operator()() [3/6]

template<typename T = void, int D = 4>
HALIDE_ALWAYS_INLINE const not_void_T& Halide::Runtime::Buffer< T, D >::operator() ( const int *  pos) const
inline

Access elements.

Use im(...) to get a reference to an element, and use &im(...) to get the address of an element. If you pass fewer arguments than the buffer has dimensions, the rest are treated as their min coordinate. The non-const versions set the host_dirty flag to true.

Definition at line 1577 of file HalideBuffer.h.

References HALIDE_ALWAYS_INLINE.

◆ operator()() [4/6]

template<typename T = void, int D = 4>
template<typename ... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
HALIDE_ALWAYS_INLINE not_void_T& Halide::Runtime::Buffer< T, D >::operator() ( int  first,
Args...  rest 
)
inline

Access elements.

Use im(...) to get a reference to an element, and use &im(...) to get the address of an element. If you pass fewer arguments than the buffer has dimensions, the rest are treated as their min coordinate. The non-const versions set the host_dirty flag to true.

Definition at line 1587 of file HalideBuffer.h.

References HALIDE_ALWAYS_INLINE.

◆ operator()() [5/6]

template<typename T = void, int D = 4>
HALIDE_ALWAYS_INLINE not_void_T& Halide::Runtime::Buffer< T, D >::operator() ( )
inline

Access elements.

Use im(...) to get a reference to an element, and use &im(...) to get the address of an element. If you pass fewer arguments than the buffer has dimensions, the rest are treated as their min coordinate. The non-const versions set the host_dirty flag to true.

Definition at line 1596 of file HalideBuffer.h.

References HALIDE_ALWAYS_INLINE.

◆ operator()() [6/6]

template<typename T = void, int D = 4>
HALIDE_ALWAYS_INLINE not_void_T& Halide::Runtime::Buffer< T, D >::operator() ( const int *  pos)
inline

Access elements.

Use im(...) to get a reference to an element, and use &im(...) to get the address of an element. If you pass fewer arguments than the buffer has dimensions, the rest are treated as their min coordinate. The non-const versions set the host_dirty flag to true.

Definition at line 1605 of file HalideBuffer.h.

◆ fill() [1/2]

template<typename T = void, int D = 4>
void Halide::Runtime::Buffer< T, D >::fill ( not_void_T  val)
inline

◆ for_each_value()

template<typename T = void, int D = 4>
template<typename Fn , typename ... Args, int N = sizeof...(Args) + 1>
void Halide::Runtime::Buffer< T, D >::for_each_value ( Fn &&  f,
Args...  other_buffers 
)
inline

Call a function on every value in the buffer, and the corresponding values in some number of other buffers of the same size.

The function should take a reference, const reference, or value of the correct type for each buffer. This effectively lifts a function of scalars to an element-wise function of buffers. This produces code that the compiler can autovectorize. This is slightly cheaper than for_each_element, because it does not need to track the coordinates.

Definition at line 1711 of file HalideBuffer.h.

References HALIDE_ALLOCA, HALIDE_ALWAYS_INLINE, Halide::max(), and Halide::min().

Referenced by Halide::Runtime::Buffer< T, D >::copy_from().

◆ for_each_element()

template<typename T = void, int D = 4>
template<typename Fn >
void Halide::Runtime::Buffer< T, D >::for_each_element ( Fn &&  f) const
inline

Call a function at each site in a buffer.

This is likely to be much slower than using Halide code to populate a buffer, but is convenient for tests. If the function has more arguments than the buffer has dimensions, the remaining arguments will be zero. If it has fewer arguments than the buffer has dimensions then the last few dimensions of the buffer are not iterated over. For example, the following code exploits this to set a floating point RGB image to red:

Buffer<float, 3> im(100, 100, 3);
im.for_each_element([&](int x, int y) {
im(x, y, 0) = 1.0f;
im(x, y, 1) = 0.0f;
im(x, y, 2) = 0.0f:
});

The compiled code is equivalent to writing the a nested for loop, and compilers are capable of optimizing it in the same way.

If the callable can be called with an int * as the sole argument, that version is called instead. Each location in the buffer is passed to it in a coordinate array. This version is higher-overhead than the variadic version, but is useful for writing generic code that accepts buffers of arbitrary dimensionality. For example, the following sets the value at all sites in an arbitrary-dimensional buffer to their first coordinate:

im.for_each_element([&](const int *pos) {im(pos) = pos[0];});

It is also possible to use for_each_element to iterate over entire rows or columns by cropping the buffer to a single column or row respectively and iterating over elements of the result. For example, to set the diagonal of the image to 1 by iterating over the columns:

Buffer<float, 3> im(100, 100, 3);
im.sliced(1, 0).for_each_element([&](int x, int c) {
im(x, x, c) = 1.0f;
});

Or, assuming the memory layout is known to be dense per row, one can memset each row of an image like so:

Buffer<float, 3> im(100, 100, 3);
im.sliced(0, 0).for_each_element([&](int y, int c) {
memset(&im(0, y, c), 0, sizeof(float) * im.width());
});

Definition at line 1944 of file HalideBuffer.h.

References buf, and HALIDE_ALLOCA.

◆ fill() [2/2]

template<typename T = void, int D = 4>
template<typename Fn , typename = typename std::enable_if<!std::is_arithmetic<typename std::decay<Fn>::type>::value>::type>
void Halide::Runtime::Buffer< T, D >::fill ( Fn &&  f)
inline

Fill a buffer by evaluating a callable at every site.

The callable should look much like a callable passed to for_each_element, but it should return the value that should be stored to the coordinate corresponding to the arguments.

Definition at line 1976 of file HalideBuffer.h.

◆ is_bounds_query()

template<typename T = void, int D = 4>
bool Halide::Runtime::Buffer< T, D >::is_bounds_query ( )
inline

Check if an input buffer passed extern stage is a querying bounds.

Compared to doing the host pointer check directly, this both adds clarity to code and will facilitate moving to another representation for bounds query arguments.

Definition at line 1986 of file HalideBuffer.h.

Member Data Documentation

◆ has_static_halide_type

template<typename T = void, int D = 4>
constexpr bool Halide::Runtime::Buffer< T, D >::has_static_halide_type = !T_is_void
static

True if the Halide type is not void (or const void).

Definition at line 140 of file HalideBuffer.h.


The documentation for this class was generated from the following file: