# gpujson

General purpose GPU JSON parsing

This project parses JSON entirely on the GPU via wgpu compute shaders. The parser decomposes JSON parsing into a pipeline of parallel prefix scans, producing a flat tape of structural characters

This is purely for research into reducing JSON parsing into what Raph Levien calls invitingly parallel problems

# Usage

As a library:

```rust
let parser = gpujson::Parser::try_new()?;
let json = r#"{"foo":"bar"}"#;
let tape = parser.parse_str(json)?;

for entry in &tape {
    println!("{:?}: {:?}", entry.token_kind(), entry.source(json.as_bytes()));
}
```

`Parser::parse_str` and `Parser::parse_bytes` return the GPU-produced tape. The tape stores token byte spans, so callers can index back into the original JSON bytes without scalar parsing on the CPU.

The current shader pipeline supports inputs up to 256 bytes.

As a CLI:

```sh
cargo r --release testdata/small.json
```

# Reading

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