Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

66 lines
1.9 KiB
ReStructuredText

.. _libcudacxx-extended-api-functional-maximum-minimum:
``cuda::maximum`` and ``cuda::minimum``
=======================================
.. code:: cuda
template <typename T>
struct maximum {
[[nodiscard]] __host__ __device__ inline
T operator()(T a, T b) const;
};
template <>
struct maximum<void> {
template <typename T1, typename T2>
[[nodiscard]] __host__ __device__ inline
cuda::std::common_type_t<T1, T2> operator()(T1 a, T2 b) const;
};
template <typename T>
struct minimum {
[[nodiscard]] __host__ __device__ inline
T operator()(T a, T b) const;
};
template <>
struct minimum<void> {
template <typename T1, typename T2>
[[nodiscard]] __host__ __device__ inline
cuda::std::common_type_t<T1, T2> operator()(T1 a, T2 b) const;
};
Function objects for performing maximum and minimum. The functions behave as ``noexcept`` when the comparison between the values is also ``noexcept``.
.. note::
Differently from ``std::plus`` and other functional operators, ``cuda::maximum`` and ``cuda::minimum`` specialized for ``void`` returns ``cuda::std::common_type_t`` and not the implicit promotion
Example
-------
.. code:: cuda
#include <cuda/functional>
#include <cuda/std/cstdint>
#include <cstdio>
#include <numeric>
__global__ void maximum_minimum_kernel() {
uint16_t v1 = 7;
uint16_t v2 = 3;
printf("%d\n", cuda::maximum<uint16_t>{}(v1, v2)); // print "7" (uint16_t)
printf("%d\n", cuda::minimum{}(v1, v2)); // print "3" (int)
}
int main() {
maximum_minimum_kernel<<<1, 1>>>();
cudaDeviceSynchronize();
int array[] = {3, 7, 5, 2};
printf("%d\n", std::accumulate(array, array + 4, 0, cuda::maximum{})); // 7
return 0;
}
`See it on Godbolt 🔗 <https://godbolt.org/z/44fdTerre>`_