Skip to content

fp8 math/packed store#917

Open
and0d0 wants to merge 3 commits into
hw-native-sys:mainfrom
and0d0:489-fp8-math-max-reduce
Open

fp8 math/packed store#917
and0d0 wants to merge 3 commits into
hw-native-sys:mainfrom
and0d0:489-fp8-math-max-reduce

Conversation

@and0d0

@and0d0 and0d0 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

TODO:

  • 真机测试中 - 测试通过,正确性也测试通过
  • 文档 & 测试整理

新增实现

  • fp8 packed store(fp8x2), 再看看(fp8x4,fp8x8)

与需求相关 - 确认的项目:

  • max_reduce 已有
  • math 相关函数(abs/abs, max/min 已有语义接口不新增alias,exp/log/pow本身已有同名接口)
  • float2 -> fp8x2 已有相关接口,可直接使用已有接口组合实现功能

其他:

  • 删除alias的修改(完成)

@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 adds support for packed float8x2 types in the PTO compiler and PTODSL, renames pto.vec to pto.Vec (using size instead of lanes), introduces SIMT scalar math aliases, and extends pto.simt_allreduce to support 32-bit integers. It also enforces that alloc_buffer is used only within SIMT subkernels and updates stg to support exact vector payloads. The review feedback highlights two critical safety issues: potential AttributeError crashes when handling raw Python scalars in stg within ptodsl/_ops.py, and a double-fault risk in _validate_scratch_buffer within ptodsl/_allreduce.py if the scratch object lacks a type attribute.

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 thread ptodsl/ptodsl/_ops.py
Comment on lines +5196 to +5205
raw_value = unwrap_surface_value(value)
if raw_value.type == elem_type:
stored_value = raw_value
elif VectorType.isinstance(elem_type):
raise TypeError(
f"stg(value, ...) vector value type must match destination element type: "
f"got {raw_value.type}, expected {elem_type}"
)
else:
stored_value = coerce_scalar_to_type(value, elem_type, context="stg(value, ...)")

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.

critical

If value is a raw Python scalar (such as a float or int), unwrap_surface_value(value) returns the raw scalar itself, which does not have a type attribute. Accessing raw_value.type directly on line 5197 will raise an AttributeError. We should check hasattr(raw_value, "type") before accessing raw_value.type to avoid crashing on raw Python scalars.

    raw_value = unwrap_surface_value(value)
    if hasattr(raw_value, "type") and raw_value.type == elem_type:
        stored_value = raw_value
    elif VectorType.isinstance(elem_type):
        got_type = getattr(raw_value, "type", type(raw_value))
        raise TypeError(
            f"stg(value, ...) vector value type must match destination element type: "
            f"got {got_type}, expected {elem_type}"
        )
    else:
        stored_value = coerce_scalar_to_type(value, elem_type, context="stg(value, ...)")

Comment on lines +45 to +49
raw_scratch = unwrap_surface_value(scratch)
try:
scratch_type = _pto.PtrType(raw_scratch.type)
except Exception as exc:
raise TypeError(f"{context} requires a UB scratch buffer pointer, got {raw_scratch.type}") from exc

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

If raw_scratch does not have a type attribute (e.g., if it is a raw Python object or not a wrapped MLIR Value), accessing raw_scratch.type in the except block will raise an AttributeError. This causes a double-fault and masks the original exception. We should check hasattr(raw_scratch, "type") first to safely handle this case.

    raw_scratch = unwrap_surface_value(scratch)
    if not hasattr(raw_scratch, "type"):
        raise TypeError(f"{context} requires a UB scratch buffer pointer, got {raw_scratch}")
    try:
        scratch_type = _pto.PtrType(raw_scratch.type)
    except Exception as exc:
        raise TypeError(f"{context} requires a UB scratch buffer pointer, got {raw_scratch.type}") from exc

@reedhecre

reedhecre commented Jul 9, 2026

Copy link
Copy Markdown

Codex Review

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

  • PR: fp8 math/packed store #917 fp8 math/packed store
  • Author: and0d0
  • Base/Head: main / 489-fp8-math-max-reduce
  • Head SHA: 292260f5a8c2
  • Trigger: PR 有新提交
  • Generated At: 2026-07-10T10:50:43Z
  • Previous Head SHA: 4ce12edbb797
  • Status: failed at codex-review (exit=1)

Summary

Review failed at stage codex-review: exit=1

Findings

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

Log Tail

