Halide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Halide::Buffer< T, D > Class Template Reference

A templated Buffer class that wraps 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

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 buffer_t &buf)
 Make a buffer from a buffer_t. More...
 
 Buffer (halide_type_t t, const buffer_t &buf)
 
template<typename T2 , int D2>
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...
 
template<typename T2 , int D2>
 Buffer (const Buffer< T2, D2 > &other)
 Make a Buffer<T> from another Buffer<T> of possibly-different dimensionality and type. More...
 
 Buffer (const Buffer< T, D > &other)
 
template<typename T2 , int D2>
 Buffer (Buffer< T2, D2 > &&other)
 Move-construct an Buffer from another Buffer of possibly-different dimensionality. More...
 
 Buffer (Buffer< T, D > &&other)
 
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)
 
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)
 
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...
 
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...
 
template<typename... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
 Buffer (int first, Args...rest)
 Allocate a new image of the given size. 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...
 
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, 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 (halide_type_t t, 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 buffer_t * ()
 Provide a cast operator to buffer_t *, so that instances can be passed directly to Halide filters. 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...
 
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...
 
void 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...
 
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-1 > 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+1 > 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...
 
template<typename Fn >
void for_each_element (Fn f) const
 Call a callable at each location within the image. More...
 
void fill (not_void_T val)
 Set every value in the buffer to the given value. 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_traw_buffer ()
 Get a pointer to the raw buffer_t this wraps. More...
 
const buffer_traw_buffer () const
 Get a pointer to the raw buffer_t this wraps. More...
 
const void * host_ptr () const
 Access to the untyped host pointer. More...
 
void * host_ptr ()
 Access to the untyped host pointer. 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...
 
void copy_to_host (void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
void copy_to_device (const struct halide_device_interface *device_interface, void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
void device_free (void *ctx=nullptr)
 Methods for managing any GPU allocation. More...
 
void device_sync (void *ctx=nullptr)
 Methods for managing any GPU allocation. 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>
ALWAYS_INLINE const not_void_T & operator() (int first, Args...rest) const
 Access elements. More...
 
ALWAYS_INLINE const not_void_T & operator() () const
 Access elements. More...
 
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>
ALWAYS_INLINE not_void_T & operator() (int first, Args...rest)
 Access elements. More...
 
ALWAYS_INLINE not_void_T & operator() ()
 Access elements. More...
 
ALWAYS_INLINE not_void_T & operator() (const int *pos)
 Access elements. More...
 
template<typename... Args>
auto operator() (Args...args) const -> decltype(image_accessor(*this, args...))
 Other calls to operator()(Args...) get redirected to a call to image_accessor(const Buffer<T, D> &, Args...). More...
 
template<typename... Args>
auto operator() (Args...args) -> decltype(image_accessor(*this, args...))
 Other calls to operator()(Args...) get redirected to a call to image_accessor(const Buffer<T, D> &, Args...). More...
 

Static Public Member Functions

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< 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< 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...
 

Detailed Description

template<typename T, int D>
class Halide::Buffer< T, D >

A templated Buffer class that wraps 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 buffer_t is minimal - it uses another ~100 bytes on the stack, and does no dynamic allocations when using it to represent existing memory. This overhead will shrink further in the future once buffer_t is deprecated.

The template parameter T is the element type, and D is the maximum number of dimensions. It must be less than or equal to 4 for now. For buffers where the element type is not known at compile time, use void for T.

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.

For accessing the shape and type, this class provides both the buffer_t-style interface (extent(i), min(i), and stride(i)), and also the interface of the yet-to-come halide_buffer_t, which will replace buffer_t. This is intended to allow a gradual transition to halide_buffer_t. New code should access the shape via dim(i).extent(), dim(i).min(), and dim(i).stride()

Examples:
tutorial/lesson_01_basics.cpp, tutorial/lesson_02_input_image.cpp, tutorial/lesson_03_debugging_1.cpp, tutorial/lesson_04_debugging_2.cpp, tutorial/lesson_05_scheduling_1.cpp, tutorial/lesson_06_realizing_over_shifted_domains.cpp, tutorial/lesson_07_multi_stage_pipelines.cpp, tutorial/lesson_08_scheduling_2.cpp, tutorial/lesson_09_update_definitions.cpp, tutorial/lesson_12_using_the_gpu.cpp, and tutorial/lesson_13_tuples.cpp.

Definition at line 44 of file HalideBuffer.h.

Member Typedef Documentation

template<typename T, int D>
typedef T Halide::Buffer< T, D >::ElemType

Definition at line 281 of file HalideBuffer.h.

Constructor & Destructor Documentation

template<typename T, int D>
Halide::Buffer< T, D >::Buffer ( )
inline

Definition at line 392 of file HalideBuffer.h.

template<typename T, int D>
Halide::Buffer< T, D >::Buffer ( const buffer_t buf)
inline

Make a buffer from a buffer_t.

Definition at line 395 of file HalideBuffer.h.

template<typename T, int D>
Halide::Buffer< T, D >::Buffer ( halide_type_t  t,
const buffer_t buf 
)
inline

Definition at line 400 of file HalideBuffer.h.

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

Make a Buffer<T> from another Buffer<T> of possibly-different dimensionality and type.

Asserts if D is less than the dimensionality of the argument, or if there's a type mismatch.

Definition at line 430 of file HalideBuffer.h.

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

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

Definition at line 438 of file HalideBuffer.h.

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

Move-construct an Buffer from another Buffer of possibly-different dimensionality.

Asserts if D is less than the dimensionality of the argument, or if there's a type mismatch.

Definition at line 450 of file HalideBuffer.h.

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

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

Definition at line 458 of file HalideBuffer.h.

template<typename T, int D>
template<typename... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
Halide::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 577 of file HalideBuffer.h.

References Halide::Buffer< T, D >::allocate(), Halide::Buffer< T, D >::check_overflow(), and buffer_t::elem_size.

template<typename T, int D>
template<typename... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
Halide::Buffer< T, D >::Buffer ( int  first,
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 598 of file HalideBuffer.h.

References Halide::Buffer< T, D >::allocate(), Halide::Buffer< T, D >::check_overflow(), and buffer_t::elem_size.

template<typename T, int D>
Halide::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 614 of file HalideBuffer.h.

References Halide::Buffer< T, D >::allocate(), Halide::Buffer< T, D >::check_overflow(), and buffer_t::elem_size.

template<typename T, int D>
template<typename Array , size_t N>
Halide::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.

Definition at line 631 of file HalideBuffer.h.

References buffer_t::elem_size, and buffer_t::host.

template<typename T, int D>
template<typename... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
Halide::Buffer< T, D >::Buffer ( halide_type_t  t,
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.

Definition at line 645 of file HalideBuffer.h.

References buffer_t::elem_size, buffer_t::host, and Halide::Runtime::Internal::t.

template<typename T, int D>
template<typename... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
Halide::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.

Definition at line 665 of file HalideBuffer.h.

References buffer_t::elem_size, and buffer_t::host.

template<typename T, int D>
Halide::Buffer< T, D >::Buffer ( halide_type_t  t,
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.

Definition at line 680 of file HalideBuffer.h.

References buffer_t::elem_size, halide_dimension_t::extent, buffer_t::extent, buffer_t::host, halide_dimension_t::min, buffer_t::min, halide_dimension_t::stride, buffer_t::stride, and Halide::Runtime::Internal::t.

template<typename T, int D>
Halide::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.

Definition at line 699 of file HalideBuffer.h.

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

template<typename T, int D>
Halide::Buffer< T, D >::~Buffer ( )
inline

Destructor.

Will release any underlying owned allocation if this is the last reference to it.

Definition at line 714 of file HalideBuffer.h.

Member Function Documentation

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

Access to the mins, strides, extents.

Will be deprecated. Do not use.

Definition at line 338 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), and Halide::Buffer< T, D >::Dimension::min().

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

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

Access to the mins, strides, extents.

Will be deprecated. Do not use.

Definition at line 339 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), and Halide::Buffer< T, D >::Dimension::extent().

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

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

Access to the mins, strides, extents.

Will be deprecated. Do not use.

Definition at line 340 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), and Halide::Buffer< T, D >::Dimension::stride().

template<typename T, int D>
size_t Halide::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 345 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), Halide::Buffer< T, D >::dimensions(), and Halide::Buffer< T, D >::Dimension::extent().

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

Get the type of the elements.

Definition at line 359 of file HalideBuffer.h.

template<typename T, int D>
T* Halide::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 365 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), Halide::Buffer< T, D >::dimensions(), buffer_t::elem_size, Halide::Buffer< T, D >::Dimension::extent(), buffer_t::host, and Halide::Buffer< T, D >::Dimension::stride().

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

template<typename T, int D>
T* Halide::Buffer< T, D >::end ( ) const
inline
template<typename T, int D>
size_t Halide::Buffer< T, D >::size_in_bytes ( ) const
inline

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

Definition at line 388 of file HalideBuffer.h.

References Halide::Buffer< T, D >::begin(), and Halide::Buffer< T, D >::end().

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

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

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

Definition at line 410 of file HalideBuffer.h.

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

Referenced by Halide::Buffer< T, D >::Buffer(), and Halide::Buffer< T, D >::operator=().

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

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

Asserts if D is less than the dimensionality of the argument, or if there's a type mismatch.

Definition at line 469 of file HalideBuffer.h.

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

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

Definition at line 484 of file HalideBuffer.h.

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

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

Asserts if D is less than the dimensionality of the argument, or if there's a type mismatch.

Definition at line 502 of file HalideBuffer.h.

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

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

Definition at line 517 of file HalideBuffer.h.

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

Check the product of the extents fits in memory.

Definition at line 532 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), Halide::Buffer< T, D >::dimensions(), and Halide::Buffer< T, D >::Dimension::extent().

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

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

