Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libcudacxx/include/cuda/__cccl_config
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <cuda/std/__cccl/exceptions.h> // IWYU pragma: export
#include <cuda/std/__cccl/execution_space.h> // IWYU pragma: export
#include <cuda/std/__cccl/extended_data_types.h> // IWYU pragma: export
#include <cuda/std/__cccl/host_std_lib.h> // IWYU pragma: export
#include <cuda/std/__cccl/os.h> // IWYU pragma: export
#include <cuda/std/__cccl/preprocessor.h> // IWYU pragma: export
#include <cuda/std/__cccl/ptx_isa.h> // IWYU pragma: export
Expand Down
4 changes: 0 additions & 4 deletions libcudacxx/include/cuda/__complex/get_real_imag.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
#include <cuda/__fwd/complex.h>
#include <cuda/std/__fwd/complex.h>

#if !_CCCL_COMPILER(NVRTC)
# include <complex>
#endif // !_CCCL_COMPILER(NVRTC)

#include <cuda/std/__cccl/prologue.h>

_CCCL_BEGIN_NAMESPACE_CUDA
Expand Down
95 changes: 46 additions & 49 deletions libcudacxx/include/cuda/std/__cccl/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <cuda/std/__cccl/attributes.h>
#include <cuda/std/__cccl/extended_data_types.h>
#include <cuda/std/__cccl/host_std_lib.h>

//! This file consolidates all compiler builtin detection for CCCL.
//!
Expand Down Expand Up @@ -607,55 +608,51 @@
# define _CCCL_BUILTIN_STRLEN(...) __builtin_strlen(__VA_ARGS__)
#endif

// Some compilers provide std::move/std::forward/etc as builtins
#if defined(__cplusplus)
// Bring in the feature test macros (needed for std::forward_like)
# if _CCCL_HAS_INCLUDE(<version>) // <version> should be the smallest include possible
# include <version>
# elif !_CCCL_COMPILER(NVRTC)
# include <ciso646> // otherwise go for the smallest possible header
# endif // !_CCCL_COMPILER(NVRTC)

// Bring in the bits of the STL we need
# if defined(_GLIBCXX_VERSION)
# include <bits/move.h> // for move, forward, forward_like, and addressof
# elif defined(_LIBCPP_VERSION)
# include <__memory/addressof.h>
# include <__utility/as_const.h>
# include <__utility/forward.h>
# include <__utility/forward_like.h>
# include <__utility/move.h>
# endif

# if defined(_GLIBCXX_VERSION) || defined(_LIBCPP_VERSION)
// std::move builtin
# if _CCCL_COMPILER(CLANG, >=, 15) || _CCCL_COMPILER(GCC, >=, 15)
# define _CCCL_HAS_BUILTIN_STD_MOVE() 1
# endif

// std::forward builtin
# if _CCCL_COMPILER(CLANG, >=, 15) || _CCCL_COMPILER(GCC, >=, 15)
# define _CCCL_HAS_BUILTIN_STD_FORWARD() 1
# endif

// std::addressof builtin
# if _CCCL_COMPILER(CLANG, >=, 15) || _CCCL_COMPILER(GCC, >=, 15)
# define _CCCL_HAS_BUILTIN_STD_ADDRESSOF() 1
# endif

// std::as_const builtin
# if _CCCL_COMPILER(CLANG, >=, 15)
# define _CCCL_HAS_BUILTIN_STD_AS_CONST() 1
# endif

// std::forward_like builtin
// Leaving out MSVC for now because it is hard for forward-declare std::forward_like.
# if (_CCCL_COMPILER(CLANG, >=, 17) || _CCCL_COMPILER(GCC, >=, 15)) && defined(__cpp_lib_forward_like) \
&& (__cpp_lib_forward_like >= 202217L)
# define _CCCL_HAS_BUILTIN_STD_FORWARD_LIKE() 1
# endif
# endif // defined(_GLIBCXX_VERSION) || defined(_LIBCPP_VERSION) || defined(_MSVC_STL_VERSION)
#endif // defined(__cplusplus)
// todo: re-enable std builtins
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were not working anyway, so I'd like to leave this for a different PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to know what is not woorking. Generally I would just replace the host STL detection and leave the rest in


