Kokkos Core Kernels Package  Version of the Day
Kokkos_Core.hpp
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Kokkos v. 2.0
6 // Copyright (2014) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact H. Carter Edwards (hcedwar@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_CORE_HPP
45 #define KOKKOS_CORE_HPP
46 
47 //----------------------------------------------------------------------------
48 // Include the execution space header files for the enabled execution spaces.
49 
50 #include <Kokkos_Core_fwd.hpp>
51 
52 #if defined( KOKKOS_HAVE_SERIAL )
53 #include <Kokkos_Serial.hpp>
54 #endif
55 
56 #if defined( KOKKOS_HAVE_OPENMP )
57 #include <Kokkos_OpenMP.hpp>
58 #endif
59 
60 #if defined( KOKKOS_HAVE_PTHREAD )
61 #include <Kokkos_Threads.hpp>
62 #endif
63 
64 #if defined( KOKKOS_HAVE_CUDA )
65 #include <Kokkos_Cuda.hpp>
66 #endif
67 
68 #include <Kokkos_MemoryPool.hpp>
69 #include <Kokkos_Pair.hpp>
70 #include <Kokkos_Array.hpp>
71 #include <Kokkos_View.hpp>
72 #include <Kokkos_Vectorization.hpp>
73 #include <Kokkos_Atomic.hpp>
74 #include <Kokkos_hwloc.hpp>
75 #include <Kokkos_Timer.hpp>
76 
77 #ifdef KOKKOS_HAVE_CXX11
78 #include <Kokkos_Complex.hpp>
79 #endif
80 
81 
82 //----------------------------------------------------------------------------
83 
84 namespace Kokkos {
85 
86 struct InitArguments {
87  int num_threads;
88  int num_numa;
89  int device_id;
90 
91  InitArguments() {
92  num_threads = -1;
93  num_numa = -1;
94  device_id = -1;
95  }
96 };
97 
98 void initialize(int& narg, char* arg[]);
99 
100 void initialize(const InitArguments& args = InitArguments());
101 
103 void finalize();
104 
106 void finalize_all();
107 
108 void fence();
109 
110 } // namespace Kokkos
111 
112 //----------------------------------------------------------------------------
113 //----------------------------------------------------------------------------
114 
115 namespace Kokkos {
116 
117 /* Allocate memory from a memory space.
118  * The allocation is tracked in Kokkos memory tracking system, so
119  * leaked memory can be identified.
120  */
121 template< class Space = typename Kokkos::DefaultExecutionSpace::memory_space >
122 inline
123 void * kokkos_malloc( const std::string & arg_alloc_label
124  , const size_t arg_alloc_size )
125 {
126  typedef typename Space::memory_space MemorySpace ;
127  return Impl::SharedAllocationRecord< MemorySpace >::
128  allocate_tracked( MemorySpace() , arg_alloc_label , arg_alloc_size );
129 }
130 
131 template< class Space = typename Kokkos::DefaultExecutionSpace::memory_space >
132 inline
133 void * kokkos_malloc( const size_t arg_alloc_size )
134 {
135  typedef typename Space::memory_space MemorySpace ;
136  return Impl::SharedAllocationRecord< MemorySpace >::
137  allocate_tracked( MemorySpace() , "no-label" , arg_alloc_size );
138 }
139 
140 template< class Space = typename Kokkos::DefaultExecutionSpace::memory_space >
141 inline
142 void kokkos_free( void * arg_alloc )
143 {
144  typedef typename Space::memory_space MemorySpace ;
145  return Impl::SharedAllocationRecord< MemorySpace >::
146  deallocate_tracked( arg_alloc );
147 }
148 
149 template< class Space = typename Kokkos::DefaultExecutionSpace::memory_space >
150 inline
151 void * kokkos_realloc( void * arg_alloc , const size_t arg_alloc_size )
152 {
153  typedef typename Space::memory_space MemorySpace ;
154  return Impl::SharedAllocationRecord< MemorySpace >::
155  reallocate_tracked( arg_alloc , arg_alloc_size );
156 }
157 
158 } // namespace Kokkos
159 
160 //----------------------------------------------------------------------------
161 //----------------------------------------------------------------------------
162 
163 #endif
164 
Declaration and definition of Kokkos::Vectorization interface.
Declaration and definition of Kokkos::pair.
Declaration and definition of Kokkos::Serial device.
void finalize_all()
Finalize all known execution spaces.
void finalize()
Finalize the spaces that were initialized via Kokkos::initialize.
Atomic functions.