Skip to content

Commit 1cf9623

Browse files
committed
Refactor distributed::command_queue
1 parent 2e9f542 commit 1cf9623

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

include/boost/compute/distributed/command_queue.hpp

+22-6
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,40 @@ class command_queue
6565
}
6666
}
6767

68-
/// Creates a distributed command queue containing command queue for each
68+
/// Creates a distributed command queue containing command queues for each
6969
/// corresponding device and context from \p devices and \p contexts.
7070
command_queue(const std::vector< ::boost::compute::context> &contexts,
71-
const std::vector<device> &devices,
71+
const std::vector< std::vector<device> > &devices,
7272
cl_command_queue_properties properties = 0)
7373
{
7474
m_context = context(contexts);
75-
size_t n = m_context.size();
76-
for(size_t i = 0; i < n; i++) {
75+
for(size_t i = 0; i < m_context.size(); i++) {
76+
for(size_t j = 0; j < devices[i].size(); j++) {
77+
m_queues.push_back(
78+
::boost::compute::command_queue(
79+
m_context.get(i), devices[i][j], properties
80+
)
81+
);
82+
}
83+
}
84+
}
85+
86+
/// Creates a distributed command queue for all devices in \p context.
87+
command_queue(const ::boost::compute::context &context,
88+
cl_command_queue_properties properties = 0)
89+
{
90+
m_context = ::boost::compute::distributed::context(context);
91+
std::vector<device> devices = context.get_devices();
92+
for(size_t i = 0; i < devices.size(); i++) {
7793
m_queues.push_back(
7894
::boost::compute::command_queue(
79-
m_context.get(i), devices[i], properties
95+
context, devices[i], properties
8096
)
8197
);
8298
}
8399
}
84100

85-
/// Creates a distributed command queue.
101+
/// Creates a distributed command queue containing \p queues.
86102
explicit
87103
command_queue(const std::vector< ::boost::compute::command_queue> queues)
88104
: m_queues(queues)

test/test_distributed_command_queue.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ BOOST_AUTO_TEST_CASE(construct_from_distributed_context)
5252
BOOST_AUTO_TEST_CASE(construct_from_contexts)
5353
{
5454
std::vector<bc::context> contexts;
55-
std::vector<bc::device> devices;
55+
std::vector<std::vector<bc::device> > devices;
5656

5757
contexts.push_back(context);
58-
devices.push_back(device);
58+
devices.push_back(std::vector<bc::device>());
59+
devices[0].push_back(device);
5960

6061
bc::distributed::command_queue distributed_queue1(contexts, devices);
6162
BOOST_CHECK_EQUAL(
6263
distributed_queue1.size(),
6364
1
6465
);
6566

66-
contexts.push_back(context);
67-
devices.push_back(device);
67+
devices[0].push_back(device);
6868

6969
bc::distributed::command_queue distributed_queue2(
7070
contexts, devices, bc::distributed::command_queue::enable_profiling
@@ -80,6 +80,21 @@ BOOST_AUTO_TEST_CASE(construct_from_contexts)
8080
);
8181
}
8282

83+
BOOST_AUTO_TEST_CASE(construct_from_context)
84+
{
85+
bc::distributed::command_queue distributed_queue(context);
86+
BOOST_CHECK_EQUAL(
87+
distributed_queue.size(),
88+
context.get_devices().size()
89+
);
90+
for(size_t i = 0; i < distributed_queue.size(); i++) {
91+
BOOST_CHECK_EQUAL(
92+
distributed_queue.get_context(i),
93+
context
94+
);
95+
}
96+
}
97+
8398
BOOST_AUTO_TEST_CASE(construct_from_command_queues)
8499
{
85100
std::vector<bc::command_queue> queues;

0 commit comments

Comments
 (0)