-
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
[Infra] Add "ti.profiler" (PythonProfiler) for intuitive Python-scope profiling #1493
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1493 +/- ##
==========================================
- Coverage 67.53% 66.51% -1.02%
==========================================
Files 40 41 +1
Lines 5630 5794 +164
Branches 982 1001 +19
==========================================
+ Hits 3802 3854 +52
- Misses 1660 1766 +106
- Partials 168 174 +6
Continue to review full report at Codecov.
|
docs/profiler.rst
Outdated
ti.profiler.print() | ||
|
||
|
||
2. ``ti.profiler()``, this one makes our code cleaner: |
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.
2. ``ti.profiler()``, this one makes our code cleaner: | |
2. Besides, ``ti.profiler()``can make our code cleaner: |
IMO
docs/profiler.rst
Outdated
10.10ms | 10.10ms | 10.10ms | 1x | 10.10ms | A | ||
|
||
|
||
3. ``@ti.profiler.timed``, this one is very intuitive when profiling kernels: |
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.
Do we need to explain this decorator more? It is still a little confused maybe.
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.
👍 Will do this once later this day.
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.
New version done! Please ff2 leave a review.
compute() | ||
ti.print_profile_info() | ||
Set ``warmup=5`` for example, will **discard** the first 5 record entries. | ||
I.e. discard the kernel compile time and possible TLB and cache misses on start up. |
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.e. discard the kernel compile time and possible TLB and cache misses on start up. | |
I.e. discard the kernel compile time and possible TLB(Translation Lookaside Buffer) and cache misses on start up. |
IMO
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.
Performance caring people should be OK with this term, and btw we use a space between brackets and chars:
I.e. discard the kernel compile time and possible TLB and cache misses on start up. | |
I.e. discard the kernel compile time and possible TLB (Translation Lookaside Buffer) and cache misses on start up. |
LGTMig + few nits |
Co-authored-by: Xudong Feng <xudongfeng1996@gmail.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! I think it would be very helpful to enable profiling in Python. However, maybe it makes more sense to simply do a pybind11 binding of the C++ ScopedProfiler
.
return len(self.rec) | ||
|
||
|
||
class PythonProfiler: |
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.
Maybe we should reuse the C++ ScopedProfiler
here? The code in this file is mostly a Python rewrite of that C++ class.
Also note that if a timed Python function calls any other timed C++ function, it would be nice to have a hierarchy containing both Python and C++ function calls.
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.
hierarchy
Oh? Is that? Not sure about how ScopedProfiler
works, I'll dig deeper once I've time.
My concern is that will invocation into pybind11 time cost make its result inaccurate?
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.
My another concern is: ScopedProfiler
is default on and will record profiling data in C++ side. Will this confuse users who only want to test a simple Python side kernel?
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.
My concern is that will invocation into pybind11 time cost make its result inaccurate?
That should be fine. If they really want accuracy directly using time.time()
would be a better choice.
My another concern is:
ScopedProfiler
is default on and will record profiling data in C++ side. Will this confuse users who only want to test a simple Python side kernel?
That's a good point. Maybe we can make ScopeProfiler
off by default and add an option to turn it on?
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.
Yes, like ti.init(cpp_scoped_profiler=True)
, but maybe iapr.
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 for the updates - I still suggest we reuse the C++ ScopedProfiler via Pybind11.
I see, but the existing base of
can make user confused if they only want to measure a little kernel, with no knowledge about these low-level details. |
Thanks - as I mentioned previously, we should introduce a flag to disable the C++ part of the existing profiler by default, in the following PR. |
Co-authored-by: Yuanming Hu <yuanming-hu@users.noreply.github.com>
Related issue = #
[Click here for the format server]
See
misc/mpm99_timed.py
for usage example.