22#ifdef RANS_PARALLEL_STL
27#include <benchmark/benchmark.h>
33#ifdef ENABLE_VTUNE_PROFILER
43template <
typename source_T>
49 const auto&
get(
size_t messageSize)
51 if (mSourceMessage.empty()) {
52 LOG(info) <<
"generating Binomial distribution";
55 const size_t draws = std::min(1ul << 27,
static_cast<size_t>(std::numeric_limits<source_T>::max()));
56 const double probability = 0.5;
57 std::binomial_distribution<source_T> dist(draws, probability);
58 const size_t sourceSize = messageSize /
sizeof(
source_T) + 1;
59 mSourceMessage.resize(sourceSize);
60#ifdef RANS_PARALLEL_STL
61 std::generate(std::execution::par_unseq, mSourceMessage.begin(), mSourceMessage.end(), [&dist, &mt]() { return dist(mt); });
63 std::generate(mSourceMessage.begin(), mSourceMessage.end(), [&dist, &mt]() { return dist(mt); });
67 return mSourceMessage;
71 std::vector<source_T> mSourceMessage{};
76template <
typename source_T>
82 const auto&
get(
size_t messageSize)
84 if (mSourceMessage.empty()) {
85 LOG(info) <<
"generating Uniform distribution";
89 const double max = std::min(1ul << 27,
static_cast<size_t>(std::numeric_limits<source_T>::max()));
90 std::uniform_int_distribution<source_T> dist(
min,
max);
91 const size_t sourceSize = messageSize /
sizeof(
source_T) + 1;
92 mSourceMessage.resize(sourceSize);
93#ifdef RANS_PARALLEL_STL
94 std::generate(std::execution::par_unseq, mSourceMessage.begin(), mSourceMessage.end(), [&dist, &mt]() { return dist(mt); });
96 std::generate(mSourceMessage.begin(), mSourceMessage.end(), [&dist, &mt]() { return dist(mt); });
99 return mSourceMessage;
103 std::vector<source_T> mSourceMessage{};
108template <
class... Args>
112 auto args_tuple = std::make_tuple(std::move(args)...);
116 using histogram_type = std::remove_cv_t<std::remove_reference_t<decltype(std::get<1>(args_tuple))>>;
117 using input_data_type = std::remove_cv_t<std::remove_reference_t<
decltype(
inputData)>>;
118 using source_type =
typename input_data_type::value_type;
123#ifdef ENABLE_VTUNE_PROFILER
127 histogram_type hist{};
130 benchmark::DoNotOptimize(hist);
132#ifdef ENABLE_VTUNE_PROFILER
137 histogram_type hist{};
138 hist.addSamples(gsl::span<const source_type>(
inputData));
140 for (std::ptrdiff_t symbol = histogram.getOffset(); symbol != histogram.getOffset() +
static_cast<std::ptrdiff_t
>(histogram.size()); ++symbol) {
141 if (histogram[symbol] > 0) {
142 LOG_IF(info, histogram[symbol] != hist[symbol]) << fmt::format(
"[{}]: {} != {}", symbol, hist[symbol], histogram[symbol]);
143 isSame = isSame && (histogram[symbol] == hist[symbol]);
148 st.SkipWithError(
"Missmatch between encoded and decoded Message");
151 const auto& datasetProperties =
metrics.getDatasetProperties();
152 st.SetItemsProcessed(
static_cast<int64_t
>(
inputData.size()) *
static_cast<int64_t
>(
st.iterations()));
153 st.SetBytesProcessed(
static_cast<int64_t
>(
inputData.size()) *
sizeof(
source_type) *
static_cast<int64_t
>(
st.iterations()));
154 st.counters[
"AlphabetRangeBits"] = datasetProperties.alphabetRangeBits;
155 st.counters[
"nUsedAlphabetSymbols"] = datasetProperties.nUsedAlphabetSymbols;
156 st.counters[
"HistogramSize"] = hist.size() *
sizeof(
source_type);
157 st.counters[
"Entropy"] = datasetProperties.entropy;
159 st.counters[
"LowerBound"] =
inputData.size() * (
static_cast<double>(
st.counters[
"Entropy"]) / 8);
162template <
class... Args>
166 auto args_tuple = std::make_tuple(std::move(args)...);
169 using histogram_type = std::remove_cv_t<std::remove_reference_t<decltype(std::get<1>(args_tuple))>>;
170 using input_data_type = std::remove_cv_t<std::remove_reference_t<
decltype(
inputData)>>;
171 using source_type =
typename input_data_type::value_type;
176 histogram_type hist{};
177 hist.addSamples(gsl::span<const source_type>(
inputData));
179#ifdef ENABLE_VTUNE_PROFILER
184 const uint32_t t = hist[symbol];
185 benchmark::DoNotOptimize(t);
188#ifdef ENABLE_VTUNE_PROFILER
193 for (std::ptrdiff_t symbol = histogram.getOffset(); symbol != histogram.getOffset() +
static_cast<std::ptrdiff_t
>(histogram.size()); ++symbol) {
194 if (histogram[symbol] > 0) {
195 LOG_IF(info, histogram[symbol] != hist[symbol]) << fmt::format(
"[{}]: {} != {}", symbol, hist[symbol], histogram[symbol]);
196 isSame = isSame && (histogram[symbol] == hist[symbol]);
201 st.SkipWithError(
"Missmatch between encoded and decoded Message");
204 const auto& datasetProperties =
metrics.getDatasetProperties();
205 st.SetItemsProcessed(
static_cast<int64_t
>(
inputData.size()) *
static_cast<int64_t
>(
st.iterations()));
206 st.SetBytesProcessed(
static_cast<int64_t
>(
inputData.size()) *
sizeof(
source_type) *
static_cast<int64_t
>(
st.iterations()));
207 st.counters[
"AlphabetRangeBits"] = datasetProperties.alphabetRangeBits;
208 st.counters[
"nUsedAlphabetSymbols"] = datasetProperties.nUsedAlphabetSymbols;
209 st.counters[
"HistogramSize"] = hist.size() *
sizeof(
source_type);
210 st.counters[
"Entropy"] = datasetProperties.entropy;
212 st.counters[
"LowerBound"] =
inputData.size() * (
static_cast<double>(
st.counters[
"Entropy"]) / 8);
Histogram for source symbols used to estimate symbol probabilities for entropy coding.
std::vector< o2::mid::ColumnData > inputData
constexpr size_t MessageSize
void ransMakeHistogramBenchmark(benchmark::State &st, Args &&... args)
void ransAccessHistogramBenchmark(benchmark::State &st, Args &&... args)
BENCHMARK_CAPTURE(ransMakeHistogramBenchmark, makeHistogram_Vector_binomial_32, std::reference_wrapper(sourceMessageBinomial32), DenseHistogram< uint32_t >{})
SourceMessageProxyBinomial< uint32_t > sourceMessageBinomial32
SourceMessageProxyUniform< uint32_t > sourceMessageUniform32
SourceMessageProxyBinomial()=default
const auto & get(size_t messageSize)
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
common functionality for rANS benchmarks.
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)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"