-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move `std::copy` to its own file * Move `std::copy_backward` to its own file * Move `std::copy_if` to its own file * Move `std::copy_n` to its own file * Move `std::move` to its own file * Move `std::move_backward` to its own file * Move `std::transform` to its own file * Move `std::replace` to its own file * Move `std::replace_if` to its own file * Move `std::replace_copy` to its own file * Move `std::replace_copy_if` to its own file * Move `std::generate` to its own file * Move `std::generate_n` to its own file * Move `std::remove` to its own file * Move `std::remove_if` to its own file * Move `std::remove_copy` to its own file * Move `std::remove_copy_if` to its own file
- Loading branch information
Showing
39 changed files
with
3,182 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
libcudacxx/include/cuda/std/detail/libcxx/include/__algorithm/copy.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCUDACXX___ALGORITHM_COPY_H | ||
#define _LIBCUDACXX___ALGORITHM_COPY_H | ||
|
||
#ifndef __cuda_std__ | ||
# include <__config> | ||
#endif // __cuda_std__ | ||
|
||
#include "../__algorithm/unwrap_iter.h" | ||
#include "../__type_traits/enable_if.h" | ||
#include "../__type_traits/is_constant_evaluated.h" | ||
#include "../__type_traits/is_same.h" | ||
#include "../__type_traits/is_trivially_copy_assignable.h" | ||
#include "../__type_traits/remove_const.h" | ||
#include "../cstdlib" | ||
#include "../cstring" | ||
|
||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) | ||
# pragma GCC system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) | ||
# pragma clang system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) | ||
# pragma system_header | ||
#endif // no system header | ||
|
||
_LIBCUDACXX_BEGIN_NAMESPACE_STD | ||
|
||
template <class _InputIterator, class _OutputIterator> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _OutputIterator | ||
__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) | ||
{ | ||
for (; __first != __last; ++__first, (void) ++__result) | ||
{ | ||
*__result = *__first; | ||
} | ||
return __result; | ||
} | ||
|
||
template <class _Tp, class _Up> | ||
inline _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 bool | ||
__dispatch_memmove(_Up* __result, _Tp* __first, const size_t __n) | ||
{ | ||
#if _LIBCUDACXX_STD_VER >= 20 | ||
if (_CUDA_VSTD::is_constant_evaluated()) | ||
{ | ||
return false; | ||
} | ||
else | ||
#endif // _LIBCUDACXX_STD_VER >= 20 | ||
{ | ||
// For now, we only ever use memmove on host | ||
// clang-format off | ||
NV_IF_ELSE_TARGET(NV_IS_HOST, ( | ||
_CUDA_VSTD::memmove(__result, __first, __n * sizeof(_Up)); | ||
return true; | ||
),( | ||
return false; | ||
)) | ||
// clang-format on | ||
} | ||
} | ||
|
||
template <class _Tp, | ||
class _Up, | ||
__enable_if_t<_LIBCUDACXX_TRAIT(is_same, __remove_const_t<_Tp>, _Up), int> = 0, | ||
__enable_if_t<_LIBCUDACXX_TRAIT(is_trivially_copy_assignable, _Up), int> = 0> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 _Up* | ||
__copy(_Tp* __first, _Tp* __last, _Up* __result) | ||
{ | ||
const ptrdiff_t __n = __last - __first; | ||
if (__n > 0) | ||
{ | ||
if (__dispatch_memmove(__result, __first, __n)) | ||
{ | ||
return __result + __n; | ||
} | ||
for (ptrdiff_t __i = 0; __i < __n; ++__i) | ||
{ | ||
*(__result + __i) = *(__first + __i); | ||
} | ||
} | ||
return __result + __n; | ||
} | ||
|
||
template <class _InputIterator, class _OutputIterator> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 _OutputIterator | ||
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) | ||
{ | ||
return _CUDA_VSTD::__copy(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); | ||
} | ||
|
||
_LIBCUDACXX_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCUDACXX___ALGORITHM_COPY_H |
76 changes: 76 additions & 0 deletions
76
libcudacxx/include/cuda/std/detail/libcxx/include/__algorithm/copy_backward.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCUDACXX___ALGORITHM_COPY_BACKWARD_H | ||
#define _LIBCUDACXX___ALGORITHM_COPY_BACKWARD_H | ||
|
||
#ifndef __cuda_std__ | ||
# include <__config> | ||
#endif // __cuda_std__ | ||
|
||
#include "../__algorithm/copy.h" | ||
#include "../__algorithm/unwrap_iter.h" | ||
#include "../__type_traits/enable_if.h" | ||
#include "../__type_traits/is_same.h" | ||
#include "../__type_traits/is_trivially_copy_assignable.h" | ||
#include "../__type_traits/remove_const.h" | ||
|
||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) | ||
# pragma GCC system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) | ||
# pragma clang system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) | ||
# pragma system_header | ||
#endif // no system header | ||
|
||
_LIBCUDACXX_BEGIN_NAMESPACE_STD | ||
|
||
template <class _BidirectionalIterator, class _OutputIterator> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _OutputIterator | ||
__copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) | ||
{ | ||
while (__first != __last) | ||
{ | ||
*--__result = *--__last; | ||
} | ||
return __result; | ||
} | ||
|
||
template <class _Tp, | ||
class _Up, | ||
__enable_if_t<_LIBCUDACXX_TRAIT(is_same, __remove_const_t<_Tp>, _Up), int> = 0, | ||
__enable_if_t<_LIBCUDACXX_TRAIT(is_trivially_copy_assignable, _Up), int> = 0> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 _Up* | ||
__copy_backward(_Tp* __first, _Tp* __last, _Up* __result) | ||
{ | ||
const ptrdiff_t __n = __last - __first; | ||
if (__n > 0) | ||
{ | ||
if (__dispatch_memmove(__result - __n, __first, __n)) | ||
{ | ||
return __result - __n; | ||
} | ||
for (ptrdiff_t __i = 1; __i <= __n; ++__i) | ||
{ | ||
*(__result - __i) = *(__last - __i); | ||
} | ||
} | ||
return __result - __n; | ||
} | ||
|
||
template <class _BidirectionalIterator1, class _BidirectionalIterator2> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator2 | ||
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last, _BidirectionalIterator2 __result) | ||
{ | ||
return _CUDA_VSTD::__copy_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result)); | ||
} | ||
|
||
_LIBCUDACXX_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCUDACXX___ALGORITHM_COPY_BACKWARD_H |
45 changes: 45 additions & 0 deletions
45
libcudacxx/include/cuda/std/detail/libcxx/include/__algorithm/copy_if.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCUDACXX___ALGORITHM_COPY_IF_H | ||
#define _LIBCUDACXX___ALGORITHM_COPY_IF_H | ||
|
||
#ifndef __cuda_std__ | ||
# include <__config> | ||
#endif // __cuda_std__ | ||
|
||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) | ||
# pragma GCC system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) | ||
# pragma clang system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) | ||
# pragma system_header | ||
#endif // no system header | ||
|
||
_LIBCUDACXX_BEGIN_NAMESPACE_STD | ||
|
||
template<class _InputIterator, class _OutputIterator, class _Predicate> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _OutputIterator | ||
copy_if(_InputIterator __first, _InputIterator __last, | ||
_OutputIterator __result, _Predicate __pred) | ||
{ | ||
for (; __first != __last; ++__first) | ||
{ | ||
if (__pred(*__first)) | ||
{ | ||
*__result = *__first; | ||
++__result; | ||
} | ||
} | ||
return __result; | ||
} | ||
|
||
_LIBCUDACXX_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCUDACXX___ALGORITHM_COPY_IF_H |
70 changes: 70 additions & 0 deletions
70
libcudacxx/include/cuda/std/detail/libcxx/include/__algorithm/copy_n.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCUDACXX___ALGORITHM_COPY_N_H | ||
#define _LIBCUDACXX___ALGORITHM_COPY_N_H | ||
|
||
#ifndef __cuda_std__ | ||
# include <__config> | ||
#endif // __cuda_std__ | ||
|
||
#include "../__algorithm/copy.h" | ||
#include "../__iterator/iterator_traits.h" | ||
#include "../__type_traits/enable_if.h" | ||
#include "../__utility/convert_to_integral.h" | ||
|
||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) | ||
# pragma GCC system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) | ||
# pragma clang system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) | ||
# pragma system_header | ||
#endif // no system header | ||
|
||
_LIBCUDACXX_BEGIN_NAMESPACE_STD | ||
|
||
template <class _InputIterator, | ||
class _Size, | ||
class _OutputIterator, | ||
__enable_if_t<__is_cpp17_input_iterator<_InputIterator>::value, int> = 0, | ||
__enable_if_t<!__is_cpp17_random_access_iterator<_InputIterator>::value, int> = 0> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 _OutputIterator | ||
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) | ||
{ | ||
using _IntegralSize = decltype(__convert_to_integral(__orig_n)); | ||
_IntegralSize __n = static_cast<_IntegralSize>(__orig_n); | ||
if (__n > 0) | ||
{ | ||
*__result = *__first; | ||
++__result; | ||
for (--__n; __n > 0; --__n) | ||
{ | ||
++__first; | ||
*__result = *__first; | ||
++__result; | ||
} | ||
} | ||
return __result; | ||
} | ||
|
||
template <class _InputIterator, | ||
class _Size, | ||
class _OutputIterator, | ||
__enable_if_t<__is_cpp17_random_access_iterator<_InputIterator>::value, int> = 0> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX17 _OutputIterator | ||
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result) | ||
{ | ||
using _IntegralSize = decltype(__convert_to_integral(__orig_n)); | ||
_IntegralSize __n = static_cast<_IntegralSize>(__orig_n); | ||
return _CUDA_VSTD::copy(__first, __first + __n, __result); | ||
} | ||
|
||
_LIBCUDACXX_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCUDACXX___ALGORITHM_COPY_N_H |
39 changes: 39 additions & 0 deletions
39
libcudacxx/include/cuda/std/detail/libcxx/include/__algorithm/generate.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef _LIBCUDACXX___ALGORITHM_GENERATE_H | ||
#define _LIBCUDACXX___ALGORITHM_GENERATE_H | ||
|
||
#ifndef __cuda_std__ | ||
# include <__config> | ||
#endif // __cuda_std__ | ||
|
||
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC) | ||
# pragma GCC system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG) | ||
# pragma clang system_header | ||
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC) | ||
# pragma system_header | ||
#endif // no system header | ||
|
||
_LIBCUDACXX_BEGIN_NAMESPACE_STD | ||
|
||
template <class _ForwardIterator, class _Generator> | ||
inline _LIBCUDACXX_HIDE_FROM_ABI _LIBCUDACXX_INLINE_VISIBILITY _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 void | ||
generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) | ||
{ | ||
for (; __first != __last; ++__first) | ||
{ | ||
*__first = __gen(); | ||
} | ||
} | ||
|
||
_LIBCUDACXX_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCUDACXX___ALGORITHM_GENERATE_H |
Oops, something went wrong.