codekingpro/portable-devtools
114k
1/******************************************************************************2 * Copyright (c) 2011, Duane Merrill. All rights reserved.3 * Copyright (c) 2011-2021, NVIDIA CORPORATION. All rights reserved.4 *5 * Redistribution and use in source and binary forms, with or without6 * modification, are permitted provided that the following conditions are met:7 * * Redistributions of source code must retain the above copyright8 * notice, this list of conditions and the following disclaimer.9 * * Redistributions in binary form must reproduce the above copyright10 * notice, this list of conditions and the following disclaimer in the11 * documentation and/or other materials provided with the distribution.12 * * Neither the name of the NVIDIA CORPORATION nor the13 * names of its contributors may be used to endorse or promote products14 * derived from this software without specific prior written permission.15 *16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE19 * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.26 *27 ******************************************************************************/28 29/**30 * \file util_namespace.cuh31 * \brief Utilities that allow `cub::` to be placed inside an32 * application-specific namespace.33 */34 35 36#pragma once37 38// This is not used by this file; this is a hack so that we can detect the39// CUB version from Thrust on older versions of CUB that did not have40// version.cuh.41#include <cub/version.cuh>42 43#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)44# pragma GCC system_header45#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)46# pragma clang system_header47#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)48# pragma system_header49#endif // no system header50 51#include <cub/detail/detect_cuda_runtime.cuh>52 53// Prior to 1.13.1, only the PREFIX/POSTFIX macros were used. Notify users54// that they must now define the qualifier macro, too.55#if (defined(CUB_NS_PREFIX) || defined(CUB_NS_POSTFIX)) && !defined(CUB_NS_QUALIFIER)56#error CUB requires a definition of CUB_NS_QUALIFIER when CUB_NS_PREFIX/POSTFIX are defined.57#endif58 59/**60 * \def THRUST_CUB_WRAPPED_NAMESPACE61 * If defined, this value will be used as the name of a namespace that wraps the62 * `thrust::` and `cub::` namespaces.63 * This macro should not be used with any other CUB namespace macros.64 */65#ifdef THRUST_CUB_WRAPPED_NAMESPACE66#define CUB_WRAPPED_NAMESPACE THRUST_CUB_WRAPPED_NAMESPACE67#endif68 69/**70 * \def CUB_WRAPPED_NAMESPACE71 * If defined, this value will be used as the name of a namespace that wraps the72 * `cub::` namespace.73 * If THRUST_CUB_WRAPPED_NAMESPACE is set, this will inherit that macro's value.74 * This macro should not be used with any other CUB namespace macros.75 */76#ifdef CUB_WRAPPED_NAMESPACE77#define CUB_NS_PREFIX \78 namespace CUB_WRAPPED_NAMESPACE \79 {80 81#define CUB_NS_POSTFIX }82 83#define CUB_NS_QUALIFIER ::CUB_WRAPPED_NAMESPACE::cub84#endif85 86/**87 * \def CUB_NS_PREFIX88 * This macro is inserted prior to all `namespace cub { ... }` blocks. It is89 * derived from CUB_WRAPPED_NAMESPACE, if set, and will be empty otherwise.90 * It may be defined by users, in which case CUB_NS_PREFIX,91 * CUB_NS_POSTFIX, and CUB_NS_QUALIFIER must all be set consistently.92 */93#ifndef CUB_NS_PREFIX94#define CUB_NS_PREFIX95#endif96 97/**98 * \def CUB_NS_POSTFIX99 * This macro is inserted following the closing braces of all100 * `namespace cub { ... }` block. It is defined appropriately when101 * CUB_WRAPPED_NAMESPACE is set, and will be empty otherwise. It may be102 * defined by users, in which case CUB_NS_PREFIX, CUB_NS_POSTFIX, and103 * CUB_NS_QUALIFIER must all be set consistently.104 */105#ifndef CUB_NS_POSTFIX106#define CUB_NS_POSTFIX107#endif108 109/**110 * \def CUB_NS_QUALIFIER111 * This macro is used to qualify members of cub:: when accessing them from112 * outside of their namespace. By default, this is just `::cub`, and will be113 * set appropriately when CUB_WRAPPED_NAMESPACE is defined. This macro may be114 * defined by users, in which case CUB_NS_PREFIX, CUB_NS_POSTFIX, and115 * CUB_NS_QUALIFIER must all be set consistently.116 */117#ifndef CUB_NS_QUALIFIER118#define CUB_NS_QUALIFIER ::cub119#endif120 121#if !defined(CUB_DETAIL_MAGIC_NS_NAME)122#define CUB_DETAIL_COUNT_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, \123 _14, _15, _16, _17, _18, _19, _20, N, ...) \124 N125#define CUB_DETAIL_COUNT(...) \126 CUB_DETAIL_IDENTITY(CUB_DETAIL_COUNT_N(__VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, \127 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1))128#define CUB_DETAIL_IDENTITY(N) N129#define CUB_DETAIL_APPLY(MACRO, ...) CUB_DETAIL_IDENTITY(MACRO(__VA_ARGS__))130#define CUB_DETAIL_MAGIC_NS_NAME1(P1) \131 CUB_##P1##_NS132#define CUB_DETAIL_MAGIC_NS_NAME2(P1, P2) \133 CUB_##P1##_##P2##_NS134#define CUB_DETAIL_MAGIC_NS_NAME3(P1, P2, P3) \135 CUB_##P1##_##P2##_##P3##_NS136#define CUB_DETAIL_MAGIC_NS_NAME4(P1, P2, P3, P4) \137 CUB_##P1##_##P2##_##P3##_##P4##_NS138#define CUB_DETAIL_MAGIC_NS_NAME5(P1, P2, P3, P4, P5) \139 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_NS140#define CUB_DETAIL_MAGIC_NS_NAME6(P1, P2, P3, P4, P5, P6) \141 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_NS142#define CUB_DETAIL_MAGIC_NS_NAME7(P1, P2, P3, P4, P5, P6, P7) \143 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_NS144#define CUB_DETAIL_MAGIC_NS_NAME8(P1, P2, P3, P4, P5, P6, P7, P8) \145 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_NS146#define CUB_DETAIL_MAGIC_NS_NAME9(P1, P2, P3, P4, P5, P6, P7, P8, P9) \147 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_NS148#define CUB_DETAIL_MAGIC_NS_NAME10(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) \149 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_NS150#define CUB_DETAIL_MAGIC_NS_NAME11(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11) \151 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_NS152#define CUB_DETAIL_MAGIC_NS_NAME12(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12) \153 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_NS154#define CUB_DETAIL_MAGIC_NS_NAME13(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13) \155 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_NS156#define CUB_DETAIL_MAGIC_NS_NAME14(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14) \157 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_NS158#define CUB_DETAIL_MAGIC_NS_NAME15(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15) \159 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_NS160#define CUB_DETAIL_MAGIC_NS_NAME16(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16) \161 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_NS162#define CUB_DETAIL_MAGIC_NS_NAME17(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17) \163 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_##P17##_NS164#define CUB_DETAIL_MAGIC_NS_NAME18(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18) \165 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_##P17##_##P18##_NS166#define CUB_DETAIL_MAGIC_NS_NAME19(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19) \167 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_##P17##_##P18##_##P19##_NS168#define CUB_DETAIL_MAGIC_NS_NAME20(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10, P11, P12, P13, P14, P15, P16, P17, P18, P19, P20) \169 CUB_##P1##_##P2##_##P3##_##P4##_##P5##_##P6##_##P7##_##P8##_##P9##_##P10##_##P11##_##P12##_##P13##_##P14##_##P15##_##P16##_##P17##_##P18##_##P19##_##P20##_NS170#define CUB_DETAIL_DISPATCH(N) CUB_DETAIL_MAGIC_NS_NAME ## N171#define CUB_DETAIL_MAGIC_NS_NAME(...) CUB_DETAIL_IDENTITY(CUB_DETAIL_APPLY(CUB_DETAIL_DISPATCH, CUB_DETAIL_COUNT(__VA_ARGS__))(__VA_ARGS__))172#endif // !defined(CUB_DETAIL_MAGIC_NS_NAME)173 174// clang-format off175#if defined(CUB_DISABLE_NAMESPACE_MAGIC) || defined(CUB_WRAPPED_NAMESPACE)176# if !defined(CUB_WRAPPED_NAMESPACE)177# if !defined(CUB_IGNORE_NAMESPACE_MAGIC_ERROR)178# error "Disabling namespace magic is unsafe without wrapping namespace"179# endif // !defined(CUB_IGNORE_NAMESPACE_MAGIC_ERROR)180# endif // !defined(CUB_WRAPPED_NAMESPACE)181# define CUB_DETAIL_MAGIC_NS_BEGIN182# define CUB_DETAIL_MAGIC_NS_END183#else // not defined(CUB_DISABLE_NAMESPACE_MAGIC)184# if defined(_NVHPC_CUDA)185# define CUB_DETAIL_MAGIC_NS_BEGIN inline namespace CUB_DETAIL_MAGIC_NS_NAME(CUB_VERSION, NV_TARGET_SM_INTEGER_LIST) {186# define CUB_DETAIL_MAGIC_NS_END }187# else // not defined(_NVHPC_CUDA)188# define CUB_DETAIL_MAGIC_NS_BEGIN inline namespace CUB_DETAIL_MAGIC_NS_NAME(CUB_VERSION, __CUDA_ARCH_LIST__) {189# define CUB_DETAIL_MAGIC_NS_END }190# endif // not defined(_NVHPC_CUDA)191#endif // not defined(CUB_DISABLE_NAMESPACE_MAGIC)192// clang-format on193 194/**195 * \def CUB_NAMESPACE_BEGIN196 * This macro is used to open a `cub::` namespace block, along with any197 * enclosing namespaces requested by CUB_WRAPPED_NAMESPACE, etc.198 * This macro is defined by CUB and may not be overridden.199 */200#define CUB_NAMESPACE_BEGIN \201 CUB_NS_PREFIX \202 namespace cub \203 { \204 CUB_DETAIL_MAGIC_NS_BEGIN205 206/**207 * \def CUB_NAMESPACE_END208 * This macro is used to close a `cub::` namespace block, along with any209 * enclosing namespaces requested by CUB_WRAPPED_NAMESPACE, etc.210 * This macro is defined by CUB and may not be overridden.211 */212#define CUB_NAMESPACE_END \213 CUB_DETAIL_MAGIC_NS_END \214 } /* end namespace cub */ \215 CUB_NS_POSTFIX216 217// Declare these namespaces here for the purpose of Doxygenating them218CUB_NS_PREFIX219 220/*! \namespace cub221 * \brief \p cub is the top-level namespace which contains all CUB222 * functions and types.223 */224namespace cub225{226}227 228CUB_NS_POSTFIX229 