Skip to content

Fix inner product distance code to vectorize on arm (affects all arch)#668

Open
pmiloslavsky wants to merge 2 commits into
nmslib:developfrom
pmiloslavsky:develop
Open

Fix inner product distance code to vectorize on arm (affects all arch)#668
pmiloslavsky wants to merge 2 commits into
nmslib:developfrom
pmiloslavsky:develop

Conversation

@pmiloslavsky
Copy link
Copy Markdown

Summary

Fixed inner product code to vectorize by removing inner loop use of void.

Changed example_search to also demonstrate use of IP space with normalization and print index build timing.

Validation

Disassembled example_search InnerProductDistance with gdb and checked for fmla instruction on ARM, Ubuntu 24 ARM.

gdb -batch -ex 'disassemble/rs _ZN7hnswlibL20InnerProductDistanceEPKvS1_S1_' ./example_search

Ran
python -m unittest discover --start-directory tests/python --pattern "bindings_test*.py"

Before fix (but with example_search.cpp copied over):

   0x0000000000002b34 <+52>:	1f000441	fmadd	s1, s2, s0, s1
...
pmilosla@iscinternal.com@qdub24arm1:/nethome/pmilosla/projects/hnswlib/testbed_linux_arm/hnswlib_clean/hnswlib$ build/example_search 
Running l2 test...
l2 index build time: 1.03063 seconds (1030.63 ms)
l2 Recall: 1
l2 Recall of deserialized index: 1

Running ip_normalized test...
ip_normalized index build time: 1.18953 seconds (1189.53 ms)
ip_normalized Recall: 1
ip_normalized Recall of deserialized index: 1

After fix (note decreased time for ip):

   0x0000000000002b30 <+48>:	4e21cc40	fmla	v0.4s, v2.4s, v1.4s
...
pmilosla@iscinternal.com@qdub24arm1:/nethome/pmilosla/projects/hnswlib/testbed_linux_arm/hnswlib_fixed/hnswlib$ build/example_search 
Running l2 test...
l2 index build time: 1.02962 seconds (1029.62 ms)
l2 Recall: 1
l2 Recall of deserialized index: 1

Running ip_normalized test...
ip_normalized index build time: 0.999375 seconds (999.375 ms)
ip_normalized Recall: 1
ip_normalized Recall of deserialized index: 1


@pmiloslavsky
Copy link
Copy Markdown
Author

@kiplingw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant