41 #include <pvsutil/Logger.h>
44 #include <SkelCL/Matrix.h>
45 #include <SkelCL/Vector.h>
54 class MapOverlapTest :
public ::testing::Test {
66 TEST_F(MapOverlapTest, CreateMapOverlapWithString) {
67 skelcl::MapOverlap<float(float)> m {
"float func(input_matrix_t f) \
68 { return -getData(f, 0, 0); }", 1};
72 TEST_F(MapOverlapTest, SimpleMapOverlap) {
73 skelcl::MapOverlap<int(int)> m{
74 "int func(__local int* f){ return f[0]; }", 1 };
77 for (
size_t i = 0; i < input.size(); ++i) {
80 EXPECT_EQ(10, input.size());
84 EXPECT_EQ(10, output.size());
85 for (
size_t i = 0; i < output.size(); ++i) {
86 EXPECT_EQ(input[i], output[i]);
90 TEST_F(MapOverlapTest, SimpleMapOverlap2) {
91 skelcl::MapOverlap<int(int)> m{
92 "int func(__local int* f){ return f[-1]+f[0]+f[1]; }", 1 };
95 for (
size_t i = 0; i < input.size(); ++i) {
98 EXPECT_EQ(10, input.size());
102 EXPECT_EQ(10, output.size());
103 EXPECT_EQ(0+input[0]+input[1], output[0]);
104 for (
size_t i = 1; i < output.size() - 1; ++i) {
105 EXPECT_EQ(input[i-1]+input[i]+input[i+1], output[i]);
107 EXPECT_EQ(input[input.size()-2]+input[input.size()-1]+0, output.back());
110 TEST_F(MapOverlapTest, SimpleMapOverlapWithZeroOverlap) {
111 skelcl::MapOverlap<float(float)> m{
112 "float func(__local float* f){ return -f[0]; }", 0 };
115 for (
size_t i = 0; i < input.size(); ++i) {
118 EXPECT_EQ(10, input.size());
122 EXPECT_EQ(10, output.size());
123 for (
size_t i = 0; i < output.size(); ++i) {
124 EXPECT_EQ(-input[i], output[i]);
128 TEST_F(MapOverlapTest, SimpleMultiDeviceMapOverlap) {
131 skelcl::MapOverlap<int(int)> m{
132 "int func(__local int* f){ return f[0]; }", 1 };
135 for (
size_t i = 0; i < input.size(); ++i) {
138 EXPECT_EQ(10, input.size());
142 EXPECT_EQ(10, output.size());
143 for (
size_t i = 0; i < output.size(); ++i) {
144 EXPECT_EQ(input[i], output[i]);
148 TEST_F(MapOverlapTest, SimpleMultiDeviceMapOverlap2) {
151 skelcl::MapOverlap<int(int)> m{
152 "int func(__local int* f){ return f[-1] + f[0] + f[+1]; }", 1 };
155 for (
size_t i = 0; i < input.size(); ++i) {
158 EXPECT_EQ(499, input.size());
162 EXPECT_EQ(499, output.size());
163 EXPECT_EQ(0+input[0]+input[1], output[0]);
164 for (
size_t i = 1; i < output.size() - 1; ++i) {
165 EXPECT_EQ(input[i-1]+input[i]+input[i+1], output[i]);
167 EXPECT_EQ(input[input.size()-2]+input[input.size()-1]+0, output.back());
174 std::cout << name <<
"\n";
178 std::cout << std::setw(2) << v <<
" ";
179 if (i == m.columnCount()) {
187 TEST_F(MapOverlapTest, SimpleMatrixRightShift) {
188 skelcl::MapOverlap<int(int)> m{
189 "int func(input_matrix_t f){ return getData(f, -1, 0); }", 1};
194 for (
size_t i = 0; i < input.size().rowCount(); ++i) {
195 for (
size_t j = 0; j < input.size().columnCount(); ++j) {
196 input[i][j] = (i*j)+i;
202 EXPECT_EQ(size, output.size().
rowCount());
205 for (
size_t i = 0; i < output.size().
rowCount(); ++i) {
206 EXPECT_EQ(input[i][0], output[i][0]);
209 for (
size_t i = 0; i < output.size().
rowCount(); ++i) {
210 for (
size_t j = 1; j < output.size().
columnCount(); ++j) {
211 EXPECT_EQ(input[i][j-1], output[i][j]);
218 TEST_F(MapOverlapTest, SimpleMatrixTwoRightShift) {
221 skelcl::MapOverlap<int(int)> m{
222 "int func(input_matrix_t f){ return getData(f, -2, 0); }", shift};
225 for (
size_t i = 0; i < input.size().rowCount(); ++i) {
226 for (
size_t j = 0; j < input.size().columnCount(); ++j) {
233 EXPECT_EQ(size, output.size().
rowCount());
236 for (
size_t i = 0; i < output.size().
rowCount(); ++i) {
237 for (
size_t j = shift; j < output.size().
columnCount(); ++j) {
238 EXPECT_EQ(input[i][j - shift], output[i][j]);
242 for (
size_t i = 0; i < output.size().
rowCount(); ++i) {
243 for (
size_t j = 0; j < shift; ++j) {
244 EXPECT_EQ(input[i][0], output[i][j]);
251 TEST_F(MapOverlapTest, SimpleMatrixLeftShift) {
252 skelcl::MapOverlap<int(int)> m{
253 "int func(input_matrix_t f){ return getData(f, +1, 0); }", 1};
258 for (
size_t i = 0; i < input.size().rowCount(); ++i) {
259 for (
size_t j = 0; j < input.size().columnCount(); ++j) {
266 EXPECT_EQ(size, output.size().
rowCount());
269 for (
size_t i = 0; i < output.size().
rowCount(); ++i) {
270 for (
size_t j = 0; j < output.size().
columnCount() - 1; ++j) {
271 EXPECT_EQ(input[i][j+1], output[i][j]);
275 for (
size_t i = 0; i < output.size().
rowCount(); ++i) {
277 EXPECT_EQ(input[i][j], output[i][j]);
283 TEST_F(MapOverlapTest, SimpleMatrixTwoLeftShift) {
286 skelcl::MapOverlap<int(int)> m{
287 "int func(input_matrix_t f){ return getData(f, +2, 0); }", shift};
290 for (
size_t i = 0; i < input.size().rowCount(); ++i) {
291 for (
size_t j = 0; j < input.size().columnCount(); ++j) {
298 EXPECT_EQ(size, output.size().
rowCount());
301 for (
size_t i = 0; i < output.size().
rowCount(); ++i) {
302 for (
size_t j = 0; j < output.size().
columnCount() - shift; ++j) {
303 EXPECT_EQ(input[i][j + shift], output[i][j]);
307 for (
size_t i = 0; i < output.size().
rowCount(); ++i) {
308 for (
size_t j = output.size().
columnCount() - shift;
310 EXPECT_EQ(input[i][output.size().
columnCount()-1], output[i][j]);
317 TEST_F(MapOverlapTest, SimpleMatrixDownShift) {
318 skelcl::MapOverlap<int(int)> m{
319 "int func(input_matrix_t f){ return getData(f, 0, -1); }", 1};
324 for (
size_t i = 0; i < input.size().rowCount(); ++i) {
325 for (
size_t j = 0; j < input.size().columnCount(); ++j) {
332 EXPECT_EQ(size, output.size().
rowCount());
335 for (
size_t j = 0; j < output.size().
columnCount(); ++j) {
336 EXPECT_EQ(input[0][j], output[0][j]);
339 for (
size_t i = 1; i < output.size().
rowCount(); ++i) {
340 for (
size_t j = 0; j < output.size().
columnCount(); ++j) {
341 EXPECT_EQ(input[i-1][j], output[i][j]);
348 TEST_F(MapOverlapTest, SimpleMatrixTwoDownShift) {
351 skelcl::MapOverlap<int(int)> m{
352 "int func(input_matrix_t f){ return getData(f, 0, -2); }", shift};
355 for (
size_t i = 0; i < input.size().rowCount(); ++i) {
356 for (
size_t j = 0; j < input.size().columnCount(); ++j) {
363 EXPECT_EQ(size, output.size().
rowCount());
366 for (
size_t i = 0; i < shift; i++) {
367 for (
size_t j = 0; j < output.size().
columnCount(); ++j) {
368 EXPECT_EQ(input[0][j], output[i][j]);
372 for (
size_t i = shift; i < output.size().
rowCount(); ++i) {
373 for (
size_t j = 0; j < output.size().
columnCount(); ++j) {
374 EXPECT_EQ(input[i-shift][j], output[i][j]);
381 TEST_F(MapOverlapTest, SimpleMatrixUpShift) {
384 skelcl::MapOverlap<int(int)> m{
385 "int func(input_matrix_t f){ return getData(f, 0, +1); }", shift};
388 for (
size_t i = 0; i < input.size().rowCount(); ++i) {
389 for (
size_t j = 0; j < input.size().columnCount(); ++j) {
396 EXPECT_EQ(size, output.size().
rowCount());
399 for (
size_t i = 0; i < output.size().
rowCount() - shift; ++i) {
400 for (
size_t j = 0; j < output.size().
columnCount(); ++j) {
401 EXPECT_EQ(input[i + shift][j], output[i][j]);
405 for (
size_t i = output.size().
rowCount() - shift;
406 i < output.size().
rowCount(); i++) {
407 for (
size_t j = 0; j < output.size().
columnCount(); ++j) {
408 EXPECT_EQ(input[i][j], output[i][j]);
415 TEST_F(MapOverlapTest, SimpleMatrixTwoUpShift) {
418 skelcl::MapOverlap<int(int)> m{
419 "int func(input_matrix_t f){ return getData(f, 0, +2); }", shift};
422 for (
size_t i = 0; i < input.size().rowCount(); ++i) {
423 for (
size_t j = 0; j < input.size().columnCount(); ++j) {
430 EXPECT_EQ(size, output.size().
rowCount());
433 for (
size_t i = 0; i < output.size().
rowCount() - shift; ++i) {
434 for (
size_t j = 0; j < output.size().
columnCount(); ++j) {
435 EXPECT_EQ(input[i + shift][j], output[i][j]);
439 for (
size_t i = output.size().
rowCount() - shift;
440 i < output.size().
rowCount(); i++) {
441 for (
size_t j = 0; j < output.size().
columnCount(); ++j) {
442 EXPECT_EQ(input[output.size().
rowCount()-1][j], output[i][j]);
450 TEST_F(MapOverlapTest, SimpleMatrixMapOverlap2) {
451 skelcl::MapOverlap<int(int)> m{
452 "int func(__local int* f){ return f[-1]+f[0]+f[1]; }", 1 };
455 for (
size_t i = 0; i < input.size(); ++i) {
458 EXPECT_EQ(10, input.size());
462 EXPECT_EQ(10, output.size());
463 EXPECT_EQ(0+input[0]+input[1], output[0]);
464 for (
size_t i = 1; i < output.size() - 1; ++i) {
465 EXPECT_EQ(input[i-1]+input[i]+input[i+1], output[i]);
467 EXPECT_EQ(input[input.size()-2]+input[input.size()-1]+0, output.back());
470 TEST_F(MapOverlapTest, SimpleMatrixMultiDeviceMapOverlap) {
473 skelcl::MapOverlap<int(int)> m{
474 "int func(__local int* f){ return f[0]; }", 1 };
477 for (
size_t i = 0; i < input.size(); ++i) {
480 EXPECT_EQ(10, input.size());
484 EXPECT_EQ(10, output.size());
485 for (
size_t i = 0; i < output.size(); ++i) {
486 EXPECT_EQ(input[i], output[i]);
490 TEST_F(MapOverlapTest, SimpleMatrixMultiDeviceMapOverlap2) {
493 skelcl::MapOverlap<int(int)> m{
494 "int func(__local int* f){ return f[-1] + f[0] + f[+1]; }", 1 };
497 for (
size_t i = 0; i < input.size(); ++i) {
500 EXPECT_EQ(499, input.size());
504 EXPECT_EQ(499, output.size());
505 EXPECT_EQ(0+input[0]+input[1], output[0]);
506 for (
size_t i = 1; i < output.size() - 1; ++i) {
507 EXPECT_EQ(input[i-1]+input[i]+input[i+1], output[i]);
509 EXPECT_EQ(input[input.size()-2]+input[input.size()-1]+0, output.back());
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...
The Vector class is a one dimensional container which makes its data accessible on the host as well a...
This class defines a two dimensional size for a Matrix.
size_type rowCount() const
Returns the number of rows.
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.
size_type columnCount() const
Returns the number of columns.