kerncraft/cacheprediction.py
def _align_iteration_with_cl_boundary(self, iteration, subtract=True):
        """Align iteration with cacheline boundary."""
        # FIXME handle multiple datatypes
        element_size = self.kernel.datatypes_size[self.kernel.datatype]
        cacheline_size = self.machine['cacheline size']
        elements_per_cacheline = int(cacheline_size // element_size)

        # Gathering some loop information:
        inner_loop = list(self.kernel.get_loop_stack(subs_consts=True))[-1]
        inner_increment = inner_loop['increment']

        # do this by aligning either writes (preferred) or reads
        # Assumption: writes (and reads) increase linearly
        o = self.kernel.compile_global_offsets(iteration=iteration)[0]
        if len(o[1]):
            # we have a write to work with:
            first_offset = min(o[1])
        else:
            # we use reads
            first_offset = min(o[0])

        diff = first_offset - \
               (int(first_offset) >> self.csim.first_level.cl_bits << self.csim.first_level.cl_bits)
        if diff == 0:
            return iteration
        elif subtract:
            return iteration - (diff // element_size) // inner_increment
        else:
            return iteration + (elements_per_cacheline - diff // element_size) // inner_increment
def _align_iteration_with_cl_boundary(self, iteration, subtract=True):
        """Align iteration with cacheline boundary."""
        # FIXME handle multiple datatypes
        element_size = self.kernel.datatypes_size[self.kernel.datatype]
        cacheline_size = self.machine['cacheline size']
        elements_per_cacheline = int(cacheline_size // element_size)

        # Gathering some loop information:
        inner_loop = list(self.kernel.get_loop_stack(subs_consts=True))[-1]
        inner_increment = inner_loop['increment']

        # do this by aligning either writes (preferred) or reads
        # Assumption: writes (and reads) increase linearly
        o = self.kernel.compile_global_offsets(iteration=iteration)[0]
        if len(o[1]):
            # we have a write to work with:
            first_offset = min(o[1])
        else:
            # we use reads
            first_offset = min(o[0])

        diff = first_offset - \
               (int(first_offset) >> self.csim.first_level.cl_bits << self.csim.first_level.cl_bits)
        if diff == 0:
            return iteration
        elif subtract:
            return iteration - (diff // element_size) // inner_increment
        else:
            return iteration + (elements_per_cacheline - diff // element_size) // inner_increment
def _align_iteration_with_cl_boundary ( self , iteration , subtract = True ) : # FIXME handle multiple datatypes element_size = self . kernel . datatypes_size [ self . kernel . datatype ] cacheline_size = self . machine [ 'cacheline size' ] elements_per_cacheline = int ( cacheline_size // element_size ) # Gathering some loop information: inner_loop = list ( self . kernel . get_loop_stack ( subs_consts = True ) ) [ - 1 ] inner_increment = inner_loop [ 'increment' ] # do this by aligning either writes (preferred) or reads # Assumption: writes (and reads) increase linearly o = self . kernel . compile_global_offsets ( iteration = iteration ) [ 0 ] if len ( o [ 1 ] ) : # we have a write to work with: first_offset = min ( o [ 1 ] ) else : # we use reads first_offset = min ( o [ 0 ] ) diff = first_offset - ( int ( first_offset ) >> self . csim . first_level . cl_bits << self . csim . first_level . cl_bits ) if diff == 0 : return iteration elif subtract : return iteration - ( diff // element_size ) // inner_increment else : return iteration + ( elements_per_cacheline - diff // element_size ) // inner_increment
Align iteration with cacheline boundary.
Align iteration with cacheline boundary .