Skip to content

Commit

Permalink
Add xrt::runlist::state() to return runlist ERT command state (#8407)
Browse files Browse the repository at this point in the history
* Add xrt::runlist::state() to return runlist ERT command state

The xrt::runlist::state() API mirrors xrt::run::state() and is the
preferred method for polling a runlist for completion.

Except for return value, the xrt::runlist::poll() API is functionally
the same, but is now deprecated.

Signed-off-by: Soren Soe <[email protected]>

* Ensure runlist state reflects errors if any

The runlist may be composed of multiple chained commands. Upon runlist
completion, the state of the runlist must reflect errors (if any) in
any of the submitted chained commands.

Signed-off-by: Soren Soe <[email protected]>

---------

Signed-off-by: Soren Soe <[email protected]>
  • Loading branch information
stsoe authored Sep 10, 2024
1 parent f824727 commit ee82d85
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
46 changes: 39 additions & 7 deletions src/runtime_src/core/common/api/xrt_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ class kernel_command : public xrt_core::command
get_state() const
{
// For lazy state update the command must be polled. Polling
// is a no-op on platforms where command status is live.
// is a no-op on platforms where command state is live.
m_hwqueue.poll(this);

auto state = get_state_raw();
Expand Down Expand Up @@ -3037,16 +3037,23 @@ class runlist_impl
// command has comleted (error or not), then in-order execution
// guarantees that all prior command have completed (error or not).
//
// This funtion returns 0 to indicate that last command is still
// running. Any other return value implies completion.
int
// This funtion returns the ert command packet state of the last
// command or ERT_CMD_STATE_COMPLETED if no commands have been
// submitted.
ert_cmd_state
poll_last_cmd() const
{
// Treat empty runlist as completed
if (m_submitted_cmds.empty())
return 1;
return ERT_CMD_STATE_COMPLETED;

auto [cmd, pkt] = unpack(m_submitted_cmds.back());
return m_hwqueue.poll(cmd);

// For lazy state update the command must be polled. Polling
// is a no-op on platforms where command state is live.
m_hwqueue.poll(cmd);

return static_cast<ert_cmd_state>(pkt->state);
}

// Wait for runlist to complete, then check each chained command
Expand Down Expand Up @@ -3248,14 +3255,32 @@ class runlist_impl
if (m_state != state::running)
return 1;

if (!poll_last_cmd())
if (poll_last_cmd() < ERT_CMD_STATE_COMPLETED)
return 0;

// All commands have completed. Handle errors.
wait_throw_on_error(std::chrono::milliseconds(0));
return 1;
}

ert_cmd_state
get_ert_state()
{
// Poll state of the last submitted chained command
if (auto state = poll_last_cmd(); state < ERT_CMD_STATE_COMPLETED)
return state;

// All chained commands have completed. Handle errors in
// any of the submitted chained commands.
try {
wait_throw_on_error(std::chrono::milliseconds(0));
return ERT_CMD_STATE_COMPLETED;
}
catch (const xrt::runlist::command_error& err) {
return err.get_command_state();
}
}

void
reset()
{
Expand Down Expand Up @@ -3955,6 +3980,13 @@ wait(const std::chrono::milliseconds& timeout) const
return handle->wait_throw_on_error(timeout);
}

ert_cmd_state
runlist::
state() const
{
return handle->get_ert_state();
}

int
runlist::
poll() const
Expand Down
18 changes: 18 additions & 0 deletions src/runtime_src/core/include/experimental/xrt_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ class runlist : public detail::pimpl<runlist_impl>
}

/**
* state() - Check the current state of a runlist object
*
* @return
* Current state of this run object.
*
* The state values are defined in ``include/ert.h``
* The state of an empty runlist is ERT_CMD_STATE_COMPLETED.
*
* This function is the preferred way to poll a runlist for
* for completion.
*/
XRT_API_EXPORT
ert_cmd_state
state() const;

/**
* DEPRECATED, prefer `state()`.
*
* Poll the runlist for completion.
*
* @return 0 if command list is still running, any other value
Expand Down

0 comments on commit ee82d85

Please sign in to comment.