oxiblas-ffi
C FFI bindings for OxiBLAS - Drop-in replacement for BLAS/LAPACK libraries
Overview
oxiblas-ffi provides C-compatible FFI bindings for OxiBLAS, allowing it to be used as a drop-in replacement for OpenBLAS, Intel MKL, or other BLAS/LAPACK libraries in C/C++/Fortran code.
Features
- Complete BLAS API (Level 1, 2, 3) with C bindings
- LAPACK subset for common decompositions (LU, QR, SVD, Cholesky)
- Drop-in replacement for existing BLAS/LAPACK libraries
- No runtime dependencies - single static or dynamic library
- Pure Rust implementation with C-compatible ABI
Installation
Building the Library
# Build static library
# Produces: target/release/liboxiblas_ffi.a
# Build dynamic library
# Produces: target/release/liboxiblas_ffi.{so,dylib,dll}
Using from C/C++
# Link with OxiBLAS (static)
# Link with OxiBLAS (dynamic)
Drop-in Replacement
Replace OpenBLAS or MKL:
# Before (with OpenBLAS)
# After (with OxiBLAS)
C API
BLAS Level 1
// Dot product
double ;
float ;
// AXPY: y = alpha*x + y
void ;
void ;
// Scale: x = alpha*x
void ;
void ;
// Euclidean norm
double ;
float ;
BLAS Level 2
// GEMV: y = alpha*A*x + beta*y
void ;
BLAS Level 3
// GEMM: C = alpha*A*B + beta*C
void ;
void ;
LAPACK
// LU factorization
int ;
// Solve using LU
int ;
// QR factorization
int ;
// SVD
int ;
// Cholesky factorization
int ;
Usage Examples
C Example
int
Fortran Example
program test_oxiblas
implicit none
integer :: m, n, k
real(8), dimension(2,3) :: a
real(8), dimension(3,2) :: b
real(8), dimension(2,2) :: c
m = 2; n = 2; k = 3
! Initialize matrices
a = reshape([1.0d0, 4.0d0, 2.0d0, 5.0d0, 3.0d0, 6.0d0], [2, 3])
b = reshape([7.0d0, 9.0d0, 11.0d0, 8.0d0, 10.0d0, 12.0d0], [3, 2])
! C = A * B
call dgemm('N', 'N', m, n, k, 1.0d0, a, m, b, k, 0.0d0, c, m)
print *, 'Result:'
print *, c(1,1), c(1,2)
print *, c(2,1), c(2,2)
end program test_oxiblas
Supported Operations
BLAS Level 1 (Complete)
✓ All standard vector operations (SDOT, DDOT, SAXPY, DAXPY, etc.)
BLAS Level 2 (Complete)
✓ All matrix-vector operations (SGEMV, DGEMV, SSYMV, DSYMV, etc.)
BLAS Level 3 (Complete)
✓ All matrix-matrix operations (SGEMM, DGEMM, STRSM, DTRSM, etc.)
LAPACK (Subset)
✓ LU factorization (SGETRF, DGETRF) ✓ LU solve (SGETRS, DGETRS) ✓ QR factorization (SGEQRF, DGEQRF) ✓ SVD (SGESVD, DGESVD) ✓ Cholesky (SPOTRF, DPOTRF) ✓ Eigenvalues (SSYEV, DSYEV for symmetric matrices)
Performance
OxiBLAS FFI provides 80-172% of OpenBLAS performance depending on operation and platform (see main README for detailed benchmarks).
Building for Different Platforms
Linux
macOS
Windows
Cross-Compilation
One major advantage of OxiBLAS FFI is easy cross-compilation (no C dependencies):
# Cross-compile for ARM
Integration with Build Systems
CMake
find_library(OXIBLAS_LIBRARY
NAMES oxiblas_ffi
PATHS /path/to/oxiblas/target/release
)
target_link_libraries(myapp ${OXIBLAS_LIBRARY})
Makefile
LDFLAGS +=
Related Crates
oxiblas- Pure Rust APIoxiblas-blas- BLAS operationsoxiblas-lapack- LAPACK decompositions
License
Licensed under MIT or Apache-2.0 at your option.