Skip to content

Commit 63bc93b

Browse files
committed
Fix example linking and rename steady timer
1 parent 7dfd196 commit 63bc93b

6 files changed

Lines changed: 73 additions & 99 deletions

File tree

examples/c++/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,18 @@ endif()
3333

3434
# --- Dependency groups ---
3535
find_package(Threads REQUIRED)
36+
find_package(OpenMP QUIET)
3637

38+
set(zvec_openmp_deps)
39+
if(OpenMP_FOUND)
40+
list(APPEND zvec_openmp_deps OpenMP::OpenMP_CXX)
41+
endif()
3742

3843
set(zvec_core_deps
3944
zvec_turbo
45+
omega
46+
_lightgbm
47+
${zvec_openmp_deps}
4048
)
4149

4250
if (NOT WIN32)
@@ -52,6 +60,8 @@ if (NOT WIN32)
5260
set(zvec_db_deps
5361
roaring
5462
rocksdb
63+
omega
64+
_lightgbm
5565
arrow
5666
arrow_acero
5767
arrow_bundled_dependencies
@@ -63,6 +73,7 @@ if (NOT WIN32)
6373
${GFLAGS_LIB}
6474
${PROTOBUF_LIB}
6575
lz4
76+
${zvec_openmp_deps}
6677
)
6778
else ()
6879
# Windows static libraries use different naming conventions
@@ -77,6 +88,8 @@ else ()
7788
set(zvec_db_deps
7889
roaring
7990
rocksdb
91+
omega
92+
_lightgbm
8093
arrow_static
8194
arrow_acero_static
8295
arrow_bundled_dependencies
@@ -90,6 +103,7 @@ else ()
90103
lz4
91104
rpcrt4
92105
shlwapi
106+
${zvec_openmp_deps}
93107
)
94108
endif ()
95109

