Skip to content

Commit

Permalink
Replace FindcuFile with upstream FindCUDAToolkit support (#542)
Browse files Browse the repository at this point in the history
CMake's `FindCUDAToolkit` has supported cuFile since 3.25. Use this support and remove the custom `FindcuFile` module.

Authors:
  - Kyle Edwards (https://github.com/KyleFromNVIDIA)

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

URL: #542
  • Loading branch information
KyleFromNVIDIA authored Nov 9, 2024
1 parent d66e3fa commit 0f7c0c7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 163 deletions.
101 changes: 61 additions & 40 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,42 +64,52 @@ if(KvikIO_REMOTE_SUPPORT)
include(cmake/thirdparty/get_libcurl.cmake)
endif()

set(cuFile_FOUND 0)
if(KvikIO_CUDA_SUPPORT)
rapids_find_package(
CUDAToolkit REQUIRED
BUILD_EXPORT_SET kvikio-exports
INSTALL_EXPORT_SET kvikio-exports
)
include(cmake/thirdparty/get_nvtx.cmake)
endif()

rapids_find_package(
cuFile
BUILD_EXPORT_SET kvikio-exports
INSTALL_EXPORT_SET kvikio-exports
)

if(NOT cuFile_FOUND)
message(
WARNING "Cannot find cuFile - KvikIO will still work but won't use GPUDirect Storage (GDS)"
)
else()
# Check batch and stream API support (cuFile_BATCH_API_FOUND and cuFile_STREAM_API_FOUND)
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)
if(NOT TARGET CUDA::cuFile)
message(
WARNING "Cannot find cuFile - KvikIO will still work but won't use GPUDirect Storage (GDS)"
)
else()
set(cuFile_BATCH_API_FOUND TRUE)
set(cuFile_FOUND 1)

# Check batch and stream API support (cuFile_BATCH_API_FOUND and cuFile_STREAM_API_FOUND)
try_compile(
cuFile_BATCH_API_FOUND SOURCE_FROM_CONTENT
batch.cpp
[[#include <cufile.h>
int main() {
cuFileBatchIOSetUp(nullptr, 0);
return 0;
}
]]
LINK_LIBRARIES CUDA::cuFile rt ${CMAKE_DL_LIBS}
OUTPUT_VARIABLE batch_output
)
message(STATUS "Found cuFile Batch API: ${cuFile_BATCH_API_FOUND}")
try_compile(
cuFile_STREAM_API_FOUND SOURCE_FROM_CONTENT
stream.cpp
[[#include <cufile.h>
int main() {
CUfileHandle_t fh;
CUstream stream;
cuFileReadAsync(fh, nullptr, nullptr, nullptr, nullptr, nullptr, stream);
return 0;
}
]]
LINK_LIBRARIES CUDA::cuFile rt ${CMAKE_DL_LIBS}
OUTPUT_VARIABLE stream_output
)
message(STATUS "Found cuFile Stream API: ${cuFile_STREAM_API_FOUND}")
endif()
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 Stream API: ${cuFile_STREAM_API_FOUND}")
endif()

include(cmake/thirdparty/get_thread_pool.cmake)
Expand All @@ -126,18 +136,14 @@ add_library(kvikio::kvikio ALIAS kvikio)
target_include_directories(
kvikio
PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<BUILD_INTERFACE:$<$<BOOL:${KvikIO_CUDA_SUPPORT}>:${CUDAToolkit_INCLUDE_DIRS}>>"
INTERFACE "$<INSTALL_INTERFACE:include>"
)

# Notice, we do not link to cuda or cufile since KvikIO opens them manually using `dlopen()`.
target_link_libraries(
kvikio
PUBLIC Threads::Threads
BS::thread_pool
${CMAKE_DL_LIBS}
$<TARGET_NAME_IF_EXISTS:nvtx3::nvtx3-cpp>
$<COMPILE_ONLY:$<TARGET_NAME_IF_EXISTS:CUDA::cudart>>
$<COMPILE_ONLY:$<TARGET_NAME_IF_EXISTS:cufile::cufile>>
PUBLIC Threads::Threads BS::thread_pool ${CMAKE_DL_LIBS} $<TARGET_NAME_IF_EXISTS:nvtx3::nvtx3-cpp>
PRIVATE $<TARGET_NAME_IF_EXISTS:CURL::libcurl>
)

Expand Down Expand Up @@ -200,26 +206,40 @@ install(
install(DIRECTORY include/kvikio/ DESTINATION include/kvikio)
install(FILES ${KvikIO_BINARY_DIR}/include/kvikio/version_config.hpp DESTINATION include/kvikio)

include("${rapids-cmake-dir}/export/find_package_file.cmake")
rapids_export_find_package_file(
BUILD "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/FindcuFile.cmake" EXPORT_SET kvikio-exports
)
rapids_export_find_package_file(
INSTALL "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/FindcuFile.cmake" EXPORT_SET kvikio-exports
)

set(doc_string
[=[
Provide targets for KvikIO.
]=]
)

set(final_code_string
"
set(KvikIO_CUDA_SUPPORT [=[${KvikIO_CUDA_SUPPORT}]=])
set(KvikIO_CUFILE_SUPPORT [=[${cuFile_FOUND}]=])
"
)
string(
APPEND
final_code_string
[=[
if(KvikIO_CUDA_SUPPORT)
find_package(CUDAToolkit REQUIRED QUIET)
target_include_directories(kvikio::kvikio INTERFACE ${CUDAToolkit_INCLUDE_DIRS})

if(KvikIO_CUFILE_SUPPORT AND NOT TARGET CUDA::cuFile)
message(FATAL_ERROR "Compiled with cuFile support but cuFile not found")
endif()
endif()
]=]
)

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

rapids_export(
Expand All @@ -228,4 +248,5 @@ rapids_export(
GLOBAL_TARGETS kvikio
NAMESPACE kvikio::
DOCUMENTATION doc_string
FINAL_CODE_BLOCK final_code_string
)
120 changes: 0 additions & 120 deletions cpp/cmake/Modules/FindcuFile.cmake

This file was deleted.

3 changes: 0 additions & 3 deletions python/kvikio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ project(

option(USE_NVCOMP_RUNTIME_WHEEL "Use the nvcomp wheel at runtime instead of the system library" OFF)

# TODO: Should we symlink FindcuFile.cmake into python/cmake? find cuFile
include(../../cpp/cmake/Modules/FindcuFile.cmake)

find_package(kvikio REQUIRED "${RAPIDS_VERSION}")

find_package(CUDAToolkit REQUIRED)
Expand Down

0 comments on commit 0f7c0c7

Please sign in to comment.