junrushao commented on issue #13559: URL: https://github.com/apache/tvm/issues/13559#issuecomment-1339843476
Thanks for bringing this up @lightzhan-intellif! @cyx-6 and I had a long discussion on this topic: do we allow `T.alloc_buffer` anywhere under a recursively nested structure, or only allow it to appear directly under a `T.block`. The supporting argument for the former one is that it could be potentially more convenient to write in some cases, particularly the one you provided, while that for the latter is that because `alloc_buffer` is part of the block signature, it's more accurate to restrict it immediately under the block - the debate itself could go either way and we do not have strong opinion. The real issue here though is that "python assignment" in TVMScript means let binding by default, which creates recursion in the AST. For example: ```python a = 1 b = 2 ... ``` in the AST is: ```python Let(a, 1, Let(b, 2, ...)) ``` In cases of mixing let bindings with `T.alloc_buffer`, it could cause some trouble if we don't handle really carefully, for example: ```python a = 1 B = T.alloc_buffer(shape=[a, a + 1]) ``` which becomes use-before-def when translated to the AST: ```python T.alloc_buffer(shape=[a, a + 1]) # `a` is used before definition Let(a, 1, ...) ``` In this particular case, I would say an enhanced error message could be helpful, for example, say we cannot put `T.alloc_buffer` under let, but please move it to somewhere immediately under `T.block`. I'm happy to chat more, and let me know if it makes sense. -- 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]
