Skip to content
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

feat: Add support for CUDA streams in GNN plugin #4012

Merged

Conversation

benjaminhuth
Copy link
Member

@benjaminhuth benjaminhuth commented Jan 9, 2025

Uses the torch framework (as it is required anyways currently) as a source of cuda streams. Extends the interface of the some components to use the streams.

--- END COMMIT MESSAGE ---

Any further description goes here, @-mentions are ok here!

  • Use a conventional commits prefix: quick summary
    • We mostly use feat, fix, refactor, docs, chore and build types.
  • A milestone will be assigned by one of the maintainers

Summary by CodeRabbit

  • New Features

    • Introduced ExecutionContext structure to manage device and stream information across ExaTrkX plugin components.
    • Enhanced execution context handling for graph construction, edge classification, and track building processes.
  • Refactor

    • Updated method signatures in multiple classes to use ExecutionContext instead of direct torch::Device parameters.
    • Improved device and stream management in ExaTrkX pipeline components.
  • Chores

    • Standardized execution context management across ExaTrkX plugin implementation.

Copy link

coderabbitai bot commented Jan 9, 2025

Walkthrough

Introduce a new ExecutionContext structure in the ExaTrkX plugin, this pull request does. Replace direct torch::Device parameters with a comprehensive context object, it does. Affect multiple classes across header and source files, these changes will. Standardize how device and stream information is managed during graph construction, edge classification, and track building processes, they aim to. A more flexible and unified approach to handling execution contexts in machine learning-based track reconstruction, provide it will.

Changes

File Change Summary
Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/Stages.hpp New ExecutionContext struct added, method signatures in base classes updated
Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/OnnxEdgeClassifier.hpp
Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/OnnxMetricLearning.hpp
Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/TorchEdgeClassifier.hpp
Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/TorchMetricLearning.hpp
torch::Device parameter replaced with const ExecutionContext &execContext in method signatures
Plugins/ExaTrkX/src/BoostTrackBuilding.cpp
Plugins/ExaTrkX/src/OnnxEdgeClassifier.cpp
Plugins/ExaTrkX/src/TorchEdgeClassifier.cpp
Plugins/ExaTrkX/src/TorchMetricLearning.cpp
Method implementations updated to use new ExecutionContext
Plugins/ExaTrkX/src/ExaTrkXPipeline.cpp Logic added to create and populate ExecutionContext with device and stream information

Suggested Labels

Component - Examples, automerge, Track Finding, Event Data Model

Suggested Reviewers

  • andiwand
  • paulgessinger

Poem

Devices dance, context flows free
Torch meets Acts in harmony
Streams of data, graphs entwine
Yoda's wisdom in each line! 🚀🧘‍♂️


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b14d041 and a56dcdd.

📒 Files selected for processing (2)
  • Plugins/ExaTrkX/src/TorchEdgeClassifier.cpp (1 hunks)
  • Plugins/ExaTrkX/src/TorchMetricLearning.cpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (25)
  • GitHub Check: merge-sentinel
  • GitHub Check: unused_files
  • GitHub Check: missing_includes
  • GitHub Check: CI Bridge / lcg_106a: [alma9, clang16]
  • GitHub Check: linux_ubuntu_extra (ubuntu2204_clang, 20)
  • GitHub Check: CI Bridge / lcg_106a: [alma9, gcc14]
  • GitHub Check: CI Bridge / lcg_106a: [alma9, gcc13]
  • GitHub Check: CI Bridge / lcg_105: [alma9, clang16]
  • GitHub Check: CI Bridge / lcg_105: [alma9, gcc13]
  • GitHub Check: CI Bridge / linux_ubuntu_2204_clang
  • GitHub Check: CI Bridge / linux_ubuntu_2204
  • GitHub Check: linux_ubuntu_extra (ubuntu2204, 20)
  • GitHub Check: build_debug
  • GitHub Check: macos
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: CI Bridge / build_exatrkx
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: CI Bridge / build_exatrkx_cpu
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: linux_ubuntu
  • GitHub Check: docs
  • GitHub Check: CI Bridge / build_exatrkx
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: CI Bridge / build_exatrkx_cpu
🔇 Additional comments (6)
Plugins/ExaTrkX/src/TorchMetricLearning.cpp (3)

72-74: Wise changes in the Force, I sense!

The ExecutionContext, properly used it is. Device handling, clear and consistent it remains.


79-81: Protected the CPU-only path is!

Assert the device type we must, when CPU-only compilation we choose. Wisdom in defensive programming, there is.


