def get_pattern_matches(self, permissive=False, states=None, patterns=None, sdfg=None, options=None) -> Iterator[PatternTransformation]: """ Returns all possible transformations for the current SDFG. :param permissive: Consider transformations in permissive mode. :param states: An iterable of SDFG states to consider when pattern matching. If None, considers all. :param patterns: An iterable of transformation classes to consider when matching. If None, considers all registered transformations in ``PatternTransformation``. :param sdfg: If not None, searches for patterns on given SDFG. :param options: An optional iterable of transformation parameters. :return: List of matching ``PatternTransformation`` objects. :see: PatternTransformation. """ sdfg = sdfg or self.sdfg patterns = patterns or self.patterns yield from pattern_matching.match_patterns(sdfg, patterns, metadata=self.transformation_metadata, permissive=permissive, states=states, options=options)
def get_pattern_matches(self, strict=False, states=None, patterns=None, sdfg=None) -> Iterator[Transformation]: """ Returns all possible transformations for the current SDFG. :param strict: Only consider strict transformations (i.e., ones that surely increase performance or enhance readability) :param states: An iterable of SDFG states to consider when pattern matching. If None, considers all. :param patterns: An iterable of transformation classes to consider when matching. If None, considers all registered transformations in ``Transformation``. :param sdfg: If not None, searches for patterns on given SDFG. :return: List of matching ``Transformation`` objects. :see: Transformation. """ sdfg = sdfg or self.sdfg patterns = patterns or self.patterns yield from pattern_matching.match_patterns( sdfg, patterns, metadata=self.transformation_metadata, strict=strict, states=states)
def test_double_buffering(): A = np.random.rand(256, 256).astype(np.float32) B = np.random.rand(256, 256).astype(np.float32) expected_C = A @ B C = np.zeros((256, 256), dtype=np.float32) sdfg = mm_double_buffered.to_sdfg() sdfg(A=A, B=B, C=C) diff = np.linalg.norm(expected_C - C) / (256 * 256) print('Difference (before):', diff) # Apply local storage transformation on inner map (last two transformations) sdfg.apply_strict_transformations() for i in range(2): for match in reversed( list( match_patterns(sdfg, InLocalStorage, states=[sdfg.node(0)]))): match.apply(sdfg) break else: raise ValueError('Local storage transformation not applied') applied = sdfg.apply_transformations(DoubleBuffering) if applied != 1: raise ValueError('Double-buffering transformation not applied') C = np.zeros((256, 256), dtype=np.float32) sdfg(A=A, B=B, C=C) diff2 = np.linalg.norm(expected_C - C) / (256 * 256) print('Difference (after):', diff2) assert (diff <= 1e-5 and diff2 <= 1e-5)
def test(): sdfg = tile_twice_test.to_sdfg() sdfg.apply_strict_transformations() sdfg.apply_transformations(MapTiling, options={'tile_sizes': (5, )}) for i, match in enumerate( match_patterns(sdfg, MapTiling, states=[sdfg.node(0)])): if i == 0: # Match the first map again match.tile_sizes = (4, ) match.apply_pattern(sdfg) A = np.random.rand(200) expected = 2 * A sdfg(a=A) diff = np.linalg.norm(A - expected) print('Difference:', diff) assert diff <= 1e-8