Get a pointer to the raw buffer_t this wraps.

Definition at line 720 of file HalideBuffer.h.

References buf.

template<typename T, int D>
const buffer_t* Halide::Buffer< T, D >::raw_buffer ( ) const
inline

Get a pointer to the raw buffer_t this wraps.

Definition at line 724 of file HalideBuffer.h.

References buf.

template<typename T, int D>
const void* Halide::Buffer< T, D >::host_ptr ( ) const
inline

Access to the untyped host pointer.

Definition at line 731 of file HalideBuffer.h.

References buffer_t::host.

template<typename T, int D>
void* Halide::Buffer< T, D >::host_ptr ( )
inline

Access to the untyped host pointer.

Definition at line 734 of file HalideBuffer.h.

References buffer_t::host.

template<typename T, int D>
Halide::Buffer< T, D >::operator buffer_t * ( )
inline

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

Definition at line 741 of file HalideBuffer.h.

References buf.

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

Conventional names for the first three dimensions.

Definition at line 747 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), Halide::Buffer< T, D >::dimensions(), and Halide::Buffer< T, D >::Dimension::extent().

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

Conventional names for the first three dimensions.

Definition at line 750 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), Halide::Buffer< T, D >::dimensions(), and Halide::Buffer< T, D >::Dimension::extent().

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

