MCPcopy Index your code
hub / github.com/apache/tvm / _DLTensorShapeProxy

Class _DLTensorShapeProxy

python/tvm/relax/expr.py:393–460  ·  view source on GitHub ↗

A proxy object for unpacking the shape from DLTensor Exposes accessors for the `DLTensor::shape` field. Accessing these fields will produce `relax.Call` expressions, representing the field's runtime value. If the datatype of the tensor is known at compile-time, the `relax.Call` wi

Source from the content-addressed store, hash-verified

391
392
393class _DLTensorShapeProxy(tvm.runtime.ObjectConvertible):
394 """A proxy object for unpacking the shape from DLTensor
395
396 Exposes accessors for the `DLTensor::shape` field. Accessing
397 these fields will produce `relax.Call` expressions, representing
398 the field's runtime value. If the datatype of the tensor is known
399 at compile-time, the `relax.Call` will be normalized into a
400 `relax.PrimValue`, with no runtime cost.
401
402 Parameters
403 ----------
404 tensor: relax.Expr
405
406 The relax tensor (or a variable referring to a relax tensor),
407 whose runtime shape is being inspected.
408 """
409
410 def __init__(self, tensor):
411 self.tensor = tensor
412
413 def asobject(self):
414 """Provide expected in error message
415
416 This method is called when `_DLTensorShapeProxy` is used in a
417 context that requires a `relax.Expr`. This usage is not
418 supported, and raising an error here can provide suggested
419 fixes that are not present in the default error message from
420 `tvm.runtime.convert`.
421 """
422 raise TypeError(
423 f"{self.tensor}.shape cannot be converted to a relax expression, "
424 f"and should be used as a proxy object to access the runtime shape of the DLTensor. "
425 f"The DLTensor::ndim field can be accessed as len({self.tensor}), "
426 f"and the DLTensor::shape array can be accessed as {self.tensor}.shape[i]"
427 )
428
429 def __getitem__(self, axis: int | PrimExpr | Expr) -> Expr:
430 """Returns the extent of a tensor axis
431
432 Parameters
433 ----------
434 axis: int | PrimExpr | Expr
435
436 The tensor axis whose extent should be returned. For ease
437 of use, any python integers or TIR expressions are
438 converted to `relax.Expr`.
439
440 Returns
441 -------
442 extent: Expr
443
444 The extent of the tensor's axis.
445 """
446
447 if not isinstance(axis, tvm.relax.Expr):
448 axis = tvm.relax.PrimValue(axis)
449
450 if axis.struct_info_ is not None and not isinstance(

Callers 1

shapeMethod · 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…