From 71e5b91344716ad25f6272c7af1948b0c6e7aa37 Mon Sep 17 00:00:00 2001 From: Riley Dixon Date: Fri, 28 Nov 2025 13:47:58 -0700 Subject: [PATCH 1/3] Batch: Create Mock BatchOperation. --- hipfile/src/amd_detail/batch/batch.h | 7 ++++++- hipfile/test/amd_detail/mbatch.h | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/hipfile/src/amd_detail/batch/batch.h b/hipfile/src/amd_detail/batch/batch.h index f8372a17..7bd07213 100644 --- a/hipfile/src/amd_detail/batch/batch.h +++ b/hipfile/src/amd_detail/batch/batch.h @@ -28,8 +28,13 @@ struct InvalidBatchHandle : public std::invalid_argument { } }; +class IBatchOperation { +public: + virtual ~IBatchOperation() = default; +}; + /// @brief Represents a single IO Request -class BatchOperation { +class BatchOperation : public IBatchOperation { public: /// @brief Create an operation to handle and track an IO request. /// @param [in] params IO parameters diff --git a/hipfile/test/amd_detail/mbatch.h b/hipfile/test/amd_detail/mbatch.h index c59ba908..e5d21bed 100644 --- a/hipfile/test/amd_detail/mbatch.h +++ b/hipfile/test/amd_detail/mbatch.h @@ -15,6 +15,9 @@ namespace hipFile { +class MBatchOperation : public IBatchOperation { +}; + class MBatchContext : public IBatchContext { public: MOCK_METHOD(unsigned, get_capacity, (), (const, noexcept, override)); From 448fb8b9944534d6417152f2cafedbeeeb58c5fd Mon Sep 17 00:00:00 2001 From: Riley Dixon Date: Fri, 28 Nov 2025 15:29:46 -0700 Subject: [PATCH 2/3] Batch: Replace with IBatchOperation. --- hipfile/src/amd_detail/batch/batch.cpp | 4 ++-- hipfile/src/amd_detail/batch/batch.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hipfile/src/amd_detail/batch/batch.cpp b/hipfile/src/amd_detail/batch/batch.cpp index 7ff7c14f..460a7d93 100644 --- a/hipfile/src/amd_detail/batch/batch.cpp +++ b/hipfile/src/amd_detail/batch/batch.cpp @@ -113,7 +113,7 @@ BatchContext::submit_operations(const hipFileIOParams_t *params, unsigned num_pa throw std::invalid_argument(msg.str()); } - std::vector> pending_ops{}; + std::vector> pending_ops{}; // It would be more performant to be able to perform multiple lookups // rather than waiting to lock the DriverState lock for each lookup. @@ -124,7 +124,7 @@ BatchContext::submit_operations(const hipFileIOParams_t *params, unsigned num_pa // file flags. 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); + auto op = std::shared_ptr{new BatchOperation{std::move(param_copy), _buffer, _file}}; pending_ops.push_back(op); } diff --git a/hipfile/src/amd_detail/batch/batch.h b/hipfile/src/amd_detail/batch/batch.h index 7bd07213..8a691aad 100644 --- a/hipfile/src/amd_detail/batch/batch.h +++ b/hipfile/src/amd_detail/batch/batch.h @@ -94,7 +94,7 @@ class BatchContext : public IBatchContext { /// but is not yet complete or completed but not yet retrieved by the /// application. /// shared_ptr as it may need to be passed to a backend. - std::unordered_set> outstanding_ops; + std::unordered_set> outstanding_ops; BatchContext(unsigned capacity); From 69dcde101deccf5f8dc7a076947577c868907a5a Mon Sep 17 00:00:00 2001 From: Riley Dixon Date: Wed, 3 Dec 2025 14:55:57 -0700 Subject: [PATCH 3/3] Use a friend class to gain access to Context's private attrs Create a friend class of BatchContext to be able to peer into BatchContext's private members. This class should not be used in any production code. It is used to be able to seed the BatchContext with mocked Operation data. This will be useful in the future if we want to unit test what happens with completed/failed operations. --- hipfile/src/amd_detail/batch/batch.cpp | 5 +++++ hipfile/src/amd_detail/batch/batch.h | 14 ++++++++++++++ hipfile/test/amd_detail/batch/batch.cpp | 14 ++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/hipfile/src/amd_detail/batch/batch.cpp b/hipfile/src/amd_detail/batch/batch.cpp index 460a7d93..b4133526 100644 --- a/hipfile/src/amd_detail/batch/batch.cpp +++ b/hipfile/src/amd_detail/batch/batch.cpp @@ -133,6 +133,11 @@ BatchContext::submit_operations(const hipFileIOParams_t *params, unsigned num_pa outstanding_ops.insert(pending_ops.begin(), pending_ops.end()); } +std::unordered_set>& +BatchContextAccessor::get_ops_set(BatchContext& _context){ + return _context.outstanding_ops; +} + void BatchContextMap::clear() { diff --git a/hipfile/src/amd_detail/batch/batch.h b/hipfile/src/amd_detail/batch/batch.h index 8a691aad..62d914e6 100644 --- a/hipfile/src/amd_detail/batch/batch.h +++ b/hipfile/src/amd_detail/batch/batch.h @@ -98,9 +98,23 @@ class BatchContext : public IBatchContext { BatchContext(unsigned capacity); + friend class BatchContextAccessor; friend class BatchContextMap; }; +/* + * Friend class of BatchContext + * + * Can be used to peer into BatchContext's hidden members. + * Should not be used in production. + */ +class BatchContextAccessor { +public: + // Return a reference to the unordered_set to modify what ops are loaded + // in the context. + std::unordered_set>& get_ops_set(BatchContext& _context); +}; + class BatchContextMap { public: /*! diff --git a/hipfile/test/amd_detail/batch/batch.cpp b/hipfile/test/amd_detail/batch/batch.cpp index 1c1c0044..e0c4bb70 100644 --- a/hipfile/test/amd_detail/batch/batch.cpp +++ b/hipfile/test/amd_detail/batch/batch.cpp @@ -10,6 +10,7 @@ #include "hipfile-test.h" #include "hipfile-warnings.h" #include "invalid-enum.h" +#include "mbatch.h" #include "mbuffer.h" #include "mfile.h" #include "mstate.h" @@ -348,4 +349,17 @@ TEST_F(HipFileBatchContext, SubmitSingleBadParamModeInvalid) ASSERT_THROW(_context->submit_operations(&bad_io_params, 1), std::invalid_argument); } +// Not a real test - proof of concept +TEST_F(HipFileBatchContext, _InsertMBatchOperationIntoContext) +{ + BatchContextAccessor bca; + auto ops = bca.get_ops_set(*std::dynamic_pointer_cast(_context)); + + std::shared_ptr mock_op = std::make_unique(); + + ops.insert(mock_op); + + ASSERT_EQ(1, ops.size()); +} + HIPFILE_WARN_NO_GLOBAL_CTOR_ON