Conventional names for the first three dimensions.

Definition at line 753 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), Halide::Buffer< T, D >::dimensions(), and Halide::Buffer< T, D >::Dimension::extent().

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

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

Definition at line 760 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), and Halide::Buffer< T, D >::Dimension::min().

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

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

Definition at line 764 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), and Halide::Buffer< T, D >::Dimension::max().

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

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

Definition at line 768 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), and Halide::Buffer< T, D >::Dimension::min().

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

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

Definition at line 772 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dim(), and Halide::Buffer< T, D >::Dimension::max().

template<typename T, int D>
Buffer<T, D> Halide::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 781 of file HalideBuffer.h.

References Halide::Buffer< T, D >::allocate(), Halide::Buffer< T, D >::dim(), Halide::Buffer< T, D >::dimensions(), dst, buffer_t::elem_size, Halide::Buffer< T, D >::for_each_element(), memcpy(), Halide::Buffer< T, D >::Dimension::min(), Halide::Buffer< T, D >::sliced(), Halide::Buffer< T, D >::Dimension::stride(), and Halide::Buffer< T, D >::transpose().

template<typename T, int D>
Buffer<T, D> Halide::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 831 of file HalideBuffer.h.

References Halide::Buffer< T, D >::crop(), and buffer_t::dev.

