BloomFilters.py revision 14262
1# Copyright (c) 2019 Inria 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright 9# notice, this list of conditions and the following disclaimer in the 10# documentation and/or other materials provided with the distribution; 11# neither the name of the copyright holders nor the names of its 12# contributors may be used to endorse or promote products derived from 13# this software without specific prior written permission. 14# 15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26# 27# Authors: Daniel Carvalho 28 29from m5.params import * 30from m5.proxy import * 31from m5.SimObject import SimObject 32 33class BloomFilterBase(SimObject): 34 type = 'BloomFilterBase' 35 abstract = True 36 cxx_header = "base/filters/base.hh" 37 cxx_class = 'BloomFilter::Base' 38 39 size = Param.Int(4096, "Number of entries in the filter") 40 41 # By default assume that bloom filters are used for 64-byte cache lines 42 offset_bits = Param.Unsigned(6, "Number of bits in a cache line offset") 43 44 # Most of the filters are booleans, and thus saturate on 1 45 threshold = Param.Int(1, "Value at which an entry is considered as set") 46 47class BloomFilterBlock(BloomFilterBase): 48 type = 'BloomFilterBlock' 49 cxx_class = 'BloomFilter::Block' 50 cxx_header = "base/filters/block_bloom_filter.hh" 51 52 masks_lsbs = VectorParam.Unsigned([Self.offset_bits, 53 2 * Self.offset_bits], "Position of the LSB of each mask") 54 masks_sizes = VectorParam.Unsigned([Self.offset_bits, Self.offset_bits], 55 "Size, in number of bits, of each mask") 56 57class BloomFilterBulk(BloomFilterBase): 58 type = 'BloomFilterBulk' 59 cxx_class = 'BloomFilter::Bulk' 60 cxx_header = "base/filters/bulk_bloom_filter.hh" 61 62class BloomFilterLSBCounting(BloomFilterBase): 63 type = 'BloomFilterLSBCounting' 64 cxx_class = 'BloomFilter::LSBCounting' 65 cxx_header = "base/filters/lsb_counting_bloom_filter.hh" 66 67 # By default use 4-bit saturating counters 68 max_value = Param.Int(15, "Maximum value of the filter entries") 69 70 # We assume that isSet will return true only when the counter saturates 71 threshold = Self.max_value 72 73class BloomFilterMultiBitSel(BloomFilterBase): 74 type = 'BloomFilterMultiBitSel' 75 cxx_class = 'BloomFilter::MultiBitSel' 76 cxx_header = "base/filters/multi_bit_sel_bloom_filter.hh" 77 78 num_hashes = Param.Int(4, "Number of hashes") 79 threshold = Self.num_hashes 80 skip_bits = Param.Int(2, "Offset from block number") 81 is_parallel = Param.Bool(False, "Whether hashing is done in parallel") 82 83class BloomFilterH3(BloomFilterMultiBitSel): 84 type = 'BloomFilterH3' 85 cxx_class = 'BloomFilter::H3' 86 cxx_header = "base/filters/h3_bloom_filter.hh" 87 88class BloomFilterMulti(BloomFilterBase): 89 type = 'BloomFilterMulti' 90 cxx_class = 'BloomFilter::Multi' 91 cxx_header = "base/filters/multi_bloom_filter.hh" 92 93 # The base filter should not be used, since this filter is the combination 94 # of multiple sub-filters, so we use a dummy value 95 size = 1 96 97 # By default there are two sub-filters that hash sequential bitfields 98 filters = VectorParam.BloomFilterBase([ 99 BloomFilterBlock(size = 4096, masks_lsbs = [6, 12]), 100 BloomFilterBlock(size = 1024, masks_lsbs = [18, 24])], 101 "Sub-filters to be combined") 102 103 # By default match this with the number of sub-filters 104 threshold = 2 105