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 fence() ;
144 
146  static void print_configuration( std::ostream & , const bool detail = false );
147 
149  static void finalize() ;
150 
154  struct SelectDevice {
155  int rocm_device_id ;
156  SelectDevice() : rocm_device_id(1) {}
157  explicit SelectDevice( int id ) : rocm_device_id( id+1 ) {}
158  };
159 
160  int rocm_device() const { return m_device ; }
161  bool isAPU();
162  bool isAPU(int device);
163 
164  static void initialize( const SelectDevice = SelectDevice());
165 
166  static int is_initialized();
167 
168 // static size_type device_arch();
169 
170 // static size_type detect_device_count();
171 
172 
173  static int concurrency() ;
174  static const char* name();
175 private:
176  int m_device ;
177 
178 };
179 }
180 } // namespace Kokkos
181 
182 namespace Kokkos {
183 namespace Impl {
184 
185 template<>
186 struct MemorySpaceAccess
187  < Kokkos::Experimental::ROCmSpace
188  , Kokkos::Experimental::ROCm::scratch_memory_space
189  >
190 {
191  enum { assignable = false };
192  enum { accessible = true };
193  enum { deepcopy = false };
194 };
195 
196 template<>
197 struct VerifyExecutionCanAccessMemorySpace
198  < Kokkos::Experimental::ROCm::memory_space
199  , Kokkos::Experimental::ROCm::scratch_memory_space
200  >
201 {
202  enum { value = true };
203  KOKKOS_INLINE_FUNCTION static void verify( void ) { }
204  KOKKOS_INLINE_FUNCTION static void verify( const void * ) { }
205 };
206 
207 template<>
208 struct VerifyExecutionCanAccessMemorySpace
209  < Kokkos::HostSpace
210  , Kokkos::Experimental::ROCm::scratch_memory_space
211  >
212 {
213  enum { value = false };
214  inline static void verify( void ) { Kokkos::Experimental::ROCmSpace::access_error(); }
215  inline static void verify( const void * p ) { Kokkos::Experimental::ROCmSpace::access_error(p); }
216 };
217 
218 } // namespace Experimental
219 } // namespace Kokkos
220 
221 
222 
223 
224 
225 #define threadIdx_x (hc_get_workitem_id(0))
226 #define threadIdx_y (hc_get_workitem_id(1))
227 #define threadIdx_z (hc_get_workitem_id(2))
228 
229 #define blockIdx_x (hc_get_group_id(0))
230 #define blockIdx_y (hc_get_group_id(1))
231 #define blockIdx_z (hc_get_group_id(2))
232 
233 #define blockDim_x (hc_get_group_size(0))
234 #define blockDim_y (hc_get_group_size(1))
235 #define blockDim_z (hc_get_group_size(2))
236 
237 #define gridDim_x (hc_get_num_groups(0))
238 #define gridDim_y (hc_get_num_groups(1))
239 #define gridDim_z (hc_get_num_groups(2))
240 
241 
242 #include <ROCm/Kokkos_ROCm_Parallel.hpp>
243 #include <ROCm/Kokkos_ROCm_Task.hpp>
244 
245 #endif
246 #endif
247 
248 
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.