template<typename T, int D>
void Halide::Buffer< T, D >::crop ( int  d,
int  min,
int  extent 
)
inline
template<typename T, int D>
Buffer<T, D> Halide::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 856 of file HalideBuffer.h.

References Halide::Buffer< T, D >::crop(), and buffer_t::dev.

template<typename T, int D>
void Halide::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 868 of file HalideBuffer.h.

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

template<typename T, int D>
Buffer<T, D> Halide::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 878 of file HalideBuffer.h.

References buffer_t::dev, and Halide::Buffer< T, D >::translate().

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

Translate an image in-place along one dimension.

Definition at line 886 of file HalideBuffer.h.

References buffer_t::min.

Referenced by Halide::Buffer< T, D >::embed(), Halide::Buffer< T, D >::embedded(), Halide::Buffer< T, D >::translate(), and Halide::Buffer< T, D >::translated().

template<typename T, int D>
void Halide::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 892 of file HalideBuffer.h.

References buffer_t::dev, and Halide::Buffer< T, D >::translate().

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

Translate an image along the first N dimensions.

Definition at line 900 of file HalideBuffer.h.

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

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

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

Examples:
tutorial/lesson_07_multi_stage_pipelines.cpp.

Definition at line 908 of file HalideBuffer.h.

References Halide::Buffer< T, D >::dimensions(), and buffer_t::min.

template<typename T, int D>
Buffer<T, D> Halide::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 919 of file HalideBuffer.h.

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

template<typename T, int D>
void Halide::Buffer< T, D >::transpose ( int  d1,
int  d2 
)
inline
template<typename T, int D>
Buffer<T, D-1> Halide::Buffer< T, D >::sliced ( int  d,
int  pos 
) const
inline

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

Drops any device handle.

Definition at line 934 of file HalideBuffer.h.

References buffer_t::dev, and Halide::Buffer< T, D >::slice().

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

template<typename T, int D>
Buffer<T, D+1> Halide::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. Drops any device handle. 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 967 of file HalideBuffer.h.

References Halide::Buffer< T, D >::add_dimension(), buffer_t::dev, Halide::Buffer< T, D >::dimensions(), Halide::Buffer< T, D >::translate(), and Halide::Buffer< T, D >::transpose().

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

Embed an image in-place, increasing the dimensionality.

Requires that the actual number of dimensions is less than template parameter D

Definition at line 982 of file HalideBuffer.h.

References Halide::Buffer< T, D >::add_dimension(), Halide::Buffer< T, D >::dimensions(), Halide::Buffer< T, D >::translate(), and Halide::Buffer< T, D >::transpose().

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

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

The new dimension is the last dimension. This is a special case of embed. It requires that the actual number of dimensions is less than template parameter D.

Definition at line 995 of file HalideBuffer.h.

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

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

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

Call a callable at each location within the image.

See for_each_element below for more details.

Definition at line 1011 of file HalideBuffer.h.

References Halide::for_each_element().

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

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

Methods for managing any GPU allocation.

Definition at line 1017 of file HalideBuffer.h.

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

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

Methods for managing any GPU allocation.

Definition at line 1021 of file HalideBuffer.h.

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

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

Methods for managing any GPU allocation.

Definition at line 1025 of file HalideBuffer.h.

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

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

Methods for managing any GPU allocation.

