Skip to content

Expand C API with conv2d/softmax/layer_norm/gelu/silu/reshape/transpose and add a C/CMake example - #12

Merged
voidstackloop merged 1 commit into
voidstackloop:mainfrom
emreocell:feat/c-api-ops
Nov 24, 2026
Merged

voidstackloop merged 1 commit into
voidstackloop:mainfrom
emreocell:feat/c-api-ops

Conversation

@emreocell

Copy link
Copy Markdown
Contributor

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 in crates/oxideon-core/src/c_api.rs, declared in include/oxideon.h:

Function Notes
oxideon_tensor_gelu, oxideon_tensor_silu elementwise
oxideon_tensor_softmax(x, axis) negative axes allowed
oxideon_tensor_reshape(x, shape, ndim)
oxideon_tensor_transpose(x, dim0, dim1) negative dims allowed
oxideon_tensor_layer_norm(x, normalized_shape, ndim, weight, bias, eps) weight / bias may be NULL
oxideon_tensor_conv2d(input, weight, bias, stride_h/w, pad_h/w, dilation_h/w) bias may be NULL

They follow the existing conventions: NULL checks, the panic guard, and errors reported through oxideon_last_error_message() with a NULL return.

examples/c_embed/ is a small C program plus a CMakeLists.txt. The CMake file builds the oxideon facade crate (already a cdylib, 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

  • Three new unit tests in 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_api passes (5 tests) and cargo clippy -p oxideon-core --all-targets -- -D warnings is clean.
  • I configured, built and ran the example with CMake and MSVC on Windows (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 the BUILD_RPATH branch is untested.

🤖 Generated with Claude Code

…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>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 15:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@voidstackloop
voidstackloop merged commit 7ff068e into voidstackloop:main Nov 24, 2026
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.

3 participants