From d5ca0a2c838f88c8968f8af6a57f494188217a31 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Fri, 31 Oct 2025 16:45:11 -0600 Subject: [PATCH 1/2] rocFile: Consolidate namesapces to a single rocFile namespace Also renames some exceptions to implicitly "namespace" them. --- rocfile/src/async.cpp | 11 +++---- rocfile/src/async.h | 14 ++++----- rocfile/src/backend.h | 9 +++--- rocfile/src/backend/asyncop-fallback.cpp | 15 +++++----- rocfile/src/backend/asyncop-fallback.h | 10 +++---- rocfile/src/backend/fallback.cpp | 20 +++++-------- rocfile/src/backend/fallback.h | 14 ++++----- rocfile/src/batch/batch.cpp | 10 +++---- rocfile/src/batch/batch.h | 14 ++++----- rocfile/src/buffer.cpp | 16 +++++----- rocfile/src/buffer.h | 14 ++++----- rocfile/src/context.cpp | 2 +- rocfile/src/context.h | 2 +- rocfile/src/file.cpp | 10 +++---- rocfile/src/file.h | 14 ++++----- rocfile/src/hip.cpp | 10 +++---- rocfile/src/hip.h | 1 + rocfile/src/io.h | 2 +- rocfile/src/mountinfo.cpp | 1 - rocfile/src/rocfile-private.cpp | 2 +- rocfile/src/rocfile-private.h | 2 +- rocfile/src/rocfile.cpp | 31 +++++++++----------- rocfile/src/state.cpp | 20 +++++-------- rocfile/src/state.h | 37 ++++++++++++------------ rocfile/src/stream.cpp | 4 +-- rocfile/src/stream.h | 2 +- rocfile/src/sys.cpp | 4 ++- rocfile/test/async.cpp | 21 ++++++-------- rocfile/test/batch/batch.cpp | 22 ++++++-------- rocfile/test/batch/batch_mt.cpp | 2 +- rocfile/test/buffer.cpp | 20 +++++-------- rocfile/test/context.cpp | 4 +-- rocfile/test/handle.cpp | 11 +++---- rocfile/test/io.cpp | 25 +++++++--------- rocfile/test/mbackend.h | 9 +++--- rocfile/test/mbatch.h | 2 +- rocfile/test/mbuffer.h | 8 ++--- rocfile/test/mfile.h | 6 ++-- rocfile/test/mhip.h | 2 +- rocfile/test/mmountinfo.h | 4 +-- rocfile/test/mstate.h | 14 ++++----- rocfile/test/mstream.h | 2 +- rocfile/test/msys.h | 2 +- rocfile/test/rocfile.cpp | 2 +- rocfile/test/state_mt.cpp | 4 +-- rocfile/test/stream.cpp | 9 +++--- 46 files changed, 208 insertions(+), 252 deletions(-) diff --git a/rocfile/src/async.cpp b/rocfile/src/async.cpp index e6c0ec39..fddd8455 100644 --- a/rocfile/src/async.cpp +++ b/rocfile/src/async.cpp @@ -10,8 +10,7 @@ #include #include -using namespace rocFile::async; -using rocFile::context::Context; +namespace rocFile { AsyncMonitor::AsyncMonitor() : is_finished{false} { @@ -78,9 +77,9 @@ AsyncMonitor::completion_thread() } } -AsyncOp::AsyncOp(io::IoType _io_type, std::shared_ptr _file, - std::shared_ptr _buffer, std::shared_ptr _stream, - size_t *_size, off_t *_file_offset, off_t *_buffer_offset, ssize_t *_bytes_transferred) +AsyncOp::AsyncOp(IoType _io_type, std::shared_ptr _file, std::shared_ptr _buffer, + std::shared_ptr _stream, size_t *_size, off_t *_file_offset, off_t *_buffer_offset, + ssize_t *_bytes_transferred) : io_type{_io_type}, file{_file}, buffer{_buffer}, stream{_stream}, size{stream->fixedIOSize() ? std::variant{*_size} @@ -96,3 +95,5 @@ AsyncOp::AsyncOp(io::IoType _io_type, std::shared_ptr _file, AsyncOp::~AsyncOp() { } + +} diff --git a/rocfile/src/async.h b/rocfile/src/async.h index 19615c47..548aec98 100644 --- a/rocfile/src/async.h +++ b/rocfile/src/async.h @@ -18,14 +18,14 @@ #include #include -namespace rocFile::async { +namespace rocFile { class AsyncOp { public: - const io::IoType io_type; - std::shared_ptr file; - std::shared_ptr buffer; - std::shared_ptr stream; + const IoType io_type; + std::shared_ptr file; + std::shared_ptr buffer; + std::shared_ptr stream; std::variant size; std::variant file_offset; std::variant buffer_offset; @@ -37,8 +37,8 @@ class AsyncOp { AsyncOp &&operator=(AsyncOp &&) = delete; virtual ~AsyncOp(); - AsyncOp(io::IoType ioType, std::shared_ptr file, std::shared_ptr buffer, - std::shared_ptr stream, size_t *size, off_t *file_offset, off_t *buffer_offset, + AsyncOp(IoType ioType, std::shared_ptr file, std::shared_ptr buffer, + std::shared_ptr stream, size_t *size, off_t *file_offset, off_t *buffer_offset, ssize_t *bytes_transferred); }; diff --git a/rocfile/src/backend.h b/rocfile/src/backend.h index 7ee42a5e..2ec93c39 100644 --- a/rocfile/src/backend.h +++ b/rocfile/src/backend.h @@ -16,7 +16,7 @@ #include #include -namespace rocFile::backend { +namespace rocFile { // The maximum number of bytes that can be transferred in a single read() or // write() system call. Mirrors kernel's MAX_RW_COUNT @@ -39,7 +39,7 @@ struct Backend { /// @param file_offset Offset from the start of the file /// @param buffer_offset Offset from the start of the buffer /// @return - virtual int score(std::shared_ptr file, std::shared_ptr buffer, size_t size, + virtual int score(std::shared_ptr file, std::shared_ptr buffer, size_t size, off_t file_offset, off_t buffer_offset) const = 0; /// @brief Perform a read or write operation @@ -54,9 +54,8 @@ struct Backend { /// @return Number of bytes transferred, negative on error /// /// @throws Hip::RuntimeError Sys::RuntimeError - virtual ssize_t io(rocFile::io::IoType type, std::shared_ptr file, - std::shared_ptr buffer, size_t size, off_t file_offset, - off_t buffer_offset) = 0; + virtual ssize_t io(IoType type, std::shared_ptr file, std::shared_ptr buffer, size_t size, + off_t file_offset, off_t buffer_offset) = 0; }; } diff --git a/rocfile/src/backend/asyncop-fallback.cpp b/rocfile/src/backend/asyncop-fallback.cpp index 5d5d37ed..508db3ed 100644 --- a/rocfile/src/backend/asyncop-fallback.cpp +++ b/rocfile/src/backend/asyncop-fallback.cpp @@ -10,24 +10,23 @@ #include #include -using namespace rocFile::backend; -using rocFile::context::Context; +using namespace rocFile; static void hipHostDeleter(void *buffer) { try { - Context::get()->hipHostFree(buffer); + Context::get()->hipHostFree(buffer); } catch (...) { - Context::get()->syslog(LOG_CRIT, "Error freeing pinned host memory."); + Context::get()->syslog(LOG_CRIT, "Error freeing pinned host memory."); } } -AsyncOpFallback::AsyncOpFallback(io::IoType _io_type, std::shared_ptr _file, - std::shared_ptr _buffer, - std::shared_ptr _stream, size_t *_size, off_t *_file_offset, - off_t *_buffer_offset, ssize_t *_bytes_transferred) +AsyncOpFallback::AsyncOpFallback(IoType _io_type, std::shared_ptr _file, + std::shared_ptr _buffer, std::shared_ptr _stream, + size_t *_size, off_t *_file_offset, off_t *_buffer_offset, + ssize_t *_bytes_transferred) : AsyncOp{_io_type, _file, _buffer, _stream, _size, _file_offset, _buffer_offset, _bytes_transferred}, bytes_transferred_internal{0}, gpu_buffer{buffer->getBuffer()}, bounce_buffer_dev_ptr{nullptr}, bounce_buffer{nullptr, [](void *addr) { (void)addr; }} diff --git a/rocfile/src/backend/asyncop-fallback.h b/rocfile/src/backend/asyncop-fallback.h index a13a2a4b..ddab828e 100644 --- a/rocfile/src/backend/asyncop-fallback.h +++ b/rocfile/src/backend/asyncop-fallback.h @@ -6,9 +6,9 @@ #include "async.h" -namespace rocFile::backend { +namespace rocFile { -struct AsyncOpFallback : async::AsyncOp { +struct AsyncOpFallback : AsyncOp { ssize_t bytes_transferred_internal; void *const gpu_buffer; void *bounce_buffer_dev_ptr; @@ -17,9 +17,9 @@ struct AsyncOpFallback : async::AsyncOp { std::unique_ptr bounce_buffer; public: - AsyncOpFallback(io::IoType ioType, std::shared_ptr file, - std::shared_ptr buffer, std::shared_ptr stream, - size_t *size, off_t *fileOffset, off_t *bufferOffset, ssize_t *bytesTransferred); + AsyncOpFallback(IoType ioType, std::shared_ptr file, std::shared_ptr buffer, + std::shared_ptr stream, size_t *size, off_t *fileOffset, off_t *bufferOffset, + ssize_t *bytesTransferred); void *bounceBufferHostPtr(); void *devPtr(); diff --git a/rocfile/src/backend/fallback.cpp b/rocfile/src/backend/fallback.cpp index 0c499cb5..f9f1860e 100644 --- a/rocfile/src/backend/fallback.cpp +++ b/rocfile/src/backend/fallback.cpp @@ -11,11 +11,7 @@ #include using namespace rocFile; -using namespace rocFile::backend; -using rocFile::buffer::IBuffer; -using rocFile::context::Context; -using rocFile::file::IFile; using std::min; using std::shared_ptr; using std::unique_ptr; @@ -23,8 +19,8 @@ using std::unique_ptr; static const size_t DefaultChunkSize = 16 * 1024 * 1024; int -Fallback::score(std::shared_ptr file, std::shared_ptr buffer, size_t size, - off_t file_offset, off_t buffer_offset) const +Fallback::score(std::shared_ptr file, std::shared_ptr buffer, size_t size, off_t file_offset, + off_t buffer_offset) const { (void)buffer_offset; (void)file; @@ -34,17 +30,17 @@ Fallback::score(std::shared_ptr file, std::shared_ptr file, std::shared_ptr buffer, - size_t size, off_t file_offset, off_t buffer_offset) +Fallback::io(IoType type, std::shared_ptr file, std::shared_ptr buffer, size_t size, + off_t file_offset, off_t buffer_offset) { return io(type, file, buffer, size, file_offset, buffer_offset, DefaultChunkSize); } ssize_t -Fallback::io(io::IoType io_type, shared_ptr file, shared_ptr buffer, size_t size, +Fallback::io(IoType io_type, shared_ptr file, shared_ptr buffer, size_t size, off_t file_offset, off_t buffer_offset, size_t chunk_size) { - size = min(size, rocFile::backend::MAX_RW_COUNT); + size = min(size, rocFile::MAX_RW_COUNT); if ((buffer_offset < 0) || (buffer->getLength() <= static_cast(buffer_offset)) || (buffer->getLength() - static_cast(buffer_offset) < size)) { @@ -74,14 +70,14 @@ Fallback::io(io::IoType io_type, shared_ptr file, shared_ptr buf static_cast(total_io_bytes)); try { switch (io_type) { - case io::IoType::Read: + case IoType::Read: io_bytes = Context::get()->pread(file->getFd(), bounce_buffer.get(), count, offset); if (io_bytes > 0) { Context::get()->hipMemcpy(device_buffer_position, bounce_buffer.get(), static_cast(io_bytes), hipMemcpyHostToDevice); } break; - case io::IoType::Write: + case IoType::Write: Context::get()->hipMemcpy(bounce_buffer.get(), device_buffer_position, count, hipMemcpyDeviceToHost); Context::get()->hipStreamSynchronize(nullptr); diff --git a/rocfile/src/backend/fallback.h b/rocfile/src/backend/fallback.h index 1d03e592..fe81a01b 100644 --- a/rocfile/src/backend/fallback.h +++ b/rocfile/src/backend/fallback.h @@ -9,22 +9,22 @@ #include "file.h" #include "io.h" -namespace rocFile::backend { +namespace rocFile { struct Fallback : public Backend { virtual ~Fallback() override = default; - int score(std::shared_ptr file, std::shared_ptr buffer, size_t size, - off_t file_offset, off_t buffer_offset) const override; + int score(std::shared_ptr file, std::shared_ptr buffer, size_t size, off_t file_offset, + off_t buffer_offset) const override; - ssize_t io(io::IoType type, std::shared_ptr file, std::shared_ptr buffer, - size_t size, off_t file_offset, off_t buffer_offset) override; + ssize_t io(IoType type, std::shared_ptr file, std::shared_ptr buffer, size_t size, + off_t file_offset, off_t buffer_offset) override; // Once we can import gtest.h and make test suites or test friends everything // below here should be made protected. // protected: - ssize_t io(io::IoType type, std::shared_ptr file, std::shared_ptr buffer, - size_t size, off_t file_offset, off_t buffer_offset, size_t chunk_size); + ssize_t io(IoType type, std::shared_ptr file, std::shared_ptr buffer, size_t size, + off_t file_offset, off_t buffer_offset, size_t chunk_size); }; } diff --git a/rocfile/src/batch/batch.cpp b/rocfile/src/batch/batch.cpp index 9f869c25..3f92eb74 100644 --- a/rocfile/src/batch/batch.cpp +++ b/rocfile/src/batch/batch.cpp @@ -18,10 +18,10 @@ #include #include -namespace rocFile::batch { +namespace rocFile { BatchOperation::BatchOperation(std::unique_ptr params, - std::shared_ptr _buffer, std::shared_ptr _file) + std::shared_ptr _buffer, std::shared_ptr _file) : io_params{std::move(params)}, buffer{_buffer}, file{_file} { // Cookie allows the user to track which operation caused the error. @@ -120,7 +120,7 @@ BatchContext::submit_operations(const rocFileIOParams_t *params, unsigned num_pa auto param_copy = std::make_unique(params[i]); // flags currently unused. Ambiguous if flags in rocFileBatchIOSubmit is for buffer or // file flags. - auto [_file, _buffer] = context::Context::get()->getFileAndBuffer( + auto [_file, _buffer] = Context::get()->getFileAndBuffer( param_copy->fh, param_copy->u.batch.devPtr_base, param_copy->u.batch.size, 0); auto op = std::make_shared(std::move(param_copy), _buffer, _file); @@ -159,7 +159,7 @@ BatchContextMap::destroyContext(rocFileBatchHandle_t handle) auto context = active_contexts.find(handle); if (context == active_contexts.end()) { - throw InvalidHandle(); + throw InvalidBatchHandle(); } // TODO: Check for outstanding operations. // TODO: Attempt to cancel any outstanding operations. @@ -177,7 +177,7 @@ BatchContextMap::get(rocFileBatchHandle_t handle) auto context = active_contexts.find(handle); if (context == active_contexts.end()) { - throw InvalidHandle(); + throw InvalidBatchHandle(); } return context->second; } diff --git a/rocfile/src/batch/batch.h b/rocfile/src/batch/batch.h index 050eba1f..22dfd0e8 100644 --- a/rocfile/src/batch/batch.h +++ b/rocfile/src/batch/batch.h @@ -16,10 +16,10 @@ #include #include -namespace rocFile::batch { +namespace rocFile { -struct InvalidHandle : public std::invalid_argument { - InvalidHandle() : std::invalid_argument{"Invalid batch handle"} +struct InvalidBatchHandle : public std::invalid_argument { + InvalidBatchHandle() : std::invalid_argument{"Invalid batch handle"} { } }; @@ -31,8 +31,8 @@ class BatchOperation { /// @param [in] params IO parameters /// @param [in] buffer Buffer corresponding to params->u.batch.devPtr_base /// @param [in] file File corresponding params->fh - BatchOperation(std::unique_ptr params, std::shared_ptr buffer, - std::shared_ptr file); + BatchOperation(std::unique_ptr params, std::shared_ptr buffer, + std::shared_ptr file); private: /// @brief A copy of the params provided by the application. @@ -40,10 +40,10 @@ class BatchOperation { const std::unique_ptr io_params; /// @brief A reference to the specified Buffer. - const std::shared_ptr buffer; + const std::shared_ptr buffer; /// @brief A reference to the specified registered File. - const std::shared_ptr file; + const std::shared_ptr file; }; class IBatchContext { diff --git a/rocfile/src/buffer.cpp b/rocfile/src/buffer.cpp index 8b6d02a4..81d15cce 100644 --- a/rocfile/src/buffer.cpp +++ b/rocfile/src/buffer.cpp @@ -18,13 +18,11 @@ #include #include -using rocFile::Hip; -using rocFile::context::Context; using std::shared_ptr; using std::transform; using std::vector; -namespace rocFile::buffer { +namespace rocFile { static bool isValidBufferRegion(void *ptr, size_t length) @@ -57,11 +55,11 @@ Buffer::Buffer(const void *_buffer, size_t _length, int _flags) } if (type != hipMemoryTypeDevice) { - throw buffer::InvalidMemoryType(); + throw InvalidMemoryType(); } if (!isValidBufferRegion(buffer, length)) { - throw buffer::InvalidPointerRange(); + throw InvalidPointerRange(); } } @@ -93,7 +91,7 @@ void BufferMap::registerBuffer(const void *buf, size_t length, int flags) { if (from_ptr.end() != from_ptr.find(buf)) { - throw buffer::AlreadyRegistered(); + throw BufferAlreadyRegistered(); } auto buffer = std::shared_ptr(new Buffer(buf, length, flags)); @@ -105,11 +103,11 @@ BufferMap::deregisterBuffer(const void *buf) { auto itr = from_ptr.find(buf); if (from_ptr.end() == itr) { - throw buffer::NotRegistered(); + throw BufferNotRegistered(); } if (1 < itr->second.use_count()) { - throw buffer::OperationsOutstanding(); + throw BufferOperationsOutstanding(); } from_ptr.erase(buf); @@ -120,7 +118,7 @@ BufferMap::getBuffer(const void *buf) { auto itr = from_ptr.find(buf); if (from_ptr.end() == itr) { - throw buffer::NotRegistered(); + throw BufferNotRegistered(); } return itr->second; diff --git a/rocfile/src/buffer.h b/rocfile/src/buffer.h index caff70fe..8668f4c8 100644 --- a/rocfile/src/buffer.h +++ b/rocfile/src/buffer.h @@ -13,18 +13,18 @@ #include #include -namespace rocFile::buffer { +namespace rocFile { /// @brief Buffer is currently registered -struct AlreadyRegistered : public std::runtime_error { - AlreadyRegistered() : std::runtime_error("Already registered") +struct BufferAlreadyRegistered : public std::runtime_error { + BufferAlreadyRegistered() : std::runtime_error("Buffer already registered") { } }; /// @brief Buffer is not currently registered -struct NotRegistered : public std::runtime_error { - NotRegistered() : std::runtime_error("Not registered") +struct BufferNotRegistered : public std::runtime_error { + BufferNotRegistered() : std::runtime_error("Buffer not registered") { } }; @@ -44,8 +44,8 @@ struct InvalidPointerRange : public std::runtime_error { }; /// @brief Buffer has outstanding operations -struct OperationsOutstanding : public std::runtime_error { - OperationsOutstanding() : std::runtime_error("Operations outstanding") +struct BufferOperationsOutstanding : public std::runtime_error { + BufferOperationsOutstanding() : std::runtime_error("Buffer operations outstanding") { } }; diff --git a/rocfile/src/context.cpp b/rocfile/src/context.cpp index e3a82d5a..bd829970 100644 --- a/rocfile/src/context.cpp +++ b/rocfile/src/context.cpp @@ -9,7 +9,7 @@ #include "state.h" #include "sys.h" -namespace rocFile::context { +namespace rocFile { RocFileInit::RocFileInit() { diff --git a/rocfile/src/context.h b/rocfile/src/context.h index b2ab0daa..83df9e53 100644 --- a/rocfile/src/context.h +++ b/rocfile/src/context.h @@ -11,7 +11,7 @@ #include #endif -namespace rocFile::context { +namespace rocFile { template struct ContextOverride; diff --git a/rocfile/src/file.cpp b/rocfile/src/file.cpp index d90dbc24..1b1cf1e2 100644 --- a/rocfile/src/file.cpp +++ b/rocfile/src/file.cpp @@ -16,7 +16,7 @@ using std::shared_ptr; using std::transform; using std::vector; -namespace rocFile::file { +namespace rocFile { rocFileHandle_t IFile::getHandle() const @@ -64,7 +64,7 @@ FileMap::getFile(rocFileHandle_t fh) { auto itr = from_fh.find(fh); if (from_fh.end() == itr) { - throw NotRegistered(); + throw FileNotRegistered(); } return itr->second; @@ -74,7 +74,7 @@ rocFileHandle_t FileMap::registerFile(int fd, struct stat &fstat, int status_flags, optional mountinfo) { if (from_fd.end() != from_fd.find(fd)) { - throw file::AlreadyRegistered(); + throw FileAlreadyRegistered(); } auto file = std::shared_ptr(new File(fd, fstat, status_flags, mountinfo)); @@ -90,11 +90,11 @@ FileMap::deregisterFile(rocFileHandle_t fh) auto itr = from_fh.find(fh); if (from_fh.end() == itr) { - throw NotRegistered(); + throw FileNotRegistered(); } if (2 < itr->second.use_count()) { - throw file::OperationsOutstanding(); + throw FileOperationsOutstanding(); } from_fd.erase(itr->second->getFd()); diff --git a/rocfile/src/file.h b/rocfile/src/file.h index 369d681a..0697e96d 100644 --- a/rocfile/src/file.h +++ b/rocfile/src/file.h @@ -15,25 +15,25 @@ #include #include -namespace rocFile::file { +namespace rocFile { /// @brief File is not registered -struct NotRegistered : public std::runtime_error { - NotRegistered() : std::runtime_error("Not registered") +struct FileNotRegistered : public std::runtime_error { + FileNotRegistered() : std::runtime_error("File not registered") { } }; /// @brief File is already registered -struct AlreadyRegistered : public std::runtime_error { - AlreadyRegistered() : std::runtime_error("Already registered") +struct FileAlreadyRegistered : public std::runtime_error { + FileAlreadyRegistered() : std::runtime_error("File already registered") { } }; /// @brief File has operations outstanding -struct OperationsOutstanding : public std::runtime_error { - OperationsOutstanding() : std::runtime_error("Operations outstanding") +struct FileOperationsOutstanding : public std::runtime_error { + FileOperationsOutstanding() : std::runtime_error("File operations outstanding") { } }; diff --git a/rocfile/src/hip.cpp b/rocfile/src/hip.cpp index ee06f38d..59297b61 100644 --- a/rocfile/src/hip.cpp +++ b/rocfile/src/hip.cpp @@ -10,9 +10,7 @@ #include #include -using namespace rocFile; -using namespace rocFile::io; -using namespace rocFile::context; +namespace rocFile { static void * hipGetProcAddressHelper(const char *symbol) @@ -25,7 +23,7 @@ catch (...) { } hipAmdFileRead_t -rocFile::getHipAmdFileReadPtr() +getHipAmdFileReadPtr() { static hipAmdFileRead_t hipAmdFileReadPtr{ reinterpret_cast(hipGetProcAddressHelper("hipAmdFileRead"))}; @@ -33,7 +31,7 @@ rocFile::getHipAmdFileReadPtr() } hipAmdFileWrite_t -rocFile::getHipAmdFileWritePtr() +getHipAmdFileWritePtr() { static hipAmdFileWrite_t hipAmdFileWritePtr{ reinterpret_cast(hipGetProcAddressHelper("hipAmdFileWrite"))}; @@ -160,3 +158,5 @@ Hip::hipAmdFileWrite(hipAmdFileHandle_t handle, void *devicePtr, uint64_t size, return bytes_written; } + +} diff --git a/rocfile/src/hip.h b/rocfile/src/hip.h index 244b1da1..dbfa1ea5 100644 --- a/rocfile/src/hip.h +++ b/rocfile/src/hip.h @@ -81,4 +81,5 @@ struct Hip { } }; }; + } diff --git a/rocfile/src/io.h b/rocfile/src/io.h index d0638f19..0babd96f 100644 --- a/rocfile/src/io.h +++ b/rocfile/src/io.h @@ -4,7 +4,7 @@ */ #pragma once -namespace rocFile::io { +namespace rocFile { enum class IoType { Read, diff --git a/rocfile/src/mountinfo.cpp b/rocfile/src/mountinfo.cpp index fb511d4f..116497f3 100644 --- a/rocfile/src/mountinfo.cpp +++ b/rocfile/src/mountinfo.cpp @@ -10,7 +10,6 @@ #include using namespace rocFile; -using namespace rocFile::context; LibMount::~LibMount() { diff --git a/rocfile/src/rocfile-private.cpp b/rocfile/src/rocfile-private.cpp index 4af11a46..0ea5be16 100644 --- a/rocfile/src/rocfile-private.cpp +++ b/rocfile/src/rocfile-private.cpp @@ -10,5 +10,5 @@ void rocFileEnsureDriverInitPrivate() { - rocFile::context::Context::get()->ensureInitialized(); + rocFile::Context::get()->ensureInitialized(); } diff --git a/rocfile/src/rocfile-private.h b/rocfile/src/rocfile-private.h index 30eb5727..e2d3b2f7 100644 --- a/rocfile/src/rocfile-private.h +++ b/rocfile/src/rocfile-private.h @@ -17,5 +17,5 @@ ROCFILE_API void rocFileEnsureDriverInitPrivate(); -ssize_t rocFileIo(rocFile::io::IoType type, rocFileHandle_t fh, const void *buffer_base, size_t size, +ssize_t rocFileIo(rocFile::IoType type, rocFileHandle_t fh, const void *buffer_base, size_t size, off_t file_offset, off_t buffer_offset); diff --git a/rocfile/src/rocfile.cpp b/rocfile/src/rocfile.cpp index ab89407f..2c10c2ac 100644 --- a/rocfile/src/rocfile.cpp +++ b/rocfile/src/rocfile.cpp @@ -20,10 +20,6 @@ #include using namespace rocFile; -using namespace rocFile::io; -using rocFile::buffer::IBuffer; -using rocFile::context::Context; -using rocFile::file::IFile; const char * rocFileOpStatusError(rocFileOpError_t status) @@ -151,7 +147,7 @@ try { return {rocFileIONotSupported, hipSuccess}; } } -catch (const file::AlreadyRegistered &) { +catch (const FileAlreadyRegistered &) { return {rocFileHandleAlreadyRegistered, hipSuccess}; } catch (...) { @@ -171,10 +167,10 @@ try { catch (const DriverNotInitialized &) { return {rocFileDriverNotInitialized, hipSuccess}; } -catch (const file::OperationsOutstanding &) { +catch (const FileOperationsOutstanding &) { return {rocFileInternalError, hipSuccess}; } -catch (const file::NotRegistered &) { +catch (const FileNotRegistered &) { return {rocFileHandleNotRegistered, hipSuccess}; } catch (...) { @@ -187,13 +183,13 @@ try { Context::get()->registerBuffer(buffer_base, length, flags); return {rocFileSuccess, hipSuccess}; } -catch (const buffer::AlreadyRegistered &) { +catch (const BufferAlreadyRegistered &) { return {rocFileMemoryAlreadyRegistered, hipSuccess}; } -catch (const buffer::InvalidMemoryType &) { +catch (const InvalidMemoryType &) { return {rocFileHipMemoryTypeInvalid, hipSuccess}; } -catch (const buffer::InvalidPointerRange &) { +catch (const InvalidPointerRange &) { return {rocFileHipPointerRangeError, hipSuccess}; } catch (const Hip::RuntimeError &e) { @@ -218,10 +214,10 @@ try { catch (const DriverNotInitialized &) { return {rocFileDriverNotInitialized, hipSuccess}; } -catch (const buffer::NotRegistered &) { +catch (const BufferNotRegistered &) { return {rocFileMemoryNotRegistered, hipSuccess}; } -catch (const buffer::OperationsOutstanding &) { +catch (const BufferOperationsOutstanding &) { return {rocFileInternalError, hipSuccess}; } catch (...) { @@ -237,8 +233,8 @@ try { HIPFILE_WARN_NO_EXIT_DTOR_ON auto [file, buffer] = Context::get()->getFileAndBuffer(fh, buffer_base, size, 0); - int score{-1}; - std::shared_ptr backend{}; + int score{-1}; + std::shared_ptr backend{}; for (const auto &_backend : backends) { auto _score = _backend->score(file, buffer, size, file_offset, buffer_offset); @@ -265,13 +261,13 @@ catch (const DriverNotInitialized &) { catch (rocFileError_t e) { return -e.err; } -catch (const buffer::InvalidMemoryType &) { +catch (const InvalidMemoryType &) { return -rocFileHipMemoryTypeInvalid; } catch (const std::invalid_argument &) { return -rocFileInvalidValue; } -catch (const file::NotRegistered &) { +catch (const FileNotRegistered &) { return -rocFileHandleNotRegistered; } catch (const Hip::RuntimeError &e) { @@ -411,8 +407,7 @@ rocFileBatchIOSubmit(rocFileBatchHandle_t batch_idp, unsigned nr, rocFileIOParam try { (void)flags; // Unused at this time. - std::shared_ptr batch_context = - Context::get()->getBatchContext(batch_idp); + std::shared_ptr batch_context = Context::get()->getBatchContext(batch_idp); batch_context->submit_operations(iocbp, nr); return {rocFileSuccess, hipSuccess}; diff --git a/rocfile/src/state.cpp b/rocfile/src/state.cpp index 9362cb9f..fdfe9526 100644 --- a/rocfile/src/state.cpp +++ b/rocfile/src/state.cpp @@ -18,11 +18,6 @@ #include #include -using rocFile::buffer::IBuffer; -using rocFile::context::Context; -using rocFile::file::IFile; -using rocFile::stream::IStream; - using std::shared_lock; using std::shared_mutex; using std::shared_ptr; @@ -30,13 +25,12 @@ using std::unique_lock; namespace rocFile { -DriverState::DriverState() - : ref_count{0}, backends{std::shared_ptr(new backend::Fallback{})} +DriverState::DriverState() : ref_count{0}, backends{std::shared_ptr(new Fallback{})} { - this->file_map = std::make_unique(); - this->batch_map = std::make_unique(); - this->buffer_map = std::make_unique(); - this->stream_map = std::make_unique(); + this->file_map = std::make_unique(); + this->batch_map = std::make_unique(); + this->buffer_map = std::make_unique(); + this->stream_map = std::make_unique(); } DriverState::~DriverState() @@ -59,7 +53,7 @@ DriverState::destroyBatchContext(rocFileBatchHandle_t handle) batch_map->destroyContext(handle); } -std::shared_ptr +std::shared_ptr DriverState::getBatchContext(rocFileBatchHandle_t handle) { return batch_map->get(handle); @@ -283,7 +277,7 @@ DriverState::ensureInitialized() } } -std::vector> +std::vector> DriverState::getBackends() const { return backends; diff --git a/rocfile/src/state.h b/rocfile/src/state.h index 13e4af3f..260894a1 100644 --- a/rocfile/src/state.h +++ b/rocfile/src/state.h @@ -26,14 +26,14 @@ struct DriverNotInitialized : public std::runtime_error { }; struct file_buffer_pair { - std::shared_ptr file; - std::shared_ptr buffer; + std::shared_ptr file; + std::shared_ptr buffer; }; struct file_buffer_stream_tuple { - std::shared_ptr file; - std::shared_ptr buffer; - std::shared_ptr stream; + std::shared_ptr file; + std::shared_ptr buffer; + std::shared_ptr stream; }; // rocFile "state" @@ -72,7 +72,7 @@ class DriverState { /// @brief Get a batch context /// @param [in] handle The opaque handle associated with a batch context /// @return A batch context - virtual std::shared_ptr getBatchContext(rocFileBatchHandle_t handle); + virtual std::shared_ptr getBatchContext(rocFileBatchHandle_t handle); // // Buffer interface @@ -91,7 +91,7 @@ class DriverState { /// @brief Look up a registered buffer using the buffer pointer /// @param [in] buf Buffer pointer /// @return A registered buffer - virtual std::shared_ptr getBuffer(const void *buf); + virtual std::shared_ptr getBuffer(const void *buf); /// @brief Look up a registered buffer. Returns a temporary unregistered /// buffer (of size length, using flags) if no matching buffer is found. @@ -99,7 +99,7 @@ class DriverState { /// @param [in] length Buffer length /// @param [in] flags Buffer flags (unused) /// @return A registered or temporary unregistered buffer - virtual std::shared_ptr getBuffer(const void *buf, size_t length, int flags); + virtual std::shared_ptr getBuffer(const void *buf, size_t length, int flags); // // File interface @@ -116,8 +116,9 @@ class DriverState { /// @brief Look up a file given a rocFileHandle_t /// @param [in] fh The file handle to lookup the file with - /// @return If file handle is valid, return a shared pointer to the file, otherwise throw NotRegistered. - virtual std::shared_ptr getFile(rocFileHandle_t fh); + /// @return If file handle is valid, return a shared pointer to the file, otherwise throw + /// FileNotRegistered. + virtual std::shared_ptr getFile(rocFileHandle_t fh); // // Stream interface @@ -135,7 +136,7 @@ class DriverState { // @brief Look up a stream given a hipStream_t // @param [in] hip_stream A valid hipStream // @return Return a shared pointer to the Stream - virtual std::shared_ptr getStream(hipStream_t hip_stream); + virtual std::shared_ptr getStream(hipStream_t hip_stream); // // Buffer and file calls @@ -195,7 +196,7 @@ class DriverState { /// @brief Get the backends that can service IO requests /// @return A collection of backends that can service IO requests - virtual std::vector> getBackends() const; + virtual std::vector> getBackends() const; // // Misc @@ -221,22 +222,22 @@ class DriverState { int64_t ref_count; // Allows Context to manage DriverState. - friend struct context::Context; + friend struct Context; // Manages the driver's File objects - std::unique_ptr file_map; + std::unique_ptr file_map; // Manages the allocated Batch Context's - std::unique_ptr batch_map; + std::unique_ptr batch_map; // Manages the driver's Buffer objects - std::unique_ptr buffer_map; + std::unique_ptr buffer_map; // Manages the driver's Stream objects - std::unique_ptr stream_map; + std::unique_ptr stream_map; // Backends available to service IO requests - const std::vector> backends; + const std::vector> backends; /// Mutex to protect the state mutable std::shared_mutex state_mutex; diff --git a/rocfile/src/stream.cpp b/rocfile/src/stream.cpp index 88b642b4..13d24c80 100644 --- a/rocfile/src/stream.cpp +++ b/rocfile/src/stream.cpp @@ -12,9 +12,7 @@ #include -using rocFile::context::Context; - -namespace rocFile::stream { +namespace rocFile { Stream::Stream(const hipStream_t _hip_stream, uint32_t flags) : hip_stream{_hip_stream}, fixed_buf_offset{(flags & ROCFILE_STREAM_FIXED_BUF_OFFSET) != 0}, diff --git a/rocfile/src/stream.h b/rocfile/src/stream.h index e648bb3a..383b0ca1 100644 --- a/rocfile/src/stream.h +++ b/rocfile/src/stream.h @@ -8,7 +8,7 @@ #include #include -namespace rocFile::stream { +namespace rocFile { class IStream { public: diff --git a/rocfile/src/sys.cpp b/rocfile/src/sys.cpp index f2077d22..21b80a0a 100644 --- a/rocfile/src/sys.cpp +++ b/rocfile/src/sys.cpp @@ -11,7 +11,7 @@ #include #include -using rocFile::Sys; +namespace rocFile { template static inline R @@ -69,3 +69,5 @@ Sys::fcntl(int fd, int op, uintptr_t arg) const { return throwOn(-1, ::fcntl(fd, op, arg)); } + +} diff --git a/rocfile/test/async.cpp b/rocfile/test/async.cpp index 8033d359..5cb0373f 100644 --- a/rocfile/test/async.cpp +++ b/rocfile/test/async.cpp @@ -26,9 +26,6 @@ HIPFILE_WARN_NO_GLOBAL_CTOR_OFF using namespace rocFile; -using async::AsyncMonitor; -using async::AsyncOp; -using backend::AsyncOpFallback; using std::shared_ptr; using ::testing::_; using ::testing::AnyNumber; @@ -104,7 +101,7 @@ TEST_P(RocFileAsyncOpStreamParams, asyncOp_construction_has_correct_variants) off_t file_offset = 0; off_t buffer_offset = 0; off_t bytes_transferred = 0; - auto op = std::make_shared(io::IoType::Read, file, buffer, stream, &size, &file_offset, + auto op = std::make_shared(IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred); // Unfixed flags will be pointers @@ -142,7 +139,7 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_new_uses_pinned_host_memory) EXPECT_CALL(mhip, hipHostFree(Eq(bounce_buffer.get()))); EXPECT_CALL(mhip, hipHostFree(Eq(op_data.get()))); auto op = std::shared_ptr(new AsyncOpFallback{ - io::IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}); + IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}); } TEST_F(RocFileAsyncOp, AsyncOpFallback_new_failure_throws_bad_alloc) @@ -153,7 +150,7 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_new_failure_throws_bad_alloc) off_t bytes_transferred = 0; auto op_data = std::shared_ptr(new uint8_t[sizeof(AsyncOpFallback)]); EXPECT_CALL(mhip, hipHostMalloc).WillOnce(Throw(Hip::RuntimeError(hipErrorOutOfMemory))); - EXPECT_THROW(std::shared_ptr(new AsyncOpFallback{io::IoType::Read, file, buffer, stream, + EXPECT_THROW(std::shared_ptr(new AsyncOpFallback{IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}), std::bad_alloc); @@ -170,7 +167,7 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_bounce_alloc_failure_throws) .WillOnce(Return(op_data.get())) .WillOnce(Throw(Hip::RuntimeError(hipErrorOutOfMemory))); EXPECT_CALL(mhip, hipHostFree(Eq(op_data.get()))); - EXPECT_THROW(std::shared_ptr(new AsyncOpFallback{io::IoType::Read, file, buffer, stream, + EXPECT_THROW(std::shared_ptr(new AsyncOpFallback{IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}), Hip::RuntimeError); @@ -191,7 +188,7 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_bounce_buffer_deleter_failure_calls_syslo EXPECT_CALL(mhip, hipHostFree(Eq(op_data.get()))); EXPECT_CALL(msys, syslog); auto op = std::shared_ptr(new AsyncOpFallback{ - io::IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}); + IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}); } TEST_F(RocFileAsyncOp, AsyncOpFallback_delete_failure_calls_syslog) @@ -209,7 +206,7 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_delete_failure_calls_syslog) .WillOnce(Throw(Hip::RuntimeError(hipErrorInvalidValue))); EXPECT_CALL(msys, syslog); auto op = std::shared_ptr(new AsyncOpFallback{ - io::IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}); + IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}); } struct RocFileAsyncOpFallbackFunctions : public RocFileAsyncOp { @@ -219,7 +216,7 @@ struct RocFileAsyncOpFallbackFunctions : public RocFileAsyncOp { // AsyncOpFallback EXPECT_CALL(mhip, hipHostMalloc).WillOnce(Return(bounce_buffer.get())); EXPECT_CALL(mhip, hipHostGetDevicePointer).WillOnce(Return(bounce_buffer_dev_ptr)); - op = std::make_shared(io::IoType::Read, file, buffer, stream, &size, &file_offset, + op = std::make_shared(IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred); } ~RocFileAsyncOpFallbackFunctions() override @@ -253,7 +250,7 @@ TEST_F(RocFileAsyncMonitor, addOp_and_completeOp_with_valid_params_works) off_t file_offset = 0; off_t buffer_offset = 0; off_t bytes_transferred = 0; - auto op = std::make_shared(io::IoType::Read, file, buffer, stream, &size, &file_offset, + auto op = std::make_shared(IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred); monitor.addOp(op); @@ -271,7 +268,7 @@ TEST_F(RocFileAsyncMonitor, addOp_without_completeOp_prints_error_on_AsyncMonito off_t file_offset = 0; off_t buffer_offset = 0; off_t bytes_transferred = 0; - auto op = std::make_unique(io::IoType::Read, file, buffer, stream, &size, &file_offset, + auto op = std::make_unique(IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred); monitor.addOp(std::move(op)); EXPECT_CALL(msys, syslog); diff --git a/rocfile/test/batch/batch.cpp b/rocfile/test/batch/batch.cpp index 800083a1..1a0a1d66 100644 --- a/rocfile/test/batch/batch.cpp +++ b/rocfile/test/batch/batch.cpp @@ -26,10 +26,6 @@ using ::testing::StrictMock; using ::testing::Throw; using namespace rocFile; -using rocFile::batch::BatchContext; -using rocFile::batch::BatchContextMap; -using rocFile::batch::BatchOperation; -using rocFile::batch::IBatchContext; HIPFILE_WARN_NO_GLOBAL_CTOR_OFF @@ -192,12 +188,12 @@ TEST_F(RocFileBatch, DestroyContext) TEST_F(RocFileBatch, DestroyMissingContext) { - ASSERT_THROW(batch_map.destroyContext(reinterpret_cast(1)), batch::InvalidHandle); + ASSERT_THROW(batch_map.destroyContext(reinterpret_cast(1)), InvalidBatchHandle); } TEST_F(RocFileBatch, DestroyNullptrContext) { - ASSERT_THROW(batch_map.destroyContext(nullptr), batch::InvalidHandle); + ASSERT_THROW(batch_map.destroyContext(nullptr), InvalidBatchHandle); } TEST_F(RocFileBatch, GetContext) @@ -210,19 +206,19 @@ TEST_F(RocFileBatch, GetContext) TEST_F(RocFileBatch, GetNullptrContext) { - ASSERT_THROW(batch_map.get(nullptr), batch::InvalidHandle); + ASSERT_THROW(batch_map.get(nullptr), InvalidBatchHandle); } TEST_F(RocFileBatch, GetInvalidContext) { - ASSERT_THROW(batch_map.get(reinterpret_cast(0xBAC00001)), batch::InvalidHandle); + ASSERT_THROW(batch_map.get(reinterpret_cast(0xBAC00001)), InvalidBatchHandle); } TEST_F(RocFileBatch, GetDestroyedContext) { rocFileBatchHandle_t handle = batch_map.createContext(1); batch_map.destroyContext(handle); - ASSERT_THROW(batch_map.get(handle), batch::InvalidHandle); + ASSERT_THROW(batch_map.get(handle), InvalidBatchHandle); } struct RocFileBatchContext : public RocFileUnopened { @@ -296,14 +292,14 @@ TEST_F(RocFileBatchContext, SubmitOverCapacityOverMultipleSubmissions) TEST_F(RocFileBatchContext, SubmitSingleBadBuffer) { - EXPECT_CALL(*mock_driver_state, getFileAndBuffer).WillOnce(Throw(buffer::NotRegistered())); - ASSERT_THROW(_context->submit_operations(&io_params, 1), buffer::NotRegistered); + EXPECT_CALL(*mock_driver_state, getFileAndBuffer).WillOnce(Throw(BufferNotRegistered())); + ASSERT_THROW(_context->submit_operations(&io_params, 1), BufferNotRegistered); } TEST_F(RocFileBatchContext, SubmitSingleBadFileHandle) { - EXPECT_CALL(*mock_driver_state, getFileAndBuffer).WillOnce(Throw(file::NotRegistered())); - ASSERT_THROW(_context->submit_operations(&io_params, 1), file::NotRegistered); + EXPECT_CALL(*mock_driver_state, getFileAndBuffer).WillOnce(Throw(FileNotRegistered())); + ASSERT_THROW(_context->submit_operations(&io_params, 1), FileNotRegistered); } // BatchOperation is not mocked. diff --git a/rocfile/test/batch/batch_mt.cpp b/rocfile/test/batch/batch_mt.cpp index 473285c8..2b944f0a 100644 --- a/rocfile/test/batch/batch_mt.cpp +++ b/rocfile/test/batch/batch_mt.cpp @@ -45,7 +45,7 @@ thread_function(int id) constexpr int N_PRELOAD = 10; // # of handles to load before cycling constexpr int CAPACITY = 64; // Arbitrary - auto bcm = batch::BatchContextMap{}; + auto bcm = BatchContextMap{}; vector handles; diff --git a/rocfile/test/buffer.cpp b/rocfile/test/buffer.cpp index 5b9367a4..0e73ac38 100644 --- a/rocfile/test/buffer.cpp +++ b/rocfile/test/buffer.cpp @@ -24,8 +24,6 @@ using namespace rocFile; -using rocFile::buffer::Buffer; -using rocFile::context::Context; using ::testing::StrictMock; // Put tests inside the macros to suppress the global constructor @@ -71,8 +69,7 @@ TEST_F(RocFileBuffer, register_internal_not_device_memory) hipPointerAttribute_t attrs; attrs.type = memoryType; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Return(attrs)); - ASSERT_THROW(Context::get()->registerBuffer(nonnull_ptr, 0, 0), - buffer::InvalidMemoryType); + ASSERT_THROW(Context::get()->registerBuffer(nonnull_ptr, 0, 0), InvalidMemoryType); } } } @@ -114,7 +111,7 @@ TEST_F(RocFileBuffer, register_internal_already_registered) StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); - ASSERT_THROW(Context::get()->registerBuffer(nonnull_ptr, 0, 0), buffer::AlreadyRegistered); + ASSERT_THROW(Context::get()->registerBuffer(nonnull_ptr, 0, 0), BufferAlreadyRegistered); } TEST_F(RocFileBuffer, register_already_registered) @@ -170,7 +167,7 @@ TEST_F(RocFileBuffer, registerOverflowingRangeReturnsError) TEST_F(RocFileBuffer, deregister_internal_not_registered) { - ASSERT_THROW(Context::get()->deregisterBuffer(nonnull_ptr), buffer::NotRegistered); + ASSERT_THROW(Context::get()->deregisterBuffer(nonnull_ptr), BufferNotRegistered); } TEST_F(RocFileBuffer, deregister_not_registered) @@ -200,7 +197,7 @@ TEST_F(RocFileBuffer, deregister_internal_duplicate_deregister) expect_buffer_registration(mhip, hipMemoryTypeDevice); Context::get()->registerBuffer(nonnull_ptr, 0, 0); Context::get()->deregisterBuffer(nonnull_ptr); - ASSERT_THROW(Context::get()->deregisterBuffer(nonnull_ptr), buffer::NotRegistered); + ASSERT_THROW(Context::get()->deregisterBuffer(nonnull_ptr), BufferNotRegistered); } TEST_F(RocFileBuffer, deregister_duplicate_deregister) @@ -219,8 +216,7 @@ TEST_F(RocFileBuffer, deregister_internal_get_prevents_deregister) Context::get()->registerBuffer(nonnull_ptr, 0, 0); { auto buffer = Context::get()->getBuffer(nonnull_ptr); - ASSERT_THROW(Context::get()->deregisterBuffer(nonnull_ptr), - buffer::OperationsOutstanding); + ASSERT_THROW(Context::get()->deregisterBuffer(nonnull_ptr), BufferOperationsOutstanding); } Context::get()->deregisterBuffer(nonnull_ptr); } @@ -239,7 +235,7 @@ TEST_F(RocFileBuffer, deregister_get_prevents_deregister) TEST_F(RocFileBuffer, get_not_registered) { - ASSERT_THROW(Context::get()->getBuffer(nonnull_ptr), buffer::NotRegistered); + ASSERT_THROW(Context::get()->getBuffer(nonnull_ptr), BufferNotRegistered); } TEST_F(RocFileBuffer, get_internal_after_register) @@ -264,7 +260,7 @@ TEST_F(RocFileBuffer, get_internal_after_deregister) expect_buffer_registration(mhip, hipMemoryTypeDevice); Context::get()->registerBuffer(nonnull_ptr, 0, 0); Context::get()->deregisterBuffer(nonnull_ptr); - ASSERT_THROW(Context::get()->getBuffer(nonnull_ptr), buffer::NotRegistered); + ASSERT_THROW(Context::get()->getBuffer(nonnull_ptr), BufferNotRegistered); } TEST_F(RocFileBuffer, get_after_deregister) @@ -273,7 +269,7 @@ TEST_F(RocFileBuffer, get_after_deregister) expect_buffer_registration(mhip, hipMemoryTypeDevice); ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); ASSERT_EQ(rocFileBufDeregister(nonnull_ptr), ROCFILE_SUCCESS); - ASSERT_THROW(Context::get()->getBuffer(nonnull_ptr), buffer::NotRegistered); + ASSERT_THROW(Context::get()->getBuffer(nonnull_ptr), BufferNotRegistered); } TEST_F(RocFileBuffer, get_buffer_makes_temporary_buffer) diff --git a/rocfile/test/context.cpp b/rocfile/test/context.cpp index df93a275..75d449c1 100644 --- a/rocfile/test/context.cpp +++ b/rocfile/test/context.cpp @@ -8,9 +8,7 @@ #include "hipfile-warnings.h" #include -using namespace rocFile::context; - -using rocFile::Hip; +using namespace rocFile; // Put tests inside the macros to suppress the global constructor // warnings diff --git a/rocfile/test/handle.cpp b/rocfile/test/handle.cpp index f2ef6ef7..2a2e9985 100644 --- a/rocfile/test/handle.cpp +++ b/rocfile/test/handle.cpp @@ -22,9 +22,6 @@ using namespace rocFile; -using rocFile::context::Context; -using rocFile::file::IFile; - using ::testing::Return; using ::testing::StrictMock; using ::testing::Throw; @@ -88,7 +85,7 @@ TEST_F(RocFileHandle, register_handle_internal_linux_fd_already_registered) EXPECT_CALL(msys, fcntl).Times(2); EXPECT_CALL(mlibmounthelper, getMountInfo).Times(2); ASSERT_NE(Context::get()->registerFile(fd), nullptr); - ASSERT_THROW(Context::get()->registerFile(fd), file::AlreadyRegistered); + ASSERT_THROW(Context::get()->registerFile(fd), FileAlreadyRegistered); } TEST_F(RocFileHandle, register_handle_linux_fd) @@ -210,7 +207,7 @@ TEST_F(RocFileHandle, register_handle_userspace_fs_not_supported) TEST_F(RocFileHandle, deregister_handle_internal_throws_if_not_registered) { ASSERT_THROW(Context::get()->deregisterFile(reinterpret_cast(0xdeadbeef)), - file::NotRegistered); + FileNotRegistered); } TEST_F(RocFileHandle, deregister_handle_returns_error_if_not_registered) @@ -228,7 +225,7 @@ TEST_F(RocFileHandle, deregister_handle_internal) EXPECT_CALL(mlibmounthelper, getMountInfo); auto fh = Context::get()->registerFile(0xBADF00D); Context::get()->deregisterFile(fh); - ASSERT_THROW(Context::get()->deregisterFile(fh), file::NotRegistered); + ASSERT_THROW(Context::get()->deregisterFile(fh), FileNotRegistered); } TEST_F(RocFileHandle, deregister_handle) @@ -261,7 +258,7 @@ TEST_F(RocFileHandle, deregister_handle_internal_fails_when_operations_are_ousta auto fh = Context::get()->registerFile(0xBADF00D); { auto file = Context::get()->getFile(fh); - ASSERT_THROW(Context::get()->deregisterFile(fh), file::OperationsOutstanding); + ASSERT_THROW(Context::get()->deregisterFile(fh), FileOperationsOutstanding); } Context::get()->deregisterFile(fh); } diff --git a/rocfile/test/io.cpp b/rocfile/test/io.cpp index 788d1c41..38f3671d 100644 --- a/rocfile/test/io.cpp +++ b/rocfile/test/io.cpp @@ -39,13 +39,8 @@ #include using namespace rocFile; -using namespace rocFile::backend; -using namespace rocFile::buffer; -using namespace rocFile::io; using namespace testing; -using rocFile::context::Context; -using rocFile::file::IFile; using std::shared_ptr; using ::testing::Return; using ::testing::StrictMock; @@ -175,7 +170,7 @@ TEST(RocFileFallbackBackend, FallbackBackendRejectsNonDeviceMemory) } } -struct RocFileFallbackValidation : ::testing::TestWithParam { +struct RocFileFallbackValidation : ::testing::TestWithParam { shared_ptr buffer; shared_ptr file; @@ -215,7 +210,7 @@ struct RocFileFallbackValidation : ::testing::TestWithParam { io_type = GetParam(); } - io::IoType io_type; + IoType io_type; }; TEST_P(RocFileFallbackValidation, fallback_io_throws_on_negative_buffer_offset) @@ -261,13 +256,13 @@ TEST_P(RocFileFallbackValidation, fallback_io_truncates_size_to_MAX_RW_COUNT) EXPECT_CALL(msys, mmap).WillOnce(testing::Return(reinterpret_cast(0xFEFEFEFE))); switch (io_type) { - case io::IoType::Read: + case IoType::Read: EXPECT_CALL(msys, pread) .WillRepeatedly(testing::Invoke( [](int, void *, size_t count, off_t) -> ssize_t { return static_cast(count); })); EXPECT_CALL(mhip, hipMemcpy).WillRepeatedly(testing::Return()); break; - case io::IoType::Write: + case IoType::Write: EXPECT_CALL(mhip, hipMemcpy).WillRepeatedly(testing::Return()); EXPECT_CALL(mhip, hipStreamSynchronize).WillRepeatedly(testing::Return()); EXPECT_CALL(msys, pwrite) @@ -299,10 +294,10 @@ TEST_P(RocFileFallbackValidation, fallback_io_allocates_chunk_sized_host_bounce_ EXPECT_CALL(msys, mmap(testing::_, chunk_size, testing::_, testing::_, testing::_, testing::_)) .WillOnce(testing::Return(ptr)); switch (io_type) { - case io::IoType::Read: + case IoType::Read: EXPECT_CALL(msys, pread).WillOnce(testing::Return(0)); break; - case io::IoType::Write: + case IoType::Write: EXPECT_CALL(mhip, hipMemcpy); EXPECT_CALL(mhip, hipStreamSynchronize); EXPECT_CALL(msys, pwrite).WillOnce(testing::Return(0)); @@ -315,7 +310,7 @@ TEST_P(RocFileFallbackValidation, fallback_io_allocates_chunk_sized_host_bounce_ } INSTANTIATE_TEST_SUITE_P(FallbackValidationTests, RocFileFallbackValidation, - ::testing::Values(io::IoType::Read, io::IoType::Write)); + ::testing::Values(IoType::Read, IoType::Write)); struct RocFileWrite : public RocFileIO { @@ -1114,7 +1109,7 @@ struct RocFileIoBackendSelectionParam : public ::testing::TestWithParam TEST_P(RocFileIoBackendSelectionParam, RocFileIoThrowsIfThereAreNoBackends) { - auto backends{std::vector>()}; + auto backends{std::vector>()}; EXPECT_CALL(mds, getFileAndBuffer(handle, buffer, io_size, flags)) .WillOnce(Return(file_buffer_pair{mfile, mbuffer})); @@ -1136,7 +1131,7 @@ TEST_P(RocFileIoBackendSelectionParam, RocFileIoThrowsIfThereAreNoBackends) TEST_P(RocFileIoBackendSelectionParam, RocFileIoThrowsIfAllBackendsRejectTheIO) { - std::vector> backends{mbe1, mbe2, mbe3}; + std::vector> backends{mbe1, mbe2, mbe3}; EXPECT_CALL(mds, getFileAndBuffer(handle, buffer, io_size, flags)) .WillOnce(Return(file_buffer_pair{mfile, mbuffer})); @@ -1164,7 +1159,7 @@ TEST_P(RocFileIoBackendSelectionParam, RocFileIoThrowsIfAllBackendsRejectTheIO) TEST_P(RocFileIoBackendSelectionParam, RocFileIoIssuesIoToHighestScoringBackend) { - std::vector> backends{mbe1, mbe2, mbe3}; + std::vector> backends{mbe1, mbe2, mbe3}; EXPECT_CALL(mds, getFileAndBuffer(handle, buffer, io_size, flags)) .WillOnce(Return(file_buffer_pair{mfile, mbuffer})); diff --git a/rocfile/test/mbackend.h b/rocfile/test/mbackend.h index 0256af58..d175444e 100644 --- a/rocfile/test/mbackend.h +++ b/rocfile/test/mbackend.h @@ -9,15 +9,14 @@ #include -namespace rocFile::backend { +namespace rocFile { struct MBackend : Backend { - MOCK_METHOD(int, score, - (std::shared_ptr, std::shared_ptr, size_t, off_t, off_t), + MOCK_METHOD(int, score, (std::shared_ptr, std::shared_ptr, size_t, off_t, off_t), (const override)); MOCK_METHOD(ssize_t, io, - (rocFile::io::IoType type, std::shared_ptr, std::shared_ptr, - size_t, off_t, off_t), + (rocFile::IoType type, std::shared_ptr, std::shared_ptr, size_t, off_t, + off_t), (override)); }; diff --git a/rocfile/test/mbatch.h b/rocfile/test/mbatch.h index 91b0babe..5b637524 100644 --- a/rocfile/test/mbatch.h +++ b/rocfile/test/mbatch.h @@ -15,7 +15,7 @@ namespace rocFile { -class MBatchContext : public batch::IBatchContext { +class MBatchContext : public IBatchContext { public: MOCK_METHOD(unsigned, get_capacity, (), (const, noexcept, override)); MOCK_METHOD(void, submit_operations, (const rocFileIOParams_t *params, const unsigned num_params), diff --git a/rocfile/test/mbuffer.h b/rocfile/test/mbuffer.h index 9ad66b01..527a6c01 100644 --- a/rocfile/test/mbuffer.h +++ b/rocfile/test/mbuffer.h @@ -15,7 +15,7 @@ namespace rocFile { -class MBuffer : public buffer::IBuffer { +class MBuffer : public IBuffer { public: MOCK_METHOD(void *, getBuffer, (), (const override)); MOCK_METHOD(size_t, getLength, (), (const override)); @@ -23,15 +23,15 @@ class MBuffer : public buffer::IBuffer { MOCK_METHOD(hipMemoryType, getType, (), (const override)); }; -class MBufferMap : public buffer::BufferMap { +class MBufferMap : public BufferMap { public: MBufferMap() { } MOCK_METHOD(void, registerBuffer, (const void *bufptr, size_t length, int flags), (override)); MOCK_METHOD(void, deregisterBuffer, (const void *bufptr), (override)); - MOCK_METHOD(std::shared_ptr, getBuffer, (const void *bufptr), (override)); - MOCK_METHOD(std::shared_ptr, getBuffer, (const void *bufptr, size_t length, int flags), + MOCK_METHOD(std::shared_ptr, getBuffer, (const void *bufptr), (override)); + MOCK_METHOD(std::shared_ptr, getBuffer, (const void *bufptr, size_t length, int flags), (override)); MOCK_METHOD(void, clear, (), (override)); }; diff --git a/rocfile/test/mfile.h b/rocfile/test/mfile.h index 6ff0aca4..0a80b42a 100644 --- a/rocfile/test/mfile.h +++ b/rocfile/test/mfile.h @@ -16,7 +16,7 @@ namespace rocFile { -class MFile : public file::IFile { +class MFile : public IFile { public: MOCK_METHOD(rocFileHandle_t, getHandle, (), (const override)); MOCK_METHOD(int, getFd, (), (const override)); @@ -26,7 +26,7 @@ class MFile : public file::IFile { MOCK_METHOD(std::optional, getMountInfo, (), (const override)); }; -class MFileMap : public file::FileMap { +class MFileMap : public FileMap { public: MFileMap() { @@ -35,7 +35,7 @@ class MFileMap : public file::FileMap { (int fd, struct stat &fstat, int _status_flags, std::optional mountinfo), (override)); MOCK_METHOD(void, deregisterFile, (rocFileHandle_t fh), (override)); - MOCK_METHOD(std::shared_ptr, getFile, (rocFileHandle_t), (override)); + MOCK_METHOD(std::shared_ptr, getFile, (rocFileHandle_t), (override)); MOCK_METHOD(void, clear, (), (override)); }; diff --git a/rocfile/test/mhip.h b/rocfile/test/mhip.h index 0579dcbb..78647a1e 100644 --- a/rocfile/test/mhip.h +++ b/rocfile/test/mhip.h @@ -17,7 +17,7 @@ namespace rocFile { struct MHip : Hip { - context::ContextOverride co; + ContextOverride co; MHip() : co{this} { } diff --git a/rocfile/test/mmountinfo.h b/rocfile/test/mmountinfo.h index 21d186ff..c1b8718b 100644 --- a/rocfile/test/mmountinfo.h +++ b/rocfile/test/mmountinfo.h @@ -13,7 +13,7 @@ namespace rocFile { struct MLibMount : LibMount { - context::ContextOverride co; + ContextOverride co; MLibMount() : co{this} { @@ -30,7 +30,7 @@ struct MLibMount : LibMount { }; struct MLibMountHelper : LibMountHelper { - context::ContextOverride co; + ContextOverride co; MLibMountHelper() : co{this} { diff --git a/rocfile/test/mstate.h b/rocfile/test/mstate.h index 637c8433..64321cb4 100644 --- a/rocfile/test/mstate.h +++ b/rocfile/test/mstate.h @@ -21,7 +21,7 @@ namespace rocFile { class MDriverState : public DriverState { public: - context::ContextOverride o_co; + ContextOverride o_co; MDriverState() : o_co{this} { @@ -29,22 +29,20 @@ class MDriverState : public DriverState { MOCK_METHOD(rocFileBatchHandle_t, createBatchContext, (unsigned capacity), (override)); MOCK_METHOD(void, destroyBatchContext, (rocFileBatchHandle_t handle), (override)); - MOCK_METHOD(std::shared_ptr, getBatchContext, (rocFileBatchHandle_t handle), - (override)); + MOCK_METHOD(std::shared_ptr, getBatchContext, (rocFileBatchHandle_t handle), (override)); MOCK_METHOD(void, registerBuffer, (const void *buf, size_t length, int flags), (override)); MOCK_METHOD(void, deregisterBuffer, (const void *buf), (override)); - MOCK_METHOD(std::shared_ptr, getBuffer, (const void *buf), (override)); - MOCK_METHOD(std::shared_ptr, getBuffer, - (const void *buf, size_t length, int flags), (override)); + MOCK_METHOD(std::shared_ptr, getBuffer, (const void *buf), (override)); + MOCK_METHOD(std::shared_ptr, getBuffer, (const void *buf, size_t length, int flags), (override)); MOCK_METHOD(rocFileHandle_t, registerFile, (int fd), (override)); MOCK_METHOD(void, deregisterFile, (rocFileHandle_t fh), (override)); - MOCK_METHOD(std::shared_ptr, getFile, (rocFileHandle_t fh), (override)); + MOCK_METHOD(std::shared_ptr, getFile, (rocFileHandle_t fh), (override)); MOCK_METHOD(file_buffer_pair, getFileAndBuffer, (rocFileHandle_t fh, const void *buf, size_t length, int flags), (override)); MOCK_METHOD(void, incrRefCount, (), (override)); MOCK_METHOD(void, decrRefCount, (), (override)); MOCK_METHOD(int64_t, getRefCount, (), (override, const)); - MOCK_METHOD(std::vector>, getBackends, (), (const override)); + MOCK_METHOD(std::vector>, getBackends, (), (const override)); }; } diff --git a/rocfile/test/mstream.h b/rocfile/test/mstream.h index dc5ebb9c..72a12016 100644 --- a/rocfile/test/mstream.h +++ b/rocfile/test/mstream.h @@ -8,7 +8,7 @@ namespace rocFile { -class MStream : public stream::IStream { +class MStream : public IStream { public: MOCK_METHOD(hipStream_t, getHipStream, (), (const override)); MOCK_METHOD(bool, fixedBufferOffset, (), (const override)); diff --git a/rocfile/test/msys.h b/rocfile/test/msys.h index 1de78aea..20a4ad35 100644 --- a/rocfile/test/msys.h +++ b/rocfile/test/msys.h @@ -14,7 +14,7 @@ namespace rocFile { struct MSys : Sys { - context::ContextOverride co; + ContextOverride co; MSys() : co{this} { } diff --git a/rocfile/test/rocfile.cpp b/rocfile/test/rocfile.cpp index 16fa6068..5289e5a8 100644 --- a/rocfile/test/rocfile.cpp +++ b/rocfile/test/rocfile.cpp @@ -86,7 +86,7 @@ TEST_F(RocFileUnit, TestRocFileBatchIOSubmitBadHandle) rocFileIOParams_t io_param; std::shared_ptr mock_b_context = std::make_shared(); - EXPECT_CALL(mock_state, getBatchContext).WillOnce(Throw(batch::InvalidHandle())); + EXPECT_CALL(mock_state, getBatchContext).WillOnce(Throw(InvalidBatchHandle())); EXPECT_CALL(*mock_b_context, submit_operations).Times(0); auto result = rocFileBatchIOSubmit(b_handle, 1, &io_param, 0); diff --git a/rocfile/test/state_mt.cpp b/rocfile/test/state_mt.cpp index 47fd419d..98dce6ae 100644 --- a/rocfile/test/state_mt.cpp +++ b/rocfile/test/state_mt.cpp @@ -28,8 +28,6 @@ #include using namespace rocFile; -using rocFile::buffer::IBuffer; -using rocFile::file::IFile; using namespace std; @@ -75,7 +73,7 @@ thread_function(int id) constexpr int N_CYCLES = 100; // # of cycles before checking the run flag constexpr int N_PRELOAD = 10; // # of files/buffers to load before cycling - auto *ds = context::Context::get(); + auto *ds = Context::get(); vector> files; vector buffers; diff --git a/rocfile/test/stream.cpp b/rocfile/test/stream.cpp index 8d92c2c3..a009cda3 100644 --- a/rocfile/test/stream.cpp +++ b/rocfile/test/stream.cpp @@ -18,7 +18,6 @@ using namespace rocFile; -using rocFile::stream::IStream; using ::testing::StrictMock; // Put tests inside the macros to suppress the global constructor @@ -39,10 +38,10 @@ struct RocFileStream : public ::testing::Test { { nonnull_stream = reinterpret_cast(1); } - StrictMock mhip; - StrictMock msys; - hipStream_t nonnull_stream; - stream::StreamMap stream_map; + StrictMock mhip; + StrictMock msys; + hipStream_t nonnull_stream; + StreamMap stream_map; }; struct RocFileStreamValidParams From b4047035c357e2f64fa691a26a3d04a448306ed3 Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Sat, 1 Nov 2025 09:29:01 -0600 Subject: [PATCH 2/2] Put mountinfo source in rocFile namespace --- rocfile/src/mountinfo.cpp | 4 +++- rocfile/src/mountinfo.h | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rocfile/src/mountinfo.cpp b/rocfile/src/mountinfo.cpp index 116497f3..769fd65a 100644 --- a/rocfile/src/mountinfo.cpp +++ b/rocfile/src/mountinfo.cpp @@ -9,7 +9,7 @@ #include #include -using namespace rocFile; +namespace rocFile { LibMount::~LibMount() { @@ -117,3 +117,5 @@ LibMountHelper::getMountInfo(dev_t dev) const libmount->mnt_free_context(mnt_ctx); return std::make_optional(mountinfo); } + +} diff --git a/rocfile/src/mountinfo.h b/rocfile/src/mountinfo.h index a1dfe817..d0db6a2f 100644 --- a/rocfile/src/mountinfo.h +++ b/rocfile/src/mountinfo.h @@ -69,4 +69,4 @@ class LibMountHelper { virtual std::optional getMountInfo(dev_t dev) const; }; -} // namespace rocfile +}