44 #ifndef KOKKOS_SCRATCHSPACE_HPP
45 #define KOKKOS_SCRATCHSPACE_HPP
48 #include <Kokkos_Core_fwd.hpp>
49 #include <Kokkos_Concepts.hpp>
58 template<
class ExecSpace >
60 static_assert (is_execution_space<ExecSpace>::value,
"Instantiating ScratchMemorySpace on non-execution-space type.");
69 mutable char * m_iter_L0 ;
71 mutable char * m_iter_L1 ;
75 mutable int m_multiplier;
77 mutable int m_default_level;
82 enum { MASK = ALIGN - 1 };
88 typedef ExecSpace execution_space ;
90 typedef Kokkos::Device<execution_space,memory_space>
device_type;
92 typedef typename ExecSpace::array_layout array_layout ;
93 typedef typename ExecSpace::size_type size_type ;
95 template<
typename IntType >
96 KOKKOS_INLINE_FUNCTION
static
97 IntType align(
const IntType & size )
98 {
return ( size + MASK ) & ~MASK ; }
100 template<
typename IntType >
101 KOKKOS_INLINE_FUNCTION
102 void* get_shmem (
const IntType& size,
int level = -1)
const {
104 level = m_default_level;
106 void* tmp = m_iter_L0 + m_offset * align (size);
107 if (m_end_L0 < (m_iter_L0 += align (size) * m_multiplier)) {
108 m_iter_L0 -= align (size) * m_multiplier;
113 printf (
"ScratchMemorySpace<...>::get_shmem: Failed to allocate "
114 "%ld byte(s); remaining capacity is %ld byte(s)\n",
long(size),
115 long(m_end_L0-m_iter_L0));
116 #endif // KOKKOS_DEBUG
121 void* tmp = m_iter_L1 + m_offset * align (size);
122 if (m_end_L1 < (m_iter_L1 += align (size) * m_multiplier)) {
123 m_iter_L1 -= align (size) * m_multiplier;
128 printf (
"ScratchMemorySpace<...>::get_shmem: Failed to allocate "
129 "%ld byte(s); remaining capacity is %ld byte(s)\n",
long(size),
130 long(m_end_L1-m_iter_L1));
131 #endif // KOKKOS_DEBUG
140 KOKKOS_INLINE_FUNCTION
141 void* get_shmem_aligned (
const ptrdiff_t size,
const ptrdiff_t alignment,
int level = -1)
const {
143 level = m_default_level;
146 char* previous = m_iter_L0;
147 const ptrdiff_t missalign = size_t(m_iter_L0)%alignment;
148 if(missalign) m_iter_L0 += alignment-missalign;
150 void* tmp = m_iter_L0 + m_offset * size;
151 if (m_end_L0 < (m_iter_L0 += size * m_multiplier)) {
152 m_iter_L0 = previous;
157 printf (
"ScratchMemorySpace<...>::get_shmem: Failed to allocate "
158 "%ld byte(s); remaining capacity is %ld byte(s)\n",
long(size),
159 long(m_end_L0-m_iter_L0));
160 #endif // KOKKOS_DEBUG
166 char* previous = m_iter_L1;
167 const ptrdiff_t missalign = size_t(m_iter_L1)%alignment;
168 if(missalign) m_iter_L1 += alignment-missalign;
170 void* tmp = m_iter_L1 + m_offset * size;
171 if (m_end_L1 < (m_iter_L1 += size * m_multiplier)) {
172 m_iter_L1 = previous;
177 printf (
"ScratchMemorySpace<...>::get_shmem: Failed to allocate "
178 "%ld byte(s); remaining capacity is %ld byte(s)\n",
long(size),
179 long(m_end_L1-m_iter_L1));
180 #endif // KOKKOS_DEBUG
188 template<
typename IntType >
189 KOKKOS_INLINE_FUNCTION
190 ScratchMemorySpace(
void * ptr_L0 ,
const IntType & size_L0 ,
void * ptr_L1 = NULL ,
const IntType & size_L1 = 0)
191 : m_iter_L0( (char *) ptr_L0 )
192 , m_end_L0( m_iter_L0 + size_L0 )
193 , m_iter_L1( (char *) ptr_L1 )
194 , m_end_L1( m_iter_L1 + size_L1 )
197 , m_default_level( 0 )
200 KOKKOS_INLINE_FUNCTION
201 const ScratchMemorySpace& set_team_thread_mode(
const int& level,
const int& multiplier,
const int& offset)
const {
202 m_default_level = level;
203 m_multiplier = multiplier;
Scratch memory space associated with an execution space.
ScratchMemorySpace memory_space
Tag this class as a memory space.
Kokkos::Device< execution_space, memory_space > device_type
This execution space preferred device_type.