usearch 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/.clang-format +10 -0
  2. package/.github/workflows/package.json +82 -0
  3. package/.github/workflows/release.yml +111 -0
  4. package/.gitmodules +6 -0
  5. package/.vscode/launch.json +116 -0
  6. package/.vscode/settings.json +109 -0
  7. package/.vscode/tasks.json +35 -0
  8. package/CMakeLists.txt +84 -0
  9. package/CMakeListsInstructuons.md +109 -0
  10. package/README.md +69 -0
  11. package/VERSION +1 -0
  12. package/assets/unum.png +0 -0
  13. package/binding.gyp +28 -0
  14. package/build.rs +14 -0
  15. package/cargo.toml +15 -0
  16. package/cmake/clipp.cmake +8 -0
  17. package/cmake/jemalloc.cmake +80 -0
  18. package/docs/Makefile +20 -0
  19. package/docs/_static/custom.css +26 -0
  20. package/docs/_static/custom.js +7 -0
  21. package/docs/conf.py +48 -0
  22. package/docs/index.rst +10 -0
  23. package/fp16/CMakeLists.txt +176 -0
  24. package/fp16/LICENSE +11 -0
  25. package/fp16/README.md +20 -0
  26. package/fp16/bench/alt-element.cc +89 -0
  27. package/fp16/bench/from-alt-array.cc +175 -0
  28. package/fp16/bench/from-ieee-array.cc +399 -0
  29. package/fp16/bench/ieee-element.cc +272 -0
  30. package/fp16/bench/to-alt-array.cc +91 -0
  31. package/fp16/bench/to-ieee-array.cc +303 -0
  32. package/fp16/cmake/DownloadGoogleBenchmark.cmake +15 -0
  33. package/fp16/cmake/DownloadGoogleTest.cmake +15 -0
  34. package/fp16/cmake/DownloadPSimd.cmake +15 -0
  35. package/fp16/configure.py +65 -0
  36. package/fp16/confu.yaml +8 -0
  37. package/fp16/include/fp16/__init__.py +0 -0
  38. package/fp16/include/fp16/avx.py +50 -0
  39. package/fp16/include/fp16/avx2.py +53 -0
  40. package/fp16/include/fp16/bitcasts.h +92 -0
  41. package/fp16/include/fp16/fp16.h +451 -0
  42. package/fp16/include/fp16/psimd.h +131 -0
  43. package/fp16/include/fp16.h +11 -0
  44. package/fp16/jni/Android.mk +6 -0
  45. package/fp16/jni/Application.mk +4 -0
  46. package/fp16/test/alt-from-fp32-value.cc +498 -0
  47. package/fp16/test/alt-to-fp32-bits.cc +263 -0
  48. package/fp16/test/alt-to-fp32-psimd.cc +145 -0
  49. package/fp16/test/alt-to-fp32-value.cc +348 -0
  50. package/fp16/test/alt-to-fp32x2-psimd.cc +245 -0
  51. package/fp16/test/bitcasts.cc +56 -0
  52. package/fp16/test/ieee-from-fp32-value.cc +523 -0
  53. package/fp16/test/ieee-to-fp32-bits.cc +333 -0
  54. package/fp16/test/ieee-to-fp32-psimd.cc +312 -0
  55. package/fp16/test/ieee-to-fp32-value.cc +420 -0
  56. package/fp16/test/ieee-to-fp32x2-psimd.cc +541 -0
  57. package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +96 -0
  58. package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +96 -0
  59. package/fp16/test/peachpy/stubs.py +38 -0
  60. package/fp16/test/tables.cc +530 -0
  61. package/fp16/test/tables.h +13 -0
  62. package/fp16/third-party/THHalf.h +92 -0
  63. package/fp16/third-party/eigen-half.h +170 -0
  64. package/fp16/third-party/float16-compressor.h +80 -0
  65. package/fp16/third-party/half.hpp +2916 -0
  66. package/fp16/third-party/npy-halffloat.h +328 -0
  67. package/include/usearch/usearch.hpp +1345 -0
  68. package/package.json +19 -0
  69. package/pyproject.toml +33 -0
  70. package/setup.py +63 -0
  71. package/simsimd/.clang-format +10 -0
  72. package/simsimd/.vscode/launch.json +24 -0
  73. package/simsimd/.vscode/settings.json +73 -0
  74. package/simsimd/.vscode/tasks.json +17 -0
  75. package/simsimd/CMakeLists.txt +82 -0
  76. package/simsimd/LICENSE +201 -0
  77. package/simsimd/README.md +73 -0
  78. package/simsimd/bench.cxx +82 -0
  79. package/simsimd/include/simsimd/simsimd.h +322 -0
  80. package/simsimd/include/simsimd/simsimd.hpp +443 -0
  81. package/src/advanced.hpp +489 -0
  82. package/src/bench.cpp +415 -0
  83. package/src/bench.py +89 -0
  84. package/src/javascript.cpp +198 -0
  85. package/src/main.rs +42 -0
  86. package/src/python.cpp +226 -0
  87. package/src/rust.cpp +23 -0
  88. package/src/rust.h +22 -0
  89. package/src/test.js +17 -0
  90. package/src/test.py +20 -0
