Conversion

The conversion part of IR APIs.

tvm.aipu.script.ir.conversion.i16x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.u16x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.i32x16(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.i32x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.u32x16(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.u32x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.fp16x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.int16x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.uint16x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.int32x16(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.int32x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.uint32x16(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.uint32x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.float16x32(init_value)

Create a new variable with the specified type and initial value.

Parameters

init_valueUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The initial value of the new variable.

Returns

rettir.PrimExpr

The new created variable.

tvm.aipu.script.ir.conversion.size_i16x32(init_value)

Create a new variable that represent a vector index size whose value is always greater or equal to zero.

Parameters

init_valueUnion[tir.PrimExpr, int, list, tuple]

The initial value of the new variable.

Returns

ret : tir.SizeVar The new created size variable.

tvm.aipu.script.ir.conversion.size_i32x16(init_value)

Create a new variable that represent a vector index size whose value is always greater or equal to zero.

Parameters

init_valueUnion[tir.PrimExpr, int, list, tuple]

The initial value of the new variable.

Returns

ret : tir.SizeVar The new created size variable.

tvm.aipu.script.ir.conversion.size_i32x32(init_value)

Create a new variable that represent a vector index size whose value is always greater or equal to zero.

Parameters

init_valueUnion[tir.PrimExpr, int, list, tuple]

The initial value of the new variable.

Returns

ret : tir.SizeVar The new created size variable.

tvm.aipu.script.ir.conversion.size_int16x32(init_value)

Create a new variable that represent a vector index size whose value is always greater or equal to zero.

Parameters

init_valueUnion[tir.PrimExpr, int, list, tuple]

The initial value of the new variable.

Returns

ret : tir.SizeVar The new created size variable.

tvm.aipu.script.ir.conversion.size_int32x16(init_value)

Create a new variable that represent a vector index size whose value is always greater or equal to zero.

Parameters

init_valueUnion[tir.PrimExpr, int, list, tuple]

The initial value of the new variable.

Returns

ret : tir.SizeVar The new created size variable.

tvm.aipu.script.ir.conversion.size_int32x32(init_value)

Create a new variable that represent a vector index size whose value is always greater or equal to zero.

Parameters

init_valueUnion[tir.PrimExpr, int, list, tuple]

The initial value of the new variable.

Returns

ret : tir.SizeVar The new created size variable.

tvm.aipu.script.ir.conversion.cast(x, dtype, part='all', saturate=None)

Converts the given expression or value to the specified type.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[tir.PrimExpr, Literal[“inf”, “-inf”, “nan”], int, float, list, tuple]

The expression or value that needs to be cast.

dtypeUnion[str, DataType]

The target data type. If it is set to a scalar one when the given expression or value is a vector, it will be changed to a vector one with the lanes of the given expression or value automatically.

partOptional[str]

Only used for the vector conversion, used to specify which part data of the given expression or value needs to be converted.

  • all: Represent all data.

  • low, high, even, odd: Represent the corresponding half data.

  • ll, lh, hl, hh: Represent the corresponding quarter data.

saturateOptional[bool]

Whether the result needs to be saturated or not. Only used when the target data type is integer, and its range does not complete contain that of the source data type, e.g., i8 -> u16, (i32x8, i32x8) -> i16x16. None means auto set according to best performance, i.e., when casting floating to integer, True for float16/float32 to int32 stage, False for int32 to the target data type stage, False when casting in other situations.

Returns

rettir.PrimExpr

The result expression with the needed type.

Examples

scalar_b = S.cast(scalar_var, dtype)
fp32_100 = S.cast(100, "float32")
vb = S.cast(va, dtype)
vindex0_u = S.cast(vindex0, "uint16x16")
inp1_fp32_l, inp1_fp32_h = S.cast(inp1, "float32", "low"), S.cast(inp1, "float32", "high")
va_fp32_e = S.cast(va, "fp32", part="even")
va_fp32_o = S.cast(va, "fp32", part="odd")
va_fp16x16 = S.cast((va_fp32x8, va_fp32x8), "fp16")
vb = S.cast(va, dtype, saturate=True)

See Also

tvm.aipu.script.ir.conversion.i(x)

Converts the given expression to the signed type with the same bits and lanes.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xtir.PrimExpr

The expression that needs to be cast to signed type.

Returns

rettir.PrimExpr

The result expression with the signed type.

Supported DType

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

Examples

a0_i32 = S.i(a_ptr_u32[0])
a0_i16 = S.i(a_ptr_u16[0] + vector_b)
a0_i8 = S.i(a_ptr_u8[0] - 10)

See Also

tvm.aipu.script.ir.conversion.u(x)

Converts the given expression to the unsigned type with the same bits and lanes.

  • The feature Flexible Width Vector is supported.

  • The feature Multiple Width Vector is supported.

Parameters

xtir.PrimExpr

The expression that needs to be cast to unsigned type.

Returns

rettir.PrimExpr

The result expression with the unsigned type.

Supported DType

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

Examples

a0_u32 = S.u(a_ptr_i32[0])
a0_u16 = S.u(a_ptr_i16[0] + vector_b)
a0_u8 = S.u(a_ptr_i8[0] - 10)

See Also

tvm.aipu.script.ir.conversion.reinterpret(x, dtype)

Reinterprets the given expression to the specific data type.

  • The feature Multiple Width Vector is supported.

Parameters

xUnion[Pointer, PrimExpr, int, float]

The expression or value that need to be reinterpreted.

dtypeUnion[str, DataType]

The target data type.

Returns

retPrimExpr

The result expression.

Examples

a0_u32 = S.reinterpret(a_ptr_i32[0], "u32")
a0_i16 = S.reinterpret(a_ptr_u16[0] + vector_b, "i16")
a0_u8 = S.reinterpret(a_ptr_i8[0] - 10, "u8")
a0_u32 = S.reinterpret(1.2345, "u32")
a0_fp16 = S.reinterpret(S.i16(1.2345), "fp16")
a0_fp32x8 = S.reinterpret(S.u32x8(123), "fp32x8")

See Also

tvm.aipu.script.ir.conversion.vxtl(x)

Extends the low half elements of x to double size. Sign-extends if signed dtype else zero-extends.

 x(i16x16): 1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16

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

Parameters

xPrimExpr

The operands.

Returns

retPrimExpr

The result expression.

Supported DType

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

Examples

vc = S.vxtl(vx)

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vsxtl, __vuxtl

tvm.aipu.script.ir.conversion.vxth(x)

Extends the high half elements of x to double size. Sign-extends if signed dtype else zero-extends.

 x(i16x16): 1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16

out = S.vxth(x)
out(i32x8): 9     10    11    12    13    14    15    16

Parameters

xPrimExpr

The operands.

Returns

retPrimExpr

The result expression.

Supported DType

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

Examples

vc = S.vxth(vx)

See Also

  • Zhouyi Compass OpenCL Programming Guide: __vsxth, __vuxth