Repository navigation
Expand C API with conv2d/softmax/layer_norm/gelu/silu/reshape/transpose and add a C/CMake example - #12
Merged
Conversation
…anspose and a C/CMake example
- c_api.rs / oxideon.h: oxideon_tensor_{gelu,silu,softmax,reshape,transpose,
layer_norm,conv2d}; weight/bias arguments are optional (NULL). Errors are
reported through oxideon_last_error_message like the existing ops.
- tests: results checked against hand-computed values, plus null pointers,
bad axes/shapes and wrong-rank input returning NULL instead of panicking
- examples/c_embed: minimal C project + CMakeLists.txt that builds the
`oxideon` cdylib with cargo and links it (conv2d -> layer_norm -> gelu ->
softmax)
Safetensors loading and CUDA device selection from the issue are left for
follow-ups.
Refs voidstackloop#5
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #5 (covers the tensor-ops bullet and the
examples/c_embed/CMake bullet; weight I/O and CUDA selection are left for follow-ups)What
New
extern "C"functions incrates/oxideon-core/src/c_api.rs, declared ininclude/oxideon.h:oxideon_tensor_gelu,oxideon_tensor_siluoxideon_tensor_softmax(x, axis)oxideon_tensor_reshape(x, shape, ndim)oxideon_tensor_transpose(x, dim0, dim1)oxideon_tensor_layer_norm(x, normalized_shape, ndim, weight, bias, eps)weight/biasmay be NULLoxideon_tensor_conv2d(input, weight, bias, stride_h/w, pad_h/w, dilation_h/w)biasmay be NULLThey follow the existing conventions: NULL checks, the panic
guard, and errors reported throughoxideon_last_error_message()with a NULL return.examples/c_embed/is a small C program plus aCMakeLists.txt. The CMake file builds theoxideonfacade crate (already acdylib, which exports the C symbols) with cargo, links it, and copies the DLL next to the executable on Windows or sets the rpath elsewhere. The program runs conv2d -> layer_norm -> GELU -> softmax.Tests
c_api: activations / softmax / layer_norm (with and without weight and bias), reshape / transpose, and conv2d (bias, no bias, padding). They compare against hand-computed values and also cover NULL pointers, bad axes, mismatched shapes and wrong-rank input.cargo test -p oxideon-core --lib c_apipasses (5 tests) andcargo clippy -p oxideon-core --all-targets -- -D warningsis clean.cmake -S examples/c_embed -B ..., then--build --config Release). It links against the cdylib and prints softmax rows that sum to 1. I have not run it on Linux or macOS, so theBUILD_RPATHbranch is untested.🤖 Generated with Claude Code