Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lang] Support ndarray argument for real function #8188

Merged
merged 8 commits into from
Jun 19, 2023

Conversation

lin-hitonami
Copy link
Contributor

@lin-hitonami lin-hitonami commented Jun 15, 2023

🤖 Generated by Copilot at a936066

Summary

🧮🧪🎁

This pull request adds support for passing ti.ndarray as arguments to ti.func and ti.experimental.real_func, which allows users to write more flexible and generic functions that can operate on different types of arrays. It also updates and adds some tests to verify the correctness and error handling of this feature.

AnyArray is the key to unleash the power
Pass it to the func and real_func in the hour
Invoke the insert_ndarray_param to bind the data
Break the limits of the backends and the taichi

Walkthrough

  • Import AnyArray class to support unified indexing and arithmetic operations for ti.Matrix and ti.ndarray (link)
  • Modify Func.__call__ to return arg_features of arguments, which are tuples of element type, dimension, needs_grad, and boundary attributes (link)
  • Add branch to Func.func_call_rvalue to handle AnyArray arguments with ndarray_type.NdarrayType annotations, and append pointer to AnyArray data to non_template_args (link)
  • Modify Func.do_compile to take arg_features as input and pass them to _get_tree_and_ctx, which generates AST and context for function (link)
  • Add branch to TaichiCallableTemplateMapper.extract_arg to return arg_features for AnyArray arguments (link)
  • Add binding for Function.insert_ndarray_param to Python interface, which inserts pointer to AnyArray data to function parameters and sets flag (link)
  • Modify and add tests for passing ti.ndarray to ti.func and ti.experimental.real_func in test_ndarray.py (link)

Stack from ghstack (oldest at bottom):

lin-hitonami added a commit that referenced this pull request Jun 15, 2023
ghstack-source-id: 37c69d56ddbb41a09d00bb6361eadd17b2fdb118
Pull Request resolved: #8188
lin-hitonami added a commit that referenced this pull request Jun 15, 2023
ghstack-source-id: 78a359fac9fc628ed0bc578dec9d968b67dcb97b
Pull Request resolved: #8188
lin-hitonami added a commit that referenced this pull request Jun 15, 2023
ghstack-source-id: d4d28d83721112b58796a18d648eb32447485e7a
Pull Request resolved: #8188
lin-hitonami added a commit that referenced this pull request Jun 15, 2023
ghstack-source-id: d4d28d83721112b58796a18d648eb32447485e7a
Pull Request resolved: #8188
lin-hitonami added a commit that referenced this pull request Jun 15, 2023
ghstack-source-id: 346f82cd7e292567311a53974bfa1f66a3b23384
Pull Request resolved: #8188
lin-hitonami added a commit that referenced this pull request Jun 15, 2023
ghstack-source-id: 346f82cd7e292567311a53974bfa1f66a3b23384
Pull Request resolved: #8188
<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at a936066</samp>

### Summary
🧮🧪🎁

<!--
1.  🧮 for adding the binding for the `insert_ndarray_param` method.
2.  🧪 for modifying and adding the tests for the functionality.
3.  🎁 for enabling the feature of passing `ti.ndarray` as arguments.
-->
This pull request adds support for passing `ti.ndarray` as arguments to `ti.func` and `ti.experimental.real_func`, which allows users to write more flexible and generic functions that can operate on different types of arrays. It also updates and adds some tests to verify the correctness and error handling of this feature.

> _`AnyArray` is the key to unleash the power_
> _Pass it to the `func` and `real_func` in the hour_
> _Invoke the `insert_ndarray_param` to bind the data_
> _Break the limits of the backends and the taichi_

### Walkthrough
*  Import `AnyArray` class to support unified indexing and arithmetic operations for `ti.Matrix` and `ti.ndarray` ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1R15))
*  Modify `Func.__call__` to return `arg_features` of arguments, which are tuples of element type, dimension, needs_grad, and boundary attributes ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L229-R235))
*  Add branch to `Func.func_call_rvalue` to handle `AnyArray` arguments with `ndarray_type.NdarrayType` annotations, and append pointer to `AnyArray` data to `non_template_args` ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1R261-R266))
*  Modify `Func.do_compile` to take `arg_features` as input and pass them to `_get_tree_and_ctx`, which generates AST and context for function ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L277-R287))
*  Add branch to `TaichiCallableTemplateMapper.extract_arg` to return `arg_features` for `AnyArray` arguments ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1R415-R418))
*  Add binding for `Function.insert_ndarray_param` to Python interface, which inserts pointer to `AnyArray` data to function parameters and sets flag ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-af631a0c71978fe591e17005f01f7c06bc30ae36c65df306bbb3b08ade770167R720))
*  Modify and add tests for passing `ti.ndarray` to `ti.func` and `ti.experimental.real_func` in `test_ndarray.py` ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1008-R1051))






