Skip to content

HIP/CUDA Gen: Use correct block size bounds in non-tensor dynamic dispatch calculations - #1993

Merged
zatkins-dev merged 4 commits into
mainfrom
zach/gen-block-size-fix
Aug 11, 2026
Merged

HIP/CUDA Gen: Use correct block size bounds in non-tensor dynamic dispatch calculations#1993
zatkins-dev merged 4 commits into
mainfrom
zach/gen-block-size-fix

Conversation

@zatkins-dev

Copy link
Copy Markdown
Collaborator

Purpose:

Removes hard coded constants for block size bounds with dynamically queried values for both HIP and CUDA gen backend non-tensor kernels.

Also, fixes a bug in the field reuse code in HIP.

Closes:

LLM/GenAI Disclosure:

None.

By submitting this PR, the author certifies to its contents as described by the Developer's Certificate of Origin.
Please follow the Contributing Guidelines for all PRs.

@zatkins-dev
zatkins-dev requested a review from jeremylt July 17, 2026 17:31
@zatkins-dev zatkins-dev changed the title Zach/gen block size fix HIP/CUDA Gen: Use correct block size bounds in non-tensor dynamic dispatch calculations Jul 17, 2026
@zatkins-dev zatkins-dev self-assigned this Jul 17, 2026
@zatkins-dev

Copy link
Copy Markdown
Collaborator Author

See #1994 for my thoughts on how to automatically catch these failures moving forward.

@zatkins-dev

Copy link
Copy Markdown
Collaborator Author

Also, note that we have to use hipModuleOccupancyMaxPotentialBlockSize, not hipOccupancyMaxPotentialBlockSize (like the CUDA equivalent cudaOccupancyMaxPotentialBlockSize), as HIP requires the functions passed to the latter to be compiled in advance using hipcc/hipcxx.

@zatkins-dev

Copy link
Copy Markdown
Collaborator Author

Also, should we use a more sophisticated algorithm for the HIP block and grid sizes, like we do for CUDA? It seems like the limitation was in not knowing the optimal minimum grid size and block sizes, which we now have access to.

@jeremylt

Copy link
Copy Markdown
Member

We need to do profiling here probably, because I think this has serious perf implications? @nbeams and @YohannDudouit know way better than I

@zatkins-dev

Copy link
Copy Markdown
Collaborator Author

We need to do profiling here probably, because I think this has serious perf implications?

FWIW -- The current code always falls back for Nitsche operators in Ratel, regardless of quadrature/solution order. This is a sizable perf improvement just by virtue of actually supporting gen in those cases. Not sure about general non-tensor, but I imagine this will fix some issues there too.

@jeremylt

Copy link
Copy Markdown
Member

Good point. I think a combo of profiling and expert opinion probably is still appropriate to make sure we are appropriately slicing the available resources?

Comment thread backends/cuda-gen/ceed-cuda-gen-operator.c Outdated
@nbeams

nbeams commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

My recollection: Back when we added the launch bounds to the HIP kernels, it (adding launch bounds) was recommended as best practice by our AMD liaisons for CEED, for performance. And also, an equivalent to cuOccupancyMaxPotentialBlockSize was not available for AMD GPUs until more recently (see Jed's/my comments in ROCm/hip#924).

But now that something like the CUDA routine is available, I guess the question is whether or not its (hopefully better) guess for occupancy is more important than the launch bounds or not. Of course since we have to compile the kernel first, if we either add launch bounds prematurely or go back and add launch bounds after calling the max occupancy routine, there is a chance it could change the kernel produced in a way that would alter the occupancy calculation. I really have no idea how much the launch bounds matter for recent ROCm and on the latest AMD GPUs, but it would be interesting to check.

@jeremylt

Copy link
Copy Markdown
Member

Searching around, I think there should not be a performance impact as long as we don't have any loops governed by block size (which I think we shouldn't)

@zatkins-dev

Copy link
Copy Markdown
Collaborator Author

That's a new clang-cuda issue, I can look at it more tomorrow but truly have no idea what it means. Pretty sure it's unrelated to this PR though

@jeremylt

Copy link
Copy Markdown
Member

I think its a clang/cuda compatibility issue. For Cuda 13.2 we really want a newer Clang than 21. I'm running Clang 23 on my current machine

@zatkins-dev

Copy link
Copy Markdown
Collaborator Author

Oh weird -- this job is supposed to be using Cuda 12.9, not 13.2

@jeremylt

Copy link
Copy Markdown
Member

Yea, I think its something about what version of Cuda that Rust is picking up as the default. Odd that this only became an issue with the latest Rust nightly, so dunno what's up with that

@zatkins-dev

Copy link
Copy Markdown
Collaborator Author

Yea, I think its something about what version of Cuda that Rust is picking up as the default. Odd that this only became an issue with the latest Rust nightly, so dunno what's up with that

I think I have a fix for it #1993. We probably should've been specifying the CUDA dir anyway

@jeremylt

Copy link
Copy Markdown
Member

since the rebase will reset my approval, I'll approve once this is rebased

@zatkins-dev
zatkins-dev force-pushed the zach/gen-block-size-fix branch from 1e585b5 to 3723f5f Compare August 11, 2026 15:46
@zatkins-dev
zatkins-dev merged commit fd85cfe into main Aug 11, 2026
31 checks passed
@zatkins-dev
zatkins-dev deleted the zach/gen-block-size-fix branch August 11, 2026 17:23
pvelesko added a commit to CHIP-SPV/chipStar that referenced this pull request Aug 12, 2026
CEED/libCEED#1993 (merged 2026-08-11) makes the hip-gen backend call
hipModuleOccupancyMaxPotentialBlockSize, which chipStar declares but
does not implement, so every CI run cloning libCEED main now fails at
link with an undefined reference -- including against chipStar main.
Pin the clone to the preceding main commit; unpin once the occupancy
APIs land in chipStar (an implementation exists on the
occupancy-max-potential-blocksize branch and belongs in its own PR).
pvelesko added a commit to CHIP-SPV/chipStar that referenced this pull request Aug 12, 2026
CEED/libCEED#1993 (merged 2026-08-11) makes the hip-gen backend call
hipModuleOccupancyMaxPotentialBlockSize, which chipStar declares but
does not implement, so every CI run cloning libCEED main now fails at
link with an undefined reference -- including against chipStar main.
Pin the clone to the preceding main commit; unpin once the occupancy
APIs land in chipStar (an implementation exists on the
occupancy-max-potential-blocksize branch and belongs in its own PR).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants