usearch 2.10.3 → 2.11.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/README.md +28 -8
- package/binding.gyp +101 -0
- package/c/CMakeLists.txt +27 -0
- package/c/README.md +244 -0
- package/c/lib.cpp +459 -0
- package/c/test.c +386 -0
- package/c/usearch.h +451 -0
- package/cmake/clipp.cmake +7 -0
- package/cmake/config.cmake.in +15 -0
- package/cmake/emscripten.cmake +8 -0
- package/cmake/jemalloc.cmake +62 -0
- package/cmake/pkg-config.pc.in +4 -0
- package/cmake/usearchConfigVersion.cmake.in +20 -0
- package/cpp/CMakeLists.txt +14 -0
- package/cpp/README.md +161 -0
- package/cpp/bench.cpp +616 -0
- package/cpp/test.cpp +335 -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/index.hpp +3838 -0
- package/include/usearch/index_dense.hpp +2022 -0
- package/include/usearch/index_plugins.hpp +2317 -0
- package/javascript/dist/cjs/usearch.js +5 -5
- package/javascript/dist/esm/usearch.js +2 -2
- package/javascript/dist-package-cjs.json +3 -0
- package/javascript/dist-package-esm.json +3 -0
- package/javascript/lib.cpp +350 -0
- package/javascript/node-gyp-build.d.ts +1 -0
- package/javascript/tsconfig-base.json +25 -0
- package/javascript/tsconfig-cjs.json +8 -0
- package/javascript/tsconfig-esm.json +8 -0
- package/javascript/usearch.test.js +84 -0
- package/javascript/usearch.ts +640 -0
- package/package.json +14 -7
- package/prebuilds/darwin-arm64+x64/usearch.node +0 -0
- package/prebuilds/linux-arm64/usearch.node +0 -0
- package/prebuilds/linux-x64/usearch.node +0 -0
- package/prebuilds/win32-ia32/usearch.node +0 -0
- package/prebuilds/win32-x64/usearch.node +0 -0
- package/simsimd/.releaserc +87 -0
- package/simsimd/CONTRIBUTING.md +114 -0
- package/simsimd/Cargo.lock +709 -0
- package/simsimd/Cargo.toml +44 -0
- package/simsimd/LICENSE +201 -0
- package/simsimd/README.md +708 -0
- package/simsimd/binding.gyp +36 -0
- package/simsimd/build.rs +51 -0
- package/simsimd/c/lib.c +110 -0
- package/simsimd/include/simsimd/binary.h +258 -0
- package/simsimd/include/simsimd/dot.h +1237 -0
- package/simsimd/include/simsimd/geospatial.h +37 -0
- package/simsimd/include/simsimd/probability.h +563 -0
- package/simsimd/include/simsimd/simsimd.h +1129 -0
- package/simsimd/include/simsimd/spatial.h +1019 -0
- package/simsimd/include/simsimd/types.h +309 -0
- package/simsimd/javascript/bench.js +127 -0
- package/simsimd/javascript/dist-package-cjs.json +3 -0
- package/simsimd/javascript/dist-package-esm.json +3 -0
- package/simsimd/javascript/fallback.ts +203 -0
- package/simsimd/javascript/lib.c +107 -0
- package/simsimd/javascript/node-gyp-build.d.ts +1 -0
- package/simsimd/javascript/simsimd.ts +135 -0
- package/simsimd/javascript/test.mjs +179 -0
- package/simsimd/javascript/tsconfig-base.json +37 -0
- package/simsimd/javascript/tsconfig-cjs.json +8 -0
- package/simsimd/javascript/tsconfig-esm.json +8 -0
- package/simsimd/package-lock.json +1709 -0
- package/simsimd/package.json +61 -0
- package/simsimd/rust/benches/cosine.rs +27 -0
- package/simsimd/rust/benches/native.rs +30 -0
- package/simsimd/rust/benches/sqeuclidean.rs +27 -0
- package/simsimd/rust/lib.rs +778 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12 FATAL_ERROR)
|
|
2
|
+
|
|
3
|
+
PROJECT(psimd-download NONE)
|
|
4
|
+
|
|
5
|
+
INCLUDE(ExternalProject)
|
|
6
|
+
ExternalProject_Add(psimd
|
|
7
|
+
GIT_REPOSITORY https://github.com/Maratyszcza/psimd.git
|
|
8
|
+
GIT_TAG master
|
|
9
|
+
SOURCE_DIR "${CMAKE_BINARY_DIR}/psimd-source"
|
|
10
|
+
BINARY_DIR "${CMAKE_BINARY_DIR}/psimd"
|
|
11
|
+
CONFIGURE_COMMAND ""
|
|
12
|
+
BUILD_COMMAND ""
|
|
13
|
+
INSTALL_COMMAND ""
|
|
14
|
+
TEST_COMMAND ""
|
|
15
|
+
)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import confu
|
|
5
|
+
parser = confu.standard_parser("FP16 configuration script")
|
|
6
|
+
parser.add_argument("--compare", dest="compare", action="store_true",
|
|
7
|
+
help="Enable performance comparison with other half-precision implementations")
|
|
8
|
+
|
|
9
|
+
def main(args):
|
|
10
|
+
options = parser.parse_args(args)
|
|
11
|
+
build = confu.Build.from_options(options)
|
|
12
|
+
|
|
13
|
+
build.export_cpath("include", ["fp16.h"])
|
|
14
|
+
|
|
15
|
+
with build.options(source_dir="test", extra_include_dirs="test", deps=[build.deps.googletest, build.deps.psimd]):
|
|
16
|
+
fp16_tables = build.cxx("tables.cc")
|
|
17
|
+
build.unittest("ieee-to-fp32-bits",
|
|
18
|
+
[build.cxx("ieee-to-fp32-bits.cc"), fp16_tables])
|
|
19
|
+
build.unittest("ieee-to-fp32-value",
|
|
20
|
+
[build.cxx("ieee-to-fp32-value.cc"), fp16_tables])
|
|
21
|
+
build.unittest("ieee-from-fp32-value",
|
|
22
|
+
[build.cxx("ieee-from-fp32-value.cc"), fp16_tables])
|
|
23
|
+
|
|
24
|
+
build.unittest("alt-to-fp32-bits",
|
|
25
|
+
[build.cxx("alt-to-fp32-bits.cc"), fp16_tables])
|
|
26
|
+
build.unittest("alt-to-fp32-value",
|
|
27
|
+
[build.cxx("alt-to-fp32-value.cc"), fp16_tables])
|
|
28
|
+
build.unittest("alt-from-fp32-value",
|
|
29
|
+
[build.cxx("alt-from-fp32-value.cc"), fp16_tables])
|
|
30
|
+
|
|
31
|
+
if build.target.is_x86_64:
|
|
32
|
+
stubs = build.peachpy("peachpy/stubs.py")
|
|
33
|
+
build.unittest("alt-xmm-to-fp32-ymm-avx", [build.cxx("peachpy/alt-xmm-to-fp32-xmm-avx.cc"), stubs])
|
|
34
|
+
build.unittest("alt-xmm-to-fp32-ymm-avx2", [build.cxx("peachpy/alt-xmm-to-fp32-ymm-avx2.cc"), stubs])
|
|
35
|
+
|
|
36
|
+
if not build.target.is_emscripten:
|
|
37
|
+
build.unittest("ieee-to-fp32-psimd", build.cxx("ieee-to-fp32-psimd.cc"))
|
|
38
|
+
build.unittest("alt-to-fp32-psimd", build.cxx("alt-to-fp32-psimd.cc"))
|
|
39
|
+
|
|
40
|
+
build.unittest("ieee-to-fp32x2-psimd", build.cxx("ieee-to-fp32x2-psimd.cc"))
|
|
41
|
+
build.unittest("alt-to-fp32x2-psimd", build.cxx("alt-to-fp32x2-psimd.cc"))
|
|
42
|
+
|
|
43
|
+
build.unittest("bitcasts", build.cxx("bitcasts.cc"))
|
|
44
|
+
|
|
45
|
+
macros = ["BENCHMARK_HAS_NO_INLINE_ASSEMBLY"]
|
|
46
|
+
if options.compare:
|
|
47
|
+
macros.append("FP16_COMPARATIVE_BENCHMARKS")
|
|
48
|
+
with build.options(source_dir="bench", extra_include_dirs=".", macros=macros,
|
|
49
|
+
deps=[build.deps.googlebenchmark, build.deps.psimd]):
|
|
50
|
+
|
|
51
|
+
build.benchmark("ieee-element-bench", build.cxx("ieee-element.cc"))
|
|
52
|
+
build.benchmark("alt-element-bench", build.cxx("alt-element.cc"))
|
|
53
|
+
|
|
54
|
+
build.benchmark("from-ieee-array-bench", build.cxx("from-ieee-array.cc"))
|
|
55
|
+
build.benchmark("from-alt-array-bench", build.cxx("from-alt-array.cc"))
|
|
56
|
+
|
|
57
|
+
build.benchmark("to-ieee-array-bench", build.cxx("to-ieee-array.cc"))
|
|
58
|
+
build.benchmark("to-alt-array-bench", build.cxx("to-alt-array.cc"))
|
|
59
|
+
|
|
60
|
+
return build
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
import sys
|
|
65
|
+
main(sys.argv[1:]).generate()
|
package/fp16/confu.yaml
ADDED
|
File without changes
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from peachpy import *
|
|
2
|
+
from peachpy.x86_64 import *
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def fp16_alt_xmm_to_fp32_xmm(xmm_half):
|
|
6
|
+
xmm_zero = XMMRegister()
|
|
7
|
+
VPXOR(xmm_zero, xmm_zero, xmm_zero)
|
|
8
|
+
|
|
9
|
+
xmm_word = XMMRegister()
|
|
10
|
+
VPUNPCKLWD(xmm_word, xmm_zero, xmm_half)
|
|
11
|
+
|
|
12
|
+
xmm_shl1_half = XMMRegister()
|
|
13
|
+
VPADDW(xmm_shl1_half, xmm_half, xmm_half)
|
|
14
|
+
|
|
15
|
+
xmm_shl1_nonsign = XMMRegister()
|
|
16
|
+
VPADDD(xmm_shl1_nonsign, xmm_word, xmm_word)
|
|
17
|
+
|
|
18
|
+
sign_mask = Constant.float32x4(-0.0)
|
|
19
|
+
|
|
20
|
+
xmm_sign = XMMRegister()
|
|
21
|
+
VANDPS(xmm_sign, xmm_word, sign_mask)
|
|
22
|
+
|
|
23
|
+
xmm_shr3_nonsign = XMMRegister()
|
|
24
|
+
VPSRLD(xmm_shr3_nonsign, xmm_shl1_nonsign, 4)
|
|
25
|
+
|
|
26
|
+
exp_offset = Constant.uint32x4(0x38000000)
|
|
27
|
+
|
|
28
|
+
xmm_norm_nonsign = XMMRegister()
|
|
29
|
+
VPADDD(xmm_norm_nonsign, xmm_shr3_nonsign, exp_offset)
|
|
30
|
+
|
|
31
|
+
magic_mask = Constant.uint16x8(0x3E80)
|
|
32
|
+
xmm_denorm_nonsign = XMMRegister()
|
|
33
|
+
VPUNPCKLWD(xmm_denorm_nonsign, xmm_shl1_half, magic_mask)
|
|
34
|
+
|
|
35
|
+
magic_bias = Constant.float32x4(0.25)
|
|
36
|
+
VSUBPS(xmm_denorm_nonsign, xmm_denorm_nonsign, magic_bias)
|
|
37
|
+
|
|
38
|
+
xmm_denorm_cutoff = XMMRegister()
|
|
39
|
+
VMOVDQA(xmm_denorm_cutoff, Constant.uint32x4(0x00800000))
|
|
40
|
+
|
|
41
|
+
xmm_denorm_mask = XMMRegister()
|
|
42
|
+
VPCMPGTD(xmm_denorm_mask, xmm_denorm_cutoff, xmm_shr3_nonsign)
|
|
43
|
+
|
|
44
|
+
xmm_nonsign = XMMRegister()
|
|
45
|
+
VBLENDVPS(xmm_nonsign, xmm_norm_nonsign, xmm_denorm_nonsign, xmm_denorm_mask)
|
|
46
|
+
|
|
47
|
+
xmm_float = XMMRegister()
|
|
48
|
+
VORPS(xmm_float, xmm_nonsign, xmm_sign)
|
|
49
|
+
|
|
50
|
+
return xmm_float
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from peachpy import *
|
|
2
|
+
from peachpy.x86_64 import *
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def fp16_alt_xmm_to_fp32_ymm(xmm_half):
|
|
6
|
+
ymm_half = YMMRegister()
|
|
7
|
+
VPERMQ(ymm_half, xmm_half.as_ymm, 0b01010000)
|
|
8
|
+
|
|
9
|
+
ymm_zero = YMMRegister()
|
|
10
|
+
VPXOR(ymm_zero.as_xmm, ymm_zero.as_xmm, ymm_zero.as_xmm)
|
|
11
|
+
|
|
12
|
+
ymm_word = YMMRegister()
|
|
13
|
+
VPUNPCKLWD(ymm_word, ymm_zero, ymm_half)
|
|
14
|
+
|
|
15
|
+
ymm_shl1_half = YMMRegister()
|
|
16
|
+
VPADDW(ymm_shl1_half, ymm_half, ymm_half)
|
|
17
|
+
|
|
18
|
+
ymm_shl1_nonsign = YMMRegister()
|
|
19
|
+
VPADDD(ymm_shl1_nonsign, ymm_word, ymm_word)
|
|
20
|
+
|
|
21
|
+
sign_mask = Constant.float32x8(-0.0)
|
|
22
|
+
|
|
23
|
+
ymm_sign = YMMRegister()
|
|
24
|
+
VANDPS(ymm_sign, ymm_word, sign_mask)
|
|
25
|
+
|
|
26
|
+
ymm_shr3_nonsign = YMMRegister()
|
|
27
|
+
VPSRLD(ymm_shr3_nonsign, ymm_shl1_nonsign, 4)
|
|
28
|
+
|
|
29
|
+
exp_offset = Constant.uint32x8(0x38000000)
|
|
30
|
+
|
|
31
|
+
ymm_norm_nonsign = YMMRegister()
|
|
32
|
+
VPADDD(ymm_norm_nonsign, ymm_shr3_nonsign, exp_offset)
|
|
33
|
+
|
|
34
|
+
magic_mask = Constant.uint16x16(0x3E80)
|
|
35
|
+
ymm_denorm_nonsign = YMMRegister()
|
|
36
|
+
VPUNPCKLWD(ymm_denorm_nonsign, ymm_shl1_half, magic_mask)
|
|
37
|
+
|
|
38
|
+
magic_bias = Constant.float32x8(0.25)
|
|
39
|
+
VSUBPS(ymm_denorm_nonsign, ymm_denorm_nonsign, magic_bias)
|
|
40
|
+
|
|
41
|
+
ymm_denorm_cutoff = YMMRegister()
|
|
42
|
+
VMOVDQA(ymm_denorm_cutoff, Constant.uint32x8(0x00800000))
|
|
43
|
+
|
|
44
|
+
ymm_denorm_mask = YMMRegister()
|
|
45
|
+
VPCMPGTD(ymm_denorm_mask, ymm_denorm_cutoff, ymm_shr3_nonsign)
|
|
46
|
+
|
|
47
|
+
ymm_nonsign = YMMRegister()
|
|
48
|
+
VBLENDVPS(ymm_nonsign, ymm_norm_nonsign, ymm_denorm_nonsign, ymm_denorm_mask)
|
|
49
|
+
|
|
50
|
+
ymm_float = YMMRegister()
|
|
51
|
+
VORPS(ymm_float, ymm_nonsign, ymm_sign)
|
|
52
|
+
|
|
53
|
+
return ymm_float
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#ifndef FP16_BITCASTS_H
|
|
3
|
+
#define FP16_BITCASTS_H
|
|
4
|
+
|
|
5
|
+
#if defined(__cplusplus) && (__cplusplus >= 201103L)
|
|
6
|
+
#include <cstdint>
|
|
7
|
+
#elif !defined(__OPENCL_VERSION__)
|
|
8
|
+
#include <stdint.h>
|
|
9
|
+
#endif
|
|
10
|
+
|
|
11
|
+
#if defined(__INTEL_COMPILER)
|
|
12
|
+
#include <immintrin.h>
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
#if defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
|
|
16
|
+
#include <intrin.h>
|
|
17
|
+
#endif
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
static inline float fp32_from_bits(uint32_t w) {
|
|
21
|
+
#if defined(__OPENCL_VERSION__)
|
|
22
|
+
return as_float(w);
|
|
23
|
+
#elif defined(__CUDA_ARCH__)
|
|
24
|
+
return __uint_as_float((unsigned int) w);
|
|
25
|
+
#elif defined(__INTEL_COMPILER)
|
|
26
|
+
return _castu32_f32(w);
|
|
27
|
+
#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
|
|
28
|
+
return _CopyFloatFromInt32((__int32) w);
|
|
29
|
+
#else
|
|
30
|
+
union {
|
|
31
|
+
uint32_t as_bits;
|
|
32
|
+
float as_value;
|
|
33
|
+
} fp32 = { w };
|
|
34
|
+
return fp32.as_value;
|
|
35
|
+
#endif
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static inline uint32_t fp32_to_bits(float f) {
|
|
39
|
+
#if defined(__OPENCL_VERSION__)
|
|
40
|
+
return as_uint(f);
|
|
41
|
+
#elif defined(__CUDA_ARCH__)
|
|
42
|
+
return (uint32_t) __float_as_uint(f);
|
|
43
|
+
#elif defined(__INTEL_COMPILER)
|
|
44
|
+
return _castf32_u32(f);
|
|
45
|
+
#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
|
|
46
|
+
return (uint32_t) _CopyInt32FromFloat(f);
|
|
47
|
+
#else
|
|
48
|
+
union {
|
|
49
|
+
float as_value;
|
|
50
|
+
uint32_t as_bits;
|
|
51
|
+
} fp32 = { f };
|
|
52
|
+
return fp32.as_bits;
|
|
53
|
+
#endif
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static inline double fp64_from_bits(uint64_t w) {
|
|
57
|
+
#if defined(__OPENCL_VERSION__)
|
|
58
|
+
return as_double(w);
|
|
59
|
+
#elif defined(__CUDA_ARCH__)
|
|
60
|
+
return __longlong_as_double((long long) w);
|
|
61
|
+
#elif defined(__INTEL_COMPILER)
|
|
62
|
+
return _castu64_f64(w);
|
|
63
|
+
#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
|
|
64
|
+
return _CopyDoubleFromInt64((__int64) w);
|
|
65
|
+
#else
|
|
66
|
+
union {
|
|
67
|
+
uint64_t as_bits;
|
|
68
|
+
double as_value;
|
|
69
|
+
} fp64 = { w };
|
|
70
|
+
return fp64.as_value;
|
|
71
|
+
#endif
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static inline uint64_t fp64_to_bits(double f) {
|
|
75
|
+
#if defined(__OPENCL_VERSION__)
|
|
76
|
+
return as_ulong(f);
|
|
77
|
+
#elif defined(__CUDA_ARCH__)
|
|
78
|
+
return (uint64_t) __double_as_longlong(f);
|
|
79
|
+
#elif defined(__INTEL_COMPILER)
|
|
80
|
+
return _castf64_u64(f);
|
|
81
|
+
#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
|
|
82
|
+
return (uint64_t) _CopyInt64FromDouble(f);
|
|
83
|
+
#else
|
|
84
|
+
union {
|
|
85
|
+
double as_value;
|
|
86
|
+
uint64_t as_bits;
|
|
87
|
+
} fp64 = { f };
|
|
88
|
+
return fp64.as_bits;
|
|
89
|
+
#endif
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#endif /* FP16_BITCASTS_H */
|