util_macro.cuh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /******************************************************************************
  2. * Copyright (c) 2011, Duane Merrill. All rights reserved.
  3. * Copyright (c) 2011-2014, 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. * Common C/C++ macro utilities
  30. ******************************************************************************/
  31. #pragma once
  32. #include "util_namespace.cuh"
  33. /// Optional outer namespace(s)
  34. CUB_NS_PREFIX
  35. /// CUB namespace
  36. namespace cub {
  37. /**
  38. * \addtogroup UtilModule
  39. * @{
  40. */
  41. /**
  42. * Align struct
  43. */
  44. #if defined(_WIN32) || defined(_WIN64)
  45. #define CUB_ALIGN(bytes) __declspec(align(32))
  46. #else
  47. #define CUB_ALIGN(bytes) __attribute__((aligned(bytes)))
  48. #endif
  49. /**
  50. * Select maximum(a, b)
  51. */
  52. #define CUB_MAX(a, b) (((b) > (a)) ? (b) : (a))
  53. /**
  54. * Select minimum(a, b)
  55. */
  56. #define CUB_MIN(a, b) (((b) < (a)) ? (b) : (a))
  57. /**
  58. * Quotient of x/y rounded down to nearest integer
  59. */
  60. #define CUB_QUOTIENT_FLOOR(x, y) ((x) / (y))
  61. /**
  62. * Quotient of x/y rounded up to nearest integer
  63. */
  64. #define CUB_QUOTIENT_CEILING(x, y) (((x) + (y) - 1) / (y))
  65. /**
  66. * x rounded up to the nearest multiple of y
  67. */
  68. #define CUB_ROUND_UP_NEAREST(x, y) ((((x) + (y) - 1) / (y)) * y)
  69. /**
  70. * x rounded down to the nearest multiple of y
  71. */
  72. #define CUB_ROUND_DOWN_NEAREST(x, y) (((x) / (y)) * y)
  73. /**
  74. * Return character string for given type
  75. */
  76. #define CUB_TYPE_STRING(type) ""#type
  77. #ifndef DOXYGEN_SHOULD_SKIP_THIS // Do not document
  78. #define CUB_CAT_(a, b) a ## b
  79. #define CUB_CAT(a, b) CUB_CAT_(a, b)
  80. #endif // DOXYGEN_SHOULD_SKIP_THIS
  81. /**
  82. * Static assert
  83. */
  84. #define CUB_STATIC_ASSERT(cond, msg) typedef int CUB_CAT(cub_static_assert, __LINE__)[(cond) ? 1 : -1]
  85. /** @} */ // end group UtilModule
  86. } // CUB namespace
  87. CUB_NS_POSTFIX // Optional outer namespace(s)