gemini-code-assist[bot] commented on PR #18716: URL: https://github.com/apache/tvm/pull/18716#issuecomment-3856687918
## Summary of Changes Hello @tqchen, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request represents a significant refactoring effort to modernize the Intermediate Representation (IR) construction within TVM. By transitioning from the older `tir.ir_builder` to the more expressive and Pythonic `tvm.script` and `IRBuilder` APIs, the project aims to enhance code readability, maintainability, and developer experience. The changes standardize how TIR is generated, making it easier to write and understand complex computational kernels. ### Highlights * **Deprecation and Removal of Legacy IR Builder**: The `python/tvm/tir/ir_builder.py` module, which provided the old `tir.ir_builder.create()` API for constructing TIR, has been completely removed. Correspondingly, the import of `ir_builder` from `tvm.tir/__init__.py` has also been removed. * **Migration to TVMScript and IRBuilder API**: All instances of the legacy `tir.ir_builder` API have been migrated to use the modern `tvm.script` syntax or direct `IRBuilder` constructs. This includes replacing `ib.buffer_ptr`, `ib.for_range`, `ib.if_scope`, `ib.else_scope`, `ib.new_scope`, `ib.scope_attr`, and `ib.allocate` with `T.buffer_proxy`, `T.serial`/`T.parallel`, `T.If`/`T.Else`, `T.frame_scope`, `T.attr`, and `T.allocate` respectively. * **Introduction of IRBuilder Utilities**: A new file, `python/tvm/script/ir_builder/tir/utils.py`, has been added. This file introduces helper classes and functions such as `buffer_proxy`, `frame_scope`, and `seq_scope` to streamline the use of the new IRBuilder API, particularly for managing multiple frames and handling flat indexing on multi-dimensional buffers. * **Extensive Codebase Update**: This migration impacts a wide range of files across `tvm.relax`, `tvm.topi`, and numerous test cases, ensuring consistency and adherence to the new IR construction paradigm throughout the codebase. 🧠**New Feature in Public Preview:** You can now enable **Memory** to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.** <details> <summary><b>Changelog</b></summary> * **python/tvm/relax/transform/legalize_ops/grad.py** * Updated IR construction for `_grad_take_backward` to use `tvm.script.ir_builder` components like `IRBuilder`, `T.serial`, `T.If`, and `buffer_proxy`. * **python/tvm/script/ir_builder/tir/__init__.py** * Added imports for new utility functions: `buffer_proxy`, `frame_scope`, and `seq_scope`. * **python/tvm/script/ir_builder/tir/utils.py** * Added new file containing `_FrameScope`, `frame_scope`, `seq_scope`, `_unravel_index`, `_BufferProxy`, and `buffer_proxy` to aid IR building. * **python/tvm/tir/__init__.py** * Removed import of the deprecated `ir_builder` module. * **python/tvm/tir/ir_builder.py** * Removed the legacy `tir.ir_builder` module. * **python/tvm/topi/gpu/scan.py** * Refactored `exclusive_scan_ir` to use `tvm.script.ir_builder` for loop and conditional statements, and buffer handling. * **python/tvm/topi/gpu/sort.py** * Migrated `_get_threads`, `_sort_init`, and `_odd_even_sort` to use `tvm.script.ir_builder` constructs like `T.frame_scope`, `T.attr`, `T.serial`, `T.If`, `T.allocate`, and `T.buffer_proxy`. * **python/tvm/topi/index_put.py** * Updated `gen_ir` to use `tvm.script.ir_builder` for parallel loops and buffer proxying, combining statements with `tir.SeqStmt`. * **python/tvm/topi/scan.py** * Removed `ir_builder` import and refactored `gen_ir` to use `tvm.script.ir_builder` for parallel and serial loops. * **python/tvm/topi/scatter.py** * Migrated `gen_ir` to use `tvm.script.ir_builder` for buffer handling, loops, and conditional logic, using `tir.SeqStmt` for statement sequencing. * **python/tvm/topi/scatter_elements.py** * Updated `gen_ir` to use `tvm.script.ir_builder` for parallel loops and buffer proxying, combining statements with `tir.SeqStmt`. * **python/tvm/topi/searchsorted.py** * Removed `ir_builder` import and refactored `binary_search` and `ir` functions to use `tvm.script.ir_builder` for allocations, while loops, and conditionals. * **python/tvm/topi/signal.py** * Migrated `gen_ir` functions for STFT and FFT to use `tvm.script.ir_builder` for loops and conditionals. * **python/tvm/topi/sparse_reshape.py** * Removed `ir_builder` import and updated `gen_ir` to use `tvm.script.ir_builder` for buffer handling, loops, and conditional logic, including `T.frame_scope` for local allocations. * **python/tvm/topi/unique.py** * Refactored `_calc_adjacent_diff_ir` to use `tvm.script.ir_builder` for parallel loops and conditional statements. * **python/tvm/topi/vision/nms.py** * Migrated `_nms_loop`, `searchsorted_ir`, and `_collect_selected_indices_ir` to use `tvm.script.ir_builder` for loops, conditionals, and local buffer management. * **python/tvm/topi/vision/nms_util.py** * Updated `binary_search` and `_all_class_nms_ir` to use `tvm.script.ir_builder` for local allocations, while loops, and conditionals. * **tests/python/codegen/test_target_codegen_extern.py** * Converted test cases to define IR using `tvm.script` decorators (`@I.ir_module`, `@T.prim_func`) instead of `te.extern` and `tir.ir_builder`. * **tests/python/codegen/test_target_codegen_llvm.py** * Converted test cases to define IR using `tvm.script` decorators (`@T.prim_func`, `T.launch_thread`) instead of `tir.ir_builder`. * **tests/python/codegen/test_target_codegen_static_init.py** * Converted test cases to define IR using `tvm.script` decorators (`@I.ir_module`, `@T.prim_func`, `T.launch_thread`) instead of `tir.ir_builder`. * **tests/python/codegen/test_target_codegen_vulkan.py** * Converted test cases to define IR using `tvm.script` decorators (`@T.prim_func`, `T.launch_thread`) instead of `tir.ir_builder`. * **tests/python/runtime/test_runtime_extension.py** * Converted test cases to define IR using `tvm.script` decorators (`@I.ir_module`, `@T.prim_func`) instead of `tir.ir_builder`. * **tests/python/tir-base/test_tir_base.py** * Converted test cases to define IR using `tvm.script` decorators (`@T.prim_func`) instead of `tir.ir_builder`. * **tests/python/tir-base/test_tir_stmt_functor_ir_transform.py** * Converted test cases to define IR using `tvm.script` decorators (`@I.ir_module`, `@T.prim_func`) instead of `tir.ir_builder`. * **tests/python/tir-base/test_tir_structural_equal_hash.py** * Converted test cases to define IR using `tvm.script` decorators (`@T.prim_func`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_hoist_if.py** * Converted test cases to define IR using `tvm.script` decorators (`@T.prim_func`, `T.launch_thread`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_inject_double_buffer.py** * Converted test cases to define IR using `tvm.script` decorators (`@I.ir_module`, `@T.prim_func`, `T.launch_thread`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_inject_virtual_thread.py** * Converted test cases to define IR using `tvm.script` decorators (`@I.ir_module`, `@T.prim_func`, `T.launch_thread`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_loop_partition.py** * Converted test cases to define IR using `tvm.script` decorators (`@T.prim_func`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_lower_tvm_builtin.py** * Converted test cases to use direct TIR construction for IR definition instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_make_unpacked_api.py** * Converted test cases to use direct TIR construction for IR definition instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_narrow_datatype.py** * Converted test cases to define IR using `tvm.script` decorators (`@T.prim_func`, `T.launch_thread`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_rewrite_unsafe_select.py** * Converted test cases to define IR using `tvm.script` decorators (`@I.ir_module`, `@T.prim_func`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_simplify.py** * Converted test cases to define IR using `tvm.script` decorators (`@T.prim_func`, `T.launch_thread`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_storage_rewrite.py** * Converted test cases to define IR using `tvm.script` decorators (`@T.prim_func`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_unroll_loop.py** * Converted test cases to define IR using `tvm.script` decorators (`@I.ir_module`, `@T.prim_func`) instead of `tir.ir_builder`. * **tests/python/tir-transform/test_tir_transform_vectorize.py** * Converted test cases to define IR using `tvm.script` decorators (`@I.ir_module`, `@T.prim_func`) instead of `tir.ir_builder`. </details> <details> <summary><b>Activity</b></summary> * The pull request author, tqchen, initiated a comprehensive migration from the legacy `tir.ir_builder` API to the modern `tvm.script` and `IRBuilder` APIs. * A new utility file, `python/tvm/script/ir_builder/tir/utils.py`, was introduced to provide helper functions for managing IRBuilder frames and buffer indexing, simplifying the migration process. * The old `python/tvm/tir/ir_builder.py` module was removed, marking a complete transition away from the deprecated API. * Numerous files across `tvm.relax`, `tvm.topi`, and the test suite were updated to adopt the new IR construction syntax, demonstrating a broad impact and thoroughness of the migration. </details> <details> <summary><b>Using Gemini Code Assist</b></summary> <br> The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips. <b>Invoking Gemini</b> You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page. Feature | Command | Description --- | --- | --- Code Review | `/gemini review` | Performs a code review for the current pull request in its current state. Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state. Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. Help | `/gemini help` | Displays a list of available commands. <b>Customization</b> To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). <b>Limitations & Feedback</b> Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG). <b>You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the [Gemini Code Assist IDE Extension](https://cloud.google.com/products/gemini/code-assist).</b> </details> [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487). -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
