Skip to content

Commit 031e1a8

Browse files
authored
Add fallback for when LBT_DEFAULT_LIBS is not set (#109)
Adding a compile-time specified fallback makes it easier to use LBT as a drop-in replacement for any given BLAS implementation. One simply needs to add a definition for `LBT_FALLBACK_LIBS` to `CFLAGS` at build time to specify the fallback.
1 parent 9a8742e commit 031e1a8

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Julia Packages that utilize libblastrampline to provide easy access to BLAS libr
2525

2626
Build `libblastrampoline.so`, then link your BLAS-using library against it instead of `libblas.so`.
2727
When `libblastrampoline` is loaded, it will inspect the `LBT_DEFAULT_LIBS` environment variable and attempt to forward BLAS calls made to it on to that library (this can be a list of semicolon-separated libraries if your backing implementation is split across multiple libraries, such as in the case of separate `BLAS` and `LAPACK` libraries).
28+
If `LBT_DEFAULT_LIBS` is not set, then `libblastrampoline` will fall back to the definition of the `LBT_FALLBACK_LIBS` macro specified at compile time.
2829
At any time, you may call `lbt_forward(libname, clear, verbose)` to redirect forwarding to a new BLAS library.
2930
If you set `clear` to `1` it will clear out all previous mappings before setting new mappings, while if it is set to `0` it will leave symbols that do not exist within the given `libname` alone.
3031
This is used to implement layering of libraries, such as between a split BLAS and LAPACK library:

src/libblastrampoline.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ __attribute__((constructor)) void init(void) {
445445

446446
// LBT_DEFAULT_LIBS is a semicolon-separated list of paths that should be loaded as BLAS libraries
447447
const char * default_libs = getenv("LBT_DEFAULT_LIBS");
448+
#if defined(LBT_FALLBACK_LIBS)
449+
if (default_libs == NULL) {
450+
default_libs = LBT_FALLBACK_LIBS;
451+
}
452+
#endif
448453
if (default_libs != NULL) {
449454
const char * curr_lib_start = default_libs;
450455
int clear = 1;

0 commit comments

Comments
 (0)