-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Struct argument to kernel has no function attributes #7822
Comments
Ah... this is something funny. Struct arguments are compiled into IR struct type which does not have encapsulation. We might need to support UFCS to make such things like member methods work in Taichi. @ailzhang @lin-hitonami |
Maybe we can implement this feature in the AST transformer. |
lin-hitonami
added a commit
that referenced
this issue
Apr 23, 2023
…rn value (#7865) Issue: fixes #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))
lin-hitonami
added a commit
to lin-hitonami/taichi
that referenced
this issue
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 issue
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 issue
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
A struct passed into a kernel as an argument doesn't have function attributes as a normal struct does, an example showing the difference below.
The text was updated successfully, but these errors were encountered: