elif_scope
Description
Specifies the current elif_scope code block to be executed if previous if_scope and elif_scope are not true and the current elif_scope is true.
The pseudocode is as follows:
# When cond1 is true, execute the if_scope code block. if_scope(cond1) # Execute the elif_scope code block if if_scope is not true while cond2 in this statement is true. # The first elif_scope statement must be after the if_scope function. elif_scope(cond2) # Execute the elif_scope code block when the preceding if_scope and elif_scope statements are not true while cond3 in this statement is true. elif_scope(cond3)
Prototype
elif_scope(cond)
Parameters
Parameter |
Input/Output |
Description |
|---|---|---|
cond |
Input |
It supports the InputScalar, Scalar, immediate (int and float), Expr, and bool data types, and any, all, and negate functions. Specifically,
NOTICE:
The Expr supports the following operators:
You can use supported operators to form a complex expression. However, the comparison operators cannot be used together. For example, if you want to express n > 1 and n < 4: |
Applicability
Restrictions
- Use this conditional statement after the if_scope or elif_scope function.
- The number of elif_scope and else_scope statements following if_scope must not exceed 400.
- The Scalar in Expr does not support the following data types:
For the
Atlas training product , the Expr must not contain Scalars of type float16.For the
Atlas inference product AI Core, the Expr must not contain Scalars of type float16.For the
Atlas inference product Vector Core, the Expr must not contain Scalars of type float16.For the
Atlas A2 training product /Atlas A2 inference product , the Expr must not contain Scalars of type float16.For the
Atlas 200I/500 A2 inference product , the Expr must not contain Scalars of type float16.
Returns
A TikWithScope object.
It is inherited from WithScope of TVM.
Example
tik_instance = tik.Tik()
cond = tik_instance.InputScalar(dtype="int16", name="cond")
src_gm = tik_instance.Tensor(dtype="int64", shape=(16, ),
scope=tik.scope_gm, name="src_gm")
dst_ub = tik_instance.Tensor(dtype="int64", shape=(4, ),
scope=tik.scope_ubuf, name="dst_ub")
dst_gm = tik_instance.Tensor(dtype="int64", shape=(4, ),
scope=tik.scope_gm, name="dst_gm")
# Initialize dst to src_gm[0:3].
tik_instance.data_move(dst_ub, src_gm[0:3,], 0, 1, 1, 0, 0)
# Move slices of src to dst based on cond's value.
# When cond==1 is true, execute the if_scope code block.
with tik_instance.if_scope(cond == 1):
tik_instance.data_move(dst_ub, src_gm[4:7,], 0, 1, 1, 0, 0)
# When cond==1 is false and cond==2 is true, execute the elif_scope code block.
with tik_instance.elif_scope(cond == 2):
tik_instance.data_move(dst_ub, src_gm[8:11,], 0, 1, 1, 0, 0)
# When cond==1 and cond==2 are false while cond==3 is true, execute the elif_scope code block.
with tik_instance.elif_scope(cond == 3):
tik_instance.data_move(dst_ub, src_gm[12:15,], 0, 1, 1, 0, 0)
# Move dst to the Global Memory for output.
tik_instance.data_move(dst_gm, dst_ub, 0, 1, 1, 0, 0)
tik_instance.BuildCCE(kernel_name="if_scope", inputs=[src_gm, cond], outputs=[dst_gm])
Result example
Input (src_gm): [0, 1, 2,..., 15] Input (cond): 3 Output (dst_gm): [12, 13, 14, 15]