FilesLast commitLast update
10 days ago
3 months ago
1 month ago
28 days ago
28 days ago
28 days ago
1 month ago
1 month ago
11 days ago
README

PopulationCount

English | 简体中文

Product Support Status

Product Supported
Ascend 950PR&950DT products √
Atlas A3 products √
Atlas A2 products √
Atlas 200I/500 A2 inference products √
Atlas inference products √
Atlas training products √

Function Description

  • Operator function: counts the number of bits with bit=1 in the binary representation of each 16-bit integer in the input tensor element by element (population count, also known as Hamming weight / popcount).

  • Computation formula:

yi=popcount(xi)y_i = \text{popcount}(x_i)

where:

  • xix_i: the i-th element of the input tensor, interpreted as an unsigned 16-bit width (negative INT16 values are counted bit by bit in two's complement)

  • yiy_i: the i-th element of the output tensor, with the value range [0,16][0, 16]

  • Use cases: scenarios that require counting binary bits, such as Hamming distance computation, sparsity analysis, and bitmask processing.

Parameter Description

Parameter Name Input/Output Description Data Type Data Format
x Input Integer tensor to be counted, which is x in the formula. 0-8 dimensional tensors are supported, and a 0-dimensional tensor indicates a scalar. INT16, UINT16 ND
y Output Bit count result of each element, which is y in the formula. The shape is the same as that of x. UINT8 ND

Constraint Description

  • The data type of the input x must be INT16 or UINT16, and the data type of the output y is fixed to UINT8.
  • The shape of the output y must be exactly the same as the shape of the input x. Broadcast is not supported.
  • 0-8 dimensional tensors are supported, and a 0-dimensional tensor indicates a scalar.
  • Empty tensors (with 0 elements) are supported, and an empty result is returned directly.
  • Dynamic shape and dynamic rank are supported. The operator can still be correctly executed when the shape is uncertain.
  • Both contiguous and non-contiguous inputs are supported. Non-contiguous inputs are automatically converted to contiguous by the framework before computation.

Invocation Description

Invocation Method Invocation Sample Description
Graph-mode invocation test_geir_population_count Invokes the PopulationCount operator by building a graph through the operator IR.