| 483 | |
| 484 | private: |
| 485 | void start_bench(core_interface::Index::Pointer index, size_t max_iter, |
| 486 | const bool *is_stop) { |
| 487 | size_t thread_index = pool_->indexof_this(); |
| 488 | |
| 489 | size_t i = thread_index; |
| 490 | size_t sparse_query_size = batch_sparse_indices_.size(); |
| 491 | for (; i < max_iter && !*is_stop; i += threads_) { |
| 492 | int idx = i % sparse_query_size; |
| 493 | |
| 494 | // prefilter |
| 495 | FilterResultCache filter_cache; |
| 496 | std::shared_ptr<IndexFilter> filter_ptr = nullptr; |
| 497 | if (filter_mode_ == FM_TAG) { |
| 498 | if (batch_taglists_[idx].size() != 1) { |
| 499 | LOG_ERROR("query tag list not equal to one!"); |
| 500 | return; |
| 501 | } |
| 502 | |
| 503 | int ret = filter_cache.filter(id_to_tags_list_, batch_taglists_[idx][0], |
| 504 | tag_key_list_); |
| 505 | if (ret != 0) { |
| 506 | LOG_ERROR("prefilter failed, idx: %d", idx); |
| 507 | return; |
| 508 | } |
| 509 | |
| 510 | auto filter_func = [&](uint64_t key) { return filter_cache.find(key); }; |
| 511 | |
| 512 | filter_ptr = std::make_shared<IndexFilter>(); |
| 513 | filter_ptr->set(filter_func); |
| 514 | } |
| 515 | |
| 516 | auto query_param = query_param_->clone(); |
| 517 | query_param->filter = filter_ptr; |
| 518 | |
| 519 | // Do knn_search |
| 520 | uint64_t start = Monotime::MicroSeconds(); |
| 521 | int ret; |
| 522 | if (batch_count_ == 1) { |
| 523 | if (batch_sparse_counts_[idx].size() != 1) { |
| 524 | LOG_ERROR("Sparse count size should be 1, since batch count is 1"); |
| 525 | return; |
| 526 | } |
| 527 | ret = do_knn_search<T>(index, batch_sparse_counts_[idx][0], |
| 528 | batch_sparse_indices_[idx], |
| 529 | batch_sparse_features_[idx], query_param); |
| 530 | } else { |
| 531 | ret = do_knn_search_batch<T>( |
| 532 | index, batch_sparse_counts_[idx], batch_sparse_indices_[idx], |
| 533 | batch_sparse_features_[idx], idx, query_param); |
| 534 | } |
| 535 | |
| 536 | if (ret != 0) { |
| 537 | LOG_ERROR("Failed to sparse knn search, ret=%d %s", ret, |
| 538 | IndexError::What(ret)); |
| 539 | return; |
| 540 | } |
| 541 | |
| 542 | uint64_t end = Monotime::MicroSeconds(); |