set_as

Description

Sets the value of a Scalar.

Prototype

set_as(value, src_offset=None)

Parameters

Table 1 Parameter description

Parameter

Input/Output

Description

value

Input

Value to set. Supported data types:

  • An immediate of type int or float
  • A Scalar variable
  • An Expr consisting of a Scalar variable and an immediate
  • A Tensor value. Must be in the following scope:

    Atlas training product: scope_ubuf

    Atlas inference product AI Core: scope_ubuf or scope_gm

    Atlas inference product Vector Core: scope_ubuf or scope_gm

    Atlas A2 training product/Atlas A2 inference product: scope_ubuf or scope_gm

    Atlas 200I/500 A2 inference product: scope_ubuf or scope_gm

src_offset

Input

Reserved and not recommended.

Applicability

Atlas training product

Atlas inference product AI Core

Atlas inference product Vector Core

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Restrictions

For the Atlas training product, setting a Scalar of type float16 to an Expr value is not supported.

For the Atlas inference product AI Core, setting a Scalar of type float16 to an Expr value is not supported.

For the Atlas inference product Vector Core, setting a Scalar of type float16 to an Expr value is not supported.

For the Atlas A2 training product/Atlas A2 inference product, setting a Scalar of type float16 to an Expr value is not supported.

For the Atlas 200I/500 A2 inference product, setting a Scalar of type float16 to an Expr value is not supported.

Returns

None

Example

from tbe import tik
tik_instance = tik.Tik()
# Immediate: int
index_reg = tik_instance.Scalar(dtype = "int32")
index_reg.set_as(10)   

# Immediate: float
index_reg2 = tik_instance.Scalar(dtype = "float16")
index_reg2.set_as(10.2) 

# A Scalar variable
index_reg3 = tik_instance.Scalar(dtype = "float16")
index_reg3.set_as(index_reg2)  

# A Tensor value
data_A = tik_instance.Tensor("float16", (128,), name="data_A", scope=tik.scope_ubuf)
index_reg3.set_as(data_A[0])// tensor value

#An Expr
index_reg4 = tik_instance.Scalar(dtype = "int32")
index_reg4.set_as(index_reg+20)