Skip to content

Commit

Permalink
Apply east const. Fix header issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kingcrimsontianyu committed Jan 23, 2025
1 parent 716a99f commit 008b63b
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 90 deletions.
6 changes: 3 additions & 3 deletions cpp/include/kvikio/batch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class BatchHandle {
/**
* @brief BatchHandle support move semantic but isn't copyable
*/
BatchHandle(const BatchHandle&) = delete;
BatchHandle(BatchHandle const&) = delete;
BatchHandle& operator=(BatchHandle const&) = delete;
BatchHandle(BatchHandle&& o) noexcept;
~BatchHandle() noexcept;
Expand All @@ -96,7 +96,7 @@ class BatchHandle {
* @param operations The vector of batch operations, which must not exceed the
* `max_num_events`.
*/
void submit(const std::vector<BatchOp>& operations);
void submit(std::vector<BatchOp> const& operations);

/**
* @brief Get status of submitted operations
Expand Down Expand Up @@ -127,7 +127,7 @@ class BatchHandle {

void close() noexcept;

void submit(const std::vector<BatchOp>& operations);
void submit(std::vector<BatchOp> const& operations);

std::vector<CUfileIOEvents_t> status(unsigned min_nr,
unsigned max_nr,
Expand Down
12 changes: 6 additions & 6 deletions cpp/include/kvikio/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ namespace kvikio {
* streaming buffer that is reused across multiple cuFile IO operations.
*/
/*NOLINTNEXTLINE(readability-function-cognitive-complexity)*/
void buffer_register(const void* devPtr_base,
void buffer_register(void const* devPtr_base,
std::size_t size,
int flags = 0,
const std::vector<int>& errors_to_ignore = std::vector<int>());
std::vector<int> const& errors_to_ignore = std::vector<int>());

/**
* @brief deregister an already registered device memory from cuFile
*
* @param devPtr_base device pointer to deregister
*/
void buffer_deregister(const void* devPtr_base);
void buffer_deregister(void const* devPtr_base);

/**
* @brief Register device memory allocation which is part of devPtr. Use this
Expand All @@ -61,15 +61,15 @@ void buffer_deregister(const void* devPtr_base);
* @warning This API is intended for usecases where the memory is used as
* streaming buffer that is reused across multiple cuFile IO operations.
*/
void memory_register(const void* devPtr,
void memory_register(void const* devPtr,
int flags = 0,
const std::vector<int>& errors_to_ignore = {});
std::vector<int> const& errors_to_ignore = {});

/**
* @brief deregister an already registered device memory from cuFile.
*
* @param devPtr device pointer to deregister
*/
void memory_deregister(const void* devPtr);
void memory_deregister(void const* devPtr);

} // namespace kvikio
2 changes: 1 addition & 1 deletion cpp/include/kvikio/defaults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ CompatMode parse_compat_mode_str(std::string_view compat_mode_str);
template <typename T>
T getenv_or(std::string_view env_var_name, T default_val)
{
const auto* env_val = std::getenv(env_var_name.data());
auto const* env_val = std::getenv(env_var_name.data());
if (env_val == nullptr) { return default_val; }

std::stringstream sstream(env_val);
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/kvikio/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct CUfileException : public std::runtime_error {

namespace detail {
template <typename Exception>
void cuda_driver_try_2(CUresult error, int line_number, const char* filename)
void cuda_driver_try_2(CUresult error, int line_number, char const* filename)
{
if (error == CUDA_ERROR_STUB_LIBRARY) {
throw Exception{std::string{"CUDA error at: "} + std::string(filename) + ":" +
Expand All @@ -76,8 +76,8 @@ void cuda_driver_try_2(CUresult error, int line_number, const char* filename)
"The CUDA driver loaded is a stub library)"};
}
if (error != CUDA_SUCCESS) {
const char* err_name = nullptr;
const char* err_str = nullptr;
char const* err_name = nullptr;
char const* err_str = nullptr;
CUresult err_name_status = cudaAPI::instance().GetErrorName(error, &err_name);
CUresult err_str_status = cudaAPI::instance().GetErrorString(error, &err_str);
if (err_name_status == CUDA_ERROR_INVALID_VALUE) { err_name = "unknown"; }
Expand All @@ -89,7 +89,7 @@ void cuda_driver_try_2(CUresult error, int line_number, const char* filename)
}

template <typename Exception>
void cufile_try_2(CUfileError_t error, int line_number, const char* filename)
void cufile_try_2(CUfileError_t error, int line_number, char const* filename)
{
if (error.err != CU_FILE_SUCCESS) {
if (error.err == CU_FILE_CUDA_DRIVER_ERROR) {
Expand All @@ -103,7 +103,7 @@ void cufile_try_2(CUfileError_t error, int line_number, const char* filename)
}

template <typename Exception>
void cufile_check_bytes_done_2(ssize_t nbytes_done, int line_number, const char* filename)
void cufile_check_bytes_done_2(ssize_t nbytes_done, int line_number, char const* filename)
{
if (nbytes_done < 0) {
auto const err = std::abs(nbytes_done);
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/kvikio/file_handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ class FileHandle {
* @param mode Access modes (see `open(2)`).
* @param compat_mode Set KvikIO's compatibility mode for this file.
*/
FileHandle(const std::string& file_path,
const std::string& flags = "r",
FileHandle(std::string const& file_path,
std::string const& flags = "r",
mode_t mode = m644,
CompatMode compat_mode = defaults::compat_mode());

/**
* @brief FileHandle support move semantic but isn't copyable
*/
FileHandle(const FileHandle&) = delete;
FileHandle(FileHandle const&) = delete;
FileHandle& operator=(FileHandle const&) = delete;
FileHandle(FileHandle&& o) noexcept;
FileHandle& operator=(FileHandle&& o) noexcept;
Expand Down Expand Up @@ -216,7 +216,7 @@ class FileHandle {
* case, the value of `sync_default_stream` is ignored.
* @return Size of bytes that were successfully written.
*/
std::size_t write(const void* devPtr_base,
std::size_t write(void const* devPtr_base,
std::size_t size,
std::size_t file_offset,
std::size_t devPtr_offset,
Expand Down Expand Up @@ -289,7 +289,7 @@ class FileHandle {
* @note The `std::future` object's `wait()` or `get()` should not be called after the lifetime of
* the FileHandle object ends. Otherwise, the behavior is undefined.
*/
std::future<std::size_t> pwrite(const void* buf,
std::future<std::size_t> pwrite(void const* buf,
std::size_t size,
std::size_t file_offset = 0,
std::size_t task_size = defaults::task_size(),
Expand Down
20 changes: 10 additions & 10 deletions cpp/include/kvikio/posix_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class StreamsByThread {

static CUstream get();

StreamsByThread(const StreamsByThread&) = delete;
StreamsByThread(StreamsByThread const&) = delete;
StreamsByThread& operator=(StreamsByThread const&) = delete;
StreamsByThread(StreamsByThread&& o) = delete;
StreamsByThread& operator=(StreamsByThread&& o) = delete;
Expand All @@ -88,11 +88,11 @@ class StreamsByThread {
* @return The number of bytes read or written (always gather than zero)
*/
template <IOOperationType Operation, PartialIO PartialIOStatus>
ssize_t posix_host_io(int fd, const void* buf, size_t count, off_t offset)
ssize_t posix_host_io(int fd, void const* buf, size_t count, off_t offset)
{
off_t cur_offset = offset;
size_t byte_remaining = count;
char* buffer = const_cast<char*>(static_cast<const char*>(buf));
char* buffer = const_cast<char*>(static_cast<char const*>(buf));
while (byte_remaining > 0) {
ssize_t nbytes = 0;
if constexpr (Operation == IOOperationType::READ) {
Expand All @@ -101,7 +101,7 @@ ssize_t posix_host_io(int fd, const void* buf, size_t count, off_t offset)
nbytes = ::pwrite(fd, buffer, byte_remaining, cur_offset);
}
if (nbytes == -1) {
const std::string name = Operation == IOOperationType::READ ? "pread" : "pwrite";
std::string const name = Operation == IOOperationType::READ ? "pread" : "pwrite";
if (errno == EBADF) {
throw CUfileException{std::string{"POSIX error on " + name + " at: "} + __FILE__ + ":" +
KVIKIO_STRINGIFY(__LINE__) + ": Operation not permitted"};
Expand Down Expand Up @@ -136,7 +136,7 @@ ssize_t posix_host_io(int fd, const void* buf, size_t count, off_t offset)
*/
template <IOOperationType Operation>
std::size_t posix_device_io(int fd,
const void* devPtr_base,
void const* devPtr_base,
std::size_t size,
std::size_t file_offset,
std::size_t devPtr_offset)
Expand All @@ -145,13 +145,13 @@ std::size_t posix_device_io(int fd,
CUdeviceptr devPtr = convert_void2deviceptr(devPtr_base) + devPtr_offset;
off_t cur_file_offset = convert_size2off(file_offset);
off_t byte_remaining = convert_size2off(size);
const off_t chunk_size2 = convert_size2off(alloc.size());
off_t const chunk_size2 = convert_size2off(alloc.size());

// Get a stream for the current CUDA context and thread
CUstream stream = StreamsByThread::get();

while (byte_remaining > 0) {
const off_t nbytes_requested = std::min(chunk_size2, byte_remaining);
off_t const nbytes_requested = std::min(chunk_size2, byte_remaining);
ssize_t nbytes_got = nbytes_requested;
if constexpr (Operation == IOOperationType::READ) {
nbytes_got = posix_host_io<IOOperationType::READ, PartialIO::YES>(
Expand Down Expand Up @@ -209,7 +209,7 @@ std::size_t posix_host_read(int fd, void* buf, std::size_t size, std::size_t fil
* @return Size of bytes that were successfully read.
*/
template <PartialIO PartialIOStatus>
std::size_t posix_host_write(int fd, const void* buf, std::size_t size, std::size_t file_offset)
std::size_t posix_host_write(int fd, void const* buf, std::size_t size, std::size_t file_offset)
{
KVIKIO_NVTX_SCOPED_RANGE("posix_host_write()", size);
return detail::posix_host_io<IOOperationType::WRITE, PartialIOStatus>(
Expand All @@ -230,7 +230,7 @@ std::size_t posix_host_write(int fd, const void* buf, std::size_t size, std::siz
* @return Size of bytes that were successfully read.
*/
std::size_t posix_device_read(int fd,
const void* devPtr_base,
void const* devPtr_base,
std::size_t size,
std::size_t file_offset,
std::size_t devPtr_offset);
Expand All @@ -249,7 +249,7 @@ std::size_t posix_device_read(int fd,
* @return Size of bytes that were successfully written.
*/
std::size_t posix_device_write(int fd,
const void* devPtr_base,
void const* devPtr_base,
std::size_t size,
std::size_t file_offset,
std::size_t devPtr_offset);
Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/shim/cufile_h_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct CUfileDescr_t {
} handle;
};

static inline const char* cufileop_status_error(CUfileOpError err) { return CUFILE_ERRSTR(err); };
inline static char const* cufileop_status_error(CUfileOpError err) { return CUFILE_ERRSTR(err); };
CUfileError_t cuFileHandleRegister(...);
CUfileError_t cuFileHandleDeregister(...);
ssize_t cuFileRead(...);
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/kvikio/shim/libcurl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
"cannot include the remote IO API, please build KvikIO with libcurl (-DKvikIO_REMOTE_SUPPORT=ON)"
#endif

#include <curl/curl.h>
#include <functional>
#include <memory>
#include <mutex>
#include <sstream>
#include <string>
#include <vector>

#include <curl/curl.h>

namespace kvikio {

/**
Expand Down
9 changes: 5 additions & 4 deletions cpp/include/kvikio/shim/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <dlfcn.h>
#include <sys/utsname.h>
#include <stdexcept>
#include <vector>

namespace kvikio {
Expand Down Expand Up @@ -44,15 +45,15 @@ namespace kvikio {
* @param name Name of the library to load.
* @return The library handle.
*/
void* load_library(const char* name, int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);
void* load_library(char const* name, int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);

/**
* @brief Load shared library
*
* @param names Vector of names to try when loading shared library.
* @return The library handle.
*/
void* load_library(const std::vector<const char*>& names,
void* load_library(std::vector<char const*> const& names,
int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NODELETE);

/**
Expand All @@ -64,12 +65,12 @@ void* load_library(const std::vector<const char*>& names,
* @param name Name of the symbol/function to load.
*/
template <typename T>
void get_symbol(T& handle, void* lib, const char* name)
void get_symbol(T& handle, void* lib, char const* name)
{
::dlerror(); // Clear old errors
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
handle = reinterpret_cast<T>(::dlsym(lib, name));
const char* err = ::dlerror();
char const* err = ::dlerror();
if (err != nullptr) { throw std::runtime_error(err); }
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/include/kvikio/stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class StreamFuture {
/**
* @brief StreamFuture support move semantic but isn't copyable
*/
StreamFuture(const StreamFuture&) = delete;
StreamFuture(StreamFuture const&) = delete;
StreamFuture& operator=(StreamFuture& o) = delete;
StreamFuture(StreamFuture&& o) noexcept;
StreamFuture& operator=(StreamFuture&& o) noexcept;
Expand Down
10 changes: 5 additions & 5 deletions cpp/include/kvikio/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ inline constexpr std::size_t page_size = 4096;

[[nodiscard]] ssize_t convert_size2ssize(std::size_t x);

[[nodiscard]] CUdeviceptr convert_void2deviceptr(const void* devPtr);
[[nodiscard]] CUdeviceptr convert_void2deviceptr(void const* devPtr);

/**
* @brief Help function to convert value to 64 bit signed integer
Expand Down Expand Up @@ -127,7 +127,7 @@ constexpr bool is_host_memory(const void* ptr) { return true; }
* @param devPtr Device pointer to query
* @return Usable CUDA context
*/
[[nodiscard]] CUcontext get_context_from_pointer(const void* devPtr);
[[nodiscard]] CUcontext get_context_from_pointer(void const* devPtr);

/**
* @brief Push CUDA context on creation and pop it on destruction
Expand All @@ -138,19 +138,19 @@ class PushAndPopContext {

public:
PushAndPopContext(CUcontext ctx);
PushAndPopContext(const PushAndPopContext&) = delete;
PushAndPopContext(PushAndPopContext const&) = delete;
PushAndPopContext& operator=(PushAndPopContext const&) = delete;
PushAndPopContext(PushAndPopContext&&) = delete;
PushAndPopContext&& operator=(PushAndPopContext&&) = delete;
~PushAndPopContext();
};

// Find the base and offset of the memory allocation `devPtr` is in
std::tuple<void*, std::size_t, std::size_t> get_alloc_info(const void* devPtr,
std::tuple<void*, std::size_t, std::size_t> get_alloc_info(void const* devPtr,
CUcontext* ctx = nullptr);

template <typename T>
bool is_future_done(const T& future)
bool is_future_done(T const& future)
{
return future.wait_for(std::chrono::seconds(0)) != std::future_status::timeout;
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/batch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ void BatchHandle::close() noexcept
cuFileAPI::instance().BatchIODestroy(_handle);
}

void BatchHandle::submit(const std::vector<BatchOp>& operations)
void BatchHandle::submit(std::vector<BatchOp> const& operations)
{
if (convert_size2ssize(operations.size()) > _max_num_events) {
throw CUfileException("Cannot submit more than the max_num_events)");
}
std::vector<CUfileIOParams_t> io_batch_params;
io_batch_params.reserve(operations.size());
for (const auto& op : operations) {
for (auto const& op : operations) {
if (op.file_handle.is_compat_mode_preferred()) {
throw CUfileException("Cannot submit a FileHandle opened in compatibility mode");
}
Expand Down Expand Up @@ -102,7 +102,7 @@ bool BatchHandle::closed() const noexcept { return true; }

void BatchHandle::close() noexcept {}

void BatchHandle::submit(const std::vector<BatchOp>& operations) {}
void BatchHandle::submit(std::vector<BatchOp> const& operations) {}

std::vector<CUfileIOEvents_t> BatchHandle::status(unsigned min_nr,
unsigned max_nr,
Expand Down
Loading

0 comments on commit 008b63b

Please sign in to comment.