Skip to content

Commit 7644183

Browse files
committed
Allow for BLAS, LAPACK, and ARPACK symbols hijacking
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.
1 parent 96828db commit 7644183

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

arpack/src/main/native/jni.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -2124,11 +2124,9 @@ jboolean get_system_property(JNIEnv *env, jstring key, jstring def, jstring *res
21242124
return TRUE;
21252125
}
21262126

2127-
static void *libhandle;
2128-
21292127
jboolean load_symbols(void) {
21302128
#define LOAD_SYMBOL(name) \
2131-
name = dlsym(libhandle, #name); \
2129+
name = dlsym(NULL, #name); \
21322130
if (!name) { \
21332131
return FALSE; \
21342132
}
@@ -2196,6 +2194,8 @@ jboolean load_symbols(void) {
21962194
return TRUE;
21972195
}
21982196

2197+
static void *libhandle;
2198+
21992199
jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
22002200
JNIEnv *env;
22012201
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) {
@@ -2270,7 +2270,7 @@ jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
22702270
return -1;
22712271
}
22722272

2273-
libhandle = dlopen(name, RTLD_LAZY);
2273+
libhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
22742274
if (!libhandle) {
22752275
return -1;
22762276
}

blas/src/main/native/jni.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1974,11 +1974,9 @@ jboolean get_system_property(JNIEnv *env, jstring key, jstring def, jstring *res
19741974
return TRUE;
19751975
}
19761976

1977-
static void *libhandle;
1978-
19791977
jboolean load_symbols(void) {
19801978
#define LOAD_SYMBOL(name) \
1981-
name = dlsym(libhandle, #name); \
1979+
name = dlsym(NULL, #name); \
19821980
if (!name) { \
19831981
return FALSE; \
19841982
}
@@ -2055,6 +2053,8 @@ jboolean load_symbols(void) {
20552053
return TRUE;
20562054
}
20572055

2056+
static void *libhandle;
2057+
20582058
jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
20592059
JNIEnv *env;
20602060
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) {
@@ -2129,7 +2129,7 @@ jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
21292129
return -1;
21302130
}
21312131

2132-
libhandle = dlopen(name, RTLD_LAZY);
2132+
libhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
21332133
if (!libhandle) {
21342134
return -1;
21352135
}

generator.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,9 @@ def __init__(self, pkg, libname, *routines):
370370
print("}")
371371
print()
372372
# Print symbols loading
373-
print("static void *libhandle;")
374-
print()
375373
print("jboolean load_symbols(void) {")
376374
print("#define LOAD_SYMBOL(name) \\")
377-
print(" name = dlsym(libhandle, #name); \\")
375+
print(" name = dlsym(NULL, #name); \\")
378376
print(" if (!name) { \\")
379377
print(" return FALSE; \\")
380378
print(" }")
@@ -387,6 +385,8 @@ def __init__(self, pkg, libname, *routines):
387385
print("}")
388386
print()
389387
# Print JNI entry functions
388+
print("static void *libhandle;")
389+
print()
390390
print("jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {")
391391
print(" JNIEnv *env;")
392392
print(" if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) {")
@@ -461,7 +461,7 @@ def __init__(self, pkg, libname, *routines):
461461
print(" return -1;")
462462
print(" }")
463463
print("")
464-
print(" libhandle = dlopen(name, RTLD_LAZY);")
464+
print(" libhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);")
465465
print(" if (!libhandle) {")
466466
print(" return -1;")
467467
print(" }")

lapack/src/main/native/jni.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -27507,11 +27507,9 @@ jboolean get_system_property(JNIEnv *env, jstring key, jstring def, jstring *res
2750727507
return TRUE;
2750827508
}
2750927509

27510-
static void *libhandle;
27511-
2751227510
jboolean load_symbols(void) {
2751327511
#define LOAD_SYMBOL(name) \
27514-
name = dlsym(libhandle, #name); \
27512+
name = dlsym(NULL, #name); \
2751527513
if (!name) { \
2751627514
return FALSE; \
2751727515
}
@@ -28244,6 +28242,8 @@ jboolean load_symbols(void) {
2824428242
return TRUE;
2824528243
}
2824628244

28245+
static void *libhandle;
28246+
2824728247
jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
2824828248
JNIEnv *env;
2824928249
if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) {
@@ -28318,7 +28318,7 @@ jint JNI_OnLoad(JavaVM *vm, UNUSED void *reserved) {
2831828318
return -1;
2831928319
}
2832028320

28321-
libhandle = dlopen(name, RTLD_LAZY);
28321+
libhandle = dlopen(name, RTLD_LAZY | RTLD_GLOBAL);
2832228322
if (!libhandle) {
2832328323
return -1;
2832428324
}

0 commit comments

Comments
 (0)