Skip to content

[Profiler][PrivateUse1] Profiler support PrivateUse1 key - #120556

Closed
fwenguang wants to merge 26 commits into
pytorch:mainfrom
fwenguang:support_privateuse1_kineto
Closed

fwenguang wants to merge 26 commits into
pytorch:mainfrom
fwenguang:support_privateuse1_kineto

Conversation

@fwenguang

Copy link
Copy Markdown
Contributor

Summary:
1.Package public headers of kineto if USE_KINETO so that they can be used by PrivateUse1 user.
2.Add PrivateUse1 key to ActivityType.
3. Support PrivateUse1 key in function deviceTypeFromActivity and _supported_activities.
4. Fix some bugs when processing profiler results.

@pytorch-bot

pytorch-bot Bot commented Feb 24, 2024 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/120556

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 191c094 with merge base 34bce27 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@fwenguang

Copy link
Copy Markdown
Contributor Author

Depend on pytorch/kineto#874

@fwenguang
fwenguang marked this pull request as ready for review February 26, 2024 02:07

@albanD albanD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit to avoid the extra exception.

Comment thread torch/autograd/profiler.py Resolved
@janeyx99 janeyx99 added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Feb 28, 2024
@fwenguang
fwenguang requested a review from albanD February 29, 2024 02:27
@aaronenyeshi

Copy link
Copy Markdown
Member

Adding @xunsongh, to help with cross-review, since privateuse1 and xpu are going through similar code.

@aaronenyeshi aaronenyeshi added release notes: profiler release notes category topic: not user facing topic category labels Feb 29, 2024
@xunsongh

Copy link
Copy Markdown
Contributor

Thank you for bringing this to my attention. Based on my review, it appears that the modifications in this PR do not affect the XPU pathway, so I have no objections. Thank you.

@aaronenyeshi aaronenyeshi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please take a look at failing CI

@fwenguang

Copy link
Copy Markdown
Contributor Author

Please take a look at failing CI

This patch needs libkineto::ActivityType::PRIVATEUSE1_RUNTIME. The pr pytorch/kineto#874 in kineto should be merged first.

@fwenguang

Copy link
Copy Markdown
Contributor Author

Hi @aaronenyeshi , thank you for accepting the dependented kineto pr pytorch/kineto#874. I just updated commit id of kineto, please also help to review this.

@aaronenyeshi aaronenyeshi added the ciflow/trunk Trigger trunk jobs on your pull request label Mar 28, 2024
Comment thread torch/autograd/profiler_util.py Outdated
def export_stacks(self, path: str, metric: str):
# Support passing more meaningful names for privateuse1 users
metric = (
metric.replace(self._use_device, "privateuse1")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should _use_device be more generic, since we may have other devices in the future?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Without this replacing, metric only can be set to "self_privateuse1_time_total" for privateuse1 backend. but our user may pass a more meaningful name.
For example, our privateuse1 backend named "MLU", so self._use_device will be set to "mlu".
We prefer to set metric to "self_mlu_time_total", there will raise an error if no replacing.
Of course, we can also use "self_privateuse1_time_total" , in which case replacing will do nothing.

For other devices, their self.user_device may be some ohter strings, they can use the original string "self_privateuse1_time_total" as metric and also can use self{self._use_device}_time_total. The logical is generic.

So, i believe self._use_device should be specific, like the current design, allowing it to represent different device names. Additionally, we can use self._use_device to extend some more generic strings like self_privateuse1_time_total to specific.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi, @aaronenyeshi @briancoutinho , could you please give some suggestions about this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, i will revert this.

                    metric_value = getattr(
                        evt,
                        metric.replace("cuda", "device")
                        .replace("xpu", "device")
                        .replace("privateuse1", "device"),
                    )

By the way, i noticed the above code in https://github.com/pytorch/pytorch/pull/123247/files, Actually, this modification doesn't solve the issue I wanted to address. What I'm looking to do is something like appending a new line .replace(self._use_device, "device"). However, this isn't a critical issue, just something for convenience. For now, I'll remove my modification.

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@fwenguang your PR has been successfully reverted.

@pytorch-bot
pytorch-bot Bot dismissed aaronenyeshi’s stale review April 17, 2024 15:38

This PR was reopened (likely due to being reverted), so your approval was removed. Please request another review.

@fwenguang

Copy link
Copy Markdown
Contributor Author

@fwenguang , sorry about this. This diff is causing a regression to the chrome trace UI of GPU traces for PyTorch Profiler users (GPU processes are no longer named or sorted after CPU processes). We will revert this, please take a look and re-open a new PR.

Before: image After: image

Hi, @aaronenyeshi , I previously added libkineto::ActivityType::PRIVATEUSE1_RUNTIME into kCpuTypes, which was right, but it's no longer possible to detemine if it's PrivateUse1 backend through libkineto::hasPrivateUse1Type , i have removed hasPrivateUse1Type, see PR:pytorch/kineto#909, once it is merged and updated, this PR can be merged without any modifications.

facebook-github-bot pushed a commit to pytorch/kineto that referenced this pull request Apr 18, 2024
Summary:
Fix issue in pytorch/pytorch#120556 (comment).

Pull Request resolved: #909

Reviewed By: xuzhao9

Differential Revision: D56303311

Pulled By: aaronenyeshi

fbshipit-source-id: 07061f6ac4d333b796d1c003d72444edcc4be717
sanketpurandare pushed a commit to sanketpurandare/pytorch that referenced this pull request Apr 22, 2024
)

Summary:
1.Package public headers of kineto if USE_KINETO so that they can be used by PrivateUse1 user.
2.Add PrivateUse1 key to ActivityType.
3. Support PrivateUse1 key in function deviceTypeFromActivity and _supported_activities.
4. Fix some bugs when processing profiler results.
Co-authored-by: albanD <[email protected]>
Co-authored-by: Aaron Shi <[email protected]>
Pull Request resolved: pytorch#120556
Approved by: https://github.com/aaronenyeshi
sanketpurandare pushed a commit to sanketpurandare/pytorch that referenced this pull request Apr 22, 2024
@fwenguang

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Rebase failed due to Command git -C /home/runner/work/pytorch/pytorch rebase refs/remotes/origin/viable/strict pull/120556/head returned non-zero exit code 1

Rebasing (1/19)
Auto-merging setup.py
Auto-merging torch/autograd/profiler.py
Auto-merging torch/autograd/profiler_util.py
CONFLICT (content): Merge conflict in torch/autograd/profiler_util.py
Auto-merging torch/csrc/autograd/init.cpp
Auto-merging torch/csrc/autograd/profiler_kineto.cpp
Auto-merging torch/csrc/profiler/kineto_shim.cpp
CONFLICT (content): Merge conflict in torch/csrc/profiler/kineto_shim.cpp
Auto-merging torch/csrc/profiler/python/init.cpp
Auto-merging torch/profiler/profiler.py
CONFLICT (content): Merge conflict in torch/profiler/profiler.py
error: could not apply 94599b30d04... [Profiler][PrivateUse1] Profiler support PrivateUse1 key
hint: Resolve all conflicts manually, mark them as resolved with
hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
hint: You can instead skip this commit: run "git rebase --skip".
hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 94599b30d04... [Profiler][PrivateUse1] Profiler support PrivateUse1 key

Raised by https://github.com/pytorch/pytorch/actions/runs/8811279727

@aaronenyeshi

Copy link
Copy Markdown
Member

Moving to new PR

petrex pushed a commit to petrex/pytorch that referenced this pull request May 3, 2024
)

