Skip to content

Commit

Permalink
Defer cuFile feature checks until finding kvikio package (#342)
Browse files Browse the repository at this point in the history
This PR closes #341.

The kvikio `INTERFACE_COMPILE_DEFINITIONS` were being set based on the packages available during the libkvikio conda build (e.g. CUDA 12.2 since #328), which might not be the same packages/versions as when libkvikio is actually being used (e.g. to build libcudf with CUDA 12.0). Because we built libkvikio with CUDA 12.2 and then tried to use it with CUDA 12.0 devcontainers, the build failed to find the cuFile Stream APIs that were introduced in CUDA 12.2.

This PR defers these definitions until the call to `find_package`, which will then use the exact cuFile features present (if cuFile is available at all) when building a package like cudf that depends on kvikio. The libkvikio example/test binary is built with the cuFile features available at build time, for use in the `libkvikio-tests` conda package. However, this test binary will still be compatible with a runtime where cuFile is unavailable or is version 12.0, as it is dlopen-ing the library and has runtime checks for the batch/stream features it tries to use.

I did local testing of this PR with cudf devcontainers. I tested both 12.0 and 12.2 to reproduce (and fix) the failure, and also tested clean builds of libcudf after removing `libcufile` (to test when cuFile is not found). All seems to work as intended.

Authors:
  - Bradley Dice (https://github.com/bdice)

Approvers:
  - Robert Maynard (https://github.com/robertmaynard)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #342
  • Loading branch information
bdice authored Feb 14, 2024
1 parent e5bc184 commit c434cef
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 14 deletions.
61 changes: 48 additions & 13 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# =============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# Copyright (c) 2021-2024, 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
Expand Down Expand Up @@ -70,14 +70,14 @@ else()
else()
set(cuFile_BATCH_API_FOUND TRUE)
endif()
message(STATUS "Found cuFile's Batch API: ${cuFile_BATCH_API_FOUND}")
message(STATUS "Found cuFile Batch API: ${cuFile_BATCH_API_FOUND}")
string(FIND "${CUFILE_H_STR}" "cuFileReadAsync" cuFileReadAsync_location)
if(cuFileReadAsync_location EQUAL "-1")
set(cuFile_STREAM_API_FOUND FALSE)
else()
set(cuFile_STREAM_API_FOUND TRUE)
endif()
message(STATUS "Found cuFile's Stream API: ${cuFile_STREAM_API_FOUND}")
message(STATUS "Found cuFile Stream API: ${cuFile_STREAM_API_FOUND}")
endif()

# library targets
Expand All @@ -91,16 +91,6 @@ target_include_directories(

target_link_libraries(kvikio INTERFACE Threads::Threads)
target_link_libraries(kvikio INTERFACE CUDA::toolkit)
if(cuFile_FOUND)
target_link_libraries(kvikio INTERFACE cufile::cuFile_interface)
target_compile_definitions(kvikio INTERFACE KVIKIO_CUFILE_FOUND)
if(cuFile_BATCH_API_FOUND)
target_compile_definitions(kvikio INTERFACE KVIKIO_CUFILE_BATCH_API_FOUND)
endif()
if(cuFile_STREAM_API_FOUND)
target_compile_definitions(kvikio INTERFACE KVIKIO_CUFILE_STREAM_API_FOUND)
endif()
endif()
target_link_libraries(kvikio INTERFACE ${CMAKE_DL_LIBS})
target_compile_features(kvikio INTERFACE cxx_std_17)

Expand Down Expand Up @@ -137,12 +127,56 @@ Provide targets for KvikIO: C++ bindings for cuFile.
]=]
)

set(final_code_string
[=[
get_property(already_set_kvikio DIRECTORY PROPERTY kvikio_already_set_defines SET)
if(NOT already_set_kvikio)
set_property(DIRECTORY PROPERTY kvikio_already_set_defines "ON")

# Find cuFile and determine which features are supported
find_package(cuFile QUIET)
if(NOT cuFile_FOUND)
message(WARNING "KvikIO: cuFile not found")
else()
file(READ "${cuFile_INCLUDE_DIRS}/cufile.h" CUFILE_H_STR)
string(FIND "${CUFILE_H_STR}" "cuFileBatchIOSetUp" cuFileBatchIOSetUp_location)
if(cuFileBatchIOSetUp_location EQUAL "-1")
set(cuFile_BATCH_API_FOUND FALSE)
else()
set(cuFile_BATCH_API_FOUND TRUE)
endif()
message(STATUS "KvikIO: Found cuFile Batch API: ${cuFile_BATCH_API_FOUND}")
string(FIND "${CUFILE_H_STR}" "cuFileReadAsync" cuFileReadAsync_location)
if(cuFileReadAsync_location EQUAL "-1")
set(cuFile_STREAM_API_FOUND FALSE)
else()
set(cuFile_STREAM_API_FOUND TRUE)
endif()
message(STATUS "KvikIO: Found cuFile Stream API: ${cuFile_STREAM_API_FOUND}")
endif()

# Enable supported cuFile features in KvikIO
if(cuFile_FOUND)
target_link_libraries(kvikio::kvikio INTERFACE cufile::cuFile_interface)
target_compile_definitions(kvikio::kvikio INTERFACE KVIKIO_CUFILE_FOUND)
if(cuFile_BATCH_API_FOUND)
target_compile_definitions(kvikio::kvikio INTERFACE KVIKIO_CUFILE_BATCH_API_FOUND)
endif()
if(cuFile_STREAM_API_FOUND)
target_compile_definitions(kvikio::kvikio INTERFACE KVIKIO_CUFILE_STREAM_API_FOUND)
endif()
endif()
endif()
]=]
)

rapids_export(
INSTALL kvikio
EXPORT_SET kvikio-exports
GLOBAL_TARGETS kvikio
NAMESPACE kvikio::
DOCUMENTATION doc_string
FINAL_CODE_BLOCK final_code_string
)

# build export targets
Expand All @@ -152,4 +186,5 @@ rapids_export(
GLOBAL_TARGETS kvikio
NAMESPACE kvikio::
DOCUMENTATION doc_string
FINAL_CODE_BLOCK final_code_string
)
14 changes: 13 additions & 1 deletion cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# =============================================================================
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
# Copyright (c) 2021-2024, 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
Expand All @@ -20,6 +20,18 @@ set_target_properties(BASIC_IO_TEST PROPERTIES INSTALL_RPATH "\$ORIGIN/../../lib
target_include_directories(BASIC_IO_TEST PRIVATE ../include ${cuFile_INCLUDE_DIRS})
target_link_libraries(BASIC_IO_TEST PRIVATE kvikio CUDA::cudart)

# Enable supported cuFile features in KvikIO examples
if(cuFile_FOUND)
target_link_libraries(BASIC_IO_TEST PRIVATE cufile::cuFile_interface)
target_compile_definitions(BASIC_IO_TEST PRIVATE KVIKIO_CUFILE_FOUND)
if(cuFile_BATCH_API_FOUND)
target_compile_definitions(BASIC_IO_TEST PRIVATE KVIKIO_CUFILE_BATCH_API_FOUND)
endif()
if(cuFile_STREAM_API_FOUND)
target_compile_definitions(BASIC_IO_TEST PRIVATE KVIKIO_CUFILE_STREAM_API_FOUND)
endif()
endif()

if(CMAKE_COMPILER_IS_GNUCXX)
set(KVIKIO_CXX_FLAGS "-Wall;-Werror;-Wno-unknown-pragmas")
target_compile_options(BASIC_IO_TEST PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${KVIKIO_CXX_FLAGS}>")
Expand Down

0 comments on commit c434cef

Please sign in to comment.