42#include "debug/CacheComp.hh"
43#include "params/MultiCompressor.hh"
52 std::unique_ptr<Base::CompressionData> comp_data)
85 compressor->setCache(_cache);
89std::unique_ptr<Base::CompressionData>
96 std::unique_ptr<Base::CompressionData> compData;
98 uint8_t compressionFactor;
100 Results(
unsigned index,
101 std::unique_ptr<Base::CompressionData> comp_data,
102 Cycles decomp_lat, std::size_t blk_size)
103 :
index(
index), compData(std::move(comp_data)),
104 decompLat(decomp_lat)
106 const std::size_t size = compData->getSize();
116 compressionFactor = (size > blk_size) ? 1 :
117 ((size == 0) ? blk_size :
121 struct ResultsComparator
124 operator()(
const std::shared_ptr<Results>& lhs,
125 const std::shared_ptr<Results>& rhs)
const
127 const std::size_t lhs_cf = lhs->compressionFactor;
128 const std::size_t rhs_cf = rhs->compressionFactor;
130 if (lhs_cf == rhs_cf) {
133 return lhs->decompLat > rhs->decompLat;
135 return lhs_cf < rhs_cf;
146 std::priority_queue<std::shared_ptr<Results>,
151 auto temp_comp_data =
153 temp_comp_data->setSizeBits(temp_comp_data->getSizeBits() +
155 results.push(std::make_shared<Results>(
i, std::move(temp_comp_data),
157 max_comp_lat = std::max(max_comp_lat, comp_lat);
161 const unsigned best_index = results.top()->index;
162 std::unique_ptr<CompressionData> multi_comp_data =
163 std::unique_ptr<MultiCompData>(
164 new MultiCompData(best_index, std::move(results.top()->compData)));
165 DPRINTF(CacheComp,
"Best compressor: %d\n", best_index);
171 for (
int rank = 0; rank <
compressors.size(); rank++) {
180 return multi_comp_data;
185 uint64_t* cache_line)
190 casted_comp_data->
compData.get(), cache_line);
194 : statistics::
Group(&base_group), compressor(_compressor),
195 ADD_STAT(ranks, statistics::units::Count::get(),
196 "Number of times each compressor had the nth best compression")
205 const std::size_t num_compressors = compressor.compressors.size();
206 ranks.init(num_compressors, num_compressors);
207 for (
unsigned compressor = 0; compressor < num_compressors; compressor++) {
208 ranks.subname(compressor, std::to_string(compressor));
209 ranks.subdesc(compressor,
"Number of times compressor " +
210 std::to_string(compressor) +
" had the nth best compression.");
211 for (
unsigned rank = 0; rank < num_compressors; rank++) {
212 ranks.ysubname(rank, std::to_string(rank));
Cycles is a wrapper class for representing cycle counts, i.e.
void setSizeBits(std::size_t size)
Set compression size (in bits).
Base cache compressor interface.
const Cycles compExtraLatency
Extra latency added to compression due to packaging, shifting or other operations.
void fromChunks(const std::vector< Chunk > &chunks, uint64_t *data) const
This function re-joins the chunks to recreate the original data.
gem5::compression::Base::BaseStats stats
const Cycles decompExtraLatency
Extra latency added to decompression due to packaging, shifting or other operations.
friend class Multi
This compressor must be able to access the protected functions of its sub-compressors.
const std::size_t blkSize
Uncompressed cache line size (in bytes).
virtual void setCache(BaseCache *_cache)
The cache can only be set once.
uint8_t getIndex() const
Get the index of the best compressor.
MultiCompData(unsigned index, std::unique_ptr< Base::CompressionData > comp_data)
Default constructor.
std::unique_ptr< Base::CompressionData > compData
Compression data of the best compressor.
void setCache(BaseCache *_cache) override
The cache can only be set once.
const std::size_t numEncodingBits
An encoding is associated to each sub-compressor to inform which sub-compressor to use when decompres...
MultiCompressorParams Params
std::vector< Base * > compressors
List of sub-compressors.
std::unique_ptr< Base::CompressionData > compress(const std::vector< Base::Chunk > &chunks, Cycles &comp_lat, Cycles &decomp_lat) override
Apply the compression process to the cache line.
gem5::compression::Multi::MultiStats multiStats
void decompress(const CompressionData *comp_data, uint64_t *data) override
Apply the decompression process to the compressed data.
Definition of the a multi compressor that choses the best compression among multiple compressors.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
constexpr uint64_t alignToPowerOfTwo(uint64_t val)
Align to the next highest power of two.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
virtual void regStats()
Callback to set stat parameters.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Overload hash function for BasicBlockRange type.
void regStats() override
Callback to set stat parameters.
MultiStats(BaseStats &base_group, Multi &_compressor)
statistics::Vector2d ranks
Number of times each compressor provided the nth best compression.