-
Notifications
You must be signed in to change notification settings - Fork 14
feat!: Add the ability to probe a data_batch
#77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dhruv9vats
wants to merge
2
commits into
NVIDIA:main
Choose a base branch
from
dhruv9vats:data-batch-probe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+131
−37
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,34 @@ enum class batch_state { | |||||
| in_transit ///< Batch is currently being moved to a different memory tier | ||||||
| }; | ||||||
|
|
||||||
| /** | ||||||
| * @brief Interface for probing the data_batch class. | ||||||
| * | ||||||
| * Applications may implement this interface to hold additional application specific | ||||||
| * data_batch metadata while probing the data_batch by overriding the provided methods | ||||||
| * that expose the data_batch state when certain events occur, like state transitions. | ||||||
| */ | ||||||
| class idata_batch_probe { | ||||||
| public: | ||||||
| virtual ~idata_batch_probe() = default; | ||||||
|
|
||||||
| /** | ||||||
| * @brief The function that is called everytime a data_batch transitions into a new batch_state. | ||||||
| * | ||||||
| * @note It is the implementer's responsibility that a call to this function returns quickly, as | ||||||
| * this function is called in a thread-safe manner, and will block other mutating changes | ||||||
| * while this executes. Primarily intended for bookkeeping purposes. | ||||||
| */ | ||||||
| virtual void state_transitioned_to([[maybe_unused]] const batch_state& new_state, | ||||||
| [[maybe_unused]] const uint64_t& batch_id, | ||||||
| [[maybe_unused]] const idata_representation& data, | ||||||
| [[maybe_unused]] const size_t& processing_count, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| [[maybe_unused]] const size_t& task_created_count) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| { | ||||||
| // The default impl is no-op. | ||||||
| } | ||||||
| }; | ||||||
|
|
||||||
| // Forward declarations | ||||||
| class data_batch; | ||||||
| class data_batch_processing_handle; | ||||||
|
|
@@ -192,8 +220,11 @@ class data_batch : public std::enable_shared_from_this<data_batch> { | |||||
| * | ||||||
| * @param batch_id Unique identifier for this batch | ||||||
| * @param data Ownership of the data representation is transferred to this batch | ||||||
| * @param probe @copydoc idata_batch_probe | ||||||
| */ | ||||||
| data_batch(uint64_t batch_id, std::unique_ptr<idata_representation> data); | ||||||
| data_batch(uint64_t batch_id, | ||||||
| std::unique_ptr<idata_representation> data, | ||||||
| std::unique_ptr<idata_batch_probe> probe = std::make_unique<idata_batch_probe>()); | ||||||
|
|
||||||
| /** | ||||||
| * @brief Move constructor - transfers ownership of the batch and its data. | ||||||
|
|
@@ -353,14 +384,17 @@ class data_batch : public std::enable_shared_from_this<data_batch> { | |||||
| * @param new_batch_id The batch ID for the cloned batch | ||||||
| * @param target_memory_space The memory space where the new representation will be allocated | ||||||
| * @param stream CUDA stream for memory operations | ||||||
| * @param probe Optional @copydoc idata_batch_probe | ||||||
| * @return std::shared_ptr<data_batch> A new data_batch with cloned data | ||||||
| * @throws std::runtime_error if there is active processing on this batch | ||||||
| */ | ||||||
| template <typename TargetRepresentation> | ||||||
| std::shared_ptr<data_batch> clone_to(representation_converter_registry& registry, | ||||||
| uint64_t new_batch_id, | ||||||
| const cucascade::memory::memory_space* target_memory_space, | ||||||
| rmm::cuda_stream_view stream); | ||||||
| std::shared_ptr<data_batch> clone_to( | ||||||
| representation_converter_registry& registry, | ||||||
| uint64_t new_batch_id, | ||||||
| const cucascade::memory::memory_space* target_memory_space, | ||||||
| rmm::cuda_stream_view stream, | ||||||
| std::optional<std::unique_ptr<idata_batch_probe>> probe = std::nullopt); | ||||||
|
|
||||||
| /** | ||||||
| * @brief Attempt to create a task for this batch. | ||||||
|
|
@@ -449,11 +483,15 @@ class data_batch : public std::enable_shared_from_this<data_batch> { | |||||
| * | ||||||
| * @param new_batch_id The batch ID for the cloned batch | ||||||
| * @param stream CUDA stream for memory operations | ||||||
| * @param probe Optional @copydoc idata_batch_probe | ||||||
| * @return std::shared_ptr<data_batch> A new data_batch with copied data | ||||||
| * @throws std::runtime_error if the batch is in in_transit state | ||||||
| * @throws std::runtime_error if the underlying data is null | ||||||
| */ | ||||||
| std::shared_ptr<data_batch> clone(uint64_t new_batch_id, rmm::cuda_stream_view stream); | ||||||
| std::shared_ptr<data_batch> clone( | ||||||
| uint64_t new_batch_id, | ||||||
| rmm::cuda_stream_view stream, | ||||||
| std::optional<std::unique_ptr<idata_batch_probe>> probe = std::nullopt); | ||||||
|
|
||||||
| private: | ||||||
| friend class data_batch_processing_handle; | ||||||
|
|
@@ -466,13 +504,25 @@ class data_batch : public std::enable_shared_from_this<data_batch> { | |||||
| */ | ||||||
| void decrement_processing_count(); | ||||||
|
|
||||||
| /** | ||||||
| * @brief Handle a state transition by updating _state and invoking the probe callback. | ||||||
| * | ||||||
| * Must be called while the caller holds _mutex. Passes all member fields except _mutex | ||||||
| * and _state_change_cv as const references to the probe callback. | ||||||
| * | ||||||
| * @param new_state The state to transition to | ||||||
| * @param lock Reference to the lock proving the mutex is held | ||||||
| */ | ||||||
| void update_state_to(batch_state new_state, const std::unique_lock<std::mutex>& lock); | ||||||
|
|
||||||
| mutable std::mutex _mutex; ///< Mutex for thread-safe access to state and processing count | ||||||
| std::condition_variable _internal_cv; ///< CV used by blocking wait_to_* calls | ||||||
| uint64_t _batch_id; ///< Unique identifier for this data batch | ||||||
| std::unique_ptr<idata_representation> _data; ///< Pointer to the actual data representation | ||||||
| size_t _processing_count = 0; ///< Count of active processing handles | ||||||
| size_t _task_created_count = 0; ///< Count of pending task_created requests | ||||||
| batch_state _state = batch_state::idle; ///< Current state of the batch | ||||||
| std::unique_ptr<idata_batch_probe> _probe; ///< Probe for observing state transitions | ||||||
| std::condition_variable* _state_change_cv = nullptr; ///< Optional CV to notify on state change | ||||||
| }; | ||||||
|
|
||||||
|
|
@@ -498,7 +548,8 @@ std::shared_ptr<data_batch> data_batch::clone_to( | |||||
| representation_converter_registry& registry, | ||||||
| uint64_t new_batch_id, | ||||||
| const cucascade::memory::memory_space* target_memory_space, | ||||||
| rmm::cuda_stream_view stream) | ||||||
| rmm::cuda_stream_view stream, | ||||||
| std::optional<std::unique_ptr<idata_batch_probe>> probe) | ||||||
| { | ||||||
| std::lock_guard<std::mutex> lock(_mutex); | ||||||
|
|
||||||
|
|
@@ -508,7 +559,10 @@ std::shared_ptr<data_batch> data_batch::clone_to( | |||||
|
|
||||||
| auto new_representation = | ||||||
| registry.convert<TargetRepresentation>(*_data, target_memory_space, stream); | ||||||
| return std::make_shared<data_batch>(new_batch_id, std::move(new_representation)); | ||||||
| return std::make_shared<data_batch>( | ||||||
| new_batch_id, | ||||||
| std::move(new_representation), | ||||||
| probe ? std::move(*probe) : std::make_unique<idata_batch_probe>()); | ||||||
| } | ||||||
|
|
||||||
| } // namespace cucascade | ||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be trivial to copy (and more of these below)