-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(closes #1010) Generate PSy-layers and Kernel Subs using PSyIR lowering (instead of gen_code/f2pygen) #2834
base: master
Are you sure you want to change the base?
Changes from 106 commits
bc49de6
a3e1b35
e864bc2
df68488
cd515be
0b90f7b
96c1aa6
5c74c42
e661950
64a6bfd
6c55316
93f88f3
77fe7ff
99ffbbe
99422e6
9be02af
2481022
decd073
0e05a0b
ef34fa1
62e41e5
8908239
930ddb9
a2942f1
cf63302
3d8969c
98a899c
ddef4de
b697236
6ab2c8c
bbb31da
6bf1383
6787c5e
960855f
0d0d8e3
0cdb879
4c74023
5c08043
35180f8
2a556b2
990afa5
46eee5c
d3dab2d
3ac82c5
e8bfe66
d83f380
8183b8a
55a4eaa
225d346
17f6749
84f96e3
c9938f3
50ad16c
3cc4589
c719f11
f0c87d2
d398ed2
2a3fe85
b0d5e98
009006f
14e0b23
eee5c9c
e3d2f2e
501655a
82d8706
a5c50fd
b134171
300afee
08e9221
a0d5e2f
0fb3098
1f97c15
cfcc44d
39c3037
9edd419
298fa90
ea78b6f
cf32395
9558dc4
43a0e83
d1ab352
7cae96a
ecd20d3
b81e2ed
b3a3d82
dbac36c
5a7b0a6
36af0bf
abc2feb
0ffbb70
65afad9
c754874
713a758
bbf58ab
f3d3574
b7cb593
7d3ab2a
b9a64c1
9ff9eae
dc1c142
3ab9c4d
852a826
1dd394e
5d7d712
5dc9ec0
e90cbcf
3a4b983
3a18bb3
cd18e86
6ddb65e
c345f0a
9ec3f54
57db171
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ | |
ArrayReference, Reference, StructureReference) | ||
from psyclone.psyir.symbols import ( | ||
DataSymbol, DataTypeSymbol, UnresolvedType, ContainerSymbol, | ||
ImportInterface, ScalarType) | ||
ImportInterface, ScalarType, ArrayType) | ||
|
||
# psyir has classes created at runtime | ||
# pylint: disable=no-member | ||
|
@@ -138,9 +138,9 @@ def get_user_type(self, module_name, user_type, name, tag=None): | |
interface=ImportInterface(module)) | ||
# Declare the actual user symbol in the local symbol table, using | ||
# the datatype from the root table: | ||
sym = self._symtab.new_symbol(name, tag=tag, | ||
symbol_type=DataSymbol, | ||
datatype=user_type_symbol) | ||
sym = self._symtab.find_or_create(name, tag=tag, | ||
symbol_type=DataSymbol, | ||
datatype=user_type_symbol) | ||
return sym | ||
|
||
def append_structure_reference(self, module_name, user_type, member_list, | ||
|
@@ -207,8 +207,7 @@ def cell_map(self, var_accesses=None): | |
|
||
# Add the cell map to our argument list | ||
cell_ref_name, cell_ref = self.cell_ref_name(var_accesses) | ||
sym = self.append_array_reference(base_name, [":", ":", cell_ref], | ||
ScalarType.Intrinsic.INTEGER) | ||
sym = self.append_array_reference(base_name, [":", ":", cell_ref]) | ||
self.append(f"{sym.name}(:,:,{cell_ref_name})", | ||
var_accesses=var_accesses, var_access_name=sym.name) | ||
|
||
|
@@ -426,7 +425,6 @@ def stencil_unknown_extent(self, arg, var_accesses=None): | |
var_sym = LFRicStencils.dofmap_size_symbol(self._symtab, arg) | ||
cell_name, cell_ref = self.cell_ref_name(var_accesses) | ||
self.append_array_reference(var_sym.name, [cell_ref], | ||
ScalarType.Intrinsic.INTEGER, | ||
symbol=var_sym) | ||
self.append(f"{var_sym.name}({cell_name})", var_accesses, | ||
var_access_name=var_sym.name) | ||
|
@@ -451,7 +449,6 @@ def stencil_2d_unknown_extent(self, arg, var_accesses=None): | |
var_sym = LFRicStencils.dofmap_size_symbol(self._symtab, arg) | ||
cell_name, cell_ref = self.cell_ref_name(var_accesses) | ||
self.append_array_reference(var_sym.name, [":", cell_ref], | ||
ScalarType.Intrinsic.INTEGER, | ||
symbol=var_sym) | ||
name = f"{var_sym.name}(:,{cell_name})" | ||
self.append(name, var_accesses, var_access_name=var_sym.name) | ||
|
@@ -523,7 +520,6 @@ def stencil(self, arg, var_accesses=None): | |
var_sym = LFRicStencils.dofmap_symbol(self._symtab, arg) | ||
cell_name, cell_ref = self.cell_ref_name(var_accesses) | ||
self.append_array_reference(var_sym.name, [":", ":", cell_ref], | ||
ScalarType.Intrinsic.INTEGER, | ||
symbol=var_sym) | ||
self.append(f"{var_sym.name}(:,:,{cell_name})", var_accesses, | ||
var_access_name=var_sym.name) | ||
|
@@ -556,7 +552,6 @@ def stencil_2d(self, arg, var_accesses=None): | |
cell_name, cell_ref = self.cell_ref_name(var_accesses) | ||
self.append_array_reference(var_sym.name, | ||
[":", ":", ":", cell_ref], | ||
ScalarType.Intrinsic.INTEGER, | ||
symbol=var_sym) | ||
name = f"{var_sym.name}(:,:,:,{cell_name})" | ||
self.append(name, var_accesses, var_access_name=var_sym.name) | ||
|
@@ -642,14 +637,12 @@ def fs_compulsory_field(self, function_space, var_accesses=None): | |
if self._kern.iterates_over == 'domain': | ||
# This kernel takes responsibility for iterating over cells so | ||
# pass the whole dofmap. | ||
sym = self.append_array_reference(map_name, [":", ":"], | ||
ScalarType.Intrinsic.INTEGER) | ||
sym = self.append_array_reference(map_name, [":", ":"]) | ||
self.append(sym.name, var_accesses, var_access_name=sym.name) | ||
else: | ||
# Pass the dofmap for the cell column | ||
cell_name, cell_ref = self.cell_ref_name(var_accesses) | ||
sym = self.append_array_reference(map_name, [":", cell_ref], | ||
ScalarType.Intrinsic.INTEGER) | ||
sym = self.append_array_reference(map_name, [":", cell_ref]) | ||
self.append(f"{sym.name}(:,{cell_name})", | ||
var_accesses, var_access_name=sym.name) | ||
|
||
|
@@ -675,8 +668,7 @@ def fs_intergrid(self, function_space, var_accesses=None): | |
sym = self.append_integer_reference(function_space.undf_name) | ||
self.append(sym.name, var_accesses) | ||
map_name = function_space.map_name | ||
sym = self.append_array_reference(map_name, [":", ":"], | ||
ScalarType.Intrinsic.INTEGER) | ||
sym = self.append_array_reference(map_name, [":", ":"]) | ||
self.append(sym.name, var_accesses) | ||
else: | ||
# For the coarse mesh we only need undf and the dofmap for | ||
|
@@ -699,8 +691,10 @@ def basis(self, function_space, var_accesses=None): | |
''' | ||
for rule in self._kern.qr_rules.values(): | ||
basis_name = function_space.get_basis_name(qr_var=rule.psy_name) | ||
sym = self.append_array_reference(basis_name, [":", ":", ":", ":"], | ||
ScalarType.Intrinsic.REAL) | ||
sym = self.append_array_reference( | ||
basis_name, [":", ":", ":", ":"], | ||
LFRicTypes("LFRicRealScalarDataType")() | ||
) | ||
self.append(sym.name, var_accesses) | ||
|
||
if "gh_evaluator" in self._kern.eval_shapes: | ||
|
@@ -712,8 +706,7 @@ def basis(self, function_space, var_accesses=None): | |
# function space | ||
fspace = self._kern.eval_targets[fs_name][0] | ||
basis_name = function_space.get_basis_name(on_space=fspace) | ||
sym = self.append_array_reference(basis_name, [":", ":", ":"], | ||
ScalarType.Intrinsic.REAL) | ||
sym = self.append_array_reference(basis_name, [":", ":", ":"]) | ||
self.append(sym.name, var_accesses) | ||
|
||
def diff_basis(self, function_space, var_accesses=None): | ||
|
@@ -733,9 +726,11 @@ def diff_basis(self, function_space, var_accesses=None): | |
for rule in self._kern.qr_rules.values(): | ||
diff_basis_name = function_space.get_diff_basis_name( | ||
qr_var=rule.psy_name) | ||
sym = self.append_array_reference(diff_basis_name, | ||
[":", ":", ":", ":"], | ||
ScalarType.Intrinsic.REAL) | ||
sym = self.append_array_reference( | ||
diff_basis_name, | ||
[":", ":", ":", ":"], | ||
LFRicTypes("LFRicRealScalarDataType")() | ||
) | ||
self.append(sym.name, var_accesses) | ||
|
||
if "gh_evaluator" in self._kern.eval_shapes: | ||
|
@@ -748,9 +743,10 @@ def diff_basis(self, function_space, var_accesses=None): | |
fspace = self._kern.eval_targets[fs_name][0] | ||
diff_basis_name = function_space.get_diff_basis_name( | ||
on_space=fspace) | ||
sym = self.append_array_reference(diff_basis_name, | ||
[":", ":", ":"], | ||
ScalarType.Intrinsic.REAL) | ||
sym = self.append_array_reference( | ||
diff_basis_name, | ||
[":", ":", ":"], | ||
LFRicTypes("LFRicRealScalarDataType")()) | ||
self.append(sym.name, var_accesses) | ||
|
||
def field_bcs_kernel(self, function_space, var_accesses=None): | ||
|
@@ -784,8 +780,7 @@ def field_bcs_kernel(self, function_space, var_accesses=None): | |
f"{self._kern.name} but got '{farg.argument_type}'") | ||
|
||
base_name = "boundary_dofs_" + farg.name | ||
sym = self.append_array_reference(base_name, [":", ":"], | ||
ScalarType.Intrinsic.INTEGER) | ||
sym = self.append_array_reference(base_name, [":", ":"]) | ||
self.append(sym.name, var_accesses) | ||
|
||
def operator_bcs_kernel(self, function_space, var_accesses=None): | ||
|
@@ -805,8 +800,7 @@ def operator_bcs_kernel(self, function_space, var_accesses=None): | |
# Checks for this are performed in ArgOrdering.generate() | ||
op_arg = self._kern.arguments.args[0] | ||
base_name = "boundary_dofs_" + op_arg.name | ||
sym = self.append_array_reference(base_name, [":", ":"], | ||
ScalarType.Intrinsic.INTEGER) | ||
sym = self.append_array_reference(base_name, [":", ":"]) | ||
self.append(sym.name, var_accesses) | ||
|
||
def mesh_properties(self, var_accesses=None): | ||
|
@@ -878,13 +872,15 @@ def quad_rule(self, var_accesses=None): | |
elif generic_name in ["weights_xy", "weights_z"]: | ||
# 1d arrays: | ||
# TODO # 1910: These should be pointers | ||
self.append_array_reference(arg, [":"], | ||
ScalarType.Intrinsic.REAL) | ||
self.append_array_reference( | ||
arg, [":"], | ||
LFRicTypes("LFRicRealScalarDataType")()) | ||
elif generic_name in ["weights_xyz"]: | ||
# 2d arrays: | ||
# TODO #1910: These should be pointers | ||
self.append_array_reference(arg, [":", ":"], | ||
ScalarType.Intrinsic.REAL) | ||
self.append_array_reference( | ||
arg, [":", ":"], | ||
LFRicTypes("LFRicRealScalarDataType")()) | ||
else: | ||
raise InternalError(f"Found invalid kernel argument " | ||
f"'{arg}'.") | ||
|
@@ -970,11 +966,15 @@ def cell_ref_name(self, var_accesses=None): | |
# If there is only one colourmap we need to specify the tag | ||
# to make sure we get the right symbol. | ||
tag = "cmap" | ||
array_ref = self.get_array_reference(self._kern.colourmap, | ||
[Reference(colour_sym), | ||
Reference(cell_sym)], | ||
ScalarType.Intrinsic.INTEGER, | ||
tag=tag) | ||
symbol = self._symtab.find_or_create( | ||
self._kern.colourmap.name, symbol_type=DataSymbol, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused here. |
||
datatype=ArrayType( | ||
LFRicTypes("LFRicIntegerScalarDataType")(), | ||
[ArrayType.Extent.DEFERRED, ArrayType.Extent.DEFERRED]), | ||
tag=tag) | ||
array_ref = ArrayReference.create( | ||
symbol, | ||
[Reference(colour_sym), Reference(cell_sym)]) | ||
if var_accesses is not None: | ||
var_accesses.add_access(Signature(colour_sym.name), | ||
AccessType.READ, self._kern) | ||
|
@@ -984,7 +984,7 @@ def cell_ref_name(self, var_accesses=None): | |
AccessType.READ, | ||
self._kern, ["colour", "cell"]) | ||
|
||
return (self._kern.colourmap + "(colour,cell)", | ||
return (self._kern.colourmap.name + "(colour,cell)", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this now be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess it should also have a TODO as this will need cleaning up somehow. |
||
array_ref) | ||
|
||
if var_accesses is not None: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this TODO incorrect - i.e. it's fine that they aren't pointers? Can #1910 be closed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, as this is the kernel-call argument list I suppose we don't care whether or not they are pointers as we just need References?