Octopus
openblas_version.c
Go to the documentation of this file.
1#include <dlfcn.h>
2#include <stddef.h>
3#include <stdio.h>
4#include <string.h>
5
12int openblas_get_version(int *major, int *minor, int *patch) {
13 // Get the handle of the running program. This should always succeed, but if
14 // it fails for some reason, we just pretend that OpenBLAS wasn't linked.
15 void *self = dlopen(NULL, RTLD_LAZY);
16 if (!self) {
17 return 1;
18 }
19 // ISO C forbids conversion of object pointer to function pointer type
20 char *(*openblas_get_config)(void) = NULL;
21 *(void **)(&openblas_get_config) = dlsym(self, "openblas_get_config");
22 // Permissive rather than defensive. Assume if openblas configuration
23 // cannot be retrieved, we are probably not using openblas as a backend
24 if (!openblas_get_config) {
25 return 1;
26 }
27 /* string guaranteed to start with OpenBLAS:
28 static char* openblas_config_str=""
29 "OpenBLAS "
30 VERSION
31 " "
32 See https://github.com/OpenMathLib/OpenBLAS/blob/develop/driver/others/openblas_get_config.c
33 */
34 if (sscanf(openblas_get_config(), "OpenBLAS %d.%d.%d", major, minor, patch) != 3) {
35 return 0;
36 }
37 return 1;
38}
void * dlsym(void *__restrict __handle, const char *__restrict __name) __attribute__((__nothrow__
void * dlopen(const char *__file, int __mode) __attribute__((__nothrow__))