Skip to content

Conversation

@PhilipDeegan
Copy link
Member

@PhilipDeegan PhilipDeegan commented May 27, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a utility to zero out arrays on both CPU and GPU, with new functions available for device and host memory.
    • Added a configurable warp size parameter for CUDA and HIP backends.
    • Expanded launcher functionality with additional constructors for flexible kernel launching.
  • Documentation

    • Updated documentation to reflect new features, configuration options, and project description.
  • Tests

    • Added tests to verify correct zeroing of managed memory on the GPU.
    • Enhanced test coverage with additional threaded streaming tests.
  • Bug Fixes

    • Added error handling for invalid thread configurations in the threaded stream launcher.
  • Chores

    • Improved build configuration with explicit macro definitions for backend selection.

@coderabbitai
Copy link

coderabbitai bot commented May 27, 2025

Walkthrough

This update introduces CUDA/HIP C++20 convenience wrappers and documents a new configurable warp size macro. It adds device and host-side zeroing functions, extends the DLauncher struct with new constructors, introduces a new exception for stream launching, and updates tests to verify zeroing on managed memory. Several includes are reordered or removed for clarity and consistency.

Changes

File(s) Change Summary
README.md, README.noformat Updated project description, added C++20 target note, documented _MKN_GPU_WARP_SIZE_ config key.
inc/mkn/gpu/cpu.hpp Removed unused includes, added warpSize/warp_size constants, added zero template function.
inc/mkn/gpu/cuda.hpp, inc/mkn/gpu/rocm.hpp Removed/reordered includes, added conditional warp_size constant, included devfunc.hpp.
inc/mkn/gpu/devfunc.hpp New header with templated device function zero for parallel array zeroing on GPU.
inc/mkn/gpu/launchers.hpp Added default and variadic template constructors to DLauncher.
inc/mkn/gpu/multi_launch.hpp Reordered includes, added StreamLauncherException, modified ThreadedStreamLauncher constructor and join() for error handling.
mkn.yaml Explicitly defined preprocessor macros for each profile (ROCM, CUDA, CPU).
test/any/managed.cpp Added test_zero() to validate device zeroing; updated main() to include this test.
test/any/async_streaming.cpp Added test_threaded(0) call in main() return aggregation.

Sequence Diagram(s)

sequenceDiagram
    participant Host
    participant ManagedMem
    participant GPU
    participant Kernel

    Host->>ManagedMem: Allocate and initialize mem0, mem1
    Host->>GPU: Launch kernel (calls mkn::gpu::zero on mem0, mem1)
    GPU->>Kernel: Execute zeroing function (parallel zeroing)
    Kernel-->>GPU: Zeroed arrays
    GPU-->>Host: Return control
    Host->>ManagedMem: Validate all elements are zeroed
Loading

Possibly related PRs

Poem

In the code garden where zeroes grow,
The warp size now is set to show.
Launchers leap with new designs,
Device and host in tidy lines.
Managed tests pass—oh what cheer!
A rabbit hops, the path is clear.
🐇✨


📜 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 b14cfae and f3f0742.

