Skip to content

Add empty kernel#504

Merged
MrBurmark merged 5 commits intodevelopfrom
feature/burmark1/noop_kernel
Apr 4, 2025
Merged

Add empty kernel#504
MrBurmark merged 5 commits intodevelopfrom
feature/burmark1/noop_kernel

Conversation

@MrBurmark
Copy link
Member

Add a kernel that does nothing inside of the loop to try have a way to get the minimal cost of running a loop.

Uses an empty asm statement to convince the compiler to generate code for loops even though they do nothing.

Summary

  • This PR is a feature
  • It does the following:
    • Adds empty kernel at the request of myself

Uses an empty asm statement to convince the compiler
to generate code for loops but do nothing inside
@MrBurmark MrBurmark requested a review from a team March 27, 2025 00:08
@MrBurmark MrBurmark self-assigned this Mar 27, 2025
@MrBurmark
Copy link
Member Author

MrBurmark commented Mar 27, 2025

Does it make more sense to put EMPTY in basic or algorithm?

@artv3
Copy link
Member

artv3 commented Mar 27, 2025

Does it make more sense to put EMPTY in basic or algorithm?

Basic I would think.

@rhornung67
Copy link
Member

@MrBurmark are we sure that the kernel doesn't get optimized away in all cases?

@MrBurmark
Copy link
Member Author

That's something we'd have to double check, but it should be pretty easy to tell if its very short and not tied to problem size.
I tried the asm statement in compiler explorer and it does cause an empty serial loop to be generated with all of the compilers I tried. MSVC has different asm syntax and I tried to cover that, but I'm not sure that's supported in all cases.

@MrBurmark
Copy link
Member Author

I'm trying to guard the asm statement with #if defined(RAJA_COMPILER_MSVC) but that doesn't appear to be working in the windows build, is there a different way we're supposed to detect MSVC builds?

@adayton1
Copy link
Member

I'm trying to guard the asm statement with #if defined(RAJA_COMPILER_MSVC) but that doesn't appear to be working in the windows build, is there a different way we're supposed to detect MSVC builds?

I think #if defined(_WIN32) though I can't remember if an underscore is needed or not.

@rhornung67
Copy link
Member

https://github.com/LLNL/RAJA/blob/develop/include/RAJA/config.hpp.in#L371

@MrBurmark
Copy link
Member Author

Interestingly MSVC doesn't support its __asm on x64, only x86. Hence the build failure nonstandard extension used: '__asm' keyword not supported on this architecture.

While this adds a store to stack memory into the loop
this is the least overhead option I have found.

Also remove ::: "memory" from the asm statement as it
appears to be unnecessary and is a gnu extension.
@MrBurmark
Copy link
Member Author

MrBurmark commented Mar 27, 2025

I changed the windows build to write to a volatile local variable which adds a store to the stack into the loop. This seems like the lowest overhead option that is fairly robust where asm is not supported.

@MrBurmark MrBurmark merged commit 323fb1b into develop Apr 4, 2025
24 checks passed
@MrBurmark MrBurmark deleted the feature/burmark1/noop_kernel branch April 4, 2025 22:04
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.

4 participants