Skip to content

Commit 374c8d5

Browse files
committed
Refactor tests for distributed vector and copy()
1 parent 3d0937e commit 374c8d5

File tree

3 files changed

+88
-119
lines changed

3 files changed

+88
-119
lines changed

test/distributed_queue_setup.hpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//---------------------------------------------------------------------------//
2+
// Copyright (c) 2016 Jakub Szuppe <j.szuppe@gmail.com>
3+
//
4+
// Distributed under the Boost Software License, Version 1.0
5+
// See accompanying file LICENSE_1_0.txt or copy at
6+
// http://www.boost.org/LICENSE_1_0.txt
7+
//
8+
// See http://boostorg.github.com/compute for more information.
9+
//---------------------------------------------------------------------------//
10+
11+
#ifndef BOOST_COMPUTE_TEST_DISTRIBUTED_QUEUE_SETUP_HPP
12+
#define BOOST_COMPUTE_TEST_DISTRIBUTED_QUEUE_SETUP_HPP
13+
14+
#include <boost/compute/distributed/command_queue.hpp>
15+
16+
inline boost::compute::distributed::command_queue
17+
get_distributed_queue(boost::compute::command_queue& queue,
18+
size_t n = 1,
19+
bool same_context = false)
20+
{
21+
std::vector<boost::compute::command_queue> queues;
22+
queues.push_back(queue);
23+
for(size_t i = 0; i < n; i++) {
24+
if(same_context) {
25+
queues.push_back(
26+
boost::compute::command_queue(
27+
queue.get_context(),
28+
queue.get_device()
29+
)
30+
);
31+
}
32+
else {
33+
queues.push_back(
34+
boost::compute::command_queue(
35+
boost::compute::context(queue.get_device()),
36+
queue.get_device()
37+
)
38+
);
39+
}
40+
}
41+
42+
return boost::compute::distributed::command_queue(queues);
43+
}
44+
45+
#endif /* BOOST_COMPUTE_TEST_DISTRIBUTED_QUEUE_SETUP_HPP */

test/test_distributed_copy.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,38 +26,10 @@
2626
#include "context_setup.hpp"
2727

2828
#include "distributed_check_functions.hpp"
29+
#include "distributed_queue_setup.hpp"
2930

3031
namespace bc = boost::compute;
3132

32-
inline boost::compute::distributed::command_queue
33-
get_distributed_queue(boost::compute::command_queue& queue,
34-
size_t n = 1,
35-
bool same_context = false)
36-
{
37-
std::vector<bc::command_queue> queues;
38-
queues.push_back(queue);
39-
for(size_t i = 0; i < n; i++) {
40-
if(same_context) {
41-
queues.push_back(
42-
boost::compute::command_queue(
43-
queue.get_context(),
44-
queue.get_device()
45-
)
46-
);
47-
}
48-
else {
49-
queues.push_back(
50-
boost::compute::command_queue(
51-
boost::compute::context(queue.get_device()),
52-
queue.get_device()
53-
)
54-
);
55-
}
56-
}
57-
58-
return bc::distributed::command_queue(queues);
59-
}
60-
6133
BOOST_AUTO_TEST_CASE(copy_from_host)
6234
{
6335
// construct distributed::command_queue

test/test_distributed_vector.cpp

Lines changed: 42 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
#include "check_macros.hpp"
2424
#include "context_setup.hpp"
2525

26+
#include "distributed_check_functions.hpp"
27+
#include "distributed_queue_setup.hpp"
28+
2629
namespace bc = boost::compute;
2730

2831
BOOST_AUTO_TEST_CASE(empty_vector)
2932
{
30-
std::vector<bc::command_queue> queues;
31-
queues.push_back(queue);
32-
queues.push_back(queue);
33-
bc::distributed::command_queue distributed_queue(queues);
33+
// construct distributed::command_queue
34+
bc::distributed::command_queue distributed_queue =
35+
get_distributed_queue(queue);
36+
3437
bc::distributed::vector<bc::uint_> distributed_vector(distributed_queue);
3538

3639
BOOST_CHECK(distributed_vector.empty());
@@ -47,10 +50,9 @@ BOOST_AUTO_TEST_CASE(empty_vector)
4750

4851
BOOST_AUTO_TEST_CASE(count_ctor)
4952
{
50-
std::vector<bc::command_queue> queues;
51-
queues.push_back(queue);
52-
queues.push_back(queue);
53-
bc::distributed::command_queue distributed_queue(queues);
53+
// construct distributed::command_queue
54+
bc::distributed::command_queue distributed_queue =
55+
get_distributed_queue(queue);
5456

5557
bc::distributed::vector<bc::uint_> distributed_vector(
5658
64, distributed_queue
@@ -70,10 +72,9 @@ BOOST_AUTO_TEST_CASE(count_ctor)
7072

7173
BOOST_AUTO_TEST_CASE(command_queue_ctor)
7274
{
73-
std::vector<bc::command_queue> queues;
74-
queues.push_back(queue);
75-
queues.push_back(queue);
76-
bc::distributed::command_queue distributed_queue(queues);
75+
// construct distributed::command_queue
76+
bc::distributed::command_queue distributed_queue =
77+
get_distributed_queue(queue);
7778

7879
bc::uint_ value = 991;
7980
bc::distributed::vector<bc::uint_> distributed_vector(
@@ -97,25 +98,14 @@ BOOST_AUTO_TEST_CASE(command_queue_ctor)
9798
BOOST_CHECK_EQUAL(distributed_vector.back(), value);
9899
BOOST_CHECK_EQUAL(distributed_vector.front(), value);
99100

100-
for(size_t i = 0; i < distributed_vector.parts(); i++)
101-
{
102-
BOOST_CHECK(
103-
bc::equal(
104-
distributed_vector.begin(i),
105-
distributed_vector.end(i),
106-
bc::make_constant_iterator(value),
107-
distributed_queue.get(i)
108-
)
109-
);
110-
}
101+
BOOST_CHECK(distributed_equal(distributed_vector, value, distributed_queue));
111102
}
112103

113104
BOOST_AUTO_TEST_CASE(host_iterator_ctor)
114105
{
115-
std::vector<bc::command_queue> queues;
116-
queues.push_back(queue);
117-
queues.push_back(queue);
118-
bc::distributed::command_queue distributed_queue(queues);
106+
// construct distributed::command_queue
107+
bc::distributed::command_queue distributed_queue =
108+
get_distributed_queue(queue);
119109

120110
bc::int_ value = -1;
121111
std::vector<bc::int_> host_vector(50, value);
@@ -135,17 +125,7 @@ BOOST_AUTO_TEST_CASE(host_iterator_ctor)
135125
}
136126
BOOST_CHECK_EQUAL(distributed_vector.size(), size_sum);
137127

138-
for(size_t i = 0; i < distributed_vector.parts(); i++)
139-
{
140-
BOOST_CHECK(
141-
bc::equal(
142-
distributed_vector.begin(i),
143-
distributed_vector.end(i),
144-
bc::make_constant_iterator(value),
145-
distributed_queue.get(i)
146-
)
147-
);
148-
}
128+
BOOST_CHECK(distributed_equal(distributed_vector, value, distributed_queue));
149129

150130
// need to finish since back() and front()
151131
// use different (self-made) queues
@@ -159,12 +139,12 @@ BOOST_AUTO_TEST_CASE(host_iterator_ctor)
159139

160140
BOOST_AUTO_TEST_CASE(copy_ctor)
161141
{
162-
std::vector<bc::command_queue> queues;
163-
queues.push_back(queue);
164-
queues.push_back(queue);
165-
bc::distributed::command_queue distributed_queue1(queues);
166-
queues.push_back(queue);
167-
bc::distributed::command_queue distributed_queue2(queues);
142+
// construct distributed::command_queue
143+
bc::distributed::command_queue distributed_queue1 =
144+
get_distributed_queue(queue);
145+
// construct distributed::command_queue
146+
bc::distributed::command_queue distributed_queue2 =
147+
get_distributed_queue(queue, 2);
168148

169149
bc::int_ value = -1;
170150
size_t size = 64;
@@ -185,52 +165,25 @@ BOOST_AUTO_TEST_CASE(copy_ctor)
185165
distributed_vector, distributed_queue2
186166
);
187167

188-
for(size_t i = 0; i < distributed_vector.parts(); i++)
189-
{
190-
BOOST_CHECK(
191-
bc::equal(
192-
distributed_vector.begin(i),
193-
distributed_vector.end(i),
194-
bc::make_constant_iterator(value),
195-
distributed_queue1.get(i)
196-
)
197-
);
198-
BOOST_CHECK(
199-
bc::equal(
200-
distributed_vector_copy1.begin(i),
201-
distributed_vector_copy1.end(i),
202-
bc::make_constant_iterator(value),
203-
distributed_queue1.get(i)
204-
)
205-
);
206-
}
207-
for(size_t i = 0; i < distributed_vector_copy2.parts(); i++)
208-
{
209-
BOOST_CHECK(
210-
bc::equal(
211-
distributed_vector_copy2.begin(i),
212-
distributed_vector_copy2.end(i),
213-
bc::make_constant_iterator(value),
214-
distributed_queue2.get(i)
215-
)
216-
);
217-
BOOST_CHECK(
218-
bc::equal(
219-
distributed_vector_copy3.begin(i),
220-
distributed_vector_copy3.end(i),
221-
bc::make_constant_iterator(value),
222-
distributed_queue2.get(i)
223-
)
224-
);
225-
}
168+
BOOST_CHECK(
169+
distributed_equal(distributed_vector, value, distributed_queue1)
170+
);
171+
BOOST_CHECK(
172+
distributed_equal(distributed_vector_copy1, value, distributed_queue1)
173+
);
174+
BOOST_CHECK(
175+
distributed_equal(distributed_vector_copy2, value, distributed_queue2)
176+
);
177+
BOOST_CHECK(
178+
distributed_equal(distributed_vector_copy3, value, distributed_queue2)
179+
);
226180
}
227181

228182
BOOST_AUTO_TEST_CASE(at)
229183
{
230-
std::vector<bc::command_queue> queues;
231-
queues.push_back(queue);
232-
queues.push_back(queue);
233-
bc::distributed::command_queue distributed_queue(queues);
184+
// construct distributed::command_queue
185+
bc::distributed::command_queue distributed_queue =
186+
get_distributed_queue(queue);
234187

235188
bc::distributed::vector<bc::uint_> distributed_vector(
236189
size_t(64), bc::uint_(64), distributed_queue
@@ -263,10 +216,9 @@ BOOST_AUTO_TEST_CASE(at)
263216

264217
BOOST_AUTO_TEST_CASE(subscript_operator)
265218
{
266-
std::vector<bc::command_queue> queues;
267-
queues.push_back(queue);
268-
queues.push_back(queue);
269-
bc::distributed::command_queue distributed_queue(queues);
219+
// construct distributed::command_queue
220+
bc::distributed::command_queue distributed_queue =
221+
get_distributed_queue(queue);
270222

271223
bc::distributed::vector<bc::uint_> distributed_vector(
272224
size_t(64), bc::uint_(64), distributed_queue

0 commit comments

Comments
 (0)