Skip to content

Commit 0141ac3

Browse files
Copilot1yefuwang1
andauthored
Replace compile-time SIMD detection with Highway runtime target in vectorlite_info() (#44)
* Initial plan * Update vectorlite_info to include best SIMD target chosen by Highway at runtime Co-authored-by: 1yefuwang1 <18023393+1yefuwang1@users.noreply.github.com> * Fix pre-existing typo in GetSuppportedTargets -> GetSupportedTargets Co-authored-by: 1yefuwang1 <18023393+1yefuwang1@users.noreply.github.com> * Final: all changes complete Co-authored-by: 1yefuwang1 <18023393+1yefuwang1@users.noreply.github.com> * Remove codeql artifact and fix .gitignore Co-authored-by: 1yefuwang1 <18023393+1yefuwang1@users.noreply.github.com> * Remove compile-time 'built with' SIMD from vectorlite_info, keep only Highway runtime best target Co-authored-by: 1yefuwang1 <18023393+1yefuwang1@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: 1yefuwang1 <18023393+1yefuwang1@users.noreply.github.com>
1 parent 16a01af commit 0141ac3

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ dist/*
4444
*egg-info
4545

4646
node_modules
47-
bindings/nodejs/vectorlite/package-lock.json_codeql_detected_source_root
47+
bindings/nodejs/vectorlite/package-lock.json
48+
_codeql_detected_source_root

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Please note vectorlite is currently in beta. There could be breaking changes.
5656
### Free-standing Application Defined SQL functions
5757
The following functions can be used in any context.
5858
``` sql
59-
vectorlite_info() -- prints version info and some compile time info. e.g. Is SSE, AVX enabled.
59+
vectorlite_info() -- prints version info and the best SIMD target chosen by Highway at runtime.
6060
vector_from_json(json_string) -- converts a json array of type TEXT into BLOB(a c-style float32 array)
6161
vector_to_json(vector_blob) -- converts a vector of type BLOB(c-style float32 array) into a json array of type TEXT
6262
vector_distance(vector_blob1, vector_blob2, distance_type_str) -- calculate vector distance between two vectors, distance_type_str could be 'l2', 'cosine', 'ip'

bindings/python/vectorlite_py/test/vectorlite_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def test_vectorlite_info(conn):
3030
cur.execute('select vectorlite_info()')
3131
output = cur.fetchone()
3232
assert f'vectorlite extension version {vectorlite_py.__version__}' in output[0]
33+
assert 'Best SIMD target in use:' in output[0]
3334

3435
def test_virtual_table_happy_path(conn, random_vectors):
3536
# Note: if space is '', it will be treated as 'l2'

doc/markdown/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Please note vectorlite is currently in beta. There could be breaking changes.
44
## Free-standing Application Defined SQL functions
55
The following functions can be used in any context.
66
``` sql
7-
vectorlite_info() -- prints version info and some compile time info. e.g. Is SSE, AVX enabled.
7+
vectorlite_info() -- prints version info and the best SIMD target chosen by Highway at runtime.
88
vector_from_json(json_string) -- converts a json array of type TEXT into BLOB(a c-style float32 array)
99
vector_to_json(vector_blob) -- converts a vector of type BLOB(c-style float32 array) into a json array of type TEXT
1010
vector_distance(vector_blob1, vector_blob2, distance_type_str) -- calculate vector distance between two vectors, distance_type_str could be 'l2', 'cosine', 'ip'

vectorlite/ops/ops.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,14 @@ HWY_DLLEXPORT std::vector<const char*> GetSupportedTargets() {
966966
return target_names;
967967
}
968968

969+
HWY_DLLEXPORT const char* GetBestTarget() {
970+
std::vector<int64_t> targets = hwy::SupportedAndGeneratedTargets();
971+
if (targets.empty()) {
972+
return "Unknown";
973+
}
974+
return hwy::TargetName(targets[0]);
975+
}
976+
969977
HWY_DLLEXPORT void QuantizeF32ToF16(const float* HWY_RESTRICT in,
970978
hwy::float16_t* HWY_RESTRICT out,
971979
size_t num_elements) {

vectorlite/ops/ops.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ HWY_DLLEXPORT void Normalize_Scalar(hwy::float16_t* HWY_RESTRICT inout,
7676
size_t num_elements);
7777

7878
// Get supported SIMD target name strings.
79-
HWY_DLLEXPORT std::vector<const char*> GetSuppportedTargets();
79+
HWY_DLLEXPORT std::vector<const char*> GetSupportedTargets();
80+
81+
// Get the best SIMD target chosen by Highway at runtime.
82+
HWY_DLLEXPORT const char* GetBestTarget();
8083

8184
// in and out should not be nullptr and points to valid memory of required size.
8285
HWY_DLLEXPORT void QuantizeF32ToF16(const float* HWY_RESTRICT in,

vectorlite/sqlite_functions.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "absl/log/log.h"
77
#include "absl/status/status.h"
88
#include "absl/strings/str_format.h"
9-
#include "util.h"
9+
#include "ops/ops.h"
1010
#include "vector.h"
1111
#include "vector_space.h"
1212
#include "vectorlite/version.h"
@@ -17,10 +17,11 @@ extern const sqlite3_api_routines *sqlite3_api;
1717
namespace vectorlite {
1818

1919
void ShowInfo(sqlite3_context *ctx, int, sqlite3_value **) {
20-
auto simd = vectorlite::DetectSIMD().value_or("SIMD not enabled");
20+
const char *best_target = vectorlite::ops::GetBestTarget();
2121
std::string info =
22-
absl::StrFormat("vectorlite extension version %s, built with %s",
23-
VECTORLITE_VERSION, simd);
22+
absl::StrFormat("vectorlite extension version %s. "
23+
"Best SIMD target in use: %s",
24+
VECTORLITE_VERSION, best_target);
2425
DLOG(INFO) << "ShowInfo called: " << info;
2526
sqlite3_result_text(ctx, info.c_str(), -1, SQLITE_TRANSIENT);
2627
}

0 commit comments

Comments
 (0)