Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Kokkos_NodeHelpers.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_NODE_HELPERS_HPP_
00043 #define KOKKOS_NODE_HELPERS_HPP_
00044 
00045 #include <Kokkos_NodeAPIConfigDefs.hpp>
00046 #include "Teuchos_Array.hpp"
00047 #include "Teuchos_ArrayRCP.hpp"
00048 
00049 namespace Kokkos {
00050 
00125   template <class Node>
00126   class ReadyBufferHelper {
00127   public:
00129     ReadyBufferHelper(RCP<Node> node);
00130 
00132     virtual ~ReadyBufferHelper();
00133 
00135     void begin();
00136 
00138     template <class T>
00139     const T* addConstBuffer(ArrayRCP<const T> buff);
00140 
00142     template <class T>
00143     T* addNonConstBuffer(ArrayRCP<T> buff);
00144 
00146     void end();
00147 
00148   protected:
00150     RCP<Node> node_;
00152     Array<ArrayRCP<const char> >  cbufs_;
00154     Array<ArrayRCP<      char> > ncbufs_;
00155   };
00156 
00157   template <class Node>
00158   ReadyBufferHelper<Node>::ReadyBufferHelper (RCP<Node> node)
00159     : node_(node)
00160   {}
00161 
00162   template <class Node>
00163   ReadyBufferHelper<Node>::~ReadyBufferHelper()
00164   {}
00165 
00166   template <class Node>
00167   void ReadyBufferHelper<Node>::begin() {
00168     cbufs_.clear ();
00169     ncbufs_.clear ();
00170   }
00171 
00172   template <class Node>
00173   template <class T>
00174   const T* ReadyBufferHelper<Node>::addConstBuffer (ArrayRCP<const T> buff) {
00175     cbufs_.push_back (arcp_reinterpret_cast<const char> (buff));
00176     return buff.get ();
00177   }
00178 
00179   template <class Node>
00180   template <class T>
00181   T* ReadyBufferHelper<Node>::addNonConstBuffer (ArrayRCP<T> buff) {
00182     cbufs_.push_back (arcp_reinterpret_cast<char> (buff));
00183     return buff.get ();
00184   }
00185 
00186   template <class Node>
00187   void ReadyBufferHelper<Node>::end () {
00188     node_->readyBuffers (cbufs_ (), ncbufs_ ());
00189   }
00190 
00208   template <class Node>
00209   class ArrayOfViewsHelper {
00210   public:
00226     template <class T>
00227     static ArrayRCP<ArrayRCP<T> >
00228     getArrayOfNonConstViews (const RCP<Node> &node,
00229                              ReadWriteOption rw,
00230                              const ArrayRCP<ArrayRCP<T> > &arrayOfBuffers);
00231   private:
00233     ArrayOfViewsHelper();
00234   };
00235 
00236   template <class Node>
00237   template <class T>
00238   ArrayRCP<ArrayRCP<T> >
00239   ArrayOfViewsHelper<Node>::getArrayOfNonConstViews(const RCP<Node> &node, ReadWriteOption rw, const ArrayRCP<ArrayRCP<T> > &arrayOfBuffers) {
00240     ArrayRCP< ArrayRCP<T> > arrayofviews;
00241     const size_t numBufs = arrayOfBuffers.size();
00242     if (numBufs > 0) {
00243       arrayofviews = arcp< ArrayRCP<T> >(numBufs);
00244       for (size_t i=0; i < numBufs; ++i) {
00245         if (arrayOfBuffers[i].size() > 0) {
00246           arrayofviews[i] = node->template viewBufferNonConst<T>(rw,arrayOfBuffers[i].size(),arrayOfBuffers[i]);
00247         }
00248       }
00249     }
00250     return arrayofviews;
00251   }
00252 
00254   template <class Node>
00255   class ArrayOfViewsHelperTrivialImpl {
00256   public:
00257     template <class T>
00258     static ArrayRCP<ArrayRCP<T> > getArrayOfNonConstViews(const RCP<Node> &node, ReadWriteOption rw, const ArrayRCP<ArrayRCP<T> > &arrayOfBuffers);
00259   private:
00261     ArrayOfViewsHelperTrivialImpl();
00262     ~ArrayOfViewsHelperTrivialImpl();
00263   };
00264 
00265   template <class Node>
00266   template <class T>
00267   ArrayRCP<ArrayRCP<T> >
00268   ArrayOfViewsHelperTrivialImpl<Node>::getArrayOfNonConstViews(const RCP<Node> &node, ReadWriteOption rw, const ArrayRCP<ArrayRCP<T> > &arrayOfBuffers) {
00269     (void)node;
00270     (void)rw;
00271     return arrayOfBuffers;
00272   }
00273 
00274 } // end of namespace Kokkos
00275 
00276 
00277 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends