cli/testfloat_expr_cli 教程
本教程介绍如何用二进制运行器执行 Berkeley TestFloat 向量文件。该运行器通过 floating-conformance --backend testfloat 调用;下文以 testfloat 简称这条命令。
| 我想要 | 使用 |
|---|---|
| 运行一个生成的向量文件 | testfloat --function … FILE |
与 testfloat_gen 的选项保持一致 | --rounding, --tininess, --exact |
| 把大文件拆分到多个进程 | --shard-count, --shard-index |
| 获取机器可读的输出 | --json |
| 从 MoonBit 调用运行器 | @testfloat_expr_cli.run |
| 运行完整的 TestFloat 矩阵 | just conformance run binary |
快速入门
该可执行文件需从仓库的检出副本用 just conformance build binary 构建。
用 TestFloat 的 testfloat_gen 生成向量并运行它们。just conformance fetch binary 下载固定版本的 SoftFloat 和 TestFloat 源码;just conformance run binary 用这些源码把 testfloat_gen 构建到 .tmp/binary-conformance/vendor/TestFloat-3e/build/Linux-x86_64-GCC/ 中。
testfloat_gen -level 1 -rnear_even -tininessafter f64_mul > f64_mul.tv
testfloat --function f64_mul --rounding rnear_even --tininess after f64_mul.tv
TestFloat execution summary
function: f64_mul
rounding: rnear_even
tininess: after
cases: …
selected cases: …
passed cases: …
failed cases: 0
从 MoonBit 代码调用
运行器同时也是一个库。该包属于工具模块 Luna-Flow/floating-tools(仓库中的 tooling/ 目录,与库同版本),而不属于已发布的库。请把你的代码写成本工作区中的一个包;工具模块发布后,也可以运行 moon add Luna-Flow/floating-tools@0.11.0。 在 moon.pkg 中导入 "Luna-Flow/floating-tools/cli/testfloat_expr_cli",并用相同的参数调用 run:
///|
test "run the TestFloat runner from MoonBit code" {
let status = @testfloat_expr_cli.run([
"testfloat", "--function", "f16_add", "--rounding", "rnear_even", "--tininess",
"after", "../testdata/binary/smoke/f16_add_rnear_even_after.testfloat",
])
inspect(status, content="0")
}
just docs 在模块目录 tooling/ 中运行本页的测试,所以语料路径以 ../testdata 开头;在你自己的代码中请使用你自己的路径。
日常任务
与生成器选项保持一致
传入与生成器相同的函数、舍入模式和微小性(tininess)判定方式;若向量是用 -exact 生成的,还要加上 --exact:
testfloat_gen -rminMag -exact f32_roundToInt > r.tv
testfloat --function f32_roundToInt --rounding rminMag --exact r.tv
对大文件分片
testfloat --function f128_mulAdd --shard-count 8 --shard-index 3 --json big.tv
分片 i 运行索引对分片数取模等于 i 的向量。
供脚本使用的 JSON
--json 打印 function、rounding、tininess、exact、totalCases、selectedCases、passedCases、failedCases 和 failedIds(FUNCTION:LINE)。
深入了解
just conformance run binary --level 1 --tininess after --tininess before规划完整矩阵,将testfloat_gen的输出分块流式写入临时文件,对每一块运行此运行器,并把基于行号的 id 重新映射为全局向量编号。- testfloat_expr 教程 解释了通过规则。
常见陷阱
- 只能有一个文件。 第二个路径会报错。
- 舍入模式默认为
rnear_even。 务必传入生成器所用的模式。 - id 是所传文件中的行号。 将数据流拆分为块时,需要自行记录偏移量。