|
Kokkos Core Kernels Package
Version of the Day
|
00001 /* 00002 //@HEADER 00003 // ************************************************************************ 00004 // 00005 // Kokkos 00006 // Manycore Performance-Portable Multidimensional Arrays 00007 // 00008 // Copyright (2012) Sandia Corporation 00009 // 00010 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00011 // the U.S. Government retains certain rights in this software. 00012 // 00013 // Redistribution and use in source and binary forms, with or without 00014 // modification, are permitted provided that the following conditions are 00015 // met: 00016 // 00017 // 1. Redistributions of source code must retain the above copyright 00018 // notice, this list of conditions and the following disclaimer. 00019 // 00020 // 2. Redistributions in binary form must reproduce the above copyright 00021 // notice, this list of conditions and the following disclaimer in the 00022 // documentation and/or other materials provided with the distribution. 00023 // 00024 // 3. Neither the name of the Corporation nor the names of the 00025 // contributors may be used to endorse or promote products derived from 00026 // this software without specific prior written permission. 00027 // 00028 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00029 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00030 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00031 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00032 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00033 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00034 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00035 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00036 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00037 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00038 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 // 00040 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov) 00041 // 00042 // ************************************************************************ 00043 //@HEADER 00044 */ 00045 00046 #ifndef KOKKOS_CUDA_HPP 00047 #define KOKKOS_CUDA_HPP 00048 00049 #include <Kokkos_Core_fwd.hpp> 00050 00051 // If CUDA execution space is enabled then use this header file. 00052 00053 #if defined( KOKKOS_HAVE_CUDA ) 00054 00055 #include <iosfwd> 00056 #include <vector> 00057 00058 #include <Kokkos_CudaSpace.hpp> 00059 00060 #include <Kokkos_Parallel.hpp> 00061 #include <Kokkos_Layout.hpp> 00062 #include <Kokkos_ScratchSpace.hpp> 00063 #include <Kokkos_MemoryTraits.hpp> 00064 #include <impl/Kokkos_Tags.hpp> 00065 00066 /*--------------------------------------------------------------------------*/ 00067 00068 namespace Kokkos { 00069 namespace Impl { 00070 class CudaExec ; 00071 } // namespace Impl 00072 } // namespace Kokkos 00073 00074 /*--------------------------------------------------------------------------*/ 00075 00076 namespace Kokkos { 00077 00088 class Cuda { 00089 public: 00091 00092 00094 typedef Impl::ExecutionSpaceTag kokkos_tag ; 00096 typedef Cuda device_type ; 00098 typedef Cuda execution_space ; 00100 typedef CudaSpace memory_space ; 00102 typedef CudaSpace::size_type size_type ; 00104 typedef LayoutLeft array_layout ; 00105 00106 typedef ScratchMemorySpace< Cuda > scratch_memory_space ; 00107 00109 #if defined( KOKKOS_HAVE_OPENMP ) 00110 typedef Kokkos::OpenMP host_mirror_device_type ; 00111 #elif defined( KOKKOS_HAVE_PTHREAD ) 00112 typedef Kokkos::Threads host_mirror_device_type ; 00113 #else 00114 typedef Kokkos::Serial host_mirror_device_type ; 00115 #endif 00116 00118 00119 00120 00123 KOKKOS_INLINE_FUNCTION static int in_parallel() { 00124 #if defined( __CUDA_ARCH__ ) 00125 return true; 00126 #else 00127 return false; 00128 #endif 00129 } 00130 00142 static bool sleep(); 00143 00149 static bool wake(); 00150 00157 static void fence(); 00158 00160 static void finalize(); 00161 00163 static void print_configuration( std::ostream & , const bool detail = false ); 00164 00166 //-------------------------------------------------------------------------- 00168 00169 00170 struct SelectDevice { 00171 int cuda_device_id ; 00172 SelectDevice() : cuda_device_id(0) {} 00173 explicit SelectDevice( int id ) : cuda_device_id( id ) {} 00174 }; 00175 00177 static void initialize( const SelectDevice = SelectDevice() ); 00178 static void initialize( int device ); 00179 static void initialize( int device , int ); 00180 00181 static int is_initialized(); 00182 00186 static size_type device_arch(); 00187 00189 static size_type detect_device_count(); 00190 00194 static std::vector<unsigned> detect_device_arch(); 00195 00196 static unsigned team_max(); 00197 static unsigned team_recommended(); 00198 00200 //-------------------------------------------------------------------------- 00201 }; 00202 00203 } // namespace Kokkos 00204 00205 /*--------------------------------------------------------------------------*/ 00206 /*--------------------------------------------------------------------------*/ 00207 00208 namespace Kokkos { 00209 namespace Impl { 00210 00211 template<> 00212 struct VerifyExecutionCanAccessMemorySpace 00213 < Kokkos::Cuda::memory_space 00214 , Kokkos::Cuda::scratch_memory_space 00215 > 00216 { 00217 KOKKOS_INLINE_FUNCTION static void verify( void ) { } 00218 KOKKOS_INLINE_FUNCTION static void verify( const void * ) { } 00219 }; 00220 00221 template<> 00222 struct VerifyExecutionCanAccessMemorySpace 00223 < Kokkos::HostSpace 00224 , Kokkos::Cuda::scratch_memory_space 00225 > 00226 { 00227 inline static void verify( void ) { CudaSpace::access_error(); } 00228 inline static void verify( const void * p ) { CudaSpace::access_error(p); } 00229 }; 00230 00231 } // namespace Impl 00232 } // namespace Kokkos 00233 00234 /*--------------------------------------------------------------------------*/ 00235 /*--------------------------------------------------------------------------*/ 00236 00237 #include <Cuda/Kokkos_CudaExec.hpp> 00238 #include <Cuda/Kokkos_Cuda_View.hpp> 00239 #include <Cuda/Kokkos_Cuda_Parallel.hpp> 00240 00241 //---------------------------------------------------------------------------- 00242 00243 #endif /* #if defined( KOKKOS_HAVE_CUDA ) */ 00244 #endif /* #ifndef KOKKOS_CUDA_HPP */ 00245 00246 00247
1.7.6.1