BlockReduceMax
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
Function Usage
Computes the maximum of all elements in each data block. For details about reduction instructions, see How to Use Reduction Compute APIs.
Prototype
- Bitwise mask mode
1 2
template <typename T, bool isSetMask = true> __aicore__ inline void BlockReduceMax(const LocalTensor<T>& dst, const LocalTensor<T>& src,const int32_t repeatTime, const uint64_t mask[], const int32_t dstRepStride, const int32_t srcBlkStride, const int32_t srcRepStride)
- Contiguous mask mode
1 2
template <typename T, bool isSetMask = true> __aicore__ inline void BlockReduceMax(const LocalTensor<T>& dst, const LocalTensor<T>& src,const int32_t repeatTime, const int32_t mask, const int32_t dstRepStride, const int32_t srcBlkStride, const int32_t srcRepStride)
Parameters
|
Parameter |
Description |
|---|---|
|
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are half and float. For the For the For the For the For the |
|
isSetMask |
Indicates whether to set mask inside the API.
|
|
Parameter |
Input/Output |
Meaning |
|---|---|---|
|
dst |
Output |
Destination operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of the LocalTensor must be 16-byte aligned (for data of the half type) or 32-byte aligned (for data of the float type). |
|
src |
Input |
Source operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of LocalTensor must be 32-byte aligned. |
|
repeatTime |
Input |
Number of iteration repeats. The value range is [0, 255]. For details about this parameter, see High-dimensional Sharding APIs. |
|
mask/mask[] |
Input |
mask controls the elements that participate in computation in each iteration.
|
|
dstRepStride |
Input |
Address stride between adjacent iterations of the destination operand. The unit is the length of one reduced repeat. After each repeat (eight data blocks) is reduced, eight elements are obtained. Therefore, when the input type is half, the unit of RepStride is 16 bytes. When the input type is float, the unit of RepStride is 32 bytes. Note that this parameter cannot be set to 0 for the |
|
srcBlkStride |
Input |
Address stride of data blocks in a single iteration. For details, see dataBlockStride. |
|
srcRepStride |
Input |
Address stride between adjacent iterations of the source operand, that is, the number of data blocks skipped from the source operand in each iteration. For details, see repeatStride. |
Returns
None
Restrictions
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
- To save memory space, you can define a tensor shared by the source and destination operands (by address overlapping). Note that the computed destination operand data cannot overwrite the source operands that are not involved in the computation. Exercise caution when defining the tensor.
- For the
Atlas 200I/500 A2 inference product , if mask/mask[] is configured and no element in a data block is involved in the computation, the maximum value of all elements in the data block is filled with -inf and returned. For example, in the float scenario, if mask is set to 32, that is, only the first four data blocks are computed, -inf is returned for the maximum value in the last four data blocks. In the half scenario, -65504 is returned. - Proper use of the reduction instruction in different scenarios can improve performance. For details about the introduction, see Selecting Low-Latency Instructions to Optimize Reduction Operation Performance. For details about examples, see ReduceCustom.
Examples
These examples show only part of the code used in the computation.
- Example of BlockReduceMax – high-dimensional tensor sharding computation (contiguous mask mode)
1 2 3 4 5 6 7 8 9
// Set mask to 128, which indicates that a maximum of 128 elements are involved for computation. int32_t mask = 256/sizeof(half); // Each repeat contains 128 elements, and there are 128 elements in total. int repeat = 1; // dstLocal: destination operand tensor // srcLocal: source operand tensor // srcBlkStride = 1. Within a repeat, there are no gaps between blocks. // dstRepStride = 1, srcRepStride = 8. There are no gaps between repeats. AscendC::BlockReduceMax<half>(dstLocal, srcLocal, repeat, mask, 1, 1, 8);
- Example of BlockReduceMax – high-dimensional tensor sharding computation (bitwise mask mode)
1 2 3 4 5 6 7 8 9
// Set mask to 128, which indicates that a maximum of 128 elements are involved for computation. uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // Each repeat contains 128 elements, and there are 128 elements in total. int repeat = 1; // dstLocal: destination operand tensor // srcLocal: source operand tensor // srcBlkStride = 1. Within a repeat, there are no gaps between blocks. // dstRepStride = 1, srcRepStride = 8. There are no gaps between repeats. AscendC::BlockReduceMax<half>(dstLocal, srcLocal, repeat, mask, 1, 1, 8);
Input (src_gm): [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, ... 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ] Output (dst_gm): [2, 3, ..., 4]