-
Notifications
You must be signed in to change notification settings - Fork 452
Revised inner product #10
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
Merged
Harsha Simhadri (harsha-simhadri)
merged 85 commits into
master
from
revised_inner_product
Aug 11, 2021
Merged
Changes from all commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
a50ce3d
working towards inner product in memory indices
75b4567
done with in-memory code
194820c
made the inner product distance function return std::float_max if neg…
4fa5f9d
more changes for disk index support
661c38b
on the way to disk index support for MIPS
a3962d8
works now, need to change the PQ generation for MIPS
863edb8
now incorporated disk+memory search for inner product
79b1fce
support for mips and l2
a86e2d4
changed inner product to -IP rather than 1/IP
de9ef76
towards adding support for storing PQ vectors in disk index for very …
4dd8de9
towards adding support for storing PQ vectors in disk index for very …
d4a658f
halfway through PQ-based disk search option
833d189
code compiles for disk index pq
b07d032
fixed some bug
d6c6b8d
shards are written as and when necessary
dc5fd39
sharding is now on demand
0a71e59
minor changes
e4a25e6
fixed one malloc bug in parameters
974697b
added a vector analyzer util
787819a
added missing file
d5b3a29
fixed a bug which used L2 instead of inner product in cached beam search
b51fea7
now setting up the normalizing approach
a2e4b92
towards pre-processing data
3538324
working towards newer inner product
f5e55d1
more changes to do MIPS by reducing to L2 with extra coordinate
6fe07e0
cleaned up code a bit, need to test everything again
aa707f2
testing underway
54630f1
added back saturate graph to create denser indices
dd210bf
now we dont sample a new test dataset every iteration for estimating …
dac9d4b
now num_parts increases by 2
2ad0953
cleaned up warnings in Debug mode compiler
247f83e
working towards inner product in memory indices
e339efd
done with in-memory code
674722e
made the inner product distance function return std::float_max if neg…
34bfa3f
more changes for disk index support
b81b90a
on the way to disk index support for MIPS
6f2aa4e
works now, need to change the PQ generation for MIPS
0a21b45
now incorporated disk+memory search for inner product
1e1e14c
support for mips and l2
92f583d
changed inner product to -IP rather than 1/IP
035579e
towards adding support for storing PQ vectors in disk index for very …
af0dfab
towards adding support for storing PQ vectors in disk index for very …
52d2180
halfway through PQ-based disk search option
f4fbee2
code compiles for disk index pq
cb966dc
fixed some bug
3070a29
shards are written as and when necessary
e916751
sharding is now on demand
063336a
minor changes
6ded4aa
fixed one malloc bug in parameters
66393e7
added a vector analyzer util
56cf277
added missing file
43d94c6
fixed a bug which used L2 instead of inner product in cached beam search
31b2ae1
now setting up the normalizing approach
c36f77a
towards pre-processing data
96a5cef
working towards newer inner product
8c314e1
more changes to do MIPS by reducing to L2 with extra coordinate
fc7efff
cleaned up code a bit, need to test everything again
d1f9fcc
testing underway
d7edf6c
added back saturate graph to create denser indices
5104813
now we dont sample a new test dataset every iteration for estimating …
971a90c
now num_parts increases by 2
552e0f1
cleaned up warnings in Debug mode compiler
39fc6d9
added a normalizer to vector analysis
4be0297
added normalize option for vector analyzer
313cbda
fixed one bug for MIPS
9c61b08
addressed all comments of PR
96eba25
fixed minor typos. now running unit tests
d018a20
ran clang-format as it doesnt run by default due to LINUX flag not se…
f5426d8
clang introduced a bug in distance.h, fixed itt
d5b528d
added unit tester partially
b2078d6
minor bugfix
361a4c7
finished unit tester
b70ca3c
changed back training size to 100K for now, we can increase to 1M lat…
48cc376
added comments for unit_tester.sh
e16e411
added auto tuning parameters for unit tester
c169ea3
re-ran clang formatting
c42f3a1
small change to unit tester
3a30d70
fixed minor bug in unit tester
c7f39c9
fixed some formatting on unit tester
18ad0ee
started code for range search support in pq_flash_index
42d0c00
added more code for range search in disk index
f21883d
added range search support
197d271
tested range search on small dataset
8707a1a
Update memory_mapper.h
harsha-simhadri 90d08be
minor edits
harsha-simhadri 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
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
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 |
|---|---|---|
|
|
@@ -255,11 +255,16 @@ namespace diskann { | |
| virtual float compare(const int8_t *a, const int8_t *b, | ||
| unsigned int length) const { | ||
| #ifndef _WINDOWS | ||
| std::cout << "AVX only supported in Windows build."; | ||
| return 0; | ||
| int32_t result = 0; | ||
| #pragma omp simd reduction(+ : result) aligned(a, b : 8) | ||
| for (_s32 i = 0; i < (_s32) length; i++) { | ||
| result += ((int32_t)((int16_t) a[i] - (int16_t) b[i])) * | ||
| ((int32_t)((int16_t) a[i] - (int16_t) b[i])); | ||
| } | ||
| return (float) result; | ||
| } | ||
| #else | ||
| __m128 r = _mm_setzero_ps(); | ||
| __m128 r = _mm_setzero_ps(); | ||
| __m128i r1; | ||
| while (length >= 16) { | ||
| r1 = _mm_subs_epi8(_mm_load_si128((__m128i *) a), | ||
|
|
@@ -273,7 +278,7 @@ namespace diskann { | |
| float res = r.m128_f32[0]; | ||
|
|
||
| if (length >= 8) { | ||
| __m128 r2 = _mm_setzero_ps(); | ||
| __m128 r2 = _mm_setzero_ps(); | ||
| __m128i r3 = _mm_subs_epi8(_mm_load_si128((__m128i *) (a - 8)), | ||
| _mm_load_si128((__m128i *) (b - 8))); | ||
| r2 = _mm_add_ps(r2, _mm_mulhi_epi8(r3)); | ||
|
|
@@ -285,7 +290,7 @@ namespace diskann { | |
| } | ||
|
|
||
| if (length >= 4) { | ||
| __m128 r2 = _mm_setzero_ps(); | ||
| __m128 r2 = _mm_setzero_ps(); | ||
| __m128i r3 = _mm_subs_epi8(_mm_load_si128((__m128i *) (a - 12)), | ||
| _mm_load_si128((__m128i *) (b - 12))); | ||
| r2 = _mm_add_ps(r2, _mm_mulhi_epi8_shift32(r3)); | ||
|
|
@@ -302,8 +307,12 @@ namespace diskann { | |
| virtual float compare(const float *a, const float *b, | ||
| unsigned int length) const { | ||
| #ifndef _WINDOWS | ||
|
Contributor
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. Is this ifndef _WINDOWS or ifdef linux
Contributor
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. it should be ifdef LINUX, but we need a much bigger change, so leaving as is. |
||
| std::cout << "AVX only supported in Windows build."; | ||
| return 0; | ||
| float result = 0; | ||
| #pragma omp simd reduction(+ : result) aligned(a, b : 8) | ||
| for (_s32 i = 0; i < (_s32) length; i++) { | ||
| result += (a[i] - b[i]) * (a[i] - b[i]); | ||
| } | ||
| return result; | ||
| } | ||
| #else | ||
| __m128 diff, v1, v2; | ||
|
|
@@ -328,7 +337,7 @@ namespace diskann { | |
| template<typename T> | ||
| class DistanceInnerProduct : public Distance<T> { | ||
| public: | ||
| float compare(const T *a, const T *b, unsigned size) const { | ||
| float inner_product(const T *a, const T *b, unsigned size) const { | ||
| float result = 0; | ||
| #ifdef __GNUC__ | ||
| #ifdef __AVX__ | ||
|
|
@@ -426,10 +435,21 @@ namespace diskann { | |
| #endif | ||
| return result; | ||
| } | ||
| float compare(const T *a, const T *b, unsigned size) | ||
| const { // since we use normally minimization objective for distance | ||
| // comparisons, we are returning 1/x. | ||
| float result = inner_product(a, b, size); | ||
| // if (result < 0) | ||
| // return std::numeric_limits<float>::max(); | ||
| // else | ||
| return -result; | ||
| } | ||
| }; | ||
|
|
||
| template<typename T> | ||
| class DistanceFastL2 : public DistanceInnerProduct<T> { | ||
| class DistanceFastL2 | ||
| : public DistanceInnerProduct<T> { // currently defined only for float. | ||
| // templated for future use. | ||
| public: | ||
| float norm(const T *a, unsigned size) const { | ||
| float result = 0; | ||
|
|
@@ -522,7 +542,7 @@ namespace diskann { | |
| using DistanceInnerProduct<T>::compare; | ||
| float compare(const T *a, const T *b, float norm, | ||
| unsigned size) const { // not implement | ||
| float result = -2 * DistanceInnerProduct<T>::compare(a, b, size); | ||
| float result = -2 * DistanceInnerProduct<T>::inner_product(a, b, size); | ||
| result += norm; | ||
| return result; | ||
| } | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -12,4 +12,4 @@ namespace diskann { | |
| : std::logic_error("Function not yet implemented.") { | ||
| } | ||
| }; | ||
| } | ||
| } // namespace diskann | ||
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
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 |
|---|---|---|
|
|
@@ -38,4 +38,4 @@ namespace diskann { | |
|
|
||
| ~MemoryMapper(); | ||
| }; | ||
| } | ||
| } // namespace diskann | ||
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
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
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,4 +58,4 @@ namespace diskann { | |
| } | ||
| return avg / len; | ||
| } | ||
| } | ||
| } // namespace diskann | ||
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
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.
Did you mean to change this?
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.
Let's make it larger, to a million. If necessary we can make it small.