Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Kokkos_StandardNodeMemoryModel.hpp
00001 #ifndef KOKKOS_STANDARD_NODE_MEMORY_MODEL_HPP_
00002 #define KOKKOS_STANDARD_NODE_MEMORY_MODEL_HPP_
00003 
00004 #include "Kokkos_NodeAPIConfigDefs.hpp"
00005 #include "Kokkos_BufferMacros.hpp"
00006 
00007 #include <cstdlib>
00008 #include <algorithm>
00009 #include <Teuchos_ArrayRCP.hpp>
00010 #include <Teuchos_ArrayView.hpp>
00011 
00012 namespace Kokkos {
00013 
00017   class StandardNodeMemoryModel {
00018     public:
00020       static const bool isHostNode = true;
00021 
00023 
00037       template <class T> inline
00038       ArrayRCP<T> allocBuffer(size_t size) {
00039         ArrayRCP<T> buff;
00040         if (size > 0) {
00041           buff = arcp<T>(size);
00042         }
00043         if (isHostNode == false) {
00044           MARK_COMPUTE_BUFFER(buff);
00045         }
00046         return buff;
00047       }
00048 
00060       template <class T> inline
00061       void copyFromBuffer(size_t size, const ArrayRCP<const T> &buffSrc, const ArrayView<T> &hostDest) {
00062         if (isHostNode == false) {
00063           CHECK_COMPUTE_BUFFER(buffSrc);
00064         }
00065         ArrayRCP<T> buffDest = arcpFromArrayView(hostDest);
00066         copyBuffers(size,buffSrc,buffDest);
00067       }
00068 
00080       template <class T> inline
00081       void copyToBuffer(size_t size, const ArrayView<const T> &hostSrc, const ArrayRCP<T> &buffDest) {
00082         if (isHostNode == false) {
00083           CHECK_COMPUTE_BUFFER(buffDest);
00084         }
00085         ArrayRCP<const T> buffSrc = arcpFromArrayView(hostSrc);
00086         copyBuffers<T>(size,buffSrc,buffDest);
00087       }
00088 
00097       template <class T> inline
00098       void copyBuffers(size_t size, const ArrayRCP<const T> &buffSrc, const ArrayRCP<T> &buffDest) {
00099         if (isHostNode == false) {
00100           CHECK_COMPUTE_BUFFER(buffSrc);
00101           CHECK_COMPUTE_BUFFER(buffDest);
00102         }
00103         ArrayView<const T> av_src = buffSrc(0,size);
00104         ArrayView<T>       av_dst = buffDest(0,size);
00105         std::copy(av_src.begin(),av_src.end(),av_dst.begin());
00106       }
00107 
00109       template <class T> inline
00110       ArrayRCP<const T> viewBuffer(size_t size, ArrayRCP<const T> buff) {
00111         if (isHostNode == false) {
00112           CHECK_COMPUTE_BUFFER(buff);
00113         }
00114         return buff.persistingView(0,size);
00115       }
00116 
00118       template <class T> inline
00119       ArrayRCP<T> viewBufferNonConst(ReadWriteOption rw, size_t size, const ArrayRCP<T> &buff) {
00120         if (isHostNode == false) {
00121           CHECK_COMPUTE_BUFFER(buff);
00122         }
00123         return buff.persistingView(0,size);
00124       }
00125 
00126       inline void readyBuffers(ArrayView<ArrayRCP<const char> > buffers, ArrayView<ArrayRCP<char> > ncBuffers) {
00127 #ifdef HAVE_KOKKOS_DEBUG
00128         if (isHostNode == false) {
00129           for (size_t i=0; i < (size_t)buffers.size(); ++i) {
00130             CHECK_COMPUTE_BUFFER(buffers[i]);
00131           }
00132           for (size_t i=0; i < (size_t)ncBuffers.size(); ++i) {
00133             CHECK_COMPUTE_BUFFER(ncBuffers[i]);
00134           }
00135         }
00136 #endif
00137         (void)buffers;
00138         (void)ncBuffers;
00139       }
00140 
00141 
00143   };
00144 
00145 } // end of namespace Kokkos
00146 
00147 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends