-
Notifications
You must be signed in to change notification settings - Fork 612
Add C++ PyTorch profiler using modern torch::profiler API with cross-platform support and MPI integration #4904
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
Closed
Closed
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e9624cf
Initial plan
Copilot 3ca69f9
Implement C++ PyTorch profiler with environment variable controls
Copilot eeb7c06
Fix PyTorch profiler API usage and add integration documentation
Copilot 737878f
Update PyTorch profiler to use new torch::profiler API instead of dep…
Copilot a879955
Update documentation to reflect new PyTorch profiler API
Copilot 101a901
Add MPI rank support for PyTorch profiler output files
Copilot 4c60b92
Fix cross-platform compatibility for directory creation and path hand…
Copilot e422ee2
Remove MPI dependency from api_cc library to avoid linking issues
Copilot e28bb86
Add MPI linking to api_cc library with USE_MPI macro for conditional …
Copilot 284fc69
Remove unused MPIX_Query_cuda_support from api_cc CMakeLists.txt
Copilot b18c139
Remove unnecessary torch/profiler.h header includes
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # PyTorch C++ Profiler Integration Test | ||
|
|
||
| This test demonstrates the PyTorch profiler integration with the C++ backend. | ||
|
|
||
| ## Usage | ||
|
|
||
| 1. Set environment variables: | ||
| ```bash | ||
| export DP_ENABLE_PYTORCH_PROFILER=1 | ||
| export DP_PYTORCH_PROFILER_OUTPUT_DIR=./profiler_results | ||
| ``` | ||
|
|
||
| 2. Run your DeepMD-kit C++ application | ||
|
|
||
| 3. Check for profiler output in the specified directory: | ||
| ```bash | ||
| # For single-rank or non-MPI usage | ||
| ls -la ./profiler_results/pytorch_profiler_trace.json | ||
|
|
||
| # For MPI usage, each rank gets its own file | ||
| ls -la ./profiler_results/pytorch_profiler_trace_rank*.json | ||
| ``` | ||
|
|
||
| For MPI applications, you can use different output directories per rank: | ||
| ```bash | ||
| # Example for rank 0 | ||
| export DP_PYTORCH_PROFILER_OUTPUT_DIR=./profiler_results_rank0 | ||
| # Example for rank 1 | ||
| export DP_PYTORCH_PROFILER_OUTPUT_DIR=./profiler_results_rank1 | ||
| ``` | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| - `DP_ENABLE_PYTORCH_PROFILER`: Set to `1` or `true` to enable profiling | ||
| - `DP_PYTORCH_PROFILER_OUTPUT_DIR`: Directory for profiler output (default: `./profiler_output`) | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| The profiler uses PyTorch's modern `torch::profiler` API and automatically: | ||
| - Creates the output directory if it doesn't exist | ||
| - Profiles all forward pass operations in DeepPotPT and DeepSpinPT | ||
| - Saves profiling results to a JSON file when the object is destroyed | ||
| - Automatically includes MPI rank in filename when MPI is available and initialized | ||
|
|
||
| ## Output Files | ||
|
|
||
| - **Single-rank or non-MPI usage**: `pytorch_profiler_trace.json` | ||
| - **MPI usage**: `pytorch_profiler_trace_rank{rank}.json` (e.g., `pytorch_profiler_trace_rank0.json`, `pytorch_profiler_trace_rank1.json`) | ||
|
|
||
| This ensures that each MPI rank saves its profiling data to a separate file, preventing conflicts in multi-rank simulations. | ||
|
|
||
| This is intended for development and debugging purposes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@copilot
MPIX_Query_cuda_supportis not used inapi_cc, so I think it's not needed.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.
You're absolutely right. Removed the unnecessary
MPIX_Query_cuda_supportcheck and related CUDA-aware MPI detection from the api_cc library since it's not used in the source code. The library now only includes the essential MPI functionality needed for rank detection. Commit: 284fc69