Commit a2f84095 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Refactoring reduction operations

- Replaced Constants.h with std::numeric_limits, see also
  https://jlk.fjfi.cvut.cz/gitlab/mmg/tnl-dev/issues/3
- Made the initialValue method of reduction opeerations static and
  constexpr.
parent afce4ec6
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ SET( CURRENT_DIR ${CMAKE_SOURCE_DIR}/src/TNL )

set( headers
     Assert.h
     Constants.h
     CudaSharedMemory.h
     CudaStreamPool.h
     DevicePointer.h

src/TNL/Constants.h

deleted100644 → 0
+0 −47
Original line number Diff line number Diff line
/***************************************************************************
                           tnlConstants.h -  description
                             -------------------
    begin                : June 17, 2015
    copyright            : (C) 2015 by Tomas Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/* See Copyright Notice in tnl/Copyright */

#pragma once

#include <limits.h>
#include <float.h>
#include <TNL/Assert.h>
#include <TNL/Devices/Cuda.h>

namespace TNL {

template< typename T > constexpr T MinValue() { return T();};
template<> constexpr char               MinValue< char >() { return CHAR_MIN; }
template<> constexpr unsigned char      MinValue< unsigned char >() { return 0; }
template<> constexpr short int          MinValue< short int >() { return SHRT_MIN; }
template<> constexpr unsigned short int MinValue< unsigned short int >() { return 0; }
template<> constexpr int                MinValue< int >() { return INT_MIN; }
template<> constexpr unsigned int       MinValue< unsigned int >() { return 0; }
template<> constexpr long int           MinValue< long int >() { return LONG_MIN; }
template<> constexpr unsigned long int  MinValue< unsigned long int >() { return 0; }
template<> constexpr float              MinValue< float >() { return -FLT_MAX; }
template<> constexpr double             MinValue< double >() { return -DBL_MAX; }
template<> constexpr long double        MinValue< long double >() { return -LDBL_MAX; }

template< typename T > constexpr T MaxValue() { return T();};
template<> constexpr char               MaxValue< char >() { return CHAR_MAX; }
template<> constexpr unsigned char      MaxValue< unsigned char >() { return UCHAR_MAX; }
template<> constexpr short int          MaxValue< short int >() { return SHRT_MAX; }
template<> constexpr unsigned short int MaxValue< unsigned short int >() { return USHRT_MAX; }
template<> constexpr int                MaxValue< int >() { return INT_MAX; }
template<> constexpr unsigned int       MaxValue< unsigned int >() { return UINT_MAX; }
template<> constexpr long int           MaxValue< long int >() { return LONG_MAX; }
template<> constexpr unsigned long int  MaxValue< unsigned long int >() { return ULONG_MAX; }
template<> constexpr float              MaxValue< float >() { return FLT_MAX; }
template<> constexpr double             MaxValue< double >() { return DBL_MAX; }
template<> constexpr long double        MaxValue< long double >() { return LDBL_MAX; }

} // namespace TNL
+23 −22
Original line number Diff line number Diff line
@@ -10,7 +10,8 @@

#pragma once

#include <TNL/Constants.h>
#include <limits>  // std::numeric_limits

#include <TNL/Math.h>
#include <TNL/Devices/CudaCallable.h>

@@ -31,7 +32,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionSum< Result >;

   __cuda_callable__ Result initialValue() { return 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -67,7 +68,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionMin< Result >;

   __cuda_callable__ Result initialValue() { return MaxValue< Result >(); };
   static constexpr Result initialValue() { return std::numeric_limits< Result >::max(); };

   template< typename Index >
   __cuda_callable__ void
@@ -103,7 +104,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionMax< Result >;

   __cuda_callable__ Result initialValue() { return MinValue< Result>(); };
   static constexpr Result initialValue() { return std::numeric_limits< Result >::lowest(); };

   template< typename Index >
   __cuda_callable__ void
@@ -139,7 +140,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionLogicalAnd< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) true; };
   static constexpr Result initialValue() { return true; };

   template< typename Index >
   __cuda_callable__ void
@@ -176,7 +177,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionLogicalOr< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) false; };
   static constexpr Result initialValue() { return false; };

   template< typename Index >
   __cuda_callable__ void
@@ -212,7 +213,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionSum< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -234,7 +235,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionMin< Result >;

   __cuda_callable__ Result initialValue() { return MaxValue< Result>(); };
   static constexpr Result initialValue() { return std::numeric_limits< Result >::max(); };

   template< typename Index >
   __cuda_callable__ void
@@ -256,7 +257,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionMax< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -278,7 +279,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionSum< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -307,7 +308,7 @@ public:
      this->p = p;
   }

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -337,7 +338,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionLogicalAnd< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) true; };
   static constexpr Result initialValue() { return true; };

   template< typename Index >
   __cuda_callable__ void
@@ -359,7 +360,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionLogicalAnd< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) false; };
   static constexpr Result initialValue() { return false; };

   template< typename Index >
   __cuda_callable__ void
@@ -381,7 +382,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionSum< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -403,7 +404,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionSum< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -425,7 +426,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionMin< Result >;

   __cuda_callable__ Result initialValue() { return MaxValue< Result>(); };
   static constexpr Result initialValue() { return std::numeric_limits< Result >::max(); };

   template< typename Index >
   __cuda_callable__ void
@@ -447,7 +448,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionMax< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return std::numeric_limits< Result >::lowest(); };

   template< typename Index >
   __cuda_callable__ void
@@ -469,7 +470,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionSum< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -491,7 +492,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionMin< Result >;

   __cuda_callable__ Result initialValue() { return MaxValue< Result>(); };
   static constexpr Result initialValue() { return std::numeric_limits< Result >::max(); };

   template< typename Index >
   __cuda_callable__ void
@@ -513,7 +514,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionMax< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -535,7 +536,7 @@ public:
   using ResultType = Result;
   using LaterReductionOperation = ParallelReductionSum< Result >;

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void
@@ -563,7 +564,7 @@ public:
      this->p = p;
   }

   __cuda_callable__ Result initialValue() { return ( Result ) 0; };
   static constexpr Result initialValue() { return 0; };

   template< typename Index >
   __cuda_callable__ void