83-87: Stream the Force through your tensors, you must!

The ExecutionContext you have, but its stream you must guard. In CUDA operations, protect the stream's lifecycle you should.

Plugins/ExaTrkX/src/TorchEdgeClassifier.cpp (3)

70-72: Consistency in the Force, strong it is!

The ExecutionContext pattern, consistently applied it is. Harmony in the codebase, this brings.


79-81: Protected the CPU path is, consistent with its siblings!

The same protection pattern, across components we maintain. Wisdom in consistency, there is.


83-87: Guard the CUDA stream with wisdom, you do!

The stream's lifecycle, properly managed it is. Through RAII guards, protect the Force we must.

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@benjaminhuth benjaminhuth added this to the next milestone Jan 9, 2025
@github-actions github-actions bot added the Component - Plugins Affects one or more Plugins label Jan 9, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🔭 Outside diff range comments (1)
Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/TorchEdgeClassifier.hpp (1)

Line range hint 31-39: In Config struct, deviceID parameter remains, yet ExecutionContext we now embrace.

Confusing this dual configuration is. Choose one path we must:

  1. Remove deviceID from Config, letting ExecutionContext handle all device management
  2. Document clearly how deviceID and ExecutionContext interact, we should

The Force suggests option 1, for clarity it brings.

 struct Config {
   std::string modelPath;
   std::vector<int> selectedFeatures = {};
   float cut = 0.21;
   int nChunks = 1;  // NOTE for GNN use 1
   bool undirected = false;
-  int deviceID = 0;
   bool useEdgeFeatures = false;
 };

Also applies to: 45-45

🧹 Nitpick comments (5)
Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/TorchMetricLearning.hpp (1)

Line range hint 35-36: Update the documentation for device handling, we must.

The comment "default is the first GPU if available" outdated it now is. With ExecutionContext we work, yet old GPU assumptions in comments remain. Update documentation to reflect new CUDA streams approach, we should.

   int knnVal = 500;
   bool shuffleDirections = false;
-  int deviceID = 0;  // default is the first GPU if available
+  // Device and stream configuration now handled through ExecutionContext

Also applies to: 47-47

Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/OnnxMetricLearning.hpp (1)

Line range hint 38-38: A unified approach to CUDA streams, we need.

Across all files, scattered device handling exists. To bring balance to the Force:

  1. Create a central ExecutionContext management utility
  2. Remove all direct device handling (device(), deviceID)
  3. Document CUDA stream best practices
  4. Add examples of ExecutionContext usage

Help with implementation of these suggestions, would you like?

Also applies to: 45-45, 47-47, 42-42

Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/Stages.hpp (1)

24-28: Hmmmm, good the structure is, but documentation it needs!

Well-designed the ExecutionContext structure is, with CPU as default device and optional CUDA stream. But document its purpose and usage, you should.

Add this documentation, you must:

 /// Capture the context of the execution
+/// @brief Encapsulates device and stream information for GPU-accelerated operations
+/// @details The device defaults to CPU, and stream is optional for CUDA devices
 struct ExecutionContext {
   torch::Device device{torch::kCPU};
   std::optional<c10::cuda::CUDAStream> stream;
 };
Plugins/ExaTrkX/src/BoostTrackBuilding.cpp (1)

51-51: Use the Force of CUDA streams, you do not!

ExecutionContext you receive, but its power you do not harness. Opportunity for parallel execution with CUDA streams, you miss.

Consider using CUDA streams for graph operations when available:

+  if (execContext.stream) {
+    // Use CUDA-aware boost graph operations with the stream
+    // TODO: Implement CUDA-accelerated graph components
+  }
Plugins/ExaTrkX/src/TorchEdgeClassifier.cpp (1)

81-85: Reorganize the guards, we should.

Though functional your implementation is, improve readability we can. Move device_guard declaration closer to its usage, we should.

-  std::optional<c10::cuda::CUDAGuard> device_guard;
   std::optional<c10::cuda::CUDAStreamGuard> streamGuard;
   if (device.is_cuda()) {
+    std::optional<c10::cuda::CUDAGuard> device_guard{device.index()};
-    device_guard.emplace(device.index());
     streamGuard.emplace(execContext.stream.value());
   }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 567db0c and 4482fcf.

