MrgSort4

Applicability

Product

Supported

Atlas 350 Accelerator Card

x

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

Function Usage

Merges at most four sorted Region Proposal queues into one. The results are sorted in descending order of the score fields.

Prototype

1
2
template <typename T>
__aicore__ inline void MrgSort4(const LocalTensor<T>& dst, const MrgSortSrcList<T>& src, const MrgSort4Info& params)

Parameters

Table 1 Parameters in the template

Parameter

Description

T

Operand data type.

For the Atlas training product, the supported data type is half.

For the Atlas inference product AI Core, the supported data types are half and float.

Table 2 Parameters

Parameter

Input/Output

Meaning

dst

Output

Destination operand, which stores sorted Region Proposals.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

The start address of 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 of the MrgSortSrcList structure type, which contains four sorted Region Proposal queues. The details are as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
template <typename T> struct MrgSortSrcList {
    __aicore__ MrgSortSrcList() {}
    __aicore__ MrgSortSrcList(const LocalTensor<T>& src1In, const LocalTensor<T>& src2In, const LocalTensor<T>& src3In,
        const LocalTensor<T>& src4In)
    {
        src1 = src1In[0];
        src2 = src2In[0];
        src3 = src3In[0];
        src4 = src4In[0];
    }
    LocalTensor<T> src1; // the first sorted Region Proposal queue
    LocalTensor<T> src2; // the second sorted Region Proposal queue
    LocalTensor<T> src3; // the third sorted Region Proposal queue
    LocalTensor<T> src4; // the fourth sorted Region Proposal queue
};

The Region Proposal queues must have the same data type as the destination operand. src1, src2, src3, or src4 values are of the LocalTensor type, and the supported TPosition is VECIN, VECCALC, or VECOUT.

The start address of LocalTensor must be 16-byte aligned (for data of the half type) or 32-byte aligned (for data of the float type).

params

Input

Parameter required for sorting, which is of the MrgSort4Info structure type.

For details, see ${INSTALL_DIR}/include/ascendc/basic_api/interface/kernel_struct_proposal.h. Replace ${INSTALL_DIR} with the actual CANN component directory.

For details about the parameter description, see Table 3.

Table 3 MrgSort4Info parameters

Parameter

Input/Output

Meaning

elementLengths

Input

Lengths of the four source Region Proposal queues (or numbers of Region Proposals), an array of the uint16_t type with a length of 4. Theoretically, the value range of each element is [0, 4095], but the value cannot exceed the storage space of the UB.

ifExhaustedSuspension

Input

A bool specifying whether to stop the instruction when a queue is exhausted. The default value is false.

validBit

Input

Number of valid queues. The values are as follows:
  • 3: The first two queues are valid.
  • 7: The first three queues are valid.
  • 15: All the four queues are valid.

repeatTimes

Input

Number of iteration repeats. The total length of the four queues is skipped for the source and destination operands in each iteration. Value range: repeatTimes ∈ [1,255]

The repeatTimes parameter takes effect only when the following conditions are met:
  • The lengths of the four source Region Proposal queues are the same.
  • The four source Region Proposal queues are stored consecutively.
  • ifExhaustedSuspension = False
  • validBit=15

Restrictions

  • If the score values of proposal [i] and proposal [j] are the same and i is greater than j, proposal [j] is selected first.
  • For details about the operand address alignment requirements, see General Address Alignment Restrictions.
  • The destination operand address must not overlap the source operand address.

Examples

API usage example
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
// Create Region Proposals as follows:
// AscendC::ProposalConcat(vconcatWorkLocal[0], srcLocal[0], repeat, mode);
// AscendC::RpSort16(vconcatWorkLocal[0], vconcatWorkLocal[0], repeat);

// vconcatWorkLocal indicates the created and sorted four Region Proposal queues. Each queue has 16 Region Proposals.
// The input data is first processed by ProposalConcat to insert consecutive elements into the corresponding positions in each Region Proposal. Then, RpSort16 sorts the score fields in each Region Proposal to obtain each vconcatWorkLocal.

struct MrgSortSrcList<half> srcList(vconcatWorkLocal[0], vconcatWorkLocal[1], vconcatWorkLocal[2], vconcatWorkLocal[3]);
// The length of each of the four source Region Proposal queues is 16.
uint16_t elementLengths[4] = {16, 16, 16, 16};
// false indicates that the instruction does not need to be stopped after a queue is exhausted. 15 indicates that all the four queues are valid. With repeat set to 1, there is one iteration.
struct MrgSort4Info srcInfo(elementLengths, false, 15, 1);
AscendC::MrgSort4(dstLocal, srcList, srcInfo);
Result example:
Input (src_gm):
[-38.1    82.7   -40.75  -54.62   21.67  -58.53   25.94  -79.5   -61.44
  26.7   -27.45   48.78   86.75  -18.1   -58.8    62.38   46.38  -78.94
 -87.7   -13.81  -13.25   46.94  -47.8   -50.44   34.16   20.3    80.1
 -94.1    52.4   -42.75   83.4    80.44  -66.8   -82.7   -91.44  -95.6
  66.2   -30.97  -36.53   61.66   24.92  -45.1    38.97  -34.62  -69.8
  59.1    34.22   11.695 -33.47   52.1    -4.832  46.88   56.78   71.4
  13.29  -35.78   52.44  -46.03   83.8    83.56   71.3    -9.086 -65.06
  46.25 ]

// The input data is first processed by ProposalConcat to insert consecutive elements into the corresponding positions in each Region Proposal. Then, RpSort16 sorts the score fields in each Region Proposal and inserts them into four vconcatWorkLocal blocks. Finally, these four blocks are combined to form the output.

Output (dst_gm):
[
0.0       0.0       0.0       0.0       86.75     0.0       0.0       0.0
0.0       0.0       0.0       83.8      0.0       0.0       0.0       0.0
0.0       0.0       83.56     0.0       0.0       0.0       0.0       0.0
0.0       83.4      0.0       0.0       0.0       0.0       0.0       0.0
82.7      0.0       0.0       0.0       0.0       0.0       0.0       80.44
0.0       0.0       0.0       0.0       0.0       0.0       0.0       80.1
0.0       0.0       0.0       0.0       0.0       0.0       71.4      0.0
0.0       0.0       0.0       0.0       0.0       71.3      0.0       0.0
0.0       0.0       0.0       0.0       66.2      0.0       0.0       0.0
0.0       0.0       0.0       62.38     0.0       0.0       0.0       0.0
0.0       0.0       61.66     0.0       0.0       0.0       0.0       0.0
0.0       59.1      0.0       0.0       0.0       0.0       0.0       0.0
56.78     0.0       0.0       0.0       0.0       0.0       0.0       52.44
0.0       0.0       0.0       0.0       0.0       0.0       52.4      0.0
0.0       0.0       0.0       0.0       0.0       52.1      0.0       0.0
0.0       0.0       0.0       0.0       0.0       48.78     0.0       0.0
0.0       0.0       0.0       0.0       46.94     0.0       0.0       0.0
0.0       0.0       0.0       46.88     0.0       0.0       0.0       0.0
0.0       0.0       46.38     0.0       0.0       0.0       0.0       0.0
0.0       46.25     0.0       0.0       0.0       0.0       0.0       0.0
38.97     0.0       0.0       0.0       0.0       0.0       0.0       34.22
0.0       0.0       0.0       0.0       0.0       0.0       34.16     0.0
0.0       0.0       0.0       0.0       0.0       26.7      0.0       0.0
0.0       0.0       0.0       0.0       25.94     0.0       0.0       0.0
0.0       0.0       0.0       24.92     0.0       0.0       0.0       0.0
0.0       0.0       21.67     0.0       0.0       0.0       0.0       0.0
0.0       20.3      0.0       0.0       0.0       0.0       0.0       0.0
0.0       13.29     0.0       0.0       0.0       0.0       0.0       0.0
11.695    0.0       0.0       0.0       0.0       0.0       0.0       -4.832
0.0       0.0       0.0       0.0       0.0       0.0       -9.086    0.0
0.0       0.0       0.0       0.0       0.0       -13.25    0.0       0.0
0.0       0.0       0.0       0.0       -13.81    0.0       0.0       0.0
0.0       0.0       0.0       -18.1     0.0       0.0       0.0       0.0
0.0       0.0       0.0       -27.45    0.0       0.0       0.0       0.0
0.0       0.0       -30.97    0.0       0.0       0.0       0.0       0.0
0.0       -33.47    0.0       0.0       0.0       0.0       0.0       0.0
-34.62    0.0       0.0       0.0       0.0       0.0       0.0       -35.78
0.0       0.0       0.0       0.0       0.0       0.0       -36.53    0.0
0.0       0.0       0.0       0.0       0.0       -38.1     0.0       0.0
0.0       0.0       0.0       0.0       -40.75    0.0       0.0       0.0
0.0       0.0       0.0       -42.75    0.0       0.0       0.0       0.0
0.0       0.0       -45.1     0.0       0.0       0.0       0.0       0.0
0.0       -46.03    0.0       0.0       0.0       0.0       0.0       0.0
-47.8     0.0       0.0       0.0       0.0       0.0       0.0       0.0
-50.44    0.0       0.0       0.0       0.0       0.0       0.0       -54.62
0.0       0.0       0.0       0.0       0.0       0.0       -58.53    0.0
0.0       0.0       0.0       0.0       0.0       -58.8     0.0       0.0
0.0       0.0       0.0       0.0       -61.44    0.0       0.0       0.0
0.0       0.0       0.0       -65.06    0.0       0.0       0.0       0.0
0.0       0.0       -66.8     0.0       0.0       0.0       0.0       0.0
0.0       -69.8     0.0       0.0       0.0       0.0       0.0       0.0
-78.94    0.0       0.0       0.0       0.0       0.0       0.0       -79.5
0.0       0.0       0.0       0.0       0.0       0.0       -82.7     0.0
0.0       0.0       0.0       0.0       0.0       -87.7     0.0       0.0
0.0       0.0       0.0       0.0       -91.44    0.0       0.0       0.0
0.0       0.0       0.0       -94.1     0.0       0.0       0.0       0.0
0.0       0.0       0.0       -95.6     0.0       0.0       0.0       0.0
]