Kokkos Core Kernels Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Kokkos_ROCm.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 Christian R. Trott (crtrott@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef KOKKOS_ROCM_HPP
45 #define KOKKOS_ROCM_HPP
46 
47 #include <Kokkos_Core_fwd.hpp>
48 
49 #if defined( KOKKOS_ENABLE_ROCM )
50 
51 class dim3 {
52 public:
53 int x,y,z;
54 dim3(int _x, int _y, int _z):x(_x),y(_y),z(_z) {};
55 };
56 
57 #include <ROCm/hc_math_std.hpp>
58 //----------------------------------------------------------------------------
59 //----------------------------------------------------------------------------
60 
61 #include <cstddef>
62 #include <iosfwd>
63 #include <Kokkos_HostSpace.hpp>
64 #include <Kokkos_ROCmSpace.hpp>
65 #include <ROCm/Kokkos_ROCm_Exec.hpp>
66 #include <Kokkos_ScratchSpace.hpp>
67 #include <Kokkos_Parallel.hpp>
68 #include <Kokkos_Layout.hpp>
69 #include <impl/Kokkos_Tags.hpp>
70 
71 /*--------------------------------------------------------------------------*/
72 
73 #include <hc.hpp>
74 #include <hc_am.hpp>
75 #include <amp_math.h>
76 
77 #if defined( __HCC_ACCELERATOR__ )
78 
79 using namespace ::Concurrency::precise_math ;
80 
81 #endif
82 
83 /*--------------------------------------------------------------------------*/
84 
85 namespace Kokkos {
86 namespace Impl {
87 class ROCmExec ;
88 } // namespace Impl
89 } // namespace Kokkos
90 
91 /*--------------------------------------------------------------------------*/
92 
93 namespace Kokkos {
94 namespace Experimental {
97 class ROCm {
98 public:
99  //------------------------------------
101 
102 
104  typedef ROCm execution_space ;
105  typedef ROCmSpace memory_space ;
106  typedef Kokkos::Device<execution_space,memory_space> device_type;
107 
108  typedef LayoutLeft array_layout ;
109  typedef HostSpace::size_type size_type ;
110 
111  typedef ScratchMemorySpace< ROCm > scratch_memory_space ;
112 
113  ~ROCm() {}
114  ROCm();
115 // explicit ROCm( const int instance_id );
116 
117  ROCm( ROCm && ) = default ;
118  ROCm( const ROCm & ) = default ;
119  ROCm & operator = ( ROCm && ) = default ;
120  ROCm & operator = ( const ROCm & ) = default ;
121 
122 
124  //------------------------------------
126 
127 
128  KOKKOS_INLINE_FUNCTION static int in_parallel() {
129 #if defined( __HCC_ACCELERATOR__ )
130  return true;
131 #else
132  return false;
133 #endif
134  }
135 
137  static bool sleep() ;
138 
140  static bool wake() ;
141 
143  static void impl_static_fence();
144 
145  #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
146  static void fence();
147  #else
148  void fence() const;
149  #endif
150 
151 
153  static void print_configuration( std::ostream & , const bool detail = false );
154 
156  static void finalize() ;
157 
161  struct SelectDevice {
162  int rocm_device_id ;
163  SelectDevice() : rocm_device_id(1) {}
164  explicit SelectDevice( int id ) : rocm_device_id( id+1 ) {}
165  };
166 
167  int rocm_device() const { return m_device ; }
168  bool isAPU();
169  bool isAPU(int device);
170 
171  static void initialize( const SelectDevice = SelectDevice());
172 
173  static int is_initialized();
174 
175 // static size_type device_arch();
176 
177 // static size_type detect_device_count();
178 
179 
180  static int concurrency() ;
181  static const char* name();
182 private:
183  int m_device ;
184 
185 };
186 }
187 } // namespace Kokkos
188 
189 namespace Kokkos {
190 namespace Impl {
191 
192 template<>
193 struct MemorySpaceAccess
194  < Kokkos::Experimental::ROCmSpace
195  , Kokkos::Experimental::ROCm::scratch_memory_space
196  >
197 {
198  enum { assignable = false };
199  enum { accessible = true };
200  enum { deepcopy = false };
201 };
202 
203 template<>
204 struct VerifyExecutionCanAccessMemorySpace
205  < Kokkos::Experimental::ROCm::memory_space
206  , Kokkos::Experimental::ROCm::scratch_memory_space
207  >
208 {
209  enum { value = true };
210  KOKKOS_INLINE_FUNCTION static void verify( void ) { }
211  KOKKOS_INLINE_FUNCTION static void verify( const void * ) { }
212 };
213 
214 template<>
215 struct VerifyExecutionCanAccessMemorySpace
216  < Kokkos::HostSpace
217  , Kokkos::Experimental::ROCm::scratch_memory_space
218  >
219 {
220  enum { value = false };
221  inline static void verify( void ) { Kokkos::Experimental::ROCmSpace::access_error(); }
222  inline static void verify( const void * p ) { Kokkos::Experimental::ROCmSpace::access_error(p); }
223 };
224 
225 } // namespace Experimental
226 } // namespace Kokkos
227 
228 
229 
230 
231 
232 #define threadIdx_x (hc_get_workitem_id(0))
233 #define threadIdx_y (hc_get_workitem_id(1))
234 #define threadIdx_z (hc_get_workitem_id(2))
235 
236 #define blockIdx_x (hc_get_group_id(0))
237 #define blockIdx_y (hc_get_group_id(1))
238 #define blockIdx_z (hc_get_group_id(2))
239 
240 #define blockDim_x (hc_get_group_size(0))
241 #define blockDim_y (hc_get_group_size(1))
242 #define blockDim_z (hc_get_group_size(2))
243 
244 #define gridDim_x (hc_get_num_groups(0))
245 #define gridDim_y (hc_get_num_groups(1))
246 #define gridDim_z (hc_get_num_groups(2))
247 
248 
249 #include <ROCm/Kokkos_ROCm_Parallel.hpp>
250 #include <ROCm/Kokkos_ROCm_Task.hpp>
251 
252 #endif
253 #endif
254 
255 
void print_configuration(std::ostream &, const bool detail=false)
Print &quot;Bill of Materials&quot;.
Declaration of various MemoryLayout options.
Declaration of parallel operators.
void finalize()
Finalize the spaces that were initialized via Kokkos::initialize.