reduce_tile

template<PoolType reduce_type = REDUCE_OP, ReduceDim reduce_dim = REDUCE_DIM>
void ckernel::reduce_init(uint32_t icb, uint32_t icb_scaler, uint32_t ocb)

Performs the necessary hardware and software initialization for reduce operation for provided circular buffer identifiers (CB IDs). In order for reduce operation to be performed, this function call must be followed by a call to reduce_tile or reduce_tile_math. If another reduce op is needed which uses different CB IDs, then another reduce_init needs to be called as a part of that reduce operation.

The icb_scaler circular buffer must contain the scaling factors for the reduction. The most straightforward way of filling the icb_scaler with the scaling factors is to populate first row of each face with the followin values:

  • If reduce_type = SUM, all scaling factors should preferably be 1.

  • If reduce_type = AVG, all scaling factors should preferably be 1/N (where N is the number of elements being averaged, except if the reduction dimension is scalar, in which case the scaling factor should be 1/sqrt(N)).

  • If reduce_type = MAX, all scaling factors should preferably be 1.

NOTE: For SUM and AVG operations, the value in icb_scaler is a scaling factor of the final sum of values across rows/columns/both, so there is no real constraint in terms of it’s value. For MAX operation, maximum value will be obtained as expected, but it will be scaled by the values in icb_scaler. In any case, it is recommended to use the above-mentioned scaling factors to ensure that operations function as intended. Refer to ISA documentation for more details. NOTE: For other valid ways of populating the icb_scaler, refer to the ISA documentation.

Return value: None

Param Type

Name

Description

Type

Valid Range

Required

Template

reduce_type

The type of reduce op - sum, average or maximum

PoolType

{SUM, AVG, MAX}

True

Template

reduce_dim

The dimension of reduce op - row, column or both

ReduceDim

{REDUCE_ROW, REDUCE_COL, REDUCE_SCALAR}

True

Function

icb

The identifier of the circular buffer (CB) containing operand A

uint32_t

0 to 31

True

Function

icb_scaler

CB holding scaling factors (see above)

uint32_t

0 to 31

True

Function

ocb

The identifier of the output circular buffer (CB)

uint32_t

0 to 31

True

template<PoolType reduce_type = REDUCE_OP, ReduceDim reduce_dim = REDUCE_DIM>
void ckernel::reduce_tile(uint32_t icb, uint32_t icb_scaler, uint32_t itile, uint32_t itile_sclaer, uint32_t idst)

Performs a reduction operation B = reduce(A) using reduce_func for dimension reduction on a tile in the CB at a given index and writes the result to the DST register at index dst_tile_index. Reduction can be of type Reduce::R, Reduce::C, or Reduce::RC, identifying the dimension(s) to be reduced in size to 1. The DST register buffer must be in acquired state via acquire_dst call.

The icb_scaler circular buffer must contain the scaling factors for the reduction. The most straightforward way of filling the icb_scaler with the scaling factors is to populate first row of each face with the followin values:

  • If reduce_type = SUM, all scaling factors should preferably be 1.

  • If reduce_type = AVG, all scaling factors should preferably be 1/N (where N is the number of elements being averaged, except if the reduction dimension is scalar, in which case the scaling factor should be 1/sqrt(N)).

  • If reduce_type = MAX, all scaling factors should preferably be 1.

The templates take reduce_type which can be ReduceFunc::Sum, ReduceFunc::Avg, or ReduceFunc::Max and reduce_dim which can be Reduce::R, Reduce::C, or Reduce::RC. They can also be specified by defines REDUCE_OP and REDUCE_DIM.

NOTE: Before the next operation is initialized, the reduce_uninit function must be called to reset the packer state to default. NOTE: For SUM and AVG operations, the value in icb_scaler is a scaling factor of the final sum of values across rows/columns/both, so there is no real constraint in terms of it’s value. For MAX operation, maximum value will be obtained as expected, but it will be scaled by the values in icb_scaler. In any case, it is recommended to use the above-mentioned scaling factors to ensure that operations function as intended. Refer to ISA documentation for more details. NOTE: For other valid ways of populating the icb_scaler, refer to the ISA documentation. Return value: None

Param Type

Name

Description

Type

Valid Range

Required

Template

reduce_type

The type of reduce op - sum, average or maximum

PoolType

{SUM, AVG, MAX}

True

Template

reduce_dim

The dimension of reduce op - row, column or both

ReduceDim

{REDUCE_ROW, REDUCE_COL, REDUCE_SCALAR}

True

Function

icb

The identifier of the circular buffer (CB) containing operand A

uint32_t

0 to 31

True

Function

icb_scaler

CB holding scaling factors (see above)

uint32_t

0 to 31

True

Function

itile

The index of the tile within the first CB

uint32_t

Must be less than the size of the CB

True

Function

itile_sclaer

The index of the tile within the scaling factor CB.

uint32_t

Must be less than the size of the CB

True

Function

idst

The index of the tile in DST REG for the result

uint32_t

Must be less than the acquired size of DST REG

True