Skip to content

fix(gather_v2/view_copy): convert element offsets to byte displacements for MGATHER/MSCATTER - #134

Open
wangyuascend-spec wants to merge 1 commit into
mainfrom
fix/gather-view-byte-offsets
Open

wangyuascend-spec wants to merge 1 commit into
mainfrom
fix/gather-view-byte-offsets

Conversation

@wangyuascend-spec

Copy link
Copy Markdown
Collaborator

Summary

MGATHER/MSCATTER take byte displacements from the base pointer (PTO v0.58.4: "each element is a signed/unsigned byte displacement. Do not scale by the transfer element width" — confirmed from gfrun ExecuteMGATHER/ExecuteMSCATTER). Both kernels were accumulating offsets in element units and passing them directly, silently reading/writing at 1/sizeof(DType) of the intended position for fp16/fp32 data.

  • gather_v2: scale index_offset by sizeof(IType) before the index-tile MGATHER, and scale the accumulated input_offset_tile by sizeof(DType) before the final data MGATHER.
  • view_copy: scale both input_offset_tile and output_offset_tile by sizeof(DType) before MGATHER/MSCATTER.

Evidence that offsets are bytes (not elements):

  1. gfrun ExecuteMGATHER comment: "byte displacement. Do not scale by the transfer element width"
  2. TileOP in-tree validated users (hashtable_lookup_simd.hpp:175, microbenchmark mgather_fp32) all multiply by sizeof
  3. Pre-fix: all 6 ELFs fail embedded oracle (R2=1). Post-fix: all 6 pass (R2=0).

Validation

Base: main@64d2d77 (includes merged PR #133)

Case Pre-fix Post-fix
gather_v2 rank1 fp32 R2=1 R2=0
gather_v2 rank2 half R2=1 R2=0
gather_v2 rank2 int32 R2=1 R2=0
view_copy half ×2 R2=1 R2=0
view_copy int32 R2=1 R2=0

gfrun 4PE, embedded oracle (host reference + tolerance in main), rc=0, Reach the End of Benchmark for all runs.

…ts for MGATHER/MSCATTER

MGATHER/MSCATTER take byte displacements from the base pointer (PTO
v0.58.4: "each element is a signed/unsigned byte displacement. Do not
scale by the transfer element width" — confirmed from gfrun
ExecuteMGATHER/ExecuteMSCATTER). Both kernels were accumulating offsets
in element units and passing them directly, silently reading/writing
at 1/sizeof(DType) of the intended position for fp16/fp32 data.

gather_v2: scale index_offset by sizeof(IType) before the index-tile
MGATHER, and scale the accumulated input_offset_tile by sizeof(DType)
before the final data MGATHER.

view_copy: scale both input_offset_tile and output_offset_tile by
sizeof(DType) before MGATHER/MSCATTER.

Validation (gfrun 4PE, embedded oracle, R2):
- gather_v2 rank1 fp32, rank2 half, rank2 int32: R2=1→0 (all PASS)
- view_copy half×2, int32: R2=1→0 (all PASS)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ca0815bfb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +155 to +156
TMULS(input_offset_tile, input_offset_tile,
static_cast<std::uint32_t>(sizeof(DType)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject gathers whose byte offsets exceed uint32

When the input occupies more than 4 GiB, this multiplication wraps because input_offset_tile is a uint32_t tile. For example, a rank-1 float gather with 1,073,741,825 input elements maps the final element's displacement to zero, silently reading the first element instead. The API currently permits that InputElements value and documents no size restriction, so add a representability check or use a wider offset tile; the index-buffer scaling above needs the equivalent protection.

Useful? React with 👍 / 👎.

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