SinCos
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Performs sine and cosine computation element-wise to obtain the sine and cosine results.


Prototype
- Pass the temporary space through the sharedTmpBuffer input parameter.
1 2
template <const SinCosConfig& config = DEFAULT_SINCOS_CONFIG, typename T> __aicore__ inline void SinCos(const LocalTensor<T>& dst0, const LocalTensor<T>& dst1, const LocalTensor<T>& src, const LocalTensor<uint8_t>& sharedTmpBuffer, const uint32_t count)
- The API framework allocates temporary space.
1 2
template <const SinCosConfig& config = DEFAULT_SINCOS_CONFIG, typename T> __aicore__ inline void SinCos(const LocalTensor<T>& dst0, const LocalTensor<T>& dst1, const LocalTensor<T>& src, const uint32_t count)
Due to the complex mathematical computation involved in the internal implementation of this API, extra temporary space is required to store intermediate variables generated during computation. The temporary space can be passed by developers through the sharedTmpBuffer input parameter or allocated by the API framework.
- When the sharedTmpBuffer input parameter is used for passing the temporary space, the tensor serves as the temporary space. In this case, the API framework is not required for temporary space allocation. This enables developers to manage the sharedTmpBuffer space and reuse the buffer after calling the API, so that the buffer is not repeatedly allocated or deallocated, improving the flexibility and buffer utilization.
- When the API framework allocates temporary space, developers do not need to allocate the space but must reserve the required size for the temporary space.
If sharedTmpBuffer is used, developers must allocate space for the tensor. If the API framework is used, developers must reserve the temporary space. To obtain the size of the temporary space (BufferSize) to be reserved, use the API provided in GetSinCosMaxMinTmpSize.
Parameters
Parameter |
Description |
|---|---|
SinCosConfig |
SinCos algorithm configuration. This is an optional parameter of the SinCosConfig type. The code below describes the definition. isReuseSource: whether the source operand can be modified. This parameter is reserved. Pass the default value false. |
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are half and float. |
1 2 3 | struct SinCosConfig { bool isReuseSource; }; |
Parameter |
Input/Output |
Description |
|---|---|---|
dst0, dst1 |
Output |
Destination operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. |
src |
Input |
Source operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The source operand must have the same data type as the destination operand. |
sharedTmpBuffer |
Input |
Temporary buffer. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. For details about how to obtain the temporary space size (BufferSize), see GetSinCosMaxMinTmpSize. |
count |
Input |
Number of elements involved in the computation. |
Returns
None
Constraints
- The source operand address must not overlap the destination operand address.
- The address of sharedTmpBuffer cannot overlap that of the source or destination operand.
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
Examples
For details about a complete example, see SinCos operator sample.
- Pass the temporary space through the sharedTmpBuffer input parameter.
1 2 3 4 5 6 7 8
AscendC::TPipe pipe; AscendC::TQue<AscendC::TPosition::VECCALC, 1> tmpQue; pipe.InitBuffer(tmpQue, 1, bufferSize); // bufferSize is obtained through the tiling parameter on the host. LocalTensor<uint8_t> sharedTmpBuffer = tmpQue.AllocTensor<uint8_t>(); // The input tensor length is 1,024, the input data type of the operator is half, and the number of actually computed data elements is 512. static constexpr AscendC::SinCosConfig sincosConfig = { false }; // The source operand is not modified. // dst0, dst1, and src are LocalTensors of the half type. AscendC::SinCos<sincosConfig, half>(dst0, dst1, src, sharedTmpBuffer, 512);
- The API framework allocates temporary space.
1 2 3 4 5 6 7
AscendC::TPipe pipe; AscendC::TQue<AscendC::TPosition::VECCALC, 1> tmpQue; pipe.InitBuffer(tmpQue, 1, bufferSize); // bufferSize is obtained through the tiling parameter on the host. // The input tensor length is 1,024, the input data type of the operator is half, and the number of actually computed data elements is 512. static constexpr AscendC::SinCosConfig sincosConfig = { false }; // The source operand is not modified. // dst0, dst1, and src are LocalTensors of the half type. AscendC::SinCos<sincosConfig, half>(dst0, dst1, src, 512);
1 2 3 4 5 6 | Input (src0): [ -360, -270, -180, -90, 0, 90, 180, 270, 360 ] Output (dst0): [ 0, 1, 0, -1, 0, 1, 0, -1, 0] Output (dst1): [ 1, 0, -1, 0, 1, 0, -1, 0, 1] |