Exemple #1
0
from pattern import parse_str as parse_pattern
from instance import create_instance
from constant_assignment import VariableMap

code = """
declare A[100][100];
declare B[100][100];

for [(i, >=10, <=90), (j, >=10, <=90)] {
  A[i][j] = A[i-1][j-1] + 5;
}
"""

pattern = parse_pattern(code)
print(pattern.pprint())

instance = create_instance(pattern, VariableMap())
print(instance.pprint())

from dependence_analysis import analyze_dependence, calculate_distance_vectors

graph, annotated_instance = analyze_dependence(instance.pattern)
calculate_distance_vectors(graph)
print(graph.pprint())
Exemple #2
0
from pattern import parse_str as parse_pattern
from populator import PopulateParameters, populate_name

matmul_code = """
declare A[][];
declare B[][];
declare C[][];

for [i, j, k] {
  A[`x:index`][`y:index`] =
      A[`x:index`][`y:index`] +
      `_:array`[`x:index`][k] * `_:array`[k][`y:index`];
}
"""

skeleton = parse_skeleton(matmul_code)
print(skeleton.pprint())

array_choices = [Var('A'), Var('B'), Var('C')]
index_choices = [Var('i'), Var('j')]

populator = PopulateParameters()
populator.add('array', array_choices)
populator.add('index', index_choices)

maybe_pattern = populate_name(skeleton.clone(), populator.populate)
maybe_pattern_code = maybe_pattern.pprint()
pattern = parse_pattern(maybe_pattern_code)
print(pattern.pprint())

Exemple #3
0
    ]
    parameters = PopulateParameters()
    parameters.add('_', [parse_stmt(code) for code in stmt_codes])

    filled_skeleton = populate_stmt(skeleton, parameters.populate)
    print(filled_skeleton.pprint())
    return filled_skeleton


full_skeleton = create_full_skeleton()

# Get the string representation of the skeleton.
full_skeleton_str = full_skeleton.pprint()

# A skeleton that still has holes would fail while parsing.
pattern = parse_pattern(full_skeleton_str)

# The string representation of a pattern matches that of a
# full skeleton, but it's represented with a different AST
# in memory. A pattern is used to create an instance, which
# has more useful information to generate runnable code.
print(pattern.pprint())

# Here's another example, parsing a pattern directly from source
pattern_code = """
declare A[];
for [i] {
  A[i] = 0;
}
"""
pattern2 = parse_pattern(pattern_code)