LCOV - code coverage report
Current view: top level - test - ShiftTilePatternTest.cc (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 148 157 94.3 %
Date: 2016-06-29 12:30:40 Functions: 22 22 100.0 %

          Line data    Source code
       1             : #include <libdash.h>
       2             : #include <gtest/gtest.h>
       3             : 
       4             : #include "TestBase.h"
       5             : #include "TestLogHelpers.h"
       6             : #include "ShiftTilePatternTest.h"
       7             : 
       8             : 
       9          20 : TEST_F(ShiftTilePatternTest, Distribute1DimTile)
      10             : {
      11           4 :   DASH_TEST_LOCAL_ONLY();
      12             : 
      13             :   typedef dash::default_index_t index_t;
      14             : 
      15           1 :   size_t team_size  = dash::Team::All().size();
      16           1 :   size_t block_size = 3;
      17           1 :   size_t extent     = team_size * block_size * 2;
      18           1 :   size_t num_blocks = dash::math::div_ceil(extent, block_size);
      19           1 :   size_t local_cap  = block_size *
      20           2 :                       dash::math::div_ceil(num_blocks, team_size);
      21             :   dash::ShiftTilePattern<1, dash::ROW_MAJOR> pat_tile_row(
      22             :     dash::SizeSpec<1>(extent),
      23           2 :     dash::DistributionSpec<1>(dash::TILE(block_size)),
      24             :     dash::TeamSpec<1>(),
      25           4 :     dash::Team::All());
      26             :   // Check that memory order is irrelevant for 1-dim
      27             :   dash::ShiftTilePattern<1, dash::COL_MAJOR> pat_tile_col(
      28             :     dash::SizeSpec<1>(extent),
      29           2 :     dash::DistributionSpec<1>(dash::TILE(block_size)),
      30             :     dash::TeamSpec<1>(),
      31           4 :     dash::Team::All());
      32           1 :   EXPECT_EQ(pat_tile_row.capacity(), extent);
      33           1 :   EXPECT_EQ(pat_tile_row.blocksize(0), block_size);
      34           1 :   EXPECT_EQ(pat_tile_row.local_capacity(), local_cap);
      35           1 :   EXPECT_EQ(pat_tile_col.capacity(), extent);
      36           1 :   EXPECT_EQ(pat_tile_col.blocksize(0), block_size);
      37           1 :   EXPECT_EQ(pat_tile_col.local_capacity(), local_cap);
      38             : 
      39             :   std::array<index_t, 1> expected_coord;
      40          25 :   for (int x = 0; x < static_cast<int>(extent); ++x) {
      41          24 :     expected_coord[0]         = x;
      42          24 :     index_t expected_unit_id  = (x / block_size) % team_size;
      43          24 :     index_t block_index       = x / block_size;
      44          24 :     index_t block_base_offset = block_size * (block_index / team_size);
      45          24 :     index_t expected_offset   = (x % block_size) + block_base_offset;
      46             :     // Row major:
      47          24 :     EXPECT_EQ(
      48             :       expected_coord,
      49           0 :       pat_tile_row.coords(x));
      50          24 :     EXPECT_EQ(
      51             :       expected_unit_id,
      52           0 :       pat_tile_row.unit_at(x));
      53          24 :     EXPECT_EQ(
      54             :       expected_offset,
      55           0 :       pat_tile_row.at(x));
      56          24 :     EXPECT_EQ(
      57             :       (std::array<index_t, 1> { x }),
      58             :       pat_tile_row.global(
      59           0 :         expected_unit_id, (std::array<index_t, 1> { expected_offset })));
      60             :     // Column major:
      61          24 :     EXPECT_EQ(
      62             :       expected_coord,
      63           0 :       pat_tile_col.coords(x));
      64          24 :     EXPECT_EQ(
      65             :       expected_unit_id,
      66           0 :       pat_tile_col.unit_at(x));
      67          24 :     EXPECT_EQ(
      68             :       expected_offset,
      69           0 :       pat_tile_col.at(x));
      70          24 :     EXPECT_EQ(
      71             :       (std::array<index_t, 1> { x }),
      72             :       pat_tile_col.global(
      73           0 :         expected_unit_id, (std::array<index_t, 1> { expected_offset })));
      74             :   }
      75             : }
      76             : 
      77          20 : TEST_F(ShiftTilePatternTest, Distribute2DimTile)
      78             : {
      79           7 :   DASH_TEST_LOCAL_ONLY();
      80             : 
      81             :   typedef dash::default_index_t index_t;
      82             : 
      83           1 :   if (dash::size() % 2 != 0) {
      84             :     LOG_MESSAGE("Team size must be multiple of 2 for "
      85             :                 "ShiftTilePatternTest.Distribute2DimTile");
      86           0 :     return;
      87             :   }
      88             : 
      89             :   // 2-dimensional, blocked partitioning in first dimension:
      90             :   //
      91             :   // [ team 0[0] | team 0[1] | ... | team 0[8]  | team 0[9]  | ... ]
      92             :   // [ team 0[2] | team 0[3] | ... | team 0[10] | team 0[11] | ... ]
      93             :   // [ team 0[4] | team 0[5] | ... | team 0[12] | team 0[13] | ... ]
      94             :   // [ team 0[6] | team 0[7] | ... | team 0[14] | team 0[15] | ... ]
      95           1 :   size_t team_size      = dash::Team::All().size();
      96             :   // Choose 'inconvenient' extents:
      97           1 :   size_t block_size_x   = 3;
      98           1 :   size_t block_size_y   = 2;
      99           1 :   size_t block_size     = block_size_x * block_size_y;
     100           1 :   size_t extent_x       = team_size * 3 * block_size_x;
     101           1 :   size_t extent_y       = team_size * 2 * block_size_y;
     102           1 :   size_t size           = extent_x * extent_y;
     103           1 :   size_t max_per_unit   = size / team_size;
     104             :   LOG_MESSAGE("e:%d,%d, bs:%d,%d, nu:%d, mpu:%d",
     105             :               extent_x, extent_y,
     106             :               block_size_x, block_size_y,
     107             :               team_size,
     108             :               max_per_unit);
     109             :   dash::ShiftTilePattern<2, dash::ROW_MAJOR> pat_tile_row(
     110             :     dash::SizeSpec<2>(extent_x, extent_y),
     111             :     dash::DistributionSpec<2>(
     112           2 :       dash::TILE(block_size_x),
     113           2 :       dash::TILE(block_size_y)),
     114           1 :     dash::TeamSpec<2>(dash::size()/2, 2),
     115           4 :     dash::Team::All());
     116             :   dash::ShiftTilePattern<2, dash::COL_MAJOR> pat_tile_col(
     117             :     dash::SizeSpec<2>(extent_x, extent_y),
     118             :     dash::DistributionSpec<2>(
     119           2 :       dash::TILE(block_size_x),
     120           2 :       dash::TILE(block_size_y)),
     121           1 :     dash::TeamSpec<2>(dash::size()/2, 2),
     122           4 :     dash::Team::All());
     123             : 
     124           1 :   if (dash::myid() == 0) {
     125           2 :     dash::test::print_pattern_mapping(
     126             :       "pattern.row.unit_at", pat_tile_row, 3,
     127         576 :     [](const decltype(pat_tile_row) & _pattern, int _x, int _y) -> int {
     128         576 :       return _pattern.unit_at(std::array<index_t, 2> {_x, _y});
     129           1 :     });
     130           2 :     dash::test::print_pattern_mapping(
     131             :       "pattern.row.at", pat_tile_row, 3,
     132         576 :     [](const decltype(pat_tile_row) & _pattern, int _x, int _y) -> index_t {
     133         576 :       return _pattern.at(std::array<index_t, 2> {_x, _y});
     134           1 :     });
     135           2 :     dash::test::print_pattern_mapping(
     136             :       "pattern.row.local_index", pat_tile_row, 3,
     137         576 :     [](const decltype(pat_tile_row) & _pattern, int _x, int _y) -> index_t {
     138         576 :       return _pattern.local_index(std::array<index_t, 2> {_x, _y}).index;
     139           1 :     });
     140           2 :     dash::test::print_pattern_mapping(
     141             :       "pattern.row.local_coords", pat_tile_row, 5,
     142         576 :     [](const decltype(pat_tile_row) & _pat, int _x, int _y) -> std::string {
     143         576 :       auto l_c = _pat.local_coords(std::array<index_t, 2> {_x, _y});
     144        1152 :       std::ostringstream ss;
     145         576 :       ss << l_c[0] << "," << l_c[1];
     146        1152 :       return ss.str();
     147           1 :     });
     148           2 :     dash::test::print_pattern_mapping(
     149             :       "pattern.col.unit_at", pat_tile_col, 3,
     150         576 :     [](const decltype(pat_tile_col) & _pattern, int _x, int _y) -> int {
     151         576 :       return _pattern.unit_at(std::array<index_t, 2> {_x, _y});
     152           1 :     });
     153           2 :     dash::test::print_pattern_mapping(
     154             :       "pattern.col.at", pat_tile_col, 3,
     155         576 :     [](const decltype(pat_tile_col) & _pattern, int _x, int _y) -> index_t {
     156         576 :       return _pattern.at(std::array<index_t, 2> {_x, _y});
     157           1 :     });
     158           2 :     dash::test::print_pattern_mapping(
     159             :       "pattern.col.local_index", pat_tile_col, 3,
     160         576 :     [](const decltype(pat_tile_col) & _pattern, int _x, int _y) -> index_t {
     161         576 :       return _pattern.local_index(std::array<index_t, 2> {_x, _y}).index;
     162           1 :     });
     163           2 :     dash::test::print_pattern_mapping(
     164             :       "pattern.col.local_coords", pat_tile_col, 5,
     165         576 :     [](const decltype(pat_tile_col) & _pat, int _x, int _y) -> std::string {
     166         576 :       auto l_c = _pat.local_coords(std::array<index_t, 2> {_x, _y});
     167        1152 :       std::ostringstream ss;
     168         576 :       ss << l_c[0] << "," << l_c[1];
     169        1152 :       return ss.str();
     170           1 :     });
     171             :   }
     172             : 
     173           1 :   ASSERT_EQ(dash::TeamSpec<2>(dash::Team::All()).size(), team_size);
     174           1 :   ASSERT_EQ(pat_tile_row.capacity(), size);
     175           1 :   ASSERT_EQ(pat_tile_row.local_capacity(), max_per_unit);
     176           1 :   ASSERT_EQ(pat_tile_row.blocksize(0), block_size_x);
     177           1 :   ASSERT_EQ(pat_tile_row.blocksize(1), block_size_y);
     178           1 :   ASSERT_EQ(pat_tile_col.capacity(), size);
     179           1 :   ASSERT_EQ(pat_tile_col.local_capacity(), max_per_unit);
     180           1 :   ASSERT_EQ(pat_tile_col.blocksize(0), block_size_x);
     181           1 :   ASSERT_EQ(pat_tile_col.blocksize(1), block_size_y);
     182             :   // number of overflow blocks, e.g. 7 elements, 3 teams -> 1
     183          37 :   for (int x = 0; x < static_cast<int>(extent_x); ++x) {
     184         612 :     for (int y = 0; y < static_cast<int>(extent_y); ++y) {
     185         576 :       int num_blocks_x        = extent_x / block_size_x;
     186         576 :       int num_blocks_y        = extent_y / block_size_y;
     187         576 :       int num_l_blocks_x      = num_blocks_x / team_size;
     188         576 :       int num_l_blocks_y      = num_blocks_y / team_size;
     189         576 :       int block_index_x       = x / block_size_x;
     190         576 :       int block_index_y       = y / block_size_y;
     191         576 :       int unit_id             = (block_index_x + block_index_y) % team_size;
     192             : //    int l_block_index_x     = block_index_x / team_size;
     193         576 :       int l_block_index_y     = block_index_y / team_size;
     194             : //    int l_block_index_col   = (block_index_y * num_l_blocks_x) +
     195             : //                              l_block_index_x;
     196         576 :       int l_block_index_row   = (block_index_x * num_l_blocks_y) +
     197         576 :                                 l_block_index_y;
     198             : //    int phase_x             = (x % block_size_x);
     199         576 :       int phase_y             = (y % block_size_y);
     200             : //    int phase_col           = (y % block_size_y) * block_size_x +
     201             : //                              phase_x;
     202         576 :       int phase_row           = (x % block_size_x) * block_size_y +
     203         576 :                                 phase_y;
     204             : //    int local_x             = l_block_index_x * block_size_x + phase_x;
     205             : //    int local_y             = l_block_index_y * block_size_y + phase_y;
     206             : //    int local_index_col     = (l_block_index_col * block_size) +
     207             : //                              phase_col;
     208             :       int local_index_row     = (l_block_index_row * block_size) +
     209         576 :                                 phase_row;
     210             : 
     211             :       dash__unused(num_l_blocks_y);
     212             : 
     213             :       auto local_coords_row   = pat_tile_row.local_coords(
     214         576 :                                   std::array<index_t, 2> { x, y });
     215             : //    auto local_coords_col   = pat_tile_col.local_coords(
     216             : //                                std::array<index_t, 2> { x, y });
     217             :       LOG_MESSAGE("R %d,%d, u:%d, b:%d,%d, nlb:%d,%d, lc: %d,%d, lbi:%d, p:%d",
     218             :                   x, y,
     219             :                   unit_id,
     220             :                   block_index_x, block_index_y,
     221             :                   num_l_blocks_x, num_l_blocks_y,
     222             :                   local_coords_row[0], local_coords_row[1],
     223             :                   l_block_index_row,
     224             :                   phase_row);
     225         576 :       ASSERT_EQ_U(
     226             :         unit_id,
     227             :         pat_tile_row.unit_at(std::array<index_t, 2> { x, y }));
     228         576 :       ASSERT_EQ_U(
     229             :         local_index_row,
     230             :         pat_tile_row.at(std::array<index_t, 2> { x, y }));
     231         576 :       ASSERT_EQ_U(
     232             :         local_index_row,
     233             :         pat_tile_row.local_at(local_coords_row));
     234             :       auto glob_coords_row =
     235             :         pat_tile_row.global(
     236             :           unit_id,
     237         576 :           std::array<index_t, 2> { local_coords_row[0], local_coords_row[1] });
     238         576 :       ASSERT_EQ_U(
     239             :         (std::array<index_t, 2> { x, y }),
     240             :         glob_coords_row);
     241             :     }
     242             :   }
     243             : }
     244             : 
     245          20 : TEST_F(ShiftTilePatternTest, Tile2DimTeam1Dim)
     246             : {
     247           7 :   DASH_TEST_LOCAL_ONLY();
     248             : 
     249             :   typedef dash::default_index_t index_t;
     250             : 
     251             :   // 2-dimensional, blocked partitioning in first dimension:
     252             :   //
     253             :   // [ team 0[0] | team 0[1] | ... | team 0[8]  | team 0[9]  | ... ]
     254             :   // [ team 0[2] | team 0[3] | ... | team 0[10] | team 0[11] | ... ]
     255             :   // [ team 0[4] | team 0[5] | ... | team 0[12] | team 0[13] | ... ]
     256             :   // [ team 0[6] | team 0[7] | ... | team 0[14] | team 0[15] | ... ]
     257           1 :   size_t team_size      = dash::Team::All().size();
     258             :   // Choose 'inconvenient' extents:
     259           1 :   size_t block_size_x   = 3;
     260           1 :   size_t block_size_y   = 2;
     261           1 :   size_t block_size     = block_size_x * block_size_y;
     262           1 :   size_t extent_x       = team_size * 2 * block_size_x;
     263           1 :   size_t extent_y       = team_size * 2 * block_size_y;
     264           1 :   size_t size           = extent_x * extent_y;
     265           1 :   size_t max_per_unit   = size / team_size;
     266             :   LOG_MESSAGE("e:%d,%d, bs:%d,%d, nu:%d, mpu:%d",
     267             :               extent_x, extent_y,
     268             :               block_size_x, block_size_y,
     269             :               team_size,
     270             :               max_per_unit);
     271             :   dash__unused(max_per_unit);
     272             :   dash__unused(block_size);
     273             : 
     274           1 :   ASSERT_EQ(dash::TeamSpec<2>(dash::Team::All()).size(), team_size);
     275             : 
     276           1 :   dash::TeamSpec<2> teamspec_1d(dash::Team::All());
     277           1 :   ASSERT_EQ(1,            teamspec_1d.rank());
     278           1 :   ASSERT_EQ(dash::size(), teamspec_1d.num_units(0));
     279           1 :   ASSERT_EQ(1,            teamspec_1d.num_units(1));
     280           1 :   ASSERT_EQ(dash::size(), teamspec_1d.size());
     281             : 
     282             :   dash::ShiftTilePattern<2, dash::ROW_MAJOR> pattern(
     283             :     dash::SizeSpec<2>(extent_x, extent_y),
     284             :     dash::DistributionSpec<2>(
     285           2 :       dash::TILE(block_size_x),
     286           2 :       dash::TILE(block_size_y)),
     287             :     teamspec_1d,
     288           2 :     dash::Team::All());
     289             : 
     290           2 :   std::vector< std::vector<dart_unit_t> > pattern_units;
     291          17 :   for (int y = 0; y < static_cast<int>(extent_y); ++y) {
     292          32 :     std::vector<dart_unit_t> row_units;
     293         400 :     for (int x = 0; x < static_cast<int>(extent_x); ++x) {
     294         384 :       row_units.push_back(pattern.unit_at(std::array<index_t, 2> { x, y }));
     295             :     }
     296          16 :     pattern_units.push_back(row_units);
     297             :   }
     298           1 :   for (auto row_units : pattern_units) {
     299             :     DASH_LOG_DEBUG_VAR("ShiftTilePatternTest.Tile2DimTeam1Dim", row_units);
     300             :   }
     301          12 : }

Generated by: LCOV version 1.12