Skip to content

Commit

Permalink
Allow for BLAS, LAPACK, and ARPACK symbols hijacking
Browse files Browse the repository at this point in the history
This opens up support for NVBlas which "hijacks" symbols by defining
`dgemm_` for example. It then expects the caller to call `dgemm_` and
the loader to load NVBlas's symbol instead of OpenBLAS's or Intel MKL's.
  • Loading branch information
luhenry committed May 9, 2021
1 parent 96828db commit 7644183
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions arpack/src/main/native/jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -2124,11 +2124,9 @@ jboolean get_system_property(JNIEnv *env, jstring key, jstring def, jstring *res
return TRUE;
}

static void *libhandle;

jboolean load_symbols(void) {
#define LOAD_SYMBOL(name) \
name = dlsym(libhandle, #name); \
name = dlsym(NULL, #name); \
if (!name) { \
return FALSE; \
}
Expand Down Expand Up @@ -2196,6 +2194,8 @@ jboolean load_symbols(void) {
return TRUE;
}

static void *libhandle;

jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
JNIEnv *env;
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) {
Expand Down Expand Up @@ -2270,7 +2270,7 @@ jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
return -1;
}

libhandle = dlopen(name, RTLD_LAZY);
libhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
if (!libhandle) {
return -1;
}
Expand Down
8 changes: 4 additions & 4 deletions blas/src/main/native/jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -1974,11 +1974,9 @@ jboolean get_system_property(JNIEnv *env, jstring key, jstring def, jstring *res
return TRUE;
}

static void *libhandle;

jboolean load_symbols(void) {
#define LOAD_SYMBOL(name) \
name = dlsym(libhandle, #name); \
name = dlsym(NULL, #name); \
if (!name) { \
return FALSE; \
}
Expand Down Expand Up @@ -2055,6 +2053,8 @@ jboolean load_symbols(void) {
return TRUE;
}

static void *libhandle;

jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
JNIEnv *env;
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) {
Expand Down Expand Up @@ -2129,7 +2129,7 @@ jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
return -1;
}

libhandle = dlopen(name, RTLD_LAZY);
libhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
if (!libhandle) {
return -1;
}
Expand Down
8 changes: 4 additions & 4 deletions generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,9 @@ def __init__(self, pkg, libname, *routines):
print("}")
print()
# Print symbols loading
print("static void *libhandle;")
print()
print("jboolean load_symbols(void) {")
print("#define LOAD_SYMBOL(name) \\")
print(" name = dlsym(libhandle, #name); \\")
print(" name = dlsym(NULL, #name); \\")
print(" if (!name) { \\")
print(" return FALSE; \\")
print(" }")
Expand All @@ -387,6 +385,8 @@ def __init__(self, pkg, libname, *routines):
print("}")
print()
# Print JNI entry functions
print("static void *libhandle;")
print()
print("jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {")
print(" JNIEnv *env;")
print(" if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) {")
Expand Down Expand Up @@ -461,7 +461,7 @@ def __init__(self, pkg, libname, *routines):
print(" return -1;")
print(" }")
print("")
print(" libhandle = dlopen(name, RTLD_LAZY);")
print(" libhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);")
print(" if (!libhandle) {")
print(" return -1;")
print(" }")
Expand Down
8 changes: 4 additions & 4 deletions lapack/src/main/native/jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -27507,11 +27507,9 @@ jboolean get_system_property(JNIEnv *env, jstring key, jstring def, jstring *res
return TRUE;
}

static void *libhandle;

jboolean load_symbols(void) {
#define LOAD_SYMBOL(name) \
name = dlsym(libhandle, #name); \
name = dlsym(NULL, #name); \
if (!name) { \
return FALSE; \
}
Expand Down Expand Up @@ -28244,6 +28242,8 @@ jboolean load_symbols(void) {
return TRUE;
}

static void *libhandle;

jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
JNIEnv *env;
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) {
Expand Down Expand Up @@ -28318,7 +28318,7 @@ jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
return -1;
}

libhandle = dlopen(name, RTLD_LAZY);
libhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
if (!libhandle) {
return -1;
}
Expand Down

0 comments on commit 7644183

Please sign in to comment.