Skip to content

Commit

Permalink
Provide new public headers <Kokkos_Clamp.hpp> and `<Kokkos_MinMax.h…
Browse files Browse the repository at this point in the history
…pp>` (kokkos#6687)

* Promote min, max, clamp to public

* Drop unnecessary <Kokkos_MinMaxClamp.hpo> header includes

* Split Kokkos_MinMaxClamp.hpp into Kokkos_MinMax.hpp and Kokkos_Clamp.hpp

---------

Co-authored-by: Damien L-G <dalg24@gmail.com>
  • Loading branch information
aprokop and dalg24 committed Jan 11, 2024
1 parent 0ba8c40 commit 89ba3fb
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 29 deletions.
1 change: 0 additions & 1 deletion core/src/Cuda/Kokkos_Cuda_Parallel_MDRange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <Cuda/Kokkos_Cuda_KernelLaunch.hpp>
#include <Cuda/Kokkos_Cuda_ReduceScan.hpp>
#include <Cuda/Kokkos_Cuda_BlockSize_Deduction.hpp>
#include <Kokkos_MinMaxClamp.hpp>

#include <impl/Kokkos_Tools.hpp>
#include <typeinfo>
Expand Down
1 change: 0 additions & 1 deletion core/src/Cuda/Kokkos_Cuda_Parallel_Range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <Cuda/Kokkos_Cuda_KernelLaunch.hpp>
#include <Cuda/Kokkos_Cuda_ReduceScan.hpp>
#include <Cuda/Kokkos_Cuda_BlockSize_Deduction.hpp>
#include <Kokkos_MinMaxClamp.hpp>

#include <impl/Kokkos_Tools.hpp>
#include <typeinfo>
Expand Down
2 changes: 1 addition & 1 deletion core/src/Cuda/Kokkos_Cuda_Parallel_Team.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <Cuda/Kokkos_Cuda_ReduceScan.hpp>
#include <Cuda/Kokkos_Cuda_BlockSize_Deduction.hpp>
#include <Cuda/Kokkos_Cuda_Team.hpp>
#include <Kokkos_MinMaxClamp.hpp>
#include <Kokkos_MinMax.hpp>
#include <Kokkos_Vectorization.hpp>

#include <impl/Kokkos_Tools.hpp>
Expand Down
2 changes: 1 addition & 1 deletion core/src/HIP/Kokkos_HIP_TeamPolicyInternal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef KOKKOS_HIP_TEAM_POLICY_INTERNAL_HPP
#define KOKKOS_HIP_TEAM_POLICY_INTERNAL_HPP

#include <Kokkos_MinMaxClamp.hpp>
#include <Kokkos_MinMax.hpp>

namespace Kokkos {
namespace Impl {
Expand Down
41 changes: 41 additions & 0 deletions core/src/Kokkos_Clamp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER

#ifndef KOKKOS_CLAMP_HPP
#define KOKKOS_CLAMP_HPP

#include <Kokkos_Macros.hpp>

namespace Kokkos {

template <class T>
constexpr KOKKOS_INLINE_FUNCTION const T& clamp(const T& value, const T& lo,
const T& hi) {
KOKKOS_EXPECTS(!(hi < lo));
return (value < lo) ? lo : (hi < value) ? hi : value;
}

template <class T, class ComparatorType>
constexpr KOKKOS_INLINE_FUNCTION const T& clamp(const T& value, const T& lo,
const T& hi,
ComparatorType comp) {
KOKKOS_EXPECTS(!comp(hi, lo));
return comp(value, lo) ? lo : comp(hi, value) ? hi : value;
}

} // namespace Kokkos

#endif
3 changes: 2 additions & 1 deletion core/src/Kokkos_Core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
#include <Kokkos_Half.hpp>
#include <Kokkos_AnonymousSpace.hpp>
#include <Kokkos_Pair.hpp>
#include <Kokkos_MinMaxClamp.hpp>
#include <Kokkos_Clamp.hpp>
#include <Kokkos_MinMax.hpp>
#include <Kokkos_MathematicalConstants.hpp>
#include <Kokkos_MathematicalFunctions.hpp>
#include <Kokkos_MathematicalSpecialFunctions.hpp>
Expand Down
25 changes: 2 additions & 23 deletions core/src/Kokkos_MinMaxClamp.hpp → core/src/Kokkos_MinMax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@
//
//@HEADER

#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
#include <Kokkos_Macros.hpp>
static_assert(false,
"Including non-public Kokkos header files is not allowed.");
#endif
#ifndef KOKKOS_MIN_MAX_CLAMP_HPP
#define KOKKOS_MIN_MAX_CLAMP_HPP
#ifndef KOKKOS_MIN_MAX_HPP
#define KOKKOS_MIN_MAX_HPP

#include <Kokkos_Macros.hpp>
#include <Kokkos_Pair.hpp>
Expand All @@ -29,22 +24,6 @@ static_assert(false,

namespace Kokkos {

// clamp
template <class T>
constexpr KOKKOS_INLINE_FUNCTION const T& clamp(const T& value, const T& lo,
const T& hi) {
KOKKOS_EXPECTS(!(hi < lo));
return (value < lo) ? lo : (hi < value) ? hi : value;
}

template <class T, class ComparatorType>
constexpr KOKKOS_INLINE_FUNCTION const T& clamp(const T& value, const T& lo,
const T& hi,
ComparatorType comp) {
KOKKOS_EXPECTS(!comp(hi, lo));
return comp(value, lo) ? lo : comp(hi, value) ? hi : value;
}

// max
template <class T>
constexpr KOKKOS_INLINE_FUNCTION const T& max(const T& a, const T& b) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/Kokkos_View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static_assert(false,
#ifdef KOKKOS_ENABLE_IMPL_MDSPAN
#include <View/MDSpan/Kokkos_MDSpan_Extents.hpp>
#endif
#include <Kokkos_MinMaxClamp.hpp>
#include <Kokkos_MinMax.hpp>

//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
Expand Down

0 comments on commit 89ba3fb

Please sign in to comment.