Verifies input tuple is IntImm or Var, returns tuple of int or Var. Parameters ---------- in_tuple : tuple of Expr The input. Returns ------- out_tuple : tuple of int The output.
(in_tuple)
| 174 | |
| 175 | |
| 176 | def get_const_tuple(in_tuple): |
| 177 | """Verifies input tuple is IntImm or Var, returns tuple of int or Var. |
| 178 | |
| 179 | Parameters |
| 180 | ---------- |
| 181 | in_tuple : tuple of Expr |
| 182 | The input. |
| 183 | |
| 184 | Returns |
| 185 | ------- |
| 186 | out_tuple : tuple of int |
| 187 | The output. |
| 188 | """ |
| 189 | if isinstance(in_tuple, te.tensor.Tensor): |
| 190 | raise TypeError( |
| 191 | "get_const_tuple expects a tuple-like shape (e.g., tensor.shape), " |
| 192 | "but got a te.Tensor. Did you mean get_const_tuple(tensor.shape)?" |
| 193 | ) |
| 194 | ret = [] |
| 195 | ana = None |
| 196 | for elem in in_tuple: |
| 197 | if isinstance(elem, tvm.tirx.Var): |
| 198 | ret.append(elem) |
| 199 | elif not isinstance(elem, tvm.tirx.IntImm | int): |
| 200 | ana = tvm.arith.Analyzer() if ana is None else ana |
| 201 | elem = ana.simplify(elem) |
| 202 | if not isinstance(elem, tvm.tirx.IntImm): |
| 203 | ret.append(elem) |
| 204 | else: |
| 205 | ret.append(get_const_int(elem)) |
| 206 | else: |
| 207 | ret.append(get_const_int(elem)) |
| 208 | return tuple(ret) |
| 209 | |
| 210 | |
| 211 | def const_vector(vector, name="const_vector"): |
searching dependent graphs…