Skip to content

[XLA] Use logical dimensions in dynamic CPU kernels - #61

Open
stevenvar wants to merge 2 commits into
for-serving-2.20from
steven.cpu-logical-dynamic-dimensions
Open

[XLA] Use logical dimensions in dynamic CPU kernels#61
stevenvar wants to merge 2 commits into
for-serving-2.20from
steven.cpu-logical-dynamic-dimensions

Conversation

@stevenvar

@stevenvar stevenvar commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Dynamic CPU execution reserves storage using padded shape bounds, but convolution and dot kernels can use those bounds as their computation sizes. This makes them process padded elements instead of stopping at the logical runtime dimensions.

This change evaluates symbolic dimensions from the runtime dynamic value. Convolution uses the logical batch size, while dot uses the logical matrix and batch dimensions for both computation and buffer strides. Allocation bounds still reserve enough capacity, while runtime matrices remain packed contiguously. For example, a runtime batch of 2 in storage sized for 4 computes two batches and leaves the remaining output storage untouched.

The convolution-to-dot rewrite also preserves flattened dimension expressions, so a 1x1 convolution keeps the same runtime dimensions after optimization.

Tests

  • ConvolutionThunkTest.UsesLogicalDynamicBatch: computes a logical batch of 2 within a bound of 4 and checks that padded output elements remain untouched.
  • DotThunkTest.UsesLogicalDynamicDimension: checks the same behavior for a dot operation with a symbolic matrix dimension.
  • DotThunkDynamicStrideTest.UsesLogicalMatrixStrides: checks dynamic m, n, and k in both row-major and column-major layouts. Each case reuses one thunk at runtime sizes 2, 4, then 1, verifies distinct results for both batches, and checks that spare output storage remains untouched.
  • AlgebraicSimplifierTest.ConvertDynamicConvToMatmulPreservesFlattenedExpression: checks that converting a 1x1 convolution to a dot preserves the flattened expression and evaluates it correctly for a different runtime batch.

Validation

All 24 tests in @local_xla//xla/backends/cpu/runtime:dot_thunk_test pass locally on macOS with cached test results disabled. The six dynamic stride cases were also run before the stride fix and all failed, confirming that they catch the incorrect offsets.

Evaluate symbolic convolution and dot dimensions from the runtime root while retaining padded storage bounds. Preserve flattened expressions when 1x1 convolutions are rewritten to dots so optimized CPU execution does not process padded elements.
Match the packed runtime layout used by generated indexing and the existing Eigen matmul path. Test dynamic matrix dimensions in both layouts, including thunk reuse across changing sizes and untouched spare capacity.
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.

1 participant