stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork

This commit is contained in:
2026-02-24 18:38:47 +00:00
parent da8c28aaeb
commit 65cb2619a7
13106 changed files with 2484322 additions and 1804 deletions
@@ -0,0 +1,51 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_AS_HPP
#define BOOST_COMPUTE_FUNCTIONAL_AS_HPP
namespace boost {
namespace compute {
namespace detail {
template<class T, class Arg>
struct invoked_as
{
invoked_as(const Arg &arg)
: m_arg(arg)
{
}
Arg m_arg;
};
} // end detail namespace
/// The \ref as function converts its argument to type \c T (similar to
/// reinterpret_cast<T>).
///
/// \see \ref convert "convert<T>"
template<class T>
struct as
{
typedef T result_type;
/// \internal_
template<class Arg>
detail::invoked_as<T, Arg> operator()(const Arg &arg) const
{
return detail::invoked_as<T, Arg>(arg);
}
};
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_AS_HPP
@@ -0,0 +1,141 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_ATOMIC_HPP
#define BOOST_COMPUTE_FUNCTIONAL_ATOMIC_HPP
#include <boost/compute/cl.hpp>
#include <boost/compute/function.hpp>
#ifndef BOOST_COMPUTE_DOXYGEN_INVOKED
#ifdef CL_VERSION_1_1
#define BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "atomic_"
#else
#define BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "atom_"
#endif
#endif // BOOST_COMPUTE_DOXYGEN_INVOKED
namespace boost {
namespace compute {
template<class T>
class atomic_add : public function<T (T*, T)>
{
public:
atomic_add()
: function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "add")
{
}
};
template<class T>
class atomic_sub : public function<T (T*, T)>
{
public:
atomic_sub()
: function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "sub")
{
}
};
template<class T>
class atomic_xchg : public function<T (T*, T)>
{
public:
atomic_xchg()
: function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "xchg")
{
}
};
template<class T>
class atomic_inc : public function<T (T*)>
{
public:
atomic_inc()
: function<T (T*)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "inc")
{
}
};
template<class T>
class atomic_dec : public function<T (T*)>
{
public:
atomic_dec()
: function<T (T*)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "dec")
{
}
};
template<class T>
class atomic_cmpxchg : public function<T (T*, T, T)>
{
public:
atomic_cmpxchg()
: function<T (T*, T, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "cmpxchg")
{
}
};
template<class T>
class atomic_max : public function<T (T*, T)>
{
public:
atomic_max()
: function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "max")
{
}
};
template<class T>
class atomic_min : public function<T (T*, T)>
{
public:
atomic_min()
: function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "min")
{
}
};
template<class T>
class atomic_and : public function<T (T*, T)>
{
public:
atomic_and()
: function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "and")
{
}
};
template<class T>
class atomic_or : public function<T (T*, T)>
{
public:
atomic_or()
: function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "or")
{
}
};
template<class T>
class atomic_xor : public function<T (T*, T)>
{
public:
atomic_xor()
: function<T (T*, T)>(BOOST_COMPUTE_DETAIL_ATOMIC_PREFIX "xor")
{
}
};
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_ATOMIC_HPP
@@ -0,0 +1,261 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_BIND_HPP
#define BOOST_COMPUTE_FUNCTIONAL_BIND_HPP
#include <boost/mpl/int.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/type_traits/conditional.hpp>
#include <boost/compute/config.hpp>
#include <boost/compute/detail/meta_kernel.hpp>
namespace boost {
namespace compute {
namespace placeholders {
/// \internal_
template<int I>
struct placeholder : boost::integral_constant<int, I>
{
placeholder() { }
};
placeholder<0> const _1;
placeholder<1> const _2;
} // end placeholders namespace
/// Meta-function returning \c true if \c T is a placeholder type.
template<class T>
struct is_placeholder : boost::false_type
{
};
/// \internal_
template<int I>
struct is_placeholder<placeholders::placeholder<I> > : boost::true_type
{
};
namespace detail {
template<class Function, class BoundArgs, class Args>
struct invoked_bound_function
{
invoked_bound_function(Function f, BoundArgs bound_args, Args args)
: m_function(f),
m_bound_args(bound_args),
m_args(args)
{
}
// meta-function returning true if the N'th argument is a placeholder
template<int N>
struct is_placeholder_arg
{
typedef typename boost::tuples::element<N, BoundArgs>::type nth_bound_arg;
typedef typename is_placeholder<nth_bound_arg>::type type;
static const bool value = is_placeholder<nth_bound_arg>::value;
};
template<class Arg>
struct get_arg_type
{
typedef Arg type;
};
template<int I>
struct get_arg_type<placeholders::placeholder<I> >
{
typedef typename boost::tuples::element<I, Args>::type type;
};
// meta-function returning the type of the N'th argument when invoked
template<int N>
struct get_nth_arg_type
{
typedef typename boost::tuples::element<N, BoundArgs>::type nth_bound_arg;
typedef typename get_arg_type<nth_bound_arg>::type type;
};
template<int N>
typename get_nth_arg_type<N>::type get_nth_arg(
typename boost::enable_if_c<is_placeholder_arg<N>::value>::type* = 0
) const
{
typedef typename boost::tuples::element<N, BoundArgs>::type nth_bound_arg;
return boost::get<nth_bound_arg::value>(m_args);
}
template<int N>
typename get_nth_arg_type<N>::type get_nth_arg(
typename boost::disable_if_c<is_placeholder_arg<N>::value>::type* = 0
) const
{
return boost::get<N>(m_bound_args);
}
Function m_function;
BoundArgs m_bound_args;
Args m_args;
};
template<class Function, class BoundArgs, class Args>
inline meta_kernel& apply_invoked_bound_function(
meta_kernel &k,
const invoked_bound_function<Function, BoundArgs, Args> &expr,
typename boost::enable_if_c<
boost::tuples::length<BoundArgs>::value == 1
>::type* = 0
)
{
return k << expr.m_function(expr.template get_nth_arg<0>());
}
template<class Function, class BoundArgs, class Args>
inline meta_kernel& apply_invoked_bound_function(
meta_kernel &k,
const invoked_bound_function<Function, BoundArgs, Args> &expr,
typename boost::enable_if_c<
boost::tuples::length<BoundArgs>::value == 2
>::type* = 0
)
{
return k << expr.m_function(expr.template get_nth_arg<0>(),
expr.template get_nth_arg<1>());
}
template<class Function, class BoundArgs, class Args>
inline meta_kernel& apply_invoked_bound_function(
meta_kernel &k,
const invoked_bound_function<Function, BoundArgs, Args> &expr,
typename boost::enable_if_c<
boost::tuples::length<BoundArgs>::value == 3
>::type* = 0
)
{
return k << expr.m_function(expr.template get_nth_arg<0>(),
expr.template get_nth_arg<1>(),
expr.template get_nth_arg<2>());
}
template<class Function, class BoundArgs, class Args>
inline meta_kernel& operator<<(
meta_kernel &k,
const invoked_bound_function<Function, BoundArgs, Args> &expr
)
{
return apply_invoked_bound_function(k, expr);
}
template<class Function, class BoundArgs>
struct bound_function
{
typedef int result_type;
bound_function(Function f, BoundArgs args)
: m_function(f),
m_args(args)
{
}
template<class Arg1>
detail::invoked_bound_function<
Function,
BoundArgs,
boost::tuple<Arg1>
>
operator()(const Arg1 &arg1) const
{
return detail::invoked_bound_function<
Function,
BoundArgs,
boost::tuple<Arg1>
>(m_function, m_args, boost::make_tuple(arg1));
}
template<class Arg1, class Arg2>
detail::invoked_bound_function<
Function,
BoundArgs,
boost::tuple<Arg1, Arg2>
>
operator()(const Arg1 &arg1, const Arg2 &arg2) const
{
return detail::invoked_bound_function<
Function,
BoundArgs,
boost::tuple<Arg1, Arg2>
>(m_function, m_args, boost::make_tuple(arg1, arg2));
}
Function m_function;
BoundArgs m_args;
};
} // end detail namespace
#if !defined(BOOST_COMPUTE_NO_VARIADIC_TEMPLATES) || defined(BOOST_COMPUTE_DOXYGEN_INVOKED)
/// Returns a function wrapper which invokes \p f with \p args when called.
///
/// For example, to generate a unary function object which returns \c true
/// when its argument is less than \c 7:
/// \code
/// using boost::compute::less;
/// using boost::compute::placeholders::_1;
///
/// auto less_than_seven = boost::compute::bind(less<int>(), _1, 7);
/// \endcode
template<class F, class... Args>
inline detail::bound_function<F, boost::tuple<Args...> >
bind(F f, Args... args)
{
typedef typename boost::tuple<Args...> ArgsTuple;
return detail::bound_function<F, ArgsTuple>(f, boost::make_tuple(args...));
}
#else
template<class F, class A1>
inline detail::bound_function<F, boost::tuple<A1> >
bind(F f, A1 a1)
{
typedef typename boost::tuple<A1> Args;
return detail::bound_function<F, Args>(f, boost::make_tuple(a1));
}
template<class F, class A1, class A2>
inline detail::bound_function<F, boost::tuple<A1, A2> >
bind(F f, A1 a1, A2 a2)
{
typedef typename boost::tuple<A1, A2> Args;
return detail::bound_function<F, Args>(f, boost::make_tuple(a1, a2));
}
template<class F, class A1, class A2, class A3>
inline detail::bound_function<F, boost::tuple<A1, A2, A3> >
bind(F f, A1 a1, A2 a2, A3 a3)
{
typedef typename boost::tuple<A1, A2, A3> Args;
return detail::bound_function<F, Args>(f, boost::make_tuple(a1, a2, a3));
}
#endif // BOOST_COMPUTE_NO_VARIADIC_TEMPLATES
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_BIND_HPP
@@ -0,0 +1,29 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_COMMON_HPP
#define BOOST_COMPUTE_FUNCTIONAL_COMMON_HPP
#include <boost/compute/functional/detail/macros.hpp>
namespace boost {
namespace compute {
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(clamp, T (T, T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(degrees, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(radians, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(sign, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(smoothstep, T (T, T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(step, T (T, T), class T)
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_COMMON_HPP
@@ -0,0 +1,51 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_CONVERT_HPP
#define BOOST_COMPUTE_FUNCTIONAL_CONVERT_HPP
namespace boost {
namespace compute {
namespace detail {
template<class T, class Arg>
struct invoked_convert
{
invoked_convert(const Arg &arg)
: m_arg(arg)
{
}
Arg m_arg;
};
} // end detail namespace
/// The \ref convert function converts its argument to type \c T (similar to
/// static_cast<T>).
///
/// \see \ref as "as<T>"
template<class T>
struct convert
{
typedef T result_type;
/// \internal_
template<class Arg>
detail::invoked_convert<T, Arg> operator()(const Arg &arg) const
{
return detail::invoked_convert<T, Arg>(arg);
}
};
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_CONVERT_HPP
@@ -0,0 +1,35 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_MACROS_HPP
#define BOOST_COMPUTE_FUNCTIONAL_MACROS_HPP
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/stringize.hpp>
#include <boost/compute/function.hpp>
#define BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(name, signature, template_args) \
template<template_args> \
class name : public function<signature> \
{ \
public: \
(name)() : function<signature>(BOOST_PP_STRINGIZE(name)) { } \
};
#define BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(name, signature, template_args) \
template<template_args> \
class BOOST_PP_CAT(name, _) : public function<signature> \
{ \
public: \
BOOST_PP_CAT(name, _)() : function<signature>(BOOST_PP_STRINGIZE(name)) { } \
};
#endif // BOOST_COMPUTE_FUNCTIONAL_MACROS_HPP
@@ -0,0 +1,48 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_BALLOT_HPP
#define BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_BALLOT_HPP
#include <boost/compute/function.hpp>
#include <boost/compute/types/fundamental.hpp>
namespace boost {
namespace compute {
namespace detail {
template<class T>
class nvidia_ballot : public function<uint_(T)>
{
public:
nvidia_ballot()
: function<uint_(T)>("nvidia_ballot")
{
this->set_source(
"inline uint nvidia_ballot(const uint x)\n"
"{\n"
" uint result;\n"
" asm volatile(\n"
" \"setp.ne.u32 %%p1, %1, 0;\"\n"
" \"vote.ballot.b32 %0, %%p1;\"\n"
" : \"=r\"(result)\n"
" : \"r\"(x)\n"
" );\n"
" return result;\n"
"}\n"
);
}
};
} // end detail namespace
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_BALLOT_HPP
@@ -0,0 +1,42 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_POPCOUNT_HPP
#define BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_POPCOUNT_HPP
#include <boost/compute/function.hpp>
namespace boost {
namespace compute {
namespace detail {
template<class T>
class nvidia_popcount : public function<T(T)>
{
public:
nvidia_popcount()
: function<T(T)>("nvidia_popcount")
{
this->set_source(
"inline uint nvidia_popcount(const uint x)\n"
"{\n"
" uint count;\n"
" asm(\"popc.b32 %0, %1;\" : \"=r\"(count) : \"r\"(x));\n"
" return count;\n"
"}\n"
);
}
};
} // end detail namespace
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_POPCOUNT_HPP
@@ -0,0 +1,143 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_DETAIL_UNPACK_HPP
#define BOOST_COMPUTE_FUNCTIONAL_DETAIL_UNPACK_HPP
#include <boost/compute/functional/get.hpp>
#include <boost/compute/type_traits/is_vector_type.hpp>
#include <boost/compute/type_traits/result_of.hpp>
#include <boost/compute/type_traits/vector_size.hpp>
#include <boost/compute/detail/meta_kernel.hpp>
namespace boost {
namespace compute {
namespace detail {
template<class Function, class Arg, size_t Arity>
struct invoked_unpacked
{
invoked_unpacked(const Function &f, const Arg &arg)
: m_function(f),
m_arg(arg)
{
}
Function m_function;
Arg m_arg;
};
template<class Function, class Arg, size_t Arity>
inline meta_kernel& operator<<(meta_kernel &k, const invoked_unpacked<Function, Arg, Arity> &expr);
template<class Function, class Arg>
inline meta_kernel& operator<<(meta_kernel &k, const invoked_unpacked<Function, Arg, 1> &expr)
{
return k << expr.m_function(get<0>()(expr.m_arg));
}
template<class Function, class Arg>
inline meta_kernel& operator<<(meta_kernel &k, const invoked_unpacked<Function, Arg, 2> &expr)
{
return k << expr.m_function(get<0>()(expr.m_arg), get<1>()(expr.m_arg));
}
template<class Function, class Arg>
inline meta_kernel& operator<<(meta_kernel &k, const invoked_unpacked<Function, Arg, 3> &expr)
{
return k << expr.m_function(get<0>()(expr.m_arg), get<1>()(expr.m_arg), get<2>()(expr.m_arg));
}
template<class Function>
struct unpacked
{
template<class T, class Enable = void>
struct aggregate_length
{
BOOST_STATIC_CONSTANT(size_t, value = boost::tuples::length<T>::value);
};
template<class T>
struct aggregate_length<T, typename enable_if<is_vector_type<T> >::type>
{
BOOST_STATIC_CONSTANT(size_t, value = vector_size<T>::value);
};
template<class TupleArg, size_t TupleSize>
struct result_impl {};
template<class TupleArg>
struct result_impl<TupleArg, 1>
{
typedef typename detail::get_result_type<0, TupleArg>::type T1;
typedef typename boost::compute::result_of<Function(T1)>::type type;
};
template<class TupleArg>
struct result_impl<TupleArg, 2>
{
typedef typename detail::get_result_type<0, TupleArg>::type T1;
typedef typename detail::get_result_type<1, TupleArg>::type T2;
typedef typename boost::compute::result_of<Function(T1, T2)>::type type;
};
template<class TupleArg>
struct result_impl<TupleArg, 3>
{
typedef typename detail::get_result_type<0, TupleArg>::type T1;
typedef typename detail::get_result_type<1, TupleArg>::type T2;
typedef typename detail::get_result_type<2, TupleArg>::type T3;
typedef typename boost::compute::result_of<Function(T1, T2, T3)>::type type;
};
template<class Signature>
struct result {};
template<class This, class Arg>
struct result<This(Arg)>
{
typedef typename result_impl<Arg, aggregate_length<Arg>::value>::type type;
};
unpacked(const Function &f)
: m_function(f)
{
}
template<class Arg>
detail::invoked_unpacked<
Function, Arg, aggregate_length<typename Arg::result_type>::value
>
operator()(const Arg &arg) const
{
return detail::invoked_unpacked<
Function,
Arg,
aggregate_length<typename Arg::result_type>::value
>(m_function, arg);
}
Function m_function;
};
template<class Function>
inline unpacked<Function> unpack(const Function &f)
{
return unpacked<Function>(f);
}
} // end detail namespace
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_DETAIL_UNPACK_HPP
@@ -0,0 +1,86 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_FIELD_HPP
#define BOOST_COMPUTE_FUNCTIONAL_FIELD_HPP
#include <string>
namespace boost {
namespace compute {
namespace detail {
template<class T, class Arg>
struct invoked_field
{
typedef T result_type;
invoked_field(const Arg &arg, const std::string &field)
: m_arg(arg),
m_field(field)
{
}
Arg m_arg;
std::string m_field;
};
} // end detail namespace
/// Returns the named field from a value.
///
/// The template-type \c T specifies the field's value type. Note
/// that the value type must match the actual type of the field
/// otherwise runtime compilation or logic errors may occur.
///
/// For example, to access the \c second field in a
/// \c std::pair<int, float> object:
/// \code
/// field<float>("second");
/// \endcode
///
/// This can also be used with vector types to access individual
/// components as well as perform swizzle operations.
///
/// For example, to access the first and third components of an
/// \c int vector type (e.g. \c int4):
/// \code
/// field<int2_>("xz");
/// \endcode
///
/// \see \ref get "get<N>"
template<class T>
class field
{
public:
/// Result type.
typedef T result_type;
/// Creates a new field functor with \p field.
field(const std::string &field)
: m_field(field)
{
}
/// \internal_
template<class Arg>
detail::invoked_field<T, Arg> operator()(const Arg &arg) const
{
return detail::invoked_field<T, Arg>(arg, m_field);
}
private:
std::string m_field;
};
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_FIELD_HPP
@@ -0,0 +1,32 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_GEOMETRY_HPP
#define BOOST_COMPUTE_FUNCTIONAL_GEOMETRY_HPP
#include <boost/compute/type_traits.hpp>
#include <boost/compute/functional/detail/macros.hpp>
namespace boost {
namespace compute {
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(cross, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(dot, typename scalar_type<T>::type (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(distance, typename scalar_type<T>::type (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fast_distance, typename scalar_type<T>::type (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(length, typename scalar_type<T>::type (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fast_length, typename scalar_type<T>::type (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(normalize, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fast_normalize, T (T), class T)
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_GEOMETRY_HPP
@@ -0,0 +1,76 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_GET_HPP
#define BOOST_COMPUTE_FUNCTIONAL_GET_HPP
#include <cstddef>
#include <boost/compute/types/fundamental.hpp>
#include <boost/compute/type_traits/scalar_type.hpp>
namespace boost {
namespace compute {
namespace detail {
// meta-function returning the result type for get<N>()
template<size_t N, class Arg>
struct get_result_type
{
typedef typename scalar_type<Arg>::type type;
};
template<size_t N, class Arg, class T>
struct invoked_get
{
typedef typename get_result_type<N, T>::type result_type;
invoked_get(const Arg &arg)
: m_arg(arg)
{
}
Arg m_arg;
};
} // end detail namespace
/// Returns the \c N'th element of an aggregate type (e.g. scalarN,
/// pair, tuple, etc.).
///
/// \see \ref field "field<T>"
template<size_t N>
struct get
{
/// \internal_
template<class> struct result;
/// \internal_
template<class F, class Arg>
struct result<F(Arg)>
{
typedef typename detail::get_result_type<N, Arg>::type type;
};
template<class Arg>
detail::invoked_get<
N, Arg, typename boost::remove_cv<typename Arg::result_type>::type
> operator()(const Arg &arg) const
{
typedef typename boost::remove_cv<typename Arg::result_type>::type T;
return detail::invoked_get<N, Arg, T>(arg);
}
};
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_GET_HPP
@@ -0,0 +1,91 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_HASH_HPP
#define BOOST_COMPUTE_FUNCTIONAL_HASH_HPP
#include <boost/compute/function.hpp>
#include <boost/compute/types/fundamental.hpp>
namespace boost {
namespace compute {
namespace detail {
template<class Key>
std::string make_hash_function_name()
{
return std::string("boost_hash_") + type_name<Key>();
}
template<class Key>
inline std::string make_hash_function_source()
{
std::stringstream source;
source << "inline ulong " << make_hash_function_name<Key>()
<< "(const " << type_name<Key>() << " x)\n"
<< "{\n"
// note we reinterpret the argument as a 32-bit uint and
// then promote it to a 64-bit ulong for the result type
<< " ulong a = as_uint(x);\n"
<< " a = (a ^ 61) ^ (a >> 16);\n"
<< " a = a + (a << 3);\n"
<< " a = a ^ (a >> 4);\n"
<< " a = a * 0x27d4eb2d;\n"
<< " a = a ^ (a >> 15);\n"
<< " return a;\n"
<< "}\n";
return source.str();
}
template<class Key>
struct hash_impl
{
typedef Key argument_type;
typedef ulong_ result_type;
hash_impl()
: m_function("")
{
m_function = make_function_from_source<result_type(argument_type)>(
make_hash_function_name<argument_type>(),
make_hash_function_source<argument_type>()
);
}
template<class Arg>
invoked_function<result_type, boost::tuple<Arg> >
operator()(const Arg &arg) const
{
return m_function(arg);
}
function<result_type(argument_type)> m_function;
};
} // end detail namespace
/// The hash function returns a hash value for the input value.
///
/// The return type is \c ulong_ (the OpenCL unsigned long type).
template<class Key> struct hash;
/// \internal_
template<> struct hash<int_> : detail::hash_impl<int_> { };
/// \internal_
template<> struct hash<uint_> : detail::hash_impl<uint_> { };
/// \internal_
template<> struct hash<float_> : detail::hash_impl<float_> { };
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_HASH_HPP
@@ -0,0 +1,64 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
#define BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
namespace boost {
namespace compute {
namespace detail {
template<class T, class Arg>
struct invoked_identity
{
typedef T result_type;
invoked_identity(const Arg &arg)
: m_arg(arg)
{
}
Arg m_arg;
};
} // end detail namespace
/// Identity function which simply returns its input.
///
/// For example, to directly copy values using the transform() algorithm:
/// \code
/// transform(input.begin(), input.end(), output.begin(), identity<int>(), queue);
/// \endcode
///
/// \see \ref as "as<T>", \ref convert "convert<T>"
template<class T>
class identity
{
public:
/// Identity function result type.
typedef T result_type;
/// Creates a new identity function.
identity()
{
}
/// \internal_
template<class Arg>
detail::invoked_identity<T, Arg> operator()(const Arg &arg) const
{
return detail::invoked_identity<T, Arg>(arg);
}
};
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_IDENTITY_HPP
@@ -0,0 +1,30 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_INTEGER_HPP
#define BOOST_COMPUTE_FUNCTIONAL_INTEGER_HPP
#include <boost/compute/functional/detail/macros.hpp>
namespace boost {
namespace compute {
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(abs, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(abs_diff, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(add_sat, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(hadd, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(rhadd, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(max, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(min, T (T, T), class T)
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_INTEGER_HPP
@@ -0,0 +1,208 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP
#define BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP
namespace boost {
namespace compute {
namespace detail {
template<class Predicate, class Expr>
class invoked_unary_negate_function
{
public:
typedef int result_type;
invoked_unary_negate_function(const Predicate &pred,
const Expr &expr)
: m_pred(pred),
m_expr(expr)
{
}
Predicate pred() const
{
return m_pred;
}
Expr expr() const
{
return m_expr;
}
private:
Predicate m_pred;
Expr m_expr;
};
template<class Predicate, class Expr1, class Expr2>
class invoked_binary_negate_function
{
public:
typedef int result_type;
invoked_binary_negate_function(const Predicate &pred,
const Expr1 &expr1,
const Expr2 &expr2)
: m_pred(pred),
m_expr1(expr1),
m_expr2(expr2)
{
}
Predicate pred() const
{
return m_pred;
}
Expr1 expr1() const
{
return m_expr1;
}
Expr2 expr2() const
{
return m_expr2;
}
private:
Predicate m_pred;
Expr1 m_expr1;
Expr2 m_expr2;
};
} // end detail namespace
/// \internal_
template<class Arg, class Result>
struct unary_function
{
typedef Arg argument_type;
typedef Result result_type;
};
/// \internal_
template<class Arg1, class Arg2, class Result>
struct binary_function
{
typedef Arg1 first_argument_type;
typedef Arg2 second_argument_type;
typedef Result result_type;
};
/// \internal_
template<class Arg1, class Arg2, class Arg3, class Result>
struct ternary_function
{
typedef Arg1 first_argument_type;
typedef Arg2 second_argument_type;
typedef Arg3 third_argument_type;
typedef Result result_type;
};
/// The unary_negate function adaptor negates a unary function.
///
/// \see not1()
template<class Predicate>
class unary_negate : public unary_function<void, int>
{
public:
explicit unary_negate(Predicate pred)
: m_pred(pred)
{
}
/// \internal_
template<class Arg>
detail::invoked_unary_negate_function<Predicate, Arg>
operator()(const Arg &arg) const
{
return detail::invoked_unary_negate_function<
Predicate,
Arg
>(m_pred, arg);
}
private:
Predicate m_pred;
};
/// The binnary_negate function adaptor negates a binary function.
///
/// \see not2()
template<class Predicate>
class binary_negate : public binary_function<void, void, int>
{
public:
explicit binary_negate(Predicate pred)
: m_pred(pred)
{
}
/// \internal_
template<class Arg1, class Arg2>
detail::invoked_binary_negate_function<Predicate, Arg1, Arg2>
operator()(const Arg1 &arg1, const Arg2 &arg2) const
{
return detail::invoked_binary_negate_function<
Predicate,
Arg1,
Arg2
>(m_pred, arg1, arg2);
}
private:
Predicate m_pred;
};
/// Returns a unary_negate adaptor around \p predicate.
///
/// \param predicate the unary function to wrap
///
/// \return a unary_negate wrapper around \p predicate
template<class Predicate>
inline unary_negate<Predicate> not1(const Predicate &predicate)
{
return unary_negate<Predicate>(predicate);
}
/// Returns a binary_negate adaptor around \p predicate.
///
/// \param predicate the binary function to wrap
///
/// \return a binary_negate wrapper around \p predicate
template<class Predicate>
inline binary_negate<Predicate> not2(const Predicate &predicate)
{
return binary_negate<Predicate>(predicate);
}
/// The logical_not function negates its argument and returns it.
///
/// \see not1(), not2()
template<class T>
struct logical_not : public unary_function<T, int>
{
/// \internal_
template<class Expr>
detail::invoked_function<int, boost::tuple<Expr> >
operator()(const Expr &expr) const
{
return detail::invoked_function<int, boost::tuple<Expr> >(
"!", std::string(), boost::make_tuple(expr)
);
}
};
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_LOGICAL_HPP
@@ -0,0 +1,80 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_MATH_HPP
#define BOOST_COMPUTE_FUNCTIONAL_MATH_HPP
#include <boost/compute/functional/detail/macros.hpp>
namespace boost {
namespace compute {
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(acos, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(acosh, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(acospi, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(asin, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(asinh, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(asinpi, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(atan, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(atan2, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(atanh, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(atanpi, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(atan2pi, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(cbrt, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(ceil, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(copysign, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(cos, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(cosh, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(cospi, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(erf, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(erfc, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(exp, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(exp2, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(exp10, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(expm1, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fabs, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fdim, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(floor, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fma, T (T, T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fmax, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fmin, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(fmod, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(hypot, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(ilogb, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(lgamma, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(log, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(log2, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(log10, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(log1p, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(logb, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(mad, T (T, T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(nextafter, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(pow, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(pown, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(powr, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(remainder, T (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(rint, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(rootn, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(round, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(rsqrt, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(sin, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(sinh, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(sinpi, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(sqrt, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(tan, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(tanh, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(tanpi, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(tgamma, T (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(trunc, T (T), class T)
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_MATH_HPP
@@ -0,0 +1,100 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_OPERATORS_HPP
#define BOOST_COMPUTE_FUNCTIONAL_OPERATORS_HPP
#include <string>
namespace boost {
namespace compute {
namespace detail {
template<class Expr1, class Expr2, class Result>
struct invoked_binary_operator
{
typedef Result result_type;
invoked_binary_operator(const std::string &op,
const Expr1 &arg1,
const Expr2 &arg2)
: m_op(op),
m_expr1(arg1),
m_expr2(arg2)
{
}
std::string op() const
{
return m_op;
}
Expr1 arg1() const
{
return m_expr1;
}
Expr2 arg2() const
{
return m_expr2;
}
std::string m_op;
Expr1 m_expr1;
Expr2 m_expr2;
};
} // end detail namespace
/// \internal_
#define BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(name, op, return_type, arg_type) \
template<class arg_type> \
class name : public function<return_type (arg_type, arg_type)> \
{ \
public: \
name() : function<return_type (arg_type, arg_type)>(BOOST_PP_STRINGIZE(name)) { } \
\
template<class Arg1, class Arg2> \
detail::invoked_binary_operator<Arg1, Arg2, T> \
operator()(const Arg1 &x, const Arg2 &y) const \
{ \
return detail::invoked_binary_operator<Arg1, Arg2, T>(op, x, y); \
} \
};
// arithmetic operations
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(plus, "+", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(minus, "-", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(multiplies, "*", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(divides, "/", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(modulus, "%", T, T)
// comparisons
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(equal_to, "==", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(not_equal_to, "!=", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(greater, ">", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(less, "<", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(greater_equal, ">=", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(less_equal, "<=", T, T)
// logical operators
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(logical_and, "&&", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(logical_or, "||", T, T)
// bitwise operations
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(bit_and, "&", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(bit_or, "|", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(bit_xor, "^", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(shift_left, "<<", T, T)
BOOST_COMPUTE_DECLARE_BINARY_OPERATOR(shift_right, ">>", T, T)
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_OPERATORS_HPP
@@ -0,0 +1,55 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_POPCOUNT_HPP
#define BOOST_COMPUTE_FUNCTIONAL_POPCOUNT_HPP
#include <boost/compute/function.hpp>
#include <boost/compute/type_traits/type_name.hpp>
namespace boost {
namespace compute {
/// Returns the number of non-zero bits in \p x.
///
/// \see_opencl_ref{popcount}
template<class T>
class popcount : public function<T(T)>
{
public:
popcount()
: function<T(T)>("boost_popcount")
{
std::stringstream s;
s << "inline " << type_name<T>() << " boost_popcount"
<< "(const " << type_name<T>() << " x)\n"
<< "{\n"
// use built-in popcount if opencl 1.2 is supported
<< "#if __OPENCL_VERSION__ >= 120\n"
<< " return popcount(x);\n"
// fallback to generic popcount() implementation
<< "#else\n"
<< " " << type_name<T>() << " count = 0;\n"
<< " for(" << type_name<T>() << " i = 0; i < sizeof(i) * CHAR_BIT; i++){\n"
<< " if(x & (" << type_name<T>() << ") 1 << i){\n"
<< " count++;\n"
<< " }\n"
<< " }\n"
<< " return count;\n"
<< "#endif\n"
<< "}\n";
this->set_source(s.str());
}
};
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_POPCOUNT_HPP
@@ -0,0 +1,39 @@
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// 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
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//
#ifndef BOOST_COMPUTE_FUNCTIONAL_RELATIONAL_HPP
#define BOOST_COMPUTE_FUNCTIONAL_RELATIONAL_HPP
#include <boost/compute/functional/detail/macros.hpp>
namespace boost {
namespace compute {
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isequal, int (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isnotequal, int (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isgreater, int (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isgreaterequal, int (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isless, int (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(islessequal, int (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(islessgreater, int (T, T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isfinite, int (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isinf, int (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isnan, int (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isnormal, int (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isordered, int (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(isunordered, int (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION_UNDERSCORE(signbit, int (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(any, int (T), class T)
BOOST_COMPUTE_DECLARE_BUILTIN_FUNCTION(all, int (T), class T)
} // end compute namespace
} // end boost namespace
#endif // BOOST_COMPUTE_FUNCTIONAL_RELATIONAL_HPP