Skip to content

Commit

Permalink
Improve binary function objects and replace thrust implementation (#1872
Browse files Browse the repository at this point in the history
)

* Improve binary function objects and replace thrust implementation
* simplify use of ::cuda::std binary_function_objects
* Replace _CCCL_CONSTEXPR_CXX14 with constexpr in all libcudacxx
binary function objects that are imported in thrust.
* Determine partial sum type without ::result_type
* Ignore _LIBCUDACXX_DEPRECATED_IN_CXX11 for doxygen

Co-authored-by: Bernhard Manfred Gruber <[email protected]>
  • Loading branch information
srinivasyadav18 and bernhardmgruber committed Jul 30, 2024
1 parent 6dfc8dd commit 4188fb0
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 485 deletions.
1 change: 1 addition & 0 deletions docs/repo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ doxygen_predefined = [
"_CCCL_SUPPRESS_DEPRECATED_POP",
"DOXYGEN_SHOULD_SKIP_THIS",
"DOXYGEN_ACTIVE",
"_LIBCUDACXX_DEPRECATED_IN_CXX11",
"THRUST_DISABLE_NAMESPACE_MAGIC",
"THRUST_IGNORE_NAMESPACE_MAGIC_ERROR",
"THRUST_NAMESPACE_BEGIN=namespace thrust {",
Expand Down
64 changes: 32 additions & 32 deletions libcudacxx/include/cuda/std/__functional/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS plus : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
{
return __x + __y;
}
Expand All @@ -46,7 +46,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS plus<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) + _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -60,7 +60,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
{
return __x - __y;
}
Expand All @@ -72,7 +72,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS minus<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) - _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -86,7 +86,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
{
return __x * __y;
}
Expand All @@ -98,7 +98,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS multiplies<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) * _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -112,7 +112,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
{
return __x / __y;
}
Expand All @@ -124,7 +124,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS divides<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) / _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -138,7 +138,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
{
return __x % __y;
}
Expand All @@ -150,7 +150,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS modulus<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) % _CUDA_VSTD::forward<_T2>(__u))
{
Expand Down Expand Up @@ -191,7 +191,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
{
return __x & __y;
}
Expand All @@ -203,7 +203,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_and<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) & _CUDA_VSTD::forward<_T2>(__u))
{
Expand Down Expand Up @@ -253,7 +253,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_or<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) | _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -267,7 +267,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
{
return __x ^ __y;
}
Expand All @@ -279,7 +279,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_xor<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) ^ _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -295,7 +295,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
{
return __x == __y;
}
Expand All @@ -307,7 +307,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS equal_to<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) == _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -321,7 +321,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
{
return __x != __y;
}
Expand All @@ -333,7 +333,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) != _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -347,7 +347,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
{
return __x < __y;
}
Expand All @@ -359,7 +359,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS less<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) < _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -373,7 +373,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
{
return __x <= __y;
}
Expand All @@ -385,7 +385,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS less_equal<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) <= _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -399,7 +399,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool
{
typedef bool __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
{
return __x >= __y;
}
Expand All @@ -411,7 +411,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater_equal<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) >= _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -425,7 +425,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
{
return __x > __y;
}
Expand All @@ -437,7 +437,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) > _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -453,7 +453,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
{
return __x && __y;
}
Expand All @@ -465,7 +465,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_and<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) && _CUDA_VSTD::forward<_T2>(__u))
{
Expand All @@ -479,7 +479,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool>
{
typedef bool __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
{
return !__x;
}
Expand All @@ -504,7 +504,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
_CCCL_EXEC_CHECK_DISABLE
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
{
return __x || __y;
}
Expand All @@ -516,7 +516,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_or<void>
{
_CCCL_EXEC_CHECK_DISABLE
template <class _T1, class _T2>
_CCCL_CONSTEXPR_CXX14 _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
constexpr _LIBCUDACXX_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
noexcept(noexcept(_CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u)))
-> decltype(_CUDA_VSTD::forward<_T1>(__t) || _CUDA_VSTD::forward<_T2>(__u))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2013 NVIDIA Corporation
* Copyright 2024 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,31 +27,12 @@
#endif // no system header

#include <thrust/detail/type_traits.h>
#include <thrust/functional.h>

THRUST_NAMESPACE_BEGIN

// forward definitions for is_commutative
template <typename T>
struct plus;
template <typename T>
struct multiplies;
template <typename T>
struct minimum;
template <typename T>
struct maximum;
template <typename T>
struct logical_or;
template <typename T>
struct logical_and;
template <typename T>
struct bit_or;
template <typename T>
struct bit_and;
template <typename T>
struct bit_xor;

namespace detail
{

template <typename BinaryFunction>
struct is_commutative : public thrust::detail::false_type
{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# pragma system_header
#endif // no system header
#include <thrust/detail/type_traits.h>
#include <thrust/detail/type_traits/function_traits.h>

#include <cuda/std/__type_traits/void_t.h>

Expand Down
Loading

0 comments on commit 4188fb0

Please sign in to comment.