Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of jsmn dependency #2

Merged
merged 8 commits into from
Jan 8, 2024
Merged

Get rid of jsmn dependency #2

merged 8 commits into from
Jan 8, 2024

Conversation

zeux
Copy link
Owner

@zeux zeux commented Jan 8, 2024

We actually really only need ~75 lines to parse JSON ourselves, so let's go ahead and do that. This removes the last dependency from this code, apart from CUDA which we treat as a "platform" (similar to libc).

To simplify parsing code and edge conditions, copy the string to a null
terminated buffer. This means tensors_open now allocates (when
successfull), but this reduces the overall footprint as we no longer
need to pad the strings to 64 bytes.
We no longer need it as we use a custom JSON parser.
One of these requires a manual copy to int array but otherwise they are
easily shareable. As a side-effect we will parse data_offsets with just
one field, but that will fail to validate because end will be 0.
We don't really need json_string and json_key; also, parsing objects can
be slightly more concise.
On second thought, we don't actually need to malloc here. COW mapping
doesn't really seem to have an obvious downside that should make us
reject its viability here.
For consistency, 's' is now called 'json' everywhere.

Metadata parsing is now performed by parse_metadata function, which removes
"nested" structure parsing from tensor_parse, making it cleaner.
We let the loop break on its own which saves a little bit of flow.
We no longer use jsmn :) CUDA is considered a platform dependency.
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.

1 participant