Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #114

Open
wants to merge 24 commits into
base: dev
Choose a base branch
from
Open

Dev #114

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e8c0df8
warning --
ThomasRetornaz Feb 26, 2018
d70bbc3
fix TestData& operator=(const TestData& other) assignment operator
ThomasRetornaz Feb 26, 2018
8d91b7e
wip issue #107 add transform/reduce algorithm
ThomasRetornaz Feb 26, 2018
c679f81
issue #107 add fill,copy,copy_n algorithm
ThomasRetornaz Feb 26, 2018
4bc2c63
issue #107 gcc compil fix
Feb 28, 2018
22e5357
issue #107 add search max/min
ThomasRetornaz Mar 5, 2018
5c48da0
issue #107 add find,find_if,find_if_not
ThomasRetornaz Mar 5, 2018
ab3e92b
issue #107 fix gcc and release mode for find*
Mar 5, 2018
b0735f5
issue #107 add max_element and min_element
ThomasRetornaz Mar 6, 2018
0025a8f
issue #107 gcc compil/warning fix
Mar 6, 2018
ae48025
issue #107 add count, count_if
ThomasRetornaz Mar 7, 2018
c8d12f4
Merge branch 'dev' of https://github.com/ThomasRetornaz/libsimdpp int…
ThomasRetornaz Mar 7, 2018
dc33d00
issue #107 add all_of, any_of, none_of
Mar 7, 2018
d6a6bfa
issue #107 add replace,replace_if
Mar 8, 2018
f95aa05
issue #107 add equal and lexicographic_compare
Mar 10, 2018
b8b0b34
issue #107 add transform_reduce
Mar 11, 2018
179cc90
issue #107 ras
Mar 11, 2018
f57deb0
issue #107 visual compilation fix
ThomasRetornaz Mar 11, 2018
3d9fb98
issue #107
ThomasRetornaz Apr 9, 2018
d8b2eda
issue #107 gcc and c++11 only compil fix
Apr 9, 2018
9a3636a
issue #107
ThomasRetornaz Apr 11, 2018
6ae2a4a
issue #115 Proof of concept
ThomasRetornaz Jul 16, 2018
5977ee9
#issue 115 linux/gcc fix
Jul 20, 2018
e286519
* warn --
ThomasRetornaz Oct 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,10 @@ install(FILES

enable_testing()

option(ENABLE_BENCH "Set to on in order to compile bench suite, work only in release mode" OFF)

add_subdirectory(simdpp)
add_subdirectory(test)
if(ENABLE_BENCH)
add_subdirectory(bench)
endif()
2 changes: 2 additions & 0 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(thirdparty)
add_subdirectory(insn)
51 changes: 51 additions & 0 deletions bench/insn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
include_directories(${libsimdpp_SOURCE_DIR})
include_directories(${GOOGLE_BENCHMARK_INCLUDE_DIRS})

set(TEST_BENCH_SOURCES
main.cc
main.h
)

set(BENCH_INSN_ARCH_SOURCES
algorithm/transform_unary.cc
algorithm/transform_binary.cc
algorithm/reduce_unary.cc
algorithm/reduce_binary.cc
load_store.cc
)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
foreach(ARCH ${COMPILABLE_ARCHS}})
simdpp_get_arch_info(CXX_FLAGS DEFINES_LIST SUFFIX ${ARCH})
#message("Create benchmark for arch : ${SUFFIX} with flags: ${CXX_FLAGS} with defines ${DEFINES_LIST}")
SET(exename "bench_insn_${SUFFIX}")
add_executable(${exename} ${BENCH_INSN_ARCH_SOURCES} ${TEST_BENCH_SOURCES})
set_target_properties( ${exename} PROPERTIES COMPILE_FLAGS "${CXX_FLAGS}" )
set_target_properties (${exename} PROPERTIES FOLDER bench)
if(SIMDPP_MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
# enable _vectorcall on i386 builds (only works on MSVC 2013)
#set_target_properties(${exename} PROPERTIES COMPILE_FLAGS "/Gv")
endif()
elseif(SIMDPP_MSVC_INTEL)
set_target_properties(${exename} PROPERTIES COMPILE_FLAGS "/Qstd=c++11")
else()
# Xcode clang linker spends very long time in deduplication pass when
# linking the test executable unless -fvisibility-inlines-hidden is passed.
set_target_properties(${exename} PROPERTIES COMPILE_FLAGS "-std=c++11 -O2 -Wall -Wextra -fvisibility-inlines-hidden")
endif()
if(WIN32)
target_link_libraries(${exename}
PUBLIC benchmark
PUBLIC shlwapi.lib
)
else()
target_link_libraries(${exename}
PUBLIC benchmark
PUBLIC pthread
)
add_dependencies(${exename} ${GOOGLE_BENCHMARK})
endif()
endforeach(ARCH ${${COMPILABLE_ARCHS}})


155 changes: 155 additions & 0 deletions bench/insn/algorithm/reduce_binary.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/* Copyright (C) 2018 Povilas Kanapickas <[email protected]>
Copyright (C) 2018 Thomas Retornaz <[email protected]>

Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/

#include "benchmark/benchmark.h"
#include <vector>
#include <numeric>
#include <iterator>
#include <simdpp/simd.h>
//algorithm
#include <simdpp/algorithm/reduce.h>


namespace {

template< typename T>
struct BinaryOpPlus
{
public:
BinaryOpPlus() {}
SIMDPP_INL T operator()(T const &a0, T const &a1) const SIMDPP_NOEXCEPT
{
return a0 + a1;
}

template<typename U>
SIMDPP_INL U operator()(U const &a0, U const &a1) const SIMDPP_NOEXCEPT
{
return a0 + a1;
}
};

template <typename T>
struct GeneratorConstant
{
GeneratorConstant(T constant) { m_constant = constant; }
T operator()() { return m_constant; }
T m_constant;
};


template<typename T, class Generator>
std::vector<T, simdpp::aligned_allocator<T, simdpp::simd_traits<T>::alignment>> DataGenerator(std::size_t size, Generator gen)
{

using vector_aligned_t = std::vector<T, simdpp::aligned_allocator<T, simdpp::simd_traits<T>::alignment>>;
vector_aligned_t input(size);
std::generate(input.begin(), input.end(), gen);
return input;
}

/*********************UNARY****************************/

template<typename T>
class ReduceBinaryFixture : public ::benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& st)
{
m_inputvect = DataGenerator<T, GeneratorConstant<T>>((size_t)st.range(0), GeneratorConstant<T>(1));
}
void TearDown(const ::benchmark::State&)
{
m_inputvect.clear();
}
using vector_aligned_t = std::vector<T, simdpp::aligned_allocator<T, simdpp::simd_traits<T>::alignment>>;
vector_aligned_t m_inputvect;
};

