A proxy object for unpacking the strides from DLTensor Exposes accessors for the `DLTensor::strides` 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
| 461 | |
| 462 | |
| 463 | class _DLTensorStrideProxy(tvm.runtime.ObjectConvertible): |
| 464 | """A proxy object for unpacking the strides from DLTensor |
| 465 | |
| 466 | Exposes accessors for the `DLTensor::strides` field. Accessing |
| 467 | these fields will produce `relax.Call` expressions, representing |
| 468 | the field's runtime value. If the datatype of the tensor is known |
| 469 | at compile-time, the `relax.Call` will be normalized into a |
| 470 | `relax.PrimValue`, with no runtime cost. |
| 471 | |
| 472 | Parameters |
| 473 | ---------- |
| 474 | tensor: relax.Expr |
| 475 | |
| 476 | The relax tensor (or a variable referring to a relax tensor), |
| 477 | whose runtime strides is being inspected. |
| 478 | """ |
| 479 | |
| 480 | def __init__(self, tensor): |
| 481 | self.tensor = tensor |
| 482 | |
| 483 | def asobject(self): |
| 484 | """Provide expected in error message |
| 485 | |
| 486 | This method is called when `_DLTensorStrideProxy` is used in a |
| 487 | context that requires a `relax.Expr`. This usage is not |
| 488 | supported, and raising an error here can provide suggested |
| 489 | fixes that are not present in the default error message from |
| 490 | `tvm.runtime.convert`. |
| 491 | """ |
| 492 | raise TypeError( |
| 493 | f"{self.tensor}.strides cannot be converted to a relax expression, " |
| 494 | f"and should be used as a proxy object to access the runtime strides of the DLTensor. " |
| 495 | f"The DLTensor::ndim field can be accessed as len({self.tensor}), " |
| 496 | f"and the DLTensor::strides array can be accessed as {self.tensor}.strides[i]" |
| 497 | ) |
| 498 | |
| 499 | def __getitem__(self, axis: int | PrimExpr | Expr) -> Expr: |
| 500 | """Returns the extent of a tensor axis |
| 501 | |
| 502 | Parameters |
| 503 | ---------- |
| 504 | axis: int | PrimExpr | Expr |
| 505 | |
| 506 | The tensor axis whose extent should be returned. For ease |
| 507 | of use, any python integers or TIR expressions are |
| 508 | converted to `relax.Expr`. |
| 509 | |
| 510 | Returns |
| 511 | ------- |
| 512 | extent: Expr |
| 513 | |
| 514 | The extent of the tensor's axis. |
| 515 | """ |
| 516 | |
| 517 | if not isinstance(axis, tvm.relax.Expr): |
| 518 | axis = tvm.relax.PrimValue(axis) |
| 519 | |
| 520 | if axis.struct_info_ is not None and not isinstance( |
no outgoing calls
no test coverage detected
searching dependent graphs…