📒 Files selected for processing (10)
  • Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/OnnxEdgeClassifier.hpp (1 hunks)
  • Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/OnnxMetricLearning.hpp (1 hunks)
  • Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/Stages.hpp (4 hunks)
  • Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/TorchEdgeClassifier.hpp (1 hunks)
  • Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/TorchMetricLearning.hpp (1 hunks)
  • Plugins/ExaTrkX/src/BoostTrackBuilding.cpp (1 hunks)
  • Plugins/ExaTrkX/src/ExaTrkXPipeline.cpp (3 hunks)
  • Plugins/ExaTrkX/src/OnnxEdgeClassifier.cpp (1 hunks)
  • Plugins/ExaTrkX/src/TorchEdgeClassifier.cpp (1 hunks)
  • Plugins/ExaTrkX/src/TorchMetricLearning.cpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: merge-sentinel
  • GitHub Check: linux_ubuntu_extra (ubuntu2204_clang, 20)
  • GitHub Check: linux_ubuntu_extra (ubuntu2204, 20)
  • GitHub Check: linux_ubuntu
  • GitHub Check: build_debug
🔇 Additional comments (3)
Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/OnnxEdgeClassifier.hpp (1)

38-38: Hmmmm, inconsistent these methods are.

Device accessor method you keep, while ExecutionContext you now use. Confusion this may bring, when streams and device information from different sources flow. Consider deprecating the device() method, you should.

Run this command to check usage of device() method, we must:

Also applies to: 40-41

Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/Stages.hpp (1)

44-49: Approve this change, I do!

Wise decision it is, to use ExecutionContext with default value. Consistent with the Force, this change is.

Plugins/ExaTrkX/src/TorchEdgeClassifier.cpp (1)

70-72: Wise implementation of CUDA streams, this is.

Properly managed, the CUDA streams are. Good practices you follow, with ExecutionContext and CUDAStreamGuard.

Also applies to: 81-81, 84-84

Plugins/ExaTrkX/src/ExaTrkXPipeline.cpp Outdated Show resolved Hide resolved
Plugins/ExaTrkX/src/TorchMetricLearning.cpp Show resolved Hide resolved
Plugins/ExaTrkX/src/OnnxEdgeClassifier.cpp Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 9, 2025

📊: Physics performance monitoring for 5a826a9

Full contents

physmon summary

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4482fcf and b1d02dc.

📒 Files selected for processing (1)
  • Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/BoostTrackBuilding.hpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: merge-sentinel
  • GitHub Check: CI Bridge / lcg_106a: [alma9, gcc13]
  • GitHub Check: CI Bridge / lcg_105: [alma9, clang16]
  • GitHub Check: unused_files
  • GitHub Check: CI Bridge / lcg_105: [alma9, gcc13]
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: CI Bridge / linux_ubuntu_2204
  • GitHub Check: CI Bridge / build_exatrkx
  • GitHub Check: CI Bridge / linux_ubuntu_2204_clang
  • GitHub Check: CI Bridge / clang_tidy
  • GitHub Check: CI Bridge / build_exatrkx_cpu
  • GitHub Check: missing_includes
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: CI Bridge / build_linux_ubuntu
  • GitHub Check: CI Bridge / build_exatrkx
  • GitHub Check: linux_ubuntu_extra (ubuntu2204, 20)
  • GitHub Check: linux_ubuntu
  • GitHub Check: docs
🔇 Additional comments (1)
Plugins/ExaTrkX/include/Acts/Plugins/ExaTrkX/BoostTrackBuilding.hpp (1)

28-28: Verify the impact of ExecutionContext changes across the codebase, we must.

Throughout the ExaTrkX plugin, ripples of this change may spread. Ensure consistent usage of ExecutionContext in derived classes and calling code, we should.

Run this script to verify the changes:

✅ Verification successful

Verified, the ExecutionContext changes are. Consistent with the Force, they remain.

Throughout the ExaTrkX plugin, a harmonious pattern we observe. In all components - TorchMetricLearning, TorchEdgeClassifier, OnnxMetricLearning, OnnxEdgeClassifier, and BoostTrackBuilding - the same ExecutionContext usage flows. The change in BoostTrackBuilding.hpp, with the codebase's established patterns, aligns perfectly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining direct torch::Device usage in the ExaTrkX plugin
echo "Searching for torch::Device usage in ExaTrkX plugin..."
rg "torch::Device" -A 5 "Plugins/ExaTrkX"

# Search for ExecutionContext usage
echo "Verifying ExecutionContext adoption..."
rg "ExecutionContext" -A 5 "Plugins/ExaTrkX"

Length of output: 22218

Copy link
Member

@stephenswat stephenswat left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

@kodiakhq kodiakhq bot merged commit c0e65bc into acts-project:main Jan 15, 2025
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component - Plugins Affects one or more Plugins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants