Skip to content

Commit

Permalink
enable async operations for gmio/external buffers
Browse files Browse the repository at this point in the history
Signed-off-by: ch vamshi krishna <[email protected]>
  • Loading branch information
ch vamshi krishna committed Sep 28, 2024
1 parent e4a659d commit ebe081d
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/runtime_src/core/common/api/aie/xrt_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ class buffer_impl
{
m_buffer_handle->sync(bos, dir, size, offset);
}

void
async(std::vector<xrt::bo>& bos, xclBOSyncDirection dir, size_t size, size_t offset) const
{
m_buffer_handle->async(bos, dir, size, offset);
}

void
wait() const
{
m_buffer_handle->wait();
}
};

} // xrt::aie
Expand Down Expand Up @@ -473,6 +485,14 @@ sync(const xrt::bo& bo, xclBOSyncDirection dir, size_t size, size_t offset) cons
return get_handle()->sync(bos, dir, size, offset);
}

void
buffer::
async(const xrt::bo& bo, xclBOSyncDirection dir, size_t size, size_t offset) const
{
std::vector<xrt::bo> bos {bo};
return get_handle()->async(bos, dir, size, offset);
}

void
buffer::
sync(const xrt::bo& ping, const xrt::bo& pong, xclBOSyncDirection dir, size_t size, size_t offset) const
Expand All @@ -481,6 +501,21 @@ sync(const xrt::bo& ping, const xrt::bo& pong, xclBOSyncDirection dir, size_t si
return get_handle()->sync(bos, dir, size, offset);
}

void
buffer::
async(const xrt::bo& ping, const xrt::bo& pong, xclBOSyncDirection dir, size_t size, size_t offset) const
{
std::vector<xrt::bo> bos {ping,pong};
return get_handle()->async(bos, dir, size, offset);
}

void
buffer::
wait() const
{
return get_handle()->wait();
}

} // xrt:aie

////////////////////////////////////////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions src/runtime_src/core/common/shim/aie_buffer_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ class aie_buffer_handle
throw xrt_core::error(std::errc::not_supported, __func__);
}

virtual void
async(std::vector<xrt::bo>&, xclBOSyncDirection, size_t, size_t)
{
throw xrt_core::error(std::errc::not_supported, __func__);
}

virtual void
wait() const
{
throw xrt_core::error(std::errc::not_supported, __func__);
}

};

} // xrt_core
Expand Down
19 changes: 19 additions & 0 deletions src/runtime_src/core/edge/user/aie/aie_buffer_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,23 @@ namespace zynqaie {
{
return m_aie_array->sync_bo(bos, name.c_str(), dir, size, offset);
}

void
aie_buffer_object::async(std::vector<xrt::bo>& bos, xclBOSyncDirection dir, size_t size, size_t offset)
{
if (async_started)
throw xrt_core::error(-EINVAL, "Asynchronous operation is already initiated. Multiple 'async' calls are not supported");

async_started = true;
return m_aie_array->sync_bo_nb(bos, name.c_str(), dir, size, offset);
}

void
aie_buffer_object::wait() const
{
if (!async_started)
throw xrt_core::error(-EINVAL, "Asynchronous operation is not initiated. Please call 'wait' after 'async' call");

return m_aie_array->wait_gmio(name);
}
}
7 changes: 7 additions & 0 deletions src/runtime_src/core/edge/user/aie/aie_buffer_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,20 @@ namespace zynqaie {
{
std::string name;
std::shared_ptr<Aie> m_aie_array;
bool async_started = false;

public:
aie_buffer_object(xrt_core::device* device , const xrt::uuid uuid, const char* name, const zynqaie::hwctx_object* hwctx=nullptr);

void
sync(std::vector<xrt::bo>& bos, xclBOSyncDirection dir, size_t size, size_t offset) const;

void
async(std::vector<xrt::bo>& bos, xclBOSyncDirection dir, size_t size, size_t offset);

void
wait() const;

std::string
get_name() const;

Expand Down
41 changes: 41 additions & 0 deletions src/runtime_src/core/include/xrt/xrt_aie.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,23 @@ class buffer : public detail::pimpl<buffer_impl>
*/
void sync(const xrt::bo& bo, xclBOSyncDirection dir, size_t size, size_t offset) const;

/**
* async() - This function initiates an asynchronize operation to synchronize the buffer with a single xrt::bo object
*
* @param bo
* The xrt::bo object to synchronize
* @param dir
* The direction of synchronization (e.g., host to device or device to host)
* @param size
* The size of the data to synchronize
* @param offset
* The offset within the buffer to start synchronization
*
* This function synchronizes the buffer with the specified xrt::bo object.
* This configures the required BDs , enqueues the task
*/
void async(const xrt::bo& bo, xclBOSyncDirection dir, size_t size, size_t offset) const;

/**
* sync() - Synchronize buffer with two xrt::bo objects (ping-pong)
*
Expand All @@ -428,6 +445,30 @@ class buffer : public detail::pimpl<buffer_impl>
*/
void sync(const xrt::bo& ping, const xrt::bo& pong, xclBOSyncDirection dir, size_t size, size_t offset) const;

/**
* async() - This function initiates an asynchronize operation to synchronize buffer with two xrt::bo objects (ping-pong)
*
* @param ping
* The first xrt::bo object to synchronize (ping)
* @param pong
* The second xrt::bo object to synchronize (pong)
* @param dir
* The direction of synchronization (e.g., host to device or device to host)
* @param size
* The size of the data to synchronize
* @param offset
* The offset within the buffer to start synchronization
*
* This function synchronizes the buffer with the specified xrt::bo objects in a ping-pong manner.
* This configures the required BDs , enqueues the task
*/
void async(const xrt::bo& ping, const xrt::bo& pong, xclBOSyncDirection dir, size_t size, size_t offset) const;

/**
* wait() - This function waits for the previously initiated async operation
*/
void wait() const;

};

}} // aie, xrt
Expand Down

0 comments on commit ebe081d

Please sign in to comment.