Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Kokkos_CUDANodeMemoryModel.hpp
00001 //@HEADER
00002 // ************************************************************************
00003 // 
00004 //          Kokkos: Node API and Parallel Node Kernels
00005 //              Copyright (2008) Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00038 // 
00039 // ************************************************************************
00040 //@HEADER
00041 
00042 #ifndef KOKKOS_CUDA_NODE_MEMORY_MODEL_HPP_
00043 #define KOKKOS_CUDA_NODE_MEMORY_MODEL_HPP_
00044 
00045 #include "Kokkos_NodeAPIConfigDefs.hpp"
00046 #include <Teuchos_RCP.hpp>
00047 
00048 // forward declarations of Teuchos classes
00049 namespace std {
00050   template <typename CharT> class char_traits;
00051 }
00052 namespace Teuchos {
00053   class ParameterList;
00054   template <typename T> class ArrayRCP;
00055   template <typename T> class ArrayView;
00056   template <typename T> class RCP;
00057   template <typename CharT, typename Traits> class basic_FancyOStream;
00058   typedef basic_FancyOStream<char, std::char_traits<char> > FancyOStream;
00059 }
00060 
00061 namespace Kokkos {
00062 
00063   using Teuchos::ArrayRCP;
00064   using Teuchos::ArrayView;
00065   using Teuchos::RCP;
00066 
00070   class CUDANodeMemoryModel {
00071     public:
00073       static const bool isHostNode = false;
00074       static const bool isCUDANode = true;
00075 
00077 
00079       CUDANodeMemoryModel();
00080 
00082 
00084 
00098       template <class T> inline
00099       ArrayRCP<T> allocBuffer(size_t size);
00100 
00112       template <class T> inline
00113       void copyFromBuffer(size_t size, const ArrayRCP<const T> &buffSrc, const ArrayView<T> &hostDest);
00114 
00126       template <class T> inline
00127       void copyToBuffer(size_t size, const ArrayView<const T> &hostSrc, const ArrayRCP<T> &buffDest);
00128 
00137       template <class T> inline
00138       void copyBuffers(size_t size, const ArrayRCP<const T> &buffSrc, const ArrayRCP<T> &buffDest);
00139 
00145       template <class T> inline
00146       ArrayRCP<const T> viewBuffer(size_t size, ArrayRCP<const T> buff);
00147 
00161       template <class T> inline
00162       ArrayRCP<T> viewBufferNonConst(ReadWriteOption rw, size_t size, const ArrayRCP<T> &buff);
00163 
00164       inline void readyBuffers(ArrayView<ArrayRCP<const char> > buffers, ArrayView<ArrayRCP<char> > ncBuffers);
00165 
00167 
00169 
00171       void printStatistics(const RCP< Teuchos::FancyOStream > &os) const;
00172       
00174       void clearStatistics();
00175 
00177 
00178     public:
00179       size_t allocSize_;
00180       size_t numCopiesD2H_, numCopiesH2D_, numCopiesD2D_;
00181       size_t bytesCopiedD2H_, bytesCopiedH2D_, bytesCopiedD2D_;
00182   };
00183 
00184 } // end of namespace Kokkos
00185 
00186 #ifndef KOKKOS_NO_INCLUDE_INSTANTIATIONS
00187 #include "Kokkos_CUDANodeMemoryModelImpl.hpp"
00188 #endif
00189 
00190 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends