|
Kokkos Core Kernels Package
Version of the Day
|
00001 /* 00002 //@HEADER 00003 // ************************************************************************ 00004 // 00005 // Kokkos: Manycore Performance-Portable Multidimensional Arrays 00006 // Copyright (2012) Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov) 00039 // 00040 // ************************************************************************ 00041 //@HEADER 00042 */ 00043 00044 #ifndef KOKKOS_THREADS_HPP 00045 #define KOKKOS_THREADS_HPP 00046 00047 #include <Kokkos_Core_fwd.hpp> 00048 00049 #if defined( KOKKOS_HAVE_PTHREAD ) 00050 00051 #include <cstddef> 00052 #include <iosfwd> 00053 #include <Kokkos_HostSpace.hpp> 00054 #include <Kokkos_ScratchSpace.hpp> 00055 #include <Kokkos_Layout.hpp> 00056 #include <Kokkos_MemoryTraits.hpp> 00057 #include <impl/Kokkos_Tags.hpp> 00058 00059 /*--------------------------------------------------------------------------*/ 00060 00061 namespace Kokkos { 00062 namespace Impl { 00063 class ThreadsExec ; 00064 } // namespace Impl 00065 } // namespace Kokkos 00066 00067 /*--------------------------------------------------------------------------*/ 00068 00069 namespace Kokkos { 00070 00072 class Threads { 00073 public: 00075 00076 00077 typedef Impl::ExecutionSpaceTag kokkos_tag ; 00078 00079 typedef Threads device_type ; 00080 typedef Threads execution_space ; 00081 typedef Kokkos::HostSpace memory_space ; 00082 typedef memory_space::size_type size_type ; 00083 typedef Kokkos::LayoutRight array_layout ; 00084 typedef Kokkos::Threads host_mirror_device_type ; 00085 00086 typedef ScratchMemorySpace< Threads > scratch_memory_space ; 00088 /*------------------------------------------------------------------------*/ 00090 00091 00094 static int in_parallel(); 00095 00107 static bool sleep(); 00108 00114 static bool wake(); 00115 00122 static void fence(); 00123 00127 static void finalize(); 00128 00130 static void print_configuration( std::ostream & , const bool detail = false ); 00131 00133 /*------------------------------------------------------------------------*/ 00134 /*------------------------------------------------------------------------*/ 00136 00137 00155 static void initialize( unsigned threads_count = 1 , 00156 unsigned use_numa_count = 0 , 00157 unsigned use_cores_per_numa = 0 , 00158 bool allow_asynchronous_threadpool = false ); 00159 00160 static int is_initialized(); 00161 00162 static Threads & instance( int = 0 ); 00163 00164 //---------------------------------------- 00172 static int thread_pool_size( int depth = 0 ); 00173 #if defined( KOKKOS_ACTIVE_EXECUTION_MEMORY_SPACE_HOST ) 00174 static int thread_pool_rank(); 00175 #else 00176 KOKKOS_INLINE_FUNCTION static int thread_pool_rank() { return 0 ; } 00177 #endif 00178 00179 inline static unsigned team_recommended() { return thread_pool_size(2); } 00180 inline static unsigned team_max() { return thread_pool_size(1); } 00181 00182 inline static unsigned max_hardware_threads() { return thread_pool_size(0); } 00183 KOKKOS_INLINE_FUNCTION static unsigned hardware_thread_id() { return thread_pool_rank(); } 00184 00186 //---------------------------------------- 00187 }; 00188 00189 } // namespace Kokkos 00190 00191 /*--------------------------------------------------------------------------*/ 00192 00193 namespace Kokkos { 00194 namespace Impl { 00195 00196 template<> 00197 struct VerifyExecutionCanAccessMemorySpace 00198 < Kokkos::Threads::memory_space 00199 , Kokkos::Threads::scratch_memory_space 00200 > 00201 { 00202 inline static void verify( void ) { } 00203 inline static void verify( const void * ) { } 00204 }; 00205 00206 } // namespace Impl 00207 } // namespace Kokkos 00208 00209 /*--------------------------------------------------------------------------*/ 00210 00211 #include <Kokkos_ExecPolicy.hpp> 00212 #include <Kokkos_Parallel.hpp> 00213 #include <Threads/Kokkos_ThreadsExec.hpp> 00214 #include <Threads/Kokkos_Threads_Parallel.hpp> 00215 00216 //---------------------------------------------------------------------------- 00217 //---------------------------------------------------------------------------- 00218 00219 #endif /* #if defined( KOKKOS_HAVE_PTHREAD ) */ 00220 #endif /* #define KOKKOS_THREADS_HPP */ 00221 00222
1.7.6.1