Skip to content

Commit

Permalink
Fix ExchangeBenchmark and PrefixSortAlgorithmBenchmark (facebookincub…
Browse files Browse the repository at this point in the history
…ator#8493)

Summary:
terminate called after throwing an instance of 'facebook::velox::VeloxRuntimeError'
  what():  Exception: VeloxRuntimeError
Error Source: RUNTIME
Error Code: INVALID_STATE
Reason: The memory manager is not set

The reason for the error is that the benchmark object is initialized before the main function is called. We need to ensure that the memory manager instance is initialized before the benchmark object.

Pull Request resolved: facebookincubator#8493

Reviewed By: Yuhta

Differential Revision: D53042869

Pulled By: mbasmanova

fbshipit-source-id: f0abec44afa347702a444854396fbdf2a96bf195
  • Loading branch information
skadilover authored and facebook-github-bot committed Jan 24, 2024
1 parent 5fa6497 commit 4cd32e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
25 changes: 13 additions & 12 deletions velox/exec/benchmarks/ExchangeBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class ExchangeBenchmark : public VectorTestBase {

int32_t ExchangeBenchmark::iteration_;

ExchangeBenchmark bm;
std::unique_ptr<ExchangeBenchmark> bm;

std::vector<RowVectorPtr> flat10k;
std::vector<RowVectorPtr> deep10k;
Expand All @@ -357,27 +357,27 @@ Counters localFlat10kCounters;
Counters struct1kCounters;

BENCHMARK(exchangeFlat10k) {
bm.run(flat10k, FLAGS_width, FLAGS_task_width, flat10kCounters);
bm->run(flat10k, FLAGS_width, FLAGS_task_width, flat10kCounters);
}

BENCHMARK_RELATIVE(exchangeFlat50) {
bm.run(flat50, FLAGS_width, FLAGS_task_width, flat50Counters);
bm->run(flat50, FLAGS_width, FLAGS_task_width, flat50Counters);
}

BENCHMARK(exchangeDeep10k) {
bm.run(deep10k, FLAGS_width, FLAGS_task_width, deep10kCounters);
bm->run(deep10k, FLAGS_width, FLAGS_task_width, deep10kCounters);
}

BENCHMARK_RELATIVE(exchangeDeep50) {
bm.run(deep50, FLAGS_width, FLAGS_task_width, deep50Counters);
bm->run(deep50, FLAGS_width, FLAGS_task_width, deep50Counters);
}

BENCHMARK(exchangeStruct1K) {
bm.run(struct1k, FLAGS_width, FLAGS_task_width, struct1kCounters);
bm->run(struct1k, FLAGS_width, FLAGS_task_width, struct1kCounters);
}

BENCHMARK(localFlat10k) {
bm.runLocal(
bm->runLocal(
flat10k, FLAGS_width, FLAGS_num_local_tasks, localFlat10kCounters);
}

Expand Down Expand Up @@ -444,11 +444,12 @@ int main(int argc, char** argv) {
MAP(BIGINT(),
ROW({{"s2_int", INTEGER()}, {"s2_string", VARCHAR()}})))}});

flat10k = bm.makeRows(flatType, 10, 10000, FLAGS_dict_pct);
deep10k = bm.makeRows(deepType, 10, 10000, FLAGS_dict_pct);
flat50 = bm.makeRows(flatType, 2000, 50, FLAGS_dict_pct);
deep50 = bm.makeRows(deepType, 2000, 50, FLAGS_dict_pct);
struct1k = bm.makeRows(structType, 100, 1000, FLAGS_dict_pct);
bm = std::make_unique<ExchangeBenchmark>();
flat10k = bm->makeRows(flatType, 10, 10000, FLAGS_dict_pct);
deep10k = bm->makeRows(deepType, 10, 10000, FLAGS_dict_pct);
flat50 = bm->makeRows(flatType, 2000, 50, FLAGS_dict_pct);
deep50 = bm->makeRows(deepType, 2000, 50, FLAGS_dict_pct);
struct1k = bm->makeRows(structType, 100, 1000, FLAGS_dict_pct);

folly::runBenchmarks();
std::cout << "flat10k: " << flat10kCounters.toString() << std::endl
Expand Down
22 changes: 12 additions & 10 deletions velox/exec/prefixsort/benchmarks/PrefixSortAlgorithmBenchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ using namespace facebook::velox;
using namespace facebook::velox::exec;

namespace {

class PrefixSortAlgorithmBenchmark {
public:
void seed(int32_t seed) {
Expand Down Expand Up @@ -58,39 +59,40 @@ class PrefixSortAlgorithmBenchmark {
folly::Random::DefaultGenerator rng_;
};

PrefixSortAlgorithmBenchmark bm;
std::unique_ptr<PrefixSortAlgorithmBenchmark> bm;

std::vector<int64_t> data10k;
std::vector<int64_t> data100k;
std::vector<int64_t> data1000k;
std::vector<int64_t> data10000k;

BENCHMARK(PrefixSort_algorithm_10k) {
bm.runQuickSort(data10k);
bm->runQuickSort(data10k);
}

BENCHMARK(PrefixSort_algorithm_100k) {
bm.runQuickSort(data100k);
bm->runQuickSort(data100k);
}

BENCHMARK(PrefixSort_algorithm_1000k) {
bm.runQuickSort(data1000k);
bm->runQuickSort(data1000k);
}

BENCHMARK(PrefixSort_algorithm_10000k) {
bm.runQuickSort(data10000k);
bm->runQuickSort(data10000k);
}

} // namespace

int main(int argc, char** argv) {
folly::Init init(&argc, &argv);
memory::MemoryManager::initialize({});
bm.seed(FLAGS_sort_data_seed);
data10k = bm.generateTestVector(10'000);
data100k = bm.generateTestVector(100'000);
data1000k = bm.generateTestVector(1'000'000);
data10000k = bm.generateTestVector(10'000'000);
bm = std::make_unique<PrefixSortAlgorithmBenchmark>();
bm->seed(FLAGS_sort_data_seed);
data10k = bm->generateTestVector(10'000);
data100k = bm->generateTestVector(100'000);
data1000k = bm->generateTestVector(1'000'000);
data10000k = bm->generateTestVector(10'000'000);
folly::runBenchmarks();
return 0;
}

0 comments on commit 4cd32e3

Please sign in to comment.