From 55413b7f7e7246bd399db352f3191d92cc08fe44 Mon Sep 17 00:00:00 2001 From: fbusato Date: Wed, 29 Jan 2025 12:29:36 -0800 Subject: [PATCH] add float128 again --- .../cuda/std/__cccl/extended_data_types.h | 24 +++++++++- libcudacxx/include/cuda/std/__cccl/os.h | 48 +++++++++++++++++++ .../macros/extended_data_types.fp128.fail.cpp | 23 +++++++++ .../macros/extended_data_types.pass.cpp | 4 ++ .../libcxx/macros/os.compile.pass.cpp | 44 +++++++++++++++++ 5 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 libcudacxx/include/cuda/std/__cccl/os.h create mode 100644 libcudacxx/test/libcudacxx/libcxx/macros/extended_data_types.fp128.fail.cpp create mode 100644 libcudacxx/test/libcudacxx/libcxx/macros/os.compile.pass.cpp diff --git a/libcudacxx/include/cuda/std/__cccl/extended_data_types.h b/libcudacxx/include/cuda/std/__cccl/extended_data_types.h index 573b22d6ea0..034ebc51b5f 100644 --- a/libcudacxx/include/cuda/std/__cccl/extended_data_types.h +++ b/libcudacxx/include/cuda/std/__cccl/extended_data_types.h @@ -23,12 +23,13 @@ #endif // no system header #include +#include #include #if !defined(_CCCL_DISABLE_INT128) -# if _CCCL_COMPILER(NVRTC) && defined(__CUDACC_RTC_INT128__) && (defined(__linux__) || defined(__LP64__)) +# if _CCCL_COMPILER(NVRTC) && defined(__CUDACC_RTC_INT128__) && _CCCL_OS(LINUX) # define _CCCL_HAS_INT128() 1 -# elif defined(__SIZEOF_INT128__) && (defined(__linux__) || defined(__LP64__)) +# elif defined(__SIZEOF_INT128__) && _CCCL_OS(LINUX) # define _CCCL_HAS_INT128() 1 # else # define _CCCL_HAS_INT128() 0 @@ -61,4 +62,23 @@ # define _CCCL_HAS_NVFP8() 0 #endif // !defined(_CCCL_DISABLE_NVFP8_SUPPORT) +#if !defined(_CCCL_DISABLE_FLOAT128) +# if _CCCL_COMPILER(NVRTC) && defined(__CUDACC_RTC_FLOAT128__) && _CCCL_OS(LINUX) +# if !defined(__CUDA_ARCH__) || (defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 1000) +# define _CCCL_HAS_FLOAT128() 1 +# else +# define _CCCL_HAS_FLOAT128() 0 +# endif +// NVC++ support float128 only in host code +# elif (defined(__SIZEOF_FLOAT128__) || defined(__FLOAT128__)) && _CCCL_OS(LINUX) && !_CCCL_CUDA_COMPILER(NVHPC) +# if !defined(__CUDA_ARCH__) || (defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 1000) +# define _CCCL_HAS_FLOAT128() 1 +# else +# define _CCCL_HAS_FLOAT128() 0 +# endif +# else +# define _CCCL_HAS_FLOAT128() 0 +# endif +#endif // !defined(_CCCL_DISABLE_FLOAT128) + #endif // __CCCL_EXTENDED_DATA_TYPES_H diff --git a/libcudacxx/include/cuda/std/__cccl/os.h b/libcudacxx/include/cuda/std/__cccl/os.h new file mode 100644 index 00000000000..a3909f5d755 --- /dev/null +++ b/libcudacxx/include/cuda/std/__cccl/os.h @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// 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_OS_H +#define __CCCL_OS_H + +// The header provides the following macros to determine the host architecture: +// +// _CCCL_OS(WINDOWS) +// _CCCL_OS(LINUX) +// _CCCL_OS(ANDROID) +// _CCCL_OS(QNX) + +// Determine the host compiler and its version +#if defined(_WIN32) || defined(_WIN64) /* _WIN64 for NVRTC */ +# define _CCCL_OS_WINDOWS_() 1 +#else +# define _CCCL_OS_WINDOWS_() 0 +#endif + +#if defined(__linux__) || defined(__LP64__) /* __LP64__ for NVRTC */ +# define _CCCL_OS_LINUX_() 1 +#else +# define _CCCL_OS_LINUX_() 0 +#endif + +#if defined(__ANDROID__) +# define _CCCL_OS_ANDROID_() 1 +#else +# define _CCCL_OS_ANDROID_() 0 +#endif + +#if defined(__QNX__) || defined(__QNXNTO__) +# define _CCCL_OS_QNX_() 1 +#else +# define _CCCL_OS_QNX_() 0 +#endif + +#define _CCCL_OS(...) _CCCL_OS_##__VA_ARGS__##_() + +#endif // __CCCL_OS_H diff --git a/libcudacxx/test/libcudacxx/libcxx/macros/extended_data_types.fp128.fail.cpp b/libcudacxx/test/libcudacxx/libcxx/macros/extended_data_types.fp128.fail.cpp new file mode 100644 index 00000000000..5cebaa96168 --- /dev/null +++ b/libcudacxx/test/libcudacxx/libcxx/macros/extended_data_types.fp128.fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// +#include + +#include "test_macros.h" + +int main(int, char**) +{ +#if !_CCCL_HAS_FLOAT128() + __float128 x4 = __float128(3.14) + __float128(3.14); + unused(x4); +#else + static_assert(false); +#endif + return 0; +} diff --git a/libcudacxx/test/libcudacxx/libcxx/macros/extended_data_types.pass.cpp b/libcudacxx/test/libcudacxx/libcxx/macros/extended_data_types.pass.cpp index e8c770e0074..3b230d8710b 100644 --- a/libcudacxx/test/libcudacxx/libcxx/macros/extended_data_types.pass.cpp +++ b/libcudacxx/test/libcudacxx/libcxx/macros/extended_data_types.pass.cpp @@ -39,6 +39,10 @@ int main(int, char**) #if defined(_CCCL_HAS_NVBF16) auto x4 = __nv_bfloat16(1.0f); unused(x4); +#endif +#if _CCCL_HAS_FLOAT128() + __float128 x5 = __float128(3.14) + __float128(3.14); + unused(x5); #endif return 0; } diff --git a/libcudacxx/test/libcudacxx/libcxx/macros/os.compile.pass.cpp b/libcudacxx/test/libcudacxx/libcxx/macros/os.compile.pass.cpp new file mode 100644 index 00000000000..9bc788526c9 --- /dev/null +++ b/libcudacxx/test/libcudacxx/libcxx/macros/os.compile.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +#include + +#if !defined(__CUDACC_RTC__) +# if _CCCL_OS(WINDOWS) +# include +# endif + +# if _CCCL_OS(LINUX) +# include +# endif + +# if _CCCL_OS(ANDROID) +# include +# endif + +# if _CCCL_OS(QNX) +# include +# endif +#endif + +int main(int, char**) +{ + static_assert(_CCCL_OS(WINDOWS) + _CCCL_OS(LINUX) == 1, ""); +#if _CCCL_OS(ANDROID) || _CCCL_OS(QNX) + static_assert(_CCCL_OS(LINUX) == 1, ""); + static_assert(_CCCL_OS(ANDROID) + _CCCL_OS(QNX) == 1, ""); +#endif +#if _CCCL_OS(LINUX) + static_assert(_CCCL_OS(WINDOWS) == 0, ""); +#endif +#if _CCCL_OS(WINDOWS) + static_assert(_CCCL_OS(ANDROID) + _CCCL_OS(QNX) + _CCCL_OS(LINUX) == 0, ""); +#endif + return 0; +}