// // Some compilers provide std::move/std::forward/etc as builtins
// #if defined(__cplusplus)
// // Bring in the bits of the STL we need
// # if _CCCL_HOST_STD_LIB(LIBSTDCXX)
// # include <bits/move.h> // for move, forward, forward_like, and addressof
// # elif _CCCL_HOST_STD_LIB(LIBCXX)
// # include <__memory/addressof.h>
// # include <__utility/as_const.h>
// # include <__utility/forward.h>
// # if __cpp_lib_forward_like >= 202217L
// # include <__utility/forward_like.h>
// # endif // __cpp_lib_forward_like >= 202217L
// # include <__utility/move.h>
// # endif

// # if _CCCL_HOST_STD_LIB(LIBSTDCXX) || _CCCL_HOST_STD_LIB(LIBCXX)
// // std::move builtin
// # if _CCCL_COMPILER(CLANG, >=, 15) || _CCCL_COMPILER(GCC, >=, 15)
// # define _CCCL_HAS_BUILTIN_STD_MOVE() 1
// # endif

// // std::forward builtin
// # if _CCCL_COMPILER(CLANG, >=, 15) || _CCCL_COMPILER(GCC, >=, 15)
// # define _CCCL_HAS_BUILTIN_STD_FORWARD() 1
// # endif

// // std::addressof builtin
// # if _CCCL_COMPILER(CLANG, >=, 15) || _CCCL_COMPILER(GCC, >=, 15)
// # define _CCCL_HAS_BUILTIN_STD_ADDRESSOF() 1
// # endif

// // std::as_const builtin
// # if _CCCL_COMPILER(CLANG, >=, 15)
// # define _CCCL_HAS_BUILTIN_STD_AS_CONST() 1
// # endif

// // std::forward_like builtin
// // Leaving out MSVC for now because it is hard for forward-declare std::forward_like.
// # if (_CCCL_COMPILER(CLANG, >=, 17) || _CCCL_COMPILER(GCC, >=, 15)) && __cpp_lib_forward_like >= 202217L
// # define _CCCL_HAS_BUILTIN_STD_FORWARD_LIKE() 1
// # endif
// # endif // _CCCL_HOST_STD_LIB(LIBSTDCXX) || _CCCL_HOST_STD_LIB(LIBCXX)
// #endif // defined(__cplusplus)

#ifndef _CCCL_HAS_BUILTIN_STD_MOVE
# define _CCCL_HAS_BUILTIN_STD_MOVE() 0
Expand Down
52 changes: 52 additions & 0 deletions libcudacxx/include/cuda/std/__cccl/host_std_lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// Part of libcu++, the C++ Standard Library for your entire system,
// 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) 2025 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef __CCCL_HOST_STD_LIB_H
#define __CCCL_HOST_STD_LIB_H

#include <cuda/std/__cccl/compiler.h>
#include <cuda/std/__cccl/preprocessor.h>
#include <cuda/std/__cccl/system_header.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

#define _CCCL_HOST_STD_LIB_LIBSTDCXX() 0
#define _CCCL_HOST_STD_LIB_LIBCXX() 0
#define _CCCL_HOST_STD_LIB_STL() 0

// include a minimal header
#if _CCCL_HAS_INCLUDE(<version>)
# include <version>
#elif _CCCL_HAS_INCLUDE(<ciso646>)
# include <ciso646>
#endif // ^^^ _CCCL_HAS_INCLUDE(<ciso646>) ^^^

#if defined(_MSVC_STL_VERSION)
# undef _CCCL_HOST_STD_LIB_STL
# define _CCCL_HOST_STD_LIB_STL() 1
#elif defined(__GLIBCXX__)
# undef _CCCL_HOST_STD_LIB_LIBSTDCXX
# define _CCCL_HOST_STD_LIB_LIBSTDCXX() 1
#elif defined(_LIBCPP_VERSION)
# undef _CCCL_HOST_STD_LIB_LIBCXX
# define _CCCL_HOST_STD_LIB_LIBCXX() 1
#endif // ^^^ _LIBCPP_VERSION ^^^

