Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Kokkos_NodeHelpers.hpp
00001 #ifndef KOKKOS_NODE_HELPERS_HPP_
00002 #define KOKKOS_NODE_HELPERS_HPP_
00003 
00004 #include <Kokkos_NodeAPIConfigDefs.hpp>
00005 #include "Teuchos_Array.hpp"
00006 #include "Teuchos_ArrayRCP.hpp"
00007 
00008 namespace Kokkos {
00009 
00013   template <class Node>
00014   class ReadyBufferHelper {
00015     public:
00017       ReadyBufferHelper(RCP<Node> node);
00018 
00020       virtual ~ReadyBufferHelper();
00021 
00023       void begin();
00024 
00026       template <class T>
00027       const T* addConstBuffer(ArrayRCP<const T> buff);
00028 
00030       template <class T>
00031       T* addNonConstBuffer(ArrayRCP<T> buff);
00032 
00034       void end();
00035 
00036 
00037     protected:
00038       RCP<Node> node_;
00039       Array< ArrayRCP<const char> >  cbufs_;
00040       Array< ArrayRCP<      char> > ncbufs_;
00041   };
00042 
00043   template <class Node>
00044   ReadyBufferHelper<Node>::ReadyBufferHelper(RCP<Node> node)
00045   : node_(node) {
00046   }
00047 
00048   template <class Node>
00049   ReadyBufferHelper<Node>::~ReadyBufferHelper() {
00050   }
00051 
00052   template <class Node>
00053   void ReadyBufferHelper<Node>::begin() {
00054     cbufs_.clear();
00055     ncbufs_.clear();
00056   }
00057 
00058   template <class Node>
00059   template <class T>
00060   const T* ReadyBufferHelper<Node>::addConstBuffer(ArrayRCP<const T> buff) {
00061     cbufs_.push_back( arcp_reinterpret_cast<const char>(buff) );
00062     return buff.get();
00063   }
00064 
00065   template <class Node>
00066   template <class T>
00067   T* ReadyBufferHelper<Node>::addNonConstBuffer(ArrayRCP<T> buff) {
00068     cbufs_.push_back( arcp_reinterpret_cast<char>(buff) );
00069     return buff.get();
00070   }
00071 
00072   template <class Node>
00073   void ReadyBufferHelper<Node>::end() {
00074     node_->readyBuffers(cbufs_(), ncbufs_());  
00075   }
00076 
00077   template <class Node>
00078   class ArrayOfViewsHelper {
00079     public:
00080       template <class T>
00081       static ArrayRCP<ArrayRCP<T> > getArrayOfNonConstViews(const RCP<Node> &node, ReadWriteOption rw, const ArrayRCP<ArrayRCP<T> > &arrayOfBuffers);
00082     private:
00084       ArrayOfViewsHelper();
00085       ~ArrayOfViewsHelper();
00086   };
00087 
00088   template <class Node>
00089   template <class T>
00090   ArrayRCP<ArrayRCP<T> > 
00091   ArrayOfViewsHelper<Node>::getArrayOfNonConstViews(const RCP<Node> &node, ReadWriteOption rw, const ArrayRCP<ArrayRCP<T> > &arrayOfBuffers) {
00092     ArrayRCP< ArrayRCP<T> > arrayofviews;
00093     const size_t numBufs = arrayOfBuffers.size();
00094     if (numBufs > 0) {
00095       arrayofviews = arcp< ArrayRCP<T> >(numBufs);
00096       for (size_t i=0; i < numBufs; ++i) {
00097         if (arrayOfBuffers[i].size() > 0) {
00098           arrayofviews[i] = node->template viewBufferNonConst<T>(rw,arrayOfBuffers[i].size(),arrayOfBuffers[i]);
00099         }
00100       }
00101     }
00102     return arrayofviews;
00103   }
00104 
00105   /* A trivial implementation of ArrayOfViewsHelper, for CPU-only nodes. */
00106   template <class Node>
00107   class ArrayOfViewsHelperTrivialImpl {
00108     public:
00109       template <class T>
00110       static ArrayRCP<ArrayRCP<T> > getArrayOfNonConstViews(const RCP<Node> &node, ReadWriteOption rw, const ArrayRCP<ArrayRCP<T> > &arrayOfBuffers);
00111     private:
00113       ArrayOfViewsHelperTrivialImpl();
00114       ~ArrayOfViewsHelperTrivialImpl();
00115   };
00116 
00117   template <class Node>
00118   template <class T>
00119   ArrayRCP<ArrayRCP<T> > 
00120   ArrayOfViewsHelperTrivialImpl<Node>::getArrayOfNonConstViews(const RCP<Node> &node, ReadWriteOption rw, const ArrayRCP<ArrayRCP<T> > &arrayOfBuffers) {
00121     (void)node;
00122     (void)rw;
00123     return arrayOfBuffers;
00124   }
00125 
00126 } // end of namespace Kokkos
00127 
00128 
00129 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends