Bitset
#
Header file: <Kokkos_Bitset.hpp>
Class Interface#
-
template<typename Device>
class Bitset# Kokkos::Bitset
represents a thread safe view to a fixed-size (at run-time) sequence of N bits.- Template Parameters:
Device – Device that physically contains the bits.
Static Constants
-
static constexpr unsigned BIT_SCAN_REVERSE = 1u#
BIT_SCAN_REVERSE
: Bit mask for scanning direction
-
static constexpr unsigned MOVE_HINT_BACKWARD = 2u#
MOVE_HINT_BACKWARD
: Bit mask for hint direction
-
static constexpr unsigned BIT_SCAN_FORWARD_MOVE_HINT_FORWARD = 0u#
BIT_SCAN_FORWARD_MOVE_HINT_FORWARD
: When passed asscan_direction
tofind_any_set_near(...)
orfind_any_reset_near(...)
, scans for the bit in the forward (increasing index) direction. If the bit was not found, selects a new hint past the current hint.
-
static constexpr unsigned BIT_SCAN_REVERSE_MOVE_HINT_FORWARD = BIT_SCAN_REVERSE#
BIT_SCAN_REVERSE_MOVE_HINT_FORWARD
: When passed asscan_direction
tofind_any_set_near(...)
orfind_any_reset_near(...)
, scans for the bit in the reverse (decreasing index) direction. If the bit was not found, selects a new hint past the current hint.
-
static constexpr unsigned BIT_SCAN_FORWARD_MOVE_HINT_BACKWARD = MOVE_HINT_BACKWARD#
BIT_SCAN_FORWARD_MOVE_HINT_BACKWARD
: When passed asscan_direction
tofind_any_set_near(...)
orfind_any_reset_near(...)
, scans for the bit in the forward (increasing index) direction. If the bit was not found, selects a new hint before the current hint.
-
static constexpr unsigned BIT_SCAN_REVERSE_MOVE_HINT_BACKWARD = BIT_SCAN_REVERSE | MOVE_HINT_BACKWARD#
BIT_SCAN_REVERSE_MOVE_HINT_BACKWARD
: When passed asscan_direction
tofind_any_set_near(...)
orfind_any_reset_near(...)
, scans for the bit in the reverse (decreasing index) direction. If the bit was not found, selects a new hint before the current hint.
Constructors
-
Bitset(unsigned arg_size = 0u)#
Host/Device: Construct a bitset with
arg_size
bits.
Data Access Functions
-
unsigned size() const#
Host/Device: return the number of bits.
-
unsigned count() const#
Host: return the number of bits which are set to
1
.
-
void set()#
Host: set all the bits to
1
.
-
void reset();#
-
void clear();#
Host/Device: set all the bits to
0
.
-
void set(unsigned i)#
Device: set the
i
‘th bit to1
.
-
void reset(unsigned i)#
Device: set the
i
‘th bit to0
.
-
bool test(unsigned i) const#
Device: return
true
if and only if thei
‘th bit is set to1
.
-
unsigned max_hint() const#
Host/Device: used with
find_any_set_near(...)
&find_any_reset_near(...)
functions.Returns the max number of times those functions should be call when searching for an available bit.
-
Kokkos::pair<bool, unsigned> find_any_set_near(unsigned hint, unsigned scan_direction = BIT_SCAN_FORWARD_MOVE_HINT_FORWARD) const#
Host/Device: starting at the
hint
position, find the first bit set to1
.Returns a
pair<bool, unsigned>
.When
result.first
istrue
thenresult.second
is the bit position found.When
result.first
isfalse
thenresult.second
is a new hint position.If
scan_direction & BIT_SCAN_REVERSE
, then the scanning for the bit happens in decreasing index order; otherwise, it happens in increasing index order.If
scan_direction & MOVE_HINT_BACKWARDS
, then the new hint position occurs at a smaller index thanhint
; otherwise, it occurs at a larger index thanhint
.
-
Kokkos::pair<bool, unsigned> find_any_unset_near(unsigned hint, unsigned scan_direction = BIT_SCAN_FORWARD_MOVE_HINT_FORWARD) const;#
Host/Device: starting at the
hint
position, find the first bit set to0
.Returns a
pair<bool, unsigned>
.When
result.first
istrue
thenresult.second
is the bit position found.When
result.first
isfalse
thenresult.second
is a new hint position.If
scan_direction & BIT_SCAN_REVERSE
, then the scanning for the bit happens in decreasing index order; otherwise, it happens in increasing index order.If
scan_direction & MOVE_HINT_BACKWARDS
, then the new hint position occurs at a smaller index thanhint
; otherwise, it occurs at a larger index thanhint
.
-
constexpr bool is_allocated() const#
Host/Device: the bits are allocated on the device.
ConstBitset
#
Class Interface#
-
template<typename Device>
class ConstBitset# - Template Parameters:
Device – Device that physically contains the bits.
Constructors / assignment
-
ConstBitset()#
Host/Device: Construct a bitset with no bits.
-
ConstBitset(ConstBitset const &rhs) = default#
-
ConstBitset &operator=(ConstBitset const &rhs) = default#
Copy constructor/assignment operator.
-
ConstBitset &operator=(Bitset<Device> const &rhs)#
Host/Device: Copy/assign a
Bitset
to aConstBitset
.
-
unsigned size() const#
Host/Device: return the number of bits.
-
unsigned count() const#
Host/Device: return the number of bits which are set to
1
.
-
bool test(unsigned i) const#
Host/Device: Return
true
if and only if thei
‘th bit set to1
.
Non-Member Functions#
- template<typename DstDevice, typename SrcDevice>
void deep_copy(Bitset<DstDevice> &dst, Bitset<SrcDevice> const &src)#Copy a
Bitset
fromsrc
onSrcDevice
todst
onDstDevice
.
- template<typename DstDevice, typename SrcDevice>
void deep_copy(Bitset<DstDevice> &dst, ConstBitset<SrcDevice> const &src)#Copy a
ConstBitset
fromsrc
onSrcDevice
to aBitset
dst
onDstDevice
.