Math

The math part of IR APIs.

tvm.aipu.script.ir.math.exp(x)

Computes the exponential of x.

  • The scalar situation where x is a scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[PrimExpr, float]

The operand.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.exp(va)
scalar_b = S.exp(1.23456)

See Also

  • Zhouyi Compass OpenCL Programming Guide: exp

tvm.aipu.script.ir.math.log(x)

Computes the natural logarithm of x.

  • The scalar situation where x is a scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[PrimExpr, float]

The operands.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.log(va)
scalar_b = S.log(1.23456)

See Also

  • Zhouyi Compass OpenCL Programming Guide: log

tvm.aipu.script.ir.math.tanh(x)

Computes the hyperbolic tangent of x.

  • The scalar situation where x is a scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[PrimExpr, float]

The operands.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.tanh(va)
scalar_b = S.tanh(1.23456)

See Also

  • Zhouyi Compass OpenCL Programming Guide: tanh

tvm.aipu.script.ir.math.sin(x)

Compute the trigonometric sine of x.

  • The scalar situation where x is a scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[PrimExpr, float]

The operands.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.sin(va)
scalar_b = S.sin(1.23456)

See Also

  • Zhouyi Compass OpenCL Programming Guide: sin

tvm.aipu.script.ir.math.cos(x)

Computes the trigonometric cosine of x.

  • The scalar situation where x is a scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[PrimExpr, float]

The operands.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.cos(va)
scalar_b = S.cos(1.23456)

See Also

  • Zhouyi Compass OpenCL Programming Guide: cos

tvm.aipu.script.ir.math.rsqrt(x)

Computes the reciprocal of the square-root of x.

  • The scalar situation where x is a scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[PrimExpr, float]

The operands.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.rsqrt(va)
scalar_b = S.rsqrt(1.23456)

See Also

  • Zhouyi Compass OpenCL Programming Guide: rsqrt

tvm.aipu.script.ir.math.sqrt(x)

Computes the square-root of x.

  • The scalar situation where x is a scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

  x: 1  4  9  16 25 36 49 64

out = S.sqrt(x)
out: 1  2  3  4  5  6  7  8

Parameters

xUnion[PrimExpr, float]

The operands.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.sqrt(va)
scalar_b = S.sqrt(1.23456)

See Also

  • Zhouyi Compass OpenCL Programming Guide: sqrt

tvm.aipu.script.ir.math.floor(x)

Computes the floor of x.

  • The scalar situation where x is a scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[PrimExpr, float]

The operands.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.floor(va)
scalar_b = S.floor(1.23456)

See Also

  • Zhouyi Compass OpenCL Programming Guide: floor

tvm.aipu.script.ir.math.ceil(x)

Computes the ceil of x.

  • The scalar situation where x is a scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[PrimExpr, float]

The operands.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.ceil(va)
scalar_b = S.ceil(1.23456)

See Also

  • Zhouyi Compass OpenCL Programming Guide: ceil

tvm.aipu.script.ir.math.ceildiv(x, y)

Computes the ceil division on integer scalar x and y.

Parameters

x, yUnion[PrimExpr, int]

The operands. They must be integer scalar.

Returns

retPrimExpr

The result.

Supported DType

“int8/16/32”, “uint8/16/32”.

Examples

b = S.ceildiv(scalar_a, 8)
b = S.ceildiv(lsram_a[0], 8)  # The "lsram_a" is a scalar buffer.
tvm.aipu.script.ir.math.pow(x, exponent)

Computes the power of x with the corresponding elements of exponent.

  • The scalar situation where both x and exponent are scalar is also supported.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[PrimExpr, float]

The base value. If it is a scalar in the vector situation, it will be automatically broadcast.

exponentUnion[PrimExpr, float]

The exponent value. If it is a scalar in the vector situation, it will be automatically broadcast.

Returns

retPrimExpr

The result.

Supported DType

“float16/32”.

Examples

vc = S.pow(va, vb)
scalar_b = S.pow(2.0, 3.0)

See Also

  • Zhouyi Compass OpenCL Programming Guide: pow