LCOV - code coverage report
Current view: top level - test - SUMMATest.cc (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 83 83 100.0 %
Date: 2016-06-29 12:30:40 Functions: 11 11 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 "SUMMATest.h"
       7             : 
       8          20 : TEST_F(SUMMATest, Deduction)
       9             : {
      10           4 :   size_t num_units   = dash::Team::All().size();
      11           4 :   size_t team_size_x = num_units;
      12           4 :   size_t team_size_y = 1;
      13             : 
      14           4 :   size_t extent_cols = num_units;
      15           4 :   size_t extent_rows = num_units;
      16             : 
      17             : #if 0
      18             :   // For explicit definition of data distribution:
      19             :   //
      20             :   pattern_t pattern(
      21             :     dash::SizeSpec<2>(
      22             :       extent_cols,
      23             :       extent_rows),
      24             :     dash::DistributionSpec<2>(
      25             :       dash::TILE(tilesize_x),
      26             :       dash::TILE(tilesize_y))
      27             :   );
      28             : #endif
      29             : 
      30             :   // Automatically deduce pattern type satisfying constraints defined by
      31             :   // SUMMA implementation:
      32           4 :   dash::SizeSpec<2> size_spec(extent_cols, extent_rows);
      33           4 :   dash::TeamSpec<2> team_spec(team_size_x, team_size_y);
      34           4 :   team_spec.balance_extents();
      35             : 
      36             :   LOG_MESSAGE("Initialize matrix pattern ...");
      37             :   auto pattern = dash::make_pattern <
      38             :                  dash::summa_pattern_partitioning_constraints,
      39             :                  dash::summa_pattern_mapping_constraints,
      40             :                  dash::summa_pattern_layout_constraints >(
      41             :                    size_spec,
      42           4 :                    team_spec);
      43             : 
      44             :   LOG_MESSAGE("SizeSpec(%lu,%lu) TeamSpec(%lu,%lu)",
      45             :               size_spec.extent(0), size_spec.extent(1),
      46             :               team_spec.extent(0), team_spec.extent(1));
      47             : 
      48             :   typedef double                value_t;
      49             :   typedef decltype(pattern)     pattern_t;
      50             :   typedef pattern_t::index_type index_t;
      51             : 
      52           4 :   if (_dash_id == 0) {
      53           2 :     dash::test::print_pattern_mapping(
      54             :       "pattern.unit_at", pattern, 3,
      55          16 :       [](const pattern_t & _pattern, int _x, int _y) -> dart_unit_t {
      56          16 :           return _pattern.unit_at(std::array<index_t, 2> {_x, _y});
      57           1 :       });
      58             :   }
      59             : 
      60             :   LOG_MESSAGE("Deduced pattern: "
      61             :               "size(%d,%d) tilesize(%d,%d) teamsize(%d,%d) disttype(%d,%d)",
      62             :               pattern.extent(0),
      63             :               pattern.extent(1),
      64             :               pattern.block(0).extent(0),
      65             :               pattern.block(0).extent(1),
      66             :               pattern.teamspec().extent(0),
      67             :               pattern.teamspec().extent(1),
      68             :               pattern.distspec()[0].type,
      69             :               pattern.distspec()[1].type);
      70             : 
      71             :   // Plausibility check of single pattern traits:
      72           4 :   ASSERT_TRUE_U(
      73             :     dash::pattern_partitioning_traits<decltype(pattern)>::type::balanced);
      74           4 :   ASSERT_TRUE_U(
      75             :     dash::pattern_partitioning_traits<decltype(pattern)>::type::minimal);
      76           4 :   ASSERT_TRUE_U(
      77             :     dash::pattern_mapping_traits<decltype(pattern)>::type::unbalanced);
      78           4 :   ASSERT_TRUE_U(
      79             :     dash::pattern_layout_traits<decltype(pattern)>::type::blocked);
      80           4 :   ASSERT_TRUE_U(
      81             :     dash::pattern_layout_traits<decltype(pattern)>::type::linear);
      82           4 :   ASSERT_FALSE_U(
      83             :     dash::pattern_layout_traits<decltype(pattern)>::type::canonical);
      84             : 
      85             :   // Test pattern constraints verification. Pattern has been deduced from
      86             :   // a set of constraints, so it is expected to satisfy these constraints:
      87             :   const bool constraints_matched =
      88             :     dash::check_pattern_constraints <
      89             :         dash::summa_pattern_partitioning_constraints,
      90             :         dash::summa_pattern_mapping_constraints,
      91           4 :         dash::summa_pattern_layout_constraints >(
      92           4 :       pattern);
      93           4 :   ASSERT_TRUE_U(constraints_matched);
      94             : 
      95             :   // Create operands and result matrices with identical distribution pattern:
      96             :   LOG_MESSAGE("Initialize matrix instances ...");
      97           8 :   dash::Matrix<value_t, 2, index_t, decltype(pattern)> matrix_a(pattern);
      98           8 :   dash::Matrix<value_t, 2, index_t, decltype(pattern)> matrix_b(pattern);
      99           8 :   dash::Matrix<value_t, 2, index_t, decltype(pattern)> matrix_c(pattern);
     100             : 
     101             :   LOG_MESSAGE("Starting initialization of matrix values");
     102           4 :   dash::barrier();
     103             : 
     104             :   // Initialize operands:
     105           4 :   if (_dash_id == 0) {
     106             :     // Matrix B is identity matrix:
     107           5 :     for (index_t d = 0; d < static_cast<index_t>(extent_rows); ++d) {
     108             :       LOG_MESSAGE("Setting matrix B value (%d,%d)", d, d);
     109           4 :       matrix_b[d][d] = 1;
     110             :     }
     111           5 :     for (index_t row = 0; row < static_cast<index_t>(extent_rows); ++row) {
     112          20 :       for (index_t col = 0; col < static_cast<index_t>(extent_cols); ++col) {
     113             :         LOG_MESSAGE("Initialize A matrix value (%d,%d)", col, row);
     114          16 :         auto unit  = matrix_a.pattern()
     115          32 :                              .unit_at(std::array<index_t, 2> { col, row });
     116          16 :         value_t value = ((1 + col) * 10000) + ((row + 1) * 100) + unit;
     117             :         LOG_MESSAGE("Setting matrix A value (%d,%d)", col, row);
     118          16 :         matrix_a[col][row] = value;
     119             :       }
     120             :     }
     121             :   }
     122             : 
     123             :   LOG_MESSAGE("Waiting for initialization of matrices ...");
     124           4 :   dash::barrier();
     125             : 
     126             :   // Expected to be resolved to SUMMA version of dash::mmult:
     127             :   LOG_MESSAGE("Calling dash::mmult ...");
     128             :   dash::mmult(matrix_a,
     129             :                  matrix_b,
     130           4 :                  matrix_c);
     131             : 
     132           4 :   if (_dash_id == 0) {
     133           1 :     dash::test::print_matrix("summa.matrix A", matrix_a, 3);
     134           1 :     dash::test::print_matrix("summa.matrix B", matrix_b, 3);
     135           1 :     dash::test::print_matrix("summa.matrix C", matrix_c, 3);
     136             :   }
     137             : 
     138           4 :   dash::barrier();
     139             : 
     140             :   // Verify multiplication result (A x id = A):
     141             :   if (false && _dash_id == 0) {
     142             :     // Multiplication of matrix A with identity matrix B should be identical
     143             :     // to matrix A:
     144             :     for (index_t row = 0; row < static_cast<index_t>(extent_rows); ++row) {
     145             :       for (index_t col = 0; col < static_cast<index_t>(extent_cols); ++col) {
     146             :         auto unit = matrix_a.pattern()
     147             :                             .unit_at(std::array<index_t, 2> { col, row });
     148             :         value_t expect = ((1 + col) * 10000) + ((row + 1) * 100) + unit;
     149             :         value_t actual = matrix_c[col][row];
     150             :         ASSERT_EQ_U(expect, actual);
     151             :       }
     152             :     }
     153             :   }
     154             : 
     155           4 :   dash::barrier();
     156             : }
     157             : 
     158          20 : TEST_F(SUMMATest, SeqTilePatternMatrix)
     159             : {
     160             :   typedef dash::SeqTilePattern<2> pattern_t;
     161             :   typedef double                  value_t;
     162             :   typedef pattern_t::index_type   index_t;
     163             :   typedef pattern_t::size_type    extent_t;
     164             : 
     165           4 :   extent_t tile_size   = 7;
     166           4 :   extent_t base_size   = tile_size * 3;
     167           4 :   extent_t extent_rows = dash::size() * base_size;
     168           4 :   extent_t extent_cols = dash::size() * base_size;
     169           4 :   dash::SizeSpec<2> size_spec(extent_rows, extent_cols);
     170             : 
     171             :   auto team_spec = dash::make_team_spec<
     172             :                      dash::summa_pattern_partitioning_constraints,
     173             :                      dash::summa_pattern_mapping_constraints,
     174             :                      dash::summa_pattern_layout_constraints >(
     175           4 :                        size_spec);
     176             : 
     177           8 :   dash::DistributionSpec<2> dist_spec(dash::TILE(tile_size),
     178          12 :                                       dash::TILE(tile_size));
     179           4 :   pattern_t pattern(size_spec, dist_spec, team_spec);
     180             : 
     181             :   // Create operands and result matrices with identical distribution pattern:
     182             :   LOG_MESSAGE("Initialize matrix instances ...");
     183           8 :   dash::Matrix<value_t, 2, index_t, pattern_t> matrix_a(pattern);
     184           8 :   dash::Matrix<value_t, 2, index_t, pattern_t> matrix_b(pattern);
     185           8 :   dash::Matrix<value_t, 2, index_t, pattern_t> matrix_c(pattern);
     186             : 
     187             :   LOG_MESSAGE("Starting initialization of matrix values");
     188           4 :   dash::barrier();
     189             : 
     190             :   // Initialize operands:
     191           4 :   if (_dash_id == 0) {
     192             :     // Matrix B is identity matrix:
     193          85 :     for (index_t d = 0; d < static_cast<index_t>(extent_rows); ++d) {
     194             :       LOG_MESSAGE("Setting matrix B value (%d,%d)", d, d);
     195          84 :       matrix_b[d][d] = 1;
     196             :     }
     197          85 :     for (index_t row = 0; row < static_cast<index_t>(extent_rows); ++row) {
     198        7140 :       for (index_t col = 0; col < static_cast<index_t>(extent_cols); ++col) {
     199             :         LOG_MESSAGE("Initialize A matrix value (%d,%d)", col, row);
     200        7056 :         auto unit  = matrix_a.pattern()
     201       14112 :                              .unit_at(std::array<index_t, 2> { col, row });
     202        7056 :         value_t value = ((1 + col) * 10000) + ((row + 1) * 100) + unit;
     203             :         LOG_MESSAGE("Setting matrix A value (%d,%d)", col, row);
     204        7056 :         matrix_a[col][row] = value;
     205             :       }
     206             :     }
     207             :   }
     208             : 
     209             :   LOG_MESSAGE("Waiting for initialization of matrices ...");
     210           4 :   dash::barrier();
     211             : 
     212             :   // Expected to be resolved to SUMMA version of dash::mmult:
     213             :   LOG_MESSAGE("Calling dash::mmult ...");
     214             : 
     215           4 :   dash::util::TraceStore::on();
     216           4 :   dash::util::TraceStore::clear();
     217           8 :   dash::util::Trace trace("SUMMATest.SeqTilePatternMatrix");
     218             :   dash::mmult(matrix_a,
     219             :                  matrix_b,
     220           4 :                  matrix_c);
     221             : 
     222           4 :   dash::barrier();
     223           4 :   dash::util::TraceStore::off();
     224           4 :   dash::util::TraceStore::write(std::cout);
     225             : 
     226           4 :   if (_dash_id == 0) {
     227           1 :     dash::test::print_matrix("summa.matrix A", matrix_a, 3);
     228           1 :     dash::test::print_matrix("summa.matrix B", matrix_b, 3);
     229           1 :     dash::test::print_matrix("summa.matrix C", matrix_c, 3);
     230             :   }
     231             : 
     232           4 :   dash::barrier();
     233             : 
     234             :   // Verify multiplication result (A x id = A):
     235             :   if (false && _dash_id == 0) {
     236             :     // Multiplication of matrix A with identity matrix B should be identical
     237             :     // to matrix A:
     238             :     for (index_t row = 0; row < static_cast<index_t>(extent_rows); ++row) {
     239             :       for (index_t col = 0; col < static_cast<index_t>(extent_cols); ++col) {
     240             :         auto unit = matrix_a.pattern()
     241             :                             .unit_at(std::array<index_t, 2> { col, row });
     242             :         value_t expect = ((1 + col) * 10000) + ((row + 1) * 100) + unit;
     243             :         value_t actual = matrix_c[col][row];
     244             :         ASSERT_EQ_U(expect, actual);
     245             :       }
     246             :     }
     247             :   }
     248             : 
     249           4 :   dash::barrier();
     250          12 : }

Generated by: LCOV version 1.12