Skip to content

Commit

Permalink
Basic support for benchmarks (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfalcou committed Mar 29, 2019
1 parent f94f640 commit 0b1648b
Show file tree
Hide file tree
Showing 26 changed files with 606 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .circleci/run.sh
Expand Up @@ -13,4 +13,4 @@ cd build
$1 --version
cmake .. -DCMAKE_BUILD_TYPE=$VARIANT -G Ninja -DCMAKE_CXX_COMPILER=$1 -DCMAKE_CXX_FLAGS=$OPTIONS
ninja unit -j 8
ctest -D Experimental -j 8
ctest -D Experimental -j 8 -R ^*.unit
6 changes: 3 additions & 3 deletions CMakeLists.txt
Expand Up @@ -29,9 +29,9 @@ include(parse_revision)
## =================================================================================================
## Options
## =================================================================================================
option( EVE_BUILD_TEST "Build tests for eve" ON )
option( EVE_BUILD_BENCHMARKS "Build benchmarks for eve" OFF )
option( EVE_BUILD_DOC "Build documentation for eve" ON )
option( EVE_BUILD_TEST "Build tests for eve" ON )
option( EVE_BUILD_BENCHMARKS "Build benchmarks for eve" ON )
option( EVE_BUILD_DOC "Build documentation for eve" ON )

message( STATUS "[eve] Building ${CMAKE_BUILD_TYPE} mode with: ${CMAKE_CXX_FLAGS}")

Expand Down
10 changes: 10 additions & 0 deletions benchmark/CMakeLists.txt
@@ -0,0 +1,10 @@
##==================================================================================================
## EVE - Expressive Vector Engine
## Copyright 2019 Joel FALCOU
## Copyright 2019 Jean-Thierry LAPRESTE
##
## Licensed under the MIT License <http://opensource.org/licenses/MIT>.
## SPDX-License-Identifier: MIT
##==================================================================================================

add_subdirectory(module/core)
138 changes: 138 additions & 0 deletions benchmark/bench.hpp
@@ -0,0 +1,138 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#ifndef BENCHMARK_BENCH_HPP
#define BENCHMARK_BENCH_HPP

#include <benchmark/benchmark.h>
#include <eve/cardinal.hpp>
#include "tts/detail/pp_helpers.hpp"
#include "cycleclock.h"
#include <algorithm>
#include <numeric>
#include <iostream>

namespace eve::bench
{
// -------------------------------------------------------------------------------------------------
struct metrics
{
std::size_t size;
void operator()(benchmark::State& state, double cycles, std::size_t byte_size, std::size_t card) const
{
auto iter = state.iterations();
state.SetItemsProcessed( iter * size * card);
state.SetBytesProcessed( iter * size * byte_size);
state.counters["cycle_per_value"] = (cycles / iter) / (size*card);
}
};

// -------------------------------------------------------------------------------------------------
// Generators
template <typename T> auto value(std::size_t sz, T const& val)
{
std::vector<T> data(sz, val);
return data;
}

template <typename T> auto iota(std::size_t sz, T first = {})
{
std::vector<T> data(sz);
std::iota(data.begin(),data.end(),first);
return data;
}

template <typename T> auto arithmetic(std::size_t sz, T first = {}, T step = 1)
{
std::vector<T> data(sz);

data[0] = first;
for(std::size_t i=1;i<sz;++i) data[i] = data[i-1] + step;

return data;
}

template <typename T> auto geomtric(std::size_t sz, T first = 1, T step = 2)
{
std::vector<T> data(sz);

data[0] = first;
for(std::size_t i=1;i<sz;++i) data[i] = data[i-1] * step;

return data;
}

template <typename T, typename U> auto random(std::size_t sz, U mn, U mx)
{
std::vector<T> data(sz);
std::generate ( data.begin(), data.end()
, [=]()
{
return static_cast<T>( mn + std::rand() / (double)RAND_MAX * (mx - mn));
}
);
return data;
}

template<typename Fun, typename... Args>
struct experiment
{
using out_type = decltype( std::declval<Fun>()(std::declval<typename Args::value_type>()...) );

experiment(std::string const& root, Fun fun, std::size_t size, Args const&... args) : output(size)
{
auto card = std::max({eve::cardinal_v<typename Args::value_type>...});
std::cout << "[EVE] - Target: "<< TTS_STRING(EVE_CURRENT_API) << " - Build type: ";
#ifdef NDEBUG
std::cout << "Release - ";
#else
std::cout << "Debug - ";
#endif
std::cout << "Cardinal: " << card << "\n";

benchmark::RegisterBenchmark( root.c_str()
, [=,out = output.data()](benchmark::State& st)
{
auto c0 = benchmark::cycleclock::Now();
while (st.KeepRunning())
{
for(std::size_t i=0;i<size;++i) out[i] = fun(args[i]...);
benchmark::DoNotOptimize(out);
}
auto c1 = benchmark::cycleclock::Now();

metrics{size} ( st, (c1 - c0)
, sizeof(out_type)
, card
);
}
);
}

private:
std::vector<out_type> output;
};
}

int main(int argc, char** argv)
{
using namespace eve::bench;
using T = TYPE();

auto size = benchmark::CPUInfo::Get().caches[1].size / sizeof(T);
auto name = std::string(TTS_STRING(FUNCTION())) + " - " + std::string(TTS_STRING(TYPE()));

experiment _(name, FUNCTION(), size, SAMPLES(size));

benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
}

#endif
16 changes: 16 additions & 0 deletions benchmark/module/core/CMakeLists.txt
@@ -0,0 +1,16 @@
##==================================================================================================
## EVE - Expressive Vector Engine
## Copyright 2019 Joel FALCOU
## Copyright 2019 Jean-Thierry LAPRESTE
##
## Licensed under the MIT License <http://opensource.org/licenses/MIT>.
## SPDX-License-Identifier: MIT
##==================================================================================================

##==================================================================================================
## scalar benchmarks
list_benchs("scalar/bitwise_and" "core" ${all_types})

##==================================================================================================
## SIMD< benchmarks
list_benchs("simd/bitwise_and" "core" ${all_types})
17 changes: 17 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/double.cpp
@@ -0,0 +1,17 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>

#define TYPE() double
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,-100.,100.),random<T>(N,-100.,100.)

