Skip to content

Commit

Permalink
#190 Implement globals to arguments transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
sergisiso committed Nov 29, 2019
1 parent d364c14 commit 5d90c37
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
7 changes: 3 additions & 4 deletions src/psyclone/psyGen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4821,11 +4821,10 @@ def access(self, value):

@property
def type(self):
'''Return the type of the argument. API's that do not have this
concept (such as gocean0.1 and dynamo0.1) can use this
baseclass version which just returns "field" in all
'''Return the type of the argument. API's that do not have this concept
can use this baseclass version which just returns "scalar" in all
cases. API's with this concept can override this method '''
return "field"
return "scalar"

@property
def call(self):
Expand Down
10 changes: 5 additions & 5 deletions src/psyclone/psyir/symbols/datasymbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,11 @@ def constant_value(self, new_value):
'''
if new_value is not None:
if not self.is_local:
raise ValueError(
"Error setting '{0}' constant value. A DataSymbol with a "
"constant value is currently limited to Local interfaces "
"but found '{1}'.".format(self.name, self.interface))
#if not self.is_local:
# raise ValueError(
# "Error setting '{0}' constant value. A DataSymbol with a "
# "constant value is currently limited to Local interfaces "
# "but found '{1}'.".format(self.name, self.interface))
if self.is_array:
raise ValueError(
"Error setting '{0}' constant value. A DataSymbol with a "
Expand Down
49 changes: 31 additions & 18 deletions src/psyclone/transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4397,25 +4397,26 @@ def apply(self, node):
symtab = kernel.symbol_table

# Globals in the Container have to be brought inside the kernel
for globalvar in kernel.parent.symbol_table.global_datasymbols:
if False:
for globalvar in kernel.parent.symbol_table.global_datasymbols:

external_container_name = globalvar.interface.container_symbol.name
external_container_name = globalvar.interface.container_symbol.name

# If the external conatiner name is not in the kernel symbol
# table, this has to be added
if external_container_name not in symtab:
symtab.add(ContainerSymbol(external_container_name))
# If the external conatiner name is not in the kernel symbol
# table, this has to be added
if external_container_name not in symtab:
symtab.add(ContainerSymbol(external_container_name))

# Copy the symbol in the kernel with the appropiate interface
new_symbol = globalvar.copy()
container_ref = symtab.lookup(external_container_name)
new_symbol.interface = GlobalInterface(container_ref)
symtab.add(new_symbol)
# Copy the symbol in the kernel with the appropiate interface
new_symbol = globalvar.copy()
container_ref = symtab.lookup(external_container_name)
new_symbol.interface = GlobalInterface(container_ref)
symtab.add(new_symbol)

# Note that we can not remove the original symbol at this point
# as they can still be used by other kernels.
# Note that we can not remove the original symbol at this point
# as they can still be used by other kernels.

# Transform each kernel global variable into an argument
# Transform each global variable into an argument
for globalvar in kernel.symbol_table.global_datasymbols:
print(globalvar.name)
if globalvar.datatype == 'deferred':
Expand All @@ -4431,10 +4432,14 @@ def apply(self, node):
globalvar.interface.container_symbol.name)
node.root.symbol_table.add(new_container_symbol)
# 2) Then copy the Global referencing the appropriate Container
new_symbol = globalvar.copy()
container_ref = invoke_symtab.lookup(external_container_name)
new_symbol.interface = GlobalInterface(container_ref)
invoke_symtab.add(new_symbol)
if not (globalvar.name in invoke_symtab and
invoke_symtab.lookup(globalvar.name).is_global and
invoke_symtab.lookup(globalvar.name).interface
.container_symbol.name == external_container_name):
new_symbol = globalvar.copy()
container_ref = invoke_symtab.lookup(external_container_name)
new_symbol.interface = GlobalInterface(container_ref)
invoke_symtab.add(new_symbol)

# Convert the symbol to an argument and add it to the argument list
current_arg_list = symtab.argument_list
Expand All @@ -4444,3 +4449,11 @@ def apply(self, node):
symtab.specify_argument_list(current_arg_list)

# Add global in the call argument list
from psyclone.psyGen import KernelArgument
from psyclone.parse.algorithm import Arg
from psyclone.parse.kernel import Descriptor
from psyclone.core.access_type import AccessType
arg = Arg("variable", globalvar.name, globalvar.name)
desc = Descriptor(AccessType.READWRITE, globalvar.name)
argument = KernelArgument(desc, arg, node)
node.arguments.args.append(argument)

0 comments on commit 5d90c37

Please sign in to comment.