[INFRA] Import NVIDIA/CCCL upstream as optimization reference library
CCCL (CUDA C++ Core Libraries) provides: - CUB: device/block/warp-level GPU primitives (reduce, scan, sort, topk) - Thrust: high-level parallel algorithms (transform_reduce, sort, scan) - libcudacxx: CUDA C++ standard library (atomics, barriers, memory) - cudax: experimental features (memory resources, allocators) - Tuning policies: per-SM hardware-specific algorithm parameters Competition optimization vectors mapped to CCCL: - Output TPS (83% weight): warp_reduce, block_reduce, device_topk - Input TPS (14% weight): device_scan, block_load, prefetch - Cache TPS (3% weight): prefix caching strategy patterns - Memory (0.9 util): pooled/cached/buddy allocators Source: https://github.com/NVIDIA/cccl (shallow clone, HEAD only) License: Apache-2.0
This commit is contained in:
161
cccl_upstream/libcudacxx/test/support/test_macros.h
Normal file
161
cccl_upstream/libcudacxx/test/support/test_macros.h
Normal file
@@ -0,0 +1,161 @@
|
||||
// -*- C++ -*-
|
||||
//===---------------------------- test_macros.h ---------------------------===//
|
||||
//
|
||||
// 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) 2024 NVIDIA CORPORATION & AFFILIATES.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef SUPPORT_TEST_MACROS_HPP
|
||||
#define SUPPORT_TEST_MACROS_HPP
|
||||
|
||||
#include <cuda/std/detail/__config>
|
||||
|
||||
// Use the CCCL compiler detection
|
||||
#define TEST_COMPILER(...) _CCCL_COMPILER(__VA_ARGS__)
|
||||
#define TEST_CUDA_COMPILER(...) _CCCL_CUDA_COMPILER(__VA_ARGS__)
|
||||
#define TEST_CUDA_COMPILATION() _CCCL_CUDA_COMPILATION()
|
||||
|
||||
// Use the CCCL diagnostic suppression
|
||||
#define TEST_DIAG_SUPPRESS_CLANG(...) _CCCL_DIAG_SUPPRESS_CLANG(__VA_ARGS__)
|
||||
#define TEST_DIAG_SUPPRESS_GCC(...) _CCCL_DIAG_SUPPRESS_GCC(__VA_ARGS__)
|
||||
#define TEST_DIAG_SUPPRESS_NVHPC(...) _CCCL_DIAG_SUPPRESS_NVHPC(__VA_ARGS__)
|
||||
#define TEST_DIAG_SUPPRESS_MSVC(...) _CCCL_DIAG_SUPPRESS_MSVC(__VA_ARGS__)
|
||||
#define TEST_NV_DIAG_SUPPRESS(...) _CCCL_BEGIN_NV_DIAG_SUPPRESS(__VA_ARGS__)
|
||||
|
||||
// Use the CCCL host device function
|
||||
#define TEST_FUNC _CCCL_HOST_DEVICE _CCCL_TILE
|
||||
#define TEST_DEVICE_FUNC _CCCL_DEVICE
|
||||
#define TEST_TILE_FUNC _CCCL_TILE
|
||||
#define TEST_TILE_DEVICE_FUNC _CCCL_TILE _CCCL_DEVICE
|
||||
|
||||
// Use the CCCL C++ dialect detection
|
||||
#define TEST_STD_VER _CCCL_STD_VER
|
||||
|
||||
// Use the CCCL constexpr macros
|
||||
#define TEST_CONSTEXPR_CXX20 _CCCL_CONSTEXPR_CXX20
|
||||
#define TEST_CONSTEXPR_CXX23 _CCCL_CONSTEXPR_CXX23
|
||||
|
||||
// Use the CCCL global variable hack
|
||||
#define TEST_GLOBAL_VARIABLE static _CCCL_GLOBAL_VARIABLE
|
||||
|
||||
// Use the CCCL exceptions detection
|
||||
#define TEST_HAS_EXCEPTIONS() _CCCL_HAS_EXCEPTIONS()
|
||||
|
||||
#if TEST_HAS_EXCEPTIONS()
|
||||
# define TEST_THROW(...) throw __VA_ARGS__
|
||||
#else
|
||||
# define TEST_THROW(...) assert(#__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
// Use the CCCL spaceship detection
|
||||
#define TEST_HAS_SPACESHIP() _LIBCUDACXX_HAS_SPACESHIP_OPERATOR()
|
||||
|
||||
#if defined(_CCCL_BUILTIN_IS_CONSTANT_EVALUATED)
|
||||
# define TEST_IS_CONSTANT_EVALUATED() _CCCL_BUILTIN_IS_CONSTANT_EVALUATED()
|
||||
#else
|
||||
# define TEST_IS_CONSTANT_EVALUATED() false
|
||||
#endif
|
||||
|
||||
#if TEST_STD_VER >= 2023
|
||||
# define TEST_IS_CONSTANT_EVALUATED_CXX23() TEST_IS_CONSTANT_EVALUATED()
|
||||
#else // ^^^ C++23 ^^^ / vvv C++20 vvv
|
||||
# define TEST_IS_CONSTANT_EVALUATED_CXX23() false
|
||||
#endif // ^^^ TEST_STD_VER <= 2020
|
||||
|
||||
// Attempt to deduce the GLIBC version
|
||||
#if __has_include(<features.h>) || defined(__linux__)
|
||||
# include <features.h>
|
||||
# if defined(__GLIBC_PREREQ)
|
||||
# define TEST_HAS_GLIBC
|
||||
# define TEST_GLIBC_PREREQ(major, minor) __GLIBC_PREREQ(major, minor)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Sniff out to see if the underling C library has C11 features
|
||||
// Note that at this time (July 2018), MacOS X and iOS do NOT.
|
||||
// This is cribbed from __config; but lives here as well because we can't assume libc++
|
||||
#if defined(__linux__)
|
||||
// This block preserves the old behavior used by include/__config:
|
||||
// _LIBCUDACXX_GLIBC_PREREQ would be defined to 0 if __GLIBC_PREREQ was not
|
||||
// available. The configuration here may be too vague though, as Bionic, uClibc,
|
||||
// newlib, etc may all support these features but need to be configured.
|
||||
# if defined(TEST_GLIBC_PREREQ)
|
||||
# if TEST_GLIBC_PREREQ(2, 17)
|
||||
# define TEST_HAS_TIMESPEC_GET
|
||||
# define TEST_HAS_C11_FEATURES
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !_CCCL_HAS_FEATURE(cxx_rtti) && __cpp_rtti == 0 && !defined(__GXX_RTTI)
|
||||
# define TEST_HAS_NO_RTTI
|
||||
#endif
|
||||
|
||||
#if _CCCL_HAS_FEATURE(address_sanitizer) || _CCCL_HAS_FEATURE(memory_sanitizer) || _CCCL_HAS_FEATURE(thread_sanitizer)
|
||||
# define TEST_HAS_SANITIZERS
|
||||
#endif
|
||||
|
||||
#define TEST_IGNORE_NODISCARD (void)
|
||||
|
||||
#if TEST_COMPILER(NVRTC, >=, 13)
|
||||
# define TEST_NVRTC_VIRTUAL_DEFAULT_DTOR_ANNOTATION TEST_FUNC
|
||||
#else
|
||||
# define TEST_NVRTC_VIRTUAL_DEFAULT_DTOR_ANNOTATION
|
||||
#endif
|
||||
|
||||
// Include <intrin.h> for _ReadWriteBarrier.
|
||||
#if TEST_COMPILER(MSVC)
|
||||
# include <intrin.h>
|
||||
#endif // TEST_COMPILER(MSVC)
|
||||
|
||||
template <class Tp>
|
||||
TEST_FUNC inline void DoNotOptimize(Tp& value)
|
||||
{
|
||||
[[maybe_unused]] const volatile void* volatile ptr = &reinterpret_cast<const volatile char&>(value);
|
||||
|
||||
// Device path.
|
||||
NV_IF_TARGET(NV_IS_DEVICE, ({ asm volatile("" ::"l"(ptr) : "memory"); }))
|
||||
|
||||
// Host path.
|
||||
#if TEST_COMPILER(CLANG)
|
||||
NV_IF_TARGET(NV_IS_HOST, ({ asm volatile("" : "+r,m"(value) : : "memory"); }))
|
||||
#elif TEST_COMPILER(MSVC)
|
||||
NV_IF_TARGET(NV_IS_HOST, ({ _ReadWriteBarrier(); }))
|
||||
#else
|
||||
NV_IF_TARGET(NV_IS_HOST, ({ asm volatile("" : "+m,r"(value) : : "memory"); }))
|
||||
#endif
|
||||
}
|
||||
|
||||
// NVCC can't handle static member variables, so with a little care
|
||||
// a function returning a reference will result in the same thing
|
||||
#ifdef __CUDA_ARCH__
|
||||
# define _STATIC_MEMBER_IMPL(type) __shared__ type v;
|
||||
#else
|
||||
# define _STATIC_MEMBER_IMPL(type) static type v;
|
||||
#endif
|
||||
|
||||
#define STATIC_MEMBER_VAR(name, type) \
|
||||
TEST_FUNC static type& name() \
|
||||
{ \
|
||||
_STATIC_MEMBER_IMPL(type); \
|
||||
return v; \
|
||||
}
|
||||
|
||||
template <class... T>
|
||||
TEST_FUNC constexpr bool unused(T&&...)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Class-type and floating-point NTTPs require C++20 and are broken on nvcc < 13.1
|
||||
#if defined(__cpp_nontype_template_args) && __cpp_nontype_template_args >= 201911L \
|
||||
&& !TEST_CUDA_COMPILER(NVCC, <, 13, 1)
|
||||
# define TEST_HAS_CLASS_NTTP 1
|
||||
#else
|
||||
# define TEST_HAS_CLASS_NTTP 0
|
||||
#endif
|
||||
|
||||
#endif // SUPPORT_TEST_MACROS_HPP
|
||||
Reference in New Issue
Block a user