Constructs a for loop with the provided body. The body is a function taking as argument the iteration variables and building the operations within the body (including continue and break). By default, only the induction variable is created. If initializers for additional iterati
(
body: Callable,
lower_bound: int | Tile,
upper_bound: int | Tile,
step: int | Tile = 1,
init_values: Sequence[Tile] = (),
el_type=Int32,
*,
unsigned: bool = False,
loc=None,
ip=None,
)
| 3935 | |
| 3936 | @cuda_tile_op |
| 3937 | def for_loop( |
| 3938 | body: Callable, |
| 3939 | lower_bound: int | Tile, |
| 3940 | upper_bound: int | Tile, |
| 3941 | step: int | Tile = 1, |
| 3942 | init_values: Sequence[Tile] = (), |
| 3943 | el_type=Int32, |
| 3944 | *, |
| 3945 | unsigned: bool = False, |
| 3946 | loc=None, |
| 3947 | ip=None, |
| 3948 | ) -> Tuple[Tile, ...]: |
| 3949 | """ |
| 3950 | Constructs a for loop with the provided body. The body is a function taking |
| 3951 | as argument the iteration variables and building the operations within the |
| 3952 | body (including continue and break). |
| 3953 | |
| 3954 | By default, only the induction variable is created. If initializers for |
| 3955 | additional iteration variables are provided in `init_values`, additional |
| 3956 | iteration variables will be passed to the body and returned from the |
| 3957 | operation. |
| 3958 | |
| 3959 | By default, the induction variable element type is Int32, which can be |
| 3960 | overriden by setting `el_type`. |
| 3961 | |
| 3962 | By default, signed comparison is used for loop termination. Set `unsigned=True` |
| 3963 | to use unsigned integer comparison. |
| 3964 | """ |
| 3965 | |
| 3966 | index_type = el_type.mlir_type |
| 3967 | |
| 3968 | def check_scalar(x: int | Tile, name: str) -> Tile: |
| 3969 | nonlocal index_type |
| 3970 | if isinstance(x, int): |
| 3971 | return constant(x, el_type) |
| 3972 | elif isinstance(x, Tile) and x.element_type == index_type and len(x.shape) == 0: |
| 3973 | return x |
| 3974 | else: |
| 3975 | raise TypeError( |
| 3976 | f"For loop {name} must be an integer or a scalar {el_type} tile value, got {x}" |
| 3977 | ) |
| 3978 | |
| 3979 | lower_bound = check_scalar(lower_bound, "lower bound") |
| 3980 | upper_bound = check_scalar(upper_bound, "upper bound") |
| 3981 | step = check_scalar(step, "step") |
| 3982 | |
| 3983 | iter_arg_types = tuple(x.tile_type for x in init_values) |
| 3984 | _for_op = _cuda_tile.ForOp( |
| 3985 | resultValues=iter_arg_types, |
| 3986 | lowerBound=lower_bound, |
| 3987 | upperBound=upper_bound, |
| 3988 | step=step, |
| 3989 | initValues=init_values, |
| 3990 | unsignedCmp=unsigned, |
| 3991 | loc=loc, |
| 3992 | ip=ip, |
| 3993 | ) |
| 3994 |
nothing calls this directly
no test coverage detected