Skip to content

Commit

Permalink
Refactor distributed::command_queue
Browse files Browse the repository at this point in the history
  • Loading branch information
jszuppe committed Aug 23, 2016
1 parent 2e9f542 commit 1cf9623
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 10 deletions.
28 changes: 22 additions & 6 deletions include/boost/compute/distributed/command_queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,40 @@ class command_queue
}
}

/// Creates a distributed command queue containing command queue for each
/// Creates a distributed command queue containing command queues for each
/// corresponding device and context from \p devices and \p contexts.
command_queue(const std::vector< ::boost::compute::context> &contexts,
const std::vector<device> &devices,
const std::vector< std::vector<device> > &devices,
cl_command_queue_properties properties = 0)
{
m_context = context(contexts);
size_t n = m_context.size();
for(size_t i = 0; i < n; i++) {
for(size_t i = 0; i < m_context.size(); i++) {
for(size_t j = 0; j < devices[i].size(); j++) {
m_queues.push_back(
::boost::compute::command_queue(
m_context.get(i), devices[i][j], properties
)
);
}
}
}

/// Creates a distributed command queue for all devices in \p context.
command_queue(const ::boost::compute::context &context,
cl_command_queue_properties properties = 0)
{
m_context = ::boost::compute::distributed::context(context);
std::vector<device> devices = context.get_devices();
for(size_t i = 0; i < devices.size(); i++) {
m_queues.push_back(
::boost::compute::command_queue(
m_context.get(i), devices[i], properties
context, devices[i], properties
)
);
}
}

/// Creates a distributed command queue.
/// Creates a distributed command queue containing \p queues.
explicit
command_queue(const std::vector< ::boost::compute::command_queue> queues)
: m_queues(queues)
Expand Down
23 changes: 19 additions & 4 deletions test/test_distributed_command_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ BOOST_AUTO_TEST_CASE(construct_from_distributed_context)
BOOST_AUTO_TEST_CASE(construct_from_contexts)
{
std::vector<bc::context> contexts;
std::vector<bc::device> devices;
std::vector<std::vector<bc::device> > devices;

contexts.push_back(context);
devices.push_back(device);
devices.push_back(std::vector<bc::device>());
devices[0].push_back(device);

bc::distributed::command_queue distributed_queue1(contexts, devices);
BOOST_CHECK_EQUAL(
distributed_queue1.size(),
1
);

contexts.push_back(context);
devices.push_back(device);
devices[0].push_back(device);

bc::distributed::command_queue distributed_queue2(
contexts, devices, bc::distributed::command_queue::enable_profiling
Expand All @@ -80,6 +80,21 @@ BOOST_AUTO_TEST_CASE(construct_from_contexts)
);
}

BOOST_AUTO_TEST_CASE(construct_from_context)
{
bc::distributed::command_queue distributed_queue(context);
BOOST_CHECK_EQUAL(
distributed_queue.size(),
context.get_devices().size()
);
for(size_t i = 0; i < distributed_queue.size(); i++) {
BOOST_CHECK_EQUAL(
distributed_queue.get_context(i),
context
);
}
}

BOOST_AUTO_TEST_CASE(construct_from_command_queues)
{
std::vector<bc::command_queue> queues;
Expand Down

0 comments on commit 1cf9623

Please sign in to comment.