Summary:
1.Package public headers of kineto if USE_KINETO so that they can be used by PrivateUse1 user.
2.Add PrivateUse1 key to ActivityType.
3. Support PrivateUse1 key in function deviceTypeFromActivity and _supported_activities.
4. Fix some bugs when processing profiler results.
Co-authored-by: albanD <[email protected]>
Co-authored-by: Aaron Shi <[email protected]>
Pull Request resolved: pytorch#120556
Approved by: https://github.com/aaronenyeshi
mcalman added a commit to IBM/kineto-spyre that referenced this pull request Mar 17, 2026
* Fix stream ID for cuda sync events at GPU scope (#884)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/884

Stream ID was being casted to large 2^32 -1 but it should be -1

Reviewed By: aaronenyeshi, amoghavs

Differential Revision: D54445884

fbshipit-source-id: e39241d3068081e27d7117c0180f4af96469ea7a

* Populate PG metadata from CPU op to GPU kernel (#880)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/880

Populate 'Process Group ID' and 'Process Group Ranks' captured at CPU op to GPU kernel

Reviewed By: aaronenyeshi

Differential Revision: D54092504

fbshipit-source-id: 911bc244410036596d2268e54707b4b7b6dd9921

* Fix misaligned order of baseline-Ops and exp-Ops in DIFF view (#883)

Summary:
fix https://github.com/pytorch/kineto/issues/881
1. Update the version of Nodejs in `fe/README.md` since Node.js 16x is too old and not in maintenance.
2. Update some dependencies in `fe/package.json` and `fe/yarn.lock` to make building successful.
3. When generating data source from underlying data in `DiffOverview.tsx`, modify the alignment order of baseline and exp using op's name instead of index.
4. Replace `index.html` in `torch_tb_profiler/static` with newly generated to update tensorboard UI.

Pull Request resolved: https://github.com/pytorch/kineto/pull/883

Reviewed By: chaekit

Differential Revision: D54690653

Pulled By: aaronenyeshi

fbshipit-source-id: 9b2468f2d19eed29adaa4df68cd68f7976f511f3

* Make Kineto traces export ns granularity for finer timestamps

Summary: Kineto traces use microsecond level granularity because of chrome tracing defaults to that precision. Fix by removing ns to us conversions and adding field to json to specify ns timeUnit for chrome tracing. This diff contains libkineto only. Will have a follow up diff with compile flags and pytorch implementation

Reviewed By: aaronenyeshi, davidberard98

Differential Revision: D54964435

fbshipit-source-id: 4559df242ace46cee218cb06ab3b4c8134663d5a

* Remove extra semi colon from katran/lib/tests/IpHelpersTest.cpp

Summary:
`-Wextra-semi` or `-Wextra-semi-stmt`

If the code compiles, this is safe to land.

Reviewed By: palmje

Differential Revision: D55087325

fbshipit-source-id: 6940beb82a423a30a69af35b1cbf4ce585c26553

* Fix fwd_bwd_events in tb_plugin to keep consistent with libkineto (#891)

Summary:
Fix https://github.com/pytorch/kineto/issues/863
 Fix fwd_bwd_events in `tb_plugin` to keep consistent with `libkineto`, so as to create forward-backward association and build op_tree completely.

Pull Request resolved: https://github.com/pytorch/kineto/pull/891

Reviewed By: aaronenyeshi

Differential Revision: D55229438

Pulled By: davidberard98

fbshipit-source-id: 5d792daddcdde80c994ccc47e950f83db6eb5b83

* Support PrivateUse1 key (#874)

Summary:
1. Add some ActivityTypes for PrivateUse1.
2. Add interface pushCorrelationId and similar interfaces to IActivityProfilerSession.
3. Move output_base.h to include dir so that PrivateUse1 user can call member functions of ActivityLogger.

Pull Request resolved: https://github.com/pytorch/kineto/pull/874

Reviewed By: chaekit

Differential Revision: D54361402

Pulled By: aaronenyeshi

fbshipit-source-id: 3ba6fd389b6055957d4175aa0fe42883e96e9e73

* Refactor Roctracer activities to match Cupti Activities to re-use existing logger logic (#892)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/892

This diff refactors the Roctracer activities to match Cupti activities, and performs the following changes:
- Switch roctracer activities from GenericTraceActivity to derived structs of ITraceActivity
- Re-use existing logic for mapping linked activities, populating resourceInfo, checking timestamp ordering and out of range.
- Use templates to handle a variety of roctracer rows, most of templates belong to runtime events, which have varying metadata.
- Clean up RoctracerActivityApi and consolidate all roctracer rows into a single buffer with row struct encapsulation.
- Finally clean up unused functions, variables, duplicate definitions, etc.

FIXME: need to propagate runtime metadata into GPU event metadata.

Test Plan: CI and internal workloads.

Reviewed By: davidberard98

Differential Revision: D55084808

Pulled By: aaronenyeshi

fbshipit-source-id: 735136131cb636e510145e6673c96c7fe9af3942

* Roctracer: Fix contention for high QPS cases and add upper limit for buffer size (#893)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/893

This diff fixes the crashing issue when number of samples is high.
- Adds a mutex for activity_callback and and api_callback when adding rows into buffer
- Adds a thread_local mutex and unordered_map in api_callback due to jemalloc SIGABRT, seems like contention on timestamp.
- Use a shared insert_row_to_buffer() function to lock when storing the row to buffer.

FIXME: We don't currently delete the rows in the buffer, since we need to keep them around until the chrome trace is created. We should fixed this by transferring ownership to CuptiActivityProfiler via Activity Buffer similar to Cupti Activity.

Test Plan: CI and internal workloads.

Reviewed By: houseroad, davidberard98

Differential Revision: D55341766

Pulled By: aaronenyeshi

fbshipit-source-id: 7f99fb00e16e9cfda55267b5a0391f53a0b72256

* Fix output_json decimal outputs to be 3 digit zero padded (#896)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/896

Currently the output for kineto in the nanosecond granularity is incorrect because the decimals are not zero padded. Add formatter in string to make sure values are zero padded in all decimals.

Reviewed By: aaronenyeshi

Differential Revision: D55668543

fbshipit-source-id: cb628151ca811adb185f596e65ece75e68c4f10a

* Fix missing #include <mutex> in RoctracerLogger.h (#898)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/898

For ROCM builds in PyTorch, we need to include header <mutex> which defines the std::mutex used in RoctracerLogger.h.

Test Plan:
CI

This was the previous build error in [PyTorch CI for ciflow/rocm](https://hud.pytorch.org/failure?name=inductor%20%2F%20rocm6.0-py3.8-inductor%20%2F%20build&jobName=undefined&failureCaptures=%5B%22%2Fvar%2Flib%2Fjenkins%2Fworkspace%2Fthird_party%2Fkineto%2Flibkineto%2Fsrc%2FRoctracerLogger.h%3A223%3A8%3A%20error%3A%20%E2%80%98mutex%E2%80%99%20in%20namespace%20%E2%80%98std%E2%80%99%20does%20not%20name%20a%20type%22%5D):
```
2024-04-06T06:23:51.4288896Z In file included from /var/lib/jenkins/workspace/third_party/kineto/libkineto/src/RoctracerActivityApi.h:19,
2024-04-06T06:23:51.4291167Z                  from /var/lib/jenkins/workspace/third_party/kineto/libkineto/src/RoctracerActivityApi.cpp:9:
2024-04-06T06:23:51.4295136Z /var/lib/jenkins/workspace/third_party/kineto/libkineto/src/RoctracerLogger.h:223:8: error: ‘mutex’ in namespace ‘std’ does not name a type
2024-04-06T06:23:51.4297026Z   223 |   std::mutex rowsMutex_;
2024-04-06T06:23:51.4297677Z       |        ^~~~~
2024-04-06T06:23:51.4300019Z /var/lib/jenkins/workspace/third_party/kineto/libkineto/src/RoctracerLogger.h:25:1: note: ‘std::mutex’ is defined in header ‘<mutex>’; did you forget to ‘#include <mutex>’?
2024-04-06T06:23:51.4302589Z    24 | #include <roctracer_roctx.h>
2024-04-06T06:23:51.4303565Z   +++ |+#include <mutex>
2024-04-06T06:23:51.4304163Z    25 |
```

Reviewed By: davidberard98

Differential Revision: D55876676

Pulled By: aaronenyeshi

fbshipit-source-id: 5b77ceecf2a607e571c2d3aac8c8fdf1643a42fa

* Fix a typo in torch_tb_profiler (#899)

Summary:
A typo fix in torch_tb_profiler

Pull Request resolved: https://github.com/pytorch/kineto/pull/899

Reviewed By: xuzhao9

Differential Revision: D55894107

Pulled By: aaronenyeshi

fbshipit-source-id: 877e33512c24cc14ed3069d40aff00f62288c416

* Initialize BackwardNode with start_time, end_time and tid in torch_tb_profiler (#900)

Summary:
Currently when building backward modules in torch_tb_profiler, we initialize `start_time` and `end_time` to `None`, and `tid` to `0` and try to fill these three fields in a bottom–up manner. However, during this process if at least one of the leaf nodes is a `BackwardNode` and the initial values of `start_time` and `end_time` are `None`, we will encounter errors in `self.children.sort(key=lambda x: (x.start_time, -x.end_time))` when calling `fill_stats`. The parent's `tid` can also be set to 0. To fix this bug, this PR assigns a `BackwardNode` with initial values of `start_time`, `end_time`, `tid`. These values can be updated later when traversing the tree backwards.

Pull Request resolved: https://github.com/pytorch/kineto/pull/900

Reviewed By: xuzhao9

Differential Revision: D55923121

Pulled By: aaronenyeshi

fbshipit-source-id: 855a4c4fa5ea31338681925355ceb11fd32ca45a

* Fix output_json.cpp build error on PyTorch Windows CI (#901)

Summary: Pull Request resolved: https://github.com/pytorch/kineto/pull/901

Reviewed By: sraikund16

Differential Revision: D55928437

Pulled By: aaronenyeshi

fbshipit-source-id: 61b6b5ec0995bf782bee7681199ad4e82b4f1bfb

* Add OSS flag for Kineto Nanosecond granularity (#903)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/903

Currently in OSS Kineto does not have the Nanosecond flag. This will cause values from the profiler to be outputted incorrectly.

Reviewed By: briancoutinho

Differential Revision: D56041422

fbshipit-source-id: 7bbe413021f9d7eaa98c99e8c75bfe9b505ca207

* Fix roctracer crash when number of samples too high (#902)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/902

There is a map access at the bottom of the `api_callback()` function that is storing the correlation id and external correlation id relation. This map is shared between threads, and is causing a SIGSEGV crash during RBTree insert_and_rebalance.

To fix this, we add a mutex for the map. This is likely why the previous thread_local mutex was fixing crashes, due to delayed timing, so we can remove the thread_local mutex now.

Resolves: https://github.com/pytorch/kineto/issues/894

Test Plan: CI and ran on internal high QPS job

Reviewed By: 842974287

Differential Revision: D56017970

Pulled By: aaronenyeshi

fbshipit-source-id: 68dc289740e2998a5b8a17fd0ee54c4a8468098d

* Support roctracer external correlations (#905)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/905

Since the recent refactor of roctracer logic, the external correlations are not properly set up.

This diff intends to:
1) Collect the correlationId and externalId pairs in an array of vector of pairs. Switched from a map to a vector, which will populate cpuCorrelationMap_ and userCorrelationMap_ in CuptiActivityProfiler.cpp.
2) Added handleCorrelationActivity function passed into roctracer's processActivities. The function handle will be used to populate the maps in CuptiActivityProfiler. This aligns closely with Cupti implementation.
3) Process correlation/external ids first, so that linked TraceActivities will populate roctracer events.

Reviewed By: 842974287

Differential Revision: D56025484

fbshipit-source-id: 48024a6a53a5cfb494d830b91bb9545e051e6ddb

* update process group ID to process group name (#906)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/906

deprecate process group id field with process group name
now ncclkernel displays ProcessGroupName, desc and collectiveName

Reviewed By: aaronenyeshi

Differential Revision: D55612967

fbshipit-source-id: a082629b62e9cc2e67783e0f82af2288930ea45c

* Remove all instances of TMP_LIBKINETO_NANOSECOND from Kineto (#907)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/907

Now that we have ns granularity working in main we can remove the temporary guards that were needed to make sure that Kineto was in sync with pytorch. Remove all the guards and follow up with a diff where we remove the compiler flags

Reviewed By: aaronenyeshi

Differential Revision: D56147637

fbshipit-source-id: d44fbb1240ac28adc929e302c43020bc9ba0721e

* remove hasPrivateUse1Type function (#909)

Summary:
Fix issue in https://github.com/pytorch/pytorch/pull/120556#issuecomment-2061557740.

Pull Request resolved: https://github.com/pytorch/kineto/pull/909

Reviewed By: xuzhao9

Differential Revision: D56303311

Pulled By: aaronenyeshi

fbshipit-source-id: 07061f6ac4d333b796d1c003d72444edcc4be717

* Update CuptiActivityProfilerTest to use nanosecond timestamps (#911)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/911

Since we've moved to use nanoseconds across all activity events collected, we should also move our tests, including MockCuptiActivityBuffer to use nanosecond timestamps and durations.

Also, this change is required before we move to relative time (D56303459).

Test Plan:
Tested locally on this test:
```
$ buck test mode/opt kineto/libkineto:cupti_activity_profiler_test
Watchman fresh instance: cleared graph state
Buck UI: https://www.internalfb.com/buck2/af5a53d6-8c1a-468c-81be-2986ea1be565
Test UI: https://www.internalfb.com/intern/testinfra/testrun/14073748865774907
Network: Up: 10KiB  Down: 151KiB  (reSessionID-6d61217f-3cfe-4ccc-bdad-1290a2d6063e)
Jobs completed: 3147. Time elapsed: 22.9s.
Cache hits: 33%. Commands: 3 (cached: 1, remote: 0, local: 2)
Tests finished: Pass 8. Fail 0. Fatal 0. Skip 0. Build failure 0
```

Reviewed By: sraikund16

Differential Revision: D56319364

Pulled By: aaronenyeshi

fbshipit-source-id: 3ee266a4cac0271efafe918776f44de0e4c91f3d

* Fix GPU User Annotations overlapping with associated GPU ops (#914)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/914

Since we transitioned the profiler events to store ns timestamps, there are overlapping gpu_user_annotation and gpu kernel events. The overlap was previously fixed by making the gpu_user_annotations start slightly earlier than associated kernels, but it seems that 1ns is not enough for Chrome Trace Viewer. Switch it to 1000ns, which was 1us equivalent to before.

Test Plan:
CI and ran locally on 2 GPU resnet50:

## Before:
Overlapping GPU annotations and GPU kernels:
 {F1492907000}
 {F1492907208}
https://www.internalfb.com/intern/perfdoctor/trace_view?filepath=tree/traces/dynocli/devvm2184.cco0.facebook.com/rank-0.Apr_21_13_04_03.1336384.pt.trace.json.gz&bucket=gpu_traces
## After:
No longer overlapping GPU annotations and GPU kernels:
 {F1492907294}
 {F1492907479}
 {F1492907609}
https://www.internalfb.com/intern/perfdoctor/trace_view?filepath=tree/traces/dynocli/devvm2184.cco0.facebook.com/rank-0.Apr_21_13_18_51.1429295.pt.trace.json.gz&bucket=gpu_traces

Reviewed By: briancoutinho

Differential Revision: D56401601

Pulled By: aaronenyeshi

fbshipit-source-id: 662a451d983ed87392642542461247fba3cd5ee6

* use relative time to ensure the 'ts' field can be accurately read (#910)

Summary:
Fix https://github.com/pytorch/kineto/pull/890#discussion_r1530009921.

Pull Request resolved: https://github.com/pytorch/kineto/pull/910

Reviewed By: xuzhao9

Differential Revision: D56303459

Pulled By: aaronenyeshi

fbshipit-source-id: 2af54346eb4f4b438d2133725459cb003a1a2edc

* Remove TMP_LIBKINETO_NANOSECOND Note (#916)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/916

In Kineto we removed all instances of TMP_LIBKINETO_NANOSECOND but we did not remove the note stating why it was in

Reviewed By: aaronenyeshi

Differential Revision: D56480889

fbshipit-source-id: e2acdc768e929fed4ea414a64250c6af237b8c96

* Add TSC Clock Callback to CUPTI

Summary:
Right now we use the default clock for CUPTI which is not monotonic nor particularly fast. To fix this, lets define a getAppoximateTime call for Kineto and use that to retrieve timestamp counts. Afterwards we can have profiler set the converter from timestamp count to timestamp. We add this converter to the timestamp() and duration() functions in Kineto.

One important detail is that this is not to be used for Windows or CUDA versions before 11.6. For this reason, necessary ifdefs have been placed. Profiler follow up diff will enable the features in this diff.

Reviewed By: aaronenyeshi

Differential Revision: D56525885

fbshipit-source-id: 68d70db953e546e1ba45e585ba634fc7f73d23ff

* Remove unused variables in kineto/libkineto/src/RoctracerActivityApi.cpp

Summary:
LLVM-15 has a warning `-Wunused-but-set-variable` which we treat as an error because it's so often diagnostic of a code issue. Unused variables can compromise readability or, worse, performance.

This diff either (a) removes an unused variable and, possibly, it's associated code, or (b) qualifies the variable with `[[maybe_unused]]`, mostly in cases where the variable _is_ used, but, eg, in an `assert` statement that isn't present in production code.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

Reviewed By: palmje

Differential Revision: D56587667

fbshipit-source-id: d19a78bf62e439e62c7706cf7199ef41f92e9a86

* Fix missing field initializer in kineto/libkineto/src/CuptiRangeProfilerApi.cpp +1

Summary:
The LLVM warning `-Wmissing-field-initializers` has found one or more structs in this diff's files which were missing field initializers.

This can be unintended such as:
```
my_struct s1 = {0}; // Initializes *only* the first field to zero; others to default values
my_struct s2 = {}; // Initializes *all* fields to default values (often zero)
```
or it may be because only some of the members of a struct are initialized, perhaps because the items were added to the struct but not every instance of it was updated.

To fix the problem, I've either used `{}` to initialize all fields to default or added appropriate default initializations to the missing fields.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

Reviewed By: palmje

Differential Revision: D56614184

fbshipit-source-id: 21b0a4c5d002c9b49107103e9e0a8852801fef58

* Handle cuLaunchKernelEx

Summary:
Triton is using cuLaunchKernelEx in some cases now, so we want to be
able to link these activities.

Proper credit goes to ngimel, who wrote this diff.  I just added a test and
ran it on fb infra where the test infra is already set up :)

Reviewed By: aaronenyeshi

Differential Revision: D56638653

fbshipit-source-id: 2da883cf9a77aa219e3a75f4d33f827dd399a22b

* Remove erroneous "include/ApproximateClock.h"

Summary: In D56525885, we added an include that does not exist. We need to remove it to fix some of the builds.

Reviewed By: aaronenyeshi

Differential Revision: D56638448

fbshipit-source-id: efb21987b2f4c0189c1b33fc3df9931f581b9548

* Fix missing field initializer in kineto/libkineto/src/CuptiNvPerfMetric.cpp +1

Summary:
The LLVM warning `-Wmissing-field-initializers` has found one or more structs in this diff's files which were missing field initializers.

This can be unintended such as:
```
my_struct s1 = {0}; // Initializes *only* the first field to zero; others to default values
my_struct s2 = {}; // Initializes *all* fields to default values (often zero)
```
or it may be because only some of the members of a struct are initialized, perhaps because the items were added to the struct but not every instance of it was updated.

To fix the problem, I've either used `{}` to initialize all fields to default or added appropriate default initializations to the missing fields.

 - If you approve of this diff, please use the "Accept & Ship" button :-)

Reviewed By: palmje, aaronenyeshi

Differential Revision: D56614178

fbshipit-source-id: fdbc234ba5c6c52607eb1bd293bf19651db4edf2

* Remove Hardcoding of /opt/rocm in CMakeLists.txt (#912)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/912

In https://github.com/pytorch/kineto/issues/838, suranap points out that we should not be using hardcoded paths for the rocm source

Reviewed By: aaronenyeshi

Differential Revision: D56319191

fbshipit-source-id: 437faf43ba8b96c81ce0e9c008673bebe9e4e7d4

* Fix deprecated use of 0/NULL in kineto/libkineto/src/CuptiCallbackApi.h + 1

Summary:
`nullptr` is typesafe. `0` and `NULL` are not. In the future, only `nullptr` will be allowed.

This diff helps us embrace the future _now_ in service of enabling `-Wzero-as-null-pointer-constant`.

Reviewed By: palmje

Differential Revision: D56650293

fbshipit-source-id: 52d69220619447b98968bd2758c110a8ee7fa8b2

* Fix deprecated use of 0/NULL in kineto/libkineto/src/CuptiCallbackApi.cpp + 1

Summary:
`nullptr` is typesafe. `0` and `NULL` are not. In the future, only `nullptr` will be allowed.

This diff helps us embrace the future _now_ in service of enabling `-Wzero-as-null-pointer-constant`.

Reviewed By: palmje

Differential Revision: D56650310

fbshipit-source-id: ec371056d3a933e8b02fa6dec648de4003f7a2a4

* Make ipcfabric have a single definition

Summary:
There is an ODR one definition rule violation that was causing a crash on sigrid
https://fb.workplace.com/groups/560979627394613/posts/2909061125919773/?comment_id=2909752389183980&reply_comment_id=2910102119149007
Sigrid includes both kineto and ipcfabric via dynolog, and on kineto the class is fused in internal. Also adding Logger.h caused a mess.

Tries to resolve this issue
Note ENABLE_IPC_FABRIC define is only used in open source kineto (and PyTorch) but not in internal fbcode

Differential Revision: D56577485

fbshipit-source-id: bc482e11f03d7ec360877a8f4a100fa5fc3234a3

* Fix deprecated use of 0/NULL in kineto/libkineto/src/CuptiRangeProfilerApi.h + 1

Summary:
`nullptr` is typesafe. `0` and `NULL` are not. In the future, only `nullptr` will be allowed.

This diff helps us embrace the future _now_ in service of enabling `-Wzero-as-null-pointer-constant`.

Reviewed By: palmje

Differential Revision: D56650279

fbshipit-source-id: 075e0bf23af90ebb97d90d7b0580ad52daa67f4c

* Change relative time of 'ts' field from init time to the start of 3 month intervals

Summary:
Use the start of 3 month intervals as the base_time which all the timestamps will be relative to. This is better than using init time of the tracer because traces across ranks are starting at different starting points, and its very hard to correlate them especially when working on PP, FSDP, etc.

There are tools like Chrome Trace Viewer that uses double to represent
each element in the timeline. Double has a 53 bit mantissa to support
up to 2^53 significant digits (up to 9007199254740992). This holds at the
nanosecond level, about 3 months and 12 days. So, let's round base time to
3 months intervals, so we can still collect traces across ranks relative to
each other. A month is 2629746, so for 3 months std::ratio is 7889238.

Reviewed By: sraikund16

Differential Revision: D56642236

Pulled By: aaronenyeshi

fbshipit-source-id: cd66d85181036b75c50c73354215b96d468e9790

* Remove TMP_USE_TSC_AS_TIMESTAMP from OSS compilation

Summary: We are taking a break on rolling out Kineto improvements until proper E2E and Unit testing is in. Lets roll back this change so we can update the kineto hash without breaking things.

Reviewed By: aaronenyeshi

Differential Revision: D56727137

fbshipit-source-id: 311b5a64554f7e0fa6301571d2dab01842f9f963

* Make Kineto Stage Log Level Lower

Summary:
Users have complained that STAGE level logs are print by default. If a user is running many profiles it can certainly clutter STDOUT. Lower the STAGE level such that it is below the default. This will only affect OSS and internally, STAGE will still be outputted.

Brought up by this issue https://github.com/pytorch/pytorch/issues/83383

Reviewed By: aaronenyeshi

Differential Revision: D56646009

fbshipit-source-id: e8eb920c866af2e566be4c3bdc7c7d760be81e6c

* Improve roctracer activities metadata and names (#922)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/922

Improving RoctracerActivity Metadata and Name:
- Similar to CUDA, fix the naming Memcpy and Memset to include Kind, src, and dst
- Improve metadata to properly include stream and kind
- Also, added correlation, which is used by downstream analyzers to correlate GPU to CPU op.

Test Plan:
Ran the diff on AMD sigrid predictor machine:
Before: https://www.internalfb.com/intern/perfdoctor/trace_view?filepath=tree/traces/dynocli/0/1714589410/localhost/libkineto_activities_1521592.json.gz&bucket=gpu_traces
After: https://www.internalfb.com/intern/perfdoctor/trace_view?filepath=tree/traces/dynocli/0/1714598360/localhost/libkineto_activities_385338.json.gz&bucket=gpu_traces

## Memcpy
- Improved Memcpy names:
Before:
 {F1501692238}
After:
 {F1501692699}

- Improved Memcpy metadata:
Before:
 {F1501697406}
After:
 {F1501698567}
## Memset
- Improved Memset names:
Before:
 {F1501696248}
After:
 {F1501696391}
- Improved Memset metadata:
Before:
 {F1501698081}
After:
 {F1501697661}

Reviewed By: xw285cornell, houseroad

Differential Revision: D56848113

Pulled By: aaronenyeshi

fbshipit-source-id: 8b9d6c7456035c69e78a9986a84fc7ff683fbec6

* Change Default Chrome Trace Unit to be in Milliseconds (#923)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/923

We have received comments stating that it would be easier to read tracings if they were back in millisecond format. For this reason, change the default back to milliseconds and if a user wants to read at nanosecond, they can just change the JSON manually.

Reviewed By: aaronenyeshi

Differential Revision: D56894110

fbshipit-source-id: 73fad992f000f1d9a4bddb5e2f7776e6bb370e63

* Delay logging for stream wait event till end to ensure filtering is (#908)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/908

Fixes https://github.com/pytorch/kineto/issues/904

Today to avoid noisy "even sync" events we do some filtering such that if a kernel is not launched on a stream till now (in trace window) we do not emit these events. But this may be incorrect if a future kernel is present but we just did not see it yet in the events.

Fix: the idea is to not filter the CUDA event synchronizations on the fly. instead defer the logging of some of these events till all other events are processed. We then log these events only if a stream has some activity to avoid noise.

Reviewed By: aaronenyeshi

Differential Revision: D56198193

fbshipit-source-id: 916715b063fff1d6496b719e2b85f8ca732d436b

* Remove CUPTI Overhead track from AMD Traces (#924)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/924

Remove CUPTI Overhead track from AMD Traces. We don't collect CUPTI overhead for Roctracer.

Test Plan: CI and ran locally, see below.

Reviewed By: HugeEngine

Differential Revision: D56947649

Pulled By: aaronenyeshi

fbshipit-source-id: a96d94b0763fab0c5d99d4b41d26a0d770e437f7

* Log CUPTI and CUDA Versions via LoggerCollector

Summary: Add CUPTI Version, CUDA Runtime Version and CUDA Driver Version to the Logger Collector / Observer metadata. This helps us quickly check which versions are used by a tracing job. Also we need to move init of LoggerCollector before ActivityProfiler.

Reviewed By: briancoutinho, zhuhan0

Differential Revision: D57002323

Pulled By: aaronenyeshi

fbshipit-source-id: 411bfa42d778f0ea0123600d2b96cdc2c8432a77

* Remove ipcfabric folder which already imported from dynolog (#929)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/929

Remove ipcfabric folder, which is not being used. In OSS, we are using ipcfabric that comes from the third_party/dynolog repo.

Test Plan: CI

Reviewed By: sraikund16

Differential Revision: D57212412

Pulled By: aaronenyeshi

fbshipit-source-id: 0225fcdc0f02545de916da6d5d05a9cd419f90c1

* Add Base Timestamp to Kineto Tracings (#928)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/928

Because we use relative timestamps in Kineto tracings, other plugins that use stitching, like GPUSnoop, have began to fail. In order for events to be stitched properly, they will need the basetime to get a relative timestamp off of. We output this in our chrome trace JSON as "baseTimeNanoseconds"

Reviewed By: aaronenyeshi

Differential Revision: D57186263

fbshipit-source-id: f7628bebda7c40c74a558c125c81aa96312df0a1

* Add deviceProperties for AMD devices to trace's metadata (#927)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/927

Similar to CUDA, save the device properties to the metadata of Roctracer GPU traces.
- Renamed CudaDeviceProperties files to DeviceProperties, and changed TARGETS' cpp_library to device_properties
- Added gpu agnostic definitions so we can re-use existing DeviceProperties functions to return a valid devicePropertiesJson() string for AMD. Return "" for any non-CUDA or non-AMD.
- Used ifdef for a few device properties specific to CUPTI: regsPerMultiprocessor, sharedMemPerBlockOptin, sharedMemPerMultiprocessor.
- Clean up the TARGETS, only need 1 library and include it.

Test Plan: CI

Reviewed By: xw285cornell

Differential Revision: D56901553

Pulled By: aaronenyeshi

fbshipit-source-id: ae87d14ab63a19abbbed836663f99e9ce6213a17

* Rework CudaUtil into DeviceUtil to support AMD (#931)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/931

Renamed CudaUtil to DeviceUtil and refactored the code to support AMD:
- Combined CudaUtil, cupti_call and cuda_call into a single DeviceUtil.
- Added functionality to print roctracer version, HIP driver version and HIP runtime version.
- Updated isGpuAvailable check to support HIP.
- Clean up TARGETS to remove file duplication and added DeviceUtil and DeviceProperties into a cpp_library, device_functions.

Test Plan: CI

Reviewed By: xw285cornell

Differential Revision: D56943493

Pulled By: aaronenyeshi

fbshipit-source-id: 805c2a32bdbe43a3b7def4c6484d1107dc2caa9b

* Log RocTracer, HIP Driver and HIP Runtime versions to Scuba (#932)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/932

Log the versions for roctracer, hip driver and hip runtime. Using same logger observer api as CUDA / CUPTI.

Test Plan: CI

Reviewed By: houseroad

Differential Revision: D57349962

Pulled By: aaronenyeshi

fbshipit-source-id: 8eaca35ee3daa130d1c85c19168e0e707a3ea19e

* Split isGpuAvailable between AMD and CUDA (#933)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/933

This allows init.cpp to check which devices are available to help determine how to startup. Required for D57063901.

Test Plan: CI

Differential Revision: D57343727

Pulled By: aaronenyeshi

fbshipit-source-id: e008da9ae1c4f83e68791d94b06ededc9a61e4ab

* Support CUPTI Range Profiler for H100 (#930)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/930

Previous errors when running on H100:

1) //kineto/libkineto:cupti_range_profiler_test_prog failed with CUPTI_ERROR_NOT_INITIALIZED

2) kineto/libkineto:kineto_playground failed with CUPTI_ERROR_MULTIPLE_SUBSCRIBERS_NOT_SUPPORTED

Reviewed By: briancoutinho

Differential Revision: D55262038

fbshipit-source-id: 7c83207e8e3aae91a953b305e690b4067dc69c33

* Revert D55262038: Multisect successfully blamed "D55262038: Support CUPTI Range Profiler for H100" for one test failure

Summary:
This diff reverts D55262038
D55262038: Support CUPTI Range Profiler for H100 by pls331 causes the following test failure:

Tests affected:
- [cogwheel:cogwheel_adranker_local_compare_test#main](https://www.internalfb.com/intern/test/281475018584027/)

Here's the Multisect link:
https://www.internalfb.com/multisect/5091629
Here are the tasks that are relevant to this breakage:

The backout may land if someone accepts it.

If this diff has been generated in error, you can Commandeer and Abandon it.

Reviewed By: aaronenyeshi

Differential Revision: D57370679

fbshipit-source-id: d10c0c84a57d3707ba6f0859756472c9eb7c09e4

* Quick fix mixed up function names and variables for isGpuAvailable (#934)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/934

Some of the APIs got mixed up, and both of them are failing to return the right values.

Test Plan: N/A

Differential Revision: D57392667

Pulled By: aaronenyeshi

fbshipit-source-id: 6fa65af017a7a551da18945c1b1fc76c214e826d

* Add new activity type

Summary: Add a new activity type for workloadd events in Kineto

Reviewed By: aaronenyeshi

Differential Revision: D57171609

fbshipit-source-id: 1ea99bda3f957f12821d4280f0e873f9468b697c

* Delayed Init for kineto for AMD

Summary:
Issue: Kineto static init doesn't happen automatically for AMD machines, and so we are unable to collect traces on-demand using dyno CLI. In libkineto_init, we initialize Profiler for NVIDIA (gated by HAS_CUPTI) and do a delayed initialize for MTIA (gated by isMTIA), but we don't initialize for AMD.

Adding a delayed initialize for AMD as well.

Reviewed By: xw285cornell

Differential Revision: D57063901

fbshipit-source-id: 76edc97ac4e0ec935d63a58359b1fee0179188b2

* Fix Non-CUDA Builds in Kineto (#937)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/937

Currently any Non-CUDA builds will fail to compile because the sources are not available for Device utils and Device Properties

Reviewed By: briancoutinho, fenypatel99

Differential Revision: D57694275

fbshipit-source-id: 1fda4fbee2a53bcaf6789e80821514835a39cfb5

* Re-land with fix -> D55262038: Support CUPTI Range Profiler for H100" for one test failure (#936)

Summary: Pull Request resolved: https://github.com/pytorch/kineto/pull/936

Reviewed By: briancoutinho

Differential Revision: D57396669

fbshipit-source-id: 4ab43b6cd2d1c54f80b8f247fd8e55e04a191eec

* Fix DeviceProperties compile on AMD (#940)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/940

One of the headers is incorrect. Need to change to <hip/hip_runtime.h>

Reviewed By: fenypatel99

Differential Revision: D57788137

fbshipit-source-id: 1aef27c624fa85156ccec5bcfb58eaddbde824ea

* Add Join to ManifoldChromeTraceLogger (#938)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/938

Requested in this post:
https://fb.workplace.com/groups/ai.efficiency.tools.users/permalink/1777663889385748/

Manifold upload fail because resources get cleaned by parent thread while manifold is still being uploaded to. In order to fix this, we save any uploading thread as an instance variable. Then, during the destructor, join on this thread if possible.

Currently, the ChromeTraceLogger is declared locally so it will deconstruct once the save() function is exited. This will result in a join() happening right after the thread launch, which negates the use of multithreading. For this reason, we save the ChomeLogger  as an instance variable of the MemLogger. That way, when the CuptiTraceActivity class exits, the MemLogger will exit and then the ChromeTraceLogger will exit thereby calling its destructor (which is much after the save() gets called).

Reviewed By: sanrise

Differential Revision: D57741999

fbshipit-source-id: 15e80130d728ab88cf357f3748e8dc465cdb3778

* Fix division by zero (#941)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/941

```
W0530 09:23:50.932043 139856935265408 loader.py:102] Failed to parse profile data for Run train on 1716249387. Exception=float division by zero
Traceback (most recent call last):
  File "/mnt/xarfuse/uid-218352/391895d9-seed-nspid4026531836_cgpid68799117-ns-4026531841/torch_tb_profiler/profiler/loader.py", line 93, in _process_data
    profile = generator.generate_run_profile()
  File "/mnt/xarfuse/uid-218352/391895d9-seed-nspid4026531836_cgpid68799117-ns-4026531841/torch_tb_profiler/profiler/run_generator.py", line 32, in generate_run_profile
    profile_run.overview = self._generate_overview()
  File "/mnt/xarfuse/uid-218352/391895d9-seed-nspid4026531836_cgpid68799117-ns-4026531841/torch_tb_profiler/profiler/run_generator.py", line 131, in _generate_overview
    build_part_time_str(costs.costs[ProfileRole.Kernel], 'Kernel'),
  File "/mnt/xarfuse/uid-218352/391895d9-seed-nspid4026531836_cgpid68799117-ns-4026531841/torch_tb_profiler/profiler/run_generator.py", line 87, in build_part_time_str
    percentage = round(100 * part_cost / costs.costs[ProfileRole.Total], 2)
```

Reviewed By: sraikund16

Differential Revision: D57975306

fbshipit-source-id: 89cd21feddecf4b91a03ab26b0392e0c65cbe569

* Fix broken test (#942)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/942

Conversion to percents lost in previous commit D57975306

Reviewed By: davidberard98

Differential Revision: D58067577

fbshipit-source-id: 4845a0257841147316dc1ae3b8db97dc54b982e0

* Lower GPU User Annotation Margin (#944)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/944

Users have reported that some GPU events overlap on only a single side. This is partially because we add a margin to our GPU User Annotations so that they don't have the same exact start and end time as other events if there is only one event in a user annotation. We can lower the margin now that we don't have rounding issues.

Reviewed By: aaronenyeshi

Differential Revision: D58254807

fbshipit-source-id: 6875fee26f57aba12cde9466d142c9dd62a67146

* Add sortIndex to fix ordering of roctracer GPU id tracks (#926)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/926

Although hipGetDeviceProperties shows 8 devices enumerating from 0 to 7, when using roctracer_record_t, the record->device_id enumerates from 2 to 9. This is because roctracer considers id 0 and 1 as CPU sockets.

So we can expect up to 8 CPU sockets and 8 GPUs, up to a total count of 16. Which would mean the enumeration will be 0 - 15. This will help put the GPU tracks in order and at the bottom of the chrome trace.

Original Bug report in ROCm/roctracer: https://github.com/ROCm/roctracer/issues/98. We can just show the device id that is given by roctracer.

Test Plan: CI, added a unit test: JsonGPUIDSortTest, and ran locally.

Reviewed By: chaekit

Differential Revision: D57067065

Pulled By: aaronenyeshi

fbshipit-source-id: 8aabf3f4e92edd708b7a6ed19c91b6a350e0b7cd

* Reintroduce CUPTI TSC Timestamp Compilation Flag to OSS (#945)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/945

Need to add flag back in for OSS to be able to use TSC timestamp for TSC events once we merge D56584521

Reviewed By: aaronenyeshi

Differential Revision: D58263179

fbshipit-source-id: 8539d358ddcea3f6a923d5f89dc8a62622363aee

* Move root level TARGETS into subdirectories (#946)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/946

Moving unit tests, samples, and stress test binaries into their respective subdirectories to make libkineto/TARGETS cleaner.

Reviewed By: davidberard98

Differential Revision: D58441051

Pulled By: aaronenyeshi

fbshipit-source-id: 0f7f62e6d14fc5f6d4f6b5b4e57cf0760046602e

* Skip CUPTIRangeProfilerApiTest and CuptiRangeProfilerTest due to SEGFAULT in CUDA 12.4 (#951)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/951

Github Actions CI on NVIDIA A10G instances are failing for these tests since the upgrade to 12.4:

19 - CuptiRangeProfilerApiTest.asyncLaunchUserRange (SEGFAULT)
20 - CuptiRangeProfilerApiTest.asyncLaunchAutoRange (SEGFAULT)
24 - CuptiRangeProfilerTest.UserRangeTest (SEGFAULT)
25 - CuptiRangeProfilerTest.AutoRangeTest (SEGFAULT)

We are tracking the issue here: https://github.com/pytorch/kineto/issues/949

Test Plan: CI

Reviewed By: sraikund16

Differential Revision: D58588836

Pulled By: aaronenyeshi

fbshipit-source-id: 4b1c02d18e235d1c8a4f7c5162d59950cfa89dcb

* Add JustKnobs to TSC CUPTI Callback (#947)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/947

Add JustKnobs so that we can turn TSC CUPTI Callback on and off. Since we need to meet open source compliance, we need to first add a default value of true in the Config class. In the FBConfig class we then add a method that checks the JK and overrides the default value of true. We also add a static variable to the CuptiActivityProfiler which will be overriden by the Config value upon initialization. Once this is set, the profiler as well as all headers will use the flag that was set by the JK. Using this flag we can essentially use the TSC timestamp or system clock via killswitch. Since the JK can run asynchronously across many initializations, wrap it in a try/catch.

On top of this change, ApproximateClock is moved from src/ to include/. This is because it is a forward facing header so it makes sense to expose it as a public header. Added also to the bazel file as a public header.

Reviewed By: aaronenyeshi

Differential Revision: D58485370

fbshipit-source-id: f69a331d11940767090718207913ae963516bbb0

* Add RoctracerActivityProfilerTest Unit Tests (#950)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/950

Adding 5 unit tests for the CuptiActivityProfiler and its interactions with RoctracerActivityApi. Mock the RoctracerLogger and the RoctracerActivityApi and pass them into the CuptiActivityProfiler orchestrator, then verify the trace files produced.

- **SyncTrace:** Mocks 5 CPU ops, 3 CPU Kernel Runtime Launches, 2 CPU Memcpy Runtime events, 3 GPU Kernels, 2 GPU Memcpy events. Checks that the trace output matches what was passed in, and names are correct after parsing.
- **GpuNCCLCollectiveTest:** Similar to CUPTI, check that NCCL metadata is properly passed into the CPU and GPU ops.
- **GpuUserAnnotationTest:** Check that GPU user annotations added via CorrelationDomain1 works properly, and the annotations are in the final trace.
- **SubActivityProfilers:** Check subactivityprofiler children will continue to work, such as glow runtime mock activity profiler.
- **JsonGPUIDSortTest:** Check that JSON file contains expected number of process_labels and process_sort_index , so that GPU rows in Chrome traces will always be sorted after CPU rows.

Test Plan: Ran locally on AMDGPU.

Reviewed By: houseroad

Differential Revision: D58554825

Pulled By: aaronenyeshi

fbshipit-source-id: 32177e7d4db3aa6c6e1b676e5500358a302d7ee7

* Add API for JK Inside Config Validation (#954)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/954

Right now we initialize all the configuration children when config is initialized. This is fine for the most part except for the fact that we set the selected activities only after the config is initialized. This makes our JustKnobs calls always get ignored. We can fix this by calling an API to check the Knobs after the parent is validated (we set activities before validation). The API (setActivityDependentConfig) in AbstractConfig will iterate through all child configs and call the child-defined version of setActivityDependentConfig. In FBConfig, will contain the JK reading.

Reviewed By: aaronenyeshi

Differential Revision: D58759304

fbshipit-source-id: ebd0d978627299b5ddecba58fc934e9342b31da3

* Remove global using namespace (#955)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/955

Fixing this:

```
kineto/libkineto/include/ThreadUtil.h:33:17: error: using namespace directive in global context in header [-Werror,-Wheader-hygiene]
   33 | using namespace libkineto;
      |                 ^
1 error generated.
```

Reviewed By: aaronenyeshi

Differential Revision: D58904139

fbshipit-source-id: 425e9d8a94e9015dbedbc0c111204c047e815451

* Remove all instances of TMP_USE_TSC_AS_TIMESTAMP (#957)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/957

Now that D56584521 is in, we can remove all insteances of TMP_USE_TSC_AS_TIMESTAMP

Reviewed By: swolchok

Differential Revision: D59132726

fbshipit-source-id: 4edfaff832aba9a4ca1779e31df4cf7041339c00

* Add Dist Info for On-Demand NCCL Traces (#956)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/956

Currently, auto-trace uses pytorches c10d.distributed library to set up the "distributedInfo" field in the chrome tracing. This makes sense as all the process groups are initialized and maintained in python. Because of this, however, on-demand is unable to retrieve this information directly as it has no access to the python side of a graph. However, we can glean the process group information based on the information that is added in to the dispatcher.

In this diff, we keep a global to enumerate all the nccl information via the args in the collectives as we print them out to the trace. At the end of the trace we output the distributed information. In order to prevent double counting for auto-trace, we skip if there was previously distributedInfo outputted to the trace.

Fixes https://github.com/pytorch/kineto/issues/885

Reviewed By: aaronenyeshi

Differential Revision: D58736045

fbshipit-source-id: 7e1a5e45398a63066f6f8f5b2e7541d67a6463a4

* Del un KINETO_NAMESPACE @ kineto/libkineto/src/IpcFabricConfigClient.h:26

Summary:
Removes a `using namespace` from the global namespace in pursuit of enabling `-Wheader-hygiene`.
Qualifies instances that relied on the `using namespace`.

Reviewed By: palmje

Differential Revision: D59178186

fbshipit-source-id: a492680f3038e58a683df3a816ec0852c3242b5d

* Update libfmt to 11-0-0. Closes #958. (#959)

Summary:
Fixes https://github.com/pytorch/kineto/issues/958

Pull Request resolved: https://github.com/pytorch/kineto/pull/959

Reviewed By: davidberard98, yoyoyocmu

Differential Revision: D59637583

Pulled By: aaronenyeshi

fbshipit-source-id: 48def339ed3097ecb4746d7870203040ac535858

* populate src/dst rank to GPU kernel (#963)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/963

Split from D59794535 V2- populate src/dst rank for p2p kernel in kineto

Reviewed By: sraikund16

Differential Revision: D59952097

fbshipit-source-id: cbe1587d90ae21bb6224915cbbd58f71457e9d09

* fix static variable client access vialotion in DamonConfigLoader (#965)

Summary:
As discussed in pytorch issue [#129626](https://github.com/pytorch/pytorch/issues/129626) , `updateThread` of `Config` will keep on accessing `client` after main thread quits.  But when main thread quits,  `client` will be destructed.  Functions in `updateThread` may use a dangling pointer of `client`, which will cause invalid memory access, and finally, `Segment fault` occurs, a core file will be generated, which  doesn't behave as expected.

Pull Request resolved: https://github.com/pytorch/kineto/pull/965

Reviewed By: xuzhao9

Differential Revision: D60291572

Pulled By: aaronenyeshi

fbshipit-source-id: d97291aa825deeb672eb8e2d8385633c2838396d

* Fix Kineto Stress Test (#971)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/971

The Kineto Stress test was failing for two reasons:

1) In the test itself, we did not set the converter for the TSC timestamp, making all values out of range

2) In Kineto itself there was a bug regarding child profilers. When these profilers are set their spans are set to all 0. However, when we set the record start in Kineto we use the start span of the CPU trace to get the start of the trace itself. In the future we should probably decouple these things but for now I added an edge case to ensure that the profile is not malformed.

Reviewed By: aaronenyeshi

Differential Revision: D60415474

fbshipit-source-id: e7b268aa0d41532448a28e1c1b4fe2ba81fda8da

* Add perfetto trace analysis benchmark (#969)

Summary:
Add a benchmark for trace analysis tasks on backends like Perfetto.

Step 1: install the benchmark (this will download and decompress sample trace from Amazon S3)

```
$ python -m benchmarks.perfetto.install

Checking out https://ossci-datasets.s3.amazonaws.com/torchbench/traces/torchbench_traces.tar.gz to /Users/xzhao9/git/kineto/benchmarks/trace_analysis/.data/torchbench_traces.tar.gz
decompressing input tarball: /Users/xzhao9/git/kineto/benchmarks/trace_analysis/.data/torchbench_traces.tar.gz...OK
Requirement already satisfied: perfetto in /Users/xzhao9/miniconda3/envs/test-numpy/lib/python3.11/site-packages (from -r /Users/xzhao9/git/kineto/benchmarks/trace_analysis/requirements.txt (line 1)) (0.7.0)
Requirement already satisfied: tabulate in /Users/xzhao9/miniconda3/envs/test-numpy/lib/python3.11/site-packages (from -r /Users/xzhao9/git/kineto/benchmarks/trace_analysis/requirements.txt (line 2)) (0.9.0)
Requirement already satisfied: protobuf in /Users/xzhao9/miniconda3/envs/test-numpy/lib/python3.11/site-packages (from perfetto->-r /Users/xzhao9/git/kineto/benchmarks/trace_analysis/requirements.txt (line 1)) (4.25.3)
```

Step 2: run the benchmark

```
$ python -m benchmarks.perfetto.run

                                    input-task    perfetto-latency
----------------------------------------------  ------------------
               torchbench_resnet50_3080ti-load         8.53069
torchbench_resnet50_3080ti-search_gemm_kernels         0.067583
     torchbench_resnet50_3080ti-select_kernels         0.000549563
      torchbench_resnet50_3080ti-group_kernels         0.0145147
```

Right now, only latency metric is available. We could add other metrics like memory footprint later.

Pull Request resolved: https://github.com/pytorch/kineto/pull/969

Reviewed By: aaronenyeshi

Differential Revision: D60466932

Pulled By: xuzhao9

fbshipit-source-id: 075476fc6b9b93f94d2d5d44183324360fdbd558

* Add Logging for Empty Traces (#968)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/968

Recently, we have had users seen empty traces when the system is idle leading to confusion as to whether it was caused by a bug in kineto formatting or not. This diff adds further logging to ensure that the user is aware that kineto finds no valid trace events and is expecting an empty trace.

Reviewed By: aaronenyeshi

Differential Revision: D60311331

fbshipit-source-id: 1836d37c622a85f17c08d6337480cb5bc49eca70

* Move group trace id and trace id to OSS kineto Config (#970)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/970

Previously the `trace_id` and `group_trace_id` fields were only parsed for `FBConfig`. There are OSS use-cases which would benefit from using these fields, so this diff moves the parsing of these fields to `Config`

Reviewed By: aaronenyeshi

Differential Revision: D60256788

fbshipit-source-id: 6e9ecccd5f888b704ba30688dff4c41014959347

* Introduce XPU profiler by following kineto plugin design (#961)

Summary:
As XPU became a PyTorch built-in device, the profiler support is indispensable part of functionality completeness. In this PR, the XPU profiler is introduced by following kineto plugin design under libkineto/src/plugin/xpupti. The XPU profiler plugin is built on the foundation of intel PTI toolkit (https://github.com/intel/pti-gpu), and underlying SYCL runtime. The LIBKINETO_NOXPUPTI option is added to enable or disable the XPU profiler plugin during kineto build stage.

CC: aaronenyeshi briancoutinho davidberard98 sraikund16

Pull Request resolved: https://github.com/pytorch/kineto/pull/961

Reviewed By: xuzhao9

Differential Revision: D60830913

Pulled By: aaronenyeshi

fbshipit-source-id: a24444e1ab1ed074bfcf5a9012076fa7c193b178

* Add API for Dynamic Activity Toggling [1/n] (#972)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/972

During PT2 there are many GPU/CPU events that are unneccessary to profile in between a given step. To remedy this, we can add an API that takes in a list of activities and an arg to toggle said activies or not. For this diff we are just adding the Kineto side to turn on/off the "CUDA" events which includes AMD/Roctracer. A follow up will be added for the generic profiler side.  Subsequent diffs will be added for CPU toggling and e2e testing.

Differential Revision: D60542040

fbshipit-source-id: 2608ec912812c9004cb87371bd8fca8145a95621

* Avoid marking every profile loop stop as Collection stage, use data available to mark errored stages. (#977)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/977

We already have the data collected to know if the collection was stopped due to `collectionDone` or `stopCollection`, the later is only set when CUPTI abruptly stops in events like not finding buffers.

We infact also set this in the itnernal Error Counters, so leverage that functionality within UST logging as well to denote a terminal stage within Kineto.

Reviewed By: aaronenyeshi

Differential Revision: D61226939

fbshipit-source-id: a4d5fa525d4457d44f0b959e4761b82de160152c

* Auto-init when CUDA_INJECTION64_PATH=none is set (#979)

Summary:
Pull Request resolved: https://github.com/pytorch/kineto/pull/979

CUDA_INJECTION64_PATH being set causes Kineto to skip auto-init. However CUDA_INJECTION64_PATH=none is a commonly used config option, and we should not skip auto-init since the path is set to none.

This diff fixes the scenario where `CUDA_INJECTION64_PATH=none` is set and on-demand trace should be enabled.

Test Plan:
CI

Ran locally with `CUDA_INJECTION64_PATH=none` and on-demand profiling works!
```
$ CUDA_INJECTION64_PATH=none buck run mode/dev-nosan kineto/libkineto/fb/integration_tests:pytorch_resnet_integration_test
Buck UI: https://www.internalfb.com/buck2/282115c8-6c29-414a-9d39-c4afb73d4e52
Network: Up: 0B  Down: 0B
Jobs completed: 19751. Time elapsed: 1.5s.
BUILD SUCCEEDED
[INFO: args.py:  113]: Setting master address to localhost and port to 62421
[INFO: pytorch_resnet_integration_test.py:  256]: Start: ready to do work 2114906
WARNING: Logging before InitGoogleLogging() is written to STDERR
I0819 09:07:08.277374 2116870 C10dScubaLogger.cpp:32] Registering C10dScubaLogger...
I0819 09:07:08.584887 2116870 ProcessGroupNCCL.cpp:865] [PG ID 0 PG GUID 0 Rank 0] ProcessGroupNCCL initialization options: size: 1, global rank: 0, TIMEOUT(ms): 600000, USE_HIGH_PRIORITY_STREAM: 0, SPLIT_FROM: 0, SPLIT_COLOR: 0, PG Name: 0
I0819 09:07:08.584949 2116870 ProcessGroupNCCL.cpp:874] [PG ID 0 PG GUID 0 Rank 0] ProcessGroupNCCL environments: NCCL version: 2.18.3, TORCH_NCCL_ASYNC_ERROR_HANDLING: 3, TORCH_NCCL_DUMP_ON_TIMEOUT: 0, TORCH_NCCL_WAIT_TIMEOUT_DUMP_MILSEC: 60000, TORCH_NCCL_DESYNC_DEBUG: 0, TORCH_NCCL_ENABLE_TIMING: 0, TORCH_NCCL_BLOCKING_WAIT: 0, TORCH_DISTRIBUTED_DEBUG: OFF, TORCH_NCCL_ENABLE_MONITORING: 0, TORCH_NCCL_HEARTBEAT_TIMEOUT_SEC: 480, TORCH_NCCL_TRACE_BUFFER_SIZE: 2000, TORCH_NCCL_COORD_CHECK_MILSEC: 1000, TORCH_NCCL_NAN_CHECK: 0, TORCH_NCCL_LOG_CPP_STACK_ON_UNCLEAN_SHUTDOWN: 1
INFO:2024-08-19 09:07:11 2116870:2116870 CuptiCallbackApi.cpp:78] Callback: domain = 3, cbid = 1
INFO:2024-08-19 09:07:11 2116870:2116870 CuptiActivityProfiler.cpp:241] CUDA versions. CUPTI: 18; Runtime: 12000; Driver: 12000
INFO:2024-08-19 09:07:11 2116870:2119791 DynoConfigLoader.cpp:61] Setting communication fabric enabled = 0
INFO:2024-08-19 09:07:12 2116870:2119791 DynoConfigLoader.cpp:61] Setting communication fabric enabled = 0
I0819 09:07:15.780548 2116870 ProcessGroupNCCL.cpp:2130] [PG ID 0 PG GUID 0(default_pg) Rank 0] ProcessGroupNCCL broadcast unique ID through store took 0.059698 ms
NCCL version 2.18.3+cudaCUDA_MAJOR.CUDA_MINOR
I0819 09:07:15.851341 2116870 ProcessGroupNCCL.cpp:2240] [PG ID 0 PG GUID 0(default_pg) Rank 0] ProcessGroupNCCL created ncclComm_ 0x7f67ce8ec000 on CUDA device:
I0819 09:07:15.851400 2116870 ProcessGroupNCCL.cpp:2245] [PG ID 0 PG GUID 0(default_pg) Rank 0] NCCL_DEBUG: WARN
[INFO: pytorch_resnet_integration_test.py:  199]: step: 0, peak allocated GPU mem: 2.97GB, peak active GPU mem: 2.97GB, peak reserved GPU mem: 3.07GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 20, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 40, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 60, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 80, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 100, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 120, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 140, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 160, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 180, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 200, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 220, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
INFO:2024-08-19 09:07:36 2116870:2119791 ConfigLoader.cpp:271] Received config from dyno:

    ACTIVITIES_COMPRESSION_ALGORITHM=GZIP
    REQUEST_GROUP_TRACE_ID=E54247FF9C32A885E23EC0A21BC9DD96
      REQUEST_TRACE_ID=E54247FF9C32A885E23EC0A21BC9DD96
    ACTIVITIES_DURATION_MSECS=500
    PROFILE_REPORT_INPUT_SHAPES=true
    PROFILE_PROFILE_MEMORY=false
    PROFILE_WITH_STACK=false
    PROFILE_WITH_FLOPS=false
    PROFILE_WITH_MODULES=false
    ACTIVITIES_MANIFOLD_PATH=gpu_traces/tree/traces/dynocli/0/1724083651/localhost/
    REQUEST_TRACE_ID=5172367202475739244

[INFO: pytorch_resnet_integration_test.py:  199]: step: 240, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
INFO:2024-08-19 09:07:37 2116870:2121591 ActivityProfilerController.cpp:147] Received on-demand activity trace request by  profile timestamp = 1724083663089205388
INFO:2024-08-19 09:07:37 2116870:2121591 output_json.cpp:119] Tracing to temporary file /tmp/libkineto_activities_2116870.json
  Log file: /tmp/libkineto_activities_2116870.json
  Trace start time: 2024-08-19 09:07:43  Trace duration: 500ms
  Warmup duration: 5s
  Max GPU buffer size: 128MB
  Enabled activities: cpu_op,user_annotation,gpu_user_annotation,gpu_memcpy,gpu_memset,kernel,external_correlation,cuda_runtime,cuda_driver,cpu_instant_event,python_function,overhead,mtia_runtime,mtia_ccp_events,cuda_sync
  Manifold bucket: gpu_traces
  Manifold object: tree/traces/dynocli/0/1724083651/localhost/libkineto_activities_2116870.json
  Trace compression enabled: 1
  TTL in seconds: 31536000 (365 days)
INFO:2024-08-19 09:07:37 2116870:2121591 CuptiActivityProfiler.cpp:1004] Enabling GPU tracing with max CUPTI buffer size 128MB)
INFO:2024-08-19 09:07:37 2116870:2121591 CuptiActivityProfiler.cpp:929] [Profiler = NcclProfiler] Evaluating whether to run child profiler.
INFO:2024-08-19 09:07:37 2116870:2121591 CuptiActivityProfiler.cpp:942] [Profiler = NcclProfiler] Not running child profiler.
INFO:2024-08-19 09:07:37 2116870:2121591 CuptiActivityProfiler.cpp:929] [Profiler = CuptiRangeProfiler] Evaluating whether to run child profiler.
INFO:2024-08-19 09:07:37 2116870:2121591 CuptiActivityProfiler.cpp:942] [Profiler = CuptiRangeProfiler] Not running child profiler.
INFO:2024-08-19 09:07:37 2116870:2121591 CuptiActivityProfiler.cpp:1060] Tracing starting in 5s
INFO:2024-08-19 09:07:37 2116870:2121591 CuptiActivityProfiler.cpp:1065] Tracing will end in 6s
[INFO: pytorch_resnet_integration_test.py:  199]: step: 260, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 280, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 300, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 320, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
STAGE:2024-08-19 09:07:43 2116870:2121591 CuptiActivityProfiler.cpp:1185] Completed Stage: Warm Up
INFO:2024-08-19 09:07:43 2116870:2121591 CuptiActivityProfiler.cpp:1194] Tracing started
INFO:2024-08-19 09:07:43 2116870:2121591 CuptiActivityProfiler.cpp:1219] Tracing complete.
STAGE:2024-08-19 09:07:44 2116870:2121591 CuptiActivityProfiler.cpp:1236] Completed Stage: Collection
[INFO: pytorch_resnet_integration_test.py:  199]: step: 340, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
INFO:2024-08-19 09:07:44 2116870:2121591 CuptiActivityProfiler.cpp:274] Processing 1 CPU buffers
INFO:2024-08-19 09:07:44 2116870:2121591 CuptiActivityProfiler.cpp:307] Processed 690712 GPU records (34396720 bytes)
INFO:2024-08-19 09:07:44 2116870:2121591 CuptiActivityProfiler.cpp:349] Record counts: Out-of-range = 172266, Blocklisted runtime = 388516, Invalid ext correlations = 0, CPU GPU out-of-order = 0, Unexpected CUDA events = 0, CUPTI stopped early? = 0
INFO:2024-08-19 09:07:44 2116870:2121591 CuptiActivityProfiler.cpp:1269] Traces Recorded:
INFO:2024-08-19 09:07:44 2116870:2121591 CuptiActivityProfiler.cpp:1272] PyTorch Profiler: 1 iterations
INFO:2024-08-19 09:07:44 2116870:2121591 output_json.cpp:563] Chrome Trace written to /tmp/libkineto_activities_2116870.json
INFO:2024-08-19 09:07:44 2116870:2121591 output_json.cpp:619] Renamed the trace file to /tmp/libkineto_activities_2116870.json
STAGE:2024-08-19 09:07:44 2116870:2121591 CuptiActivityProfiler.cpp:1259] Completed Stage: Post Processing
I0819 09:07:45.141360 2122707 RoutingDecider.cpp:227] Ping Request to proxy failed with: AsyncSocketException: connect failed, type = Socket not open, errno = 111 (Connection refused)
[INFO: pytorch_resnet_integration_test.py:  199]: step: 360, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 380, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
INFO:2024-08-19 09:07:48 2116870:2122676 ManifoldChromeTraceLogger.cpp:140] Uploaded the trace file to Manifold: gpu_traces/tree/traces/dynocli/0/1724083651/localhost/libkineto_activities_2116870.json.gz
INFO:2024-08-19 09:07:48 2116870:2122676 ManifoldChromeTraceLogger.cpp:142] Check the trace by opening the below URI in your Chrome web browser:
INFO:2024-08-19 09:07:48 2116870:2122676 ManifoldChromeTraceLogger.cpp:144] https://www.internalfb.com/intern/perfdoctor/trace_view?filepath=tree/traces/dynocli/0/1724083651/localhost/libkineto_activities_2116870.json.gz&bucket=gpu_traces
INFO:2024-08-19 09:07:48 2116870:2122676 ManifoldChromeTraceLogger.cpp:154] Trace upload time: 3486626 us
STAGE:2024-08-19 09:07:48 2116870:2122676 ManifoldChromeTraceLogger.cpp:215] Completed Stage: Manifold Push
[INFO: pytorch_resnet_integration_test.py:  199]: step: 400, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 420, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 440, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 460, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 480, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 500, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 520, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 540, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 560, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 580, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 600, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 620, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 640, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 660, peak allocated GPU mem: 3.17GB, peak active GPU mem: 3.17GB, peak reserved GPU mem: 3.39GB.
[INFO: pytorch_resnet_integration_test.py:  199]: step: 680, peak allocated GPU mem: 3.17GB,…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: profiler release notes category Reverted topic: new features topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants