-
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
[GUI] Use Taichi kernels instead of NumPy operations to reduce GUI.set_image overhead #1132
Conversation
Before:
After:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx. I have left a few questions, since I'm not very familiar with the GUI part. Also, could you briefly explain what the optimization is in the PR description?
python/taichi/lang/matrix.py
Outdated
@@ -497,11 +497,17 @@ def assign_renamed(x, y): | |||
from .meta import fill_matrix | |||
fill_matrix(self, val) | |||
|
|||
def shape_ext(self, as_vector=None): | |||
if as_vector is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why None
instead of making it a bool?
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it. Why not just
def shape_ext(self, as_vector=True):
shape_ext = (self.n, ) if as_vector else (self.n, self.m)
How is this off the topic?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.m is ignored even if self.m != 1?
I don't see why this is a problem when as_vector
is made a bool? For example, I can ask the question about what happens if as_vector
is not None
, but self.m != 1
? According to the current logic, it also returns (self.n, )
.
How about, when return as_vector
is passed in by users, then raise an exception if self.m != 1
(self.n, )
only when as_vector and self.m == 1
?
See
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Taichi kernels instead of NumPy operations to reduce GUI.set_image overhead
Sorry, this is still not clear to me. Wasn't the old code also using Taichi kernel to copy out the data, e.g. to_numpy()
? Is it because vector_to_image
is faster than matrix_to_ext_arr
? Or did we avoid some unnecessary copy somewhere?
python/taichi/lang/matrix.py
Outdated
@@ -497,11 +497,17 @@ def assign_renamed(x, y): | |||
from .meta import fill_matrix | |||
fill_matrix(self, val) | |||
|
|||
def shape_ext(self, as_vector=None): | |||
if as_vector is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it. Why not just
def shape_ext(self, as_vector=True):
shape_ext = (self.n, ) if as_vector else (self.n, self.m)
How is this off the topic?
It's a kernel fusion. Before: After: If you don't understand, just remember the result of these "mystery" works is: 21 fps -> 50 fps. |
So, if I call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a kernel fusion.
I see. That's kind of the things I was looking for. Can you put that in the PR description (it's empty) so that we know how this has been improved?
If you don't understand, just remember the result of these "mystery" works is: 21 fps -> 50 fps.
While I'm glad about the result, this is really not how code review works. If you list me as a reviewer, then I will need to care about how it works just as much as the outcome, so that I can give useful feedback.
python/taichi/lang/matrix.py
Outdated
@@ -497,11 +497,17 @@ def assign_renamed(x, y): | |||
from .meta import fill_matrix | |||
fill_matrix(self, val) | |||
|
|||
def shape_ext(self, as_vector=None): | |||
if as_vector is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.m is ignored even if self.m != 1?
I don't see why this is a problem when as_vector
is made a bool? For example, I can ask the question about what happens if as_vector
is not None
, but self.m != 1
? According to the current logic, it also returns (self.n, )
.
How about, when return as_vector
is passed in by users, then raise an exception if self.m != 1
(self.n, )
only when as_vector and self.m == 1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the as_vector
is a tiny detail. TBH given the current usage pattern, maybe we should just completely remove it and always return (self.n, )
when self.m == 1
? Otherwise LGTM, thx!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in general! Please fix a few minor issues.
If you don't understand, just remember the result of these "mystery" works is: 21 fps -> 50 fps.
Although I really like the performance boost, this sentence sounds really aggressive and unfriendly. Please always be polite. As a core developer, it's important for you to lead by example.
Co-authored-by: Yuanming Hu <yuanming-hu@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM.
The fact that we don't have unit tests for these APIs may lead to bad code quality/stability control here. We should consider adding tests for these functionalities.
Yes, you're right, it was till now I realized that |
Related issue = close #1124
[Click here for the format server]