Move the loader snapshot queue to the reader #5085
Merged
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.
Category:
Refactoring (Redesign of existing code that doesn't affect functionality)
Description:
This PR moves the snapshot queue from the loader to the reader.
Reader already is resposible for prefetching batches, so it makes sense for it to make sure to keep loader's state snapshot after each produced batch. This should simplify loaders code and remove the need for extra mutex to access loaders snapshot queue. The snapshot queue is now advanced alongside the batch prefetch queue, which makes accessing snapshots (reader's by the executor and loader's by the reader) to have no side effects.
The snapshots are put in the queue by the prefetching thread. If the loader cannot be checkpointed at the given moment, the reader simply puts None in the queue and the relevant error is raised on the attempt to access the snapshot. This could be extended to the executor as well (so that it does not have to compute epoch sizes in advance).
In the future, the snapshot queue could be extracted from the reader and provided to it as a dependency similar to loader. This way, we could provide different checkpointing mechanisms to different readers and loaders.
Additional information:
Affected modules and functionalities:
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: DALI-3653