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
IndexMatrixTests.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 <pvsutil/Logger.h>
39 
40 #include <SkelCL/Distributions.h>
41 #include <SkelCL/SkelCL.h>
42 #include <SkelCL/IndexMatrix.h>
43 #include <SkelCL/Map.h>
44 
45 #include "Test.h"
48 
49 class IndexMatrixTest : public ::testing::Test {
50 protected:
51  IndexMatrixTest() {
52  //pvsutil::defaultLogger.setLoggingLevel(pvsutil::Logger::Severity::DebugInfo);
54  }
55 
56  ~IndexMatrixTest() {
58  }
59 };
60 
61 TEST_F(IndexMatrixTest, CreateIndexMatrix) {
63 
64  EXPECT_EQ(256*32, mi.size().elemCount());
65  EXPECT_EQ(skelcl::IndexPoint(0,0), mi.front());
66  EXPECT_EQ(skelcl::IndexPoint(255,31), mi.back());
67 }
68 
69 TEST_F(IndexMatrixTest, SimpleVoidMap) {
70  skelcl::IndexMatrix index({128, 32});
71  skelcl::Map<void(skelcl::IndexPoint)> map(R"(
72 
73 void func(IndexPoint ip, int_matrix_t out) { set(out, ip.y, ip.x, ip.y+ip.x); }
74 )");
75  EXPECT_EQ(128*32, index.size().elemCount());
76 
77  skelcl::Matrix<int> m({128, 32});
78 
79  map(index, skelcl::out(m));
80 
81  for (size_t y = 0; y < m.size().rowCount(); ++y) {
82  for (size_t x = 0; x < m.size().columnCount(); ++x) {
83  EXPECT_EQ(y+x, m[y][x]);
84  }
85  }
86 }
87 
88 TEST_F(IndexMatrixTest, SimpleMap) {
89  skelcl::Map<int(skelcl::IndexPoint)> m("int func(IndexPoint i) { return i.y+i.x; }");
90 
91  skelcl::IndexMatrix index({32, 128});
92  EXPECT_EQ(32*128, index.size().elemCount());
93 
94  skelcl::Matrix<int> out = m(index);
95 
96  EXPECT_EQ(out.size().rowCount(), index.size().rowCount());
97  EXPECT_EQ(out.size().columnCount(), index.size().columnCount());
98 
99  for (size_t y = 0; y < out.size().rowCount(); ++y) {
100  for (size_t x = 0; x < out.size().columnCount(); ++x) {
101  EXPECT_EQ(y+x, out[y][x]);
102  }
103  }
104 }
105 
107 
The Matrix class is a two dimensional container which makes its data accessible on the host as well a...
Definition: Matrix.h:190
Out< ContainerType< T > > out(ContainerType< T > &c)
Helper function to create a Out wrapper object.
Definition: Out.h:94
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
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
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.
Definition: SkelCL.cpp:81
This class defines an two-dimensional IndexPoint, i.e. a pair of unsigned integers representing a val...
Definition: Index.h:128
The IndexMatrix (a.k.a. Matrix) class is a special implementation of a Matrix with Elemen...
Definition: IndexMatrix.h:73