Construct a Call to allocate a tensor with specific shape, dtype, runtime_device_index. Parameters ---------- shape : Expr The shape of the tensor to be allocated. dtype : Union[str, Expr] The datatype of the tensor to be allocated. runtime_device_index : Union
(
shape: Expr,
dtype: str | Expr,
runtime_device_index: int | Expr,
storage_scope: str | Expr = "global",
)
| 21 | |
| 22 | |
| 23 | def alloc_tensor( |
| 24 | shape: Expr, |
| 25 | dtype: str | Expr, |
| 26 | runtime_device_index: int | Expr, |
| 27 | storage_scope: str | Expr = "global", |
| 28 | ) -> Call: |
| 29 | """Construct a Call to allocate a tensor with specific shape, dtype, runtime_device_index. |
| 30 | |
| 31 | Parameters |
| 32 | ---------- |
| 33 | shape : Expr |
| 34 | The shape of the tensor to be allocated. |
| 35 | |
| 36 | dtype : Union[str, Expr] |
| 37 | The datatype of the tensor to be allocated. |
| 38 | |
| 39 | runtime_device_index : Union[int, Expr] |
| 40 | The device index indicating on which device the tensor is to be allocated at runtime. |
| 41 | Index -1 is reserved for the host device. |
| 42 | |
| 43 | storage_scope : Union[str, Expr] |
| 44 | The storage scope to allocate the storage to. |
| 45 | |
| 46 | Returns |
| 47 | ------- |
| 48 | result : Call |
| 49 | A relax Call, which gets the allocated tensor. |
| 50 | """ |
| 51 | if not isinstance(shape, Expr): |
| 52 | shape = convert_to_expr(shape) |
| 53 | if isinstance(dtype, str): |
| 54 | dtype = DataTypeImm(dtype) |
| 55 | if isinstance(runtime_device_index, int): |
| 56 | runtime_device_index = PrimValue(runtime_device_index) |
| 57 | if isinstance(storage_scope, str): |
| 58 | storage_scope = StringImm(storage_scope) |
| 59 | if not isinstance(storage_scope, StringImm): |
| 60 | raise ValueError( |
| 61 | "relax.builtin.alloc_tensor expects string as the storage scope, " |
| 62 | f"but {storage_scope} is got." |
| 63 | ) |
| 64 | |
| 65 | return _ffi_api.alloc_tensor(shape, dtype, runtime_device_index, storage_scope) # type: ignore |
| 66 | |
| 67 | |
| 68 | def stop_lift_params(x: Expr) -> Expr: |
nothing calls this directly
no test coverage detected
searching dependent graphs…