1#ifndef BLOCK_MAP_GPU_KER_CUH_
2#define BLOCK_MAP_GPU_KER_CUH_
4#include "util/cuda_util.hpp"
6#include "Vector/map_vector_sparse.hpp"
7#include "DataBlock.cuh"
8#include "TemplateUtils/encap_shmem.hpp"
10template<
typename AggregateT,
unsigned int p>
11using BlockTypeOf =
typename std::remove_reference<typename boost::fusion::result_of::at_c<typename AggregateT::type, p>::type>::type;
13template<
typename AggregateT,
unsigned int p>
14using ScalarTypeOf =
typename std::remove_reference<typename boost::fusion::result_of::at_c<typename AggregateT::type, p>::type>::type::scalarType;
16template <
typename AggregateT>
19 static const unsigned int value = AggregateT::max_prop_real - 1;
22template <
typename AggregateT,
unsigned int pMask>
36 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
46 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
50 template <
unsigned int p>
51 inline auto get() ->
decltype(
aggregate.template get<p>())
56 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
60 inline auto getMask() ->
decltype(
aggregate.template get<pMask>())
65 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
70template<
typename AggregateBlockT=aggregate<DataBlock<
float, 64>>,
typename indexT=
int,
template<
typename>
class layout_base=
memory_traits_inte>
75 const static unsigned char EXIST_BIT = 0;
78 static const unsigned int pMask = AggregateBlockT::max_prop_real - 1;
79 typedef AggregateBlockT AggregateType;
83 template<
typename BitMaskT>
84 inline static __device__ __host__
bool getBit(
const BitMaskT &bitMask,
unsigned char pos)
86 return (bitMask>>pos)&1U;
89 template<
typename BitMaskT>
90 inline static __device__ __host__
void setBit(BitMaskT &bitMask,
unsigned char pos)
92 bitMask = bitMask | (1U<<pos);
95 template<
typename BitMaskT>
96 inline static __device__ __host__
void unsetBit(BitMaskT &bitMask,
unsigned char pos)
98 bitMask = bitMask & ~(1U<<pos);
103 : blockMap(blockMap) {};
105 template<
unsigned int p>
106 inline __device__
auto get(
unsigned int linId)
const -> ScalarTypeOf<AggregateBlockT, p>
109 typedef BlockTypeOf<AggregateBlockT, p> BlockT;
110 unsigned int blockId = linId / BlockT::size;
111 unsigned int offset = linId % BlockT::size;
112 return get<p>(blockId, offset);
114 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
119 template<
unsigned int p>
120 inline __device__
auto get(
unsigned int blockId,
unsigned int offset)
const -> ScalarTypeOf<AggregateBlockT, p>
124 const auto sid = blockMap.
get_sparse(blockId);
125 const auto & block = blockMap.template get_ele<p>(sid.id)[offset];
126 const auto mask = blockMap.template get_ele<pMask>(sid.id)[offset];
130 : blockMap.template getBackground<p>()[offset];
133 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
137 inline __device__
auto getBlock(
unsigned int blockId) ->
decltype(blockMap.
get(0))
140 return blockMap.
get(blockId);
142 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
146 template<
unsigned int p>
147 inline __device__ ScalarTypeOf<AggregateBlockT, p> & getReference(
unsigned int linId)
151 typedef BlockTypeOf<AggregateBlockT, p> BlockT;
152 unsigned int blockId = linId / BlockT::size;
153 unsigned int offset = linId % BlockT::size;
154 return getReference<p>(blockId, offset);
156 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
160 template<
unsigned int p>
161 inline __device__ ScalarTypeOf<AggregateBlockT, p> & getReference(
unsigned int blockId,
unsigned int offset)
165 return blockMap.template get<p>(blockId)[offset];
167 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
171 template<
unsigned int p>
172 inline __device__
auto insert(
unsigned int linId) -> ScalarTypeOf<AggregateBlockT, p>&
175 typedef BlockTypeOf<AggregateBlockT, p> BlockT;
176 unsigned int blockId = linId / BlockT::size;
177 unsigned int offset = linId % BlockT::size;
178 return insert<p>(blockId, offset);
180 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
184 template<
unsigned int p>
185 inline __device__
auto insert(
unsigned int blockId,
unsigned int offset) -> ScalarTypeOf<AggregateBlockT, p>&
189 auto &block =
aggregate.template get<p>();
190 auto &mask =
aggregate.template get<pMask>();
191 setExist(mask[offset]);
193 return block[offset];
195 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
199 template<
unsigned int nChunksPerBlocks = 1>
200 inline __device__
auto insertBlock(indexT blockId,
unsigned int stride = 8192) ->
decltype(blockMap.
insert(0))
202 int offset = threadIdx.x / stride;
204 __shared__
int mem_[nChunksPerBlocks];
206 decltype(blockMap.
insert(0)) ec_(blockMap.private_get_data(),0);
209 if (threadIdx.x % stride == 0 && threadIdx.y == 0 && threadIdx.z == 0)
211 auto ec = blockMap.
insert(blockId);
213 mem_[offset] = ec.private_get_k();
221 ec_.private_set_k(mem_[offset]);
225 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
234 inline __device__
void get_sparse(
unsigned int linId,
unsigned int & dataBlockPos ,
unsigned int & offset)
const
238 typedef BlockTypeOf<AggregateBlockT, pMask> BlockT;
239 unsigned int blockId = linId / BlockT::size;
240 offset = linId % BlockT::size;
242 const auto sid = blockMap.
get_sparse(blockId);
244 dataBlockPos = sid.id;
247 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
251 inline static __device__
unsigned int getBlockId(
unsigned int linId)
254 return linId / BlockTypeOf<AggregateBlockT, 0>::size;
256 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
260 inline static __device__
unsigned int getOffset(
unsigned int linId)
263 return linId % BlockTypeOf<AggregateBlockT, 0>::size;
265 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
269 inline __device__
void init()
274 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
278 inline __device__
void flush_block_insert()
283 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
287 template<
typename BitMaskT>
288 inline static __device__
bool exist(
const BitMaskT &bitMask)
290 return getBit(bitMask, EXIST_BIT);
293 template<
typename BitMaskT>
294 inline static __device__
void setExist(BitMaskT &bitMask)
296 setBit(bitMask, EXIST_BIT);
299 template<
typename BitMaskT>
300 inline static __device__
void unsetExist(BitMaskT &bitMask)
302 unsetBit(bitMask, EXIST_BIT);
305 inline __device__ ScalarTypeOf<AggregateBlockT, pMask> getMask(
unsigned int linId)
const
307 return get<pMask>(linId);
310 inline __device__
void remove(
unsigned int linId)
313 typedef BlockTypeOf<AggregateBlockT, pMask> BlockT;
314 unsigned int blockId = linId / BlockT::size;
315 unsigned int offset = linId % BlockT::size;
316 remove(blockId, offset);
318 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
322 inline __device__
void remove(
unsigned int blockId,
unsigned int offset)
326 const auto sid = blockMap.
get_sparse(blockId);
327 blockMap.template get<pMask>(sid)[offset] = 0;
330 std::cout << __FILE__ <<
":" << __LINE__ <<
" error: you are supposed to compile this file with nvcc, if you want to use it with gpu" << std::endl;
365 pc = blockMap.check_device_pointer(ptr);
367 if (pc.
match ==
true)
__device__ auto getIndexBuffer() -> decltype(blockMap.getIndexBuffer())
Return the index buffer for the sparse vector.
__device__ auto getDataBuffer() -> decltype(blockMap.getDataBuffer())
Return the data buffer for the sparse vector.
__device__ void init()
This function must be called.
__device__ openfpm::sparse_index< Ti > get_sparse(Ti id) const
Get the sparse index.
__device__ void flush_block_insert()
It insert an element in the sparse vector.
__device__ auto get(Ti id) const -> decltype(vct_data.template get< p >(id))
Get an element of the vector.
__device__ auto insert(Ti ele) -> decltype(vct_data.template get< p >(0))
It insert an element in the sparse vector.
__device__ auto getIndexBuffer() const -> const decltype(vct_index)&
Get the indices buffer.
__device__ auto getDataBuffer() -> decltype(vct_data)&
Get the data buffer.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Transform the boost::fusion::vector into memory specification (memory_traits)
std::string match_str
match string
bool match
Indicate if the pointer match.