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 
00015   class StandardNodeMemoryModel {
00016     public:
00017       typedef std::size_t size_t;
00018 
00020 
00034       template <class T> inline
00035       Teuchos::ArrayRCP<T> allocBuffer(size_t size) {
00036         Teuchos::ArrayRCP<T> buff;
00037         if (size > 0) {
00038           buff = Teuchos::arcp<T>(size);
00039         }
00040         MARK_COMPUTE_BUFFER(buff);
00041         return buff;
00042       }
00043 
00055       template <class T> inline
00056       void copyFromBuffer(size_t size, const Teuchos::ArrayRCP<const T> &buffSrc, const Teuchos::ArrayView<T> &hostDest) {
00057         CHECK_COMPUTE_BUFFER(buffSrc);
00058         Teuchos::ArrayRCP<T> buffDest = Teuchos::arcpFromArrayView(hostDest);
00059         copyBuffers(size,buffSrc,buffDest);
00060       }
00061 
00073       template <class T> inline
00074       void copyToBuffer(size_t size, const Teuchos::ArrayView<const T> &hostSrc, const Teuchos::ArrayRCP<T> &buffDest) {
00075         CHECK_COMPUTE_BUFFER(buffDest);
00076         Teuchos::ArrayRCP<const T> buffSrc = Teuchos::arcpFromArrayView(hostSrc);
00077         copyBuffers<T>(size,buffSrc,buffDest);
00078       }
00079 
00088       template <class T> inline
00089       void copyBuffers(size_t size, const Teuchos::ArrayRCP<const T> &buffSrc, const Teuchos::ArrayRCP<T> &buffDest) {
00090         CHECK_COMPUTE_BUFFER(buffSrc);
00091         CHECK_COMPUTE_BUFFER(buffDest);
00092         Teuchos::ArrayView<const T> av_src = buffSrc(0,size);
00093         Teuchos::ArrayView<T>       av_dst = buffDest(0,size);
00094         std::copy(av_src.begin(),av_src.end(),av_dst.begin());
00095       }
00096 
00097       template <class T> inline
00098       Teuchos::ArrayRCP<const T> viewBuffer(size_t size, Teuchos::ArrayRCP<const T> buff) {
00099         CHECK_COMPUTE_BUFFER(buff);
00100         return buff.persistingView(0,size);
00101       }
00102 
00103       template <class T> inline
00104       Teuchos::ArrayRCP<T> viewBufferNonConst(ReadWriteOption rw, size_t size, const Teuchos::ArrayRCP<T> &buff) {
00105         CHECK_COMPUTE_BUFFER(buff);
00106         return buff.persistingView(0,size);
00107       }
00108 
00109       inline void readyBuffers(Teuchos::ArrayView<Teuchos::ArrayRCP<const char> > buffers, Teuchos::ArrayView<Teuchos::ArrayRCP<char> > ncBuffers) {
00110 #ifdef HAVE_KOKKOS_DEBUG
00111         for (size_t i=0; i < buffers.size(); ++i) {
00112           CHECK_COMPUTE_BUFFER(buffers[i]);
00113         }
00114         for (size_t i=0; i < ncBuffers.size(); ++i) {
00115           CHECK_COMPUTE_BUFFER(ncBuffers[i]);
00116         }
00117 #endif
00118         (void)buffers;
00119         (void)ncBuffers;
00120       }
00121 
00122 
00124   };
00125 
00126 } // end of namespace Kokkos
00127 
00128 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 09:59:49 2011 for Kokkos Node API and Local Linear Algebra Kernels by  doxygen 1.6.3