SkelCL
SkelCL is a high level multi GPU skeleton library developed at the university of Münster, Germany.
 All Classes Namespaces Files Functions Variables Typedefs Groups
DistributionTests.cpp
1 /*****************************************************************************
2  * Copyright (c) 2011-2012 The SkelCL Team as listed in CREDITS.txt *
3  * http://skelcl.uni-muenster.de *
4  * *
5  * This file is part of SkelCL. *
6  * SkelCL is available under multiple licenses. *
7  * The different licenses are subject to terms and condition as provided *
8  * in the files specifying the license. See "LICENSE.txt" for details *
9  * *
10  *****************************************************************************
11  * *
12  * SkelCL is free software: you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation, either version 3 of the License, or *
15  * (at your option) any later version. See "LICENSE-gpl.txt" for details. *
16  * *
17  * SkelCL is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  *****************************************************************************
23  * *
24  * For non-commercial academic use see the license specified in the file *
25  * "LICENSE-academic.txt". *
26  * *
27  *****************************************************************************
28  * *
29  * If you are interested in other licensing models, including a commercial- *
30  * license, please contact the author at michel.steuwer@uni-muenster.de *
31  * *
32  *****************************************************************************/
33 
37 
38 #include <SkelCL/SkelCL.h>
39 #include <SkelCL/Distributions.h>
40 #include <SkelCL/IndexVector.h>
41 #include <SkelCL/IndexMatrix.h>
42 #include <SkelCL/Matrix.h>
43 #include <SkelCL/Vector.h>
44 
45 #include "Test.h"
48 
49 class DistributionTest : public ::testing::Test {
50 protected:
51  DistributionTest()
52  {
54  }
55  ~DistributionTest()
56  {
58  }
59 };
60 
61 TEST_F(DistributionTest, DefaultDistribution)
62 {
63  auto dist = skelcl::detail::Distribution< skelcl::Vector<int> >();
64 
65  EXPECT_FALSE(dist.isValid());
66 }
67 
68 TEST_F(DistributionTest, SingleDistribution)
69 {
70  auto single = skelcl::detail::SingleDistribution< skelcl::Vector<int> >();
71 
72  EXPECT_TRUE(single.isValid());
73  EXPECT_EQ(1, single.devices().size());
74  EXPECT_EQ(skelcl::detail::globalDeviceList[0].get(),
75  single.device(0).get());
76 }
77 
78 TEST_F(DistributionTest, SingleDistribution2)
79 {
81  auto single = skelcl::distribution::Single(vi);
82 
83  EXPECT_TRUE(single != nullptr);
84  EXPECT_TRUE(single->isValid());
85  EXPECT_EQ(1, single->devices().size());
86  EXPECT_EQ(skelcl::detail::globalDeviceList[0].get(),
87  single->device(0).get());
88 }
89 
90 TEST_F(DistributionTest, SingleDistribution3)
91 {
94 
95  auto& dist = vi.distribution();
96 
97  EXPECT_TRUE(dist.isValid());
98  EXPECT_EQ(1, dist.devices().size());
99  EXPECT_EQ(skelcl::detail::globalDeviceList[0].get(),
100  dist.device(0).get());
101 }
102 
103 TEST_F(DistributionTest, SingleDistribution4)
104 {
107 
108  auto& dist = vi.distribution();
109 
110  EXPECT_TRUE(dist.isValid());
111  EXPECT_EQ(1, dist.devices().size());
112  EXPECT_EQ(skelcl::detail::globalDeviceList[0].get(),
113  dist.device(0).get());
114 }
115 
116 TEST_F(DistributionTest, SingleDistribution5)
117 {
119  mi.setDistribution(skelcl::distribution::Single(mi));
120 
121  auto& dist = mi.distribution();
122 
123  EXPECT_TRUE(dist.isValid());
124  EXPECT_EQ(1, dist.devices().size());
125  EXPECT_EQ(skelcl::detail::globalDeviceList[0].get(),
126  dist.device(0).get());
127 }
128 
129 TEST_F(DistributionTest, SingleDistribution6)
130 {
133 
134  auto& dist = mi.distribution();
135 
136  EXPECT_TRUE(dist.isValid());
137  EXPECT_EQ(1, dist.devices().size());
138  EXPECT_EQ(skelcl::detail::globalDeviceList[0].get(),
139  dist.device(0).get());
140 }
141 
142 TEST_F(DistributionTest, SingleDistribution7)
143 {
144  skelcl::IndexVector iv(1024);
146 
147  auto& dist = iv.distribution();
148 
149  EXPECT_TRUE(dist.isValid());
150  EXPECT_EQ(1, dist.devices().size());
151  EXPECT_EQ(skelcl::detail::globalDeviceList[0].get(),
152  dist.device(0).get());
153 }
154 
155 TEST_F(DistributionTest, SingleDistribution8)
156 {
157  skelcl::IndexMatrix im({1024, 1024});
159 
160  auto& dist = im.distribution();
161 
162  EXPECT_TRUE(dist.isValid());
163  EXPECT_EQ(1, dist.devices().size());
164  EXPECT_EQ(skelcl::detail::globalDeviceList[0].get(),
165  dist.device(0).get());
166 }
167 
168 TEST_F(DistributionTest, BlockDistribution)
169 {
172  auto block = skelcl::detail::BlockDistribution< skelcl::Vector<int> >();
173 
174  EXPECT_TRUE(block.isValid());
175  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
176  block.devices().size());
177  int i = 0;
178  for (auto iter = skelcl::detail::globalDeviceList.begin();
179  iter != skelcl::detail::globalDeviceList.end();
180  ++iter) {
181  EXPECT_EQ( iter->get(), block.device(i++).get() );
182  }
183 }
184 
185 TEST_F(DistributionTest, BlockDistribution2)
186 {
188  auto block = skelcl::distribution::Block(vi);
189 
190  EXPECT_TRUE(block != nullptr);
191  EXPECT_TRUE(block->isValid());
192  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
193  block->devices().size());
194  int i = 0;
195  for (auto iter = skelcl::detail::globalDeviceList.begin();
196  iter != skelcl::detail::globalDeviceList.end();
197  ++iter) {
198  EXPECT_EQ( iter->get(), block->device(i++).get() );
199  }
200 }
201 
202 TEST_F(DistributionTest, BlockDistribution3)
203 {
206 
207  auto& dist = vi.distribution();
208 
209  EXPECT_TRUE(dist.isValid());
210  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
211  dist.devices().size());
212  int i = 0;
213  for (auto iter = skelcl::detail::globalDeviceList.begin();
214  iter != skelcl::detail::globalDeviceList.end();
215  ++iter) {
216  EXPECT_EQ( iter->get(), dist.device(i++).get() );
217  }
218 }
219 
220 TEST_F(DistributionTest, BlockDistribution4)
221 {
224 
225  auto& dist = vi.distribution();
226 
227  EXPECT_TRUE(dist.isValid());
228  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
229  dist.devices().size());
230  int i = 0;
231  for (auto iter = skelcl::detail::globalDeviceList.begin();
232  iter != skelcl::detail::globalDeviceList.end();
233  ++iter) {
234  EXPECT_EQ( iter->get(), dist.device(i++).get() );
235  }
236 }
237 
238 TEST_F(DistributionTest, BlockDistribution5)
239 {
241  mi.setDistribution(skelcl::distribution::Block(mi));
242 
243  auto& dist = mi.distribution();
244 
245  EXPECT_TRUE(dist.isValid());
246  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
247  dist.devices().size());
248  int i = 0;
249  for (auto iter = skelcl::detail::globalDeviceList.begin();
250  iter != skelcl::detail::globalDeviceList.end();
251  ++iter) {
252  EXPECT_EQ( iter->get(), dist.device(i++).get() );
253  }
254 }
255 
256 TEST_F(DistributionTest, BlockDistribution6)
257 {
260 
261  auto& dist = mi.distribution();
262 
263  EXPECT_TRUE(dist.isValid());
264  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
265  dist.devices().size());
266  int i = 0;
267  for (auto iter = skelcl::detail::globalDeviceList.begin();
268  iter != skelcl::detail::globalDeviceList.end();
269  ++iter) {
270  EXPECT_EQ( iter->get(), dist.device(i++).get() );
271  }
272 }
273 
274 TEST_F(DistributionTest, CopyDistribution)
275 {
278  auto copy = skelcl::detail::CopyDistribution< skelcl::Vector<int> >();
279 
280  EXPECT_TRUE(copy.isValid());
281  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
282  copy.devices().size());
283  int i = 0;
284  for (auto iter = skelcl::detail::globalDeviceList.begin();
285  iter != skelcl::detail::globalDeviceList.end();
286  ++iter) {
287  EXPECT_EQ( iter->get(), copy.device(i++).get() );
288  }
289 }
290 
291 TEST_F(DistributionTest, CopyDistribution2)
292 {
294  auto copy = skelcl::distribution::Copy(vi);
295 
296  EXPECT_TRUE(copy != nullptr);
297  EXPECT_TRUE(copy->isValid());
298  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
299  copy->devices().size());
300  int i = 0;
301  for (auto iter = skelcl::detail::globalDeviceList.begin();
302  iter != skelcl::detail::globalDeviceList.end();
303  ++iter) {
304  EXPECT_EQ( iter->get(), copy->device(i++).get() );
305  }
306 }
307 
308 TEST_F(DistributionTest, CopyDistribution3)
309 {
312 
313  auto& dist = vi.distribution();
314 
315  EXPECT_TRUE(dist.isValid());
316  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
317  dist.devices().size());
318  int i = 0;
319  for (auto iter = skelcl::detail::globalDeviceList.begin();
320  iter != skelcl::detail::globalDeviceList.end();
321  ++iter) {
322  EXPECT_EQ( iter->get(), dist.device(i++).get() );
323  }
324 }
325 
326 TEST_F(DistributionTest, CopyDistribution4)
327 {
330 
331  auto& dist = vi.distribution();
332 
333  EXPECT_TRUE(dist.isValid());
334  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
335  dist.devices().size());
336  int i = 0;
337  for (auto iter = skelcl::detail::globalDeviceList.begin();
338  iter != skelcl::detail::globalDeviceList.end();
339  ++iter) {
340  EXPECT_EQ( iter->get(), dist.device(i++).get() );
341  }
342 }
343 
344 TEST_F(DistributionTest, CopyDistribution5)
345 {
347  mi.setDistribution(skelcl::distribution::Copy(mi));
348 
349  auto& dist = mi.distribution();
350 
351  EXPECT_TRUE(dist.isValid());
352  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
353  dist.devices().size());
354  int i = 0;
355  for (auto iter = skelcl::detail::globalDeviceList.begin();
356  iter != skelcl::detail::globalDeviceList.end();
357  ++iter) {
358  EXPECT_EQ( iter->get(), dist.device(i++).get() );
359  }
360 }
361 
362 TEST_F(DistributionTest, CopyDistribution6)
363 {
366 
367  auto& dist = mi.distribution();
368 
369  EXPECT_TRUE(dist.isValid());
370  EXPECT_EQ(skelcl::detail::globalDeviceList.size(),
371  dist.devices().size());
372  int i = 0;
373  for (auto iter = skelcl::detail::globalDeviceList.begin();
374  iter != skelcl::detail::globalDeviceList.end();
375  ++iter) {
376  EXPECT_EQ( iter->get(), dist.device(i++).get() );
377  }
378 }
379 
381 
The Matrix class is a two dimensional container which makes its data accessible on the host as well a...
Definition: Matrix.h:190
void setSingle(const C< T > &c)
This function sets the distribution of the given container to the SingleDistribution using the defaul...
void setDistribution(const detail::Distribution< Vector< U >> &distribution) const
Set a new distribution to the vector.
SKELCL_DLL void init(detail::DeviceProperties properties=allDevices())
Initializes the SkelCL library. This function (or another init function) has to be called prior to ev...
Definition: SkelCL.cpp:51
std::unique_ptr< skelcl::detail::Distribution< C< T > > > Block(const C< T > &c)
Factory function to create a BlockDistribution with the types of the given container.
Definition: Distributions.h:94
SKELCL_DLL detail::DeviceProperties nDevices(size_t n)
Creates a detail::DeviceProperties object representing n devices. This object should be used as param...
Definition: SkelCL.cpp:66
void setBlock(const C< T > &c)
This function sets the distribution of the given container to the BlockDistribution.
detail::Distribution< Vector< T > > & distribution() const
Returns the current distribution of the vector.
The Vector class is a one dimensional container which makes its data accessible on the host as well a...
Definition: Vector.h:113
std::unique_ptr< skelcl::detail::Distribution< C< T > > > Copy(const C< T > &c, typename identity< std::function< T(const T &, const T &)>>::type combineFunc=nullptr)
Factory function to create a CopyDistribution with the types of the given container.
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.
Definition: SkelCL.cpp:81
The IndexVector (a.k.a. Vector) class is a special implementation of a Vector with Elements of...
Definition: IndexVector.h:72
void setCopy(const C< T > &c, std::function< T(const T &, const T &)> combineFunc=nullptr)
This function sets the distribution of the given container to the CopyDistribution.
std::unique_ptr< skelcl::detail::Distribution< C< T > > > Single(const C< T > &c)
Factory function to create a SingleDistribution with the types of the given container and for the def...
The IndexMatrix (a.k.a. Matrix) class is a special implementation of a Matrix with Elemen...
Definition: IndexMatrix.h:73