49 #ifndef __INTREPID2_UTILS_HPP__ 
   50 #define __INTREPID2_UTILS_HPP__ 
   52 #include "Intrepid2_ConfigDefs.hpp" 
   55 #include "Kokkos_Core.hpp" 
   56 #include "Kokkos_Macros.hpp"  
   58 #ifdef HAVE_INTREPID2_SACADO 
   59 #include "Kokkos_LayoutNatural.hpp" 
   64 #if defined(KOKKOS_OPT_RANGE_AGGRESSIVE_VECTORIZATION) && defined(KOKKOS_ENABLE_PRAGMA_IVDEP) && !defined(__CUDA_ARCH__) 
   65 #define INTREPID2_USE_IVDEP 
   72 #define INTREPID2_TEST_FOR_WARNING(test, msg)                           \ 
   74     printf("[Intrepid2] Warning in file %s, line %d\n",__FILE__,__LINE__); \ 
   75     printf("            Test that evaluated to true: %s\n", #test);     \ 
   76     printf("            %s \n", msg);                                   \ 
   79 #define INTREPID2_TEST_FOR_EXCEPTION(test, x, msg)                      \ 
   81     printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 
   82     printf("            Test that evaluated to true: %s\n", #test);     \ 
   83     printf("            %s \n", msg);                                   \ 
   87 #ifndef KOKKOS_ENABLE_CUDA 
   88 #define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg)           \ 
   90     printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 
   91     printf("            Test that evaluated to true: %s\n", #test);     \ 
   92     printf("            %s \n", msg);                                   \ 
   96   #define INTREPID2_TEST_FOR_EXCEPTION_DEVICE_SAFE(test, x, msg) device_assert(!test); 
   99 #define INTREPID2_TEST_FOR_ABORT(test, msg)                             \ 
  101     printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 
  102     printf("            Test that evaluated to true: %s\n", #test);     \ 
  103     printf("            %s \n", msg);                                   \ 
  104     Kokkos::abort(  "[Intrepid2] Abort\n");                             \ 
  108 #ifdef INTREPID2_TEST_FOR_DEBUG_ABORT_OVERRIDE_TO_CONTINUE 
  109 #define INTREPID2_TEST_FOR_DEBUG_ABORT(test, info, msg)                 \ 
  110   if (!(info) && (test)) {                                              \ 
  111     printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 
  112     printf("            Test that evaluated to true: %s\n", #test);     \ 
  113     printf("            %s \n", msg);                                   \ 
  117 #define INTREPID2_TEST_FOR_DEBUG_ABORT(test, info, msg)                 \ 
  118   if (!(info) && (test)) {                                              \ 
  119     printf("[Intrepid2] Error in file %s, line %d\n",__FILE__,__LINE__); \ 
  120     printf("            Test that evaluated to true: %s\n", #test);     \ 
  121     printf("            %s \n", msg);                                   \ 
  123     Kokkos::abort(  "[Intrepid2] Abort\n");                             \ 
  132     typedef typename T::scalar_type scalar_type;
 
  141     typedef float scalar_type;
 
  148     typedef double scalar_type;
 
  155     typedef int scalar_type;
 
  162     typedef long int scalar_type;
 
  169     typedef long long scalar_type;
 
  177   template<
typename ViewSpaceType, 
typename UserSpaceType>
 
  179     typedef UserSpaceType ExecSpaceType;
 
  185   template<
typename ViewSpaceType>
 
  187     typedef ViewSpaceType ExecSpaceType;
 
  194   template <
typename ViewType>
 
  196     using input_layout = 
typename ViewType::array_layout;
 
  197     using default_layout = 
typename ViewType::device_type::execution_space::array_layout;
 
  198     using result_layout  =
 
  199       typename std::conditional<
 
  200         std::is_same< input_layout, Kokkos::LayoutStride >::value,
 
  202         input_layout >::type;
 
  211   template<
typename IdxType, 
typename DimType, 
typename IterType>
 
  212   KOKKOS_FORCEINLINE_FUNCTION
 
  214   unrollIndex(IdxType &i, IdxType &j, 
 
  217               const IterType iter) {
 
  227   template<
typename IdxType, 
typename DimType, 
typename IterType>
 
  228   KOKKOS_FORCEINLINE_FUNCTION
 
  230   unrollIndex(IdxType &i, IdxType &j, IdxType &k, 
 
  234               const IterType iter) {
 
  240     unrollIndex( i, tmp, dim0, dim1*dim2, iter);
 
  241     unrollIndex( j, k,   dim1,      dim2,  tmp);
 
  250     KOKKOS_FORCEINLINE_FUNCTION
 
  251     static T min(
const T a, 
const T b) {
 
  252       return (a < b ? a : b);
 
  255     KOKKOS_FORCEINLINE_FUNCTION
 
  256     static T max(
const T a, 
const T b) {
 
  257       return (a > b ? a : b);
 
  260     KOKKOS_FORCEINLINE_FUNCTION
 
  261     static T abs(
const T a) {
 
  262       return (a > 0 ? a : T(-a));
 
  268   KOKKOS_FORCEINLINE_FUNCTION
 
  269   static T min(
const T &a, 
const T &b) {
 
  270     return (a < b ? a : b);
 
  274   KOKKOS_FORCEINLINE_FUNCTION
 
  275   static T max(
const T &a, 
const T &b) {
 
  276     return (a > b ? a : b);
 
  280   KOKKOS_FORCEINLINE_FUNCTION
 
  281   static T abs(
const T &a) {
 
  282     return (a > 0 ? a : T(-a));
 
  293   KOKKOS_FORCEINLINE_FUNCTION
 
  295   std::enable_if< !std::is_pod<T>::value, 
typename ScalarTraits<T>::scalar_type >::type
 
  296   get_scalar_value(
const T& obj) {
return obj.val();}
 
  299   KOKKOS_FORCEINLINE_FUNCTION
 
  301   std::enable_if< std::is_pod<T>::value, 
typename ScalarTraits<T>::scalar_type >::type
 
  302   get_scalar_value(
const T& obj){
return obj;}
 
  311   template<
typename T, 
typename ...P>
 
  312   KOKKOS_INLINE_FUNCTION
 
  314   std::enable_if< std::is_pod<T>::value, 
unsigned >::type
 
  315   dimension_scalar(
const Kokkos::DynRankView<T, P...> ) {
return 1;}
 
  317   template<
typename T, 
typename ...P>
 
  318   KOKKOS_INLINE_FUNCTION
 
  320   std::enable_if< std::is_pod<T>::value, 
unsigned >::type
 
  321   dimension_scalar(
const Kokkos::View<T, P...> view) {
return 1;}
 
  324   KOKKOS_FORCEINLINE_FUNCTION
 
  325   static ordinal_type get_dimension_scalar(
const T view) {
 
  326     return dimension_scalar(view);
 
  337   template<
class ViewType, 
class ... DimArgs>
 
  338   inline ViewType getMatchingViewWithLabel(ViewType &view, 
const std::string &label, DimArgs... dims)
 
  340     using ValueType          = 
typename ViewType::value_type;
 
  341     using ResultLayout       = 
typename DeduceLayout< ViewType >::result_layout;
 
  342     using DeviceType         = 
typename ViewType::device_type;
 
  343     using ViewTypeWithLayout = Kokkos::DynRankView<ValueType, ResultLayout, DeviceType >;
 
  345     const bool allocateFadStorage = !std::is_pod<ValueType>::value;
 
  346     if (!allocateFadStorage)
 
  348       return ViewTypeWithLayout(label,dims...);
 
  352       const int derivative_dimension = get_dimension_scalar(view);
 
  353       return ViewTypeWithLayout(label,dims...,derivative_dimension);
 
  360 #ifdef HAVE_INTREPID2_SACADO 
  361   template <
typename ValueType>
 
  362   struct NaturalLayoutForType {
 
  364     typename std::conditional<std::is_pod<ValueType>::value,
 
  366       Kokkos::LayoutNatural<Kokkos::LayoutLeft> >::type; 
 
  369   template <
typename ValueType>
 
  371     using layout  = Kokkos::LayoutLeft;
 
  376   const int VECTOR_SIZE = 1;
 
  377 #if defined(SACADO_VIEW_CUDA_HIERARCHICAL_DFAD) && defined(KOKKOS_ENABLE_CUDA) 
  378   const int FAD_VECTOR_SIZE = 32;
 
  380   const int FAD_VECTOR_SIZE = 1;
 
  386   template<
typename Scalar>
 
  387   constexpr 
int getVectorSizeForHierarchicalParallelism()
 
  389     return std::is_pod<Scalar>::value ? VECTOR_SIZE : FAD_VECTOR_SIZE;
 
  397   template<
typename ViewType>
 
  398   KOKKOS_INLINE_FUNCTION
 
  399   constexpr 
unsigned getScalarDimensionForView(
const ViewType &view)
 
  401     return (std::is_pod<typename ViewType::value_type>::value) ? 0 : get_dimension_scalar(view);
 
Contains definitions of custom data types in Intrepid2. 
Define layout that will allow us to wrap Sacado Scalar objects in Views without copying. 
layout deduction (temporary meta-function)