📒 Files selected for processing (1)
  • inc/mkn/gpu/rocm.hpp (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • inc/mkn/gpu/rocm.hpp
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

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: 5

🧹 Nitpick comments (2)
inc/mkn/gpu/def.hpp (1)

21-24: Introduced warp size macro and constant.

Adding _MKN_GPU_WARP_SIZE_ and the warp_size constexpr provides a unified compile-time warp size constant that matches the updated documentation.
Consider, as an optional refactor, switching to an inline variable under C++20:

- static constexpr std::size_t warp_size = _MKN_GPU_WARP_SIZE_;
+ inline constexpr std::size_t warp_size = _MKN_GPU_WARP_SIZE_;

Additionally, note that macro names beginning with an underscore followed by an uppercase letter are reserved by the C++ standard; you may wish to rename _MKN_GPU_WARP_SIZE_ to MKN_GPU_WARP_SIZE_ to avoid reserved-identifier pitfalls.

inc/mkn/gpu/devfunc.hpp (1)

62-62: Consider using explicit template parameter instead of auto.

While auto& works for template parameters, using an explicit template parameter might be clearer and more maintainable.

-void inline _prinfo(auto& devProp) {
+template <typename DeviceProp>
+void inline _prinfo(DeviceProp& devProp) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 752c8e4 and b83cf97.

📒 Files selected for processing (11)
  • README.md (1 hunks)
  • README.noformat (2 hunks)
  • inc/mkn/gpu/cpu.hpp (1 hunks)
  • inc/mkn/gpu/cuda.hpp (1 hunks)
  • inc/mkn/gpu/def.hpp (1 hunks)
  • inc/mkn/gpu/devfunc.hpp (1 hunks)
  • inc/mkn/gpu/launchers.hpp (1 hunks)
  • inc/mkn/gpu/multi_launch.hpp (1 hunks)
  • inc/mkn/gpu/rocm.hpp (2 hunks)
  • mkn.yaml (1 hunks)
  • test/any/managed.cpp (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
test/any/managed.cpp (4)
inc/mkn/gpu/launchers.hpp (2)
  • DLauncher (72-72)
  • DLauncher (73-73)
inc/mkn/gpu/devfunc.hpp (2)
  • zero (41-49)
  • zero (41-41)
inc/mkn/gpu/cpu.hpp (2)
  • zero (284-286)
  • zero (284-284)
test/any/async_streaming.cpp (2)
  • test (23-54)
  • test (23-23)
inc/mkn/gpu/devfunc.hpp (4)
inc/mkn/gpu/cuda.hpp (9)
  • void (301-303)
  • void (306-308)
  • s (288-292)
  • s (288-288)
  • idx (61-61)
  • sync (238-238)
  • sync (238-238)
  • sync (239-239)
  • sync (239-239)
inc/mkn/gpu/rocm.hpp (7)
  • void (304-306)
  • void (309-311)
  • idx (60-60)
  • sync (247-247)
  • sync (247-247)
  • sync (248-248)
  • sync (248-248)
inc/mkn/gpu/cpu.hpp (7)
  • t (134-134)
  • idx (295-297)
  • idx (295-295)
  • sync (220-220)
  • sync (220-220)
  • zero (284-286)
  • zero (284-284)
inc/mkn/gpu/multi_launch.hpp (22)
  • s (81-81)
  • s (134-136)
  • i (94-94)
  • i (94-94)
  • i (105-109)
  • i (105-105)
  • i (119-119)
  • i (119-119)
  • i (169-179)
  • i (169-169)
  • i (192-201)
  • i (192-192)
  • i (221-224)
  • i (221-221)
  • i (287-287)
  • i (287-287)
  • i (312-321)
  • i (312-312)
  • idx (190-190)
  • idx (190-190)
  • idx (438-438)
  • idx (438-438)
🔇 Additional comments (13)
inc/mkn/gpu/multi_launch.hpp (1)

34-36: Consistent include ordering.

Moving project-specific headers ("mkn/gpu.hpp", "mkn/kul/log.hpp", "mkn/kul/time.hpp") above the standard library includes enhances dependency clarity and ensures foundational utilities are available before their consumers.

README.md (1)

3-5: Added project focus statement.

The new tagline "CUDA/HIP C++20 convenience wrappers" succinctly communicates the library's purpose right under the main heading.

mkn.yaml (1)

13-14: Verify ROCm test configuration.

By commenting out the test entries under the rocm profile, ROCm-specific tests will no longer run. Please confirm that ROCm tests have been intentionally disabled or migrated elsewhere; otherwise, re-enable or update these patterns to ensure ROCm code paths remain covered.

README.noformat (2)

3-4: Added concise project descriptor.

Including "CUDA/HIP C++20 convenience wrappers" at the top aligns with the README.md update and clearly states the target APIs and language standard.


30-34: Documented the new warp size configuration key.

The _MKN_GPU_WARP_SIZE_ entry along with its type and default value has been properly added. Ensure this stays in sync with inc/mkn/gpu/def.hpp.

inc/mkn/gpu/cpu.hpp (1)

283-286: LGTM! Clean CPU-side memory zeroing implementation.

The implementation correctly uses std::fill to zero out memory on the CPU side. The template design allows it to work with any data type, and the function signature is consistent with other utility functions in the codebase.

inc/mkn/gpu/launchers.hpp (1)

73-73: LGTM! Excellent use of perfect forwarding.

The new forwarding constructor enhances flexibility by allowing DLauncher to be constructed with any combination of arguments that the base Launcher class accepts. The use of auto&&... provides perfect forwarding, ensuring efficient argument passing.

inc/mkn/gpu/rocm.hpp (3)

35-35: Good refactoring: Commenting out unused include.

Commenting out the include aligns with the refactoring to centralize functionality in separate headers.


314-314: LGTM! Centralizing device functions.

Including devfunc.hpp provides access to centralized device utility functions, improving code organization and reducing duplication across CUDA/ROCm implementations.


319-319: Good use of helper function for device info printing.

Delegating to _prinfo(devProp) reduces code duplication and centralizes device property formatting logic.

test/any/managed.cpp (2)

86-103: LGTM! Well-designed test for GPU memory zeroing.

The test correctly exercises the GPU zero function:

  1. Creates managed vectors with known values (1 and 2)
  2. Launches a kernel with appropriate dimensions (dim3{1}, dim3{mkn::gpu::warp_size})
  3. The device zero function is designed for warp-level parallelism, so calling it with exactly warp_size threads is correct
  4. Verification logic properly checks that all elements are zeroed by ensuring they sum to 0

The test design aligns well with the device function's intended usage pattern where all threads in a warp cooperatively zero the array.


107-107: Good integration of new test into test suite.

Adding test_zero() to the aggregated return value ensures the new functionality is properly tested as part of the overall test suite.

inc/mkn/gpu/cuda.hpp (1)

316-316: LGTM - Clean delegation to centralized function.

The refactoring to delegate device property printing to _prinfo(devProp) is a good improvement that centralizes the implementation and reduces code duplication.

@PhilipDeegan PhilipDeegan merged commit fdc0308 into master Jul 9, 2025
1 check passed
@PhilipDeegan PhilipDeegan deleted the next branch July 9, 2025 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants