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/host_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/host_buffer.h')
-rw-r--r-- | gnuradio-runtime/include/gnuradio/host_buffer.h | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/gnuradio-runtime/include/gnuradio/host_buffer.h b/gnuradio-runtime/include/gnuradio/host_buffer.h new file mode 100644 index 0000000000..83f46d2e85 --- /dev/null +++ b/gnuradio-runtime/include/gnuradio/host_buffer.h @@ -0,0 +1,126 @@ +/* -*- c++ -*- */ +/* + * Copyright 2021 BlackLynx Inc. + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#ifndef INCLUDED_HOST_BUFFER_H +#define INCLUDED_HOST_BUFFER_H + +#include <gnuradio/buffer_single_mapped.h> +#include <gnuradio/buffer_type.h> +#include <cstddef> + +namespace gr { + + +class GR_RUNTIME_API host_buffer : public buffer_single_mapped +{ +public: + static void* device_memcpy(void* dest, const void* src, std::size_t count); + static void* device_memmove(void* dest, const void* src, std::size_t count); + + static buffer_type type; + + virtual ~host_buffer(); + + /*! + * \brief Handles post-general_work() cleanup and data transfer + * + * Called directly after call to general_work() completes and + * is used for data transfer (and perhaps other administrative + * activities) + * + * \param nitems is the number of items produced by the general_work() function. + */ + void post_work(int nitems); + + /*! + * \brief Do actual buffer allocation. Inherited from buffer_single_mapped. + */ + bool do_allocate_buffer(size_t final_nitems, size_t sizeof_item); + + /*! + * \brief Return a pointer to the write buffer depending on the context + */ + virtual void* write_pointer(); + + /*! + * \brief return pointer to read buffer depending on the context + * + * The return value points to at least items_available() items. + */ + virtual const void* _read_pointer(unsigned int read_index); + + /*! + * \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); + + /*! + * \brief Callback function that the scheduler will call when it determines + * that the output is blocked + */ + virtual bool output_blocked_callback(int output_multiple, bool force); + + /*! + * \brief Creates a new host_buffer object + * + * \param nitems + * \param sizeof_item + * \param downstream_lcm_nitems + * \param link + * \param buf_owner + * + * \return pointer to buffer base class + */ + static buffer_sptr make_host_buffer(int nitems, + std::size_t sizeof_item, + uint64_t downstream_lcm_nitems, + uint32_t downstream_max_out_mult, + block_sptr link, + block_sptr buf_owner); + +private: + // This is the simulated device buffer + std::unique_ptr<char> d_device_buf; + char* d_device_base; + + /*! + * \brief constructor is private. Use the static make_host_buffer function + * to create instances. + * + * Allocate a buffer that holds at least \p nitems of size \p sizeof_item. + * + * \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 blocks + * \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 if the block that owns the buffer which may or may not + * be the same as 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. + */ + host_buffer(int nitems, + size_t sizeof_item, + uint64_t downstream_lcm_nitems, + uint32_t downstream_max_out_mult, + block_sptr link, + block_sptr buf_owner); +}; + +// See buffer_type.h for details on this macro. It is used here to generate +// compile-time class representing the host_buffer classes "type". +MAKE_CUSTOM_BUFFER_TYPE(HOST_BUFFER, &host_buffer::make_host_buffer); + +} // namespace gr + +#endif /* INCLUDED_HOST_BUFFER_H */ |