Skip to content

Commit

Permalink
Separate acquire cu context from exec_write::add_cu (Xilinx#1312)
Browse files Browse the repository at this point in the history
  • Loading branch information
stsoe authored Apr 26, 2019
1 parent 6e3a37e commit 0a82bd3
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 18 deletions.
17 changes: 14 additions & 3 deletions src/runtime_src/xrt/xrt++/xrtexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@

namespace xrtcpp {

void
acquire_cu_context(xrt_device* device, value_type cuidx)
{
auto xdevice = static_cast<xrt::device*>(device);
xdevice->acquire_cu_context(cuidx,true);
}

void
release_cu_context(xrt_device* device, value_type cuidx)
{
auto xdevice = static_cast<xrt::device*>(device);
xdevice->release_cu_context(cuidx);
}

namespace exec {

struct command::impl : xrt::command
Expand Down Expand Up @@ -75,9 +89,6 @@ add_cu(value_type cuidx)
throw std::runtime_error("write_command supports at most 32 CUs");
auto skcmd = reinterpret_cast<ert_start_kernel_cmd*>(m_impl->ecmd);
skcmd->cu_mask |= 1<<cuidx;

auto xdevice = m_impl->get_device();
xdevice->acquire_cu_context(cuidx,true);
}

void
Expand Down
19 changes: 17 additions & 2 deletions src/runtime_src/xrt/xrt++/xrtexec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,26 @@ struct xrt_device;

namespace xrtcpp {

namespace exec {

using value_type = uint32_t;
using addr_type = uint32_t;

/**
* Open a context that allows the current process to use @cuidx
*
* A context on a CU can only be opened once for a given process
* and should be released when process is done with the CU
*/
void
acquire_cu_context(xrt_device* device, value_type cuidx);

/**
* Release a context previously acquired
*/
void
release_cu_context(xrt_device* device, value_type cuidx);

namespace exec {

/**
* class command : abstraction for commands executed by XRT
*/
Expand Down
30 changes: 17 additions & 13 deletions tests/unit_test/experimental/exec_write/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,23 @@ throw_if_error(cl_int errcode, const std::string& msg)
static int
run_kernel(xrt_device* xdev, uint32_t cuidx, uint64_t bo_dev_addr)
{
auto cmd = xrtcpp::exec::exec_write_command(xdev);
cmd.add(XHELLO_HELLO_CONTROL_ADDR_ACCESS1_DATA,bo_dev_addr); // low
cmd.add(XHELLO_HELLO_CONTROL_ADDR_ACCESS1_DATA+4,(bo_dev_addr >> 32) & 0xFFFFFFFF); // high part of a
cmd.add_cu(cuidx);
cmd.execute();
cmd.wait();


// execute same command again demo completed() API busy wait
int count = 0;
cmd.execute();
while (!cmd.completed()) ++count;
std::cout << "wait count: " << count << "\n";
xrtcpp::acquire_cu_context(xdev,cuidx);
for (int i=0; i<2; ++i) {
auto cmd = xrtcpp::exec::exec_write_command(xdev);
cmd.add(XHELLO_HELLO_CONTROL_ADDR_ACCESS1_DATA,bo_dev_addr); // low
cmd.add(XHELLO_HELLO_CONTROL_ADDR_ACCESS1_DATA+4,(bo_dev_addr >> 32) & 0xFFFFFFFF); // high part of a
cmd.add_cu(cuidx);
cmd.execute();
cmd.wait();


// execute same command again demo completed() API busy wait
int count = 0;
cmd.execute();
while (!cmd.completed()) ++count;
std::cout << "wait count: " << count << "\n";
}
xrtcpp::release_cu_context(xdev,cuidx);
return 0;
}

Expand Down

0 comments on commit 0a82bd3

Please sign in to comment.