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_ENABLE_SERIAL )
53 #include <Kokkos_Serial.hpp>
54 #endif
55 
56 #if defined( KOKKOS_ENABLE_OPENMP )
57 #include <Kokkos_OpenMP.hpp>
58 #endif
59 
60 //#if defined( KOKKOS_ENABLE_OPENMPTARGET )
61 #include <Kokkos_OpenMPTarget.hpp>
62 #include <Kokkos_OpenMPTargetSpace.hpp>
63 //#endif
64 
65 #if defined( KOKKOS_ENABLE_QTHREADS )
66 #include <Kokkos_Qthreads.hpp>
67 #endif
68 
69 #if defined( KOKKOS_ENABLE_THREADS )
70 #include <Kokkos_Threads.hpp>
71 #endif
72 
73 #if defined( KOKKOS_ENABLE_CUDA )
74 #include <Kokkos_Cuda.hpp>
75 #endif
76 
77 #include <Kokkos_Pair.hpp>
78 #include <Kokkos_MemoryPool.hpp>
79 #include <Kokkos_Array.hpp>
80 #include <Kokkos_View.hpp>
81 #include <Kokkos_Vectorization.hpp>
82 #include <Kokkos_Atomic.hpp>
83 #include <Kokkos_hwloc.hpp>
84 #include <Kokkos_Timer.hpp>
85 
86 #include <Kokkos_Complex.hpp>
87 
88 #include <iosfwd>
89 
90 //----------------------------------------------------------------------------
91 
92 namespace Kokkos {
93 
94 struct InitArguments {
95  int num_threads;
96  int num_numa;
97  int device_id;
98 
99  InitArguments() {
100  num_threads = -1;
101  num_numa = -1;
102  device_id = -1;
103  }
104 };
105 
106 void initialize(int& narg, char* arg[]);
107 
108 void initialize(const InitArguments& args = InitArguments());
109 
111 void finalize();
112 
114 void finalize_all();
115 
116 void fence();
117 
119 void print_configuration( std::ostream & , const bool detail = false );
120 
121 } // namespace Kokkos
122 
123 //----------------------------------------------------------------------------
124 //----------------------------------------------------------------------------
125 
126 namespace Kokkos {
127 
128 /* Allocate memory from a memory space.
129  * The allocation is tracked in Kokkos memory tracking system, so
130  * leaked memory can be identified.
131  */
132 template< class Space = typename Kokkos::DefaultExecutionSpace::memory_space >
133 inline
134 void * kokkos_malloc( const std::string & arg_alloc_label
135  , const size_t arg_alloc_size )
136 {
137  typedef typename Space::memory_space MemorySpace ;
138  return Impl::SharedAllocationRecord< MemorySpace >::
139  allocate_tracked( MemorySpace() , arg_alloc_label , arg_alloc_size );
140 }
141 
142 template< class Space = typename Kokkos::DefaultExecutionSpace::memory_space >
143 inline
144 void * kokkos_malloc( const size_t arg_alloc_size )
145 {
146  typedef typename Space::memory_space MemorySpace ;
147  return Impl::SharedAllocationRecord< MemorySpace >::
148  allocate_tracked( MemorySpace() , "no-label" , arg_alloc_size );
149 }
150 
151 template< class Space = typename Kokkos::DefaultExecutionSpace::memory_space >
152 inline
153 void kokkos_free( void * arg_alloc )
154 {
155  typedef typename Space::memory_space MemorySpace ;
156  return Impl::SharedAllocationRecord< MemorySpace >::
157  deallocate_tracked( arg_alloc );
158 }
159 
160 template< class Space = typename Kokkos::DefaultExecutionSpace::memory_space >
161 inline
162 void * kokkos_realloc( void * arg_alloc , const size_t arg_alloc_size )
163 {
164  typedef typename Space::memory_space MemorySpace ;
165  return Impl::SharedAllocationRecord< MemorySpace >::
166  reallocate_tracked( arg_alloc , arg_alloc_size );
167 }
168 
169 } // namespace Kokkos
170 
171 //----------------------------------------------------------------------------
172 //----------------------------------------------------------------------------
173 
174 #endif
175 
Declaration and definition of Kokkos::Vectorization interface.
void print_configuration(std::ostream &, const bool detail=false)
Print "Bill of Materials".
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.