From 0031f80998b2743ba6b9caae888444dfbb94b9d9 Mon Sep 17 00:00:00 2001 From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz> Date: Thu, 28 May 2015 20:29:29 +0200 Subject: [PATCH] Basic CUDA benchmark was added. --- tests/benchmarks/CMakeLists.txt | 11 +++- tests/benchmarks/tnl-benchmarks.cpp | 57 ------------------- tests/benchmarks/tnl-cuda-benchmarks.cu | 52 +++++++++++++++++ ...tnl-benchmarks.h => tnl-cuda-benchmarks.h} | 0 4 files changed, 62 insertions(+), 58 deletions(-) delete mode 100644 tests/benchmarks/tnl-benchmarks.cpp create mode 100644 tests/benchmarks/tnl-cuda-benchmarks.cu rename tests/benchmarks/{tnl-benchmarks.h => tnl-cuda-benchmarks.h} (100%) diff --git a/tests/benchmarks/CMakeLists.txt b/tests/benchmarks/CMakeLists.txt index 90d967d345..975147ee5a 100755 --- a/tests/benchmarks/CMakeLists.txt +++ b/tests/benchmarks/CMakeLists.txt @@ -1,6 +1,10 @@ ADD_SUBDIRECTORY( share ) IF( BUILD_CUDA ) + CUDA_ADD_EXECUTABLE( tnl-cuda-benchmarks${debugExt} tnl-cuda-benchmarks.cu + OPTIONS ${CUDA_ADD_EXECUTABLE_OPTIONS} ) + SET_TARGET_PROPERTIES( tnl-cuda-benchmarks${debugExt} PROPERTIES CUDA_COMPILE_FLAGS "${CXX_OPTIMIZE_FLAGS}" ) + TARGET_LINK_LIBRARIES( tnl-cuda-benchmarks${debugExt} tnl${debugExt}-${tnlVersion} ${CUSPARSE_LIBRARY} ) CUDA_ADD_EXECUTABLE( tnl-benchmark-spmv${debugExt} tnl-benchmark-spmv.cu OPTIONS ${CUDA_ADD_EXECUTABLE_OPTIONS} ) SET_TARGET_PROPERTIES( tnl-benchmark-spmv${debugExt} PROPERTIES CUDA_COMPILE_FLAGS "${CXX_OPTIMIZE_FLAGS}" ) @@ -18,7 +22,12 @@ ELSE() ENDIF() TARGET_LINK_LIBRARIES( tnl-benchmark-linear-solvers${debugExt} tnl${debugExt}-${tnlVersion} ) - + +if( BUILD_CUDA ) + INSTALL( TARGETS tnl-cuda-benchmarks${debugExt} + RUNTIME DESTINATION bin ) +endif() + INSTALL( TARGETS tnl-benchmark-spmv${debugExt} tnl-benchmark-linear-solvers${debugExt} RUNTIME DESTINATION bin ) diff --git a/tests/benchmarks/tnl-benchmarks.cpp b/tests/benchmarks/tnl-benchmarks.cpp deleted file mode 100644 index 69af772435..0000000000 --- a/tests/benchmarks/tnl-benchmarks.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - tnl-benchmarks.cpp - description - ------------------- - begin : Nov 25, 2010 - copyright : (C) 2010 by Tomas Oberhuber - email : tomas.oberhuber@fjfi.cvut.cz - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ - - -#include <core/vectors/tnlVectorHost.h> -#include <core/vectors/tnlVectorCUDA.h> -#include <tnl-benchmarks.h> - - -int main( int argc, char* argv[] ) -{ - -#ifdef HAVE_CUDA - cout << "Benchmarking memory bandwidth when transfering int ..." << endl; - - const int size = 1 << 22; - double host_to_host_band_width; - double host_to_device_band_width; - double device_to_host_band_width; - double device_to_device_band_width; - - transferBenchmark< int >( size, - host_to_host_band_width, - host_to_device_band_width, - device_to_host_band_width, - device_to_device_band_width ); - - - cout << "Benchmarking reduction of int ..." << endl; - for( int i = 0; i <= 6; i ++ ) - reductionBenchmark< int >( size, i ); - - cout << "Benchmarking reduction of float ..." << endl; - for( int i = 0; i <= 6; i ++ ) - reductionBenchmark< float >( size, i ); - - cout << "Benchmarking reduction of double ..." << endl; - for( int i = 0; i <= 6; i ++ ) - reductionBenchmark< double >( size / 2, i ); - -#endif - return EXIT_SUCCESS; -} diff --git a/tests/benchmarks/tnl-cuda-benchmarks.cu b/tests/benchmarks/tnl-cuda-benchmarks.cu new file mode 100644 index 0000000000..ded925bea7 --- /dev/null +++ b/tests/benchmarks/tnl-cuda-benchmarks.cu @@ -0,0 +1,52 @@ +/*************************************************************************** + tnl-cuda-benchmarks.cu - description + ------------------- + begin : May 28, 2015 + copyright : (C) 2015 by Tomas Oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include <core/vectors/tnlVector.h> +#include <core/tnlTimerRT.h> + +int main( int argc, char* argv[] ) +{ +#ifdef HAVE_CUDA + + tnlTimerRT timer; + const double oneGB = 1024.0 * 1024.0 * 1024.0; + + cout << "Benchmarking memory bandwidth when transfering int ..." << endl; + + const int size = 1 << 22; + + tnlVector< int, tnlHost > hostVector; + tnlVector< int, tnlCuda > deviceVector; + hostVector.setSize( size ); + deviceVector.setSize( size ); + + hostVector.setValue( 1.0 ); + deviceVector.setValue( 0.0 ); + + timer.reset(); + timer.start(); + deviceVector = hostVector; + timer.stop(); + + double bandwidth = ( double ) ( size ) * sizeof( int ) / timer.getTime() / oneGB; + + cout << bandwidth << " GB/sec." << endl; + + +#endif + return EXIT_SUCCESS; +} diff --git a/tests/benchmarks/tnl-benchmarks.h b/tests/benchmarks/tnl-cuda-benchmarks.h similarity index 100% rename from tests/benchmarks/tnl-benchmarks.h rename to tests/benchmarks/tnl-cuda-benchmarks.h -- GitLab