#define _CCCL_HOST_STD_LIB(_X) _CCCL_HOST_STD_LIB_##_X()
#define _CCCL_HAS_HOST_STD_LIB() \
(_CCCL_HOST_STD_LIB_LIBSTDCXX() || _CCCL_HOST_STD_LIB_LIBCXX() || _CCCL_HOST_STD_LIB_STL())

#endif // __CCCL_HOST_STD_LIB_H
5 changes: 3 additions & 2 deletions libcudacxx/include/cuda/std/__complex/complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <cuda/std/__complex/vector_support.h>
#include <cuda/std/__concepts/concept_macros.h>
#include <cuda/std/__fwd/complex.h>
#include <cuda/std/__fwd/get.h>
#include <cuda/std/__tuple_dir/tuple_element.h>
#include <cuda/std/__tuple_dir/tuple_size.h>
Expand All @@ -36,9 +37,9 @@
#include <cuda/std/limits>

// Compatibility helpers for thrust to convert between `std::complex` and `cuda::std::complex`
// todo: find a way to get rid of this include
#if !_CCCL_COMPILER(NVRTC)
# include <complex>
# include <sstream> // for std::basic_ostringstream
# include <complex> // for std::complex stream operators

# define _LIBCUDACXX_ACCESS_STD_COMPLEX_REAL(__c) reinterpret_cast<const _Up(&)[2]>(__c)[0]
# define _LIBCUDACXX_ACCESS_STD_COMPLEX_IMAG(__c) reinterpret_cast<const _Up(&)[2]>(__c)[1]
Expand Down
3 changes: 2 additions & 1 deletion libcudacxx/include/cuda/std/__complex/nvbf16.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
# include <cuda/std/__type_traits/enable_if.h>
# include <cuda/std/__type_traits/is_constructible.h>

// todo: find a way to get rid of this include
# if !_CCCL_COMPILER(NVRTC)
# include <sstream> // for std::basic_ostringstream
# include <complex> // for std::complex stream operators
# endif // !_CCCL_COMPILER(NVRTC)

# include <cuda/std/__cccl/prologue.h>
Expand Down
7 changes: 4 additions & 3 deletions libcudacxx/include/cuda/std/__complex/nvfp16.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
# include <cuda/std/__type_traits/enable_if.h>
# include <cuda/std/__type_traits/is_constructible.h>

// todo: find a way to get rid of this include
# if !_CCCL_COMPILER(NVRTC)
# include <sstream> // for std::basic_ostringstream
# include <complex> // for std::complex stream operators
# endif // !_CCCL_COMPILER(NVRTC)

# include <cuda/std/__cccl/prologue.h>
Expand Down Expand Up @@ -294,7 +295,7 @@ struct __get_complex_impl<__half>
}
};

# if !defined(_LIBCUDACXX_HAS_NO_LOCALIZATION) && !_CCCL_COMPILER(NVRTC)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is never defined

