diff options
author | David Sorber <david.sorber@blacklynx.tech> | 2021-07-29 11:34:37 -0400 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-10-25 11:27:01 -0400 |
commit | f3c558d88bc68d865f823c31e7d9aa78b3feab59 (patch) | |
tree | 026d8ff5568bc2c5ab731df29d87901cf1177e00 /gnuradio-runtime/include/gnuradio/buffer.h | |
parent | 788827ae116bef871e144abd39b1e4482208eabe (diff) |
runtime: Custom Buffer/Accelerator Device Support - Milestone 2
Completion of custom buffer/accelerator device support changes:
* Improved custom buffer interface by removing awkward memory
allocation functions from the block class
* Increased flexibility for creating custom buffers by allowing
creation of buffer_single_mapped subclasses
* Fully incorporated data movement abstraction into the custom
buffer interface and the runtime itself; accelerated blocks are no
longer directly responsible for their own data movement
* Zero copy back-to-back accelerated blocks are now supported (data
no longer needs to be moved back to the host between each block)
Signed-off-by: David Sorber <david.sorber@blacklynx.tech>
Signed-off-by: Mike Mason <mike.mason@blacklynx.tech>
Diffstat (limited to 'gnuradio-runtime/include/gnuradio/buffer.h')
-rw-r--r-- | gnuradio-runtime/include/gnuradio/buffer.h | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/gnuradio-runtime/include/gnuradio/buffer.h b/gnuradio-runtime/include/gnuradio/buffer.h index 037fade172..96daf3adcd 100644 --- a/gnuradio-runtime/include/gnuradio/buffer.h +++ b/gnuradio-runtime/include/gnuradio/buffer.h @@ -12,11 +12,13 @@ #define INCLUDED_GR_RUNTIME_BUFFER_H #include <gnuradio/api.h> +#include <gnuradio/buffer_context.h> #include <gnuradio/custom_lock.h> #include <gnuradio/logger.h> #include <gnuradio/runtime_types.h> #include <gnuradio/tags.h> #include <gnuradio/thread/thread.h> + #include <boost/weak_ptr.hpp> #include <iostream> #include <map> @@ -29,7 +31,10 @@ class vmcircbuf; class buffer_reader; class buffer_reader_sm; -enum class BufferMappingType { DoubleMapped, SingleMapped }; +enum class buffer_mapping_type { double_mapped, single_mapped }; + +typedef void* (*memcpy_func_t)(void* dest, const void* src, std::size_t count); +typedef void* (*memmove_func_t)(void* dest, const void* src, std::size_t count); /*! * \brief Allocate a buffer that holds at least \p nitems of size \p sizeof_item. @@ -40,11 +45,18 @@ enum class BufferMappingType { DoubleMapped, SingleMapped }; * * \param nitems is the minimum number of items the buffer will hold. * \param sizeof_item is the size of an item in bytes. + * \param downstream_lcm_nitems is the least common multiple of the items to + * read by downstream block(s) + * \param downstream_max_out_mult is the maximum output multiple of all + * downstream blocks * \param link is the block that writes to this buffer. + * \param buf_owner is the block that owns the buffer which may or may not + * be the same as the block that writes to this buffer */ GR_RUNTIME_API buffer_sptr make_buffer(int nitems, size_t sizeof_item, uint64_t downstream_lcm_nitems, + uint32_t downstream_max_out_mult, block_sptr link = block_sptr(), block_sptr buf_owner = block_sptr()); @@ -63,7 +75,7 @@ public: /*! * \brief return the buffer's mapping type */ - BufferMappingType get_mapping_type() { return d_buf_map_type; } + buffer_mapping_type get_mapping_type() { return d_buf_map_type; } /*! * \brief return number of items worth of space available for writing @@ -89,6 +101,13 @@ public: virtual void* write_pointer(); /*! + * \brief return pointer to read buffer. + * + * The return value points to at least items_available() items. + */ + virtual const void* _read_pointer(unsigned int read_index); + + /*! * \brief tell buffer that we wrote \p nitems into it */ void update_write_pointer(int nitems); @@ -118,6 +137,8 @@ public: uint64_t get_downstream_lcm_nitems() { return d_downstream_lcm_nitems; } + uint32_t get_max_reader_output_multiple() { return d_max_reader_output_multiple; } + virtual void update_reader_block_history(unsigned history, int delay) { d_max_reader_history = std::max(d_max_reader_history, history); @@ -167,6 +188,32 @@ public: } /*! + * \brief Function to be executed after this object's owner completes the + * call to general_work() + */ + virtual void post_work(int nitems) = 0; + + /*! + * \brief Returns true when the current thread is ready to call the callback, + * false otherwise. Note if input_blocked_callback is overridden then this + * function should also be overridden. + */ + virtual bool input_blkd_cb_ready(int items_required, unsigned read_index) + { + return false; + } + + /*! + * \brief Callback function that the scheduler will call when it determines + * that the input is blocked. Override this function if needed. + */ + virtual bool + input_blocked_callback(int items_required, int items_avail, unsigned read_index) + { + return false; + } + + /*! * \brief Returns true if the current thread is ready to execute * output_blocked_callback(), false otherwise. Note if the default * output_blocked_callback is overridden this function should also be @@ -220,6 +267,11 @@ public: // ------------------------------------------------------------------------- + /*! + * \brief Assign buffer context + */ + void set_context(const buffer_context& context); + private: friend class buffer_reader; friend class buffer_reader_sm; @@ -236,7 +288,7 @@ private: protected: char* d_base; // base address of buffer inside d_vmcircbuf. unsigned int d_bufsize; // in items - BufferMappingType d_buf_map_type; + buffer_mapping_type d_buf_map_type; // Keep track of maximum sample delay of any reader; Only prune tags past this. unsigned d_max_reader_delay; @@ -270,6 +322,9 @@ protected: uint64_t d_downstream_lcm_nitems; uint64_t d_write_multiple; + uint32_t d_max_reader_output_multiple; + + buffer_context d_context; /*! * \brief Increment read or write index for this buffer @@ -281,7 +336,7 @@ protected: */ virtual unsigned index_sub(unsigned a, unsigned b) = 0; - virtual bool allocate_buffer(int nitems, size_t sizeof_item) { return false; }; + virtual bool allocate_buffer(int nitems) { return false; }; /*! * \brief constructor is private. Use gr_make_buffer to create instances. @@ -293,16 +348,19 @@ protected: * \param sizeof_item is the size of an item in bytes. * \param downstream_lcm_nitems is the least common multiple of the items to * read by downstream block(s) + * \param downstream_max_out_mult is the maximum output multiple of all + * downstream blocks * \param link is the block that writes to this buffer. * * The total size of the buffer will be rounded up to a system * dependent boundary. This is typically the system page size, but * under MS windows is 64KB. */ - buffer(BufferMappingType buftype, + buffer(buffer_mapping_type buftype, int nitems, size_t sizeof_item, uint64_t downstream_lcm_nitems, + uint32_t downstream_max_out_mult, block_sptr link); /*! |