A proxy object for unpacking DLDatatype from DLTensor Exposes accessors for `DLDataType` fields `type_code`, `lanes`, and `bits` within a `DLTensor::dtype`. Accessing these fields will produce `relax.Call` expressions, representing the field's runtime value. If the datatype of the
| 311 | |
| 312 | |
| 313 | class _DLTensorDTypeProxy(tvm.runtime.ObjectConvertible): |
| 314 | """A proxy object for unpacking DLDatatype from DLTensor |
| 315 | |
| 316 | Exposes accessors for `DLDataType` fields `type_code`, `lanes`, |
| 317 | and `bits` within a `DLTensor::dtype`. Accessing these fields |
| 318 | will produce `relax.Call` expressions, representing the field's |
| 319 | runtime value. If the datatype of the tensor is known at |
| 320 | compile-time, the `relax.Call` will be normalized into a |
| 321 | `relax.PrimValue`, with no runtime cost. |
| 322 | |
| 323 | Parameters |
| 324 | ---------- |
| 325 | tensor: relax.Expr |
| 326 | |
| 327 | The relax tensor (or a variable referring to a relax tensor), |
| 328 | whose runtime shape is being inspected. |
| 329 | |
| 330 | """ |
| 331 | |
| 332 | def __init__(self, tensor): |
| 333 | self.tensor = tensor |
| 334 | |
| 335 | def asobject(self): |
| 336 | """Provide expected in error message |
| 337 | |
| 338 | This method is called when `_DLTensorDTypeProxy` is used in a |
| 339 | context that requires a `relax.Expr`. This usage is not |
| 340 | supported, and raising an error here can provide suggested |
| 341 | fixes that are not present in the default error message from |
| 342 | `tvm.runtime.convert`. |
| 343 | """ |
| 344 | |
| 345 | fields = [f"{self.tensor}.dtype.{field}" for field in ["type_code", "bits", "lanes"]] |
| 346 | raise TypeError( |
| 347 | f"{self.tensor}.dtype cannot be converted to a relax expression, " |
| 348 | f"and should be used as a proxy object to access " |
| 349 | f"fields {fields}" |
| 350 | ) |
| 351 | |
| 352 | @property |
| 353 | def type_code(self) -> Expr: |
| 354 | """Accessor for the DLDataType::bits field |
| 355 | |
| 356 | Returns |
| 357 | ------- |
| 358 | type_code: Expr |
| 359 | |
| 360 | The type code of the DLTensor. See the `DLDeviceType` |
| 361 | enum in `dlpack.h` for more information. |
| 362 | """ |
| 363 | op = tvm.ir.Op.get("relax.inspect.tensor_dtype_code") |
| 364 | return tvm.relax.Call(op, [self.tensor]) |
| 365 | |
| 366 | @property |
| 367 | def lanes(self) -> Expr: |
| 368 | """Accessor for the DLDataType::bits field |
| 369 | |
| 370 | Returns |
no outgoing calls
no test coverage detected
searching dependent graphs…