-
Notifications
You must be signed in to change notification settings - Fork 7
Introducing a new reader to read index using a pointer #8
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
Changes from all commits
92fb41b
da897c8
dbb2aa9
b27747d
472dc6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,35 @@ size_t VectorIOReader::operator()(void* ptr, size_t size, size_t nitems) { | |
| return nitems; | ||
| } | ||
|
|
||
| /*********************************************************************** | ||
| * IO Buffer | ||
| ***********************************************************************/ | ||
|
|
||
| size_t BufIOReader::operator()(void* ptr, size_t size, size_t nitems) { | ||
| // if the read pointer has passed the buffer size, exit out since we've | ||
| // read the complete index | ||
| if (rp >= buf_size) | ||
| return 0; | ||
|
|
||
| // check how many "items" of a particular size are to be read from the buffer | ||
| // the size of the item depends on the datatype of field being populated. | ||
| size_t nremain = (buf_size - rp) / size; | ||
| if (nremain < nitems) // we don't have enough items to be read, in which case | ||
| nitems = nremain; // read all the remaining ones | ||
| if (size * nitems > 0) { | ||
| // finally memcpy the data from buffer to the field of the index being | ||
| // populated and increment the read pointer. | ||
| memcpy(ptr, &buf[rp], size * nitems); | ||
| rp += size * nitems; | ||
| } | ||
|
|
||
| return nitems; | ||
| } | ||
|
|
||
| BufIOReader::~BufIOReader() { | ||
|
Member
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. Shouldn't we be calling
Member
Author
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. the main reason why i avoided that is because shifting the responsibility to the caller helps making better decisions as to whether we want to reuse the pointer and the memory block (which i've commented on the go-faiss write-read path) thereby reducing the costs of allocation or just free the memory block of that pointer (which we are doing right now and is being revisited for reusability purposes). please let me know if that makes sense, thanks
Member
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. Ok, we want to optimize more down this stack in the C++ side of things. We'll chat next week. |
||
| buf = NULL; | ||
| } | ||
|
|
||
| /*********************************************************************** | ||
| * IO File | ||
| ***********************************************************************/ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.