Mins (Flexible Scalar Position)
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
Function Usage
Compares each element of a vector with a scalar and returns the smaller one, with a flexible scalar position (before or after a tensor). The scalar input can also be a single element from a LocalTensor. idx indicates the position index of a LocalTensor single element.

Prototype
- Computation of the first n pieces of data of a tensor
1 2
template <typename T = BinaryDefaultType, bool isSetMask = true, const BinaryConfig& config = DEFAULT_BINARY_CONFIG, typename U, typename S, typename V> __aicore__ inline void Mins(const U& dst, const S& src0, const V& src1, const int32_t& count)
- High-dimensional tensor sharding computation
- Bitwise mask mode
1 2
template <typename T = BinaryDefaultType, bool isSetMask = true, const BinaryConfig& config = DEFAULT_BINARY_CONFIG, typename U, typename S, typename V> __aicore__ inline void Mins(const U& dst, const S& src0, const V& src1, uint64_t mask[], const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)
- Contiguous mask mode
1 2
template <typename T = BinaryDefaultType, bool isSetMask = true, const BinaryConfig& config = DEFAULT_BINARY_CONFIG, typename U, typename S, typename V> __aicore__ inline void Mins(const U& dst, const S& src0, const V& src1, uint64_t mask, const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)
- Bitwise mask mode
Parameters
|
Parameter |
Description |
||
|---|---|---|---|
|
T |
Operand data type. For an API with a flexible scalar position, this parameter is reserved for future use. If this parameter needs to be specified, pass the default value BinaryDefaultType. |
||
|
isSetMask |
Whether to set the mask mode and mask value inside the API.
For the models below, isSetMask is invalid for the APIs that compute the first n pieces of data in a tensor. Retain the default value.
|
||
|
config |
Position of a single element. This parameter is of BinaryConfig type and takes effect when the scalar input is a LocalTensor single element. The default value is DEFAULT_BINARY_CONFIG, indicating that the scalar is after the tensor.
|
||
|
U |
LocalTensor data type. The data type is automatically inferred based on dst. Developers do not need to configure this parameter. Ensure that dst meets the data type requirements. |
||
|
S |
LocalTensor or scalar data type. The data type is automatically inferred based on src0. Developers do not need to configure this parameter. Ensure that src0 meets the data type requirements. |
||
|
V |
LocalTensor or scalar data type. The data type is automatically inferred based on src1. Developers do not need to configure this parameter. Ensure that src1 meets the data type requirements. |
|
Parameter |
Input/Output |
Meaning |
|---|---|---|
|
dst |
Output |
Destination operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of LocalTensor must be 32-byte aligned. For the Atlas 350 Accelerator Card, the supported data types are uint8_t, int8_t, half, bfloat16_t, int16_t, float, int32_t, uint64_t, and int64_t. |
|
src0/src1 |
Input |
Source operands.
The data type must be the same as that of the destination operand. |
|
count |
Input |
Number of elements involved in the computation. |
|
mask/mask[] |
Input |
mask controls the elements that participate in computation in each iteration.
|
|
repeatTime |
Input |
Number of iteration repeats. The Vector Unit reads 256 bytes of contiguous data for computation each time. To read the complete data for processing, the unit needs to read the input data in multiple repeats. repeatTime indicates the number of iterations. For details about this parameter, see High-dimensional Sharding APIs. |
|
repeatParams |
Input |
Structure for controlling element-wise operations. For details, see UnaryRepeatParams. |
Returns
None
Restrictions
- If this API is called when the scalar input is a LocalTensor single element, the source operand address cannot overlap with the destination operand address.
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
- For the Atlas 350 Accelerator Card, int8_t, uint8_t, uint64_t, and int64_t support only the APIs that compute the first n pieces of data in a tensor.
- Either the left or right source operand must be a vector. Currently, the left and right operands cannot be scalars at the same time.
- If the scalar input is a LocalTensor single element, idx must be a compile-time constant. If it is a variable, it must be declared as constexpr.
Examples
For more examples, see LINK.
- Example of high-dimensional tensor sharding computation (contiguous mask mode)
1 2 3 4 5 6 7 8 9 10
uint64_t mask = 128; // repeatTime = 4. 128 elements are processed in a single iteration. To compute 512 elements, four iterations are required. // dstBlkStride, srcBlkStride = 1. The interval between src0 data addresses involved in computation in each iteration is one data block, indicating that data is continuously read and written in a single iteration. // dstRepStride, srcRepStride = 8. The interval between addresses of adjacent iterations is eight data blocks, indicating that data is continuously read and written between adjacent iterations. // The scalar is after the tensor. AscendC::Mins(dstLocal, src0Local, src1Local[0], mask, 4, { 1, 1, 8, 8 }); // The scalar is before the tensor. static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Mins<BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, mask, 4, { 1, 1, 8, 8 });
- Example of high-dimensional tensor sharding computation (bitwise mask mode)
1 2 3 4 5 6 7 8 9 10
uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // repeatTime = 4. 128 elements are processed in a single iteration. To compute 512 elements, four iterations are required. // dstBlkStride, srcBlkStride = 1. The interval between src0 data addresses involved in computation in each iteration is one data block, indicating that data is continuously read and written in a single iteration. // dstRepStride, srcRepStride = 8. The interval between addresses of adjacent iterations is eight data blocks, indicating that data is continuously read and written between adjacent iterations. // The scalar is after the tensor. AscendC::Mins(dstLocal, src0Local, src1Local[0], mask, 4, {1, 1, 8, 8}); // The scalar is before the tensor. static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Mins<BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, mask, 4, { 1, 1, 8, 8 });
- Example of computing the first n pieces of data of a tensor
1 2 3 4 5 6
// The scalar is after the tensor. AscendC::Mins(dstLocal, src0Local, src1Local[0], 512); // The scalar is before the tensor. static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Mins<BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, 512);
Input (src0Local): [1 2 3 ... 512] Input (src1Local): [2 2 2 ... 2] // The scalar src0Local[0] is before the tensor. Output (dstLocal): [1 1 1 ... 1] // The scalar src1Local[0] is after the tensor. Output (dstLocal): [1 2 2 ... 2]