BloomFilters.py revision 14264
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 num_bits = Param.Int(1, "Number of bits in a filter entry") 46 threshold = Param.Int(1, "Value at which an entry is considered as set") 47 48class BloomFilterBlock(BloomFilterBase): 49 type = 'BloomFilterBlock' 50 cxx_class = 'BloomFilter::Block' 51 cxx_header = "base/filters/block_bloom_filter.hh" 52 53 masks_lsbs = VectorParam.Unsigned([Self.offset_bits, 54 2 * Self.offset_bits], "Position of the LSB of each mask") 55 masks_sizes = VectorParam.Unsigned([Self.offset_bits, Self.offset_bits], 56 "Size, in number of bits, of each mask") 57 58class BloomFilterMultiBitSel(BloomFilterBase): 59 type = 'BloomFilterMultiBitSel' 60 cxx_class = 'BloomFilter::MultiBitSel' 61 cxx_header = "base/filters/multi_bit_sel_bloom_filter.hh" 62 63 num_hashes = Param.Int(4, "Number of hashes") 64 threshold = Self.num_hashes 65 skip_bits = Param.Int(2, "Offset from block number") 66 is_parallel = Param.Bool(False, "Whether hashing is done in parallel") 67 68class BloomFilterBulk(BloomFilterMultiBitSel): 69 type = 'BloomFilterBulk' 70 cxx_class = 'BloomFilter::Bulk' 71 cxx_header = "base/filters/bulk_bloom_filter.hh" 72 73class BloomFilterH3(BloomFilterMultiBitSel): 74 type = 'BloomFilterH3' 75 cxx_class = 'BloomFilter::H3' 76 cxx_header = "base/filters/h3_bloom_filter.hh" 77 78class BloomFilterMulti(BloomFilterBase): 79 type = 'BloomFilterMulti' 80 cxx_class = 'BloomFilter::Multi' 81 cxx_header = "base/filters/multi_bloom_filter.hh" 82 83 # The base filter should not be used, since this filter is the combination 84 # of multiple sub-filters, so we use a dummy value 85 size = 1 86 87 # By default there are two sub-filters that hash sequential bitfields 88 filters = VectorParam.BloomFilterBase([ 89 BloomFilterBlock(size = 4096, masks_lsbs = [6, 12]), 90 BloomFilterBlock(size = 1024, masks_lsbs = [18, 24])], 91 "Sub-filters to be combined") 92 93 # By default match this with the number of sub-filters 94 threshold = 2 95