GetBitCount

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Obtains the number of 0s or 1s in a binary number of the uint64_t type.

Prototype

1
2
template <int countValue> 
__aicore__ inline int64_t GetBitCount(uint64_t valueIn)

Parameters

Table 1 Template parameters

Parameter

Description

countValue

0 or 1 to be counted.

Enter 0 or 1.

Table 2 Parameters

Parameter

Input/Output

Description

valueIn

Input

A binary number.

Returns

Number of 0s or 1s in valueIn.

Constraints

None

Example

1
2
3
4
uint64_t valueIn = 0xffff; // There are 16 1s in the binary format.
constexpr int countValue = 1;    // Count the number of 1s in the binary format of valueIn.
// Output (oneCount): 16
int64_t oneCount = AscendC::GetBitCount<countValue>(valueIn);