//UINT64_T
BENCHMARK_TEMPLATE_DEFINE_F(ReduceBinaryFixture, BinaryUNINT64_SIMD_Test, uint64_t)(benchmark::State& st)
{
const auto size= (size_t)st.range(0);
uint64_t init = (uint64_t)0;
auto opPlus = BinaryOpPlus<uint64_t>();
uint64_t neutral = (uint64_t)0;
while (st.KeepRunning())
{
benchmark::DoNotOptimize(simdpp::reduce(m_inputvect.data(), m_inputvect.data() + m_inputvect.size(), init, neutral, opPlus));
}
}
BENCHMARK_REGISTER_F(ReduceBinaryFixture, BinaryUNINT64_SIMD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);

BENCHMARK_TEMPLATE_DEFINE_F(ReduceBinaryFixture, BinaryUNINT64_STD_Test, uint64_t)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
uint64_t init = (uint64_t)0;
auto opPlus = BinaryOpPlus<uint64_t>();
while (st.KeepRunning())
{
benchmark::DoNotOptimize(std::accumulate(m_inputvect.cbegin(), m_inputvect.cend(), init, opPlus));
}
}
BENCHMARK_REGISTER_F(ReduceBinaryFixture, BinaryUNINT64_STD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);


//FLOAT
BENCHMARK_TEMPLATE_DEFINE_F(ReduceBinaryFixture, BinaryFLOAT_SIMD_Test, float)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
float init = (float)0;
auto opPlus = BinaryOpPlus<float>();
float neutral = (float)0;
while (st.KeepRunning())
{
benchmark::DoNotOptimize(simdpp::reduce(m_inputvect.data(), m_inputvect.data() + m_inputvect.size(), init, neutral, opPlus));
}
}
BENCHMARK_REGISTER_F(ReduceBinaryFixture, BinaryFLOAT_SIMD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);

BENCHMARK_TEMPLATE_DEFINE_F(ReduceBinaryFixture, BinaryFLOAT_STD_Test, float)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
float init = (float)0;
auto opPlus = BinaryOpPlus<uint64_t>();
while (st.KeepRunning())
{
benchmark::DoNotOptimize(std::accumulate(m_inputvect.cbegin(), m_inputvect.cend(), init, opPlus));
}
}
BENCHMARK_REGISTER_F(ReduceBinaryFixture, BinaryFLOAT_STD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);


//DOUBLE
BENCHMARK_TEMPLATE_DEFINE_F(ReduceBinaryFixture, BinaryDOUBLE_SIMD_Test, double)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
double init = (double)0;
auto opPlus = BinaryOpPlus<double>();
double neutral = (double)0;
while (st.KeepRunning())
{
benchmark::DoNotOptimize(simdpp::reduce(m_inputvect.data(), m_inputvect.data() + m_inputvect.size(), init, neutral, opPlus));
}
}
BENCHMARK_REGISTER_F(ReduceBinaryFixture, BinaryDOUBLE_SIMD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);

