KvikIO namespace. More...
Classes | |
struct | BatchOp |
IO operation used when submitting batches. More... | |
class | BatchHandle |
class | AllocRetain |
Singleton class to retain host memory allocations. More... | |
class | CompatModeManager |
Store and manage the compatibility mode data associated with a FileHandle. More... | |
struct | DriverInitializer |
struct | DriverProperties |
class | defaults |
Singleton class of default values used throughout KvikIO. More... | |
struct | CUfileException |
class | GenericSystemError |
class | FileHandle |
Handle of an open file registered with cufile. More... | |
class | FileWrapper |
Class that provides RAII for file handling. More... | |
class | CUFileHandleWrapper |
Class that provides RAII for the cuFile handle. More... | |
class | MmapHandle |
Handle of a memory-mapped file. More... | |
class | NvtxManager |
Utility singleton class for NVTX annotation. More... | |
class | RemoteEndpoint |
Abstract base class for remote endpoints. More... | |
class | HttpEndpoint |
A remote endpoint using http. More... | |
class | S3Endpoint |
A remote endpoint using AWS's S3 protocol. More... | |
class | RemoteHandle |
Handle of remote file. More... | |
class | cudaAPI |
Shim layer of the cuda C-API. More... | |
class | cuFileAPI |
Shim layer of the cuFile C-API. More... | |
class | LibCurl |
Singleton class to initialize and cleanup the global state of libcurl. More... | |
class | CurlHandle |
Representation of a curl easy handle pointer and its operations. More... | |
class | StreamFuture |
Future of an asynchronous IO operation. More... | |
class | thread_pool_wrapper |
class | PushAndPopContext |
Push CUDA context on creation and pop it on destruction. More... | |
Typedefs | |
using | nvtx_color_type = int |
using | BS_thread_pool = thread_pool_wrapper< BS::thread_pool > |
Enumerations | |
enum class | CompatMode : uint8_t { OFF , ON , AUTO } |
I/O compatibility mode. More... | |
Functions | |
void | buffer_register (void const *devPtr_base, std::size_t size, int flags=0, std::vector< int > const &errors_to_ignore=std::vector< int >()) |
register an existing cudaMalloced memory with cuFile to pin for GPUDirect Storage access. More... | |
void | buffer_deregister (void const *devPtr_base) |
deregister an already registered device memory from cuFile More... | |
void | memory_register (void const *devPtr, int flags=0, std::vector< int > const &errors_to_ignore={}) |
Register device memory allocation which is part of devPtr. Use this together with FileHandle::pread() and FileHandle::pwrite(). More... | |
void | memory_deregister (void const *devPtr) |
deregister an already registered device memory from cuFile. More... | |
KVIKIO_EXPORT std::string const & | config_path () |
Get the filepath to cuFile's config file (cufile.json ) or the empty string. More... | |
template<typename T > | |
T | getenv_or (std::string_view env_var_name, T default_val) |
template<> | |
bool | getenv_or (std::string_view env_var_name, bool default_val) |
template<> | |
CompatMode | getenv_or (std::string_view env_var_name, CompatMode default_val) |
template<> | |
std::vector< int > | getenv_or (std::string_view env_var_name, std::vector< int > default_val) |
template<typename T > | |
std::tuple< std::string_view, T, bool > | getenv_or (std::initializer_list< std::string_view > env_var_names, T default_val) |
Get the environment variable value from a candidate list. More... | |
int | open_fd_parse_flags (std::string const &flags, bool o_direct) |
Parse open file flags given as a string and return oflags. More... | |
int | open_fd (std::string const &file_path, std::string const &flags, bool o_direct, mode_t mode) |
Open file using open(2) More... | |
int | open_flags (int fd) |
Get the flags of the file descriptor (see open(2) ) More... | |
std::size_t | get_file_size (std::string const &file_path) |
Get file size from file descriptor fstat(3) More... | |
std::size_t | get_file_size (int file_descriptor) |
Get file size given the file path. More... | |
std::pair< std::size_t, std::size_t > | get_page_cache_info (std::string const &file_path) |
Obtain the page cache residency information for a given file. More... | |
std::pair< std::size_t, std::size_t > | get_page_cache_info (int fd) |
Obtain the page cache residency information for a given file. More... | |
bool | clear_page_cache (bool reclaim_dentries_and_inodes=true, bool clear_dirty_pages=true) |
Clear the page cache. More... | |
template<typename F , typename T > | |
std::future< std::size_t > | parallel_io (F op, T buf, std::size_t size, std::size_t file_offset, std::size_t task_size, std::size_t devPtr_offset, std::uint64_t call_idx=0, nvtx_color_type nvtx_color=NvtxManager::default_color()) |
Apply read or write operation in parallel. More... | |
constexpr bool | is_cuda_available () |
Check if the CUDA library is available. More... | |
constexpr bool | is_cufile_library_available () noexcept |
Check if the cuFile library is available. More... | |
bool | is_cufile_available () noexcept |
Check if the cuFile is available and expected to work. More... | |
int | cufile_version () noexcept |
Get cufile version (or zero if older than v1.8). More... | |
bool | is_batch_api_available () noexcept |
Check if cuFile's batch API is available. More... | |
bool | is_stream_api_available () noexcept |
Check if cuFile's stream (async) API is available. More... | |
void * | load_library (std::string const &name, int mode=RTLD_LAZY|RTLD_LOCAL|RTLD_NODELETE) |
Load shared library. More... | |
template<typename T > | |
void | get_symbol (T &handle, void *lib, std::string const &name) |
Get symbol using dlsym More... | |
bool | is_running_in_wsl () noexcept |
Try to detect if running in Windows Subsystem for Linux (WSL) More... | |
bool | run_udev_readable () noexcept |
Check if /run/udev is readable. More... | |
std::size_t | get_page_size () |
off_t | convert_size2off (std::size_t x) |
ssize_t | convert_size2ssize (std::size_t x) |
CUdeviceptr | convert_void2deviceptr (void const *devPtr) |
template<typename T , std::enable_if_t< std::is_integral_v< T >> * = nullptr> | |
std::int64_t | convert_to_64bit (T value) |
Help function to convert value to 64 bit signed integer. | |
std::uint64_t | convert_to_64bit (std::uint64_t value) |
Helper function to allow NVTX payload of type std::uint64_t to pass through without doing anything. | |
template<typename T , std::enable_if_t< std::is_floating_point_v< T >> * = nullptr> | |
double | convert_to_64bit (T value) |
Help function to convert value to 64 bit float. | |
constexpr bool | is_host_memory (void const *ptr) |
Check if ptr points to host memory (as opposed to device memory) More... | |
int | get_device_ordinal_from_pointer (CUdeviceptr dev_ptr) |
Return the device owning the pointer. More... | |
KVIKIO_EXPORT CUcontext | get_primary_cuda_context (int ordinal) |
Given a device ordinal, return the primary context of the device. More... | |
std::optional< CUcontext > | get_context_associated_pointer (CUdeviceptr dev_ptr) |
Return the CUDA context associated the given device pointer, if any. More... | |
bool | current_context_can_access_pointer (CUdeviceptr dev_ptr) |
Check if the current CUDA context can access the given device pointer. More... | |
CUcontext | get_context_from_pointer (void const *devPtr) |
Return a CUDA context that can be used with the given device pointer. More... | |
std::tuple< void *, std::size_t, std::size_t > | get_alloc_info (void const *devPtr, CUcontext *ctx=nullptr) |
template<typename T > | |
std::future< std::decay_t< T > > | make_ready_future (T &&t) |
Create a shared state in a future object that is immediately ready. More... | |
template<typename T > | |
bool | is_future_done (T const &future) |
Check the status of the future object. True indicates that the result is available in the future's shared state. False otherwise. More... | |
KvikIO namespace.
|
strong |
I/O compatibility mode.
Definition at line 28 of file compat_mode.hpp.
void kvikio::buffer_deregister | ( | void const * | devPtr_base | ) |
deregister an already registered device memory from cuFile
devPtr_base | device pointer to deregister |
void kvikio::buffer_register | ( | void const * | devPtr_base, |
std::size_t | size, | ||
int | flags = 0 , |
||
std::vector< int > const & | errors_to_ignore = std::vector< int >() |
||
) |
register an existing cudaMalloced memory with cuFile to pin for GPUDirect Storage access.
devPtr_base | device pointer to allocated |
size | size of memory region from the above specified devPtr |
flags | should be zero or CU_FILE_RDMA_REGISTER (experimental) |
errors_to_ignore | CuFile errors to ignore such as CU_FILE_MEMORY_ALREADY_REGISTERED or CU_FILE_INVALID_MAPPING_SIZE |
bool kvikio::clear_page_cache | ( | bool | reclaim_dentries_and_inodes = true , |
bool | clear_dirty_pages = true |
||
) |
Clear the page cache.
reclaim_dentries_and_inodes | Whether to free reclaimable slab objects which include dentries and inodes.
|
clear_dirty_pages | Whether to trigger the writeback process to clear the dirty pages. If true , sync will be called prior to cache clearing. |
sudo
prefix. This is for the superuser and also for specially configured systems where unprivileged users cannot execute /usr/bin/sudo
but can execute /sbin/sysctl
. If this step succeeds, the function returns true
immediately.sudo
prefix. This is for the general case where selective unprivileged users have permission to run /sbin/sysctl
with sudo
prefix.kvikio::GenericSystemError | if somehow the child process could not be created. |
KVIKIO_EXPORT std::string const& kvikio::config_path | ( | ) |
Get the filepath to cuFile's config file (cufile.json
) or the empty string.
This lookup is cached.
|
noexcept |
Get cufile version (or zero if older than v1.8).
The version is returned as (1000*major + 10*minor). E.g., cufile v1.8.0 would be represented by 1080.
Notice, this is not the version of the CUDA toolkit. cufile is part of the toolkit but follows its own version scheme.
bool kvikio::current_context_can_access_pointer | ( | CUdeviceptr | dev_ptr | ) |
Check if the current CUDA context can access the given device pointer.
dev_ptr | Device pointer to query |
std::optional<CUcontext> kvikio::get_context_associated_pointer | ( | CUdeviceptr | dev_ptr | ) |
Return the CUDA context associated the given device pointer, if any.
dev_ptr | Device pointer to query |
CUcontext kvikio::get_context_from_pointer | ( | void const * | devPtr | ) |
Return a CUDA context that can be used with the given device pointer.
For robustness, we look for an usabale context in the following order: 1) If a context has been associated with devPtr
, it is returned. 2) If the current context exists and can access devPtr
, it is returned. 3) Return the primary context of the device that owns devPtr
. We assume the primary context can access devPtr
, which might not be true in the exceptional disjoint addressing cases mention in the CUDA docs[1]. In these cases, the user has to set an usable current context before reading/writing using KvikIO.
[1] https://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__UNIFIED.html
devPtr | Device pointer to query |
int kvikio::get_device_ordinal_from_pointer | ( | CUdeviceptr | dev_ptr | ) |
Return the device owning the pointer.
ptr | Device pointer to query |
std::size_t kvikio::get_file_size | ( | int | file_descriptor | ) |
Get file size given the file path.
file_path | Path to a file |
std::size_t kvikio::get_file_size | ( | std::string const & | file_path | ) |
Get file size from file descriptor fstat(3)
file_descriptor | Open file descriptor |
std::pair<std::size_t, std::size_t> kvikio::get_page_cache_info | ( | int | fd | ) |
Obtain the page cache residency information for a given file.
fd | File descriptor. |
get_page_cache_info(std::string const&)
overload. std::pair<std::size_t, std::size_t> kvikio::get_page_cache_info | ( | std::string const & | file_path | ) |
Obtain the page cache residency information for a given file.
file_path | Path to a file. |
KVIKIO_EXPORT CUcontext kvikio::get_primary_cuda_context | ( | int | ordinal | ) |
Given a device ordinal, return the primary context of the device.
This function caches the primary contexts retrieved until program exit
ordinal | Device ordinal - an integer between 0 and the number of CUDA devices |
void kvikio::get_symbol | ( | T & | handle, |
void * | lib, | ||
std::string const & | name | ||
) |
Get symbol using dlsym
T | The type of the function pointer. |
handle | The function pointer (output). |
lib | The library handle returned by dlopen . |
name | Name of the symbol/function to load. |
Definition at line 60 of file shim/utils.hpp.
std::tuple<std::string_view, T, bool> kvikio::getenv_or | ( | std::initializer_list< std::string_view > | env_var_names, |
T | default_val | ||
) |
Get the environment variable value from a candidate list.
T | Type of the environment variable value |
env_var_names | Candidate list containing the names of environment variable |
default_val | Default value of the environment variable, if none of the candidates has been found |
env_var_name
, result
, has_found
), where:has_found
will be false, result
will be default_val
, and env_var_name
will be empty.env_var_name
, then has_found
will be true, and result
be the set value. If more than one candidates have been set with the same value, env_var_name
will be assigned the last candidate.std::invalid_argument | if:
|
Definition at line 88 of file defaults.hpp.
|
noexcept |
Check if cuFile's batch API is available.
Since cuFileGetVersion()
first became available in cufile v1.8 (CTK v12.3), this function returns false for versions older than v1.8 even though the batch API became available in v1.6.
|
constexpr |
|
noexcept |
Check if the cuFile is available and expected to work.
Besides checking if the cuFile library is available, this also checks the runtime environment.
|
constexprnoexcept |
Check if the cuFile library is available.
Notice, this doesn't check if the runtime environment supports cuFile.
Definition at line 98 of file cufile.hpp.
bool kvikio::is_future_done | ( | T const & | future | ) |
Check the status of the future object. True indicates that the result is available in the future's shared state. False otherwise.
The future shall not be created using std::async(std::launch::deferred)
. Otherwise, this function always returns true.
T | Type of the future. |
future | Instance of the future. |
|
constexpr |
|
noexcept |
Try to detect if running in Windows Subsystem for Linux (WSL)
When unable to determine environment, false
is returned.
|
noexcept |
Check if cuFile's stream (async) API is available.
Since cuFileGetVersion()
first became available in cufile v1.8 (CTK v12.3), this function returns false for versions older than v1.8 even though the stream API became available in v1.7.
void* kvikio::load_library | ( | std::string const & | name, |
int | mode = RTLD_LAZY|RTLD_LOCAL|RTLD_NODELETE |
||
) |
Load shared library.
name | Name of the library to load. |
std::future<std::decay_t<T> > kvikio::make_ready_future | ( | T && | t | ) |
Create a shared state in a future object that is immediately ready.
A partial implementation of the namesake function from the concurrency TS (https://en.cppreference.com/w/cpp/experimental/make_ready_future). The cases of std::reference_wrapper and void are not implemented.
T | Type of the value provided. |
t | Object provided. |
void kvikio::memory_deregister | ( | void const * | devPtr | ) |
deregister an already registered device memory from cuFile.
devPtr | device pointer to deregister |
void kvikio::memory_register | ( | void const * | devPtr, |
int | flags = 0 , |
||
std::vector< int > const & | errors_to_ignore = {} |
||
) |
Register device memory allocation which is part of devPtr. Use this together with FileHandle::pread() and FileHandle::pwrite().
devPtr | Device pointer |
flags | Should be zero or CU_FILE_RDMA_REGISTER (experimental) |
errors_to_ignore | CuFile errors to ignore such as CU_FILE_MEMORY_ALREADY_REGISTERED or CU_FILE_INVALID_MAPPING_SIZE |
int kvikio::open_fd | ( | std::string const & | file_path, |
std::string const & | flags, | ||
bool | o_direct, | ||
mode_t | mode | ||
) |
Open file using open(2)
flags | Open flags given as a string |
o_direct | Append O_DIRECT to flags |
mode | Access modes |
int kvikio::open_fd_parse_flags | ( | std::string const & | flags, |
bool | o_direct | ||
) |
Parse open file flags given as a string and return oflags.
flags | The flags |
o_direct | Append O_DIRECT to the open flags |
std::invalid_argument | if the specified flags are not supported. |
std::invalid_argument | if o_direct is true, but O_DIRECT is not supported. |
int kvikio::open_flags | ( | int | fd | ) |
Get the flags of the file descriptor (see open(2)
)
std::future<std::size_t> kvikio::parallel_io | ( | F | op, |
T | buf, | ||
std::size_t | size, | ||
std::size_t | file_offset, | ||
std::size_t | task_size, | ||
std::size_t | devPtr_offset, | ||
std::uint64_t | call_idx = 0 , |
||
nvtx_color_type | nvtx_color = NvtxManager::default_color() |
||
) |
Apply read or write operation in parallel.
F | The type of the function applying the read or write operation. |
T | The type of the memory pointer. |
op | The function applying the read or write operation. |
buf | Buffer pointer to read or write to. |
size | Number of bytes to read or write. |
file_offset | Byte offset to the start of the file. |
task_size | Size of each task in bytes. |
Definition at line 141 of file parallel_operation.hpp.
|
noexcept |
Check if /run/udev
is readable.
cuFile files with internal error
when /run/udev
isn't readable. This typically happens when running inside a docker image not launched with --volume /run/udev:/run/udev:ro
.