1/* 2 * Copyright (c) 2018 Inria 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Daniel Carvalho 29 */ 30 31/** @file 32 * Definition of a basic cache compressor. 33 * A cache compressor must consist of a compression and a decompression 34 * methods. It must also be aware of the size of an uncompressed cache 35 * line. 36 */ 37 38#ifndef __MEM_CACHE_COMPRESSORS_BASE_HH__ 39#define __MEM_CACHE_COMPRESSORS_BASE_HH__ 40 41#include <cstdint> 42
| 1/* 2 * Copyright (c) 2018 Inria 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Daniel Carvalho 29 */ 30 31/** @file 32 * Definition of a basic cache compressor. 33 * A cache compressor must consist of a compression and a decompression 34 * methods. It must also be aware of the size of an uncompressed cache 35 * line. 36 */ 37 38#ifndef __MEM_CACHE_COMPRESSORS_BASE_HH__ 39#define __MEM_CACHE_COMPRESSORS_BASE_HH__ 40 41#include <cstdint> 42
|
| 43#include "base/statistics.hh"
|
43#include "base/types.hh" 44#include "sim/sim_object.hh" 45 46class CacheBlk; 47struct BaseCacheCompressorParams; 48 49/** 50 * Base cache compressor interface. Every cache compressor must implement a 51 * compression and a decompression method. 52 */ 53class BaseCacheCompressor : public SimObject { 54 protected: 55 /** 56 * Forward declaration of compression data. Every new compressor must 57 * create a new compression data based on it. 58 */ 59 class CompressionData; 60 61 /** 62 * Uncompressed cache line size (in bytes). 63 */ 64 const std::size_t blkSize; 65 66 /**
| 44#include "base/types.hh" 45#include "sim/sim_object.hh" 46 47class CacheBlk; 48struct BaseCacheCompressorParams; 49 50/** 51 * Base cache compressor interface. Every cache compressor must implement a 52 * compression and a decompression method. 53 */ 54class BaseCacheCompressor : public SimObject { 55 protected: 56 /** 57 * Forward declaration of compression data. Every new compressor must 58 * create a new compression data based on it. 59 */ 60 class CompressionData; 61 62 /** 63 * Uncompressed cache line size (in bytes). 64 */ 65 const std::size_t blkSize; 66 67 /**
|
| 68 * @defgroup CompressionStats Compression specific statistics. 69 * @{ 70 */ 71 72 /** Number of blocks that were compressed to this power of two size. */ 73 Stats::Vector compressionSize; 74 75 /** 76 * @} 77 */ 78 79 /**
|
67 * Apply the compression process to the cache line. 68 * Returns the number of cycles used by the compressor, however it is 69 * usually covered by a good pipelined execution, and is currently ignored. 70 * The decompression latency is also returned, in order to avoid 71 * increasing simulation time and memory consumption. 72 * 73 * @param cache_line The cache line to be compressed. 74 * @param comp_lat Compression latency in number of cycles. 75 * @param decomp_lat Decompression latency in number of cycles. 76 * @return Cache line after compression. 77 */ 78 virtual std::unique_ptr<CompressionData> compress( 79 const uint64_t* cache_line, Cycles& comp_lat, Cycles& decomp_lat) = 0; 80 81 /** 82 * Apply the decompression process to the compressed data. 83 * 84 * @param comp_data Compressed cache line. 85 * @param cache_line The cache line to be decompressed. 86 */ 87 virtual void decompress(const CompressionData* comp_data, 88 uint64_t* cache_line) = 0; 89 90 public: 91 /** Convenience typedef. */ 92 typedef BaseCacheCompressorParams Params; 93 94 /** 95 * Default constructor. 96 */ 97 BaseCacheCompressor(const Params *p); 98 99 /** 100 * Default destructor. 101 */ 102 virtual ~BaseCacheCompressor() {}; 103 104 /** 105 * Apply the compression process to the cache line. Ignores compression 106 * cycles. 107 * 108 * @param data The cache line to be compressed. 109 * @param comp_lat Compression latency in number of cycles. 110 * @param decomp_lat Decompression latency in number of cycles. 111 * @param comp_size_bits Compressed data size (in bits). 112 */ 113 void compress(const uint64_t* data, Cycles& comp_lat, 114 Cycles& decomp_lat, std::size_t& comp_size_bits); 115 116 /** 117 * Get the decompression latency if the block is compressed. Latency is 0 118 * otherwise. 119 * 120 * @param blk The compressed block. 121 */ 122 static Cycles getDecompressionLatency(const CacheBlk* blk); 123 124 /** 125 * Set the decompression latency of compressed block. 126 * 127 * @param blk The compressed block. 128 * @param lat The decompression latency. 129 */ 130 static void setDecompressionLatency(CacheBlk* blk, const Cycles lat); 131 132 /** 133 * Set the size of the compressed block, in bits. 134 * 135 * @param blk The compressed block. 136 * @param size_bits The block size. 137 */ 138 static void setSizeBits(CacheBlk* blk, const std::size_t size_bits);
| 80 * Apply the compression process to the cache line. 81 * Returns the number of cycles used by the compressor, however it is 82 * usually covered by a good pipelined execution, and is currently ignored. 83 * The decompression latency is also returned, in order to avoid 84 * increasing simulation time and memory consumption. 85 * 86 * @param cache_line The cache line to be compressed. 87 * @param comp_lat Compression latency in number of cycles. 88 * @param decomp_lat Decompression latency in number of cycles. 89 * @return Cache line after compression. 90 */ 91 virtual std::unique_ptr<CompressionData> compress( 92 const uint64_t* cache_line, Cycles& comp_lat, Cycles& decomp_lat) = 0; 93 94 /** 95 * Apply the decompression process to the compressed data. 96 * 97 * @param comp_data Compressed cache line. 98 * @param cache_line The cache line to be decompressed. 99 */ 100 virtual void decompress(const CompressionData* comp_data, 101 uint64_t* cache_line) = 0; 102 103 public: 104 /** Convenience typedef. */ 105 typedef BaseCacheCompressorParams Params; 106 107 /** 108 * Default constructor. 109 */ 110 BaseCacheCompressor(const Params *p); 111 112 /** 113 * Default destructor. 114 */ 115 virtual ~BaseCacheCompressor() {}; 116 117 /** 118 * Apply the compression process to the cache line. Ignores compression 119 * cycles. 120 * 121 * @param data The cache line to be compressed. 122 * @param comp_lat Compression latency in number of cycles. 123 * @param decomp_lat Decompression latency in number of cycles. 124 * @param comp_size_bits Compressed data size (in bits). 125 */ 126 void compress(const uint64_t* data, Cycles& comp_lat, 127 Cycles& decomp_lat, std::size_t& comp_size_bits); 128 129 /** 130 * Get the decompression latency if the block is compressed. Latency is 0 131 * otherwise. 132 * 133 * @param blk The compressed block. 134 */ 135 static Cycles getDecompressionLatency(const CacheBlk* blk); 136 137 /** 138 * Set the decompression latency of compressed block. 139 * 140 * @param blk The compressed block. 141 * @param lat The decompression latency. 142 */ 143 static void setDecompressionLatency(CacheBlk* blk, const Cycles lat); 144 145 /** 146 * Set the size of the compressed block, in bits. 147 * 148 * @param blk The compressed block. 149 * @param size_bits The block size. 150 */ 151 static void setSizeBits(CacheBlk* blk, const std::size_t size_bits);
|
| 152 153 /** 154 * Register local statistics. 155 */ 156 void regStats() override;
|
139}; 140 141class BaseCacheCompressor::CompressionData { 142 private: 143 /** 144 * Compressed cache line size (in bits). 145 */ 146 std::size_t _size; 147 148 public: 149 /** 150 * Default constructor. 151 */ 152 CompressionData(); 153 154 /** 155 * Virtual destructor. Without it unique_ptr will cause mem leak. 156 */ 157 virtual ~CompressionData(); 158 159 /** 160 * Set compression size (in bits). 161 * 162 * @param size Compressed data size. 163 */ 164 void setSizeBits(std::size_t size); 165 166 /** 167 * Get compression size (in bits). 168 * 169 * @return Compressed data size. 170 */ 171 std::size_t getSizeBits() const; 172 173 /** 174 * Get compression size (in bytes). 175 * 176 * @return Compressed data size. 177 */ 178 std::size_t getSize() const; 179}; 180 181#endif //__MEM_CACHE_COMPRESSORS_BASE_HH__
| 157}; 158 159class BaseCacheCompressor::CompressionData { 160 private: 161 /** 162 * Compressed cache line size (in bits). 163 */ 164 std::size_t _size; 165 166 public: 167 /** 168 * Default constructor. 169 */ 170 CompressionData(); 171 172 /** 173 * Virtual destructor. Without it unique_ptr will cause mem leak. 174 */ 175 virtual ~CompressionData(); 176 177 /** 178 * Set compression size (in bits). 179 * 180 * @param size Compressed data size. 181 */ 182 void setSizeBits(std::size_t size); 183 184 /** 185 * Get compression size (in bits). 186 * 187 * @return Compressed data size. 188 */ 189 std::size_t getSizeBits() const; 190 191 /** 192 * Get compression size (in bytes). 193 * 194 * @return Compressed data size. 195 */ 196 std::size_t getSize() const; 197}; 198 199#endif //__MEM_CACHE_COMPRESSORS_BASE_HH__
|