Skip to content

fix: adapt vgather2 u16 offset carrier#911

Draft
mouliangyu wants to merge 1 commit into
hw-native-sys:mainfrom
mouliangyu:codex/vgather2-u16-offset-carrier
Draft

fix: adapt vgather2 u16 offset carrier#911
mouliangyu wants to merge 1 commit into
hw-native-sys:mainfrom
mouliangyu:codex/vgather2-u16-offset-carrier

Conversation

@mouliangyu

Copy link
Copy Markdown
Contributor

Summary

  • cherry-pick ab3da79 onto main
  • adapt vgather2 lowering so 16-bit results use a half-lane i32 offset carrier
  • apply the same change to both VPTO LLVM emitters

Validation

  • built ptoas with LLVM21 in the main worktree

No focused vgather2 lit exists in main for this exact lowering shape.

@reedhecre

reedhecre commented Jul 7, 2026

Copy link
Copy Markdown

Codex Review

该评论由 review 机器人自动更新。

  • PR: fix: adapt vgather2 u16 offset carrier #911 fix: adapt vgather2 u16 offset carrier
  • Author: mouliangyu
  • Base/Head: main / codex/vgather2-u16-offset-carrier
  • Head SHA: 26822b793511
  • Trigger: PR 有新提交
  • Generated At: 2026-07-08T02:55:41Z
  • Previous Head SHA: e745708a0449
  • Status: failed at codex-review (exit=1)

Summary

Review failed at stage codex-review: exit=1

Findings

未生成结构化 findings,因为 review 过程提前失败。

Log Tail

git fetch origin 'refs/pull/911/head:pr-911' --depth 50
git fetch origin 'main' --depth 50 || true
git checkout -f 'pr-911'
git rev-parse HEAD
git diff --stat 'origin/main...HEAD' || true
Cloning into '/tmp/ptoas-pr-review-monitor/runs/20260708_105527_pr911/repo'...
From https://github.com/hw-native-sys/PTOAS
 * [new ref]           refs/pull/911/head -> pr-911
From https://github.com/hw-native-sys/PTOAS
 * branch              main       -> FETCH_HEAD
Switched to branch 'pr-911'
26822b793511e16546321ac3309b3eceade4fbb1
 lib/PTO/Transforms/VPTOCANN900LLVMEmitter.cpp      | 48 +++++++++++++++++++++-
 lib/PTO/Transforms/VPTOLLVMEmitter.cpp             | 48 +++++++++++++++++++++-
 test/lit/vpto/vgather2_u16_offsets_vpto_llvm.pto   | 27 ++++++++++++
 .../micro-op/gather-scatter/vgather2/compare.py    |  3 +-
 .../micro-op/gather-scatter/vgather2/golden.py     | 14 ++++++-
 .../micro-op/gather-scatter/vgather2/kernel.pto    | 47 ++++++++++++++++++++-
 .../micro-op/gather-scatter/vgather2/launch.cpp    | 14 +++++--
 .../micro-op/gather-scatter/vgather2/main.cpp      | 41 ++++++++++++++++--
 8 files changed, 229 insertions(+), 13 deletions(-)
===== END STAGE clone rc=0 @ 2026-07-08 10:55:33 =====

===== STAGE codex-review @ 2026-07-08 10:55:33 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260708_105527_pr911/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260708_105527_pr911/repo' -s read-only -c 'model_provider="codereview"' -c 'model="gpt-5.4"' -c 'model_reasoning_effort="xhigh"' --output-schema '/tmp/ptoas-pr-review-monitor/runs/20260708_105527_pr911/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260708_105527_pr911/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260708_105527_pr911/review_prompt.txt'
[monitor] stage timeout: 1800s
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260708_105527_pr911/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019f3fa6-f4df-7a61-9caf-29f035d98c0a
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#911 fix: adapt vgather2 u16 offset carrier
作者:mouliangyu
base branch:origin/main
head branch:HEAD(当前已 checkout 到 PR head)

要求:
1. 只审查这个 PR 相对 origin/main 的改动,必要时可以看上下文文件。
2. 重点找真实的 correctness / regression / contract mismatch / CI / runtime / compatibility 问题。
3. 不要提纯风格建议,不要提低价值猜测。
4. 严格按优先级输出:
   - P1:高概率会导致错误结果、编译/运行失败、严重回归、发布阻断
   - P2:重要缺陷、行为回归、遗漏校验/测试、较大兼容性问题
   - P3:次要但明确可改的问题
5. 如果没有问题,summary 直接写:未检查到 PR #911 存在问题,并返回 findings=[]。
6. 如果有问题,summary 简洁概括,findings 里每条都要给出:
   - severity
   - title
   - body(说明为什么是问题,尽量具体)
   - file(尽量给相对路径)
   - line(能确定就填整数,否则 null)

