MCPcopy Create free account
hub / github.com/apache/tvm / DtypeConstructor

Class DtypeConstructor

python/tvm/tirx/script/builder/ir.py:1528–1559  ·  view source on GitHub ↗

Callable + subscriptable dtype object. Replaces the plain functions previously returned by ``func_gen``. * ``T.float32()`` — same FFI call as before (returns ``Var``). * ``T.float32[N]`` — returns ``LocalVectorAnnotation("float32", (N,))``. * ``T.float32[M, N]`` — r

Source from the content-addressed store, hash-verified

1526
1527
1528class DtypeConstructor:
1529 """Callable + subscriptable dtype object.
1530
1531 Replaces the plain functions previously returned by ``func_gen``.
1532
1533 * ``T.float32()`` — same FFI call as before (returns ``Var``).
1534 * ``T.float32[N]`` — returns ``LocalVectorAnnotation("float32", (N,))``.
1535 * ``T.float32[M, N]`` — returns ``LocalVectorAnnotation("float32", (M, N))``.
1536 * ``x: T.float32`` — parser calls this object, gets a ``Var``.
1537 """
1538
1539 def __init__(self, ffi_name: str, dtype_str: str):
1540 self._ffi_name = ffi_name
1541 self._dtype_str = dtype_str
1542
1543 def __call__(
1544 self,
1545 expr: "None | PrimExpr | Literal['inf', '-inf', 'nan'] | int | float" = None,
1546 *,
1547 is_size_var: bool = False,
1548 ) -> "PrimExpr":
1549 if isinstance(expr, str):
1550 expr = float(expr)
1551 return getattr(_ffi_api, self._ffi_name)(expr, is_size_var)
1552
1553 def __getitem__(self, shape):
1554 if isinstance(shape, tuple):
1555 return LocalVectorAnnotation(self._dtype_str, shape)
1556 return LocalVectorAnnotation(self._dtype_str, (shape,))
1557
1558 def __repr__(self):
1559 return f"DtypeConstructor({self._dtype_str!r})"
1560
1561
1562def allocate(

Callers 1

func_genFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…