MorphoGraphX  2.0-1-227
Util.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef UTIL_HPP
12 #define UTIL_HPP
13 
20 #include <Config.hpp>
21 #include <cuda/CudaGlobal.hpp>
22 
23 namespace mgx
24 {
25  // Min
26  template <typename T> CU_HOST_DEVICE T min(const T a, const T b)
27  {
28  if(a <= b)
29  return a;
30  return b;
31  }
32 
33  // Max
34  template <typename T> T CU_HOST_DEVICE max(const T a, const T b)
35  {
36  if(a >= b)
37  return a;
38  return b;
39  }
40 
41  // Trim to min/max
42  template <typename T> CU_HOST_DEVICE T trim(const T x, const T minx, const T maxx) {
43  return max(minx, min(maxx, x));
44  }
45 }
46 #endif
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::max
T CU_HOST_DEVICE max(const T a, const T b)
Definition: Util.hpp:34
mgx::trim
CU_HOST_DEVICE T trim(const T x, const T minx, const T maxx)
Definition: Util.hpp:42
CudaGlobal.hpp
mgx::min
CU_HOST_DEVICE T min(const T a, const T b)
Definition: Util.hpp:26
CU_HOST_DEVICE
#define CU_HOST_DEVICE
Definition: CudaGlobal.hpp:22