[jvm-packages] Minor improvements to the CMake build (#2379)
* [jvm-packages] Fixed JNI_OnLoad overload It does not compile on Windows without proper export flags. * [jvm-packages] Use JNI types directly where appropriate * Removed lib hack from CMake build Prior to this commit the CMake build use hardcoded lib prefix for libxgboost and libxgboost4j. Unfortunatelly this did not play well with Windows, which does not use the lib- prefix.
This commit is contained in:
parent
37c27ab8e8
commit
3820ab6a0b
@ -94,8 +94,6 @@ if(MSVC)
|
|||||||
else()
|
else()
|
||||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
|
||||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
|
||||||
#Prevent shared library being called liblibxgboost.so on Linux
|
|
||||||
set(CMAKE_SHARED_LIBRARY_PREFIX "")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(LINK_LIBRARIES dmlccore rabit)
|
set(LINK_LIBRARIES dmlccore rabit)
|
||||||
@ -124,11 +122,12 @@ endif()
|
|||||||
add_library(objxgboost OBJECT ${SOURCES})
|
add_library(objxgboost OBJECT ${SOURCES})
|
||||||
set_target_properties(${objxgboost} PROPERTIES POSITION_INDEPENDENT_CODE 1)
|
set_target_properties(${objxgboost} PROPERTIES POSITION_INDEPENDENT_CODE 1)
|
||||||
|
|
||||||
add_library(libxgboost SHARED $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
|
add_executable(runxgboost $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
|
||||||
add_executable(xgboost $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
|
set_target_properties(runxgboost PROPERTIES OUTPUT_NAME xgboost)
|
||||||
|
target_link_libraries(runxgboost ${LINK_LIBRARIES})
|
||||||
|
|
||||||
|
add_library(xgboost SHARED $<TARGET_OBJECTS:objxgboost> ${CUDA_OBJS})
|
||||||
target_link_libraries(xgboost ${LINK_LIBRARIES})
|
target_link_libraries(xgboost ${LINK_LIBRARIES})
|
||||||
target_link_libraries(libxgboost ${LINK_LIBRARIES})
|
|
||||||
|
|
||||||
option(JVM_BINDINGS "Build JVM bindings" OFF)
|
option(JVM_BINDINGS "Build JVM bindings" OFF)
|
||||||
|
|
||||||
@ -137,11 +136,11 @@ if(JVM_BINDINGS)
|
|||||||
|
|
||||||
include_directories(${JNI_INCLUDE_DIRS} jvm-packages/xgboost4j/src/native)
|
include_directories(${JNI_INCLUDE_DIRS} jvm-packages/xgboost4j/src/native)
|
||||||
|
|
||||||
add_library(libxgboost4j SHARED
|
add_library(xgboost4j SHARED
|
||||||
$<TARGET_OBJECTS:objxgboost>
|
$<TARGET_OBJECTS:objxgboost>
|
||||||
${CUDA_OBJS}
|
${CUDA_OBJS}
|
||||||
jvm-packages/xgboost4j/src/native/xgboost4j.cpp)
|
jvm-packages/xgboost4j/src/native/xgboost4j.cpp)
|
||||||
target_link_libraries(libxgboost4j
|
target_link_libraries(xgboost4j
|
||||||
${LINK_LIBRARIES}
|
${LINK_LIBRARIES}
|
||||||
${JNI_LIBRARIES})
|
${JNI_LIBRARIES})
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@ -24,11 +24,7 @@
|
|||||||
// helper functions
|
// helper functions
|
||||||
// set handle
|
// set handle
|
||||||
void setHandle(JNIEnv *jenv, jlongArray jhandle, void* handle) {
|
void setHandle(JNIEnv *jenv, jlongArray jhandle, void* handle) {
|
||||||
#ifdef __APPLE__
|
jlong out = (jlong) handle;
|
||||||
jlong out = (long) handle;
|
|
||||||
#else
|
|
||||||
int64_t out = (int64_t) handle;
|
|
||||||
#endif
|
|
||||||
jenv->SetLongArrayRegion(jhandle, 0, 1, &out);
|
jenv->SetLongArrayRegion(jhandle, 0, 1, &out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +32,7 @@ void setHandle(JNIEnv *jenv, jlongArray jhandle, void* handle) {
|
|||||||
static JavaVM* global_jvm = nullptr;
|
static JavaVM* global_jvm = nullptr;
|
||||||
|
|
||||||
// overrides JNI on load
|
// overrides JNI on load
|
||||||
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||||
global_jvm = vm;
|
global_jvm = vm;
|
||||||
return JNI_VERSION_1_6;
|
return JNI_VERSION_1_6;
|
||||||
}
|
}
|
||||||
@ -76,7 +72,7 @@ XGB_EXTERN_C int XGBoost4jCallbackDataIterNext(
|
|||||||
batch, jenv->GetFieldID(batchClass, "featureValue", "[F"));
|
batch, jenv->GetFieldID(batchClass, "featureValue", "[F"));
|
||||||
XGBoostBatchCSR cbatch;
|
XGBoostBatchCSR cbatch;
|
||||||
cbatch.size = jenv->GetArrayLength(joffset) - 1;
|
cbatch.size = jenv->GetArrayLength(joffset) - 1;
|
||||||
cbatch.offset = reinterpret_cast<long *>(
|
cbatch.offset = reinterpret_cast<jlong *>(
|
||||||
jenv->GetLongArrayElements(joffset, 0));
|
jenv->GetLongArrayElements(joffset, 0));
|
||||||
if (jlabel != nullptr) {
|
if (jlabel != nullptr) {
|
||||||
cbatch.label = jenv->GetFloatArrayElements(jlabel, 0);
|
cbatch.label = jenv->GetFloatArrayElements(jlabel, 0);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user