Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework JNI CMake to leverage rapids_find_package #10649

Merged
merged 6 commits into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,8 @@ function buildLibCudfJniInDocker {
-DCUDF_CPP_BUILD_DIR=$workspaceRepoDir/java/target/libcudf-cmake-build \
-DCUDA_STATIC_RUNTIME=ON \
-DPER_THREAD_DEFAULT_STREAM=ON \
-DRMM_LOGGING_LEVEL=OFF \
-DUSE_GDS=ON \
-DGPU_ARCHS=${CUDF_CMAKE_CUDA_ARCHITECTURES} \
-DCUDF_JNI_ARROW_STATIC=ON \
-DCUDF_JNI_LIBCUDF_STATIC=ON \
-Dtest=*,!CuFileTest"
}
Expand Down
10 changes: 0 additions & 10 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,6 @@ If you decide to build without Docker and the build script, examining the cmake
settings in the [Java CI build script](ci/build-in-docker.sh) can be helpful if you are
encountering difficulties during the build.

## Dynamically Linking Arrow

Since libcudf builds by default with a dynamically linked Arrow dependency, it may be
desirable to build the Java bindings without requiring a statically-linked Arrow to avoid
rebuilding an already built libcudf.so. To do so, specify the additional command-line flag
`-DCUDF_JNI_ARROW_STATIC=OFF` when building the Java bindings with Maven. However this will
result in a jar that requires the correct Arrow version to be available in the runtime
environment, and therefore is not recommended unless you are only performing local testing
within the libcudf build environment.

## Statically Linking the CUDA Runtime

If you use the default cmake options libcudart will be dynamically linked to libcudf and libcudfjni.
Expand Down
1 change: 0 additions & 1 deletion java/ci/build-in-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ BUILD_ARG="-Dmaven.repo.local=\"$WORKSPACE/.m2\"\
-DPER_THREAD_DEFAULT_STREAM=$ENABLE_PTDS\
-DCUDA_STATIC_RUNTIME=$ENABLE_CUDA_STATIC_RUNTIME\
-DCUDF_JNI_LIBCUDF_STATIC=ON\
-DRMM_LOGGING_LEVEL=$RMM_LOGGING_LEVEL\
jlowe marked this conversation as resolved.
Show resolved Hide resolved
-DUSE_GDS=$ENABLE_GDS -Dtest=*,!CuFileTest"

if [ "$SIGN_FILE" == true ]; then
Expand Down
4 changes: 0 additions & 4 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,8 @@
<CMAKE_EXPORT_COMPILE_COMMANDS>OFF</CMAKE_EXPORT_COMPILE_COMMANDS>
<CUDA_STATIC_RUNTIME>OFF</CUDA_STATIC_RUNTIME>
<PER_THREAD_DEFAULT_STREAM>OFF</PER_THREAD_DEFAULT_STREAM>
<RMM_LOGGING_LEVEL>INFO</RMM_LOGGING_LEVEL>
<USE_GDS>OFF</USE_GDS>
<GPU_ARCHS>ALL</GPU_ARCHS>
<CUDF_JNI_ARROW_STATIC>ON</CUDF_JNI_ARROW_STATIC>
<CUDF_JNI_LIBCUDF_STATIC>OFF</CUDF_JNI_LIBCUDF_STATIC>
<native.build.path>${project.build.directory}/cmake-build</native.build.path>
<slf4j.version>1.7.30</slf4j.version>
Expand Down Expand Up @@ -386,13 +384,11 @@
<arg value="${basedir}/src/main/native"/>
<arg value="-DCUDA_STATIC_RUNTIME=${CUDA_STATIC_RUNTIME}" />
<arg value="-DPER_THREAD_DEFAULT_STREAM=${PER_THREAD_DEFAULT_STREAM}" />
<arg value="-DRMM_LOGGING_LEVEL=${RMM_LOGGING_LEVEL}" />
<arg value="-DUSE_GDS=${USE_GDS}" />
<arg value="-DCMAKE_CXX_FLAGS=${cxx.flags}"/>
<arg value="-DCMAKE_EXPORT_COMPILE_COMMANDS=${CMAKE_EXPORT_COMPILE_COMMANDS}"/>
<arg value="-DCUDF_CPP_BUILD_DIR=${CUDF_CPP_BUILD_DIR}"/>
<arg value="-DGPU_ARCHS=${GPU_ARCHS}"/>
<arg value="-DCUDF_JNI_ARROW_STATIC=${CUDF_JNI_ARROW_STATIC}"/>
<arg value="-DCUDF_JNI_LIBCUDF_STATIC=${CUDF_JNI_LIBCUDF_STATIC}"/>
<arg value="-DBUILD_SHARED_LIBS=ON"/>
</exec>
Expand Down
132 changes: 17 additions & 115 deletions java/src/main/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ option(BUILD_TESTS "Configure CMake to build tests" ON)
option(PER_THREAD_DEFAULT_STREAM "Build with per-thread default stream" OFF)
option(CUDA_STATIC_RUNTIME "Statically link the CUDA runtime" OFF)
option(USE_GDS "Build with GPUDirect Storage (GDS)/cuFile support" OFF)
option(CUDF_JNI_ARROW_STATIC "Statically link Arrow" ON)
option(CUDF_JNI_LIBCUDF_STATIC "Link with libcudf.a" OFF)

message(VERBOSE "CUDF_JNI: Build with NVTX support: ${USE_NVTX}")
Expand All @@ -50,7 +49,6 @@ message(VERBOSE "CUDF_JNI: Configure CMake to build tests: ${BUILD_TESTS}")
message(VERBOSE "CUDF_JNI: Build with per-thread default stream: ${PER_THREAD_DEFAULT_STREAM}")
message(VERBOSE "CUDF_JNI: Statically link the CUDA runtime: ${CUDA_STATIC_RUNTIME}")
message(VERBOSE "CUDF_JNI: Build with GPUDirect Storage support: ${USE_GDS}")
message(VERBOSE "CUDF_JNI: Build with static Arrow library: ${CUDF_JNI_ARROW_STATIC}")
message(VERBOSE "CUDF_JNI: Link with libcudf statically: ${CUDF_JNI_LIBCUDF_STATIC}")

set(CUDF_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../../../../cpp")
Expand Down Expand Up @@ -93,67 +91,16 @@ endif()
rapids_cmake_build_type("Release")

# ##################################################################################################
# * Thrust/CUB
# ------------------------------------------------------------------------------------
include(${CUDF_SOURCE_DIR}/cmake/thirdparty/get_thrust.cmake)
# * nvcomp------------------------------------------------------------------------------------------

# ##################################################################################################
# * CUDF ------------------------------------------------------------------------------------------

set(CUDF_INCLUDE "${PROJECT_SOURCE_DIR}/../../../../cpp/include"
"${PROJECT_SOURCE_DIR}/../../../../cpp/src/"
)

set(CUDF_LIB_HINTS HINTS "$ENV{CUDF_ROOT}" "$ENV{CUDF_ROOT}/lib" "$ENV{CONDA_PREFIX}/lib"
"${CUDF_CPP_BUILD_DIR}"
)

find_library(CUDF_LIB "cudf" REQUIRED HINTS ${CUDF_LIB_HINTS})

# ##################################################################################################
# * ZLIB ------------------------------------------------------------------------------------------

# find zlib
rapids_find_package(ZLIB REQUIRED)
set(nvcomp_DIR "${CUDF_CPP_BUILD_DIR}/_deps/nvcomp-build")
rapids_find_package(nvcomp REQUIRED)

# ##################################################################################################
# * RMM -------------------------------------------------------------------------------------------
# * CUDF ------------------------------------------------------------------------------------------

include(${CUDF_SOURCE_DIR}/cmake/thirdparty/get_rmm.cmake)

# ##################################################################################################
# * ARROW -----------------------------------------------------------------------------------------

find_path(ARROW_INCLUDE "arrow" HINTS "$ENV{ARROW_ROOT}/include"
"${CUDF_CPP_BUILD_DIR}/_deps/arrow-src/cpp/src"
)

message(STATUS "ARROW: ARROW_INCLUDE set to ${ARROW_INCLUDE}")

if(CUDF_JNI_ARROW_STATIC)
# Find static version of Arrow lib
set(CUDF_JNI_ARROW_LIBNAME "libarrow.a")
else()
set(CUDF_JNI_ARROW_LIBNAME "arrow")
endif()

find_library(
ARROW_LIBRARY ${CUDF_JNI_ARROW_LIBNAME} REQUIRED
HINTS "$ENV{ARROW_ROOT}/lib" "${CUDF_CPP_BUILD_DIR}/_deps/arrow-build/release"
"${CUDF_CPP_BUILD_DIR}/_deps/arrow-build/debug"
)

if(NOT ARROW_LIBRARY)
if(CUDF_JNI_ARROW_STATIC)
message(
FATAL_ERROR "Arrow static library not found. Was libcudf built with CUDF_USE_ARROW_STATIC=ON?"
)
else()
message(FATAL_ERROR "Arrow dynamic library not found.")
endif()
else()
message(STATUS "ARROW: ARROW_LIBRARY set to ${ARROW_LIBRARY}")
endif()
set(cudf_ROOT "${CUDF_CPP_BUILD_DIR}")
rapids_find_package(cudf REQUIRED)

# ##################################################################################################
# * find JNI -------------------------------------------------------------------------------------
Expand All @@ -164,27 +111,6 @@ else()
message(FATAL_ERROR "JDK with JNI not found, please check your settings.")
endif()

# ##################################################################################################
# * nvcomp ----------------------------------------------------------------------------------------

find_path(NVCOMP_INCLUDE "nvcomp" HINTS "${CUDF_CPP_BUILD_DIR}/_deps/nvcomp-src/include"
"$ENV{CONDA_PREFIX}/include"
)

message(STATUS "NVCOMP: NVCOMP_INCLUDE set to ${NVCOMP_INCLUDE}")

set(CUDF_JNI_NVCOMP_LIBNAME "libnvcomp.a")
find_library(
NVCOMP_LIBRARY ${CUDF_JNI_NVCOMP_LIBNAME} REQUIRED HINTS "${CUDF_CPP_BUILD_DIR}/lib"
"$ENV{CONDA_PREFIX}/lib"
)

if(NOT NVCOMP_LIBRARY)
message(FATAL_ERROR "nvcomp static library not found.")
else()
message(STATUS "NVCOMP: NVCOMP_LIBRARY set to ${NVCOMP_LIBRARY}")
endif()

# ##################################################################################################
# * GDS/cufile ------------------------------------------------------------------------------------

Expand Down Expand Up @@ -238,17 +164,8 @@ endif()
# * include paths ---------------------------------------------------------------------------------

target_include_directories(
cudfjni
PUBLIC cudf::Thrust
"${LIBCUDACXX_INCLUDE}"
"${CUDAToolkit_INCLUDE_DIRS}"
"${NVCOMP_INCLUDE}"
"${CMAKE_BINARY_DIR}/include"
"${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/src"
"${JNI_INCLUDE_DIRS}"
"${CUDF_INCLUDE}"
"${ARROW_INCLUDE}"
cudfjni PUBLIC "${CMAKE_BINARY_DIR}/include" "${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}/src" "${JNI_INCLUDE_DIRS}"
)

# ##################################################################################################
Expand Down Expand Up @@ -291,39 +208,24 @@ if(USE_GDS)
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
)
target_include_directories(
cufilejni
PUBLIC "${LIBCUDACXX_INCLUDE}" "${CUDF_INCLUDE}"
PRIVATE "${cuFile_INCLUDE_DIRS}"
)
target_link_libraries(cufilejni PRIVATE cudfjni rmm::rmm "${cuFile_LIBRARIES}")
target_include_directories(cufilejni PRIVATE "${cuFile_INCLUDE_DIRS}")
target_link_libraries(cufilejni PRIVATE cudfjni "${cuFile_LIBRARIES}")
endif()

# ##################################################################################################
# * rmm logging level -----------------------------------------------------------------------------

set(RMM_LOGGING_LEVEL
"INFO"
CACHE STRING "Choose the logging level."
)
# Set the possible values of build type for cmake-gui
set_property(
CACHE RMM_LOGGING_LEVEL PROPERTY STRINGS "TRACE" "DEBUG" "INFO" "WARN" "ERROR" "CRITICAL" "OFF"
)
message(STATUS "RMM_LOGGING_LEVEL = '${RMM_LOGGING_LEVEL}'.")

target_compile_definitions(cudfjni PUBLIC SPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_${RMM_LOGGING_LEVEL})

# ##################################################################################################
# * link libraries --------------------------------------------------------------------------------

set(CUDF_LINK ${CUDF_LIB})
set(CUDF_LINK PUBLIC cudf::cudf)
if(CUDF_JNI_LIBCUDF_STATIC)
set(CUDF_LINK -Wl,--whole-archive ${CUDF_LIB} -Wl,--no-whole-archive ZLIB::ZLIB)
# Whole-link libcudf.a into the shared library but not its dependencies
set(CUDF_LINK PRIVATE -Wl,--whole-archive cudf::cudf -Wl,--no-whole-archive PUBLIC cudf::cudf)
endif()

# When nvcomp is installed we need to use nvcomp::nvcomp but from the cudf build directory it will
# just be nvcomp.
target_link_libraries(
cudfjni PRIVATE ${CUDF_LINK} ${NVCOMP_LIBRARY} ${ARROW_LIBRARY} rmm::rmm CUDA::cuda_driver
cudfjni ${CUDF_LINK} PRIVATE $<TARGET_NAME_IF_EXISTS:nvcomp>
$<TARGET_NAME_IF_EXISTS:nvcomp::nvcomp>
)

# ##################################################################################################
Expand Down