From 10d7f72179c7711971375c37ded0e9a33f9c3d35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Oberhuber?= <oberhuber.tomas@gmail.com> Date: Wed, 19 Dec 2018 21:12:19 +0100 Subject: [PATCH] Fixed typo in vector operations benchmark comment. --- src/Benchmarks/BLAS/vector-operations.h | 2 +- src/Benchmarks/Traversers/WriteOne.h | 88 +++++++++++++++++++++ src/Benchmarks/Traversers/grid-traversing.h | 54 +++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/Benchmarks/Traversers/WriteOne.h create mode 100644 src/Benchmarks/Traversers/grid-traversing.h diff --git a/src/Benchmarks/BLAS/vector-operations.h b/src/Benchmarks/BLAS/vector-operations.h index b9a68d618b..8dd63de85b 100644 --- a/src/Benchmarks/BLAS/vector-operations.h +++ b/src/Benchmarks/BLAS/vector-operations.h @@ -64,7 +64,7 @@ benchmarkVectorOperations( Benchmark & benchmark, deviceVector.setValue( 1.0 ); #endif // A relatively harmless call to keep the compiler from realizing we - // don't actually do any useful work with the result of the reduciton. + // don't actually do any useful work with the result of the reduction. srand48(resultHost); resultHost = resultDevice = 0.0; }; diff --git a/src/Benchmarks/Traversers/WriteOne.h b/src/Benchmarks/Traversers/WriteOne.h new file mode 100644 index 0000000000..73bf0bfecf --- /dev/null +++ b/src/Benchmarks/Traversers/WriteOne.h @@ -0,0 +1,88 @@ +/*************************************************************************** + WriteOne.h - description + ------------------- + begin : Dec 19, 2018 + copyright : (C) 2018 by oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +// Implemented by: Tomas Oberhuber + +#pragma once + +#include <TNL/ParallelFor.h> +#include <TNL/Devices/Host.h> +#include <TNL/Devices/Cuda.h> +#include <TNL/Containers/Vector.h> + +namespace TNL { + namespace Benchmarks { + + +template< int Dimenions, + typename Device, + typename Real, + typename Index > +class WriteOne{}; + +template< typename Device, + typename Real, + typename Index > +class WriteOne< 1, Device, Real, Index > +{ + public: + + using Vector = Containers::Vector< Real, Device, Index >; + + static void run( std::size_t size ) + { + Vector v( size ); + auto writeOne = []( Index i, Real* data ) + { + data[ i ] = 1.0; + }; + + + ParallelFor< Devices::Host >::exec( ( std::size_t ) 0, size, writeOne, v.getData() ); + } +}; + + +template< typename Device, + typename Real, + typename Index > +class WriteOne< 2, Device, Real, Index > +{ + public: + + using Vector = Containers::Vector< Real, Device, Index >; + + static void run( std::size_t size ) + { + + } +}; + +template< typename Device, + typename Real, + typename Index > +class WriteOne< 3, Device, Real, Index > +{ + public: + + using Vector = Containers::Vector< Real, Device, Index >; + + static void run( std::size_t size ) + { + + } +}; + + + } // namespace Benchmarks +} // namespace TNL + + + diff --git a/src/Benchmarks/Traversers/grid-traversing.h b/src/Benchmarks/Traversers/grid-traversing.h new file mode 100644 index 0000000000..df45b1d7fe --- /dev/null +++ b/src/Benchmarks/Traversers/grid-traversing.h @@ -0,0 +1,54 @@ +/*************************************************************************** + grid-traversing.h - description + ------------------- + begin : Dec 19, 2018 + copyright : (C) 2018 by oberhuber + email : tomas.oberhuber@fjfi.cvut.cz + ***************************************************************************/ + +/* See Copyright Notice in tnl/Copyright */ + +// Implemented by: Tomas Oberhuber + +#pragma once + +#include "../Benchmarks.h" +#include "WriteOne.h" + +#include <TNL/Containers/Vector.h> + +namespace TNL { + namespace Benchmarks { + +template< int Dimension, + typename Real = double, + typename Index = int > +class benchmarkTraversingFullGrid +{ + public: + + static void run ( Benchmark& benchmark, std::size_t size ) + { + auto reset = [&]() + {}; + + auto testHost = [&] () + { + WriteOne< Dimension, Devices::Host, Real, Index >::run( size ); + }; + + auto testCuda = [&] () + { + WriteOne< Dimension, Devices::Cuda, Real, Index >::run( size ); + }; + + benchmark.setOperation( "writeOne", size * sizeof( Real ) ); + benchmark.time( reset, "CPU", testHost ); +#ifdef HAVE_CUDA + benchmark.time( reset, "GPU", testCuda ); +#endif + + } +}; + } // namespace Benchmarks +} // namespace TNL \ No newline at end of file -- GitLab