# if !_CCCL_COMPILER(NVRTC)
template <class _CharT, class _Traits>
::std::basic_istream<_CharT, _Traits>& operator>>(::std::basic_istream<_CharT, _Traits>& __is, complex<__half>& __x)
{
Expand All @@ -310,7 +311,7 @@ operator<<(::std::basic_ostream<_CharT, _Traits>& __os, const complex<__half>& _
{
return __os << complex<float>{__x};
}
# endif // !_LIBCUDACXX_HAS_NO_LOCALIZATION && !_CCCL_COMPILER(NVRTC)
# endif // !_CCCL_COMPILER(NVRTC)

_CCCL_END_NAMESPACE_CUDA_STD

Expand Down
13 changes: 13 additions & 0 deletions libcudacxx/include/cuda/std/__fwd/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@

#include <cuda/std/__cccl/prologue.h>

// std:: forward declarations

#if _CCCL_HAS_HOST_STD_LIB()
_CCCL_BEGIN_NAMESPACE_STD

template <class _Tp>
class allocator;

_CCCL_END_NAMESPACE_STD
#endif // _CCCL_HAS_HOST_STD_LIB()

// cuda::std:: forward declarations

_CCCL_BEGIN_NAMESPACE_CUDA_STD

template <class _Tp>
Expand Down
13 changes: 13 additions & 0 deletions libcudacxx/include/cuda/std/__fwd/char_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@

#include <cuda/std/__cccl/prologue.h>

// std:: forward declarations

#if _CCCL_HAS_HOST_STD_LIB()
_CCCL_BEGIN_NAMESPACE_STD

template <class _CharT>
struct char_traits;

_CCCL_END_NAMESPACE_STD
#endif // _CCCL_HAS_HOST_STD_LIB()

// cuda::std:: forward declarations

_CCCL_BEGIN_NAMESPACE_CUDA_STD

template <class _CharT>
Expand Down
17 changes: 13 additions & 4 deletions libcudacxx/include/cuda/std/__fwd/complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@
# pragma system_header
#endif // no system header

#if !_CCCL_COMPILER(NVRTC)
# include <complex>
#endif // !_CCCL_COMPILER(NVRTC)

#include <cuda/std/__cccl/prologue.h>

// std:: forward declarations

#if _CCCL_HAS_HOST_STD_LIB()
_CCCL_BEGIN_NAMESPACE_STD

template <class>
class complex;

_CCCL_END_NAMESPACE_STD
#endif // _CCCL_HAS_HOST_STD_LIB()

// cuda::std:: forward declarations

_CCCL_BEGIN_NAMESPACE_CUDA_STD

template <class _Tp>
Expand Down
13 changes: 13 additions & 0 deletions libcudacxx/include/cuda/std/__fwd/pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@

#include <cuda/std/__cccl/prologue.h>

// std:: forward declarations

#if _CCCL_HAS_HOST_STD_LIB()
_CCCL_BEGIN_NAMESPACE_STD

template <class, class>
struct pair;

_CCCL_END_NAMESPACE_STD
#endif // _CCCL_HAS_HOST_STD_LIB()

// cuda::std:: forward declarations

_CCCL_BEGIN_NAMESPACE_CUDA_STD

template <class, class>
Expand Down
22 changes: 22 additions & 0 deletions libcudacxx/include/cuda/std/__fwd/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@

#include <cuda/std/__cccl/prologue.h>

// std:: forward declarations

#if _CCCL_HAS_HOST_STD_LIB()
_CCCL_BEGIN_NAMESPACE_STD

// libstdc++ puts basic_string to inline cxx11 namespace
# if _GLIBCXX_USE_CXX11_ABI
inline _GLIBCXX_BEGIN_NAMESPACE_CXX11
# endif // _GLIBCXX_USE_CXX11_ABI

template <class _CharT, class _Traits, class _Alloc>
class basic_string;

# if _GLIBCXX_USE_CXX11_ABI
_GLIBCXX_END_NAMESPACE_CXX11
# endif // _GLIBCXX_USE_CXX11_ABI

_CCCL_END_NAMESPACE_STD
#endif // _CCCL_HAS_HOST_STD_LIB()

// cuda::std:: forward declarations

_CCCL_BEGIN_NAMESPACE_CUDA_STD

#if 0 // we don't support these features
Expand Down
14 changes: 14 additions & 0 deletions libcudacxx/include/cuda/std/__fwd/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@

#include <cuda/std/__cccl/prologue.h>

// std:: forward declarations

#if _CCCL_HAS_HOST_STD_LIB() && __cpp_lib_string_view >= 201606L
_CCCL_BEGIN_NAMESPACE_STD

template <class _CharT, class _Traits>
class basic_string_view;

_CCCL_END_NAMESPACE_STD
#endif // _CCCL_HAS_HOST_STD_LIB() && __cpp_lib_string_view >= 201606L

// cuda::std:: forward declarations

_CCCL_BEGIN_NAMESPACE_CUDA_STD

template <class _CharT, class _Traits = char_traits<_CharT>>
Expand Down Expand Up @@ -52,6 +65,7 @@ _CCCL_PREFERRED_NAME(wstring_view)
#endif // _CCCL_HAS_WCHAR_T()
basic_string_view;
// clang-format on

_CCCL_END_NAMESPACE_CUDA_STD

#include <cuda/std/__cccl/epilogue.h>
Expand Down
Loading