git fetch origin 'main' --depth 50 || true
git checkout -f 'pr-917'
git rev-parse HEAD
git diff --stat 'origin/main...HEAD' || true
Cloning into '/tmp/ptoas-pr-review-monitor/runs/20260710_185027_pr917/repo'...
From https://github.com/hw-native-sys/PTOAS
 * [new ref]           refs/pull/917/head -> pr-917
From https://github.com/hw-native-sys/PTOAS
 * branch              main       -> FETCH_HEAD
Switched to branch 'pr-917'
292260f5a8c2701437656988a5c1f6bf9be1dac7
 include/PTO/IR/PTOTypeUtils.h                      |  4 ++
 lib/PTO/IR/PTOTypeUtils.cpp                        | 21 +++++++++
 lib/PTO/IR/VPTO.cpp                                |  5 +-
 lib/PTO/Transforms/VPTOCANN900LLVMEmitter.cpp      | 43 +++++++++++++++++
 lib/PTO/Transforms/VPTOLLVMEmitter.cpp             | 43 +++++++++++++++++
 ptodsl/ptodsl/_ops.py                              | 13 +++++-
 ptodsl/ptodsl/_types.py                            | 17 ++++++-
 ptodsl/tests/test_jit_compile.py                   | 40 ++++++++++++++++
 .../simt_lowlevel_fp8_packed_ldg_stg_vpto_llvm.pto | 54 ++++++++++++++++++++++
 9 files changed, 235 insertions(+), 5 deletions(-)
===== END STAGE clone rc=0 @ 2026-07-10 18:50:35 =====

===== STAGE codex-review @ 2026-07-10 18:50:35 =====
set -euo pipefail
cd '/tmp/ptoas-pr-review-monitor/runs/20260710_185027_pr917/repo'
'codex' exec -C '/tmp/ptoas-pr-review-monitor/runs/20260710_185027_pr917/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/20260710_185027_pr917/review_schema.json' -o '/tmp/ptoas-pr-review-monitor/runs/20260710_185027_pr917/codex_last_message.json' --color never - < '/tmp/ptoas-pr-review-monitor/runs/20260710_185027_pr917/review_prompt.txt'
[monitor] stage timeout: 1800s
OpenAI Codex v0.115.0 (research preview)
--------
workdir: /tmp/ptoas-pr-review-monitor/runs/20260710_185027_pr917/repo
model: gpt-5.4
provider: codereview
approval: never
sandbox: read-only
reasoning effort: xhigh
reasoning summaries: none
session id: 019f4ba6-93af-7082-8721-07a3a2e2090b
--------
user
你现在在审查 GitHub PR。

仓库:hw-native-sys/PTOAS
PR:#917 fp8 math/packed store
作者:and0d0
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 #917 存在问题,并返回 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: a18f0227783c5d22-LAS, request id: 6235381e-2fb8-4075-b11e-d0d84d079222)
Reconnecting... 2/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18f022a4f992b7b-LAX, request id: 2981e24d-a360-4a3b-aba3-36d5df572947)
Reconnecting... 3/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18f022e590c4320-LAS, request id: 85c2b23f-48c0-43a8-8e4b-175bca21615e)
Reconnecting... 4/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18f02352851d7cc-LAX, request id: 59bfbc67-2112-4bbd-a02e-037c183b5c24)
Reconnecting... 5/5 (unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18f02408814da94-LAS, request id: b8bee77d-097c-44fa-b54f-d28280765fed)
ERROR: unexpected status 403 Forbidden: {"code":"INSUFFICIENT_BALANCE","message":"Insufficient account balance"}, url: https://codex.0u0o.com/responses, cf-ray: a18f0256bf9972e0-LAX, request id: c3da0fe2-76db-47c8-9320-38b0da3e2b7f
Warning: no last agent message; wrote empty content to /tmp/ptoas-pr-review-monitor/runs/20260710_185027_pr917/codex_last_message.json
===== END STAGE codex-review rc=1 @ 2026-07-10 18:50:43 =====

@and0d0 and0d0 force-pushed the 489-fp8-math-max-reduce branch from 0bcbaee to 8d1629a Compare July 9, 2026 02:41
@and0d0 and0d0 force-pushed the 489-fp8-math-max-reduce branch 3 times, most recently from 9a99940 to f3bd1cb Compare July 9, 2026 07:15
@and0d0 and0d0 force-pushed the 489-fp8-math-max-reduce branch from 4ce12ed to 292260f Compare July 10, 2026 10:45
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