使用计算着色器在GPU上进行并行JSON解析

Lobsters Hottest 工具

摘要

slurpjson是一个Rust库,它完全在GPU上使用wgpu计算着色器解析JSON,将解析过程分解为并行前缀扫描,用于研究目的。

<p><a href="https://lobste.rs/s/nhixqy/parallel_json_parsing_on_gpu_with_compute">评论</a></p>
查看原文
查看缓存全文

缓存时间: 2026/07/28 16:27

friendlymatthew/slurpjson 源码:https://github.com/friendlymatthew/slurpjson

slurpjson

本项目通过 wgpu 计算着色器在 GPU 上完整解析 JSON。解析器将 JSON 解析分解为一系列并行前缀扫描的流水线,生成扁平的结构字符磁带。

此项目纯属研究性质,旨在探索如何将 JSON 解析归约为 Raph Levien 所称的“易于并行的难题”。

用法

fn main() {
    let json = r#"
    {
        "foo": "bar",
        "baz": {
            "wef": [1, 2, 3],
            "yearn": {
                "1": 2,
                "2": 3.0
            }
        }
    }
    "#;
    let parser = slurpjson::Parser::try_new()?;
    let tape = parser.parse_str(&json)?;
    let document = slurpjson::Document::new(json.as_bytes(), &tape);
    dbg!(document);
}

参考资料

https://raphlinus.github.io/gpu/2020/09/05/stack-monoid.html
https://raphlinus.github.io/personal/2018/05/10/toward-gpu-json-parsing.html

相似文章

在 Python 中以每秒数十 GB 的速度解析 JSON

Lobsters Hottest

Daniel Lemire 演示了如何在无 GIL 的 Python 3.14 中,使用 fastsimdjson 的 map_many 多线程与惰性解析,在数秒内解析 7.6 GB 的 GH Archive JSON 数据,性能远超标准库 json、orjson 与 msgspec。

Rust 中的 GPU 卸载:可移植、安全且快速

Hacker News Top

本文介绍了一种零开销、多厂商的 GPU 编译框架,该框架内置于 Rust 编译器中,利用 Rust 的所有权模型确保内存安全,并实现与原生 CUDA 和 HIP 基准相媲美的性能。

Rust SIMD on the GPU

Hacker News Top

VectorWare announces that Rust's portable SIMD (core::simd) now works on the GPU, mapping SIMD vectors to warp lanes and enabling familiar Rust abstractions for GPU programming.