Skip to content

[Code scan] SE-A tabulation dereferences em_x[-1] when nnei == 0 #5892

Description

@njzjz-bot

This issue comes from a focused review of tabulation at commit 21b73ab303581f467bba0cae101a880c35cc2d82.

Problem

The SE-A GPU kernels assume at least one neighbor and read the last em_x element before processing the neighbor loop:

When nloc > 0 and nnei == 0, each address is em_x[-1]. The wrappers guard only nloc <= 0, so they still launch these kernels for empty-neighbor tensors.

The CPU implementations mirror the same assumption by evaluating em_x[ii * nnei + nnei - 1] before their loops.

Impact

Shapes such as em_x=[nloc, 0] and em=[nloc, 0, 4] are representable by the TensorFlow and PyTorch wrappers. They can trigger an invalid pointer read, a CUDA/HIP illegal-address error, or undefined output. A simple early return is not sufficient for forward because some wrappers allocate the descriptor with empty; the mathematically correct empty reduction must be initialized to zero.

Validation note

The source-level out-of-bounds access is deterministic from the index expression. A bare CUDA probe on an NVIDIA GeForce RTX 5090 did not surface a driver error, and CUDA 12.4 compute-sanitizer on this system reports Error: Device not supported. for that GPU, so there is no sanitizer trace attached.

Suggested fix

Handle nnei <= 0 explicitly in CPU and GPU entry points:

  • zero the forward descriptor and return;
  • leave/initialize first- and second-order gradient outputs to zero and return;
  • add CPU and GPU tests for nloc > 0, nnei == 0.

Coding agent: Codex
Codex version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning effort: xhigh

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions