Project
Loading...
Searching...
No Matches
bench_ransDecodeScaling.cxx
Go to the documentation of this file.
1// Copyright 2019-2023 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
17
18#include <vector>
19#include <cstring>
20#include <random>
21#include <algorithm>
22#ifdef RANS_PARALLEL_STL
23#include <execution>
24#endif
25#include <iterator>
26
27#include <benchmark/benchmark.h>
28
29#include "rANS/factory.h"
30#include "rANS/histogram.h"
31
32#ifdef ENABLE_VTUNE_PROFILER
33#include <ittnotify.h>
34#endif
35
36#include "helpers.h"
37
38using namespace o2::rans;
39
40inline constexpr size_t MessageSize = 1ull << 22;
41
42template <typename source_T>
44{
45 public:
46 SourceMessageUniform(size_t messageSize, size_t max) : mMax{max}
47 {
48 std::mt19937 mt(0); // same seed we want always the same distrubution of random numbers;
49 std::uniform_int_distribution<source_T> dist(0, max);
50 const size_t sourceSize = messageSize / sizeof(source_T) + 1;
51 mSourceMessage.resize(sourceSize);
52#ifdef RANS_PARALLEL_STL
53 std::generate(std::execution::par_unseq, mSourceMessage.begin(), mSourceMessage.end(), [&dist, &mt]() { return dist(mt); });
54#else
55 std::generate(mSourceMessage.begin(), mSourceMessage.end(), [&dist, &mt]() { return dist(mt); });
56#endif // RANS_PARALLEL_STL
57 }
58
59 const auto& get() const { return mSourceMessage; };
60 size_t getMax() const { return mMax; };
61
62 private:
63 size_t mMax{};
64 std::vector<source_T> mSourceMessage{};
65};
66
68
69void ransDecodeBenchmark(benchmark::State& st)
70{
71
72 using source_type = uint32_t;
73 size_t max = utils::pow2(st.range(0));
74
75 if (max != sourceMessage.getMax()) {
77 }
78 const auto& inputData = sourceMessage.get();
80 encodeBuffer{inputData.size()};
82
83 const auto histogram = makeDenseHistogram::fromSamples(gsl::span<const source_type>(inputData));
85 const auto renormedHistogram = renorm(histogram, metrics, RenormingPolicy::Auto, 10);
86
87 auto encoder = makeDenseEncoder<>::fromRenormed(renormedHistogram);
88 encodeBuffer.encodeBufferEnd = encoder.process(inputData.data(), inputData.data() + inputData.size(), encodeBuffer.buffer.data());
89
90 auto decoder = makeDecoder<>::fromRenormed(renormedHistogram);
91#ifdef ENABLE_VTUNE_PROFILER
92 __itt_resume();
93#endif
94 for (auto _ : st) {
95 decoder.process(encodeBuffer.encodeBufferEnd, decodeBuffer.buffer.data(), inputData.size(), encoder.getNStreams());
96 }
97#ifdef ENABLE_VTUNE_PROFILER
98 __itt_pause();
99#endif
100
101 if (!(decodeBuffer == inputData)) {
102 st.SkipWithError("Missmatch between encoded and decoded Message");
103 }
104
105 const auto& datasetProperties = metrics.getDatasetProperties();
106 st.SetItemsProcessed(static_cast<int64_t>(inputData.size()) * static_cast<int64_t>(st.iterations()));
107 st.SetBytesProcessed(static_cast<int64_t>(inputData.size()) * sizeof(source_type) * static_cast<int64_t>(st.iterations()));
108 st.counters["AlphabetRangeBits"] = datasetProperties.alphabetRangeBits;
109 st.counters["nUsedAlphabetSymbols"] = datasetProperties.nUsedAlphabetSymbols;
110 st.counters["SymbolTablePrecision"] = renormedHistogram.getRenormingBits();
111 st.counters["Entropy"] = datasetProperties.entropy;
112 st.counters["ExpectedCodewordLength"] = computeExpectedCodewordLength(histogram, renormedHistogram);
113 st.counters["SourceSize"] = inputData.size() * sizeof(source_type);
114 st.counters["CompressedSize"] = std::distance(encodeBuffer.buffer.data(), encodeBuffer.encodeBufferEnd) * sizeof(typename decltype(encoder)::stream_type);
115 st.counters["Compression"] = st.counters["SourceSize"] / static_cast<double>(st.counters["CompressedSize"]);
116 st.counters["LowerBound"] = inputData.size() * (static_cast<double>(st.counters["Entropy"]) / 8);
117 st.counters["CompressionWRTEntropy"] = st.counters["CompressedSize"] / st.counters["LowerBound"];
118};
119
120BENCHMARK(ransDecodeBenchmark)->DenseRange(8, 27, 1);
121
std::vector< o2::mid::ColumnData > inputData
constexpr size_t MessageSize
BENCHMARK_MAIN()
void ransDecodeBenchmark(benchmark::State &st)
SourceMessageUniform< uint32_t > sourceMessage
BENCHMARK(ransDecodeBenchmark) -> DenseRange(8, 27, 1)
benchmark::State & st
uint32_t source_type
uint32_t stream_type
SourceMessageUniform(size_t messageSize, size_t max)
static constexpr decltype(auto) fromRenormed(const RenormedHistogramConcept< container_T > &renormed)
Definition factory.h:106
static constexpr decltype(auto) fromRenormed(const RenormedDenseHistogram< source_T > &renormed)
Definition factory.h:195
preprocessor defines to enable features based on CPU architecture
static factory classes for building histograms, encoders and decoders.
GLsizei GLenum const void GLuint GLsizei GLfloat * metrics
Definition glcorearb.h:5500
common functionality for rANS benchmarks.
public interface for building and renorming histograms from source data.
double_t computeExpectedCodewordLength(const DenseHistogram< source_T > &histogram, const RenormedDenseHistogram< source_T > &rescaledHistogram)
Definition utils.h:33
decltype(auto) renorm(histogram_T histogram, size_t newPrecision, RenormingPolicy renormingPolicy=RenormingPolicy::Auto, size_t lowProbabilityCutoffBits=0)
Definition renorm.h:203
static decltype(auto) fromSamples(source_IT begin, source_IT end, typename std::iterator_traits< source_IT >::value_type min, typename std::iterator_traits< source_IT >::value_type max)
Definition factory.h:144
std::string decodeBuffer(int feeId, gsl::span< const std::byte > buffer)
constexpr size_t max