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.
- package/.clang-format +10 -0
- package/.github/workflows/package.json +82 -0
- package/.github/workflows/release.yml +111 -0
- package/.gitmodules +6 -0
- package/.vscode/launch.json +116 -0
- package/.vscode/settings.json +109 -0
- package/.vscode/tasks.json +35 -0
- package/CMakeLists.txt +84 -0
- package/CMakeListsInstructuons.md +109 -0
- package/README.md +69 -0
- package/VERSION +1 -0
- package/assets/unum.png +0 -0
- package/binding.gyp +28 -0
- package/build.rs +14 -0
- package/cargo.toml +15 -0
- package/cmake/clipp.cmake +8 -0
- package/cmake/jemalloc.cmake +80 -0
- package/docs/Makefile +20 -0
- package/docs/_static/custom.css +26 -0
- package/docs/_static/custom.js +7 -0
- package/docs/conf.py +48 -0
- package/docs/index.rst +10 -0
- package/fp16/CMakeLists.txt +176 -0
- package/fp16/LICENSE +11 -0
- package/fp16/README.md +20 -0
- package/fp16/bench/alt-element.cc +89 -0
- package/fp16/bench/from-alt-array.cc +175 -0
- package/fp16/bench/from-ieee-array.cc +399 -0
- package/fp16/bench/ieee-element.cc +272 -0
- package/fp16/bench/to-alt-array.cc +91 -0
- package/fp16/bench/to-ieee-array.cc +303 -0
- package/fp16/cmake/DownloadGoogleBenchmark.cmake +15 -0
- package/fp16/cmake/DownloadGoogleTest.cmake +15 -0
- package/fp16/cmake/DownloadPSimd.cmake +15 -0
- package/fp16/configure.py +65 -0
- package/fp16/confu.yaml +8 -0
- package/fp16/include/fp16/__init__.py +0 -0
- package/fp16/include/fp16/avx.py +50 -0
- package/fp16/include/fp16/avx2.py +53 -0
- package/fp16/include/fp16/bitcasts.h +92 -0
- package/fp16/include/fp16/fp16.h +451 -0
- package/fp16/include/fp16/psimd.h +131 -0
- package/fp16/include/fp16.h +11 -0
- package/fp16/jni/Android.mk +6 -0
- package/fp16/jni/Application.mk +4 -0
- package/fp16/test/alt-from-fp32-value.cc +498 -0
- package/fp16/test/alt-to-fp32-bits.cc +263 -0
- package/fp16/test/alt-to-fp32-psimd.cc +145 -0
- package/fp16/test/alt-to-fp32-value.cc +348 -0
- package/fp16/test/alt-to-fp32x2-psimd.cc +245 -0
- package/fp16/test/bitcasts.cc +56 -0
- package/fp16/test/ieee-from-fp32-value.cc +523 -0
- package/fp16/test/ieee-to-fp32-bits.cc +333 -0
- package/fp16/test/ieee-to-fp32-psimd.cc +312 -0
- package/fp16/test/ieee-to-fp32-value.cc +420 -0
- package/fp16/test/ieee-to-fp32x2-psimd.cc +541 -0
- package/fp16/test/peachpy/alt-xmm-to-fp32-xmm-avx.cc +96 -0
- package/fp16/test/peachpy/alt-xmm-to-fp32-ymm-avx2.cc +96 -0
- package/fp16/test/peachpy/stubs.py +38 -0
- package/fp16/test/tables.cc +530 -0
- package/fp16/test/tables.h +13 -0
- package/fp16/third-party/THHalf.h +92 -0
- package/fp16/third-party/eigen-half.h +170 -0
- package/fp16/third-party/float16-compressor.h +80 -0
- package/fp16/third-party/half.hpp +2916 -0
- package/fp16/third-party/npy-halffloat.h +328 -0
- package/include/usearch/usearch.hpp +1345 -0
- package/package.json +19 -0
- package/pyproject.toml +33 -0
- package/setup.py +63 -0
- package/simsimd/.clang-format +10 -0
- package/simsimd/.vscode/launch.json +24 -0
- package/simsimd/.vscode/settings.json +73 -0
- package/simsimd/.vscode/tasks.json +17 -0
- package/simsimd/CMakeLists.txt +82 -0
- package/simsimd/LICENSE +201 -0
- package/simsimd/README.md +73 -0
- package/simsimd/bench.cxx +82 -0
- package/simsimd/include/simsimd/simsimd.h +322 -0
- package/simsimd/include/simsimd/simsimd.hpp +443 -0
- package/src/advanced.hpp +489 -0
- package/src/bench.cpp +415 -0
- package/src/bench.py +89 -0
- package/src/javascript.cpp +198 -0
- package/src/main.rs +42 -0
- package/src/python.cpp +226 -0
- package/src/rust.cpp +23 -0
- package/src/rust.h +22 -0
- package/src/test.js +17 -0
- package/src/test.py +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
<h1 align="center">USearch</h1>
|
|
2
|
+
<h3 align="center">
|
|
3
|
+
C++11 Single Header Vector Search<br/>
|
|
4
|
+
Compact, yet Powerful<br/>
|
|
5
|
+
</h3>
|
|
6
|
+
<br/>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<a href="https://discord.gg/A6wxt6dS9j"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/discord.svg" alt="Discord"></a>
|
|
10
|
+
|
|
11
|
+
<a href="https://www.linkedin.com/company/unum-cloud/"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/linkedin.svg" alt="LinkedIn"></a>
|
|
12
|
+
|
|
13
|
+
<a href="https://twitter.com/unum_cloud"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/twitter.svg" alt="Twitter"></a>
|
|
14
|
+
|
|
15
|
+
<a href="https://unum.cloud/post"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/blog.svg" alt="Blog"></a>
|
|
16
|
+
|
|
17
|
+
<a href="https://github.com/unum-cloud/usearch"><img height="25" src="https://github.com/unum-cloud/.github/raw/main/assets/github.svg" alt="GitHub"></a>
|
|
18
|
+
</p>
|
|
19
|
+
|
|
20
|
+
- [x] Single C++11 header, easily extendible.
|
|
21
|
+
- [x] 4B+ sized space efficient point-clouds with `uint40_t`.
|
|
22
|
+
- [x] Half-precision support with [`maratyszcza/fp16`](https://github.com/maratyszcza/fp16).
|
|
23
|
+
- [x] View from disk, without loading into RAM.
|
|
24
|
+
- [x] Any metric, includes:
|
|
25
|
+
- [x] Euclidean, Dot-product, Cosine,
|
|
26
|
+
- [x] Jaccard, Hamming, Haversine.
|
|
27
|
+
- [x] Hardware-accelerated [`ashvardanian/simsimd`](https://github.com/ashvardanian/simsimd).
|
|
28
|
+
- [x] Variable dimensionality vectors.
|
|
29
|
+
- [x] Don't copy vectors if not needed.
|
|
30
|
+
- [x] Bring your threads.
|
|
31
|
+
- [x] Multiple vectors per label.
|
|
32
|
+
- [x] CPython bindings for Python 3.
|
|
33
|
+
- [ ] Node.js bindings for JavaScript.
|
|
34
|
+
- [ ] Wolfram language bindings.
|
|
35
|
+
- [x] For Linux: GCC, Clang.
|
|
36
|
+
- [x] For MacOS: Apple Clang.
|
|
37
|
+
- [ ] For Windows.
|
|
38
|
+
- [ ] Distributed construction.
|
|
39
|
+
- [ ] Multi-index lookups.
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
### C++
|
|
44
|
+
|
|
45
|
+
To use in a C++ project simply copy the `include/usearch/usearch.hpp` header into your project.
|
|
46
|
+
|
|
47
|
+
```c++
|
|
48
|
+
using namespace unum::usearch;
|
|
49
|
+
|
|
50
|
+
index_gt<cos_gt<float>> index;
|
|
51
|
+
float vec[3] = {0.1, 0.3, 0.2};
|
|
52
|
+
index.add(/* label: */ 42, /* vector: */ {&vec, 3});
|
|
53
|
+
index.search(
|
|
54
|
+
/* query: */ {&vec, 3}, 10 /* results */,
|
|
55
|
+
/* callback: */ [](std::size_t label, float distance) { });
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Alternatively fetch it with CMake:
|
|
59
|
+
|
|
60
|
+
```cmake
|
|
61
|
+
FetchContent_Declare(usearch GIT_REPOSITORY https://github.com/unum-cloud/usearch.git)
|
|
62
|
+
FetchContent_MakeAvailable(usearch)
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Features
|
|
66
|
+
|
|
67
|
+
### Bring your Threads
|
|
68
|
+
|
|
69
|
+
## Performance
|
package/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.0
|
package/assets/unum.png
ADDED
|
Binary file
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "usearch",
|
|
5
|
+
"sources": [
|
|
6
|
+
"src/javascript.cpp"
|
|
7
|
+
],
|
|
8
|
+
"include_dirs": [
|
|
9
|
+
"<!@(node -p \"require('node-addon-api').include\")",
|
|
10
|
+
"include",
|
|
11
|
+
"fp16/include",
|
|
12
|
+
"simsimd/include"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": [
|
|
15
|
+
"<!(node -p \"require('node-addon-api').gyp\")"
|
|
16
|
+
],
|
|
17
|
+
"cflags!": ["-fno-exceptions", "-Wunknown-pragmas"],
|
|
18
|
+
"cflags_cc!": ["-fno-exceptions", "-Wunknown-pragmas"],
|
|
19
|
+
"conditions": [
|
|
20
|
+
["OS==\"mac\"", {
|
|
21
|
+
"xcode_settings": {
|
|
22
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
|
|
23
|
+
}
|
|
24
|
+
}]
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
package/build.rs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
fn main() {
|
|
2
|
+
cxx_build::bridge("src/main.rs")
|
|
3
|
+
.file("src/rust.cpp")
|
|
4
|
+
.flag_if_supported("-std=c++11")
|
|
5
|
+
.include("include")
|
|
6
|
+
.include("src")
|
|
7
|
+
.include("fp16/include")
|
|
8
|
+
.include("simsimd/include")
|
|
9
|
+
.compile("usearch");
|
|
10
|
+
|
|
11
|
+
println!("cargo:rerun-if-changed=src/main.rs");
|
|
12
|
+
println!("cargo:rerun-if-changed=src/rust.cpp");
|
|
13
|
+
println!("cargo:rerun-if-changed=src/rust.h");
|
|
14
|
+
}
|
package/cargo.toml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "usearch"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
authors = ["Ashot Vardanian <1983160+ashvardanian@users.noreply.github.com>"]
|
|
5
|
+
description = "The Tiny Vector Search Engine from Unum"
|
|
6
|
+
edition = "2021"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
publish = false
|
|
9
|
+
repository = "https://github.com/unum-cloud/usearch"
|
|
10
|
+
|
|
11
|
+
[dependencies]
|
|
12
|
+
cxx = "1.0"
|
|
13
|
+
|
|
14
|
+
[build-dependencies]
|
|
15
|
+
cxx-build = "1.0"
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
|
|
2
|
+
include(ExternalProject)
|
|
3
|
+
set(JEMALLOC_DISABLE_TLS)
|
|
4
|
+
|
|
5
|
+
if(${USTORE_BUILD_SDK_PYTHON})
|
|
6
|
+
set(JEMALLOC_DISABLE_TLS --disable-initial-exec-tls)
|
|
7
|
+
endif()
|
|
8
|
+
|
|
9
|
+
if(${USTORE_REBUILD_JEMALLOC})
|
|
10
|
+
set(JEMALLOC_PREFIX_DIR ${CMAKE_BINARY_DIR}/_deps/jemalloc)
|
|
11
|
+
set(JEMALLOC_SRC_DIR ${JEMALLOC_PREFIX_DIR}/src/jemalloc)
|
|
12
|
+
set(JEMALLOC_INSTALL_DIR ${JEMALLOC_PREFIX_DIR}/install)
|
|
13
|
+
set(JEMALLOC_DEPENDENCY jemalloc)
|
|
14
|
+
|
|
15
|
+
ExternalProject_Add(jemalloc
|
|
16
|
+
GIT_REPOSITORY https://github.com/jemalloc/jemalloc.git
|
|
17
|
+
GIT_TAG 5.3.0
|
|
18
|
+
PREFIX ${JEMALLOC_PREFIX_DIR}
|
|
19
|
+
CONFIGURE_COMMAND echo Configuring jemalloc
|
|
20
|
+
&& cd ${JEMALLOC_SRC_DIR}
|
|
21
|
+
&& ./autogen.sh && ./configure
|
|
22
|
+
--prefix=${JEMALLOC_INSTALL_DIR} --enable-prof ${JEMALLOC_DISABLE_TLS} # --with-jemalloc-prefix=je_
|
|
23
|
+
BUILD_COMMAND echo Building jemalloc && cd ${JEMALLOC_SRC_DIR}
|
|
24
|
+
&& make install_lib_static install_include
|
|
25
|
+
INSTALL_COMMAND ""
|
|
26
|
+
UPDATE_COMMAND ""
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Create libjemalloc and libjemalloc_pic targets to be used as
|
|
30
|
+
# dependencies
|
|
31
|
+
add_library(libjemalloc STATIC IMPORTED GLOBAL)
|
|
32
|
+
add_library(libjemalloc_pic STATIC IMPORTED GLOBAL)
|
|
33
|
+
|
|
34
|
+
set_property(TARGET libjemalloc
|
|
35
|
+
PROPERTY IMPORTED_LOCATION
|
|
36
|
+
${JEMALLOC_INSTALL_DIR}/lib/libjemalloc.a
|
|
37
|
+
)
|
|
38
|
+
set_property(TARGET libjemalloc_pic
|
|
39
|
+
PROPERTY IMPORTED_LOCATION
|
|
40
|
+
${JEMALLOC_INSTALL_DIR}/lib/libjemalloc_pic.a
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
link_libraries(-Wl,--no-as-needed)
|
|
44
|
+
link_libraries(dl ${libjemalloc_pic})
|
|
45
|
+
|
|
46
|
+
# Export the include directory path.
|
|
47
|
+
set(JEMALLOC_SOURCE_DIR ${JEMALLOC_INSTALL_DIR})
|
|
48
|
+
set(JEMALLOC_LIBRARIES ${JEMALLOC_INSTALL_DIR}/lib/libjemalloc_pic.a ${JEMALLOC_INSTALL_DIR}/lib/libjemalloc.a)
|
|
49
|
+
|
|
50
|
+
include_directories(${JEMALLOC_SOURCE_DIR}/include)
|
|
51
|
+
|
|
52
|
+
else()
|
|
53
|
+
find_path(JEMALLOC_ROOT_DIR
|
|
54
|
+
NAMES include/jemalloc/jemalloc.h
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
find_library(JEMALLOC_LIBRARIES
|
|
58
|
+
NAMES jemalloc
|
|
59
|
+
HINTS ${JEMALLOC_ROOT_DIR}/lib
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
find_path(JEMALLOC_INCLUDE_DIR
|
|
63
|
+
NAMES jemalloc/jemalloc.h
|
|
64
|
+
HINTS ${JEMALLOC_ROOT_DIR}/include
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
include(FindPackageHandleStandardArgs)
|
|
68
|
+
find_package_handle_standard_args(JeMalloc DEFAULT_MSG
|
|
69
|
+
JEMALLOC_LIBRARIES
|
|
70
|
+
JEMALLOC_INCLUDE_DIR
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
mark_as_advanced(
|
|
74
|
+
JEMALLOC_ROOT_DIR
|
|
75
|
+
JEMALLOC_LIBRARIES
|
|
76
|
+
JEMALLOC_INCLUDE_DIR
|
|
77
|
+
)
|
|
78
|
+
endif()
|
|
79
|
+
|
|
80
|
+
message("JEMALLOC_LIBRARIES:" ${JEMALLOC_LIBRARIES})
|
package/docs/Makefile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Minimal makefile for Sphinx documentation
|
|
2
|
+
#
|
|
3
|
+
|
|
4
|
+
# You can set these variables from the command line, and also
|
|
5
|
+
# from the environment for the first two.
|
|
6
|
+
SPHINXOPTS ?=
|
|
7
|
+
SPHINXBUILD ?= sphinx-build
|
|
8
|
+
SOURCEDIR = .
|
|
9
|
+
BUILDDIR = ../build/docs
|
|
10
|
+
|
|
11
|
+
# Put it first so that "make" without argument is like "make help".
|
|
12
|
+
help:
|
|
13
|
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
14
|
+
|
|
15
|
+
.PHONY: help Makefile
|
|
16
|
+
|
|
17
|
+
# Catch-all target: route all unknown targets to Sphinx using the new
|
|
18
|
+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
|
19
|
+
%: Makefile
|
|
20
|
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
p.caption {
|
|
2
|
+
font-size: 0 !important;
|
|
3
|
+
margin: 8px 0px !important;
|
|
4
|
+
padding: 0 !important;
|
|
5
|
+
border-bottom: 1px solid #8b7f8b12;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
article>section>h1:nth-child(1) {
|
|
9
|
+
display: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.sidebar-brand-text {
|
|
13
|
+
cursor: initial;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
table>tbody>tr>td {
|
|
17
|
+
text-align: center;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
table>tbody>tr>td:first-child {
|
|
21
|
+
text-align: left;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#overview>p>a>img {
|
|
25
|
+
height: 25px !important;
|
|
26
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
$(document).ready(function () {
|
|
2
|
+
const github_logo = `<a style="text-decoration:none;" class="Header-link" href="https://github.com/unum-cloud/usearch/" data-hotkey="g d" aria-label="Homepage " data-turbo="false" data-analytics-event="{"category":"Header","action":"go to dashboard","label":"icon:logo"}">
|
|
3
|
+
<svg style="fill: var(--color-foreground-primary);" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"></path></svg>
|
|
4
|
+
</a>`
|
|
5
|
+
|
|
6
|
+
$(".sidebar-brand-text").html("Unum · USearch<br/> <span style='font-size:0.8em'>$(VERSION)</span>" + github_logo)
|
|
7
|
+
})
|
package/docs/conf.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Configuration file for the Sphinx documentation builder.
|
|
2
|
+
#
|
|
3
|
+
# For the full list of built-in configuration values, see the documentation:
|
|
4
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
5
|
+
|
|
6
|
+
# -- Project information -----------------------------------------------------
|
|
7
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
|
|
8
|
+
|
|
9
|
+
project = 'Unum · USearch'
|
|
10
|
+
copyright = '2023, Unum'
|
|
11
|
+
author = 'Unum'
|
|
12
|
+
release = open('../VERSION', 'r').read().strip()
|
|
13
|
+
with open('_static/custom.js', 'r+') as js:
|
|
14
|
+
content = js.read()
|
|
15
|
+
js.seek(0)
|
|
16
|
+
js.truncate()
|
|
17
|
+
js.write(content.replace('$(VERSION)', release))
|
|
18
|
+
|
|
19
|
+
# -- General configuration ---------------------------------------------------
|
|
20
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
21
|
+
|
|
22
|
+
extensions = [
|
|
23
|
+
'breathe', 'm2r2',
|
|
24
|
+
'sphinx.ext.autodoc',
|
|
25
|
+
'sphinx.ext.autosummary',
|
|
26
|
+
'sphinx.ext.intersphinx',
|
|
27
|
+
'sphinx.ext.napoleon',
|
|
28
|
+
'sphinxcontrib.jquery',
|
|
29
|
+
'sphinxcontrib.googleanalytics']
|
|
30
|
+
|
|
31
|
+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '*.md']
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
googleanalytics_id = '341385789'
|
|
35
|
+
googleanalytics_enabled = True
|
|
36
|
+
|
|
37
|
+
# -- Options for HTML output -------------------------------------------------
|
|
38
|
+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
|
|
39
|
+
|
|
40
|
+
html_logo = '../assets/unum.png'
|
|
41
|
+
html_theme = 'furo'
|
|
42
|
+
html_static_path = ['_static']
|
|
43
|
+
html_css_files = ['custom.css']
|
|
44
|
+
html_js_files = ['custom.js']
|
|
45
|
+
html_baseurl = '/docs/usearch/'
|
|
46
|
+
|
|
47
|
+
breathe_projects = {'USearch': '../build/xml'}
|
|
48
|
+
breathe_default_project = 'USearch'
|
package/docs/index.rst
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
|
|
2
|
+
|
|
3
|
+
INCLUDE(GNUInstallDirs)
|
|
4
|
+
|
|
5
|
+
# ---[ Project
|
|
6
|
+
PROJECT(FP16 C CXX)
|
|
7
|
+
|
|
8
|
+
# ---[ Options.
|
|
9
|
+
OPTION(FP16_BUILD_TESTS "Build FP16 unit tests" ON)
|
|
10
|
+
OPTION(FP16_BUILD_BENCHMARKS "Build FP16 micro-benchmarks" ON)
|
|
11
|
+
|
|
12
|
+
# ---[ CMake options
|
|
13
|
+
IF(FP16_BUILD_TESTS)
|
|
14
|
+
ENABLE_TESTING()
|
|
15
|
+
ENDIF()
|
|
16
|
+
|
|
17
|
+
MACRO(FP16_TARGET_ENABLE_CXX11 target)
|
|
18
|
+
IF(${CMAKE_VERSION} VERSION_LESS "3.1")
|
|
19
|
+
IF(NOT MSVC)
|
|
20
|
+
TARGET_COMPILE_OPTIONS(${target} PRIVATE -std=c++11)
|
|
21
|
+
ENDIF()
|
|
22
|
+
ELSE()
|
|
23
|
+
SET_TARGET_PROPERTIES(${target} PROPERTIES
|
|
24
|
+
CXX_STANDARD 11
|
|
25
|
+
CXX_STANDARD_REQUIRED YES
|
|
26
|
+
CXX_EXTENSIONS YES)
|
|
27
|
+
ENDIF()
|
|
28
|
+
ENDMACRO()
|
|
29
|
+
|
|
30
|
+
# ---[ Download deps
|
|
31
|
+
IF(NOT DEFINED PSIMD_SOURCE_DIR)
|
|
32
|
+
MESSAGE(STATUS "Downloading PSimd to ${CMAKE_BINARY_DIR}/psimd-source (define PSIMD_SOURCE_DIR to avoid it)")
|
|
33
|
+
CONFIGURE_FILE(cmake/DownloadPSimd.cmake "${CMAKE_BINARY_DIR}/psimd-download/CMakeLists.txt")
|
|
34
|
+
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
|
|
35
|
+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/psimd-download")
|
|
36
|
+
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
|
|
37
|
+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/psimd-download")
|
|
38
|
+
SET(PSIMD_SOURCE_DIR "${CMAKE_BINARY_DIR}/psimd-source" CACHE STRING "PSimd source directory")
|
|
39
|
+
ENDIF()
|
|
40
|
+
|
|
41
|
+
IF(FP16_BUILD_TESTS AND NOT DEFINED GOOGLETEST_SOURCE_DIR)
|
|
42
|
+
MESSAGE(STATUS "Downloading Google Test to ${CMAKE_BINARY_DIR}/googletest-source (define GOOGLETEST_SOURCE_DIR to avoid it)")
|
|
43
|
+
CONFIGURE_FILE(cmake/DownloadGoogleTest.cmake "${CMAKE_BINARY_DIR}/googletest-download/CMakeLists.txt")
|
|
44
|
+
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
|
|
45
|
+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download")
|
|
46
|
+
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
|
|
47
|
+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googletest-download")
|
|
48
|
+
SET(GOOGLETEST_SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-source" CACHE STRING "Google Test source directory")
|
|
49
|
+
ENDIF()
|
|
50
|
+
|
|
51
|
+
IF(FP16_BUILD_BENCHMARKS AND NOT DEFINED GOOGLEBENCHMARK_SOURCE_DIR)
|
|
52
|
+
MESSAGE(STATUS "Downloading Google Benchmark to ${CMAKE_BINARY_DIR}/googlebenchmark-source (define GOOGLEBENCHMARK_SOURCE_DIR to avoid it)")
|
|
53
|
+
CONFIGURE_FILE(cmake/DownloadGoogleBenchmark.cmake "${CMAKE_BINARY_DIR}/googlebenchmark-download/CMakeLists.txt")
|
|
54
|
+
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
|
|
55
|
+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googlebenchmark-download")
|
|
56
|
+
EXECUTE_PROCESS(COMMAND "${CMAKE_COMMAND}" --build .
|
|
57
|
+
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/googlebenchmark-download")
|
|
58
|
+
SET(GOOGLEBENCHMARK_SOURCE_DIR "${CMAKE_BINARY_DIR}/googlebenchmark-source" CACHE STRING "Google Benchmark source directory")
|
|
59
|
+
ENDIF()
|
|
60
|
+
|
|
61
|
+
# ---[ FP16 library
|
|
62
|
+
IF(${CMAKE_VERSION} VERSION_LESS "3.0")
|
|
63
|
+
ADD_LIBRARY(fp16 STATIC
|
|
64
|
+
include/fp16.h
|
|
65
|
+
include/fp16/fp16.h
|
|
66
|
+
include/fp16/bitcasts.h
|
|
67
|
+
include/fp16/psimd.h)
|
|
68
|
+
SET_TARGET_PROPERTIES(fp16 PROPERTIES LINKER_LANGUAGE C)
|
|
69
|
+
ELSE()
|
|
70
|
+
ADD_LIBRARY(fp16 INTERFACE)
|
|
71
|
+
ENDIF()
|
|
72
|
+
TARGET_INCLUDE_DIRECTORIES(fp16 INTERFACE
|
|
73
|
+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
74
|
+
$<INSTALL_INTERFACE:include>)
|
|
75
|
+
|
|
76
|
+
INSTALL(FILES include/fp16.h
|
|
77
|
+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
|
78
|
+
INSTALL(FILES
|
|
79
|
+
include/fp16/bitcasts.h
|
|
80
|
+
include/fp16/fp16.h
|
|
81
|
+
include/fp16/psimd.h
|
|
82
|
+
include/fp16/__init__.py
|
|
83
|
+
include/fp16/avx.py
|
|
84
|
+
include/fp16/avx2.py
|
|
85
|
+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fp16)
|
|
86
|
+
|
|
87
|
+
# ---[ Configure psimd
|
|
88
|
+
IF(NOT TARGET psimd)
|
|
89
|
+
ADD_SUBDIRECTORY(
|
|
90
|
+
"${PSIMD_SOURCE_DIR}"
|
|
91
|
+
"${CMAKE_BINARY_DIR}/psimd")
|
|
92
|
+
ENDIF()
|
|
93
|
+
|
|
94
|
+
IF(FP16_BUILD_TESTS)
|
|
95
|
+
# ---[ Build google test
|
|
96
|
+
IF(NOT TARGET gtest)
|
|
97
|
+
SET(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
98
|
+
ADD_SUBDIRECTORY(
|
|
99
|
+
"${GOOGLETEST_SOURCE_DIR}"
|
|
100
|
+
"${CMAKE_BINARY_DIR}/googletest")
|
|
101
|
+
ENDIF()
|
|
102
|
+
|
|
103
|
+
# ---[ Build FP16 unit tests
|
|
104
|
+
ADD_EXECUTABLE(ieee-to-fp32-bits-test test/ieee-to-fp32-bits.cc test/tables.cc)
|
|
105
|
+
TARGET_INCLUDE_DIRECTORIES(ieee-to-fp32-bits-test PRIVATE test)
|
|
106
|
+
TARGET_LINK_LIBRARIES(ieee-to-fp32-bits-test fp16 gtest gtest_main)
|
|
107
|
+
ADD_TEST(ieee-to-fp32-bits ieee-to-fp32-bits-test)
|
|
108
|
+
|
|
109
|
+
ADD_EXECUTABLE(ieee-to-fp32-value-test test/ieee-to-fp32-value.cc test/tables.cc)
|
|
110
|
+
TARGET_INCLUDE_DIRECTORIES(ieee-to-fp32-value-test PRIVATE test)
|
|
111
|
+
TARGET_LINK_LIBRARIES(ieee-to-fp32-value-test fp16 gtest gtest_main)
|
|
112
|
+
ADD_TEST(ieee-to-fp32-value ieee-to-fp32-value-test)
|
|
113
|
+
|
|
114
|
+
ADD_EXECUTABLE(ieee-from-fp32-value-test test/ieee-from-fp32-value.cc test/tables.cc)
|
|
115
|
+
TARGET_INCLUDE_DIRECTORIES(ieee-from-fp32-value-test PRIVATE test)
|
|
116
|
+
TARGET_LINK_LIBRARIES(ieee-from-fp32-value-test fp16 gtest gtest_main)
|
|
117
|
+
ADD_TEST(ieee-from-fp32-value ieee-from-fp32-value-test)
|
|
118
|
+
|
|
119
|
+
ADD_EXECUTABLE(alt-to-fp32-bits-test test/alt-to-fp32-bits.cc test/tables.cc)
|
|
120
|
+
TARGET_INCLUDE_DIRECTORIES(alt-to-fp32-bits-test PRIVATE test)
|
|
121
|
+
TARGET_LINK_LIBRARIES(alt-to-fp32-bits-test fp16 gtest gtest_main)
|
|
122
|
+
ADD_TEST(alt-to-fp32-bits alt-to-fp32-bits-test)
|
|
123
|
+
|
|
124
|
+
ADD_EXECUTABLE(alt-to-fp32-value-test test/alt-to-fp32-value.cc test/tables.cc)
|
|
125
|
+
TARGET_INCLUDE_DIRECTORIES(alt-to-fp32-value-test PRIVATE test)
|
|
126
|
+
TARGET_LINK_LIBRARIES(alt-to-fp32-value-test fp16 gtest gtest_main)
|
|
127
|
+
ADD_TEST(alt-to-fp32-value alt-to-fp32-value-test)
|
|
128
|
+
|
|
129
|
+
ADD_EXECUTABLE(alt-from-fp32-value-test test/alt-from-fp32-value.cc test/tables.cc)
|
|
130
|
+
TARGET_INCLUDE_DIRECTORIES(alt-from-fp32-value-test PRIVATE test)
|
|
131
|
+
TARGET_LINK_LIBRARIES(alt-from-fp32-value-test fp16 gtest gtest_main)
|
|
132
|
+
ADD_TEST(alt-from-fp32-value alt-from-fp32-value-test)
|
|
133
|
+
|
|
134
|
+
ADD_EXECUTABLE(bitcasts-test test/bitcasts.cc)
|
|
135
|
+
TARGET_LINK_LIBRARIES(bitcasts-test fp16 gtest gtest_main)
|
|
136
|
+
ADD_TEST(bitcasts bitcasts-test)
|
|
137
|
+
ENDIF()
|
|
138
|
+
|
|
139
|
+
IF(FP16_BUILD_BENCHMARKS)
|
|
140
|
+
# ---[ Build google benchmark
|
|
141
|
+
IF(NOT TARGET benchmark)
|
|
142
|
+
SET(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "")
|
|
143
|
+
ADD_SUBDIRECTORY(
|
|
144
|
+
"${GOOGLEBENCHMARK_SOURCE_DIR}"
|
|
145
|
+
"${CMAKE_BINARY_DIR}/googlebenchmark")
|
|
146
|
+
ENDIF()
|
|
147
|
+
|
|
148
|
+
# ---[ Build FP16 benchmarks
|
|
149
|
+
ADD_EXECUTABLE(ieee-element-bench bench/ieee-element.cc)
|
|
150
|
+
TARGET_COMPILE_DEFINITIONS(ieee-element-bench PRIVATE FP16_COMPARATIVE_BENCHMARKS=1)
|
|
151
|
+
TARGET_INCLUDE_DIRECTORIES(ieee-element-bench PRIVATE ${PROJECT_SOURCE_DIR})
|
|
152
|
+
TARGET_LINK_LIBRARIES(ieee-element-bench fp16 psimd benchmark)
|
|
153
|
+
|
|
154
|
+
ADD_EXECUTABLE(alt-element-bench bench/alt-element.cc)
|
|
155
|
+
TARGET_LINK_LIBRARIES(alt-element-bench fp16 psimd benchmark)
|
|
156
|
+
|
|
157
|
+
ADD_EXECUTABLE(from-ieee-array-bench bench/from-ieee-array.cc)
|
|
158
|
+
FP16_TARGET_ENABLE_CXX11(from-ieee-array-bench)
|
|
159
|
+
TARGET_COMPILE_DEFINITIONS(from-ieee-array-bench PRIVATE FP16_COMPARATIVE_BENCHMARKS=1)
|
|
160
|
+
TARGET_INCLUDE_DIRECTORIES(from-ieee-array-bench PRIVATE ${PROJECT_SOURCE_DIR})
|
|
161
|
+
TARGET_LINK_LIBRARIES(from-ieee-array-bench fp16 psimd benchmark)
|
|
162
|
+
|
|
163
|
+
ADD_EXECUTABLE(from-alt-array-bench bench/from-alt-array.cc)
|
|
164
|
+
FP16_TARGET_ENABLE_CXX11(from-alt-array-bench)
|
|
165
|
+
TARGET_LINK_LIBRARIES(from-alt-array-bench fp16 psimd benchmark)
|
|
166
|
+
|
|
167
|
+
ADD_EXECUTABLE(to-ieee-array-bench bench/to-ieee-array.cc)
|
|
168
|
+
FP16_TARGET_ENABLE_CXX11(to-ieee-array-bench)
|
|
169
|
+
TARGET_COMPILE_DEFINITIONS(to-ieee-array-bench PRIVATE FP16_COMPARATIVE_BENCHMARKS=1)
|
|
170
|
+
TARGET_INCLUDE_DIRECTORIES(to-ieee-array-bench PRIVATE ${PROJECT_SOURCE_DIR})
|
|
171
|
+
TARGET_LINK_LIBRARIES(to-ieee-array-bench fp16 psimd benchmark)
|
|
172
|
+
|
|
173
|
+
ADD_EXECUTABLE(to-alt-array-bench bench/to-alt-array.cc)
|
|
174
|
+
FP16_TARGET_ENABLE_CXX11(to-alt-array-bench)
|
|
175
|
+
TARGET_LINK_LIBRARIES(to-alt-array-bench fp16 psimd benchmark)
|
|
176
|
+
ENDIF()
|
package/fp16/LICENSE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Facebook Inc.
|
|
4
|
+
Copyright (c) 2017 Georgia Institute of Technology
|
|
5
|
+
Copyright 2019 Google LLC
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
8
|
+
|
|
9
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/fp16/README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# FP16
|
|
2
|
+
Header-only library for conversion to/from half-precision floating point formats
|
|
3
|
+
|
|
4
|
+
## Features
|
|
5
|
+
|
|
6
|
+
- Supports IEEE and ARM alternative half-precision floating-point format
|
|
7
|
+
- Property converts infinities and NaNs
|
|
8
|
+
- Properly converts denormal numbers, even on systems without denormal support
|
|
9
|
+
- Header-only library, no installation or build required
|
|
10
|
+
- Compatible with C99 and C++11
|
|
11
|
+
- Fully covered with unit tests and microbenchmarks
|
|
12
|
+
|
|
13
|
+
## Acknowledgements
|
|
14
|
+
|
|
15
|
+
[](http://hpcgarage.org)
|
|
16
|
+
[](http://www.cse.gatech.edu/)
|
|
17
|
+
|
|
18
|
+
The library is developed by [Marat Dukhan](http://www.maratdukhan.com) of Georgia Tech. FP16 is a research project at [Richard Vuduc](http://vuduc.org)'s HPC Garage lab in the Georgia Institute of Technology, College of Computing, School of Computational Science and Engineering.
|
|
19
|
+
|
|
20
|
+
This material is based upon work supported by the U.S. National Science Foundation (NSF) Award Number 1339745. Any opinions, findings and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect those of NSF.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#include <benchmark/benchmark.h>
|
|
2
|
+
|
|
3
|
+
#include <fp16.h>
|
|
4
|
+
#ifndef EMSCRIPTEN
|
|
5
|
+
#include <fp16/psimd.h>
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
static inline uint16_t next_xorshift16(uint16_t x) {
|
|
9
|
+
x ^= x >> 8;
|
|
10
|
+
x ^= x << 9;
|
|
11
|
+
x ^= x >> 5;
|
|
12
|
+
return x;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static inline uint32_t next_xorshift32(uint32_t x) {
|
|
16
|
+
x ^= x >> 13;
|
|
17
|
+
x ^= x << 17;
|
|
18
|
+
x ^= x >> 5;
|
|
19
|
+
return x;
|
|
20
|
+
}
|
|
21
|
+
#ifndef EMSCRIPTEN
|
|
22
|
+
PSIMD_INTRINSIC psimd_u16 next_xorshift16_psimd(psimd_u16 x) {
|
|
23
|
+
x ^= x >> psimd_splat_u16(8);
|
|
24
|
+
x ^= x << psimd_splat_u16(9);
|
|
25
|
+
x ^= x >> psimd_splat_u16(5);
|
|
26
|
+
return x;
|
|
27
|
+
}
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
static void fp16_alt_to_fp32_bits(benchmark::State& state) {
|
|
32
|
+
uint16_t fp16 = UINT16_C(0x7C00);
|
|
33
|
+
while (state.KeepRunning()) {
|
|
34
|
+
const uint32_t fp32 = fp16_alt_to_fp32_bits(fp16);
|
|
35
|
+
|
|
36
|
+
fp16 = next_xorshift16(fp16);
|
|
37
|
+
benchmark::DoNotOptimize(fp32);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
BENCHMARK(fp16_alt_to_fp32_bits);
|
|
41
|
+
|
|
42
|
+
static void fp16_alt_to_fp32_value(benchmark::State& state) {
|
|
43
|
+
uint16_t fp16 = UINT16_C(0x7C00);
|
|
44
|
+
while (state.KeepRunning()) {
|
|
45
|
+
const float fp32 = fp16_alt_to_fp32_value(fp16);
|
|
46
|
+
|
|
47
|
+
fp16 = next_xorshift16(fp16);
|
|
48
|
+
benchmark::DoNotOptimize(fp32);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
BENCHMARK(fp16_alt_to_fp32_value);
|
|
52
|
+
|
|
53
|
+
#ifndef EMSCRIPTEN
|
|
54
|
+
static void fp16_alt_to_fp32_psimd(benchmark::State& state) {
|
|
55
|
+
psimd_u16 fp16 = (psimd_u16) { 0x7C00, 0x7C01, 0x7C02, 0x7C03 };
|
|
56
|
+
while (state.KeepRunning()) {
|
|
57
|
+
const psimd_f32 fp32 = fp16_alt_to_fp32_psimd(fp16);
|
|
58
|
+
|
|
59
|
+
fp16 = next_xorshift16_psimd(fp16);
|
|
60
|
+
benchmark::DoNotOptimize(fp32);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
BENCHMARK(fp16_alt_to_fp32_psimd);
|
|
64
|
+
|
|
65
|
+
static void fp16_alt_to_fp32x2_psimd(benchmark::State& state) {
|
|
66
|
+
psimd_u16 fp16 =
|
|
67
|
+
(psimd_u16) { 0x7C00, 0x7C01, 0x7C02, 0x7C03, 0x7C04, 0x7C05, 0x7C06, 0x7C07 };
|
|
68
|
+
while (state.KeepRunning()) {
|
|
69
|
+
const psimd_f32x2 fp32 = fp16_alt_to_fp32x2_psimd(fp16);
|
|
70
|
+
|
|
71
|
+
fp16 = next_xorshift16_psimd(fp16);
|
|
72
|
+
benchmark::DoNotOptimize(fp32);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
BENCHMARK(fp16_alt_to_fp32x2_psimd);
|
|
76
|
+
#endif
|
|
77
|
+
|
|
78
|
+
static void fp16_alt_from_fp32_value(benchmark::State& state) {
|
|
79
|
+
uint32_t fp32 = UINT32_C(0x7F800000);
|
|
80
|
+
while (state.KeepRunning()) {
|
|
81
|
+
const uint16_t fp16 = fp16_alt_from_fp32_value(fp32_from_bits(fp32));
|
|
82
|
+
|
|
83
|
+
fp32 = next_xorshift32(fp32);
|
|
84
|
+
benchmark::DoNotOptimize(fp16);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
BENCHMARK(fp16_alt_from_fp32_value);
|
|
88
|
+
|
|
89
|
+
BENCHMARK_MAIN();
|