diff --git a/.gitignore b/.gitignore index 127259f..0c09d2c 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ dist/* *egg-info node_modules -bindings/nodejs/vectorlite/package-lock.json_codeql_detected_source_root +bindings/nodejs/vectorlite/package-lock.json +_codeql_detected_source_root diff --git a/README.md b/README.md index 6100e0b..32cdeab 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Please note vectorlite is currently in beta. There could be breaking changes. ### Free-standing Application Defined SQL functions The following functions can be used in any context. ``` sql -vectorlite_info() -- prints version info and some compile time info. e.g. Is SSE, AVX enabled. +vectorlite_info() -- prints version info and the best SIMD target chosen by Highway at runtime. vector_from_json(json_string) -- converts a json array of type TEXT into BLOB(a c-style float32 array) vector_to_json(vector_blob) -- converts a vector of type BLOB(c-style float32 array) into a json array of type TEXT vector_distance(vector_blob1, vector_blob2, distance_type_str) -- calculate vector distance between two vectors, distance_type_str could be 'l2', 'cosine', 'ip' diff --git a/bindings/python/vectorlite_py/test/vectorlite_test.py b/bindings/python/vectorlite_py/test/vectorlite_test.py index 461f3ad..6db435a 100644 --- a/bindings/python/vectorlite_py/test/vectorlite_test.py +++ b/bindings/python/vectorlite_py/test/vectorlite_test.py @@ -30,6 +30,7 @@ def test_vectorlite_info(conn): cur.execute('select vectorlite_info()') output = cur.fetchone() assert f'vectorlite extension version {vectorlite_py.__version__}' in output[0] + assert 'Best SIMD target in use:' in output[0] def test_virtual_table_happy_path(conn, random_vectors): # Note: if space is '', it will be treated as 'l2' diff --git a/doc/markdown/api.md b/doc/markdown/api.md index f1c31e3..fb1cb46 100644 --- a/doc/markdown/api.md +++ b/doc/markdown/api.md @@ -4,7 +4,7 @@ Please note vectorlite is currently in beta. There could be breaking changes. ## Free-standing Application Defined SQL functions The following functions can be used in any context. ``` sql -vectorlite_info() -- prints version info and some compile time info. e.g. Is SSE, AVX enabled. +vectorlite_info() -- prints version info and the best SIMD target chosen by Highway at runtime. vector_from_json(json_string) -- converts a json array of type TEXT into BLOB(a c-style float32 array) vector_to_json(vector_blob) -- converts a vector of type BLOB(c-style float32 array) into a json array of type TEXT vector_distance(vector_blob1, vector_blob2, distance_type_str) -- calculate vector distance between two vectors, distance_type_str could be 'l2', 'cosine', 'ip' diff --git a/vectorlite/ops/ops.cpp b/vectorlite/ops/ops.cpp index 5d51e11..d5182b9 100644 --- a/vectorlite/ops/ops.cpp +++ b/vectorlite/ops/ops.cpp @@ -966,6 +966,14 @@ HWY_DLLEXPORT std::vector GetSupportedTargets() { return target_names; } +HWY_DLLEXPORT const char* GetBestTarget() { + std::vector targets = hwy::SupportedAndGeneratedTargets(); + if (targets.empty()) { + return "Unknown"; + } + return hwy::TargetName(targets[0]); +} + HWY_DLLEXPORT void QuantizeF32ToF16(const float* HWY_RESTRICT in, hwy::float16_t* HWY_RESTRICT out, size_t num_elements) { diff --git a/vectorlite/ops/ops.h b/vectorlite/ops/ops.h index 87cd216..58ac041 100644 --- a/vectorlite/ops/ops.h +++ b/vectorlite/ops/ops.h @@ -76,7 +76,10 @@ HWY_DLLEXPORT void Normalize_Scalar(hwy::float16_t* HWY_RESTRICT inout, size_t num_elements); // Get supported SIMD target name strings. -HWY_DLLEXPORT std::vector GetSuppportedTargets(); +HWY_DLLEXPORT std::vector GetSupportedTargets(); + +// Get the best SIMD target chosen by Highway at runtime. +HWY_DLLEXPORT const char* GetBestTarget(); // in and out should not be nullptr and points to valid memory of required size. HWY_DLLEXPORT void QuantizeF32ToF16(const float* HWY_RESTRICT in, diff --git a/vectorlite/sqlite_functions.cpp b/vectorlite/sqlite_functions.cpp index 95b2973..a979e40 100644 --- a/vectorlite/sqlite_functions.cpp +++ b/vectorlite/sqlite_functions.cpp @@ -6,7 +6,7 @@ #include "absl/log/log.h" #include "absl/status/status.h" #include "absl/strings/str_format.h" -#include "util.h" +#include "ops/ops.h" #include "vector.h" #include "vector_space.h" #include "vectorlite/version.h" @@ -17,10 +17,11 @@ extern const sqlite3_api_routines *sqlite3_api; namespace vectorlite { void ShowInfo(sqlite3_context *ctx, int, sqlite3_value **) { - auto simd = vectorlite::DetectSIMD().value_or("SIMD not enabled"); + const char *best_target = vectorlite::ops::GetBestTarget(); std::string info = - absl::StrFormat("vectorlite extension version %s, built with %s", - VECTORLITE_VERSION, simd); + absl::StrFormat("vectorlite extension version %s. " + "Best SIMD target in use: %s", + VECTORLITE_VERSION, best_target); DLOG(INFO) << "ShowInfo called: " << info; sqlite3_result_text(ctx, info.c_str(), -1, SQLITE_TRANSIENT); }