Class ov::util::ParallelReadStreamBuf#
-
class ParallelReadStreamBuf : public std::streambuf#
A std::streambuf that reads from a file using parallel I/O for large reads, bypassing the OS page cache pressure that mmap+memcpy incurs.
For reads >= threshold bytes, the read is split across N threads where each thread issues its own independent positional read operation using platform-specific APIs. Smaller reads fall through to a single positional call.
Usage:
ParallelReadStreamBuf buf(cache_path, blob_offset_in_file); std::istream stream(&buf); cldnn::BinaryInputBuffer ib(stream, engine); ib >> ...;
Public Functions
-
explicit ParallelReadStreamBuf(const std::filesystem::path &path, std::streamoff header_offset = 0, size_t threshold = default_parallel_io_threshold)#
- Parameters:
path – Path to the file to read.
header_offset – Initial file position (absolute offset from the start of the file; the stream starts reading from here).
threshold – Minimum read size to trigger parallel I/O.
-
bool prefetch(std::streamsize size)#
Preload
sizebytes starting at the current logical position into an internal buffer using one parallel positional read.After a successful prefetch, subsequent xsgetn()/underflow() calls that fall inside [current_pos, current_pos + size) are served from memory via memcpy instead of issuing per-call pread(). Reads that fall outside the prefetched window transparently fall back to the normal file-IO path and invalidate the prefetched window.
Intended call site: the producer of a long serialized region (e.g. program::weights_load in the GPU plugin) calls prefetch() once at the start of the region to collapse thousands of small ib >> … small-reads into a single bulk parallel pread.
- Parameters:
size – Number of bytes to preload. Clamped to remaining file size.
- Returns:
true if the prefetch read succeeded (buffer is now valid), false otherwise (buffer is left empty; reads fall back to file I/O).
-
explicit ParallelReadStreamBuf(const std::filesystem::path &path, std::streamoff header_offset = 0, size_t threshold = default_parallel_io_threshold)#