Skip to content

Commit

Permalink
Provide libcu++ transparent functors in C++11
Browse files Browse the repository at this point in the history
Addresses part of: NVIDIA#1664
  • Loading branch information
bernhardmgruber committed Jun 12, 2024
1 parent bab3b8c commit 6fbd21d
Show file tree
Hide file tree
Showing 24 changed files with 6 additions and 137 deletions.
94 changes: 1 addition & 93 deletions libcudacxx/include/cuda/std/__functional/operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.
// SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

Expand Down Expand Up @@ -55,11 +55,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS plus<void>
typedef void is_transparent;
};

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
Expand All @@ -71,7 +67,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS minus : __binary_function<_Tp, _Tp, _Tp>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(minus);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS minus<void>
{
Expand All @@ -85,7 +80,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS minus<void>
}
typedef void is_transparent;
};
#endif

template <class _Tp = void>
struct _LIBCUDACXX_TEMPLATE_VIS multiplies : __binary_function<_Tp, _Tp, _Tp>
Expand Down Expand Up @@ -113,11 +107,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS multiplies<void>
typedef void is_transparent;
};

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
Expand All @@ -129,7 +119,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS divides : __binary_function<_Tp, _Tp, _Tp>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(divides);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS divides<void>
{
Expand All @@ -143,13 +132,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS divides<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
Expand All @@ -161,7 +145,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS modulus : __binary_function<_Tp, _Tp, _Tp>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(modulus);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS modulus<void>
{
Expand All @@ -175,7 +158,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS modulus<void>
}
typedef void is_transparent;
};
#endif

template <class _Tp = void>
struct _LIBCUDACXX_TEMPLATE_VIS negate : __unary_function<_Tp, _Tp>
Expand Down Expand Up @@ -204,11 +186,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS negate<void>

// Bitwise operations

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
Expand All @@ -220,7 +198,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_and : __binary_function<_Tp, _Tp, _Tp>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_and);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS bit_and<void>
{
Expand All @@ -234,9 +211,7 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_and<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
struct _LIBCUDACXX_TEMPLATE_VIS bit_not : __unary_function<_Tp, _Tp>
{
Expand All @@ -260,13 +235,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_not<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
Expand All @@ -278,7 +248,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_or : __binary_function<_Tp, _Tp, _Tp>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_or);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS bit_or<void>
{
Expand All @@ -292,13 +261,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_or<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp>
{
typedef _Tp __result_type; // used by valarray
Expand All @@ -310,7 +274,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_xor : __binary_function<_Tp, _Tp, _Tp>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(bit_xor);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS bit_xor<void>
{
Expand All @@ -324,15 +287,10 @@ struct _LIBCUDACXX_TEMPLATE_VIS bit_xor<void>
}
typedef void is_transparent;
};
#endif

// Comparison operations

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
Expand All @@ -344,7 +302,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS equal_to : __binary_function<_Tp, _Tp, bool>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(equal_to);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS equal_to<void>
{
Expand All @@ -358,13 +315,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS equal_to<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
Expand All @@ -376,7 +328,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to : __binary_function<_Tp, _Tp, bool>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(not_equal_to);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to<void>
{
Expand All @@ -390,13 +341,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS not_equal_to<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
Expand All @@ -408,7 +354,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS less : __binary_function<_Tp, _Tp, bool>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(less);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS less<void>
{
Expand All @@ -422,13 +367,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS less<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
Expand All @@ -440,7 +380,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS less_equal : __binary_function<_Tp, _Tp, bool>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(less_equal);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS less_equal<void>
{
Expand All @@ -454,13 +393,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS less_equal<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
Expand All @@ -472,7 +406,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater_equal : __binary_function<_Tp, _Tp, bool
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(greater_equal);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS greater_equal<void>
{
Expand All @@ -486,13 +419,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater_equal<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
Expand All @@ -504,7 +432,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater : __binary_function<_Tp, _Tp, bool>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(greater);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS greater<void>
{
Expand All @@ -518,15 +445,10 @@ struct _LIBCUDACXX_TEMPLATE_VIS greater<void>
}
typedef void is_transparent;
};
#endif

// Logical operations

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
Expand All @@ -538,7 +460,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_and : __binary_function<_Tp, _Tp, bool>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_and);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS logical_and<void>
{
Expand All @@ -552,13 +473,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_and<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool>
{
typedef bool __result_type; // used by valarray
Expand All @@ -570,7 +486,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_not : __unary_function<_Tp, bool>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_not);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS logical_not<void>
{
Expand All @@ -583,13 +498,8 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_not<void>
}
typedef void is_transparent;
};
#endif

#if _CCCL_STD_VER > 2011
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCUDACXX_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool>
{
typedef bool __result_type; // used by valarray
Expand All @@ -601,7 +511,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_or : __binary_function<_Tp, _Tp, bool>
};
_LIBCUDACXX_CTAD_SUPPORTED_FOR_TYPE(logical_or);

#if _CCCL_STD_VER > 2011
template <>
struct _LIBCUDACXX_TEMPLATE_VIS logical_or<void>
{
Expand All @@ -615,7 +524,6 @@ struct _LIBCUDACXX_TEMPLATE_VIS logical_or<void>
}
typedef void is_transparent;
};
#endif

_LIBCUDACXX_END_NAMESPACE_STD

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ int main(int, char**)
static_assert((cuda::std::is_same<int, F::result_type>::value), "");
#endif
assert(f(36, 4) == 9);
#if TEST_STD_VER > 2011
typedef cuda::std::divides<> F2;
const F2 f2 = F2();
assert(f2(36, 4) == 9);
Expand All @@ -59,7 +58,6 @@ int main(int, char**)

constexpr double bar = cuda::std::divides<>()(3.0, 2);
static_assert(bar == 1.5, ""); // exact in binary
#endif

return 0;
}
Loading

0 comments on commit 6fbd21d

Please sign in to comment.