Commit 365229b4 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Reorganization of benchmarks - moved into src

parent 36639482
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ option(WITH_TESTS "Build tests" ON)
option(WITH_COVERAGE "Enable code coverage reports from unit tests" OFF)
option(WITH_EXAMPLES "Compile the 'examples' directory" ON)
option(WITH_TOOLS "Compile the 'src/Tools' directory" ON)
option(WITH_BENCHMARKS "Compile the 'src/Benchmarks' directory" ON)
option(WITH_PYTHON "Compile the Python bindings" ON)
option(WITH_TEMPLATES_INSTANTIATION "Enable explicit template instantiation" OFF)

@@ -473,6 +474,7 @@ message( " WITH_TESTS=${WITH_TESTS}" )
message( "   WITH_COVERAGE=${WITH_COVERAGE}" )
message( "   WITH_EXAMPLES=${WITH_EXAMPLES}" )
message( "   WITH_TOOLS=${WITH_TOOLS}" )
message( "   WITH_BENCHMARKS=${WITH_BENCHMARKS}" )
message( "   WITH_PYTHON=${WITH_PYTHON}" )
message( "   WITH_TEMPLATES_INSTANTIATION=${WITH_TEMPLATES_INSTANTIATION}" )
# Print compiler options
+3 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ WITH_COVERAGE="no"
WITH_EXAMPLES="yes"
WITH_PYTHON="yes"
WITH_TOOLS="yes"
WITH_BENCHMARKS="yes"

WITH_TEMPLATE_INSTANTIATION="no"
INSTANTIATE_LONG_INT="no"
@@ -60,6 +61,7 @@ do
        --with-coverage=*                ) WITH_COVERAGE="${option#*=}" ;;
        --with-examples=*                ) WITH_EXAMPLES="${option#*=}" ;;
        --with-tools=*                   ) WITH_TOOLS="${option#*=}" ;;
        --with-benchmarks=*              ) WITH_BENCHMARKS="${option#*=}" ;;
        --with-python=*                  ) WITH_PYTHON="${option#*=}" ;;
        --with-templates-instantiation=* ) WITH_TEMPLATE_INSTANTIATION="${option#*=}" ;;
        --instantiate-long-int=*         ) INSTANTIATE_LONG_INT="${option#*=}" ;;
