OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
DataBlock.cuh
1 //
2 // Created by tommaso on 14/05/19.
3 //
4 
5 #ifndef OPENFPM_PDATA_DATABLOCK_CUH
6 #define OPENFPM_PDATA_DATABLOCK_CUH
7 
8 #include <cstdlib>
9 #include "util/cuda_util.hpp"
10 #include <cstring>
11 
12 //todo: Copy the new DataBlock definition here (the one where bitmask is external)
13 //todo: Rename static exist/setBit methods to getBit and setBit which can work with generic bitmasks
14 
15 template<typename ScalarT, unsigned int DataBlockSize=64>
16 struct DataBlock
17 {
18  typedef ScalarT scalarType;
19 
20  typedef ScalarT value_type;
21 
22  static const unsigned int EXISTBIT = 0;
23 
24  static const unsigned int size = DataBlockSize;
25  ScalarT block[size];
26 
27  __device__ __host__ DataBlock() = default;
28 
29  __device__ __host__ DataBlock(const DataBlock &other)
30  {
31 #ifdef __CUDA_ARCH__
32 #ifdef __NVCC__
33  block[threadIdx.x % size] = other.block[threadIdx.x % size];
34 #endif // __NVCC__
35 #else // __CUDA_ARCH__
36  memcpy(block, other.block, size * sizeof(ScalarT));
37 #endif // __CUDA_ARCH__
38  }
39 
40  __device__ __host__ inline DataBlock & operator=(const DataBlock &other)
41  {
42 #ifdef __CUDA_ARCH__
43 #ifdef __NVCC__
44  block[threadIdx.x % size] = other.block[threadIdx.x % size];
45 #endif // __NVCC__
46 #else
47  memcpy(block, other.block, size * sizeof(ScalarT));
48 #endif
49  return *this;
50  }
51 
52  __device__ __host__ inline DataBlock & operator=(ScalarT v)
53  {
54 #ifdef __CUDA_ARCH__
55 #ifdef __NVCC__
56  block[threadIdx.x % size] = v;
57 #endif // __NVCC__
58 #else
59  for (unsigned int i = 0; i < size; ++i)
60  {
61  block[i] = v;
62  }
63 #endif
64  return *this;
65  }
66 
67  __device__ __host__ inline ScalarT &operator[](unsigned int i)
68  {
69  return block[i];
70  }
71 
72  __device__ __host__ inline const ScalarT &operator[](unsigned int i) const
73  {
74  return block[i];
75  }
76 };
77 
78 #endif //OPENFPM_PDATA_DATABLOCK_CUH