[ghstack-poisoned]
lin-hitonami added a commit that referenced this pull request Jun 16, 2023
ghstack-source-id: 84a312b25b980873395cbbc847144897c9c2e797
Pull Request resolved: #8188
<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at a936066</samp>

### Summary
🧮🧪🎁

<!--
1.  🧮 for adding the binding for the `insert_ndarray_param` method.
2.  🧪 for modifying and adding the tests for the functionality.
3.  🎁 for enabling the feature of passing `ti.ndarray` as arguments.
-->
This pull request adds support for passing `ti.ndarray` as arguments to `ti.func` and `ti.experimental.real_func`, which allows users to write more flexible and generic functions that can operate on different types of arrays. It also updates and adds some tests to verify the correctness and error handling of this feature.

> _`AnyArray` is the key to unleash the power_
> _Pass it to the `func` and `real_func` in the hour_
> _Invoke the `insert_ndarray_param` to bind the data_
> _Break the limits of the backends and the taichi_

### Walkthrough
*  Import `AnyArray` class to support unified indexing and arithmetic operations for `ti.Matrix` and `ti.ndarray` ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1R15))
*  Modify `Func.__call__` to return `arg_features` of arguments, which are tuples of element type, dimension, needs_grad, and boundary attributes ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L229-R235))
*  Add branch to `Func.func_call_rvalue` to handle `AnyArray` arguments with `ndarray_type.NdarrayType` annotations, and append pointer to `AnyArray` data to `non_template_args` ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1R261-R266))
*  Modify `Func.do_compile` to take `arg_features` as input and pass them to `_get_tree_and_ctx`, which generates AST and context for function ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1L277-R287))
*  Add branch to `TaichiCallableTemplateMapper.extract_arg` to return `arg_features` for `AnyArray` arguments ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-a157043b38542c8145447ff342fda65fe4d54fb777fe514daa70007e83e20dc1R415-R418))
*  Add binding for `Function.insert_ndarray_param` to Python interface, which inserts pointer to `AnyArray` data to function parameters and sets flag ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-af631a0c71978fe591e17005f01f7c06bc30ae36c65df306bbb3b08ade770167R720))
*  Modify and add tests for passing `ti.ndarray` to `ti.func` and `ti.experimental.real_func` in `test_ndarray.py` ([link](https://github.com/taichi-dev/taichi/pull/8188/files?diff=unified&w=0#diff-ca3c8d1edb25b6a7f4affbb79b2e3e74f73b3757e5d465258ce42ea9eb09fbc0L1008-R1051))






[ghstack-poisoned]
lin-hitonami added a commit that referenced this pull request Jun 16, 2023
ghstack-source-id: e8d7bbed74d451affa1ab3db3864e0dc51417edd
Pull Request resolved: #8188
@lin-hitonami
Copy link
Contributor Author

/land

@taichi-gardener taichi-gardener merged commit bcd32b1 into gh/lin-hitonami/8/base Jun 19, 2023
taichi-gardener pushed a commit that referenced this pull request Jun 19, 2023
ghstack-source-id: e8d7bbed74d451affa1ab3db3864e0dc51417edd
Pull Request resolved: #8188
@taichi-gardener taichi-gardener deleted the gh/lin-hitonami/8/head branch June 19, 2023 01:25
L2ncE pushed a commit to L2ncE/taichi that referenced this pull request Jun 20, 2023
ghstack-source-id: e8d7bbed74d451affa1ab3db3864e0dc51417edd
Pull Request resolved: taichi-dev#8188
PGZXB pushed a commit to PGZXB/taichi that referenced this pull request Jul 13, 2023
ghstack-source-id: e8d7bbed74d451affa1ab3db3864e0dc51417edd
Pull Request resolved: taichi-dev#8188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants