You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/libcudacxx/extended_api/math/ceil_div.rst
+11-9Lines changed: 11 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,25 @@
1
1
.. _libcudacxx-extended-api-math-ceil-div:
2
2
3
-
``ceil_div`` Ceiling Division
4
-
=============================
3
+
Math
4
+
=====
5
5
6
6
.. code:: cuda
7
7
8
-
template <typename T, typename = U>
9
-
[[nodiscard]] __host__ __device__ constexpr T ceil_div(T value, U divisor) noexcept;
8
+
template <typename T, typename U>
9
+
[[nodiscard]] __host__ __device__ inline
10
+
constexpr _CUDA_VSTD::common_type_t<_Tp, _Up> ceil_div(T a, U b) noexcept;
10
11
11
-
``value``: The value to be divided.
12
-
``divisor``: The divisor.
12
+
ceil_div
13
+
---------
13
14
14
-
- *Requires*: ``is_integral_v<T>`` is true and ``is_integral_v<U>`` is true.
15
+
- *Requires*: ``T`` is an integral type (including 128-bit integers) or enumerator.
15
16
- *Preconditions*: ``a >= 0`` is true and ``b > 0`` is true.
16
17
- *Returns*: divides ``a`` by ``b``. If ``a`` is not a multiple of ``b`` rounds the result up to the next integer value.
17
18
18
-
.. note::
19
+
**Performance considerations**
19
20
20
-
The function is only constexpr from C++14 onwards
21
+
- The function computes ``(a + b - 1) / b`` when the common type is a signed integer.
22
+
- The function computes ``min(a, 1 + ((a - 1) / b)`` when the common type is an unsigned integer in CUDA, which generates less instructions than ``(a / b) + ((a / b) * b != a)``, especially for 64-bit types.
21
23
22
24
**Example**: This API is very useful for determining the *number of thread blocks* required to process a fixed amount of work, given a fixed number of threads per block:
0 commit comments