bug: f16 writes always fail in the compiled writer on engines without DataView.setFloat16 (React Native / Hermes)

未关闭 适合新手
#3,405 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@dchaudhari7177 已经在做这个了。

开始于 2026年11月20日。

  • #3423 来自 @dchaudhari7177 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

从 compiledIO.ts 开始,该文件中 f16 写入会调用 DataView.setFloat16;然后查看 numeric.ts 中现有的 toHalfBits 转换。将编译后的 writer 的字节输出与 fallback writer 以及可用时的原生 setFloat16 进行比较。完成标准是:无需 setFloat16 也能成功写入,生成匹配的字节,并避免 fallback 警告。

由索引模型根据 Issue 内容生成。

描述

Summary

On engines without DataView.prototype.setFloat16 (Hermes in React Native; also Node 22 and older browsers), every write of data that contains f16 throws inside the compiled writer. TypeGPU then falls back to the slow writer and logs a "this is likely a bug" warning on every call.

Repro

Node 24, with setFloat16 removed to mimic Hermes:

import { d } from 'typegpu';
import { writeToArrayBuffer } from './src/data/dataIO.ts';

delete (DataView.prototype as any).setFloat16;

const schema = d.arrayOf(d.f16, 100_000);
const data = Array.from({ length: 100_000 }, (_, i) => i * 0.001);
writeToArrayBuffer(new ArrayBuffer(d.sizeOf(schema)), schema, data);

Output, repeated on every write:

⚠️ [fallback] Error when using compiled writer for data type 'array' (unnamed) - this is likely a bug, please submit an issue at https://github.com/software-mansion/TypeGPU/issues
Using fallback writer instead. TypeError: output.setFloat16 is not a function

Impact

  • Node 24, arrayOf(f16, 100k): ~0.12 ms with native setFloat16 vs ~1.75 ms without it, plus one warning per write.
  • iPhone (react-native-webgpu 0.22, Hermes), mnist-inference example: uploading the weights takes 320 ms; with the fix below it takes 155 ms.
  • #3383 adds mat*h schemas that go through the same setFloat16 path, so they would be affected too.

Cause

compiledIO.ts maps f16 to setFloat16 without checking that the method exists. The writer is built fine and throws only at write time, so the failure repeats on every call.

Possible fix

Feature-detect once. When setFloat16 is missing, emit:

output.setUint16(offset, toHalfBits(v), littleEndian);

toHalfBits already exists in numeric.ts. Optionally, add a one-loop fast path for arrayOf(f16).

I have a local version with tests (bytes match both the fallback writer and native setFloat16) if that helps.

主要语言
TypeScript
星标
3.4k
派生
151
平均合并
3 天 8 小时
30 天内合并 PR
55

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

software-mansion/TypeGPU 的其他 Issue

查看 software-mansion/TypeGPU 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。