forked from NVIDIA/cccl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Architecture and OS identification macros (NVIDIA#3237)
- Loading branch information
Showing
5 changed files
with
162 additions
and
0 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
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,37 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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_64) X86 64 bit | ||
|
||
// Determine the host compiler and its version | ||
|
||
// Arm 64-bit | ||
#if (defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) /*emulation*/) | ||
# define _CCCL_ARCH_ARM64_() 1 | ||
#else | ||
# define _CCCL_ARCH_ARM64_() 0 | ||
#endif | ||
|
||
// X86 64-bit | ||
#if defined(_M_X64) || defined(__amd64__) || defined(__x86_64__) | ||
# define _CCCL_ARCH_X86_64_() 1 | ||
#else | ||
# define _CCCL_ARCH_X86_64_() 0 | ||
#endif | ||
|
||
#define _CCCL_ARCH(...) _CCCL_ARCH_##__VA_ARGS__##_() | ||
|
||
#endif // __CCCL_ARCH_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,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 |
31 changes: 31 additions & 0 deletions
31
libcudacxx/test/libcudacxx/std/cccl/architecture.compile.pass.cpp
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,31 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 <cuda/std/__cccl/architecture.h> | ||
#include <cuda/std/__cccl/compiler.h> | ||
|
||
#if !defined(__CUDACC_RTC__) | ||
# if _CCCL_ARCH(X86_64) | ||
# if _CCCL_COMPILER(MSVC) | ||
# include <intrin.h> | ||
# elif _CCCL_COMPILER(GCC) || _CCCL_COMPILER(CLANG) | ||
# include <cpuid.h> | ||
# endif | ||
# endif | ||
|
||
# if _CCCL_ARCH(ARM64) && defined(__ARM_ACLE) | ||
# include <arm_acle.h> | ||
# endif | ||
#endif | ||
|
||
int main(int, char**) | ||
{ | ||
static_assert(sizeof(void*) == 8, ""); | ||
return 0; | ||
} |
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,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 <cuda/std/__cccl/os.h> | ||
|
||
#if !defined(__CUDACC_RTC__) | ||
# if _CCCL_OS(WINDOWS) | ||
# include <windows.h> | ||
# endif | ||
|
||
# if _CCCL_OS(LINUX) | ||
# include <unistd.h> | ||
# endif | ||
|
||
# if _CCCL_OS(ANDROID) | ||
# include <android/api-level.h> | ||
# endif | ||
|
||
# if _CCCL_OS(QNX) | ||
# include <qnx.h> | ||
# 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; | ||
} |