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
ReduceTests.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 
38 
39 #include <fstream>
40 
41 #include <pvsutil/Logger.h>
42 
43 #include <SkelCL/SkelCL.h>
44 #include <SkelCL/Vector.h>
45 #include <SkelCL/Reduce.h>
46 
47 #include <SkelCL/detail/Device.h>
48 
49 #include <iostream>
50 
51 #include "Test.h"
54 
55 typedef skelcl::detail::Device::Type device_type;
56 
57 class ReduceTest : public ::testing::Test {
58 protected:
59  ReduceTest()
60  {
61  //pvsutil::defaultLogger.setLoggingLevel(
62  // pvsutil::Logger::Severity::DebugInfo);
64  }
65 
66  ~ReduceTest()
67  {
69  }
70 };
71 
72 TEST_F(ReduceTest, CreateReduce)
73 {
74  skelcl::Reduce<float(float)> r("float func(float x, float y){ return x+y; }");
75 }
76 
77 TEST_F(ReduceTest, SimpleReduce)
78 {
79  skelcl::Reduce<float(float)> r("float func(float x, float y){ return x+y; }");
80 
81  skelcl::Vector<float> input(100);
82  for (size_t i = 0; i < input.size(); ++i) {
83  input[i] = i;
84  }
85 
86  skelcl::Vector<float> output = r(input);
87 
88  EXPECT_LE(1, output.size());
89  EXPECT_EQ(4950, output[0]);
90 }
91 
92 TEST_F(ReduceTest, AdditionalArg)
93 {
94  skelcl::Reduce<float(float)> r(
95  "float func(float x, float y, float a){ return a*(x+y); }");
96 
97  skelcl::Vector<float> input(100);
98  for (size_t i = 0; i < input.size(); ++i) {
99  input[i] = i;
100  }
101 
102  skelcl::Vector<float> output = r(input, 1.0f);
103 
104  EXPECT_LE(1, output.size());
105  EXPECT_EQ(4950, output[0]);
106 }
107 
108 TEST_F(ReduceTest, SimpleReduce2)
109 {
110  skelcl::Reduce<int(int)> r("int func(int x, int y){ return x+y; }");
111 
112  skelcl::Vector<int> input(1587);
113  for (unsigned int i = 0; i < input.size(); ++i) {
114  input[i] = i;
115  }
116 
117  skelcl::Vector<int> output = r(input);
118 
119  EXPECT_LE(1, output.size());
120  EXPECT_EQ(1258491, output[0]);
121 }
122 
123 TEST_F(ReduceTest, LongReduce)
124 {
125  skelcl::Reduce<int(int)> r("int func(int x, int y){ return x+y; }");
126 
127  skelcl::Vector<int> input(100000000);
128  for (unsigned int i = 0; i < input.size(); ++i) {
129  input[i] = 1;
130  }
131 
132  skelcl::Vector<int> output = r(input);
133 
134  EXPECT_LE(1, output.size());
135  EXPECT_EQ(100000000, output[0]);
136 }
137 
138 TEST_F(ReduceTest, nSizesReduce1)
139 {
140  skelcl::Reduce<float(float)> r("float func(float x, float y){ return x+y; }");
141 
142  const int N = 256;
143 
144  skelcl::Vector<float> input;
145  skelcl::Vector<float> output;
146 
147  for (int i = 1; i < N; ++i) {
148  input.resize(i, 1);
149  output = r(input);
150 
151  EXPECT_EQ(input.size(), output[0]);
152  }
153 }
154 
155 TEST_F(ReduceTest, nSizesReduce2)
156 {
157  skelcl::Reduce<float(float)> r("float func(float x, float y){ return x+y; }");
158 
159  const int N = 256;
160 
161  skelcl::Vector<float> input;
162  skelcl::Vector<float> output;
163 
164  for (int i = 8192; i < (8192 + N); ++i) {
165  input.resize(i, 1);
166  output = r(input);
167 
168  EXPECT_EQ(input.size(), output[0]);
169  }
170 }
171 
173 
detail::Device::Type device_type
Public name for a type representing different types of device. E.g. CPU or GPU.
Definition: SkelCL.h:137
size_type size() const
Returns the number of elements in 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
void resize(size_type count, T value=T())
Resizes the container to contain count elements.
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
The Vector class is a one dimensional container which makes its data accessible on the host as well a...
Definition: Vector.h:113
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.
Definition: SkelCL.cpp:81