Commit 1c3b49b4 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Benchmarks: removed method newBenchmark and refactored logging of remaining...

Benchmarks: removed method newBenchmark and refactored logging of remaining metadata into table columns

The global metadata like hardware information is logged into a separate JSON
file, so the handling of MetadataMap in the Logging classes is not
needed anymore.
parent b82fbda3
Loading
Loading
Loading
Loading
+15 −18
Original line number Diff line number Diff line
@@ -31,36 +31,33 @@ using namespace TNL::Benchmarks;
template< typename Real >
void
runBlasBenchmarks( Benchmark<> & benchmark,
                   Benchmark<>::MetadataMap metadata,
                   const std::size_t & minSize,
                   const std::size_t & maxSize,
                   const double & sizeStepFactor )
{
   const String precision = getType< Real >();
   metadata["precision"] = precision;

   // Array operations
   benchmark.newBenchmark( String("Array operations (") + precision + ", host allocator = Host)",
                           metadata );
   std::cout << "\n== Array operations ==\n" << std::endl;
   for( std::size_t size = minSize; size <= maxSize; size *= 2 ) {
      benchmark.setMetadataColumns( Benchmark<>::MetadataColumns({
         { "precision", getType< Real >() },
         { "host allocator", "Host" },
         { "size", convertToString( size ) },
      } ));
      benchmarkArrayOperations< Real >( benchmark, size );
   }
#ifdef HAVE_CUDA
   benchmark.newBenchmark( String("Array operations (") + precision + ", host allocator = CudaHost)",
                           metadata );
   for( std::size_t size = minSize; size <= maxSize; size *= 2 ) {
      benchmark.setMetadataColumns( Benchmark<>::MetadataColumns({
         { "precision", getType< Real >() },
         { "host allocator", "CudaHost" },
         { "size", convertToString( size ) },
      } ));
      benchmarkArrayOperations< Real, int, Allocators::CudaHost >( benchmark, size );
   }
   benchmark.newBenchmark( String("Array operations (") + precision + ", host allocator = CudaManaged)",
                           metadata );
   for( std::size_t size = minSize; size <= maxSize; size *= 2 ) {
      benchmark.setMetadataColumns( Benchmark<>::MetadataColumns({
         { "precision", getType< Real >() },
         { "host allocator", "CudaManaged" },
         { "size", convertToString( size ) },
      } ));
      benchmarkArrayOperations< Real, int, Allocators::CudaManaged >( benchmark, size );
@@ -68,10 +65,10 @@ runBlasBenchmarks( Benchmark<> & benchmark,
#endif

   // Vector operations
   benchmark.newBenchmark( String("Vector operations (") + precision + ")",
                           metadata );
   std::cout << "\n== Vector operations ==\n" << std::endl;
   for( std::size_t size = minSize; size <= maxSize; size *= sizeStepFactor ) {
      benchmark.setMetadataColumns( Benchmark<>::MetadataColumns({
         { "precision", getType< Real >() },
         { "size", convertToString( size ) },
      } ));
      benchmarkVectorOperations< Real >( benchmark, size );
@@ -79,10 +76,10 @@ runBlasBenchmarks( Benchmark<> & benchmark,

   // Triad benchmark: copy from host, compute, copy to host
#ifdef HAVE_CUDA
   benchmark.newBenchmark( String("Triad benchmark (") + precision + ")",
                           metadata );
   std::cout << "\n== Triad ==\n" << std::endl;
   for( std::size_t size = minSize; size <= maxSize; size *= 2 ) {
      benchmark.setMetadataColumns( Benchmark<>::MetadataColumns({
         { "precision", getType< Real >() },
         { "size", convertToString( size ) },
      } ));
      benchmarkTriad< Real >( benchmark, size );
@@ -90,13 +87,13 @@ runBlasBenchmarks( Benchmark<> & benchmark,
#endif

   // Dense matrix-vector multiplication
   benchmark.newBenchmark( String("Dense matrix-vector multiplication (") + precision + ")",
                           metadata );
   std::cout << "\n== Dense matrix-vector multiplication ==\n" << std::endl;
   for( std::size_t rows = 10; rows <= 20000 * 20000; rows *= 2 ) {
      for( std::size_t columns = 10; columns <= 20000 * 20000; columns *= 2 ) {
         if( rows * columns > 20000 * 20000 )
            break;
         benchmark.setMetadataColumns( Benchmark<>::MetadataColumns({
            { "precision", getType< Real >() },
            { "rows", convertToString( rows ) },
            { "columns", convertToString( columns ) }
         } ));
@@ -176,9 +173,9 @@ main( int argc, char* argv[] )
   writeMapAsJson( metadata, logFileName, ".metadata.json" );

   if( precision == "all" || precision == "float" )
      runBlasBenchmarks< float >( benchmark, metadata, minSize, maxSize, sizeStepFactor );
      runBlasBenchmarks< float >( benchmark, minSize, maxSize, sizeStepFactor );
   if( precision == "all" || precision == "double" )
      runBlasBenchmarks< double >( benchmark, metadata, minSize, maxSize, sizeStepFactor );
      runBlasBenchmarks< double >( benchmark, minSize, maxSize, sizeStepFactor );

   return EXIT_SUCCESS;
}
+10 −12
Original line number Diff line number Diff line
@@ -157,7 +157,6 @@ struct SpmvBenchmark

   static bool
   run( Benchmark<>& benchmark,
        Benchmark<>::MetadataMap metadata,
        const Config::ParameterContainer& parameters )
   {
      MatrixType matrix;
@@ -169,10 +168,11 @@ struct SpmvBenchmark
      matrix.getCompressedRowLengths( rowLengths );
      const IndexType maxRowLength = max( rowLengths );

      const String name = String( (TNL::MPI::GetSize() > 1) ? "DistSpMV" : "SpMV" )
                          + " (" + parameters.getParameter< String >( "name" ) + "): ";
      benchmark.newBenchmark( name, metadata );
      const String title = (TNL::MPI::GetSize() > 1) ? "DistSpMV" : "SpMV";
      std::cout << "\n== " << title << " ==\n" << std::endl;

      benchmark.setMetadataColumns( Benchmark<>::MetadataColumns({
         { "matrix name", parameters.getParameter< String >( "name" ) },
         // TODO: strip the device
//         { "matrix type", matrix.getType() },
         { "rows", convertToString( matrix.getRows() ) },
@@ -190,15 +190,15 @@ struct SpmvBenchmark
         MatrixType matrix_perm;
         Matrices::reorderSparseMatrix( matrix, matrix_perm, perm, iperm );
         if( TNL::MPI::GetSize() > 1 )
            runDistributed( benchmark, metadata, parameters, matrix_perm, vector );
            runDistributed( benchmark, parameters, matrix_perm, vector );
         else
            runNonDistributed( benchmark, metadata, parameters, matrix_perm, vector );
            runNonDistributed( benchmark, parameters, matrix_perm, vector );
      }
      else {
         if( TNL::MPI::GetSize() > 1 )
            runDistributed( benchmark, metadata, parameters, matrix, vector );
            runDistributed( benchmark, parameters, matrix, vector );
         else
            runNonDistributed( benchmark, metadata, parameters, matrix, vector );
            runNonDistributed( benchmark, parameters, matrix, vector );
      }

      return true;
@@ -206,7 +206,6 @@ struct SpmvBenchmark

   static void
   runNonDistributed( Benchmark<>& benchmark,
                      Benchmark<>::MetadataMap metadata,
                      const Config::ParameterContainer& parameters,
                      MatrixType& matrix,
                      VectorType& vector )
@@ -219,7 +218,6 @@ struct SpmvBenchmark

   static void
   runDistributed( Benchmark<>& benchmark,
                   Benchmark<>::MetadataMap metadata,
                   const Config::ParameterContainer& parameters,
                   MatrixType& matrix,
                   VectorType& vector )
@@ -343,12 +341,12 @@ main( int argc, char* argv[] )
   // TODO: implement resolveMatrixType
//   return ! Matrices::resolveMatrixType< MainConfig,
//                                         Devices::Host,
//                                         SpmvBenchmark >( benchmark, metadata, parameters );
//                                         SpmvBenchmark >( benchmark, parameters );
   using MatrixType = TNL::Matrices::SparseMatrix< double,
                                                   Devices::Host,
                                                   int,
                                                   TNL::Matrices::GeneralMatrix,
                                                   SegmentsType
                                                 >;
   return ! SpmvBenchmark< MatrixType >::run( benchmark, metadata, parameters );
   return ! SpmvBenchmark< MatrixType >::run( benchmark, parameters );
}
+10 −12
Original line number Diff line number Diff line
@@ -338,7 +338,6 @@ struct LinearSolversBenchmark

   static bool
   run( Benchmark<>& benchmark,
        Benchmark<>::MetadataMap metadata,
        const Config::ParameterContainer& parameters )
   {
      const String file_matrix = parameters.getParameter< String >( "input-matrix" );
@@ -381,10 +380,11 @@ struct LinearSolversBenchmark
      matrixPointer->getCompressedRowLengths( rowLengths );
      const IndexType maxRowLength = max( rowLengths );

      const String name = String( (TNL::MPI::GetSize() > 1) ? "Distributed linear solvers" : "Linear solvers" )
                          + " (" + parameters.getParameter< String >( "name" ) + "): ";
      benchmark.newBenchmark( name, metadata );
      const String title = (TNL::MPI::GetSize() > 1) ? "Distributed linear solvers" : "Linear solvers";
      std::cout << "\n== " << title << " ==\n" << std::endl;

      benchmark.setMetadataColumns( Benchmark<>::MetadataColumns({
         { "matrix name", parameters.getParameter< String >( "name" ) },
         // TODO: strip the device
//         { "matrix type", matrixPointer->getType() },
         { "rows", convertToString( matrixPointer->getRows() ) },
@@ -407,15 +407,15 @@ struct LinearSolversBenchmark
         Matrices::reorderArray( x0, x0_perm, perm );
         Matrices::reorderArray( b, b_perm, perm );
         if( TNL::MPI::GetSize() > 1 )
            runDistributed( benchmark, metadata, parameters, matrix_perm, x0_perm, b_perm );
            runDistributed( benchmark, parameters, matrix_perm, x0_perm, b_perm );
         else
            runNonDistributed( benchmark, metadata, parameters, matrix_perm, x0_perm, b_perm );
            runNonDistributed( benchmark, parameters, matrix_perm, x0_perm, b_perm );
      }
      else {
         if( TNL::MPI::GetSize() > 1 )
            runDistributed( benchmark, metadata, parameters, matrixPointer, x0, b );
            runDistributed( benchmark, parameters, matrixPointer, x0, b );
         else
            runNonDistributed( benchmark, metadata, parameters, matrixPointer, x0, b );
            runNonDistributed( benchmark, parameters, matrixPointer, x0, b );
      }

      return true;
@@ -423,7 +423,6 @@ struct LinearSolversBenchmark

   static void
   runDistributed( Benchmark<>& benchmark,
                   Benchmark<>::MetadataMap metadata,
                   const Config::ParameterContainer& parameters,
                   const SharedPointer< MatrixType >& matrixPointer,
                   const VectorType& x0,
@@ -467,7 +466,6 @@ struct LinearSolversBenchmark

   static void
   runNonDistributed( Benchmark<>& benchmark,
                      Benchmark<>::MetadataMap metadata,
                      const Config::ParameterContainer& parameters,
                      const SharedPointer< MatrixType >& matrixPointer,
                      const VectorType& x0,
@@ -623,12 +621,12 @@ main( int argc, char* argv[] )
   // TODO: implement resolveMatrixType
//   return ! Matrices::resolveMatrixType< MainConfig,
//                                         Devices::Host,
//                                         LinearSolversBenchmark >( benchmark, metadata, parameters );
//                                         LinearSolversBenchmark >( benchmark, parameters );
   using MatrixType = TNL::Matrices::SparseMatrix< double,
                                                   Devices::Host,
                                                   int,
                                                   TNL::Matrices::GeneralMatrix,
                                                   SegmentsType
                                                 >;
   return ! LinearSolversBenchmark< MatrixType >::run( benchmark, metadata, parameters );
   return ! LinearSolversBenchmark< MatrixType >::run( benchmark, parameters );
}
+11 −15
Original line number Diff line number Diff line
@@ -108,16 +108,14 @@ struct ODESolversBenchmark

   static bool
   run( Benchmark<>& benchmark,
        Benchmark<>::MetadataMap metadata,
        const Config::ParameterContainer& parameters )
   {
      const String precision = getType< Real >();
      const String name = String( (TNL::MPI::GetSize() > 1) ? "Distributed ODE solvers" : "ODE solvers" ) + " (" + precision + ")";
      metadata["precision"] = precision;
      benchmark.newBenchmark( name, metadata );
      const String title = (TNL::MPI::GetSize() > 1) ? "Distributed ODE solvers" : "ODE solvers";
      std::cout << "\n== " << title << " ==\n" << std::endl;

      for( size_t dofs = 25; dofs <= 10000000; dofs *= 2 ) {
         benchmark.setMetadataColumns( Benchmark<>::MetadataColumns({
            // TODO: strip the device
            { "precision", getType< Real >() },
            { "DOFs", convertToString( dofs ) },
         } ));

@@ -129,24 +127,22 @@ struct ODESolversBenchmark

template< typename Real >
bool resolveIndexType( Benchmark<>& benchmark,
   Benchmark<>::MetadataMap& metadata,
                       Config::ParameterContainer& parameters )
{
   const String& index = parameters.getParameter< String >( "index-type" );
   if( index == "int" ) return ODESolversBenchmark< Real, int >::run( benchmark, metadata, parameters );
   return ODESolversBenchmark< Real, long int >::run( benchmark, metadata, parameters );
   if( index == "int" ) return ODESolversBenchmark< Real, int >::run( benchmark, parameters );
   return ODESolversBenchmark< Real, long int >::run( benchmark, parameters );
}

bool resolveRealTypes( Benchmark<>& benchmark,
   Benchmark<>::MetadataMap& metadata,
                       Config::ParameterContainer& parameters )
{
   const String& realType = parameters.getParameter< String >( "real-type" );
   if( ( realType == "float" || realType == "all" ) &&
       ! resolveIndexType< float >( benchmark, metadata, parameters ) )
       ! resolveIndexType< float >( benchmark, parameters ) )
      return false;
   if( ( realType == "double" || realType == "all" ) &&
       ! resolveIndexType< double >( benchmark, metadata, parameters ) )
       ! resolveIndexType< double >( benchmark, parameters ) )
      return false;
   return true;
}
@@ -229,5 +225,5 @@ main( int argc, char* argv[] )
   std::map< std::string, std::string > metadata = getHardwareMetadata();
   writeMapAsJson( metadata, logFileName, ".metadata.json" );

   return ! resolveRealTypes( benchmark, metadata, parameters );
   return ! resolveRealTypes( benchmark, parameters );
}
+1 −0
Original line number Diff line number Diff line
@@ -729,6 +729,7 @@ benchmarkSpmv( BenchmarkType& benchmark,
   //
   benchmark.setMetadataColumns({
      { "matrix name", inputFileName },
      { "precision", getType< Real >() },
      { "rows", convertToString( csrHostMatrix.getRows() ) },
      { "columns", convertToString( csrHostMatrix.getColumns() ) },
      { "nonzeros", convertToString( nonzeros ) },
Loading