@@ -124,6 +138,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
124138
elseif(APPLE)
125139
target_link_libraries(zvec-core INTERFACE
126140
-Wl,-force_load ${ZVEC_LIB_DIR}/libzvec_core.a
141+
-Wl,-force_load ${ZVEC_LIB_DIR}/libomega.a
127142
zvec-ailego
128143
${zvec_core_deps}
129144
)
@@ -161,6 +176,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
161176
)
162177
elseif(APPLE)
163178
target_link_libraries(zvec-db INTERFACE
179+
-Wl,-force_load ${ZVEC_LIB_DIR}/libzvec_db.a
164180
zvec_db
165181
zvec-core
166182
zvec-ailego

examples/c/CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ link_directories(${ZVEC_LIB_DIR} ${ZVEC_DEPENDENCY_LIB_DIR})
4545

4646
# Find required packages
4747
find_package(Threads REQUIRED)
48+
find_package(OpenMP QUIET)
49+
50+
set(zvec_openmp_deps)
51+
if(OpenMP_FOUND)
52+
list(APPEND zvec_openmp_deps OpenMP::OpenMP_CXX)
53+
endif()
4854

4955
# --- Determine debug/release library names ---
5056
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
@@ -62,6 +68,8 @@ if(NOT WIN32)
6268
set(zvec_c_api_deps
6369
roaring
6470
rocksdb
71+
omega
72+
_lightgbm
6573
arrow
6674
arrow_acero
6775
arrow_bundled_dependencies
@@ -73,6 +81,7 @@ if(NOT WIN32)
7381
${GFLAGS_LIB}
7482
${PROTOBUF_LIB}
7583
lz4
84+
${zvec_openmp_deps}
7685
${CMAKE_THREAD_LIBS_INIT}
7786
${CMAKE_DL_LIBS}
7887
)
@@ -82,6 +91,8 @@ else()
8291
set(zvec_c_api_deps
8392
roaring
8493
rocksdb
94+
omega
95+
_lightgbm
8596
arrow_static
8697
arrow_acero_static
8798
arrow_bundled_dependencies
@@ -93,6 +104,7 @@ else()
93104
${GFLAGS_LIB}
94105
${PROTOBUF_LIB}
95106
lz4
107+
${zvec_openmp_deps}
96108
${CMAKE_THREAD_LIBS_INIT}
97109
rpcrt4
98110
shlwapi
@@ -206,4 +218,4 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release" AND ANDROID)
206218
set_property(TARGET c_api_basic_example c_api_collection_schema_example c_api_doc_example
207219
c_api_index_example c_api_field_schema_example c_api_optimized_example
208220
PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
209-
endif()
221+
endif()

src/core/algorithm/hnsw/hnsw_streamer.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include <ailego/internal/cpu_features.h>
1919
#include <ailego/pattern/defer.h>
2020
#include <ailego/utility/memory_helper.h>
21-
#include "utility/rdtsc_timer.h"
2221
#include "utility/sparse_utility.h"
22+
#include "utility/steady_clock_timer.h"
2323
#include "hnsw_algorithm.h"
2424
#include "hnsw_context.h"
2525
#include "hnsw_dist_calculator.h"
@@ -680,9 +680,9 @@ int HnswStreamer::search_impl(const void *query, const IndexQueryMeta &qmeta,
680680
const bool use_empty_hooks = UseEmptyHnswHooks();
681681
HnswAlgorithm::SearchHooks empty_hooks;
682682
for (size_t q = 0; q < count; ++q) {
683-
auto query_start = RdtscTimer::Now();
683+
auto query_start = SteadyClockTimer::Now();
684684
ctx->reset_query(query);
685-
auto query_search_start = RdtscTimer::Now();
685+
auto query_search_start = SteadyClockTimer::Now();
686686
if (use_empty_hooks) {
687687
bool stopped_early = false;
688688
ret = alg_->search_with_hooks(ctx, &empty_hooks, &stopped_early);
@@ -693,11 +693,11 @@ int HnswStreamer::search_impl(const void *query, const IndexQueryMeta &qmeta,
693693
LOG_ERROR("Hnsw searcher fast search failed");
694694
return ret;
695695
}
696-
auto query_search_end = RdtscTimer::Now();
696+
auto query_search_end = SteadyClockTimer::Now();
697697
auto query_search_time_ns =
698-
RdtscTimer::ElapsedNs(query_search_start, query_search_end);
698+
SteadyClockTimer::ElapsedNs(query_search_start, query_search_end);
699699
auto query_latency_ns =
700-
RdtscTimer::ElapsedNs(query_start, RdtscTimer::Now());
700+
SteadyClockTimer::ElapsedNs(query_start, SteadyClockTimer::Now());
701701
uint64_t query_seq = HnswQueryStatsSequence().fetch_add(1);
702702
if (ShouldLogHnswQueryStats(query_seq)) {
703703
LOG_INFO(
@@ -811,7 +811,7 @@ int HnswStreamer::search_bf_impl(
811811
auto &topk = ctx->topk_heap();
812812

813813
for (size_t q = 0; q < count; ++q) {
814-
auto query_start = RdtscTimer::Now();
814+
auto query_start = SteadyClockTimer::Now();
815815
ctx->reset_query(query);
816816
topk.clear();
817817
for (node_id_t id = 0; id < entity_.doc_cnt(); ++id) {
@@ -825,7 +825,7 @@ int HnswStreamer::search_bf_impl(
825825
}
826826
}
827827
auto query_latency_ns =
828-
RdtscTimer::ElapsedNs(query_start, RdtscTimer::Now());
828+
SteadyClockTimer::ElapsedNs(query_start, SteadyClockTimer::Now());
829829
uint64_t query_seq = HnswQueryStatsSequence().fetch_add(1);
830830
if (ShouldLogHnswQueryStats(query_seq)) {
831831
LOG_INFO(

src/core/utility/rdtsc_timer.cc

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2025-present the zvec project
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "utility/steady_clock_timer.h"
16+
17+
namespace zvec {
18+
namespace core {
19+
20+
SteadyClockTimer::tick_t SteadyClockTimer::Now() {
21+
const auto now = std::chrono::steady_clock::now().time_since_epoch();
22+
return static_cast<tick_t>(
23+
std::chrono::duration_cast<std::chrono::nanoseconds>(now).count());
24+
}
25+
26+
uint64_t SteadyClockTimer::ElapsedNs(tick_t start, tick_t end) {
27+
return end > start ? (end - start) : 0;
28+
}
29+
30+
} // namespace core
31+
} // namespace zvec
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,24 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#ifndef ZVEC_CORE_UTILITY_RDTSC_TIMER_H_
16-
#define ZVEC_CORE_UTILITY_RDTSC_TIMER_H_
15+
#ifndef ZVEC_CORE_UTILITY_STEADY_CLOCK_TIMER_H_
16+
#define ZVEC_CORE_UTILITY_STEADY_CLOCK_TIMER_H_
1717

18+
#include <chrono>
1819
#include <cstdint>
1920

20-
#if defined(__x86_64__) || defined(__i386__)
21-
#define ZVEC_CORE_HAS_TSC 1
22-
#else
23-
#define ZVEC_CORE_HAS_TSC 0
24-
#endif
25-
2621
namespace zvec {
2722
namespace core {
2823

29-
class RdtscTimer {
24+
class SteadyClockTimer {
3025
public:
3126
using tick_t = uint64_t;
3227

3328
static tick_t Now();
3429
static uint64_t ElapsedNs(tick_t start, tick_t end);
35-
36-
private:
37-
static uint64_t MonotonicRawNs();
38-
static double NsPerTick();
39-
static double CalibrateNsPerTick();
4030
};
4131

4232
} // namespace core
4333
} // namespace zvec
4434

45-
#endif // ZVEC_CORE_UTILITY_RDTSC_TIMER_H_
35+
#endif // ZVEC_CORE_UTILITY_STEADY_CLOCK_TIMER_H_

0 commit comments

Comments
 (0)