Skip to content

Commit

Permalink
Use ns.bench + Add bitwise_and example
Browse files Browse the repository at this point in the history
  • Loading branch information
ccharly committed May 18, 2016
1 parent d98a67b commit c370547
Show file tree
Hide file tree
Showing 8 changed files with 1,610 additions and 25 deletions.
38 changes: 22 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,26 @@ NS_prevent_in_source_build()

## External projects
## -------------------------------------------------------------------------------------------------
set(STF_STANDALONE_DESTINATION ${PROJECT_SOURCE_DIR}/test)
set(BRIGAND_STANDALONE_DESTINATION ${PROJECT_SOURCE_DIR}/include/boost/simd/detail)

NS_project_include(brigand.standalone)
set(STF_STANDALONE_DESTINATION ${PROJECT_SOURCE_DIR}/test)
set(BRIGAND_STANDALONE_DESTINATION ${PROJECT_SOURCE_DIR}/include/boost/simd/detail)
set(NS_BENCH_STANDALONE_DESTINATION ${PROJECT_SOURCE_DIR}/bench)

set(NS_CMAKE_PROJECT_OPTIONS
CMAKE_ARGS "-DBOOST_ROOT=${BOOST_HEADER_ONLY_DESTINATION}/include"
)
if (DEFINED USE_SELF_BOOST)
set(BOOST_HEADER_ONLY_GIT_TAG develop)
NS_project_include(boost-header-only)
set(Boost_INCLUDE_DIRS ${BOOST_HEADER_ONLY_DESTINATION}/include)
endif()

# NOTE: (workaround)
# We DO need to use `CMAKE_ARGS` here otherwise, travis is not able to find boost even when
# exporting BOOST_ROOT using shell export...
set(BOOST_DISPATCH_GIT_TAG develop)
set(BOOST_DISPATCH_OPTIONS
CMAKE_ARGS "-DBOOST_ROOT=${BOOST_HEADER_ONLY_DESTINATION}/include"
)

set( STF_OPTIONS
CMAKE_ARGS "-DBOOST_ROOT=${BOOST_HEADER_ONLY_DESTINATION}/include"
)
# Use the same BOOST_ROOT for every projects
set(NS_CMAKE_PROJECT_OPTIONS
CMAKE_ARGS "-DBOOST_ROOT=${Boost_INCLUDE_DIRS}"
)

if (DEFINED USE_SELF_BOOST)
set(BOOST_DISPATCH_GIT_TAG develop)
NS_project_include(boost.dispatch)
add_dependencies(BOOST_DISPATCH BOOST_HEADER_ONLY)
add_dependencies(BOOST_DISPATCH-install BOOST_HEADER_ONLY)
Expand All @@ -76,6 +75,8 @@ if (DEFINED USE_SELF_BOOST)
)
endif()

NS_project_include(ns.bench.standalone)
NS_project_include(brigand.standalone)
NS_project_include(stf.standalone)

## Compute version string and mode + Documentation
Expand All @@ -97,17 +98,22 @@ endif()
include_directories(
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/test
${PROJECT_SOURCE_DIR}/bench
${Boost_INCLUDE_DIRS}
)

## Setup Unit & Coverage Test
## Setup Unit/Bench & Coverage Test
## -------------------------------------------------------------------------------------------------
include(./setup.cmake) # Import compiler specific setup
include(CTest)
add_custom_target(tests)
add_custom_target(unit)
add_dependencies(tests unit)
add_subdirectory(test)

add_custom_target(bench)
add_subdirectory(bench)

if (NOT DEFINED IS_TRAVIS_CI)
NS_include(coverage)
enable_coverage(boost.simd)
Expand Down
13 changes: 13 additions & 0 deletions bench/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## -------------------------------------------------------------------------------------------------
## Copyright 2016 - NumScale SAS
##
## Distributed under the Boost Software License, Version 1.0.
## See accompanying file LICENSE.txt or copy at
## http://www.boost.org/LICENSE_1_0.txt
## -------------------------------------------------------------------------------------------------

NS_include(make_bench)

