Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Kokkos_NodeExampleKernels.hpp
Go to the documentation of this file.
00001 #ifndef KOKKOS_NODE_EXAMPLE_KERNELS
00002 #define KOKKOS_NODE_EXAMPLE_KERNELS
00003 
00004 #include <Teuchos_RCP.hpp>
00005 #include <Teuchos_ArrayRCP.hpp>
00006 #include <Kokkos_NodeHelpers.hpp>
00007 
00012 #ifndef KERNEL_PREFIX
00013 #define KERNEL_PREFIX
00014 #endif
00015 
00016 namespace KokkosExamples {
00017 
00020   struct VecInit {
00022     int * x;
00024     KERNEL_PREFIX inline void execute(int i) {x[i] = i;}
00025   };
00026 
00029   template <class NODE>
00030   void initVec(Teuchos::RCP<NODE> node, Teuchos::ArrayRCP<int> data) {
00031     Kokkos::ReadyBufferHelper<NODE> rbh(node);
00032     VecInit init;
00033     // ready the buffer and encapsulate the kernel arguments
00034     rbh.begin();
00035     init.x = rbh.addNonConstBuffer(data);
00036     rbh.end();  // this call node->readyBuffers()
00037     // execute the kernel
00038     node->parallel_for(0,data.size(),init);
00039   }
00040 
00043   struct VecReduce {
00045     const int * x;
00047     typedef int ReductionType;
00049     KERNEL_PREFIX static inline int identity()            { return 0;    }
00051     KERNEL_PREFIX        inline int generate(int i)       { return x[i]; }
00053     KERNEL_PREFIX        inline int reduce  (int a, int b){ return a+b;  }
00054   };
00055 
00058   template <class NODE>
00059   int reduceVec(Teuchos::RCP<NODE> node, Teuchos::ArrayRCP<const int> data) {
00060     Kokkos::ReadyBufferHelper<NODE> rbh(node);
00061     VecReduce reduce;
00062     // ready the buffer and encapsulate the kernel arguments
00063     rbh.begin();
00064     reduce.x = rbh.addConstBuffer(data);
00065     rbh.end();  // this call node->readyBuffers()
00066     int ret = node->parallel_reduce(0,data.size(),reduce);
00067     return ret;
00068   }
00069 
00074 } // end of namespace KokkosExamples
00075 
00076 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends