Skip to content

Commit

Permalink
Add a cmake option to link to GDS/cuFile (#6847)
Browse files Browse the repository at this point in the history
Add a cmake find module to locate cuFile. If found, add the include directory and link to the shared library.

This shouldn't have any effect if cuFile is not installed locally.
  • Loading branch information
rongou committed Nov 30, 2020
1 parent 80464ce commit 0e94bab
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
- PR #6796 Add create_metadata_file in dask_cudf
- PR #6765 Cupy fallback for __array_function__ and __array_ufunc__ for cudf.Series
- PR #6805 Implement `cudf::detail::copy_if` for `decimal32` and `decimal64`
- PR #6847 Add a cmake find module for cuFile in JNI code

## Improvements

Expand Down
121 changes: 121 additions & 0 deletions cpp/cmake/Modules/FindcuFile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#=============================================================================
# Copyright (c) 2020, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#[=======================================================================[.rst:
FindcuFile
----------

Find cuFile headers and libraries.

Imported Targets
^^^^^^^^^^^^^^^^

``cuFile::cuFile``
The cuFile library, if found.
``cuFile::cuFileRDMA``
The cuFile RDMA library, if found.

Result Variables
^^^^^^^^^^^^^^^^

This will define the following variables in your project:

``cuFile_FOUND``
true if (the requested version of) cuFile is available.
``cuFile_VERSION``
the version of cuFile.
``cuFile_LIBRARIES``
the libraries to link against to use cuFile.
``cuFileRDMA_LIBRARIES``
the libraries to link against to use cuFile RDMA.
``cuFile_INCLUDE_DIRS``
where to find the cuFile headers.
``cuFile_COMPILE_OPTIONS``
this should be passed to target_compile_options(), if the
target is not used for linking

#]=======================================================================]


# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig QUIET)
pkg_check_modules(PKG_cuFile QUIET cuFile)

set(cuFile_COMPILE_OPTIONS ${PKG_cuFile_CFLAGS_OTHER})
set(cuFile_VERSION ${PKG_cuFile_VERSION})

find_path(cuFile_INCLUDE_DIR
NAMES
cufile.h
HINTS
${PKG_cuFile_INCLUDE_DIRS}
/usr/local/gds/lib
)

find_library(cuFile_LIBRARY
NAMES
cufile
HINTS
${PKG_cuFile_LIBRARY_DIRS}
/usr/local/gds/lib
)

find_library(cuFileRDMA_LIBRARY
NAMES
cufile_rdma
HINTS
${PKG_cuFile_LIBRARY_DIRS}
/usr/local/gds/lib
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(cuFile
FOUND_VAR
cuFile_FOUND
REQUIRED_VARS
cuFile_LIBRARY
cuFileRDMA_LIBRARY
cuFile_INCLUDE_DIR
VERSION_VAR
cuFile_VERSION
)


if (cuFile_FOUND AND NOT TARGET cuFile::cuFile)
add_library(cuFile::cuFile UNKNOWN IMPORTED)
set_target_properties(cuFile::cuFile PROPERTIES
IMPORTED_LOCATION "${cuFile_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${cuFile_COMPILE_OPTIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${cuFile_INCLUDE_DIR}"
)
endif ()

if (cuFile_FOUND AND NOT TARGET cuFile::cuFileRDMA)
add_library(cuFile::cuFileRDMA UNKNOWN IMPORTED)
set_target_properties(cuFile::cuFileRDMA PROPERTIES
IMPORTED_LOCATION "${cuFileRDMA_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${cuFile_COMPILE_OPTIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${cuFile_INCLUDE_DIR}"
)
endif ()

mark_as_advanced(cuFile_LIBRARY cuFileRDMA_LIBRARY cuFile_INCLUDE_DIR)

if (cuFile_FOUND)
set(cuFile_LIBRARIES ${cuFile_LIBRARY})
set(cuFileRDMA_LIBRARIES ${cuFileRDMA_LIBRARY})
set(cuFile_INCLUDE_DIRS ${cuFile_INCLUDE_DIR})
endif ()
17 changes: 15 additions & 2 deletions java/src/main/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ endif(CUDA_STATIC_RUNTIME)
###################################################################################################
# - cmake modules ---------------------------------------------------------------------------------

set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/"
"${PROJECT_SOURCE_DIR}/../../../../cpp/cmake/Modules/"
${CMAKE_MODULE_PATH})

include(FeatureSummary)
include(CheckIncludeFiles)
Expand Down Expand Up @@ -262,6 +265,15 @@ endif(NVCOMP_FOUND)

add_library(nvcomp STATIC IMPORTED ${NVCOMP_LIB})

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

option(USE_GDS "Build with GPUDirect Storage (GDS)/cuFile support" OFF)
if(USE_GDS)
message(STATUS "Building with GPUDirect Storage (GDS)/cuFile support")
find_package(cuFile REQUIRED)
endif(USE_GDS)

###################################################################################################
# - include paths ---------------------------------------------------------------------------------

Expand All @@ -277,7 +289,8 @@ include_directories("${THRUST_INCLUDE}"
"${JNI_INCLUDE_DIRS}"
"${CUDF_INCLUDE}"
"${RMM_INCLUDE}"
"${ARROW_INCLUDE}")
"${ARROW_INCLUDE}"
"$<$<BOOL:${cuFile_FOUND}>:${cuFile_INCLUDE_DIRS}>")

###################################################################################################
# - library paths ---------------------------------------------------------------------------------
Expand Down

0 comments on commit 0e94bab

Please sign in to comment.