8000 Allow disabling of BLAS prototypes at compile-time. · flame/blis@feefcab · GitHub
[go: up one dir, main page]

Skip to content

Commit feefcab

Browse files
committed
Allow disabling of BLAS prototypes at compile-time.
Details: - Modified bli_blas.h so that: - By default, if the BLAS layer is enabled at configure-time, BLAS prototypes are also enabled within blis.h; - But if the user #defines BLIS_DISABLE_BLAS_DEFS prior to including blis.h, BLAS prototypes are skipped over entirely so that, for example, the application or some other header pulled in by the application may prototype the BLAS functions without causing any duplication. - Updated docs/BuildSystem.md to document the feature above, and related text.
1 parent 153e0be commit feefcab

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

docs/BuildSystem.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* **[Step 3b: Testing (optional)](BuildSystem.md#step-3b-testing-optional)**
1010
* **[Step 4: Installation](BuildSystem.md#step-4-installation)**
1111
* **[Cleaning out build products](BuildSystem.md#cleaning-out-build-products)**
12+
* **[Compiling with BLIS](BuildSystem.md#compiling-with-blis)**
13+
* [Disabling BLAS prototypes](BuildSystem.md#disabling-blas-prototypes)
14+
* [CBLAS](BuildSystem.md#cblas)
1215
* **[Linking against BLIS](BuildSystem.md#linking-against-blis)**
1316
* **[Uninstalling](BuildSystem.md#uninstalling)**
1417
* **[make targets](BuildSystem.md#make-targets)**
@@ -83,7 +86,7 @@ Alternatively, `configure` can automatically select a configuration based on you
8386
```
8487
$ ./configure auto
8588
```
86-
However, as of this writing, only a limited number of architectures are detected. If the `configure` script is not able to detect your architecture, the `generic` configuration will be used.
89+
However, as of this writing, only a limited number of architectures are detected. If the `configure` script is not able to detect your architecture, the `generic` configuration will be used.
8790

8891
Upon running configure, you will get output similar to the following. The exact output will depend on whether you cloned BLIS from a `git` repository or whether you obtained BLIS via a downloadable tarball from the [releases](https://github.com/flame/blis/releases) page.
8992
```
@@ -338,6 +341,47 @@ Removing include.
338341
Running the `distclean` target is like saying, "Remove anything ever created by the build system."
339342

340343

344+
## Compiling with BLIS
345+
346+
All BLIS definitions and prototypes may be included in your C source file by including a single header file, `blis.h`:
347+
```c
348+
#include "stdio.h"
349+
#include "stdlib.h"
350+
#include "otherstuff.h"
351+
#include "blis.h"
352+
```
353+
If the BLAS compatibility layer was enabled at configure-time (as it is by default), then `blis.h` will also provide BLAS prototypes to your source code.
354+
355+
356+
### Disabling BLAS prototypes
357+
358+
Some applications already `#include` a header that contains BLAS prototypes. This can cause problems if those applications also try to `#include` the BLIS header file, as shown above. Suppose for a moment that `otherstuff.h` in the example above already provides BLAS prototypes.
359+
```
360+
$ gcc -I/path/to/blis -I/path/to/otherstuff -c main.c -o main.o
361+
In file included from main.c:41:0:
362+
/path/to/blis/blis.h:36900:111: error: conflicting declaration of C function ‘int xerbla_(const bla_character*, const bla_integer*, ftnlen)’
363+
TEF770(xerbla)(const bla_character *srname, const bla_integer *info, ftnlen srname_len);
364+
```
365+
If your application is already declaring (prototyping) BLAS functions, then you may disable those prototypes from being defined included within `blis.h`. This prevents `blis.h` from re-declaring those prototypes, or, allows your other header to declare those functions for the first time, depending on the order that you `#include` the headers.
366+
```c
367+
#include "stdio.h"
368+
#include "stdlib.h"
369+
#include "otherstuff.h"
370+
#define BLIS_DISABLE_BLAS_DEFS // disable BLAS prototypes within BLIS.
371+
#include "blis.h"
372+
```
373+
By `#defining` the `BLIS_DISABLE_BLAS_DEFS` macro, we signal to `blis.h` that it should skip over the BLAS prototypes, but otherwise `#include` everything else as it normally would. Note that `BLIS_DISABLE_BLAS_DEFS` must be `#defined` *prior* to the `#include "blis.h"` directive in order for it to have any effect.
374+
375+
376+
### CBLAS
377+
378+
If you build BLIS with CBLAS enabled and you wish to access CBLAS function prototypes from within your application, you will have to `#include` the `cblas.h` header separately from `blis.h`.
379+
```
380+
#include "blis.h"
381+
#include "cblas.h"
382+
```
383+
384+
341385
## Linking against BLIS
342386

343387
Once you have instantiated (configured and compiled, and perhaps installed) a BLIS library, you can link to it in your application's makefile as you would any other library. The following is an abbreviated makefile for a small hypothetical application that has just two external dependencies: BLIS and the standard C math library. We also link against libpthread since that library has been a runtime dependency of BLIS since 70640a3 (December 2017).
@@ -357,7 +401,7 @@ OBJS = main.o util.o other.o
357401
%.o: %.c
358402
$(CC) $(CFLAGS) -c $< -o $@
359403

360-
all: $(OBJS)
404+
all: $(OBJS)
361405
$(LINKER) $(OBJS) $(BLIS_LIB) $(OTHER_LIBS) -o my_program.x
362406
```
363407
The above example assumes you will want to include BLIS definitions and function prototypes into your application via `#include blis.h`. (If you are only using the BLIS via the BLAS compatibility layer, including `blis.h` is not necessary.) Since BLIS headers are installed into a `blis` subdirectory of `PREFIX/include`, you must make sure that the compiler knows where to find the `blis.h` header file. This is typically accomplished by inserting `#include "blis.h"` into your application's source code files and compiling the code with `-I PREFIX/include/blis`.

frame/compat/bli_blas.h

Copy file name to clipboard
Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,31 @@
4040
#endif
4141
#endif // BLIS_ENABLE_CBLAS
4242

43+
// By default, if the BLAS compatibility layer is enabled, we define
44+
// (include) all of the BLAS prototypes. However, if the user is
45+
// #including "blis.h" and also #including another header that also
46+
// declares the BLAS functions, then we provide an opportunity to
47+
// #undefine the BLIS_ENABLE_BLAS_DEFS macro (see below).
48+
#ifdef BLIS_ENABLE_BLAS
49+
#define BLIS_ENABLE_BLAS_DEFS
50+
#else
51+
#undef BLIS_ENABLE_BLAS_DEFS
52+
#endif
53+
4354
// Skip prototyping all of the BLAS if the BLAS test drivers are being
4455
// compiled.
45-
#ifndef BLIS_VIA_BLASTEST
46-
#ifdef BLIS_ENABLE_BLAS
56+
#ifdef BLIS_VIA_BLASTEST
57+
#undef BLIS_ENABLE_BLAS_DEFS
58+
#endif
59+
60+
// Skip prototyping all of the BLAS if the environment has defined the
61+
// macro BLIS_DISABLE_BLAS_DEFS.
62+
#ifdef BLIS_DISABLE_BLAS_DEFS
63+
#undef BLIS_ENABLE_BLAS_DEFS
64+
#endif
65+
66+
// Begin including all BLAS prototypes.
67+
#ifdef BLIS_ENABLE_BLAS_DEFS
4768

4869

4970
// -- System headers needed by BLAS compatibility layer --
@@ -180,4 +201,3 @@
180201

181202

182203
#endif // BLIS_ENABLE_BLAS
183-
#endif // BLIS_VIA_BLASTEST

0 commit comments

Comments
 (0)
0