@@ -164,6 +166,7 @@ cmake_command=(
         -DWITH_COVERAGE=${WITH_COVERAGE}
         -DWITH_EXAMPLES=${WITH_EXAMPLES}
         -DWITH_TOOLS=${WITH_TOOLS}
         -DWITH_BENCHMARKS=${WITH_BENCHMARKS}
         -DWITH_PYTHON=${WITH_PYTHON}
         -DDCMTK_DIR=${DCMTK_DIR}
         -DWITH_TEMPLATE_INSTANTIATION=${WITH_TEMPLATE_INSTANTIATION}
+10 −0
Original line number Diff line number Diff line
if( BUILD_CUDA )
    CUDA_ADD_EXECUTABLE( tnl-benchmark-blas tnl-benchmark-blas.cu )
    CUDA_ADD_CUBLAS_TO_TARGET( tnl-benchmark-blas )
    TARGET_LINK_LIBRARIES( tnl-benchmark-blas tnl )
else()
    ADD_EXECUTABLE( tnl-benchmark-blas tnl-benchmark-blas.cpp )
    TARGET_LINK_LIBRARIES( tnl-benchmark-blas tnl )
endif()

install( TARGETS tnl-benchmark-blas RUNTIME DESTINATION bin )
+165 −0
Original line number Diff line number Diff line
/***************************************************************************
                          array-operations.h  -  description
                             -------------------
    begin                : Dec 30, 2015
    copyright            : (C) 2015 by Tomas Oberhuber et al.
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

// Implemented by: Jakub Klinkovsky

#pragma once

#include "../Benchmarks.h"

#include <TNL/Containers/Array.h>

namespace TNL {
namespace Benchmarks {

template< typename Real = double,
          typename Index = int >
bool
benchmarkArrayOperations( Benchmark & benchmark,
                          const int & loops,
                          const long & size )
{
   typedef Containers::Array< Real, Devices::Host, Index > HostArray;
   typedef Containers::Array< Real, Devices::Cuda, Index > CudaArray;
   using namespace std;

   double datasetSize = ( double ) ( loops * size ) * sizeof( Real ) / oneGB;

   HostArray hostArray, hostArray2;
   CudaArray deviceArray, deviceArray2;
   hostArray.setSize( size );
   hostArray2.setSize( size );
#ifdef HAVE_CUDA
   deviceArray.setSize( size );
   deviceArray2.setSize( size );
#endif

   Real resultHost, resultDevice;


   // reset functions
   auto reset1 = [&]() {
      hostArray.setValue( 1.0 );
#ifdef HAVE_CUDA
      deviceArray.setValue( 1.0 );
#endif
   };
   auto reset2 = [&]() {
      hostArray2.setValue( 1.0 );
#ifdef HAVE_CUDA
      deviceArray2.setValue( 1.0 );
#endif
   };
   auto reset12 = [&]() {
      reset1();
      reset2();
   };


   reset12();


   auto compareHost = [&]() {
      resultHost = (int) hostArray == hostArray2;
   };
   auto compareCuda = [&]() {
      resultDevice = (int) deviceArray == deviceArray2;
   };
   benchmark.setOperation( "comparison (operator==)", 2 * datasetSize );
   benchmark.time( reset1, "CPU", compareHost );
#ifdef HAVE_CUDA
   benchmark.time( reset1, "GPU", compareCuda );
#endif


   auto copyAssignHostHost = [&]() {
      hostArray = hostArray2;
   };
   auto copyAssignCudaCuda = [&]() {
      deviceArray = deviceArray2;
   };
   benchmark.setOperation( "copy (operator=)", 2 * datasetSize );
   // copyBasetime is used later inside HAVE_CUDA guard, so the compiler will
   // complain when compiling without CUDA
   const double copyBasetime = benchmark.time( reset1, "CPU", copyAssignHostHost );
#ifdef HAVE_CUDA
   benchmark.time( reset1, "GPU", copyAssignCudaCuda );
#endif


   auto copyAssignHostCuda = [&]() {
      deviceArray = hostArray;
   };
   auto copyAssignCudaHost = [&]() {
      hostArray = deviceArray;
   };
#ifdef HAVE_CUDA
   benchmark.setOperation( "copy (operator=)", datasetSize, copyBasetime );
   benchmark.time( reset1,
                   "CPU->GPU", copyAssignHostCuda,
                   "GPU->CPU", copyAssignCudaHost );
#endif


   auto setValueHost = [&]() {
      hostArray.setValue( 3.0 );
   };
   auto setValueCuda = [&]() {
      deviceArray.setValue( 3.0 );
   };
   benchmark.setOperation( "setValue", datasetSize );
   benchmark.time( reset1, "CPU", setValueHost );
#ifdef HAVE_CUDA
   benchmark.time( reset1, "GPU", setValueCuda );
#endif


   auto setSizeHost = [&]() {
      hostArray.setSize( size );
   };
   auto setSizeCuda = [&]() {
      deviceArray.setSize( size );
   };
   auto resetSize1 = [&]() {
      hostArray.reset();
#ifdef HAVE_CUDA
      deviceArray.reset();
#endif
   };
   benchmark.setOperation( "allocation (setSize)", datasetSize );
   benchmark.time( resetSize1, "CPU", setSizeHost );
#ifdef HAVE_CUDA
   benchmark.time( resetSize1, "GPU", setSizeCuda );
#endif


   auto resetSizeHost = [&]() {
      hostArray.reset();
   };
   auto resetSizeCuda = [&]() {
      deviceArray.reset();
   };
   auto setSize1 = [&]() {
      hostArray.setSize( size );
#ifdef HAVE_CUDA
      deviceArray.setSize( size );
#endif
   };
   benchmark.setOperation( "deallocation (reset)", datasetSize );
   benchmark.time( setSize1, "CPU", resetSizeHost );
#ifdef HAVE_CUDA
   benchmark.time( setSize1, "GPU", resetSizeCuda );
#endif

   return true;
}

} // namespace Benchmarks
} // namespace TNL
+14 −14

File changed and moved.

Contains only whitespace changes.

Loading