ShiftLeft (Shift Amount as Tensor)
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Performs a left shift on each element of the source operand. A left shift operation is classified into the following types based on the data type of the source operand:
- If the data type is unsigned, a logical left shift is performed. In this case, a left shift moves a binary number to the left by the specified number of bits, discarding the highest bits and filling the lowest bits with zeros. For example, the binary number 1010101010101010 (uint16_t) after a logical left shift by 1 bit becomes 0101010101010100.
- If the data type is signed, an arithmetic left shift is performed. In this case, a left shift moves the binary number to the left by a specified number of bits, discarding the next most significant bits and filling the least significant bits with zeros. For example, the binary number 1010101010101010 (int16_t) becomes 1101010101010100 after an arithmetic left shift by 1 bit, and becomes 1101010101010000 after an arithmetic left shift by 3 bits.
Prototype
1 2 | template <typename T, typename U> __aicore__ inline void ShiftLeft(const LocalTensor<T>& dst, const LocalTensor<T>& src0, const LocalTensor<U>& src1, const int32_t& count) |
Parameters
Parameter |
Description |
|---|---|
T |
Data type of the source and destination operands. For the Atlas 350 Accelerator Card, the supported data types are int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, and uint64_t. |
U |
Data type of the source operand. For the Atlas 350 Accelerator Card, the supported data types are int8_t, int16_t, int32_t, and int64_t. |
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. |
src0 |
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. The data type must be the same as that of the destination operand. |
src1 |
Input |
LocalTensor that stores the number of bits to shift (shift amount). It must have a data type with the same byte size as the tensor element data type of the src0 operand. Negative values are not supported. |
count |
Input |
Number of elements involved in the computation. |
Returns
None
Restrictions
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
- For a logical shift (unsigned data type), if the shift amount is greater than the bit width of the data type, the output is 0.
- For an arithmetic shift (signed data type), if both src0 and src1 are less than 0 and the shift amount is greater than the bit width of the data type, the output is –1. If src0 is greater than 0 and the shift amount is greater than the bit width of the data type, the output is 0.
Examples
1 | AscendC::ShiftLeft(dstLocal, srcLocal0, srcLocal1, 512); |
Input (srcLocal0): [1 2 3 ... 512] Input (srcLocal1): [2 2 2 ... 2] Output (dstLocal): [4 8 12 ... 2048]