-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lang] Add TensorType support for Constant Folding (#8250)
Issue: # ### Brief Summary <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at b0140a9</samp> Improve and simplify the constant folding transform for arithmetic operations. Use helper functions to evaluate and replace constant expressions with matrices in `taichi/transforms/constant_fold.cpp`. ### Walkthrough <!-- copilot:walkthrough --> ### <samp>🤖 Generated by Copilot at b0140a9</samp> * Refactor `visit` functions for `BinaryOpStmt` and `UnaryOpStmt` to use separate functions `get_scalar_value_to_replace` that return optional `TypedConstant` based on operands and operation type ([link](https://github.com/taichi-dev/taichi/pull/8250/files?diff=unified&w=0#diff-82a8161a7771f3ee974357cda46f5684aead5225049e864e89767b078ad58b30L49-R52), [link](https://github.com/taichi-dev/taichi/pull/8250/files?diff=unified&w=0#diff-82a8161a7771f3ee974357cda46f5684aead5225049e864e89767b078ad58b30L233-R301)) * Handle constant folding for binary and unary operations on matrices by iterating over scalar values and creating new `MatrixInitStmt` with evaluated constants ([link](https://github.com/taichi-dev/taichi/pull/8250/files?diff=unified&w=0#diff-82a8161a7771f3ee974357cda46f5684aead5225049e864e89767b078ad58b30L152-R211), [link](https://github.com/taichi-dev/taichi/pull/8250/files?diff=unified&w=0#diff-82a8161a7771f3ee974357cda46f5684aead5225049e864e89767b078ad58b30L233-R301)) * Simplify `insert_and_erase` function calls by using local variables `res` and `dst_type` and moving them out of switch statements ([link](https://github.com/taichi-dev/taichi/pull/8250/files?diff=unified&w=0#diff-82a8161a7771f3ee974357cda46f5684aead5225049e864e89767b078ad58b30L60-R58), [link](https://github.com/taichi-dev/taichi/pull/8250/files?diff=unified&w=0#diff-82a8161a7771f3ee974357cda46f5684aead5225049e864e89767b078ad58b30L68-R90), [link](https://github.com/taichi-dev/taichi/pull/8250/files?diff=unified&w=0#diff-82a8161a7771f3ee974357cda46f5684aead5225049e864e89767b078ad58b30L118-R122), [link](https://github.com/taichi-dev/taichi/pull/8250/files?diff=unified&w=0#diff-82a8161a7771f3ee974357cda46f5684aead5225049e864e89767b078ad58b30L209-R242)) * Add new function `insert_and_erase` that takes a vector of `TypedConstant` and creates a vector of `ConstStmt` and a `MatrixInitStmt` to replace a statement with a constant matrix ([link](https://github.com/taichi-dev/taichi/pull/8250/files?diff=unified&w=0#diff-82a8161a7771f3ee974357cda46f5684aead5225049e864e89767b078ad58b30R327-R343))
- Loading branch information
1 parent
560b740
commit a992f22
Showing
1 changed file
with
157 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters