kparzysz-quic commented on PR #15260:
URL: https://github.com/apache/tvm/pull/15260#issuecomment-1638815681

   I think I got it to work:
   ```python
   import tvm
   from tvm import relax
   from tvm.script import relax as R
   
   @R.macro
   def alloc_and_shape(dtype: str):
       alloc = R.builtin.alloc_tensor(R.shape([4, 4]), runtime_device_index=0, 
dtype=dtype)
       shape = R.shape_of(alloc)
       return shape
   
   @R.function
   def foo(x: R.Tensor((4, 4), "float32")):
       shape = alloc_and_shape(dtype="float32")
       return shape
   
   
   print(alloc_and_shape)
   print()
   print(foo)
   ```
   
   Produces
   ```python
   @R.macro
   def alloc_and_shape(dtype: str):
       alloc = R.builtin.alloc_tensor(R.shape([4, 4]), runtime_device_index=0, 
dtype=dtype)
       shape = R.shape_of(alloc)
       return shape
   
   
   # from tvm.script import relax as R
   
   @R.function
   def foo(x: R.Tensor((4, 4), dtype="float32")) -> R.Shape([4, 4]):
       alloc: R.Tensor((4, 4), dtype="float32") = 
R.builtin.alloc_tensor(R.shape([4, 4]), R.dtype("float32"), R.prim_value(0))
       shape: R.Shape([4, 4]) = R.shape_of(alloc)
       shape_1: R.Shape([4, 4]) = shape
       return shape_1
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to