1 /******************************************************************************
2  * Copyright (c) 2011, Duane Merrill.  All rights reserved.
3  * Copyright (c) 2011-2018, NVIDIA CORPORATION.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *     * Redistributions of source code must retain the above copyright
8  *       notice, this list of conditions and the following disclaimer.
9  *     * Redistributions in binary form must reproduce the above copyright
10  *       notice, this list of conditions and the following disclaimer in the
11  *       documentation and/or other materials provided with the distribution.
12  *     * Neither the name of the NVIDIA CORPORATION nor the
13  *       names of its contributors may be used to endorse or promote products
14  *       derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  ******************************************************************************/
28 
29 /******************************************************************************
30  * Common C/C++ macro utilities
31  ******************************************************************************/
32 
33 #pragma once
34 
35 #include "util_namespace.cuh"
36 
37 /// Optional outer namespace(s)
38 CUB_NS_PREFIX
39 
40 /// CUB namespace
41 namespace cub {
42 
43 
44 /**
45  * \addtogroup UtilModule
46  * @{
47  */
48 
49 #ifndef CUB_ALIGN
50     #if defined(_WIN32) || defined(_WIN64)
51         /// Align struct
52         #define CUB_ALIGN(bytes) __declspec(align(32))
53     #else
54         /// Align struct
55         #define CUB_ALIGN(bytes) __attribute__((aligned(bytes)))
56     #endif
57 #endif
58 
59 #ifndef CUB_MAX
60     /// Select maximum(a, b)
61     #define CUB_MAX(a, b) (((b) > (a)) ? (b) : (a))
62 #endif
63 
64 #ifndef CUB_MIN
65     /// Select minimum(a, b)
66     #define CUB_MIN(a, b) (((b) < (a)) ? (b) : (a))
67 #endif
68 
69 #ifndef CUB_QUOTIENT_FLOOR
70     /// Quotient of x/y rounded down to nearest integer
71     #define CUB_QUOTIENT_FLOOR(x, y) ((x) / (y))
72 #endif
73 
74 #ifndef CUB_QUOTIENT_CEILING
75     /// Quotient of x/y rounded up to nearest integer
76     #define CUB_QUOTIENT_CEILING(x, y) (((x) + (y) - 1) / (y))
77 #endif
78 
79 #ifndef CUB_ROUND_UP_NEAREST
80     /// x rounded up to the nearest multiple of y
81     #define CUB_ROUND_UP_NEAREST(x, y) ((((x) + (y) - 1) / (y)) * y)
82 #endif
83 
84 #ifndef CUB_ROUND_DOWN_NEAREST
85     /// x rounded down to the nearest multiple of y
86     #define CUB_ROUND_DOWN_NEAREST(x, y) (((x) / (y)) * y)
87 #endif
88 
89 
90 #ifndef CUB_STATIC_ASSERT
91     #ifndef DOXYGEN_SHOULD_SKIP_THIS    // Do not document
92         #define CUB_CAT_(a, b) a ## b
93         #define CUB_CAT(a, b) CUB_CAT_(a, b)
94     #endif // DOXYGEN_SHOULD_SKIP_THIS
95 
96     /// Static assert
97     #define CUB_STATIC_ASSERT(cond, msg) typedef int CUB_CAT(cub_static_assert, __LINE__)[(cond) ? 1 : -1]
98 #endif
99 
100 /** @} */       // end group UtilModule
101 
102 }               // CUB namespace
103 CUB_NS_POSTFIX  // Optional outer namespace(s)
104