package/.clang-format ADDED
@@ -0,0 +1,10 @@
1
+ Language: Cpp
2
+ BasedOnStyle: LLVM
3
+ IndentWidth: 4
4
+ TabWidth: 4
5
+ NamespaceIndentation: None
6
+ ColumnLimit: 120
7
+ ReflowComments: true
8
+ UseTab: Never
9
+ PointerAlignment: Left
10
+ AllowShortCaseLabelsOnASingleLine: True
@@ -0,0 +1,82 @@
1
+ {
2
+ "devDependencies": {
3
+ "@semantic-release/exec": "github:semantic-release/exec",
4
+ "@semantic-release/git": "^10.0.1",
5
+ "conventional-changelog-eslint": "^3.0.9",
6
+ "semantic-release": "^20.1.3"
7
+ },
8
+ "release": {
9
+ "branches": [
10
+ "main"
11
+ ],
12
+ "debug": true,
13
+ "ci": true,
14
+ "dryRun": false,
15
+ "plugins": [
16
+ [
17
+ "@semantic-release/commit-analyzer",
18
+ {
19
+ "preset": "eslint",
20
+ "releaseRules": [
21
+ {
22
+ "tag": "Add",
23
+ "release": "minor"
24
+ },
25
+ {
26
+ "tag": "Improve",
27
+ "release": "patch"
28
+ },
29
+ {
30
+ "tag": "Make",
31
+ "release": "patch"
32
+ },
33
+ {
34
+ "tag": "Refactor",
35
+ "release": false
36
+ }
37
+ ]
38
+ }
39
+ ],
40
+ [
41
+ "@semantic-release/release-notes-generator",
42
+ {
43
+ "preset": "eslint",
44
+ "releaseRules": [
45
+ {
46
+ "tag": "Add",
47
+ "release": "minor"
48
+ },
49
+ {
50
+ "tag": "Improve",
51
+ "release": "patch"
52
+ },
53
+ {
54
+ "tag": "Make",
55
+ "release": "patch"
56
+ },
57
+ {
58
+ "tag": "Refactor",
59
+ "release": false
60
+ }
61
+ ]
62
+ }
63
+ ],
64
+ "@semantic-release/github",
65
+ [
66
+ "@semantic-release/exec",
67
+ {
68
+ "prepareCmd": "echo '${nextRelease.version}' > VERSION"
69
+ }
70
+ ],
71
+ [
72
+ "@semantic-release/git",
73
+ {
74
+ "assets": [
75
+ "VERSION"
76
+ ],
77
+ "message": "Build: Released ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
78
+ }
79
+ ]
80
+ ]
81
+ }
82
+ }
@@ -0,0 +1,111 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+
7
+ env:
8
+ BUILD_TYPE: Release
9
+ GH_TOKEN: ${{ secrets.SEMANTIC_RELEASE_TOKEN }}
10
+
11
+ # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12
+ permissions:
13
+ contents: read
14
+ pages: write
15
+ id-token: write
16
+
17
+ jobs:
18
+
19
+ # versioning:
20
+ # name: Semantic Release
21
+ # runs-on: ubuntu-latest
22
+ # steps:
23
+ # - uses: actions/checkout@v3
24
+ # with:
25
+ # persist-credentials: false
26
+ # - uses: actions/setup-node@v3
27
+ # - run: cp .github/workflows/package.json . && npm install && npx semantic-release
28
+
29
+ build_wheels:
30
+ name: Build Wheels for ${{ matrix.os }}
31
+ runs-on: ${{ matrix.os }}
32
+ # needs: versioning
33
+ strategy:
34
+ matrix:
35
+ os: [ubuntu-20.04, macOS-11]
36
+
37
+ steps:
38
+ - uses: actions/checkout@v3
39
+ with:
40
+ ref: 'main'
41
+ - uses: actions/setup-python@v3
42
+ - uses: crazy-max/ghaction-setup-docker@v1.0.0
43
+ with:
44
+ version: 23.0.1
45
+ - uses: docker/setup-qemu-action@v2.1.0
46
+
47
+ - name: Install CIBuildWheel
48
+ run: python -m pip install cibuildwheel
49
+
50
+ - name: Build wheels
51
+ run: python -m cibuildwheel
52
+
53
+ - uses: actions/upload-artifact@v3
54
+ with:
55
+ path: ./wheelhouse/*.whl
56
+
57
+
58
+ publish_wheels:
59
+ name: Publish Wheels to PyPi
60
+ runs-on: ubuntu-20.04
61
+ needs: build_wheels
62
+ environment:
63
+ name: pypi
64
+ url: https://pypi.org/p/usearch
65
+ permissions:
66
+ id-token: write
67
+
68
+ steps:
69
+ - name: Download artifacts
70
+ uses: actions/download-artifact@v3.0.2
71
+ with:
72
+ path: ./dist/
73
+
74
+ - name: Publish to PyPi
75
+ uses: pypa/gh-action-pypi-publish@release/v1
76
+ with:
77
+ packages_dir: ./dist/artifact
78
+ verbose: true
79
+ print_hash: true
80
+
81
+
82
+ deploy_docs:
83
+ name: Deploy Docs
84
+ environment:
85
+ name: github-pages
86
+ url: ${{ steps.deployment.outputs.page_url }}
87
+ runs-on: ubuntu-22.04
88
+ needs: publish_wheels
89
+ steps:
90
+ - name: Checkout
91
+ uses: actions/checkout@v3
92
+ with:
93
+ ref: 'main'
94
+ - name: Setup GitHub Pages
95
+ uses: actions/configure-pages@v2
96
+ - name: Install dependencies
97
+ run: sudo apt update && sudo apt install -y doxygen graphviz dia git && pip install sphinx breathe furo m2r2 sphinxcontrib-googleanalytics==0.2.dev20220708 sphinxcontrib-jquery
98
+ - name: Install USearch from PyPi
99
+ run: pip install usearch
100
+ - name: Build documentation
101
+ run: cd docs && make html
102
+ - name: Copy assets
103
+ run: cp -r assets build/docs/html/
104
+ - name: Upload artifacts
105
+ uses: actions/upload-pages-artifact@v1
106
+ with:
107
+ # Upload entire repository
108
+ path: "./build/docs/html/"
109
+ - name: Deploy to GitHub Pages
110
+ id: deployment
111
+ uses: actions/deploy-pages@v1
package/.gitmodules ADDED
@@ -0,0 +1,6 @@
1
+ [submodule "simsimd"]
2
+ path = simsimd
3
+ url = https://github.com/ashvardanian/simsimd
4
+ [submodule "fp16"]
5
+ path = fp16
6
+ url = https://github.com/maratyszcza/fp16
@@ -0,0 +1,116 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Debug C++ Bench on Wiki 1M @Cos",
9
+ "type": "cppdbg",
10
+ "request": "launch",
11
+ "program": "${workspaceFolder}/build_debug/bench",
12
+ "cwd": "${workspaceFolder}",
13
+ "args": [
14
+ "--vectors",
15
+ "datasets/wiki_1M/base.1M.fbin",
16
+ "--queries",
17
+ "datasets/wiki_1M/query.public.100K.fbin",
18
+ "--neighbors",
19
+ "datasets/wiki_1M/groundtruth.public.100K.ibin",
20
+ "--ip"
21
+ ],
22
+ "environment": [
23
+ {
24
+ "name": "ASAN_OPTIONS",
25
+ "value": "detect_leaks=0:atexit=1:strict_init_order=1:strict_string_checks=1"
26
+ }
27
+ ],
28
+ "stopAtEntry": false,
29
+ "linux": {
30
+ "preLaunchTask": "Linux Build C++ Bench Debug",
31
+ "MIMode": "gdb"
32
+ },
33
+ "osx": {
34
+ "preLaunchTask": "MacOS Build C++ Bench Debug",
35
+ "MIMode": "lldb"
36
+ }
37
+ },
38
+ {
39
+ "name": "Debug C++ Bench on Text-to-Image 1M @Cos",
40
+ "type": "cppdbg",
41
+ "request": "launch",
42
+ "program": "${workspaceFolder}/build_debug/bench",
43
+ "cwd": "${workspaceFolder}",
44
+ "args": [
45
+ "--vectors",
46
+ "datasets/t2i_1M/base.1M.fbin",
47
+ "--queries",
48
+ "datasets/t2i_1M/query.public.100K.fbin",
49
+ "--neighbors",
50
+ "datasets/t2i_1M/groundtruth.public.100K.ibin",
51
+ ],
52
+ "environment": [
53
+ {
54
+ "name": "ASAN_OPTIONS",
55
+ "value": "detect_leaks=0:atexit=1:strict_init_order=1:strict_string_checks=1"
56
+ }
57
+ ],
58
+ "stopAtEntry": false,
59
+ "linux": {
60
+ "preLaunchTask": "Linux Build C++ Bench Debug",
61
+ "MIMode": "gdb"
62
+ },
63
+ "osx": {
64
+ "preLaunchTask": "MacOS Build C++ Bench Debug",
65
+ "MIMode": "lldb"
66
+ }
67
+ },
68
+ {
69
+ "name": "Run C++ Bench on Text-to-Image 1M @Cos",
70
+ "type": "cppdbg",
71
+ "request": "launch",
72
+ "program": "${workspaceFolder}/build_release/bench",
73
+ "cwd": "${workspaceFolder}",
74
+ "args": [
75
+ "--vectors",
76
+ "datasets/t2i_1M/base.1M.fbin",
77
+ "--queries",
78
+ "datasets/t2i_1M/query.public.100K.fbin",
79
+ "--neighbors",
80
+ "datasets/t2i_1M/groundtruth.public.100K.ibin",
81
+ ],
82
+ "stopAtEntry": false,
83
+ "preLaunchTask": "Linux Build C++ Bench Release",
84
+ "MIMode": "gdb"
85
+ },
86
+ {
87
+ "name": "Debug PyBind11 Test",
88
+ "type": "pythoncpp",
89
+ "request": "launch",
90
+ "pythonLaunchName": "Python: Current File",
91
+ "cppAttachName": "Debug PyBind11: Attach with GDB"
92
+ },
93
+ {
94
+ "name": "Debug PyBind11: Attach with GDB",
95
+ "type": "cppdbg",
96
+ "request": "attach",
97
+ "program": "/Users/av/miniconda3/bin/python",
98
+ "processId": "",
99
+ "MIMode": "lldb",
100
+ "setupCommands": [
101
+ {
102
+ "description": "Enable pretty-printing for gdb",
103
+ "text": "-enable-pretty-printing",
104
+ "ignoreFailures": true
105
+ }
106
+ ]
107
+ },
108
+ {
109
+ "name": "Python: Current File",
110
+ "type": "python",
111
+ "request": "launch",
112
+ "program": "${file}",
113
+ "console": "integratedTerminal"
114
+ }
115
+ ]
116
+ }
@@ -0,0 +1,109 @@
1
+ {
2
+ "files.associations": {
3
+ "array": "cpp",
4
+ "atomic": "cpp",
5
+ "hash_map": "cpp",
6
+ "hash_set": "cpp",
7
+ "barrier": "cpp",
8
+ "bit": "cpp",
9
+ "*.tcc": "cpp",
10
+ "bitset": "cpp",
11
+ "cctype": "cpp",
12
+ "chrono": "cpp",
13
+ "cinttypes": "cpp",
14
+ "clocale": "cpp",
15
+ "cmath": "cpp",
16
+ "codecvt": "cpp",
17
+ "compare": "cpp",
18
+ "complex": "cpp",
19
+ "concepts": "cpp",
20
+ "condition_variable": "cpp",
21
+ "csignal": "cpp",
22
+ "cstdarg": "cpp",
23
+ "cstddef": "cpp",
24
+ "cstdint": "cpp",
25
+ "cstdio": "cpp",
26
+ "cstdlib": "cpp",
27
+ "cstring": "cpp",
28
+ "ctime": "cpp",
29
+ "cwchar": "cpp",
30
+ "cwctype": "cpp",
31
+ "deque": "cpp",
32
+ "forward_list": "cpp",
33
+ "list": "cpp",
34
+ "map": "cpp",
35
+ "set": "cpp",
36
+ "string": "cpp",
37
+ "unordered_map": "cpp",
38
+ "unordered_set": "cpp",
39
+ "vector": "cpp",
40
+ "exception": "cpp",
41
+ "algorithm": "cpp",
42
+ "functional": "cpp",
43
+ "iterator": "cpp",
44
+ "memory": "cpp",
45
+ "memory_resource": "cpp",
46
+ "numeric": "cpp",
47
+ "optional": "cpp",
48
+ "random": "cpp",
49
+ "ratio": "cpp",
50
+ "regex": "cpp",
51
+ "string_view": "cpp",
52
+ "system_error": "cpp",
53
+ "tuple": "cpp",
54
+ "type_traits": "cpp",
55
+ "utility": "cpp",
56
+ "fstream": "cpp",
57
+ "initializer_list": "cpp",
58
+ "iomanip": "cpp",
59
+ "iosfwd": "cpp",
60
+ "iostream": "cpp",
61
+ "istream": "cpp",
62
+ "limits": "cpp",
63
+ "mutex": "cpp",
64
+ "new": "cpp",
65
+ "numbers": "cpp",
66
+ "ostream": "cpp",
67
+ "semaphore": "cpp",
68
+ "sstream": "cpp",
69
+ "stdexcept": "cpp",
70
+ "stop_token": "cpp",
71
+ "streambuf": "cpp",
72
+ "thread": "cpp",
73
+ "typeindex": "cpp",
74
+ "typeinfo": "cpp",
75
+ "valarray": "cpp",
76
+ "variant": "cpp",
77
+ "__bit_reference": "cpp",
78
+ "__bits": "cpp",
79
+ "__config": "cpp",
80
+ "__debug": "cpp",
81
+ "__errc": "cpp",
82
+ "__hash_table": "cpp",
83
+ "__locale": "cpp",
84
+ "__mutex_base": "cpp",
85
+ "__node_handle": "cpp",
86
+ "__nullptr": "cpp",
87
+ "__split_buffer": "cpp",
88
+ "__string": "cpp",
89
+ "__threading_support": "cpp",
90
+ "__tree": "cpp",
91
+ "__tuple": "cpp",
92
+ "any": "cpp",
93
+ "ios": "cpp",
94
+ "locale": "cpp",
95
+ "queue": "cpp",
96
+ "stack": "cpp",
97
+ "__memory": "cpp",
98
+ "filesystem": "cpp",
99
+ "__availability": "cpp",
100
+ "version": "cpp"
101
+ },
102
+ "cSpell.words": [
103
+ "equidimensional",
104
+ "jaccard",
105
+ "ndim",
106
+ "simsimd",
107
+ "usearch"
108
+ ]
109
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "Linux Build C++ Bench Debug",
6
+ "command": "cmake -DCMAKE_CXX_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=Debug -B ./build_debug && make bench -C ./build_debug",
7
+ "args": [],
8
+ "type": "shell",
9
+ "problemMatcher": [
10
+ "$gcc"
11
+ ]
12
+ },
13
+ {
14
+ "label": "Linux Build C++ Bench Release",
15
+ "command": "cmake -DCMAKE_CXX_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_BUILD_TYPE=RelWithDebInfo -B ./build_release && make bench -C ./build_release",
16
+ "args": [],
17
+ "type": "shell",
18
+ "problemMatcher": [
19
+ "$gcc"
20
+ ]
21
+ },
22
+ {
23
+ "label": "MacOS Build C++ Bench Debug",
24
+ "command": "cmake -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ -DCMAKE_BUILD_TYPE=Debug -B ./build_debug && make bench -C ./build_debug",
25
+ "args": [],
26
+ "type": "shell",
27
+ },
28
+ {
29
+ "label": "MacOS Build C++ Bench Release",
30
+ "command": "cmake -DCMAKE_C_COMPILER=/opt/homebrew/opt/llvm/bin/clang -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm/bin/clang++ -DCMAKE_BUILD_TYPE=RelWithDebInfo -B ./build_release && make bench -C ./build_release",
31
+ "args": [],
32
+ "type": "shell"
33
+ }
34
+ ]
35
+ }
package/CMakeLists.txt ADDED
@@ -0,0 +1,84 @@
1
+ cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
2
+ project(usearch LANGUAGES CXX)
3
+
4
+ set(CMAKE_CXX_STANDARD 11)
5
+ set(CMAKE_CXX_STANDARD_REQUIRED YES)
6
+ set(CMAKE_CXX_EXTENSIONS NO)
7
+
8
+ option(USEARCH_USE_JEMALLOC "Use JeMalloc for Faster Memory Allocations" OFF)
9
+ option(USEARCH_USE_OPENMP "Use OpenMP for a thread pool" OFF)
10
+
11
+ # Make "Release" by default
12
+ if(NOT CMAKE_BUILD_TYPE)
13
+ set(CMAKE_BUILD_TYPE Release)
14
+ endif()
15
+
16
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
17
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
18
+ set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 -pg -g")
19
+
20
+ # List of all possible compiler IDs:
21
+ # https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html
22
+ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
23
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address")
24
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-conversion -Wno-unknown-pragmas")
25
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
26
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmax-errors=1")
27
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
28
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
29
+
30
+ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
31
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wfatal-errors")
32
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
33
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
34
+
35
+ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "NVIDIA" OR CMAKE_CXX_COMPILER_ID STREQUAL "NVHPC")
36
+ set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr --extended-lambda")
37
+ set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -gencode arch=compute_86,code=sm_86")
38
+ set_property(SOURCE src/bench.cpp PROPERTY LANGUAGE CUDA)
39
+ set_target_properties(bench PROPERTIES POSITION_INDEPENDENT_CODE ON)
40
+ set_target_properties(bench PROPERTIES CUDA_ARCHITECTURES "86")
41
+
42
+ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
43
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")
44
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ferror-limit=1")
45
+
46
+ endif()
47
+
48
+ if(APPLE)
49
+ set(CMAKE_THREAD_LIBS_INIT "-lpthread")
50
+ set(CMAKE_HAVE_THREADS_LIBRARY 1)
51
+ set(CMAKE_USE_WIN32_THREADS_INIT 0)
52
+ set(CMAKE_USE_PTHREADS_INIT 1)
53
+ set(THREADS_PREFER_PTHREAD_FLAG ON)
54
+ endif()
55
+ find_package(Threads REQUIRED)
56
+
57
+ if(${USEARCH_USE_OPENMP})
58
+ find_package(OpenMP REQUIRED)
59
+ include_directories(${OPENMP_INCLUDE_DIRS})
60
+ endif()
61
+
62
+ if(${USEARCH_USE_JEMALLOC})
63
+ include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/jemalloc.cmake")
64
+ endif()
65
+ include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/clipp.cmake")
66
+
67
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
68
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/fp16/include")
69
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/simsimd/include")
70
+
71
+ # Define our header-only library.
72
+ add_library(usearch INTERFACE)
73
+ target_sources(usearch INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include/usearch/usearch.hpp")
74
+ target_include_directories(usearch INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
75
+
76
+ # Define the targets
77
+ add_executable(bench src/bench.cpp)
78
+ target_link_libraries(bench PRIVATE Threads::Threads)
79
+ if(${USEARCH_USE_OPENMP})
80
+ target_link_libraries(bench PRIVATE ${OPENMP_LIBRARIES})
81
+ endif()
82
+ if(${USEARCH_USE_JEMALLOC})
83
+ target_link_libraries(bench PRIVATE ${JEMALLOC_LIBRARIES})
84
+ endif()
@@ -0,0 +1,109 @@
1
+ # Compiling USearch
2
+
3
+ ## Build
4
+
5
+ Before building the first time, please pull submodules.
6
+
7
+ ```sh
8
+ git submodule update --init --recursive
9
+ ```
10
+
11
+ ### Linux
12
+
13
+ ```sh
14
+ cmake -B ./build_release \
15
+ -DCMAKE_BUILD_TYPE=Release \
16
+ -DUSEARCH_USE_OPENMP=1 \
17
+ -DUSEARCH_USE_JEMALLOC=1 && \
18
+ make -C ./build_release -j
19
+
20
+ # To benchmark:
21
+ ./build_release/bench \
22
+ --vectors datasets/wiki_1M/base.1M.fbin \
23
+ --queries datasets/wiki_1M/query.public.100K.fbin \
24
+ --neighbors datasets/wiki_1M/groundtruth.public.100K.ibin \
25
+ --ip
26
+ ```
27
+
28
+ ### MacOS
29
+
30
+ ```sh
31
+ brew install libomp llvm
32
+ cmake \
33
+ -DCMAKE_C_COMPILER="/opt/homebrew/opt/llvm/bin/clang" \
34
+ -DCMAKE_CXX_COMPILER="/opt/homebrew/opt/llvm/bin/clang++" \
35
+ -B ./build_release && \
36
+ make -C ./build_release -j
37
+
38
+ # To benchmark:
39
+ ./build_release/bench \
40
+ --vectors datasets/wiki_1M/base.1M.fbin \
41
+ --queries datasets/wiki_1M/query.public.100K.fbin \
42
+ --neighbors datasets/wiki_1M/groundtruth.public.100K.ibin \
43
+ --ip
44
+ ```
45
+
46
+ ### Python
47
+
48
+ ```sh
49
+ pip install -e .
50
+ python src/test.py
51
+
52
+ # To benchmark:
53
+ python src/bench.py \
54
+ --vectors datasets/wiki_1M/base.1M.fbin \
55
+ --queries datasets/wiki_1M/query.public.100K.fbin \
56
+ --neighbors datasets/wiki_1M/groundtruth.public.100K.ibin \
57
+ --ip
58
+ ```
59
+
60
+ ### JavaScript
61
+
62
+ ```sh
63
+ npm install
64
+ node src/test.js
65
+ npm publish
66
+ ```
67
+
68
+ ### JavaScript
69
+
70
+ ```sh
71
+ cargo run
72
+ ```
73
+
74
+ ## Benchmarks
75
+
76
+ ### Datasets
77
+
78
+ ### Evaluation
79
+
80
+ Yandex Text-to-Image embeddings.
81
+
82
+ ```sh
83
+ export path_vectors=datasets/t2i_1M/base.1M.fbin
84
+ export path_queries=datasets/t2i_1M/query.public.100K.fbin
85
+ export path_neighbors=datasets/t2i_1M/groundtruth.public.100K.ibin
86
+ ./build_release/bench
87
+ ```
88
+
89
+ Wikipedia UForm embeddings.
90
+
91
+ ```sh
92
+ export path_vectors=datasets/wiki_1M/base.1M.fbin
93
+ export path_queries=datasets/wiki_1M/query.public.100K.fbin
94
+ export path_neighbors=datasets/wiki_1M/groundtruth.public.100K.ibin
95
+ ./build_release/bench
96
+ ```
97
+
98
+ ### Profiling
99
+
100
+ With `perf`:
101
+
102
+ ```sh
103
+ # Pass environment variables with `-E`, and `-d` for details
104
+ sudo -E perf stat -d ./build_release/bench
105
+ sudo -E perf mem -d ./build_release/bench
106
+ # Sample on-CPU functions for the specified command, at 1 Kilo Hertz:
107
+ sudo -E perf record -F 1000 ./build_release/bench
108
+ perf record -d -e arm_spe// -- ./build_release/bench
109
+ ```