Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Architecture and OS identification macros #3237

Merged
merged 13 commits into from
Jan 7, 2025
2 changes: 2 additions & 0 deletions libcudacxx/include/cuda/__cccl_config
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#ifndef _CUDA__CCCL_CONFIG
#define _CUDA__CCCL_CONFIG

#include <cuda/std/__cccl/architecture.h> // IWYU pragma: export
#include <cuda/std/__cccl/assert.h> // IWYU pragma: export
#include <cuda/std/__cccl/attributes.h> // IWYU pragma: export
#include <cuda/std/__cccl/builtin.h> // IWYU pragma: export
Expand All @@ -21,6 +22,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_floating_point.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
#include <cuda/std/__cccl/rtti.h> // IWYU pragma: export
Expand Down
44 changes: 44 additions & 0 deletions libcudacxx/include/cuda/std/__cccl/architecture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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_ARCH_H
#define __CCCL_ARCH_H

// The header provides the following macros to determine the host architecture:
//
// _CCCL_ARCH(ARM64) ARM64
// _CCCL_ARCH(X86) X86 both 32 and 64 bit
// _CCCL_ARCH(X86_64) X86 64 bit
// _CCCL_ARCH(X86_32) X86 64 bit
// _CCCL_ARCH(64BIT) Any 64 bit OS (supported by CUDA)
// _CCCL_ARCH(32BIT) Any 32 bit OS (supported by CUDA)

// Determine the host compiler and its version
#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) /* Windows Emulation Compatible */
# define _CCCL_ARCH_ARM64_() 1
#elif defined(_M_X64) || defined(_M_IX86) || defined(__amd64__) || defined(__x86_64__)
# define _CCCL_ARCH_X86_() 1
# if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__)
# define _CCCL_ARCH_X86_64_() 1
# else
# define _CCCL_ARCH_X86_32_() 1
# endif
#endif

#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) || defined(__amd64__) || defined(__x86_64__) \
|| defined(_M_X64)
# define _CCCL_ARCH_64BIT_() 1
#elif defined(_M_IX86)
# define _CCCL_ARCH_32BIT_() 1
#endif

#define _CCCL_ARCH(...) _CCCL_ARCH_##__VA_ARGS__##_()
fbusato marked this conversation as resolved.
Show resolved Hide resolved

#endif // __CCCL_ARCH_H
36 changes: 36 additions & 0 deletions libcudacxx/include/cuda/std/__cccl/os.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// 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)
# define _CCCL_OS_WINDOWS_() 1
#elif defined(__linux__)
# define _CCCL_OS_LINUX_() 1
#endif

#if defined(__ANDROID__)
# define _CCCL_OS_ANDROID_() 1
#elif defined(__QNX__) || defined(__QNXNTO__)
# define _CCCL_OS_QNX_() 1
#endif

#define _CCCL_OS(...) _CCCL_OS_##__VA_ARGS__##_()

#endif // __CCCL_OS_H
Loading