westonpace commented on a change in pull request #12067:
URL: https://github.com/apache/arrow/pull/12067#discussion_r834000260



##########
File path: cpp/src/arrow/compute/exec/bloom_filter_test.cc
##########
@@ -0,0 +1,484 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include <gmock/gmock-matchers.h>
+
+#include <algorithm>
+#include <chrono>
+#include <condition_variable>
+#include <set>
+#include <thread>
+#include "arrow/compute/exec/bloom_filter.h"
+#include "arrow/compute/exec/key_hash.h"
+#include "arrow/compute/exec/test_util.h"
+#include "arrow/compute/exec/util.h"
+#include "arrow/util/bitmap_ops.h"
+#include "arrow/util/cpu_info.h"
+
+namespace arrow {
+namespace compute {
+
+Status BuildBloomFilter(BloomFilterBuildStrategy strategy, size_t num_threads,
+                        int64_t hardware_flags, MemoryPool* pool, int64_t 
num_rows,
+                        std::function<void(int64_t, int, uint32_t*)> 
get_hash32_impl,
+                        std::function<void(int64_t, int, uint64_t*)> 
get_hash64_impl,
+                        BlockedBloomFilter* target, float* build_cost) {
+  constexpr int batch_size_max = 32 * 1024;
+  int64_t num_batches = bit_util::CeilDiv(num_rows, batch_size_max);
+
+  auto builder = BloomFilterBuilder::Make(strategy);
+
+  std::vector<std::vector<uint32_t>> thread_local_hashes32;
+  std::vector<std::vector<uint64_t>> thread_local_hashes64;
+  thread_local_hashes32.resize(num_threads);
+  thread_local_hashes64.resize(num_threads);
+  for (size_t i = 0; i < num_threads; ++i) {
+    thread_local_hashes32[i].resize(batch_size_max);
+    thread_local_hashes64[i].resize(batch_size_max);
+  }
+
+  // Repeate the entire test in a loop multiple times in order to get 
meaningful time
+  // measurements. Time measurements in debug do not provide useful 
information and would
+  // make test take unreasonably long, so there are no repeats in debug.
+  //
+  std::vector<float> build_cost_vector;
+  int64_t num_repeats =
+      std::max(static_cast<int64_t>(1), bit_util::CeilDiv(1LL << 27, 
num_rows));
+#ifndef NDEBUG
+  num_repeats = 1LL;
+#endif
+  build_cost_vector.resize(num_repeats);
+
+  for (int64_t irepeat = 0; irepeat < num_repeats; ++irepeat) {
+    auto time0 = std::chrono::high_resolution_clock::now();
+
+    RETURN_NOT_OK(builder->Begin(num_threads, hardware_flags, pool, num_rows,
+                                 bit_util::CeilDiv(num_rows, batch_size_max), 
target));
+
+    for (int64_t i = 0; i < num_batches; ++i) {
+      size_t thread_index = 0;
+      int batch_size = static_cast<int>(
+          std::min(num_rows - i * batch_size_max, 
static_cast<int64_t>(batch_size_max)));
+      if (target->NumHashBitsUsed() > 32) {
+        uint64_t* hashes = thread_local_hashes64[thread_index].data();
+        get_hash64_impl(i * batch_size_max, batch_size, hashes);
+        Status status = builder->PushNextBatch(thread_index, batch_size, 
hashes);
+        ARROW_DCHECK(status.ok());
+      } else {
+        uint32_t* hashes = thread_local_hashes32[thread_index].data();
+        get_hash32_impl(i * batch_size_max, batch_size, hashes);
+        Status status = builder->PushNextBatch(thread_index, batch_size, 
hashes);
+        ARROW_DCHECK(status.ok());
+      }
+    }
+
+    auto time1 = std::chrono::high_resolution_clock::now();
+    auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(time1 - 
time0).count();
+
+    builder->CleanUp();
+
+    build_cost_vector[irepeat] = static_cast<float>(ns) / 
static_cast<float>(num_rows);
+  }
+
+  std::sort(build_cost_vector.begin(), build_cost_vector.end());
+  *build_cost = build_cost_vector[build_cost_vector.size() / 2];
+
+  return Status::OK();
+}
+
+// FPR (false positives rate) - fraction of false positives relative to the sum
+// of false positives and true negatives.
+//
+// Output FPR and build and probe cost.
+//
+Status TestBloomSmall(BloomFilterBuildStrategy strategy, int64_t num_build,
+                      int num_build_copies, int dop, bool use_simd,
+                      bool enable_prefetch) {
+  int64_t hardware_flags = use_simd ? ::arrow::internal::CpuInfo::AVX2 : 0;
+
+  // Generate input keys
+  //
+  int64_t num_probe = 4 * num_build;

Review comment:
       The FPR is now calculated and checked.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to