Skip to content

Commit

Permalink
Fix unnowkn function problem
Browse files Browse the repository at this point in the history
  • Loading branch information
joscao committed Oct 27, 2023
1 parent 7d08953 commit d9b97aa
Showing 1 changed file with 55 additions and 43 deletions.
98 changes: 55 additions & 43 deletions example/06_array_data_dependency_detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"[Loki::Sourcefile] Constructed from src/phys_mod.F90 in 1.64s\n"
"[Loki::Sourcefile] Constructed from src/phys_mod.F90 in 1.40s\n"
]
}
],
Expand Down Expand Up @@ -127,7 +127,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Extracting the iteration space is an easy process. We know that all our assignments which are worth comparing are inside the deepest loop body therfore simply collecting all nested loops is enough and transforming them via the polyhedron utility into the required inequality relation. For a more complex situation view further down \"Collecting access in different loop bodies\""
"Additionaly we create a small loop extractor, selecting the loops based on their nested structure."
]
},
{
Expand All @@ -136,18 +136,39 @@
"metadata": {},
"outputs": [],
"source": [
"from loki.analyse.analyse_dependency_detection import get_nested_loops\n",
"from loki import FindNodes, Loop\n",
"\n",
"\n",
"def simple_loop_extractor(start_node):\n",
" \"\"\"Find all loops in the AST and structure them depending on their nesting level\"\"\"\n",
" start_loops = FindNodes(Loop, greedy=True).visit(start_node)\n",
" return [FindNodes(Loop).visit(node) for node in start_loops]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Extracting the iteration space is an easy process. We know that all our assignments which are worth comparing are inside the deepest loop body therfore simply collecting all nested loops is enough and transforming them via the polyhedron utility into the required inequality relation. For a more complex situation view further down \"Collecting access in different loop bodies\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from loki.analyse.util_polyhedron import Polyhedron\n",
"\n",
"nested_loops = list(get_nested_loops(routine.body))\n",
"nested_loops = list(simple_loop_extractor(routine.body)[0])\n",
"poly = Polyhedron.from_nested_loops(nested_loops)\n",
"B, b = poly.A, as_column(poly.b)\n",
"iteration_space_required_variables = list(str(v) for v in poly.variables)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -175,7 +196,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -214,15 +235,15 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from loki.analyse.analyse_dependency_detection import (\n",
"from loki.analyse.analyse_array_data_dependency_detection import (\n",
" construct_affine_array_access_function_representation,\n",
")\n",
"\n",
"F, f, access_variables = construct_affine_array_access_function_representation(\n",
"first_access_function, access_variables = construct_affine_array_access_function_representation(\n",
" first_assignement.lhs.dimensions, iteration_space_required_variables\n",
")"
]
Expand All @@ -236,7 +257,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand All @@ -252,7 +273,7 @@
}
],
"source": [
"pprint_equation(F, \"*\", as_column(access_variables), \"+\", f, \"=\", 0)"
"pprint_equation(first_access_function.matrix, \"*\", as_column(access_variables), \"+\", first_access_function.vector, \"=\", 0)"
]
},
{
Expand All @@ -264,13 +285,12 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"(\n",
" F_dash,\n",
" f_dash,\n",
" second_access_function,\n",
" access_variables_dash,\n",
") = construct_affine_array_access_function_representation(\n",
" second_assignment.rhs.dimensions, iteration_space_required_variables\n",
Expand All @@ -288,7 +308,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand All @@ -304,7 +324,7 @@
}
],
"source": [
"pprint_equation(F_dash, \"*\", as_column(access_variables_dash), \"+\", f_dash, \"=\", 0)"
"pprint_equation(second_access_function.matrix, \"*\", as_column(access_variables_dash), \"+\", second_access_function.vector, \"=\", 0)"
]
},
{
Expand All @@ -316,7 +336,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -330,8 +350,8 @@
"source": [
"from loki.analyse.analyse_array_data_dependency_detection import has_data_dependency\n",
"\n",
"first_access_represenetation = ((B, b), (F, f))\n",
"second_access_represenetation = ((B, b), (F_dash, f_dash))\n",
"first_access_represenetation = ((B, b), first_access_function)\n",
"second_access_represenetation = ((B, b), second_access_function)\n",
"\n",
"if has_data_dependency(first_access_represenetation, second_access_represenetation):\n",
" print(\"There is a data dependency between the two accesses.\")\n",
Expand All @@ -356,14 +376,14 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[Loki::Sourcefile] Constructed from ../tests/sources/data_dependency_detection/loop_carried_dependencies.f90 in 0.20s\n"
"[Loki::Sourcefile] Constructed from ../tests/sources/data_dependency_detection/loop_carried_dependencies.f90 in 0.19s\n"
]
}
],
Expand All @@ -377,7 +397,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -407,7 +427,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -421,7 +441,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand All @@ -442,7 +462,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -476,7 +496,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -504,7 +524,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"outputs": [
{
Expand All @@ -516,16 +536,16 @@
}
],
"source": [
"F, f, access_variables = construct_affine_array_access_function_representation(\n",
"first_access, access_variables = construct_affine_array_access_function_representation(\n",
" first_assignement.lhs.dimensions, iteration_space_required_variables\n",
")\n",
"\n",
"pprint_equation(F, \"*\", as_column(access_variables), \"+\", f, \"=\", 0)"
"pprint_equation(first_access.matrix, \"*\", as_column(access_variables), \"+\", first_access.vector, \"=\", 0)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"metadata": {},
"outputs": [
{
Expand All @@ -538,16 +558,15 @@
],
"source": [
"(\n",
" F_dash,\n",
" f_dash,\n",
" second_access,\n",
" access_variables_dash,\n",
") = construct_affine_array_access_function_representation(\n",
" second_assignment.lhs.dimensions, iteration_space_required_variables\n",
")\n",
"\n",
"assert access_variables == access_variables_dash\n",
"\n",
"pprint_equation(F_dash, \"*\", as_column(access_variables_dash), \"+\", f_dash, \"=\", 0)"
"pprint_equation(second_access.matrix, \"*\", as_column(access_variables_dash), \"+\", second_access.vector, \"=\", 0)"
]
},
{
Expand All @@ -559,7 +578,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand All @@ -571,21 +590,14 @@
}
],
"source": [
"first_access_represenetation = ((B, b), (F, f))\n",
"second_access_represenetation = ((B_dash, b_dash), (F_dash, f_dash))\n",
"first_access_represenetation = ((B, b), first_access)\n",
"second_access_represenetation = ((B_dash, b_dash), second_access)\n",
"\n",
"if has_data_dependency(first_access_represenetation, second_access_represenetation):\n",
" print(\"There is a data dependency between the two accesses.\")\n",
"else:\n",
" print(\"There is no data dependency between the two accesses.\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit d9b97aa

Please sign in to comment.