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 the functions of dataclass as kernel argument and return value #7865

Merged
merged 1 commit into from
Apr 23, 2023

Conversation

lin-hitonami
Copy link
Contributor

@lin-hitonami lin-hitonami commented Apr 21, 2023

Issue: fixes #7822

🤖 Generated by Copilot at 4ae87d7

Summary

🧪🛠️🚀

This pull request enables data classes defined by ti.dataclass to have methods decorated by ti.func and ti.kernel. It also adds tests to check the functionality and correctness of this feature.

StructType creates the data class of doom
With __struct_methods to unleash its power
Call them from Python, or pass them to ti.kernel
ti.func returns them, the ultimate metal

Walkthrough

  • Add __struct_methods attribute to data class dictionaries to enable access of methods defined in ti.dataclass decorator (link, link)
  • Add test cases for using ti.func and ti.kernel as methods of data classes, both as kernel arguments and kernel returns, in test_struct.py (link)

@netlify
Copy link

netlify bot commented Apr 21, 2023

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit 4ae87d7
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/644249f721638f0009573399
😎 Deploy Preview https://deploy-preview-7865--docsite-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@ailzhang ailzhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@lin-hitonami lin-hitonami merged commit bb1ec45 into taichi-dev:master Apr 23, 2023
@lin-hitonami lin-hitonami deleted the struct_func branch April 23, 2023 06:40
lin-hitonami added a commit to lin-hitonami/taichi that referenced this pull request Apr 27, 2023
…rn value (taichi-dev#7865)

Issue: fixes taichi-dev#7822

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at 4ae87d7</samp>

### Summary
🧪🛠️🚀

<!--
1. 🧪 - This emoji represents testing, experimentation, or science, and
can be used to indicate the addition of test cases or the verification
of functionality.
2. 🛠️ - This emoji represents tools, construction, or repair, and can be
used to indicate the addition of a new feature or the improvement of an
existing one.
3. 🚀 - This emoji represents speed, launch, or innovation, and can be
used to indicate the enhancement of performance, the expansion of
capabilities, or the introduction of a novel idea.
-->
This pull request enables data classes defined by `ti.dataclass` to have
methods decorated by `ti.func` and `ti.kernel`. It also adds tests to
check the functionality and correctness of this feature.

> _`StructType` creates the data class of doom_
> _With `__struct_methods` to unleash its power_
> _Call them from Python, or pass them to `ti.kernel`_
> _`ti.func` returns them, the ultimate metal_

### Walkthrough
* Add `__struct_methods` attribute to data class dictionaries to enable
access of methods defined in `ti.dataclass` decorator
([link](https://github.com/taichi-dev/taichi/pull/7865/files?diff=unified&w=0#diff-3154e0533b9fd63e663c16c2e87c65068c3b002a65cf80529b6577d173bdb5feR633),
[link](https://github.com/taichi-dev/taichi/pull/7865/files?diff=unified&w=0#diff-3154e0533b9fd63e663c16c2e87c65068c3b002a65cf80529b6577d173bdb5feR654))
* Add test cases for using `ti.func` and `ti.kernel` as methods of data
classes, both as kernel arguments and kernel returns, in
`test_struct.py`
([link](https://github.com/taichi-dev/taichi/pull/7865/files?diff=unified&w=0#diff-e87bf5cb1cd09e10b5cfa001ab2ef18f31a242db3a7b66ee98a76d60b1615e71R79-R130))
feisuzhu pushed a commit to feisuzhu/taichi that referenced this pull request Apr 27, 2023
…rn value (taichi-dev#7865)

Issue: fixes taichi-dev#7822

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at 4ae87d7</samp>

### Summary
🧪🛠️🚀

<!--
1. 🧪 - This emoji represents testing, experimentation, or science, and
can be used to indicate the addition of test cases or the verification
of functionality.
2. 🛠️ - This emoji represents tools, construction, or repair, and can be
used to indicate the addition of a new feature or the improvement of an
existing one.
3. 🚀 - This emoji represents speed, launch, or innovation, and can be
used to indicate the enhancement of performance, the expansion of
capabilities, or the introduction of a novel idea.
-->
This pull request enables data classes defined by `ti.dataclass` to have
methods decorated by `ti.func` and `ti.kernel`. It also adds tests to
check the functionality and correctness of this feature.

> _`StructType` creates the data class of doom_
> _With `__struct_methods` to unleash its power_
> _Call them from Python, or pass them to `ti.kernel`_
> _`ti.func` returns them, the ultimate metal_

### Walkthrough
* Add `__struct_methods` attribute to data class dictionaries to enable
access of methods defined in `ti.dataclass` decorator
([link](https://github.com/taichi-dev/taichi/pull/7865/files?diff=unified&w=0#diff-3154e0533b9fd63e663c16c2e87c65068c3b002a65cf80529b6577d173bdb5feR633),
[link](https://github.com/taichi-dev/taichi/pull/7865/files?diff=unified&w=0#diff-3154e0533b9fd63e663c16c2e87c65068c3b002a65cf80529b6577d173bdb5feR654))
* Add test cases for using `ti.func` and `ti.kernel` as methods of data
classes, both as kernel arguments and kernel returns, in
`test_struct.py`
([link](https://github.com/taichi-dev/taichi/pull/7865/files?diff=unified&w=0#diff-e87bf5cb1cd09e10b5cfa001ab2ef18f31a242db3a7b66ee98a76d60b1615e71R79-R130))
quadpixels pushed a commit to quadpixels/taichi that referenced this pull request May 13, 2023
…rn value (taichi-dev#7865)

Issue: fixes taichi-dev#7822

<!--
copilot:all
-->
### <samp>🤖 Generated by Copilot at 4ae87d7</samp>

### Summary
🧪🛠️🚀

<!--
1. 🧪 - This emoji represents testing, experimentation, or science, and
can be used to indicate the addition of test cases or the verification
of functionality.
2. 🛠️ - This emoji represents tools, construction, or repair, and can be
used to indicate the addition of a new feature or the improvement of an
existing one.
3. 🚀 - This emoji represents speed, launch, or innovation, and can be
used to indicate the enhancement of performance, the expansion of
capabilities, or the introduction of a novel idea.
-->
This pull request enables data classes defined by `ti.dataclass` to have
methods decorated by `ti.func` and `ti.kernel`. It also adds tests to
check the functionality and correctness of this feature.

> _`StructType` creates the data class of doom_
> _With `__struct_methods` to unleash its power_
> _Call them from Python, or pass them to `ti.kernel`_
> _`ti.func` returns them, the ultimate metal_

### Walkthrough
* Add `__struct_methods` attribute to data class dictionaries to enable
access of methods defined in `ti.dataclass` decorator
([link](https://github.com/taichi-dev/taichi/pull/7865/files?diff=unified&w=0#diff-3154e0533b9fd63e663c16c2e87c65068c3b002a65cf80529b6577d173bdb5feR633),
[link](https://github.com/taichi-dev/taichi/pull/7865/files?diff=unified&w=0#diff-3154e0533b9fd63e663c16c2e87c65068c3b002a65cf80529b6577d173bdb5feR654))
* Add test cases for using `ti.func` and `ti.kernel` as methods of data
classes, both as kernel arguments and kernel returns, in
`test_struct.py`
([link](https://github.com/taichi-dev/taichi/pull/7865/files?diff=unified&w=0#diff-e87bf5cb1cd09e10b5cfa001ab2ef18f31a242db3a7b66ee98a76d60b1615e71R79-R130))
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.

Struct argument to kernel has no function attributes
2 participants