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

Feature: Optimize dngvd_op with CPU/GPU Branching Based on nstart #5919

Closed
wants to merge 9 commits into from

Conversation

jieli-matrix
Copy link
Collaborator

Currently, dngvd_op in module_hsolver/kernels/rocm/dngvd_op.hip.cu uses the ROCm implementation for all input sizes (nstart). Performance analysis shows that the CPU implementation (dngvd_op.cpp) is faster for smaller nstart values.
This PR proposes adding a conditional branch within the dngvd_op<double, base_device::DEVICE_GPU>::operator() function to select the optimal implementation based on nstart:

If nstart > 234, use the existing ROCm implementation.
If nstart <= 234, call the CPU implementation (dngvd_op<double, base_device::DEVICE_CPU>).
This change requires:
Adding an if (nstart > 234) { ... } else { ... } block within the GPU operator().
Inside the else block, calling the CPU implementation with appropriate type casts.

This optimization is expected to improve performance, especially for bigger matrix sizes.

@dyzheng
Copy link
Collaborator

dyzheng commented Feb 25, 2025

please fix the compiling error

// copied from ../cuda/dngvd_op.cu, "dngvd_op"
assert(nstart == ldh);

if (nstart > N_DCU){
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add notes for this kernel has intersection point of the performance curves between CPU and DCU.

// copied from ../cuda/dngvd_op.cu, "dngvd_op"
assert(nstart == ldh);

if (nstart > N_DCU){
Copy link
Collaborator

Choose a reason for hiding this comment

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

please add notes for this kernel has intersection point of the performance curves between CPU and DCU.

Copy link
Collaborator

Choose a reason for hiding this comment

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

to be honest, N_DCU is tested only for "complex" kernel, but maybe not good intersection point for "double" and "complex" kernel.

@mohanchen mohanchen added Features Needed The features are indeed needed, and developers should have sophisticated knowledge Refactor Refactor ABACUS codes labels Mar 11, 2025
@dyzheng dyzheng deleted the branch deepmodeling:stable March 31, 2025 09:48
@dyzheng dyzheng closed this Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Features Needed The features are indeed needed, and developers should have sophisticated knowledge Refactor Refactor ABACUS codes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants