| AI Engine API User Guide (AIE-API) 2025.2

Loading...
Searching...
No Matches
Topics | Functions
Elementary Functions

## Overview

## Topics
| Floating-point Scalar Operations

## Functions
template<ComplexElem E>
constexpr auto | aie::abs_square (const E &v) -> detail::remove_complex_t< operand_base_type_t< E > >
| Compute the absolute square of a scalar complex value.
template<RealVector Vec> requires (arch::is(arch::AIE))
auto | aie::cos (const Vec &v) -> aie_dm_resource_remove_t< Vec >
| Performs a cosine operation on all elements in the input vector.
template<typename E> requires (arch::is(arch::AIE) && (RealElem<E> || std::is_integral_v<E>))
auto | aie::cos (E a)
| Performs a cosine operation on a single value.
template<typename TR = bfloat16, unsigned Elems> requires ((arch::is(arch::XDNA2) && Utils::is_one_of_v<TR, bfloat16>) || (arch::is(arch::AIE_MLv2) && Utils::is_one_of_v<TR, bfloat16, float>))
auto | aie::exp2 (const vector< float, Elems > &v) -> vector< TR, Elems >
| Compute the 2 raised to the power function for all elements in a vector.
template<ComplexElem C>
auto | aie::inv (C a)
| Returns the inverse value of a complex number.
template<unsigned Elems> requires (arch::is(arch::AIE))
accum< accfloat, Elems > | aie::inv (const accum< accfloat, Elems > &v)
| Returns the inverse value of every element in an accumulator.
template<Vector Vec>
auto | aie::inv (const Vec &v) -> aie_dm_resource_remove_t< Vec >
| Returns the inverse value of every element in a vector.
template<RealElem E>
auto | aie::inv (E a)
| Returns the inverse value.
template<unsigned Elems> requires (arch::is(arch::AIE))
accum< accfloat, Elems > | aie::invsqrt (const accum< accfloat, Elems > &v)
| Performs an approximation of the inversed square root of every element in a floating point accumulator.
template<RealVector Vec>
auto | aie::invsqrt (const Vec &v) -> aie_dm_resource_remove_t< Vec >
| Performs an approximation of the inversed square root of every element in a vector.
template<RealElem E>
auto | aie::invsqrt (E a)
| Performs an approximation of the inversed square root of a single value.
template<RealVector Vec> requires (arch::is(arch::AIE))
auto | aie::sin (const Vec &v) -> aie_dm_resource_remove_t< Vec >
| Performs a sine operation on all elements in the input vector.
template<typename E> requires (arch::is(arch::AIE) && (RealElem<E> || std::is_integral_v<E>))
auto | aie::sin (E a)
| Performs a sine operation on a single value.
template<RealVector Vec> requires (arch::is(arch::AIE))
auto | aie::sincos (const Vec &v) -> std::pair< aie_dm_resource_remove_t< Vec >, aie_dm_resource_remove_t< Vec > >
| Same as sin and cos, but performs both operations and returns a std::pair of vectors of result values.
template<typename E> requires (arch::is(arch::AIE) && (RealElem<E> || std::is_integral_v<E>))
auto | aie::sincos (E a)
| Performs both sin and cos, and returns both values as an std::pair (sin first, then cos).
template<RealVector Vec> requires (arch::is(arch::AIE))
auto | aie::sincos_complex (const Vec &v) -> vector< std::conditional_t< Vec::is_floating_point(), cfloat, cint16 >, Vec::size()>
| Same as sincos, but returns both values as the real and imaginary parts in a vector of complex values (cos in the real part, sin in the imaginary).
template<typename E> requires (arch::is(arch::AIE) && (RealElem<E> || std::is_integral_v<E>))
auto | aie::sincos_complex (E a) -> std::conditional_t< detail::is_floating_point_v< operand_base_type_t< E > >, cfloat, cint16 >
| Same as sincos, but returns both values as the real and imaginary parts of a complex number (cos in the real part, sin in the imaginary part).
template<unsigned Elems> requires (arch::is(arch::AIE))
accum< accfloat, Elems > | aie::sqrt (const accum< accfloat, Elems > &v)
| Returns the square root of all values in an accumulator.
template<RealVector Vec>
auto | aie::sqrt (const Vec &v) -> aie_dm_resource_remove_t< Vec >
| Returns the square root of all values in a vector.
template<RealElem E>
auto | aie::sqrt (E a)
| Returns the square root of a value.
template<typename TR = bfloat16, unsigned Elems> requires (arch::is(arch::XDNA2, arch::AIE_MLv2))
auto | aie::tanh (const vector< float, Elems > &v) -> vector< TR, Elems >
| Compute the hyperbolic tangent function on the elements of the input vector.

## Function Documentation

## ◆ abs_square()

template<ComplexElem E>

auto aie::abs_square | ( | const E & | v | ) | -> detail::remove_complex_t<operand_base_type_t<E>>
| constexpr

Compute the absolute square of a scalar complex value.

\( f(a + b i) = a^2 + b^2 \)