Definition at line 1029 of file HalideBuffer.h.

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

Methods for managing any GPU allocation.

Definition at line 1033 of file HalideBuffer.h.

References Halide::Buffer< T, D >::device_dirty(), and halide_copy_to_host().

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

Methods for managing any GPU allocation.

Definition at line 1039 of file HalideBuffer.h.

References halide_copy_to_device(), and Halide::Buffer< T, D >::host_dirty().

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

Methods for managing any GPU allocation.

Definition at line 1045 of file HalideBuffer.h.

References halide_device_free().

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

Methods for managing any GPU allocation.

Definition at line 1049 of file HalideBuffer.h.

References halide_device_sync().

template<typename T, int D>
static Buffer<void, D> Halide::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 1060 of file HalideBuffer.h.

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

template<typename T, int D>
static Buffer<T, D> Halide::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 1074 of file HalideBuffer.h.

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

template<typename T, int D>
static Buffer<void, D> Halide::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 1083 of file HalideBuffer.h.

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

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

Wrap an existing interleaved image.

Definition at line 1092 of file HalideBuffer.h.

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

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

Make a zero-dimensional Buffer.

Definition at line 1101 of file HalideBuffer.h.

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

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

Make a zero-dimensional Buffer.

Definition at line 1108 of file HalideBuffer.h.

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

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

Get a pointer to the address of the min coordinate.

Definition at line 1140 of file HalideBuffer.h.

References buffer_t::host.

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

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

Get a pointer to the address of the min coordinate.

Definition at line 1144 of file HalideBuffer.h.

References buffer_t::host.

template<typename T, int D>
template<typename... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
ALWAYS_INLINE const not_void_T& Halide::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.

Definition at line 1158 of file HalideBuffer.h.

template<typename T, int D>
ALWAYS_INLINE const not_void_T& Halide::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.

Definition at line 1166 of file HalideBuffer.h.

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

template<typename T, int D>
ALWAYS_INLINE const not_void_T& Halide::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.

Definition at line 1174 of file HalideBuffer.h.

template<typename T, int D>
template<typename... Args, typename = typename std::enable_if<AllInts<Args...>::value>::type>
ALWAYS_INLINE not_void_T& Halide::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.

Definition at line 1183 of file HalideBuffer.h.

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

template<typename T, int D>
ALWAYS_INLINE not_void_T& Halide::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.

Definition at line 1192 of file HalideBuffer.h.

References Halide::Buffer< T, D >::data(), and Halide::Buffer< T, D >::set_host_dirty().

template<typename T, int D>
ALWAYS_INLINE not_void_T& Halide::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.

Definition at line 1201 of file HalideBuffer.h.

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

template<typename T, int D>
template<typename... Args>
auto Halide::Buffer< T, D >::operator() ( Args...  args) const -> decltype(image_accessor(*this, args...))
inline

Other calls to operator()(Args...) get redirected to a call to image_accessor(const Buffer<T, D> &, Args...).

This makes it possible for later code to add new Buffer access methods for types not convertible to int (e.g. Exprs). To add a custom accessor, define an overload of image_accessor that takes the expected arguments. See test/correctness/custom_image_accessor.cpp for an example.

Definition at line 1218 of file HalideBuffer.h.

References Halide::image_accessor().

template<typename T, int D>
template<typename... Args>
auto Halide::Buffer< T, D >::operator() ( Args...  args) -> decltype(image_accessor(*this, args...))
inline

Other calls to operator()(Args...) get redirected to a call to image_accessor(const Buffer<T, D> &, Args...).

This makes it possible for later code to add new Buffer access methods for types not convertible to int (e.g. Exprs). To add a custom accessor, define an overload of image_accessor that takes the expected arguments. See test/correctness/custom_image_accessor.cpp for an example.

Definition at line 1224 of file HalideBuffer.h.

References Halide::image_accessor().

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

Set every value in the buffer to the given value.

Definition at line 1254 of file HalideBuffer.h.


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