#include "bench.hpp"
17 changes: 17 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/float.cpp
@@ -0,0 +1,17 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>

#define TYPE() float
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,-100.f,100.f),random<T>(N,-100.f,100.f)

#include "bench.hpp"
18 changes: 18 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/int16.cpp
@@ -0,0 +1,18 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>
#include <cstddef>

#define TYPE() std::int16_t
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,-100,100),random<T>(N,-100,100)

#include "bench.hpp"
18 changes: 18 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/int32.cpp
@@ -0,0 +1,18 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>
#include <cstddef>

#define TYPE() std::int32_t
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,-100,100),random<T>(N,-100,100)

#include "bench.hpp"
18 changes: 18 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/int64.cpp
@@ -0,0 +1,18 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>
#include <cstddef>

#define TYPE() std::int64_t
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,-100,100),random<T>(N,-100,100)

#include "bench.hpp"
18 changes: 18 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/int8.cpp
@@ -0,0 +1,18 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>
#include <cstddef>

#define TYPE() std::int8_t
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,-100,100),random<T>(N,-100,100)

#include "bench.hpp"
18 changes: 18 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/uint16.cpp
@@ -0,0 +1,18 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>
#include <cstddef>

#define TYPE() std::uint16_t
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,0,10000),random<T>(N,0,10000)

#include "bench.hpp"
18 changes: 18 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/uint32.cpp
@@ -0,0 +1,18 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>
#include <cstddef>

#define TYPE() std::uint32_t
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,0,10000),random<T>(N,0,10000)

#include "bench.hpp"
18 changes: 18 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/uint64.cpp
@@ -0,0 +1,18 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>
#include <cstddef>

#define TYPE() std::uint64_t
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,0,10000),random<T>(N,0,10000)

#include "bench.hpp"
18 changes: 18 additions & 0 deletions benchmark/module/core/scalar/bitwise_and/uint8.cpp
@@ -0,0 +1,18 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>
#include <cstddef>

#define TYPE() std::uint8_t
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,0,200),random<T>(N,0,200)

#include "bench.hpp"
19 changes: 19 additions & 0 deletions benchmark/module/core/simd/bitwise_and/double.cpp
@@ -0,0 +1,19 @@
//==================================================================================================
/**
EVE - Expressive Vector Engine
Copyright 2019 Joel FALCOU
Copyright 2019 Jean-Thierry LAPRESTE
Licensed under the MIT License <http://opensource.org/licenses/MIT>.
SPDX-License-Identifier: MIT
**/
//==================================================================================================
#include <eve/function/bitwise_and.hpp>
#include <eve/wide.hpp>

#define TYPE() eve::wide<double>
#define FUNCTION() eve::bitwise_and
#define SAMPLES(N) random<T>(N,-100.,100.),random<T>(N,-100.,100.)

#include "bench.hpp"

0 comments on commit 0b1648b

Please sign in to comment.