Skip to content

Commit

Permalink
Unify KVIKIO_CUFILE_FOUND (#243)
Browse files Browse the repository at this point in the history
Fixing a mismatch where CMake cannot find cuFile but later when compiling, GCC finds `cufile.h` using `__has_include()`.  

To fix this, CMake now defines `KVIKIO_CUFILE_FOUND` and we stop using `__has_include()`.

Authors:
  - Mads R. B. Kristensen (https://github.com/madsbk)

Approvers:
  - Lawrence Mitchell (https://github.com/wence-)

URL: #243
  • Loading branch information
madsbk authored Jun 20, 2023
1 parent d9eee8b commit 65f84e6
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 29 deletions.
4 changes: 3 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ 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 CUFILE_BATCH_API_FOUND)
target_compile_definitions(kvikio INTERFACE KVIKIO_CUFILE_BATCH_API_FOUND)
endif()
endif()
target_link_libraries(kvikio INTERFACE ${CMAKE_DL_LIBS})
Expand Down
3 changes: 0 additions & 3 deletions cpp/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ target_link_libraries(BASIC_IO_TEST PRIVATE kvikio CUDA::cudart)

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

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct BatchOp {
CUfileOpcode_t opcode;
};

#ifdef CUFILE_BATCH_API_FOUND
#ifdef KVIKIO_CUFILE_BATCH_API_FOUND

/**
* @brief Handle of an cuFile batch using semantic.
Expand Down
6 changes: 3 additions & 3 deletions cpp/include/kvikio/buffer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2022, NVIDIA CORPORATION.
* Copyright (c) 2021-2023, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,7 +50,7 @@ inline void buffer_register(const void* devPtr_base,
const std::vector<int>& errors_to_ignore = std::vector<int>())
{
if (defaults::compat_mode()) { return; }
#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND
CUfileError_t status = cuFileAPI::instance().BufRegister(devPtr_base, size, flags);
if (status.err != CU_FILE_SUCCESS) {
// Check if `status.err` is in `errors_to_ignore`
Expand All @@ -70,7 +70,7 @@ inline void buffer_register(const void* devPtr_base,
inline void buffer_deregister(const void* devPtr_base)
{
if (defaults::compat_mode()) { return; }
#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND
CUFILE_TRY(cuFileAPI::instance().BufDeregister(devPtr_base));
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/kvikio/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline void set_driver_flag(unsigned int& prop, unsigned int flag, bool val) noe
}
} // namespace detail

#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND

class DriverInitializer {
// Optional, if not used cuFiles opens the driver automatically
Expand Down Expand Up @@ -178,7 +178,7 @@ class DriverProperties {

[[nodiscard]] std::size_t get_max_batch_io_size()
{
#ifdef CUFILE_BATCH_API_FOUND
#ifdef KVIKIO_CUFILE_BATCH_API_FOUND
lazy_init();
return _props.max_batch_io_size;
#else
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct CUfileException : public std::runtime_error {
#define CUDA_DRIVER_TRY_1(_call) CUDA_DRIVER_TRY_2(_call, CUfileException)
#endif

#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND
#ifndef CUFILE_TRY
#define CUFILE_TRY(...) \
GET_CUFILE_TRY_MACRO(__VA_ARGS__, CUFILE_TRY_2, CUFILE_TRY_1) \
Expand Down
8 changes: 4 additions & 4 deletions cpp/include/kvikio/file_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class FileHandle {
}

if (_compat_mode) { return; }
#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND
CUfileDescr_t desc{}; // It is important to set to zero!
desc.type = CU_FILE_HANDLE_TYPE_OPAQUE_FD;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-union-access)
Expand Down Expand Up @@ -213,7 +213,7 @@ class FileHandle {
if (closed()) { return; }

if (!_compat_mode) {
#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND
cuFileAPI::instance().HandleDeregister(_handle);
#endif
}
Expand Down Expand Up @@ -308,7 +308,7 @@ class FileHandle {
if (_compat_mode) {
return posix_device_read(_fd_direct_off, devPtr_base, size, file_offset, devPtr_offset);
}
#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND
ssize_t ret = cuFileAPI::instance().Read(
_handle, devPtr_base, size, convert_size2off(file_offset), convert_size2off(devPtr_offset));
if (ret == -1) {
Expand Down Expand Up @@ -358,7 +358,7 @@ class FileHandle {
if (_compat_mode) {
return posix_device_write(_fd_direct_off, devPtr_base, size, file_offset, devPtr_offset);
}
#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND
ssize_t ret = cuFileAPI::instance().Write(
_handle, devPtr_base, size, convert_size2off(file_offset), convert_size2off(devPtr_offset));
if (ret == -1) {
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/kvikio/shim/cufile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

namespace kvikio {

#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND

/**
* @brief Shim layer of the cuFile C-API
Expand All @@ -47,7 +47,7 @@ class cuFileAPI {
decltype(cuFileDriverSetMaxCacheSize)* DriverSetMaxCacheSize{nullptr};
decltype(cuFileDriverSetMaxPinnedMemSize)* DriverSetMaxPinnedMemSize{nullptr};

#ifdef CUFILE_BATCH_API_FOUND
#ifdef KVIKIO_CUFILE_BATCH_API_FOUND
decltype(cuFileBatchIOSetUp)* BatchIOSetUp{nullptr};
decltype(cuFileBatchIOSubmit)* BatchIOSubmit{nullptr};
decltype(cuFileBatchIOGetStatus)* BatchIOGetStatus{nullptr};
Expand Down Expand Up @@ -83,7 +83,7 @@ class cuFileAPI {
get_symbol(DriverSetMaxCacheSize, lib, KVIKIO_STRINGIFY(cuFileDriverSetMaxCacheSize));
get_symbol(DriverSetMaxPinnedMemSize, lib, KVIKIO_STRINGIFY(cuFileDriverSetMaxPinnedMemSize));

#ifdef CUFILE_BATCH_API_FOUND
#ifdef KVIKIO_CUFILE_BATCH_API_FOUND
get_symbol(BatchIOSetUp, lib, KVIKIO_STRINGIFY(cuFileBatchIOSetUp));
get_symbol(BatchIOSubmit, lib, KVIKIO_STRINGIFY(cuFileBatchIOSubmit));
get_symbol(BatchIOGetStatus, lib, KVIKIO_STRINGIFY(cuFileBatchIOGetStatus));
Expand Down Expand Up @@ -141,7 +141,7 @@ class cuFileAPI {
*
* @return The boolean answer
*/
#ifdef KVIKIO_CUFILE_EXIST
#ifdef KVIKIO_CUFILE_FOUND
inline bool is_cufile_library_available()
{
try {
Expand Down Expand Up @@ -173,7 +173,7 @@ inline bool is_cufile_available()
*
* @return The boolean answer
*/
#ifdef CUFILE_BATCH_API_FOUND
#ifdef KVIKIO_CUFILE_BATCH_API_FOUND
inline bool is_batch_available()
{
try {
Expand Down
13 changes: 4 additions & 9 deletions cpp/include/kvikio/shim/cufile_h_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@

/**
* In order to support compilation when `cufile.h` isn't available, we
* wrap all use of cufile in a `#ifdef KVIKIO_CUFILE_EXIST` guard.
* wrap all use of cufile in a `#ifdef KVIKIO_CUFILE_FOUND` guard.
*
* The motivation here is to make KvikIO work in all circumstances so
* that libraries doesn't have to implement there own fallback solutions.
*/
#ifndef KVIKIO_DISABLE_CUFILE
#if __has_include(<cufile.h>)
#ifdef KVIKIO_CUFILE_FOUND
#include <cufile.h>
#define KVIKIO_CUFILE_EXIST
#endif
#endif

#ifndef KVIKIO_CUFILE_EXIST
#else
using CUfileDriverControlFlags_t = enum CUfileDriverControlFlags {
CU_FILE_USE_POLL_MODE = 0, /*!< use POLL mode. properties.use_poll_mode*/
CU_FILE_ALLOW_COMPAT_MODE = 1 /*!< allow COMPATIBILITY mode. properties.allow_compat_mode*/
Expand All @@ -39,7 +34,7 @@ using CUfileHandle_t = void*;

// If the Batch API isn't defined, we define some of the data types here.
// Notice, this doesn't need to be ABI compatible with the cufile definitions.
#ifndef CUFILE_BATCH_API_FOUND
#ifndef KVIKIO_CUFILE_BATCH_API_FOUND
typedef enum CUfileOpcode { CUFILE_READ = 0, CUFILE_WRITE } CUfileOpcode_t;

typedef enum CUFILEStatus_enum {
Expand Down

0 comments on commit 65f84e6

Please sign in to comment.