Commit 6d04648
feat: add PyTorch profiler support to LAMMPS MD (#4969)
This pull request adds support for enabling the PyTorch profiler in the
`DeepPotPT` backend via an environment variable, making it easier to
profile and debug performance issues.
The profiler can be activated by setting the `DP_PROFILER` environment
variable, and will save profiling results to a JSON file when the object
is destroyed.
Fixes #4431
**Profiler integration:**
* Added a `profiler_enabled` flag and `profiler_file` string to the
`DeepPotPT` class to track profiler state and output location
(`DeepPotPT.h`).
* In the `init` method, added logic to check for the `DP_PROFILER`
environment variable. If set, the PyTorch profiler is configured and
enabled, with output written to a file named according to the
environment variable and GPU ID (`DeepPotPT.cc`).
* On destruction of `DeepPotPT`, if profiling was enabled, the profiler
is properly disabled and results are saved to the specified file
(`DeepPotPT.cc`).
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Optional runtime profiling via DP_PROFILER environment variable.
Produces per-process JSON traces (CPU-only or CPU+GPU) and saves them
automatically on shutdown; console messages report profiler status and
output filename.
* **Refactor**
* Improved device selection: auto-detects CUDA, selects a GPU per
process when available and falls back to CPU; clearer startup
diagnostics with no public API changes.
* **Documentation**
* Added DP_PROFILER usage, filename rules, examples, and operational
tips to the C++ interface docs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Signed-off-by: Chun Cai <amoycaic@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jinzhe Zeng <njzjz@qq.com>1 parent 40f0b1c commit 6d04648
3 files changed
Lines changed: 79 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
91 | 123 | | |
92 | 124 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| 343 | + | |
| 344 | + | |
343 | 345 | | |
344 | 346 | | |
345 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 73 | + | |
78 | 74 | | |
| 75 | + | |
79 | 76 | | |
80 | 77 | | |
81 | 78 | | |
| |||
86 | 83 | | |
87 | 84 | | |
88 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
89 | 117 | | |
90 | 118 | | |
91 | 119 | | |
| |||
119 | 147 | | |
120 | 148 | | |
121 | 149 | | |
122 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
123 | 161 | | |
124 | 162 | | |
125 | 163 | | |
| |||
0 commit comments