建议先查看:
- git status --short
- git diff --stat origin/main...HEAD
- git diff --unified=80 origin/main...HEAD

最终输出必须严格匹配 JSON schema。

mcp startup: no servers
Reconnecting... 1/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a17bcf8f8ecbd59a-SJC, request id: 1b9411f5-84f7-4e17-98fc-1dd4e74dd9d3)
Reconnecting... 2/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a17bcf921f5a2f21-LAX, request id: c051b623-5fd9-4f3b-b7fa-65166587ff6e)
Reconnecting... 3/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a17bcf967f03cec1-SJC, request id: d10abf27-48a1-4e84-adec-fdaf9a85e8fe)
Reconnecting... 4/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a17bcf9cdfa14b39-SJC, request id: 7574ed54-ebcf-423b-8e28-fd3ffe9ce73c)
Reconnecting... 5/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a17bcfa91d83cf4d-SJC, request id: f62b6116-f3b3-4700-a202-80858aae0470)
ERROR: unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a17bcfbd7e9150a1-SJC, request id: 234a8283-f1ee-4995-992b-cc19926b8472
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260708_105527_pr911/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-07-08 10:55:41 =====

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a helper function getVgather2OffsetsCarrierType and updates LowerVgather2OpPattern in both VPTOCANN900LLVMEmitter.cpp and VPTOLLVMEmitter.cpp to handle offsets carrier types and perform bitcasts when necessary. The review feedback points out a potential issue where the total bitwidth of the input offsetsType is not verified against the expected carrier type bitwidth for 16-bit element types, which could cause LLVM::BitcastOp verification to fail. Additionally, the feedback suggests guarding against *lanes being zero to prevent creating an invalid VectorType with a dimension of 0.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +3688 to +3702
static FailureOr<Type> getVgather2OffsetsCarrierType(PatternRewriter &rewriter,
Type resultType,
Type offsetsType) {
Type elementType = getElementTypeFromVectorLike(resultType);
auto lanes = getElementCountFromVectorLike(resultType);
if (!elementType || !lanes)
return failure();

if (pto::getPTOStorageElemBitWidth(elementType) == 16) {
if (*lanes % 2 != 0)
return failure();
return VectorType::get({*lanes / 2}, rewriter.getI32Type());
}
return offsetsType;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The helper function getVgather2OffsetsCarrierType does not verify that the total bitwidth of the input offsetsType matches the expected bitwidth of the returned carrier type when the element type is 16-bit. If they do not match, the subsequent LLVM::BitcastOp will fail verification because LLVM bitcasts require matching source and destination bitwidths. Additionally, we should defensively guard against *lanes being zero to prevent creating an invalid VectorType with a dimension of 0.

Let's add these checks to ensure robustness and prevent potential compiler crashes.

static FailureOr<Type> getVgather2OffsetsCarrierType(PatternRewriter &rewriter,
                                                     Type resultType,
                                                     Type offsetsType) {
  Type elementType = getElementTypeFromVectorLike(resultType);
  auto lanes = getElementCountFromVectorLike(resultType);
  if (!elementType || !lanes)
    return failure();

  if (pto::getPTOStorageElemBitWidth(elementType) == 16) {
    if (*lanes <= 0 || *lanes % 2 != 0)
      return failure();

    Type offsetsElementType = getElementTypeFromVectorLike(offsetsType);
    auto offsetsLanes = getElementCountFromVectorLike(offsetsType);
    if (!offsetsElementType || !offsetsLanes)
      return failure();

    int64_t totalOffsetsBits = pto::getPTOStorageElemBitWidth(offsetsElementType) * (*offsetsLanes);
    int64_t expectedCarrierBits = *lanes * 16;
    if (totalOffsetsBits != expectedCarrierBits)
      return failure();

    return VectorType::get({*lanes / 2}, rewriter.getI32Type());
  }
  return offsetsType;
}

Comment on lines +3624 to +3638
static FailureOr<Type> getVgather2OffsetsCarrierType(PatternRewriter &rewriter,
Type resultType,
Type offsetsType) {
Type elementType = getElementTypeFromVectorLike(resultType);
auto lanes = getElementCountFromVectorLike(resultType);
if (!elementType || !lanes)
return failure();

if (pto::getPTOStorageElemBitWidth(elementType) == 16) {
if (*lanes % 2 != 0)
return failure();
return VectorType::get({*lanes / 2}, rewriter.getI32Type());
}
return offsetsType;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The helper function getVgather2OffsetsCarrierType does not verify that the total bitwidth of the input offsetsType matches the expected bitwidth of the returned carrier type when the element type is 16-bit. If they do not match, the subsequent LLVM::BitcastOp will fail verification because LLVM bitcasts require matching source and destination bitwidths. Additionally, we should defensively guard against *lanes being zero to prevent creating an invalid VectorType with a dimension of 0.

Let's add these checks to ensure robustness and prevent potential compiler crashes.

static FailureOr<Type> getVgather2OffsetsCarrierType(PatternRewriter &rewriter,
                                                     Type resultType,
                                                     Type offsetsType) {
  Type elementType = getElementTypeFromVectorLike(resultType);
  auto lanes = getElementCountFromVectorLike(resultType);
  if (!elementType || !lanes)
    return failure();

  if (pto::getPTOStorageElemBitWidth(elementType) == 16) {
    if (*lanes <= 0 || *lanes % 2 != 0)
      return failure();

    Type offsetsElementType = getElementTypeFromVectorLike(offsetsType);
    auto offsetsLanes = getElementCountFromVectorLike(offsetsType);
    if (!offsetsElementType || !offsetsLanes)
      return failure();

    int64_t totalOffsetsBits = pto::getPTOStorageElemBitWidth(offsetsElementType) * (*offsetsLanes);
    int64_t expectedCarrierBits = *lanes * 16;
    if (totalOffsetsBits != expectedCarrierBits)
      return failure();

    return VectorType::get({*lanes / 2}, rewriter.getI32Type());
  }
  return offsetsType;
}

@mouliangyu mouliangyu force-pushed the codex/vgather2-u16-offset-carrier branch from 92430a3 to e745708 Compare July 8, 2026 02:03
@mouliangyu

Copy link
Copy Markdown
Contributor Author

Updated in e745708:\n\n- added bitwidth validation before emitting the vgather2 offset carrier bitcast, so incompatible offset vectors fail lowering instead of producing an invalid LLVM bitcast\n- rejected zero-lane result shapes in the carrier helper\n- added focused lit coverage: test/lit/vpto/vgather2_u16_offsets_vpto_llvm.pto\n\nValidation:\n- built ptoas with LLVM21\n- llvm-lit -v build-llvm21/test/lit --filter 'vgather2_u16_offsets_vpto_llvm'

@mouliangyu mouliangyu force-pushed the codex/vgather2-u16-offset-carrier branch from e745708 to 26822b7 Compare July 8, 2026 02:26
@mouliangyu

Copy link
Copy Markdown
Contributor Author

Updated PR #911 with runtime coverage in the existing test/vpto vgather2 case, instead of adding a new standalone case directory.\n\nValidation run:\n- lit: PATH=/home/mouliangyu/projects/github.com/vpto-dev/llvm-project-llvm21/build-shared-21/bin:/usr/local/Ascend/cann-9.0.0/bin:/usr/local/Ascend/cann-9.0.0/tools/ccec_compiler/bin:/usr/local/Ascend/cann-9.0.0/tools/profiler/bin:/usr/local/Ascend/cann-9.0.0/tools/ascend_system_advisor/asys:/usr/local/Ascend/cann-9.0.0/tools/show_kernel_debug_data:/usr/local/Ascend/cann-9.0.0/tools/msobjdump:/home/mouliangyu/env/bin:/home/mouliangyu/.nvm/versions/node/v24.16.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/vendor/x86_64-unknown-linux-musl/codex-path:/home/mouliangyu/.codex/tmp/arg0/codex-arg0RGBgd0:/home/mouliangyu/env/bin:/home/mouliangyu/.vscode-server/data/User/globalStorage/github.copilot-chat/debugCommand:/home/mouliangyu/.vscode-server/data/User/globalStorage/github.copilot-chat/copilotCli:/home/mouliangyu/.vscode-server/cli/servers/Stable-3c631b164c239e7aeaaae7c626b46c527b361af2/server/bin/remote-cli:/home/mouliangyu/env/bin:/home/mouliangyu/.nvm/versions/node/v24.16.0/bin:/home/mouliangyu/miniconda3/bin:/home/mouliangyu/miniconda3/condabin:/home/mouliangyu/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin /home/mouliangyu/projects/github.com/vpto-dev/llvm-project-llvm21/build-shared-21/bin/llvm-lit -v build-llvm21/test/lit --filter 'vgather2_u16_offsets_vpto_llvm'\n- sim: WORK_SPACE=/tmp/pto-vpto-vgather2-u16 CASE_NAME='micro-op/gather-scatter/vgather2' PTOAS_BIN=.../build-llvm21/tools/ptoas/ptoas test/vpto/scripts/run_host_vpto_validation.sh\n\nBoth passed; sim compare now checks both the original f32/i32 path and the new f16/ui16-offset path.

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.

2 participants