<commit_before>"""Handles shared memory usage to accelerate memory accesses for CUDA"""

from math import floor
import CUDAParams
import utils
import os

class variable(object):
    def __init__(self, base, index, lang='cuda'):
        self.base = base
        self.index = index
        self.last_use_count = 0
        self.lang = lang
    def __eq__(self, other):
        return self.base == other.base and self.index == other.index
    def reset(self):
        self.last_use_count = 0
    def update(self):
        self.last_use_count += 1
    def to_string(self):
        return utils.to_string(self.lang, self.base, self.index)

class shared_memory_manager(object):
    def __init__(self, blocks_per_sm=8, num_threads=64, L1_PREFERRED=True):
        SHARED_MEMORY_SIZE = CUDAParams.get_shared_size(L1_PREFERRED)
        self.blocks_per_sm = blocks_per_sm
        self.num_threads = num_threads
        self.skeleton = 'shared_temp[{}]'
        self.shared_dict = {}
        self.shared_per_block = int(floor(SHARED_MEMORY_SIZE / self.blocks_per_sm))
        self.shared_per_thread = int(floor(self.shared_per_block / self.num_threads))
        self.shared_indexes = [True for i in range(self.shared_per_thread)]
        self.eviction_marking = [False for i in range(self.shared_per_thread)]
        self.on_eviction = None
        self.self_eviction_strategy = lambda x: x.last_use_count > 2

    def force_eviction(self):
        for shared_index in self.shared_dict.iterkeys(): 
            self.evict(shared_index)

    def evict_longest_gap(self):
        """evicts the entry that has gone the longest without use"""
        if len(self.shared_dict):
            ind = max(x for x in self.shared_dict if self.mark_for_eviction[x],
                      key=lambda k: self.shared_dict[k].last_use_count)
            self.evict(ind)

    def evict(self, shared_index):
        del self.shared_dict[shared_index]
        self.shared_indexes.append(shared_index)
        self.mark_for_eviction[shared_index] = False
        if self.on_eviction is not None:
            self.on_eviction(var, self.__get_string(shared_index))<commit_msg>slight change to eviction strategy<commit_after>"""Handles shared memory usage to accelerate memory accesses for CUDA"""

from math import floor
import CUDAParams
import utils
import os

class variable(object):
    def __init__(self, base, index, lang='cuda'):
        self.base = base
        self.index = index
        self.last_use_count = 0
        self.lang = lang
    def __eq__(self, other):
        return self.base == other.base and self.index == other.index
    def reset(self):
        self.last_use_count = 0
    def update(self):
        self.last_use_count += 1
    def to_string(self):
        return utils.to_string(self.lang, self.base, self.index)

class shared_memory_manager(object):
    def __init__(self, blocks_per_sm=8, num_threads=64, L1_PREFERRED=True):
        SHARED_MEMORY_SIZE = CUDAParams.get_shared_size(L1_PREFERRED)
        self.blocks_per_sm = blocks_per_sm
        self.num_threads = num_threads
        self.skeleton = 'shared_temp[{}]'
        self.shared_dict = {}
        self.shared_per_block = int(floor(SHARED_MEMORY_SIZE / self.blocks_per_sm))
        self.shared_per_thread = int(floor(self.shared_per_block / self.num_threads))
        self.shared_indexes = [True for i in range(self.shared_per_thread)]
        self.eviction_marking = [False for i in range(self.shared_per_thread)]
        self.on_eviction = None
        self.self_eviction_strategy = lambda x: x.last_use_count >= 2

    def force_eviction(self):
        for shared_index in self.shared_dict.iterkeys(): 
            self.evict(shared_index)

    def evict_longest_gap(self):
        """evicts the entry that has gone the longest without use"""
        if len(self.shared_dict):
            ind = max(x for x in self.shared_dict if self.mark_for_eviction[x],
                      key=lambda k: self.shared_dict[k].last_use_count)
            self.evict(ind)

    def evict(self, shared_index):
        del self.shared_dict[shared_index]
        self.shared_indexes.append(shared_index)
        self.mark_for_eviction[shared_index] = False
        if self.on_eviction is not None:
            self.on_eviction(var, self.__get_string(shared_index))
{'fraction_non_alphanumeric': 0.09228265922826592, 'fraction_numerical': 0.0041841004184100415, 'mean_word_length': 2.9586016559337627, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '572990', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1374, 'n_words': 297}