43#include "debug/CacheComp.hh"
46#include "params/BaseCacheCompressor.hh"
81 return std::ceil(_size/(
float)CHAR_BIT);
94 "64 must be a multiple of the chunk granularity.");
97 "Compressor processes more chunks per cycle than the number of "
98 "chunks in the input");
100 "Decompressor processes more chunks per cycle than the number of "
101 "chunks in the input");
117 const unsigned num_chunks_per_64 =
122 for (
int i = 0;
i < chunks.size();
i++) {
123 const int index_64 = std::floor(
i / (
double)num_chunks_per_64);
124 const unsigned start =
i % num_chunks_per_64;
136 const unsigned num_chunks_per_64 =
141 for (
int i = 0;
i < chunks.size();
i++) {
142 const int index_64 = std::floor(
i / (
double)num_chunks_per_64);
143 const unsigned start =
i % num_chunks_per_64;
149std::unique_ptr<Base::CompressionData>
153 std::unique_ptr<CompressionData> comp_data =
158 #ifdef DEBUG_COMPRESSION
159 uint64_t decomp_data[
blkSize/8];
166 "Decompressed line does not match original line.");
171 std::size_t comp_size_bits = comp_data->getSizeBits();
173 comp_size_bits =
blkSize * CHAR_BIT;
174 comp_data->setSizeBits(comp_size_bits);
181 if (comp_size_bits != 0) {
188 DPRINTF(CacheComp,
"Compressed cache line from %d to %d bits. " \
189 "Compression latency: %llu, decompression latency: %llu\n",
190 blkSize*8, comp_size_bits, comp_lat, decomp_lat);
203 DPRINTF(CacheComp,
"Decompressing block: %s (%d cycles)\n",
204 comp_blk->
print(), decomp_lat);
217 assert(blk !=
nullptr);
227 assert(blk !=
nullptr);
234 : statistics::
Group(&_compressor), compressor(_compressor),
235 ADD_STAT(compressions, statistics::units::Count::get(),
236 "Total number of compressions"),
237 ADD_STAT(failedCompressions, statistics::units::Count::get(),
238 "Total number of failed compressions"),
239 ADD_STAT(compressionSize, statistics::units::Count::get(),
240 "Number of blocks that were compressed to this power of two "
242 ADD_STAT(compressionSizeBits, statistics::units::Bit::get(),
243 "Total compressed data size"),
244 ADD_STAT(avgCompressionSizeBits, statistics::units::Rate<
245 statistics::units::Bit, statistics::units::Count>::get(),
246 "Average compression size"),
247 ADD_STAT(decompressions, statistics::units::Count::get(),
248 "Total number of decompressions")
258 compressionSize.init(std::log2(compressor.blkSize*8) + 2);
259 compressionSize.subname(0,
"0");
260 compressionSize.subdesc(0,
261 "Number of blocks that compressed to fit in 0 bits");
262 for (
unsigned i = 0;
i <= std::log2(compressor.blkSize*8); ++
i) {
263 std::string str_i = std::to_string(1 <<
i);
264 compressionSize.subname(1+
i, str_i);
265 compressionSize.subdesc(1+
i,
266 "Number of blocks that compressed to fit in " + str_i +
" bits");
271 avgCompressionSizeBits = compressionSizeBits / compressions;
A superblock is composed of sub-blocks, and each sub-block has information regarding its superblock a...
std::string print() const override
Pretty-print sector offset and other CacheBlk information.
bool isCompressed() const
Check if this block holds compressed data.
Cycles getDecompressionLatency() const
Get number of cycles needed to decompress this block.
Cycles is a wrapper class for representing cycle counts, i.e.
Abstract superclass for simulation objects.
virtual ~CompressionData()
Virtual destructor.
CompressionData()
Default constructor.
std::size_t getSize() const
Get compression size (in bytes).
void setSizeBits(std::size_t size)
Set compression size (in bits).
std::size_t getSizeBits() const
Get compression size (in bits).
Base cache compressor interface.
const Cycles compExtraLatency
Extra latency added to compression due to packaging, shifting or other operations.
BaseCacheCompressorParams Params
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
BaseCache * cache
Pointer to the parent cache.
std::vector< Chunk > toChunks(const uint64_t *data) const
This function splits the raw data into chunks, so that it can be parsed by the compressor.
const Cycles decompExtraLatency
Extra latency added to decompression due to packaging, shifting or other operations.
const Cycles compChunksPerCycle
Degree of parallelization of the compression process.
Cycles getDecompressionLatency(const CacheBlk *blk)
Get the decompression latency if the block is compressed.
static void setSizeBits(CacheBlk *blk, const std::size_t size_bits)
Set the size of the compressed block, in bits.
const std::size_t blkSize
Uncompressed cache line size (in bytes).
virtual void setCache(BaseCache *_cache)
The cache can only be set once.
virtual void decompress(const CompressionData *comp_data, uint64_t *cache_line)=0
Apply the decompression process to the compressed data.
const unsigned chunkSizeBits
Chunk size, in number of bits.
const std::size_t sizeThreshold
Size in bytes at which a compression is classified as bad and therefore the compressed block is resto...
static void setDecompressionLatency(CacheBlk *blk, const Cycles lat)
Set the decompression latency of compressed block.
virtual std::unique_ptr< CompressionData > compress(const std::vector< Chunk > &chunks, Cycles &comp_lat, Cycles &decomp_lat)=0
Apply the compression process to the cache line.
const Cycles decompChunksPerCycle
Degree of parallelization of the decompression process.
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
constexpr void replaceBits(T &val, unsigned first, unsigned last, B bit_val)
A convenience function to replace bits first to last of val with bit_val in place.
#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.
Declares a basic cache interface BaseCache.
Definition of a basic cache compressor.
const FlagsType nonan
Don't print if this is NAN.
const FlagsType nozero
Don't print if this is zero.
const FlagsType total
Print the total.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
statistics::Scalar compressions
Number of compressions performed.
void regStats() override
Callback to set stat parameters.
BaseStats(Base &compressor)
statistics::Scalar decompressions
Number of decompressions performed.
statistics::Vector compressionSize
Number of blocks that were compressed to this power of two size.
statistics::Scalar failedCompressions
Number of failed compressions.
statistics::Scalar compressionSizeBits
Total compressed data size, in number of bits.
Copyright (c) 2018 Inria All rights reserved.