mmap() - backed istream implementation #150
Closed
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.
This is for issue #91.
Treat this as a first draft. There are definitely some thing that need to be changed and will be changed shortly.
I have not benchmarked. I'm submitting the PR early to get feedback.
Questions/Observations for discussion:
llama_istream
be a part ofutils.cpp
?MADV_SEQUENTIAL
is probably wrong, as brought up in Should usemmap
for model loading #91. I'll benchmark to make sure, then fix that before it's merged.llama_istream
, the intent was that you wouldn't have to checkUSE_MMAP
at the site where it's constructed. Reduce model loading time #43 throws a wrench in that. I could create a quick wrapper class, rather than usingusing
. It might be a little confusing when people merge though.std::istream
's copy constructor is explicitly deleted. So I can't get it out of a function except as an rvalue as the return value (or a global variable which I think would be worse), and the convention elsewhere is that the return value is for the error.istream
was WAY more painful than I expected. For some reason, if I don't reimplementseekoff()
andseekpos()
this way,tellg()
seems to return garbage. Couldn't tell you why. Nor can I find any hint of why on the internet. The signature is also very finicky. If you have any insight into why it needs to be exactly this way, let me know.mmap()
arguments to use. If you have a better suggestion, let me know.