SIGN IN SIGN UP

Qualcomm AI Engine Direct - Adding QNN backend support for _pdist_forward core ATen op (#20892)

### Summary
Added support for `aten.pdist` and `aten._pdist_forward` ops for the QNN
backend via a decomposition pass.

`torch.pdist(x, p=2)` computes pairwise Euclidean distances between all
rows of a 2D input tensor `[N, M]`, returning a condensed 1D vector of
length `N*(N-1)/2`.

__Decomposition (p=2 only):__

Precomputes upper-triangle row/column index pairs at decomposition time,
then uses `index_select` to extract only the `N*(N-1)/2` pairs that
contribute to the output — avoiding the full `[N, N, M]` broadcast:

1. Precompute `rows`, `cols` index tensors for upper-triangle pairs `(i,
j)` where `i < j`
2. `index_select(x, 0, rows)` - `index_select(x, 0, cols)` → pairwise
differences `[N*(N-1)/2, M]`
3. `pow(2)` → square differences
4. `sum(dim=-1)` → sum over features → `[N*(N-1)/2]`
5. `sqrt` → Euclidean distances `[N*(N-1)/2]`

The index buffers are registered with node-unique names
(`_pdist_rows_{node.name}`, `_pdist_cols_{node.name}`) to avoid
collisions when multiple `pdist` ops exist in the same graph.

Note that only `p=2` is supported, similar to the existing
`DecomposeCDist` constraint. Static shapes are required for precomputing
the index pairs at decomposition time.

Also added a docstring to `DecomposeCDist` to better explain how that
decomposition works.

### Test plan
```
python backends/qualcomm/tests/test_qnn_delegate.py TestQNNQuantizedOperator.test_qnn_backend_pdist_forward --soc_model SM8750 --host aisw-vm15-labsd --device 545ee4aa --build_folder build-android

python backends/qualcomm/tests/test_qnn_delegate.py TestQNNFloatingPointOperator.test_qnn_backend_pdist_forward --soc_model SM8750 --host aisw-vm15-labsd --device 545ee4aa --build_folder build-android


python backends/qualcomm/tests/test_qnn_delegate.py TestQNNQuantizedOperator.test_qnn_backend_pdist --soc_model SM8750 --host aisw-vm15-labsd --device 545ee4aa --build_folder build-android

python backends/qualcomm/tests/test_qnn_delegate.py TestQNNFloatingPointOperator.test_qnn_backend_pdist --soc_model SM8750 --host aisw-vm15-labsd --device 545ee4aa --build_folder build-android
```
Q
qti-horodnic committed
497b0d937e3e2469292535362ef2f455c588df7a
Parent: 46fdc13
Committed by GitHub <noreply@github.com> on 7/28/2026, 11:31:11 PM