set(CMAKE_BUILD_TYPE "Release")

add_subdirectory(function)
9 changes: 9 additions & 0 deletions bench/function/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## -------------------------------------------------------------------------------------------------
## Copyright 2016 - NumScale SAS
##
## Distributed under the Boost Software License, Version 1.0.
## See accompanying file LICENSE.txt or copy at
## http://www.boost.org/LICENSE_1_0.txt
## -------------------------------------------------------------------------------------------------

add_subdirectory(simd)
13 changes: 13 additions & 0 deletions bench/function/simd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## -------------------------------------------------------------------------------------------------
## Copyright 2016 - NumScale SAS
##
## Distributed under the Boost Software License, Version 1.0.
## See accompanying file LICENSE.txt or copy at
## http://www.boost.org/LICENSE_1_0.txt
## -------------------------------------------------------------------------------------------------

set(SOURCES
bitwise_and.cpp
)

make_bench("function.simd" ${SOURCES})
100 changes: 100 additions & 0 deletions bench/function/simd/bitwise_and.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// -------------------------------------------------------------------------------------------------
// Copyright 2016 - NumScale SAS
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
// -------------------------------------------------------------------------------------------------

#include <ns.bench.hpp>
#include <boost/simd/pack.hpp>
#include <boost/simd/function/bitwise_and.hpp>
#include <boost/simd/function/sin.hpp>
#include <cmath>

namespace bs = boost::simd;
namespace nsb = ns::bench;

template<typename T> inline std::string type_id()
{
typedef std::is_const<typename std::remove_reference<T>::type> const_t;
typedef std::is_lvalue_reference<T> lref_t;
typedef std::is_rvalue_reference<T> rref_t;

std::string s = boost::core::demangle(typeid(T).name());
s += const_t::value ? " const" : "";
s += lref_t::value ? "&" : "";
s += rref_t::value ? "&&" : "";

return s;
}

/// @overload
template<typename T> inline std::string type_id( const T& )
{
return type_id<T>();
}


template <typename T>
struct bitwise_and_packed
{
template <typename U>
void operator()(U min1, U max1)
{
using pack_t = bs::pack<T>;
nsb::make_function_experiment_cpe_sized_<pack_t::static_size>
( [](const pack_t& x, const pack_t& y ) -> pack_t
{
//std::cout << type_id<typename pack_t::storage_type>() << std::endl;
return bs::bitwise_and(x, y);
}
, nsb::generators::rand<pack_t>(min1, max1)
, nsb::generators::rand<pack_t>(min1, max1)
);
}
};

template <typename T>
struct bitwise_and_scalar
{
template <typename U>
void operator()(U min1, U max1)
{
nsb::make_function_experiment_cpe_sized_<1>
( [](const T & x, const T & y) -> T
{ return bs::bitwise_and(x, y); }
, nsb::generators::rand<T>(min1, max1)
, nsb::generators::rand<T>(min1, max1)
);
}
};

template <typename T>
struct bitwise_and_std
{
template <typename U>
void operator()(U min1, U max1)
{
nsb::make_function_experiment_cpe_sized_<1>
( [](const T & x, const T & y) -> T
{ return x & y; }
, nsb::generators::rand<T>(min1, max1)
, nsb::generators::rand<T>(min1, max1)
);
}
};

int main(int argc, char **argv) {
nsb::parse_args(argc, argv);

nsb::make_for_each<bitwise_and_packed, short>(-10, 10);
//nsb::make_for_each<bitwise_and_scalar, short>(-10, 10);

//nsb::make_for_each<bitwise_and_packed, uint64_t>(0, 20);
//nsb::make_for_each<bitwise_and_packed, NS_BENCH_NUMERIC_TYPES>(-10, 10);
//nsb::make_for_each<bitwise_and_scalar, NS_BENCH_NUMERIC_TYPES>(-10, 10);
//nsb::make_for_each<bitwise_and_std, NS_BENCH_INTEGRAL_TYPES>(-10, 10);
return 0;
}

Loading

0 comments on commit c370547

Please sign in to comment.