>From merged pr https://github.com/apache/tvm/pull/17278/files . We can do code >generation for `LetStmt`. For example, if we disable let-inlining in the >Simplify Pass:
```python iter_var: T.int32() = T.ceildiv(K, block_K) for ko in T.serial(iter_var): ... ``` The generated CUDA code becomes: ```c int32_t iter_var = K / Block_K; for (int32_t k = 0; k < iter_var; k++){ ... } ``` This is powerful, but I'd like to discuss feasible solutions for cleanly defining local variables. For instance, when using single-element buffers in TVM: ```python a = T.alloc_buffer([1], dtype="int32", scope="local") a[0] += 1 a[0] -= 0 ``` We encounter inconveniences: 1. Numerous `[0]` indices clutter the code (non-essential and inelegant) 2. Generated code becomes verbose: ```c int32_t a[1]; a[0] = a[0] + 1; a[0] = a[0] - 1; ``` **Possible Solutions:** **Approach 1: Extend LetStmt** ```python a: T.int32() = 0 # Define a += 1 # Reassign (currently causes redefinition error) ``` Would generate cleaner C: ```c int32_t a = 0; a = a + 1; ``` *Concern:* This might violate `Let` semantics (immutable bindings). **Approach 2: Introduce Local Variables via Buffer Extension** This would require AST modifications to support first-class local variables instead of single-element buffers. Looking forward to community thoughts on these approaches or alternative solutions. --- [Visit Topic](https://discuss.tvm.apache.org/t/how-to-design-a-local-variable/18490/1) to respond. You are receiving this because you enabled mailing list mode. To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/7d282001f937071556497b5f3cf2604d7f3f98726526a7d1d1c709cabd51e80c).