42 #include <pvsutil/Logger.h>
45 #include <SkelCL/Vector.h>
54 void testAllPairsWithMatrices(
const unsigned int,
const unsigned int,
const unsigned int);
56 class AllPairsTest :
public ::testing::Test {
71 TEST_F(AllPairsTest, ConstructorWithZipAndReduce) {
72 skelcl::Zip<float(float, float)> zip(
"float func(float x, float y){ return x*y; }");
73 skelcl::Reduce<float(float)> reduce(
"float func(float x, float y){ return x+y; }");
74 skelcl::AllPairs<float(float, float)> allpairs(reduce, zip);
78 TEST_F(AllPairsTest, SquareMatrices64x64) {
79 testAllPairsWithMatrices(64, 64, 64);
83 TEST_F(AllPairsTest, NoSquareMatrices32x128Simple) {
84 testAllPairsWithMatrices(32, 128, 32);
88 TEST_F(AllPairsTest, ArbitraryMatrices) {
89 testAllPairsWithMatrices(100, 60, 11);
97 void testAllPairsWithMatrices(
const unsigned int height,
const unsigned int dim,
const unsigned int width) {
98 skelcl::Zip<float(float, float)> zip(
"float func(float x, float y){ return x*y; }");
99 skelcl::Reduce<float(float)> reduce(
"float func(float x, float y){ return x+y; }");
100 skelcl::AllPairs<float(float, float)> allpairs(reduce, zip);
102 std::vector<float> tmpleft(height*dim);
103 for (
size_t i = 0; i < tmpleft.size(); ++i)
104 tmpleft[i] = rand() % 100;
105 EXPECT_EQ(height*dim, tmpleft.size());
107 std::vector<float> tmpright(dim*width);
108 for (
size_t i = 0; i < tmpright.size(); ++i)
109 tmpright[i] = rand() % 101;
110 EXPECT_EQ(dim*width, tmpright.size());
113 EXPECT_EQ(height, left.rowCount());
114 EXPECT_EQ(dim, left.columnCount());
117 EXPECT_EQ(dim, right.rowCount());
118 EXPECT_EQ(width, right.columnCount());
121 EXPECT_EQ(height, output.rowCount());
122 EXPECT_EQ(width, output.columnCount());
124 for (
size_t i = 0; i < output.rowCount(); ++i) {
125 for (
size_t j = 0; j < output.columnCount(); ++j) {
127 for (
size_t k = 0; k < left.columnCount(); ++k) {
128 tmp += left[i][k] * right[k][j];
130 EXPECT_EQ(tmp, output[i][j]);
136 TEST_F(AllPairsTest, AdditionalArguments) {
137 skelcl::Zip<float(float, float)> zip(
"float func(float x, float y, float a){ return x*y+a; }");
138 skelcl::Reduce<float(float)> reduce(
"float func(float x, float y, float b){ return x+y+b; }");
139 skelcl::AllPairs<float(float, float)> allpairs(reduce, zip);
141 std::vector<float> tmpleft(4096);
142 for (
size_t i = 0; i < tmpleft.size(); ++i)
143 tmpleft[i] = rand() % 100;
144 EXPECT_EQ(4096, tmpleft.size());
146 std::vector<float> tmpright(4096);
147 for (
size_t i = 0; i < tmpright.size(); ++i)
148 tmpright[i] = rand() % 101;
149 EXPECT_EQ(4096, tmpright.size());
152 EXPECT_EQ(64, left.rowCount());
153 EXPECT_EQ(64, left.columnCount());
156 EXPECT_EQ(64, right.rowCount());
157 EXPECT_EQ(64, right.columnCount());
159 float a = 5.0f;
float b = 6.0f;
161 EXPECT_EQ(64, output.rowCount());
162 EXPECT_EQ(64, output.columnCount());
164 for (
size_t i = 0; i < output.rowCount(); ++i) {
165 for (
size_t j = 0; j < output.columnCount(); ++j) {
167 for (
size_t k = 0; k < left.columnCount(); ++k) {
168 tmp += (left[i][k] * right[k][j] + a) + b;
170 EXPECT_EQ(tmp, output[i][j]);
176 TEST_F(AllPairsTest, AlternativeKernelConstructor) {
177 skelcl::AllPairs<float(float, float)> allpairs(
"float func(lmatrix_t* row, rmatrix_t* col, const unsigned int dim){return 1;}");
181 TEST_F(AllPairsTest, AlternativeKernel) {
182 skelcl::AllPairs<float(float, float)> allpairs(
"float func(lmatrix_t* row, rmatrix_t* col, const unsigned int dim) {" \
184 "for (int i = 0; i < dim; ++i) {" \
185 " res += getElementFromRow(row, i) * getElementFromColumn(col, i); }" \
188 const unsigned int height = 100;
189 const unsigned int dim = 55;
190 const unsigned int width = 23;
192 std::vector<float> tmpleft(height*dim);
193 for (
size_t i = 0; i < tmpleft.size(); ++i)
194 tmpleft[i] = rand() % 99;
195 EXPECT_EQ(height*dim, tmpleft.size());
197 std::vector<float> tmpright(dim*width);
198 for (
size_t i = 0; i < tmpright.size(); ++i)
199 tmpright[i] = rand() % 101;
200 EXPECT_EQ(dim*width, tmpright.size());
203 EXPECT_EQ(height, left.rowCount());
204 EXPECT_EQ(dim, left.columnCount());
207 EXPECT_EQ(dim, right.rowCount());
208 EXPECT_EQ(width, right.columnCount());
211 EXPECT_EQ(height, output.rowCount());
212 EXPECT_EQ(width, output.columnCount());
214 for (
size_t i = 0; i < output.rowCount(); ++i) {
215 for (
size_t j = 0; j < output.columnCount(); ++j) {
217 for (
size_t k = 0; k < left.columnCount(); ++k) {
218 tmp += left[i][k] * right[k][j];
220 EXPECT_EQ(tmp, output[i][j]);
226 TEST_F(AllPairsTest, AltKernelAddArguments) {
227 skelcl::AllPairs<float(float, float)> allpairs(
"float func(lmatrix_t* row, rmatrix_t* col, const unsigned int dim, int start) {" \
228 "float res = start;" \
229 "for (int i = 0; i < dim; ++i) {" \
230 " res += getElementFromRow(row, i) * getElementFromColumn(col, i); }" \
233 const unsigned int height = 10;
234 const unsigned int dim = 55;
235 const unsigned int width = 23;
237 std::vector<float> tmpleft(height*dim);
238 for (
size_t i = 0; i < tmpleft.size(); ++i)
239 tmpleft[i] = rand() % 98;
240 EXPECT_EQ(height*dim, tmpleft.size());
242 std::vector<float> tmpright(dim*width);
243 for (
size_t i = 0; i < tmpright.size(); ++i)
244 tmpright[i] = rand() % 107;
245 EXPECT_EQ(dim*width, tmpright.size());
248 EXPECT_EQ(height, left.rowCount());
249 EXPECT_EQ(dim, left.columnCount());
252 EXPECT_EQ(dim, right.rowCount());
253 EXPECT_EQ(width, right.columnCount());
257 EXPECT_EQ(height, output.rowCount());
258 EXPECT_EQ(width, output.columnCount());
260 for (
size_t i = 0; i < output.rowCount(); ++i) {
261 for (
size_t j = 0; j < output.columnCount(); ++j) {
263 for (
size_t k = 0; k < left.columnCount(); ++k) {
264 tmp += left[i][k] * right[k][j];
266 EXPECT_EQ(tmp, output[i][j]);
The Matrix class is a two dimensional container which makes its data accessible on the host as well a...
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...
SKELCL_DLL detail::DeviceProperties nDevices(size_t n)
Creates a detail::DeviceProperties object representing n devices. This object should be used as param...
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.