BENCHMARK_TEMPLATE_DEFINE_F(ReduceBinaryFixture, BinaryDOUBLE_STD_Test, double)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
double init = (double)0;
auto opPlus = BinaryOpPlus<uint64_t>();
while (st.KeepRunning())
{
benchmark::DoNotOptimize(std::accumulate(m_inputvect.cbegin(), m_inputvect.cend(), init, opPlus));
}
}
BENCHMARK_REGISTER_F(ReduceBinaryFixture, BinaryDOUBLE_STD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);



} // namespace
122 changes: 122 additions & 0 deletions bench/insn/algorithm/reduce_unary.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/* Copyright (C) 2018 Povilas Kanapickas <[email protected]>
Copyright (C) 2018 Thomas Retornaz <[email protected]>

Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
*/

#include "benchmark/benchmark.h"
#include <vector>
#include <numeric>
#include <iterator>
#include <simdpp/simd.h>
//algorithm
#include <simdpp/algorithm/reduce.h>


namespace {

template <typename T>
struct GeneratorConstant
{
GeneratorConstant(T constant) { m_constant = constant; }
T operator()() { return m_constant; }
T m_constant;
};


template<typename T, class Generator>
std::vector<T, simdpp::aligned_allocator<T, simdpp::simd_traits<T>::alignment>> DataGenerator(std::size_t size, Generator gen)
{

using vector_aligned_t = std::vector<T, simdpp::aligned_allocator<T, simdpp::simd_traits<T>::alignment>>;
vector_aligned_t input(size);
std::generate(input.begin(), input.end(), gen);
return input;
}

/*********************UNARY****************************/

template<typename T>
class ReduceUnaryFixture : public ::benchmark::Fixture {
public:
void SetUp(const ::benchmark::State& st)
{
m_inputvect = DataGenerator<T, GeneratorConstant<T>>((size_t)st.range(0), GeneratorConstant<T>(1));
}
void TearDown(const ::benchmark::State&)
{
m_inputvect.clear();
}
using vector_aligned_t = std::vector<T, simdpp::aligned_allocator<T, simdpp::simd_traits<T>::alignment>>;
vector_aligned_t m_inputvect;
};

//UINT64_T
BENCHMARK_TEMPLATE_DEFINE_F(ReduceUnaryFixture, UnaryUNINT64_SIMD_Test, uint64_t)(benchmark::State& st)
{
const auto size= (size_t)st.range(0);
while (st.KeepRunning())
{
benchmark::DoNotOptimize(simdpp::reduce(m_inputvect.data(), m_inputvect.data() + m_inputvect.size(),(uint64_t)0));
}
}
BENCHMARK_REGISTER_F(ReduceUnaryFixture, UnaryUNINT64_SIMD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);

BENCHMARK_TEMPLATE_DEFINE_F(ReduceUnaryFixture, UnaryUNINT64_STD_Test, uint64_t)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
while (st.KeepRunning())
{
benchmark::DoNotOptimize(std::accumulate(m_inputvect.begin(), m_inputvect.end(), (uint64_t)0));
}
}
BENCHMARK_REGISTER_F(ReduceUnaryFixture, UnaryUNINT64_STD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);


//FLOAT
BENCHMARK_TEMPLATE_DEFINE_F(ReduceUnaryFixture, UnaryFLOAT_SIMD_Test, float)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
while (st.KeepRunning())
{
benchmark::DoNotOptimize(simdpp::reduce(m_inputvect.data(), m_inputvect.data() + m_inputvect.size(), (float)0));
}
}
BENCHMARK_REGISTER_F(ReduceUnaryFixture, UnaryFLOAT_SIMD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);

BENCHMARK_TEMPLATE_DEFINE_F(ReduceUnaryFixture, UnaryFLOAT_STD_Test, float)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
while (st.KeepRunning())
{
benchmark::DoNotOptimize(std::accumulate(m_inputvect.begin(), m_inputvect.end(), (float)0));
}
}
BENCHMARK_REGISTER_F(ReduceUnaryFixture, UnaryFLOAT_STD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);

//DOUBLE
BENCHMARK_TEMPLATE_DEFINE_F(ReduceUnaryFixture, UnaryDOUBLE_SIMD_Test, double)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
while (st.KeepRunning())
{
benchmark::DoNotOptimize(simdpp::reduce(m_inputvect.data(), m_inputvect.data() + m_inputvect.size(), (double)0));
}
}
BENCHMARK_REGISTER_F(ReduceUnaryFixture, UnaryDOUBLE_SIMD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);

BENCHMARK_TEMPLATE_DEFINE_F(ReduceUnaryFixture, UnaryDOUBLE_STD_Test, double)(benchmark::State& st)
{
const auto size = (size_t)st.range(0);
while (st.KeepRunning())
{
benchmark::DoNotOptimize(std::accumulate(m_inputvect.begin(), m_inputvect.end(), (double)0));
}
}
BENCHMARK_REGISTER_F(ReduceUnaryFixture, UnaryDOUBLE_STD_Test)->Arg(1)->Arg(10)->Arg(32)->Arg(100)->Arg(1000)->Arg(10000);



} // namespace
Loading