Skip to content

[GPU] Fix select-kernel indexing mismatch for lower-rank inputs#34537

Open
davidsnam-intel wants to merge 1 commit intoopenvinotoolkit:masterfrom
davidsnam-intel:david/fix-select-op-dynamic
Open

[GPU] Fix select-kernel indexing mismatch for lower-rank inputs#34537
davidsnam-intel wants to merge 1 commit intoopenvinotoolkit:masterfrom
davidsnam-intel:david/fix-select-op-dynamic

Conversation

@davidsnam-intel
Copy link
Contributor

@davidsnam-intel davidsnam-intel commented Mar 6, 2026

Issue

Building the Select kernel can be failed when NUMPY broadcasting is used with lower-rank inputs, particularly in the dynamic / new shape inference path.

cond: [256,256]
then: [1]
else: [?,64,?,256,256]

Under NUMPY broadcasting semantics this should behave as:

cond → [1,1,1,256,256]
then → [1,1,1,1,1]
else → [?,64,?,256,256]

However, some inputs may remain lower-rank during kernel JIT generation. This can lead to mismatched macro signatures in the generated OpenCL kernel, resulting in build failures such as:

error: too many arguments provided to function-like macro invocation
error: use of undeclared identifier 'INPUT0_GET_INDEX_SAFE'

Root cause

In the dynamic/new-shape-infer path, Select input layouts are not fully canonicalized to the output rank before kernel JIT generation.

As a result:

  • the Select kernel may assume 5D indexing
  • while the generated INPUT*_GET_INDEX_SAFE macros correspond to lower-rank inputs

This mismatch leads to macro argument inconsistencies during OpenCL kernel compilation.

Solution

This PR fixes the issue in two steps:

  1. Canonicalize Select input layouts

    • In the Select impl, input shapes are extended to a consistent rank based on the output rank:
      target_rank = max(4, output_rank)
    • Shapes are extended using extend_shape_to_rank_from_begin() and layouts are adjusted with format::adjust_to_rank().
  2. Simplify Select kernel indexing

    • After canonicalization, the Select kernel always uses consistent 5D indexing when OUTPUT_DIMS == 5.
    • This ensures that kernel indexing and generated GET_INDEX_SAFE macros follow the same rank contract.

Graphs

image

Tickets

@davidsnam-intel davidsnam-intel requested review from a team as code owners March 6, 2026 10:27
@github-actions github-actions bot added the category: GPU OpenVINO GPU plugin label Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: GPU OpenVINO GPU plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant