Div
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
√ |
|
|
x |
|
|
√ |
Function Usage
Computes the element-wise quotient. The formula is as follows:

Prototype
- Computation of the entire tensor
1dst = src0 / src1;
- Computation of the first n data elements of a tensor
1 2
template <typename T, const DivConfig& config = DEFAULT_DIV_CONFIG> __aicore__ inline void Div(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const LocalTensor<T>& src1, const int32_t& count)
- High-dimensional tensor sharding computation
- Bitwise mask mode
1 2
template <typename T, bool isSetMask = true, const DivConfig& config = DEFAULT_DIV_CONFIG> __aicore__ inline void Div(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const LocalTensor<T>& src1, uint64_t mask[], const uint8_t repeatTime, const BinaryRepeatParams& repeatParams)
- Contiguous mask mode
1 2
template <typename T, bool isSetMask = true, const DivConfig& config = DEFAULT_DIV_CONFIG> __aicore__ inline void Div(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const LocalTensor<T>& src1, uint64_t mask, const uint8_t repeatTime, const BinaryRepeatParams& repeatParams)
- Bitwise mask mode
Parameters
|
Parameter |
Description |
||||
|---|---|---|---|---|---|
|
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are int16_t, uint16_t, half, int32_t, uint32_t, float, complex32, int64_t, uint64_t, and complex64. For the For the For the For the For the |
||||
|
isSetMask |
Indicates whether to set mask inside the API.
|
||||
|
config |
This parameter is supported only by the Atlas 350 Accelerator Card. Precision computation mode. The DivConfig type is defined as follows:
The precision computation mode is configured by using the algo parameter of the DivConfig structure. The options of algo are as follows:
The default value of this parameter, DEFAULT_DIV_CONFIG, is defined as follows:
|
|
Parameter |
Input/Output |
Description |
|---|---|---|
|
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. |
|
src0 and src1 |
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. Both source operands must have the same data type as 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 compute unit reads 256 bytes of contiguous data for computation each time. To process the input data, the data needs to be read and computed over multiple repeats. repeatTime indicates the number of repeats. For details about this parameter, see High-dimensional Sharding APIs. |
|
repeatParams |
Input |
Parameters that control the operand address strides. They are of the BinaryRepeatParams type, and contain such parameters as those that specify the address stride of the operand for the same data block between adjacent iterations and address stride of the operand between different data blocks in a single iteration. For details about the address stride of the operand between adjacent iterations, see repeatStride. For details about the address stride of the operand between different data blocks in a single iteration, see dataBlockStride. |
Returns
None
Restrictions
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
- For details about the constraints on operand address overlapping, see General Address Overlapping Restrictions.
- When the entire tensor computation API is used for symbol overloading, the computation workload is the total length of the destination LocalTensor.
- For the Atlas 350 Accelerator Card, uint64_t, int64_t, complex32, and complex64 support only the APIs that operate on the first n data elements of a tensor, as well as operator overloads where the entire tensor participates in the computation.
Examples
- Example of high-dimensional tensor sharding computation (contiguous mask mode)
1 2 3 4
// mask=128, 128 elements one repeat. repeatTime=4, 4 iterations // dstBlkStride=1, src0BlkStride=1, src1BlkStride=1.no gap between blocks in one repeat // dstRepStride=8, src0RepStride=8, src1RepStride=8. no gap between repeats AscendC::Div(dstLocal, src0Local, src1Local, 128, 4, { 1, 1, 1, 8, 8, 8 });
- Example of high-dimensional tensor sharding computation (bitwise mask mode)
1 2 3 4 5
uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // repeatTime = 4. 128 elements are computed in one iteration, and 512 elements are computed in total. // dstBlkStride, src0BlkStride, src1BlkStride = 1. Data is continuously read and written in a single iteration. // dstRepStride, src0RepStride, src1RepStride = 8. Data is continuously read and written between adjacent iterations. AscendC::Div(dstLocal, src0Local, src1Local, mask, 4, { 1, 1, 1, 8, 8, 8 });
- Example of computing the first n data elements of a tensor
1 2 3 4 5 6 7
AscendC::Div(dstLocal, src0Local, src1Local, 512); // Div 0ulp static constexpr DivConfig config = { DivAlgo::DIFF_COMPENSATION }; Div<T, config>(dstLocalX, srcLocalX, srcLocalY, calCount); // Div Subnormal static constexpr DivConfig config = { DivAlgo::PRECISION_0ULP_FTZ_FALSE }; Div<T, config>(dstLocalX, srcLocalX, srcLocalY, calCount);
- Example computation of the entire tensor
1dstLocal = src0Local / src1Local;
Input (src0Local): [1.0 2.0 3.0 ... 512.0] Input (src1Local): [2.0 2.0 2.0 ... 2.0] Output (dstLocal): [0.5 1.0 1.5 ... 256.0]