Expand description
§OpenBLAS FFI bindings
This crate contains OpenBLAS FFI bindings.
Current FFI version is OpenBLAS v0.3.34. If you are using an older version of OpenBLAS, this crate should still work if you do not explicitly call the function that only occurs in higher version of OpenBLAS.
OpenBLAS (C/Fortran/ASM) source code is available on github.
This crate is not official bindgen project. It is originally intended to serve rust tensor toolkit RSTSR and rust electronic structure toolkit REST.
- Audience: Anyone uses OpenBLAS function may also find it useful, not only RSTSR or REST program developers.
- Pure Extern or Dynamic Loading: This crate supports either pure extern (usual FFI, requires dynamic or static linking) and dynamic-loading, by cargo feature
dynamic_loading.
§Dynamic loading
This crate supports dynamic loading.
If you want to use dynamic loading, please enable cargo feature dynamic_loading when cargo build.
The dynamic loading will try to find proper library when your program initializes.
- This crate will automatically detect proper libraries, if these libraries are in environmental path
LD_LIBRARY_PATH(Linux)DYLD_LIBRARY_PATH(Mac OS),PATH(Windows). - If you want to override the library to be loaded, please set these shell environmental variable
RSTSR_DYLOAD_OPENBLASto the dynamic library path.
NOTE: When you call BLAS and LAPACK functions with dynamic loading, please DO NOT USE other crates (such as rstsr_lapack_ffi). Please make sure you are only using rstsr_openblas_ffi::blas, rstsr_openblas_ffi::cblas and rstsr_openblas_ffi::lapack. Sticking to using rstsr_openblas_ffi will make sure you are calling BLAS and LAPACK functions from OpenBLAS, instead of other BLAS vendors.
If you encountered large compile time or disk consumption, you may consider add these lines in your Cargo.toml:
[profile.dev.package.rstsr-openblas-ffi]
opt-level = 0
debug = false§Cargo features
Default features:
blas: Inclulde BLAS bindgens.cblas: Include CBLAS bindgens.lapack: Include LAPACK bindgens.
Optional features:
dynamic_loading: Supports dynamic loading.ilp64: Useint64_tfor dimension specification, or lapack error code types if this feature specified. Otherwise, useint32_t.- Please note that in module
blas, error code is returned byc_int; in modulecblas, OpenBLAS utility functions usec_intfor input or output.
- Please note that in module
lapacke: Include LAPACKE bindgens.quad_precisionandex_precision: Specify type extra-precisionxdoubletype in moduleblas. Probably few people will require these features.
§Crate structure
header: Header files copied (or renamed) from original source.scripts: Script to generate FFI bindgens.src: FFI bindings:blas: Corresponds tof77blas.hheader in compiled library include (orcommon_interface.hin OpenBLAS original source code). BLAS and some LAPACK functions that implemented by OpenBLAS, no post-suffix underscore.cblas: Corresponds tocblas.hheader. Original CBLAS included, along with OpenBLAS utility functions (e.g.openblas_get_num_threads) and some BLAS extensions (e.g.cblas_zgemm_batch). The Linux-only thread-affinity API (openblas_getaffinity/openblas_setaffinity) is included behind#[cfg(target_os = "linux")].lapack,lapacke: netlib LAPACK symbols provided by OpenBLAS. Their generated sources are shared with craterstsr-lapack-ffiand are not regenerated by this crate’s script.
- In each bindgens, the following files are usually automatically generated by scripts:
ffi_base.rs: Basic type, enum, struct definitions.ffi_extern.rs: Unsafe extern “C” bindgen functions. Only activated when not dynamic loading.dyload_struct.rs: StructLibfor dynamic loading.dyload_initializer.rs: The initialization function ofLibfor dynamic loading.dyload_compatible.rs: Unsafe bindgen function that is compatible to that offfi_extern.rs. Only activated when dynamic loading.- special case of
cblas::ffi_base: the enumsCBLAS_LAYOUT,CBLAS_TRANSPOSE,CBLAS_UPLO, etc. come from craterstsr-cblas-base, shared by the rstsr FFI crates.
§Changelog
-
v0.6.1
- Enhancements: Bind the Linux-only thread-affinity API
openblas_getaffinity/openblas_setaffinity(upstream declares them underOPENBLAS_OS_LINUX); the items are available only ontarget_os = "linux"builds. - Dev infrastructure:
scripts/perform_bindgen.pynow fails loudly when an upstream header or bindgen output stops matching a text patch, and propagatescfgattributes into all generated dynamic-loading files; regenerated with bindgen 0.73.2. - Docs: Corrected the crate-structure notes (CBLAS enums come from
rstsr-cblas-base;lapack/lapackesources are shared withrstsr-lapack-ffi).
- Enhancements: Bind the Linux-only thread-affinity API
-
v0.6.0
- Enhancements: Updated vendored headers to OpenBLAS v0.3.34. New CBLAS functions:
openblas_set_xerbla(withopenblas_xerbla_handlertypedef),cblas_[sdcz]gemm_batch_strided,cblas_bgemv,cblas_bgemm,cblas_sbgemm_batch_strided,cblas_shgemm. New BLAS functions:bscal_,bgemv_,shgemv_,shgemm_,bgemm_. New typehfloat16(resolved asu16by the generation toolchain). - API Breaking:
cblas_[sdcz]geaddgainedCTRANS_AandCTRANS_Carguments, and BLAS[sdcz]geadd_gained two trailingtransa/transccharacter pointers, following the upstream OpenBLAS 0.3.34 GEADD signature change. - Bugfix: Fixed
quad_precisionbuild failure. The generator now injectscore::ffi::c_ulongin thexdoublestruct instead of::core::os::raw::c_ulong, which no longer resolves on current rustc.
- Enhancements: Updated vendored headers to OpenBLAS v0.3.34. New CBLAS functions:
-
v0.5.0
- API Breaking: Now cargo feature
dynamic_loadingis not default.
- API Breaking: Now cargo feature
-
v0.4.5
- Enhancements: Updated panic information.
-
v0.4.4
- Docs Update
-
v0.4.3
- API Breaking: Change CBLAS enum definition to crate
rstsr-cblas-base.
- API Breaking: Change CBLAS enum definition to crate
-
v0.4.1
- Minor fix: fixed error printing of module information.
-
v0.4.0
- API breaking change: Supports and defaults to dynamic loading.
- Added
omp_set_num_threadsandomp_get_max_threadsfor convenience.