Skip to content

Commit

Permalink
Cleanup our __cccl_config (#1322)
Browse files Browse the repository at this point in the history
We want to consolidate our configuration and keep it maintainable. Consequently put the different functionality into individual headers
  • Loading branch information
miscco authored Feb 8, 2024
1 parent 5288c38 commit fa1c1d2
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ set(files
__bsd_locale_fallbacks.h
__errc
__cccl_config
__cccl/compiler.h
__cccl/diagnostic.h
__cccl/dialect.h
__cccl/execution_space.h
__cccl/system_header.h
__cccl/version.h
__cccl/visibility.h
__concepts/__concept_macros.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef __CCCL_COMPILER_H
#define __CCCL_COMPILER_H

// Determine the host compiler
#if defined(__INTEL_LLVM_COMPILER)
# define _CCCL_COMPILER_ICC_LLVM
#elif defined(__INTEL_COMPILER)
# define _CCCL_COMPILER_ICC
#elif defined(__NVCOMPILER)
# define _CCCL_COMPILER_NVHPC
#elif defined(__clang__)
# define _CCCL_COMPILER_CLANG
#elif defined(__GNUC__)
# define _CCCL_COMPILER_GCC
#elif defined(_MSC_VER)
# define _CCCL_COMPILER_MSVC
#elif defined(__IBMCPP__)
# define _CCCL_COMPILER_IBM
#elif defined(__CUDACC_RTC__)
# define _CCCL_COMPILER_NVRTC
#endif

// Convenient shortcut to determine which version of MSVC we are dealing with
#if defined(_CCCL_COMPILER_MSVC)
# if _MSC_VER < 1920
# define _CCCL_COMPILER_MSVC_2017
# elif _MSC_VER < 1930
# define _CCCL_COMPILER_MSVC_2019
# else // _MSC_VER < 1940
# define _CCCL_COMPILER_MSVC_2022
# endif // _MSC_VER < 1940
#endif // _CCCL_COMPILER_MSVC

// Determine the cuda compiler
#if defined(__NVCC__)
# define _CCCL_CUDA_COMPILER_NVCC
#elif defined(_NVHPC_CUDA)
# define _CCCL_CUDA_COMPILER_NVHPC
#elif defined(__CUDA__) && defined(_CCCL_COMPILER_CLANG)
# define _CCCL_CUDA_COMPILER_CLANG
#endif

// Shorthand to check whether there is a cuda compiler available
#if defined(_CCCL_CUDA_COMPILER_NVCC) || defined(_CCCL_CUDA_COMPILER_NVHPC) || defined(_CCCL_CUDA_COMPILER_CLANG) \
|| defined(_CCCL_COMPILER_NVRTC)
# define _CCCL_CUDA_COMPILER
#endif // cuda compiler available

#endif // __CCCL_COMPILER_H
123 changes: 123 additions & 0 deletions libcudacxx/include/cuda/std/detail/libcxx/include/__cccl/diagnostic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef __CCCL_DIAGNOSTIC_H
#define __CCCL_DIAGNOSTIC_H

#include "../__cccl/compiler.h"
#include "../__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

// Enable us to selectively silence host compiler warnings
#define _CCCL_TOSTRING2(_STR) #_STR
#define _CCCL_TOSTRING(_STR) _CCCL_TOSTRING2(_STR)
#ifdef _CCCL_COMPILER_CLANG
# define _CCCL_DIAG_PUSH _Pragma("clang diagnostic push")
# define _CCCL_DIAG_POP _Pragma("clang diagnostic pop")
# define _CCCL_DIAG_SUPPRESS_CLANG(str) _Pragma(_CCCL_TOSTRING(clang diagnostic ignored str))
# define _CCCL_DIAG_SUPPRESS_GCC(str)
# define _CCCL_DIAG_SUPPRESS_NVHPC(str)
# define _CCCL_DIAG_SUPPRESS_MSVC(str)
#elif defined(_CCCL_COMPILER_GCC)
# define _CCCL_DIAG_PUSH _Pragma("GCC diagnostic push")
# define _CCCL_DIAG_POP _Pragma("GCC diagnostic pop")
# define _CCCL_DIAG_SUPPRESS_CLANG(str)
# define _CCCL_DIAG_SUPPRESS_GCC(str) _Pragma(_CCCL_TOSTRING(GCC diagnostic ignored str))
# define _CCCL_DIAG_SUPPRESS_NVHPC(str)
# define _CCCL_DIAG_SUPPRESS_MSVC(str)
#elif defined(_CCCL_COMPILER_NVHPC)
# define _CCCL_DIAG_PUSH _Pragma("diagnostic push")
# define _CCCL_DIAG_POP _Pragma("diagnostic pop")
# define _CCCL_DIAG_SUPPRESS_CLANG(str)
# define _CCCL_DIAG_SUPPRESS_GCC(str)
# define _CCCL_DIAG_SUPPRESS_NVHPC(str) _Pragma(_CCCL_TOSTRING(diag_suppress str))
# define _CCCL_DIAG_SUPPRESS_MSVC(str)
#elif defined(_CCCL_COMPILER_MSVC)
# define _CCCL_DIAG_PUSH __pragma(warning(push))
# define _CCCL_DIAG_POP __pragma(warning(pop))
# define _CCCL_DIAG_SUPPRESS_CLANG(str)
# define _CCCL_DIAG_SUPPRESS_GCC(str)
# define _CCCL_DIAG_SUPPRESS_NVHPC(str)
# define _CCCL_DIAG_SUPPRESS_MSVC(str) __pragma(warning(disable : str))
#else
# define _CCCL_DIAG_PUSH
# define _CCCL_DIAG_POP
# define _CCCL_DIAG_SUPPRESS_CLANG(str)
# define _CCCL_DIAG_SUPPRESS_GCC(str)
# define _CCCL_DIAG_SUPPRESS_NVHPC(str)
# define _CCCL_DIAG_SUPPRESS_MSVC(str)
#endif

// Convenient shortcuts to silence common warnings
#if defined(_CCCL_COMPILER_CLANG)
# define _CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH \
_CCCL_DIAG_PUSH \
_CCCL_DIAG_SUPPRESS_CLANG("-Wdeprecated") \
_CCCL_DIAG_SUPPRESS_CLANG("-Wdeprecated-declarations")
# define _CCCL_DIAG_SUPPRESS_DEPRECATED_POP _CCCL_DIAG_POP
#elif defined(_CCCL_COMPILER_GCC)
# define _CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH \
_CCCL_DIAG_PUSH \
_CCCL_DIAG_SUPPRESS_GCC("-Wdeprecated") \
_CCCL_DIAG_SUPPRESS_GCC("-Wdeprecated-declarations")
# define _CCCL_DIAG_SUPPRESS_DEPRECATED_POP _CCCL_DIAG_POP
#elif defined(_CCCL_COMPILER_MSVC)
# define _CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH \
_CCCL_DIAG_PUSH \
_CCCL_DIAG_SUPPRESS_MSVC(4996)
# define _CCCL_DIAG_SUPPRESS_DEPRECATED_POP _CCCL_DIAG_POP
#else // !_CCCL_COMPILER_CLANG && !_CCCL_COMPILER_GCC
# define _CCCL_DIAG_SUPPRESS_DEPRECATED_PUSH
# define _CCCL_DIAG_SUPPRESS_DEPRECATED_POP
#endif // !_CCCL_COMPILER_CLANG && !_CCCL_COMPILER_GCC

// Enable us to selectively silence cuda compiler warnings
#if defined(_CCCL_CUDA_COMPILER)
# if defined(_CCCL_CUDA_COMPILER_CLANG)
# define _CCCL_NV_DIAG_SUPPRESS(_WARNING)
# define _CCCL_NV_DIAG_DEFAULT(_WARNING)
# elif defined(__NVCC_DIAG_PRAGMA_SUPPORT__)
# if defined(_CCCL_COMPILER_MSVC)
# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) __pragma(_CCCL_TOSTRING(nv_diag_suppress _WARNING))
# define _CCCL_NV_DIAG_DEFAULT(_WARNING) __pragma(_CCCL_TOSTRING(nv_diag_default _WARNING))
# else // ^^^ _CCCL_COMPILER_MSVC ^^^ / vvv !_CCCL_COMPILER_MSVC vvv
# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) \
_Pragma(_CCCL_TOSTRING(nv_diagnostic push)) _Pragma(_CCCL_TOSTRING(nv_diag_suppress _WARNING))
# define _CCCL_NV_DIAG_DEFAULT(_WARNING) _Pragma(_CCCL_TOSTRING(nv_diagnostic pop))
# endif // !_CCCL_COMPILER_MSVC
# elif defined(_CCCL_COMPILER_NVHPC)
# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) \
_Pragma(_CCCL_TOSTRING(diagnostic push)) _Pragma(_CCCL_TOSTRING(diag_suppress _WARNING))
# define _CCCL_NV_DIAG_DEFAULT(_WARNING) _Pragma(_CCCL_TOSTRING(diagnostic pop))
# else // ^^^ __NVCC_DIAG_PRAGMA_SUPPORT__ ^^^ / vvv !__NVCC_DIAG_PRAGMA_SUPPORT__ vvv
# if defined(_CCCL_COMPILER_MSVC_2017) // MSVC 2017 has issues with restoring the warning
# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) __pragma(_CCCL_TOSTRING(diag_suppress _WARNING))
# define _CCCL_NV_DIAG_DEFAULT(_WARNING)
# elif defined(_CCCL_COMPILER_MSVC)
# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) __pragma(_CCCL_TOSTRING(diag_suppress _WARNING))
# define _CCCL_NV_DIAG_DEFAULT(_WARNING) __pragma(_CCCL_TOSTRING(diag_default _WARNING))
# else // ^^^ _CCCL_COMPILER_MSVC ^^^ / vvv !_CCCL_COMPILER_MSVC vvv
# define _CCCL_NV_DIAG_SUPPRESS(_WARNING) _Pragma(_CCCL_TOSTRING(diag_suppress _WARNING))
# define _CCCL_NV_DIAG_DEFAULT(_WARNING) _Pragma(_CCCL_TOSTRING(diag_default _WARNING))
# endif // !_CCCL_COMPILER_MSVC
# endif // !__NVCC_DIAG_PRAGMA_SUPPORT__
#else // ^^^ _CCCL_CUDA_COMPILER ^^^ / vvv !_CCCL_CUDA_COMPILER vvv
# define _CCCL_NV_DIAG_SUPPRESS(_WARNING)
# define _CCCL_NV_DIAG_DEFAULT(_WARNING)
#endif // other compilers

#endif // __CCCL_DIAGNOSTIC_H
11 changes: 11 additions & 0 deletions libcudacxx/include/cuda/std/detail/libcxx/include/__cccl/dialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
#ifndef __CCCL_DIALECT_H
#define __CCCL_DIALECT_H

#include "../__cccl/compiler.h"
#include "../__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

#if defined(_CCCL_COMPILER_MSVC)
# if _MSVC_LANG <= 201103L
# define _CCCL_STD_VER 2011
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@
#ifndef __CCCL_EXECUTION_SPACE_H
#define __CCCL_EXECUTION_SPACE_H

#if defined(__CUDACC__) || defined(_NVHPC_CUDA)
# define _CCCL_HOST __host__
# define _CCCL_DEVICE __device__
# define _CCCL_HOST_DEVICE __host__ __device__
#include "../__cccl/compiler.h"
#include "../__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

#if defined(_CCCL_CUDA_COMPILER)
# define _CCCL_HOST __host__
# define _CCCL_DEVICE __device__
# define _CCCL_HOST_DEVICE __host__ __device__
# define _CCCL_FORCEINLINE __forceinline__
#else // ^^^ __CUDACC__ || _NVHPC_CUDA ^^^ / vvv !__CUDACC__ && !_NVHPC_CUDA
# define _CCCL_HOST
Expand All @@ -24,9 +35,7 @@
#endif // !__CUDACC__ && !_NVHPC_CUDA

#if !defined(_CCCL_EXEC_CHECK_DISABLE)
# if defined(_CCCL_COMPILER_NVRTC) || defined(_CCCL_CUDA_COMPILER_NVHPC) || defined(_CCCL_CUDA_COMPILER_CLANG)
# define _CCCL_EXEC_CHECK_DISABLE
# elif defined(_CCCL_CUDA_COMPILER_NVCC) // defined(_CCCL_CUDA_COMPILER_NVCC)
# if defined(_CCCL_CUDA_COMPILER_NVCC)
# if defined(_CCCL_COMPILER_MSVC)
# define _CCCL_EXEC_CHECK_DISABLE __pragma("nv_exec_check_disable")
# else // ^^^ _CCCL_COMPILER_MSVC ^^^ / vvv !_CCCL_COMPILER_MSVC vvv
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//

#ifndef __CCCL_SYSTEM_HEADER_H
#define __CCCL_SYSTEM_HEADER_H

#include "../__cccl/compiler.h"

// Enforce that cccl headers are treated as system headers
#if defined(_CCCL_COMPILER_GCC) || defined(_CCCL_COMPILER_NVHPC) || defined(_CCCL_COMPILER_ICC) \
|| defined(_CCCL_COMPILER_ICC_LLVM)
# define _CCCL_FORCE_SYSTEM_HEADER_GCC
#elif defined(_CCCL_COMPILER_CLANG)
# define _CCCL_FORCE_SYSTEM_HEADER_CLANG
#elif defined(_CCCL_COMPILER_MSVC)
# define _CCCL_FORCE_SYSTEM_HEADER_MSVC
#endif // other compilers

// Potentially enable that cccl headers are treated as system headers
#if !defined(_CCCL_NO_SYSTEM_HEADER) \
&& !(defined(_CCCL_COMPILER_MSVC) && defined(_LIBCUDACXX_DISABLE_PRAGMA_MSVC_WARNING)) \
&& !defined(_CCCL_COMPILER_NVRTC) && !defined(_LIBCUDACXX_DISABLE_PRAGMA_GCC_SYSTEM_HEADER)
# if defined(_CCCL_COMPILER_GCC) || defined(_CCCL_COMPILER_NVHPC) || defined(_CCCL_COMPILER_ICC) \
|| defined(_CCCL_COMPILER_ICC_LLVM)
# define _CCCL_IMPLICIT_SYSTEM_HEADER_GCC
# elif defined(_CCCL_COMPILER_CLANG)
# define _CCCL_IMPLICIT_SYSTEM_HEADER_CLANG
# elif defined(_CCCL_COMPILER_MSVC)
# define _CCCL_IMPLICIT_SYSTEM_HEADER_MSVC
# endif // other compilers
#endif // Use system header

#endif // __CCCL_SYSTEM_HEADER_H
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#error "<__cccl/visibility.h> should only be included in from <cuda/__cccl_config>"
#endif // __CCCL_CONFIG

#include "../__cccl/compiler.h"
#include "../__cccl/system_header.h"

// We want to ensure that all warning emmiting from this header are supressed
#if defined(_CCCL_FORCE_SYSTEM_HEADER_GCC)
# pragma GCC system_header
Expand Down
Loading

0 comments on commit fa1c1d2

Please sign in to comment.