Parameters

  v | Input complex scalar

## ◆ cos() [1/2]

template<RealVector Vec>
requires (arch::is(arch::AIE))

auto aie::cos | ( | const Vec & | v | ) | -> aie_dm_resource_remove_t<Vec>

Performs a cosine operation on all elements in the input vector.

The input vector can either be of float values in radians or integers. The floating-point range is [-Pi, Pi]. Integer values are handled as a fixed-point input value in Q1.31 format scaled with 1/Pi (input value 2^31 corresponds to Pi). In this case only the upper 20-bit of the input value are used.

According to input type, returns a vector of float or of signed Q.15 fixed-point format.

Parameters

  v | Input vector. The type must meet aie::RealVector.

Note
  This is a scalar operation. Even though the function operates with vectors, the actual operation is applied to each element individually.

## ◆ cos() [2/2]

template<typename E>
requires (arch::is(arch::AIE) && (RealElem<E> || std::is_integral_v<E>))

auto aie::cos | ( | E | a | ) |

Performs a cosine operation on a single value.

The input can either be a float value in radians or an integer. The floating-point range is [-Pi, Pi]. Integer values are handled as a fixed-point input value in Q1.31 format scaled with 1/Pi (input value 2^31 corresponds to Pi). In this case only the upper 20-bit of the input value are used.

According to input type, the returned value is either a float or a signed Q.15 fixed-point format.

Parameters

  a | Value. The type must meet aie::RealElem.

## ◆ exp2()

template<typename TR = bfloat16, unsigned Elems>
requires ((arch::is(arch::XDNA2) && Utils::is_one_of_v<TR, bfloat16>) || (arch::is(arch::AIE_MLv2) && Utils::is_one_of_v<TR, bfloat16, float>))

auto aie::exp2 | ( | const vector< float, Elems > & | v | ) | -> vector<TR, Elems>

Compute the 2 raised to the power function for all elements in a vector.

\( f(v_{i}) = 2^{v_{i}} \)

Parameters

  v | Input values.

## ◆ inv() [1/4]

template<ComplexElem C>

auto aie::inv | ( | C | a | ) |

Returns the inverse value of a complex number.

\( z^{-1} = \frac{1}{a + bi} = \frac{a - bi}{a^2 + b^2} \)

Parameters

  a | Input value. It must meet aie::ComplexElem.

## ◆ inv() [2/4]

template<unsigned Elems>
requires (arch::is(arch::AIE))

accum< accfloat, Elems > aie::inv | ( | const accum< accfloat, Elems > & | v | ) |

Returns the inverse value of every element in an accumulator.

\( f(v_{i}) = v_{i}^{-1} \)

Note
  This is a scalar operation. Even though the function operates with accumulators, the actual operation is applied to each element individually.

Parameters

  v | Input values.

## ◆ inv() [3/4]

template<Vector Vec>

auto aie::inv | ( | const Vec & | v | ) | -> aie_dm_resource_remove_t<Vec>

Returns the inverse value of every element in a vector.

\( f(v_{i}) = v_{i}^{-1} \)

Note
  This is a scalar operation. Even though the function operates with vectors, the actual operation is applied to each element individually.

Parameters

  v | Input values. It must meet aie::Vector

## ◆ inv() [4/4]

template<RealElem E>

auto aie::inv | ( | E | a | ) |

Returns the inverse value.

\( f(a) = a^{-1} \)

Parameters

  a | Input value. It must meet aie::RealElem.

## ◆ invsqrt() [1/3]

template<unsigned Elems>
requires (arch::is(arch::AIE))

accum< accfloat, Elems > aie::invsqrt | ( | const accum< accfloat, Elems > & | v | ) |

Performs an approximation of the inversed square root of every element in a floating point accumulator.

\( f(v_{i}) \approx \frac{1}{\sqrt{v_{i}}} \)

Parameters

  v | Input values.

## ◆ invsqrt() [2/3]

template<RealVector Vec>

auto aie::invsqrt | ( | const Vec & | v | ) | -> aie_dm_resource_remove_t<Vec>

Performs an approximation of the inversed square root of every element in a vector.

\( f(v_{i}) \approx \frac{1}{\sqrt{v_{i}}} \)

Note
  Due to the variations in support across architectures, the results of this function may differ slightly across devices.

Parameters

  v | Input values. The type must meet aie::Vector.

## ◆ invsqrt() [3/3]

template<RealElem E>

auto aie::invsqrt | ( | E | a | ) |

Performs an approximation of the inversed square root of a single value.

\( f(a) \approx \frac{1}{\sqrt{a}} \)

Note
  Due to the variations in support across architectures, the results of this function may differ slightly across devices.

Parameters

  a | Input value. The type must meet aie::Elem.

## ◆ sin() [1/2]

template<RealVector Vec>
requires (arch::is(arch::AIE))

auto aie::sin | ( | const Vec & | v | ) | -> aie_dm_resource_remove_t<Vec>

Performs a sine operation on all elements in the input vector.

