Raising: read constant globals as tensors - #3005
Merged
Merged
Conversation
wsmoses
added a commit
that referenced
this pull request
Sep 6, 2026
A kernel-local constant table (`const int map[9] = {...}`) is promoted to
a host rodata global whose address would otherwise become a kernel
argument that can never resolve to a device buffer. Reads of such a global
fold to the initializer: directly for constant offsets, as a select chain
over the elements for runtime indices.
Dropped from the union on a compile-only necessity sweep; the GPU suite
needs it: without the fold bilininteg_vecdiffusion_pa's diagonal kernels
take the int table as an operand and the runtime dies with "pointer ...
does not belong to any reactant allocation" ("Vector Diffusion Diagonal
PA", "PA Vector Diffusion"). The union's form of the pass with #3005's
lit test.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
wsmoses
added a commit
that referenced
this pull request
Sep 6, 2026
A kernel-local constant table (`const int map[9] = {...}`) is promoted to
a host rodata global whose address would otherwise become a kernel
argument that can never resolve to a device buffer. Reads of such a global
fold to the initializer: directly for constant offsets, as a select chain
over the elements for runtime indices.
Dropped from the union on a compile-only necessity sweep; the GPU suite
needs it: without the fold bilininteg_vecdiffusion_pa's diagonal kernels
take the int table as an operand and the runtime dies with "pointer ...
does not belong to any reactant allocation" ("Vector Diffusion Diagonal
PA", "PA Vector Diffusion"). The union's form of the pass with #3005's
lit test.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
wsmoses
added a commit
that referenced
this pull request
Sep 6, 2026
A kernel-local constant table (`const int map[9] = {...}`) is promoted to
a host rodata global whose address would otherwise become a kernel
argument that can never resolve to a device buffer. Reads of such a global
fold to the initializer: directly for constant offsets, as a select chain
over the elements for runtime indices.
Dropped from the union on a compile-only necessity sweep; the GPU suite
needs it: without the fold bilininteg_vecdiffusion_pa's diagonal kernels
take the int table as an operand and the runtime dies with "pointer ...
does not belong to any reactant allocation" ("Vector Diffusion Diagonal
PA", "PA Vector Diffusion"). The union's form of the pass with #3005's
lit test.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
wsmoses
added a commit
that referenced
this pull request
Sep 6, 2026
A kernel-local constant table (`const int map[9] = {...}`) is promoted to
a host rodata global whose address would otherwise become a kernel
argument that can never resolve to a device buffer. Reads of such a global
fold to the initializer: directly for constant offsets, as a select chain
over the elements for runtime indices.
Dropped from the union on a compile-only necessity sweep; the GPU suite
needs it: without the fold bilininteg_vecdiffusion_pa's diagonal kernels
take the int table as an operand and the runtime dies with "pointer ...
does not belong to any reactant allocation" ("Vector Diffusion Diagonal
PA", "PA Vector Diffusion"). The union's form of the pass with #3005's
lit test.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
wsmoses
added a commit
that referenced
this pull request
Sep 6, 2026
A kernel-local constant table (`const int map[9] = {...}`) is promoted to
a host rodata global whose address would otherwise become a kernel
argument that can never resolve to a device buffer. Reads of such a global
fold to the initializer: directly for constant offsets, as a select chain
over the elements for runtime indices.
Dropped from the union on a compile-only necessity sweep; the GPU suite
needs it: without the fold bilininteg_vecdiffusion_pa's diagonal kernels
take the int table as an operand and the runtime dies with "pointer ...
does not belong to any reactant allocation" ("Vector Diffusion Diagonal
PA", "PA Vector Diffusion"). The union's form of the pass with #3005's
lit test.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
wsmoses
added a commit
that referenced
this pull request
Sep 6, 2026
A kernel-local constant table (`const int map[9] = {...}`) is promoted to
a host rodata global whose address would otherwise become a kernel
argument that can never resolve to a device buffer. Reads of such a global
fold to the initializer: directly for constant offsets, as a select chain
over the elements for runtime indices.
Dropped from the union on a compile-only necessity sweep; the GPU suite
needs it: without the fold bilininteg_vecdiffusion_pa's diagonal kernels
take the int table as an operand and the runtime dies with "pointer ...
does not belong to any reactant allocation" ("Vector Diffusion Diagonal
PA", "PA Vector Diffusion"). The union's form of the pass with #3005's
lit test.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
wsmoses
added a commit
that referenced
this pull request
Sep 7, 2026
A kernel-local constant table (`const int map[9] = {...}`) is promoted to
a host rodata global whose address would otherwise become a kernel
argument that can never resolve to a device buffer. Reads of such a global
fold to the initializer: directly for constant offsets, as a select chain
over the elements for runtime indices.
Dropped from the union on a compile-only necessity sweep; the GPU suite
needs it: without the fold bilininteg_vecdiffusion_pa's diagonal kernels
take the int table as an operand and the runtime dies with "pointer ...
does not belong to any reactant allocation" ("Vector Diffusion Diagonal
PA", "PA Vector Diffusion"). The union's form of the pass with #3005's
lit test.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
wsmoses
force-pushed
the
pb/const-global-fold
branch
2 times, most recently
from
September 7, 2026 05:27
1656ab3 to
e61dfac
Compare
wsmoses
force-pushed
the
pb/const-global-fold
branch
from
September 7, 2026 15:07
e61dfac to
d6daf46
Compare
mfem's VectorDiffusionIntegrator::AssemblePA keeps a kernel-local
`const int map[9]` that the optimizer promotes to a rodata global; the
raised kernel captured its address as a buffer operand and failed at
runtime ("pointer does not belong to any reactant allocation").
A constant global with a dense initializer is a tensor the module already
holds. llvm.mlir.addressof of one raises to a stablehlo.constant of the
flattened initializer; the pointer2memref view and the loads through it
then take the existing buffer raising unchanged (slices for constant
indices, gathers for runtime ones). A wrapper operand that is such an
address (or a view of it) is cloned into the region the way the index
casts already are, instead of becoming a kernel operand; the global being
constant, nothing in the region can have written through it. A
pointer2memref of a static tensor to a memref<?x..> view sizes the view
statically, so the constant-index load is a plain slice rather than a
dynamic-extent access.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
wsmoses
force-pushed
the
pb/const-global-fold
branch
from
September 7, 2026 15:19
d6daf46 to
68a4a16
Compare
wsmoses
added a commit
that referenced
this pull request
Sep 7, 2026
…ers (#3142) #3005 merged with goldens generated before #3136 removed the identity reshapes and broadcasts from raised kernels; the test fails on main. Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mfem's
VectorDiffusionIntegrator::AssemblePAkeeps a kernel-localconst int map[9] = {0,3,6,1,4,7,2,5,8}that the optimizer promotes to a host.rodataglobal; the raised kernel captured its address as a buffer argument, which compiled fine and failed only at runtime ("pointer does not belong to any reactant allocation" — found via gdbinfo symbolon the failing pointer:__const.<AssemblePA lambda>.map).A constant global with a dense initializer is a tensor the module already holds, so the raiser now reads it as one instead of rewriting the loads:
llvm.mlir.addressofof such a global raises to astablehlo.constantof the (flattened) initializer. Thepointer2memrefview and the loads through it then go through the existing buffer raising unchanged (slices for constant indices, gathers for runtime ones).gpu_wrapper, or the raw pointer with the view inside, which is mfem's shape) is cloned into the region, like the index casts already are, instead of becoming a kernel operand; the global being constant, nothing in the region can have written through it.pointer2memrefof a static tensor to amemref<?x...>view now sizes the view statically instead of reading the dimension back at runtime; without it the constant-index load raises through the dynamic-extent path (get_dimension_size+dynamic_pad+ slice of atensor<?xi32>) instead of a plain slice.Part of #2968.
🤖 Generated with Claude Code
https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD