41 size_t num_bits_capacity;
47 num_bits_capacity = 0;
55 if (bit_vector != NULL)
60 assert(num_bits == 0);
61 assert(
sizeof(
unsigned long long int) * 8 == 64);
62 assert(
sizeof(uint64_t) * 8 == 64);
63 num_bits_capacity = nbits;
65 CUDA_SAFE_CALL(cudaMalloc(&bit_vector,
vec_size() *
sizeof(uint64_t)));
70 assert(nbits <= num_bits_capacity);
74 __device__ __host__
size_t size()
const {
return num_bits; }
77 size_t bit_vector_size = (num_bits + 63) / 64;
78 return bit_vector_size;
82 return vec_size() *
sizeof(uint64_t);
86 CUDA_SAFE_CALL(cudaMemset(bit_vector, 0,
vec_size() *
sizeof(uint64_t)));
90 __device__
bool test(
const size_t id)
const {
91 size_t bit_index =
id / 64;
92 uint64_t bit_offset = 1;
93 bit_offset <<= (
id % 64);
94 return ((bit_vector[bit_index] & bit_offset) != 0);
97 __device__
void set(
const size_t id) {
98 size_t bit_index =
id / 64;
99 unsigned long long int bit_offset = 1;
100 bit_offset <<= (
id % 64);
101 if ((bit_vector[bit_index] & bit_offset) == 0) {
102 atomicOr((
unsigned long long int*)&bit_vector[bit_index], bit_offset);
108 bit_vector[bit_index] = 0;
114 const uint64_t mask) {
115 bit_vector[bit_index] &= mask;
119 assert(bit_vector_cpu_copy != NULL);
120 CUDA_SAFE_CALL(cudaMemcpy(bit_vector_cpu_copy, bit_vector,
122 cudaMemcpyDeviceToHost));
126 assert(cpu_bit_vector != NULL);
127 CUDA_SAFE_CALL(cudaMemcpy(bit_vector, cpu_bit_vector,
129 cudaMemcpyHostToDevice));
134 :
public std::iterator<std::random_access_iterator_tag, bool> {
141 : bitset(b), offset(i) {}
153 __device__ __host__ __forceinline__
bool
155 return (offset < bi.offset);
158 __device__ __host__ __forceinline__
bool
160 return (offset <= bi.offset);
163 __device__ __host__ __forceinline__
bool
165 return (offset > bi.offset);
168 __device__ __host__ __forceinline__
bool
170 return (offset >= bi.offset);
195 __device__ __host__ __forceinline__ difference_type
197 return (offset - bi.offset);
201 return bitset->
test(offset);
204 __device__ __forceinline__
bool operator[](
const size_t id)
const {
205 return bitset->
test(offset +
id);
210 :
public std::iterator<std::random_access_iterator_tag, size_t> {
227 __device__ __host__ __forceinline__
bool
229 return (offset < bi.offset);
232 __device__ __host__ __forceinline__
bool
234 return (offset <= bi.offset);
237 __device__ __host__ __forceinline__
bool
239 return (offset > bi.offset);
242 __device__ __host__ __forceinline__
bool
244 return (offset >= bi.offset);
265 __device__ __host__ __forceinline__ difference_type
267 return (offset - bi.offset);
270 __device__ __forceinline__
size_t operator*()
const {
return offset; }
272 __device__ __forceinline__
size_t operator[](
const size_t id)
const {
__device__ __host__ __forceinline__ DynamicBitsetIterator(DynamicBitset *b, size_t i=0)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:139
__device__ __host__ __forceinline__ difference_type operator-(const IdentityIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:266
__device__ __host__ __forceinline__ bool operator>(const IdentityIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:238
__device__ bool test(const size_t id) const
Definition: libgluon/include/galois/cuda/DynamicBitset.h:90
__device__ __host__ __forceinline__ bool operator>=(const IdentityIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:243
__device__ __host__ __forceinline__ bool operator>(const DynamicBitsetIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:164
__device__ __host__ size_t vec_size() const
Definition: libgluon/include/galois/cuda/DynamicBitset.h:76
__device__ __host__ __forceinline__ IdentityIterator & operator++()
Definition: libgluon/include/galois/cuda/DynamicBitset.h:217
__device__ __host__ __forceinline__ IdentityIterator operator-(size_t i)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:261
void alloc(size_t nbits)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:59
__device__ __host__ __forceinline__ DynamicBitsetIterator & operator+=(size_t i)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:174
__device__ __host__ __forceinline__ DynamicBitsetIterator operator-(size_t i)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:191
Dynamic Bitset, CUDA version.
Definition: libgluon/include/galois/cuda/DynamicBitset.h:40
DynamicBitset()
Definition: libgluon/include/galois/cuda/DynamicBitset.h:46
__device__ void batch_reset(const size_t bit_index)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:107
__device__ __host__ __forceinline__ DynamicBitsetIterator & operator-=(size_t i)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:180
__device__ void set(const size_t id)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:97
__device__ __host__ __forceinline__ IdentityIterator operator+(size_t i)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:257
__device__ __host__ size_t size() const
Definition: libgluon/include/galois/cuda/DynamicBitset.h:74
__device__ __host__ __forceinline__ DynamicBitsetIterator & operator--()
Definition: libgluon/include/galois/cuda/DynamicBitset.h:148
void resize(size_t nbits)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:69
__device__ __forceinline__ size_t operator*() const
Definition: libgluon/include/galois/cuda/DynamicBitset.h:270
~DynamicBitset()
Definition: libgluon/include/galois/cuda/DynamicBitset.h:54
void copy_to_cpu(uint64_t *bit_vector_cpu_copy)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:118
__device__ __host__ __forceinline__ bool operator<=(const IdentityIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:233
__device__ __host__ __forceinline__ difference_type operator-(const DynamicBitsetIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:196
__device__ __host__ __forceinline__ bool operator<(const DynamicBitsetIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:154
Definition: libgluon/include/galois/cuda/DynamicBitset.h:133
__device__ __host__ __forceinline__ DynamicBitsetIterator & operator++()
Definition: libgluon/include/galois/cuda/DynamicBitset.h:143
Definition: libgluon/include/galois/cuda/DynamicBitset.h:209
__device__ __host__ __forceinline__ IdentityIterator & operator-=(size_t i)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:252
__device__ __host__ __forceinline__ IdentityIterator & operator+=(size_t i)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:247
__device__ __host__ __forceinline__ IdentityIterator(size_t i=0)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:214
void copy_to_gpu(uint64_t *cpu_bit_vector)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:125
__device__ __host__ __forceinline__ IdentityIterator & operator--()
Definition: libgluon/include/galois/cuda/DynamicBitset.h:222
__device__ __forceinline__ bool operator[](const size_t id) const
Definition: libgluon/include/galois/cuda/DynamicBitset.h:204
__device__ __host__ size_t alloc_size() const
Definition: libgluon/include/galois/cuda/DynamicBitset.h:81
__device__ __host__ __forceinline__ bool operator<(const IdentityIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:228
__device__ __host__ __forceinline__ bool operator>=(const DynamicBitsetIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:169
__device__ __host__ __forceinline__ DynamicBitsetIterator operator+(size_t i)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:186
__device__ __forceinline__ bool operator*() const
Definition: libgluon/include/galois/cuda/DynamicBitset.h:200
__device__ void batch_bitwise_and(const size_t bit_index, const uint64_t mask)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:113
__device__ __host__ __forceinline__ bool operator<=(const DynamicBitsetIterator &bi)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:159
DynamicBitset(size_t nbits)
Definition: libgluon/include/galois/cuda/DynamicBitset.h:52
__device__ __forceinline__ size_t operator[](const size_t id) const
Definition: libgluon/include/galois/cuda/DynamicBitset.h:272
void reset()
Definition: libgluon/include/galois/cuda/DynamicBitset.h:85