The input vector can either be of float values in radians or integers. The floating-point range is [-Pi, Pi]. Integer values are handled as a fixed-point input value in Q1.31 format scaled with 1/Pi (input value 2^31 corresponds to Pi). In this case only the upper 20-bit of the input value are used.

According to input type, returns a vector of float or of signed Q.15 fixed-point format.

Parameters

  v | Input vector. The type must meet aie::RealVector.

Note
  This is a scalar operation. Even though the function operates with vectors, the actual operation is applied to each element individually.

## ◆ sin() [2/2]

template<typename E>
requires (arch::is(arch::AIE) && (RealElem<E> || std::is_integral_v<E>))

auto aie::sin | ( | E | a | ) |

Performs a sine operation on a single value.

The input can either be a float value in radians or an integer. The floating-point range is [-Pi, Pi]. Integer values are handled as a fixed-point input value in Q1.31 format scaled with 1/Pi (input value 2^31 corresponds to Pi). In this case only the upper 20-bit of the input value are used.

Parameters

  a | Value. The type must meet aie::RealElem.

## ◆ sincos() [1/2]

template<RealVector Vec>
requires (arch::is(arch::AIE))

auto aie::sincos | ( | const Vec & | v | ) | -> std::pair<aie_dm_resource_remove_t<Vec>, aie_dm_resource_remove_t<Vec>>

Same as sin and cos, but performs both operations and returns a std::pair of vectors of result values.

The first vector contains the sine values, the second contains the cosine values

According to input type, returns a pair of vectors of float or of signed Q.15 fixed-point format.

Parameters

  v | Input vector. The type must meet aie::RealVector.

Note
  This is a scalar operation. Even though the function operates with vectors, the actual operation is applied to each element individually.

## ◆ sincos() [2/2]

template<typename E>
requires (arch::is(arch::AIE) && (RealElem<E> || std::is_integral_v<E>))

auto aie::sincos | ( | E | a | ) |

Performs both sin and cos, and returns both values as an std::pair (sin first, then cos).

The input can either be a float value in radians or an integer. The floating-point range is [-Pi, Pi]. Integer values are handled as a fixed-point input value in Q1.31 format scaled with 1/Pi (input value 2^31 corresponds to Pi). In this case only the upper 20-bit of the input value are used.

According to input type, the returned values are either float or signed Q.15 fixed-point format.

Parameters

  a | Value. The type must meet aie::RealElem.

## ◆ sincos_complex() [1/2]

template<RealVector Vec>
requires (arch::is(arch::AIE))

auto aie::sincos_complex | ( | const Vec & | v | ) | -> vector<std::conditional_t<Vec::is_floating_point(), cfloat, cint16>, Vec::size()>

Same as sincos, but returns both values as the real and imaginary parts in a vector of complex values (cos in the real part, sin in the imaginary).

According to input type, returns a vector of float or of signed Q.15 fixed-point format.

Parameters

  v | Input vector. The type must meet aie::RealVector.

## ◆ sincos_complex() [2/2]

template<typename E>
requires (arch::is(arch::AIE) && (RealElem<E> || std::is_integral_v<E>))

auto aie::sincos_complex | ( | E | a | ) | -> std::conditional_t<detail::is_floating_point_v<operand_base_type_t<E>>, cfloat, cint16>

Same as sincos, but returns both values as the real and imaginary parts of a complex number (cos in the real part, sin in the imaginary part).

Each part of the returned complex number is either a float or a signed Q.15 fixed-point format.

Parameters

  a | Value. The type must meet aie::RealElem.

## ◆ sqrt() [1/3]

template<unsigned Elems>
requires (arch::is(arch::AIE))

accum< accfloat, Elems > aie::sqrt | ( | const accum< accfloat, Elems > & | v | ) |

Returns the square root of all values in an accumulator.

\( f(v_i) = \sqrt{v_i} \)

Note
  This is a scalar operation. Even though the function operates with accumulators, the actual operation is applied to each element individually.

Parameters

  v | Input values.

## ◆ sqrt() [2/3]

template<RealVector Vec>

auto aie::sqrt | ( | const Vec & | v | ) | -> aie_dm_resource_remove_t<Vec>

Returns the square root of all values in a vector.

\( f(v_i) = \sqrt{v_i} \)

Note
  This is a scalar operation. Even though the function operates with vectors, the actual operation is applied to each element individually.

Parameters

  v | Input value. It must meet aie::Vector.

## ◆ sqrt() [3/3]

template<RealElem E>

auto aie::sqrt | ( | E | a | ) |

Returns the square root of a value.

\( f(a) = \sqrt{a} \)

Parameters

  a | Input value. It must meet aie::Elem.

## ◆ tanh()

template<typename TR = bfloat16, unsigned Elems>
requires (arch::is(arch::XDNA2, arch::AIE_MLv2))

auto aie::tanh | ( | const vector< float, Elems > & | v | ) | -> vector<TR, Elems>

Compute the hyperbolic tangent function on the elements of the input vector.

Parameters

  v | Input vector.