Skip to content
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

Fortran frontend #1866

Draft
wants to merge 55 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
dce9421
Import frontend patches from multi_sdfg
phschaad Dec 20, 2024
2e4d09f
Import fortran tests
phschaad Dec 20, 2024
6b4fa3a
Formatting and Python 3.7 typing conforming
phschaad Dec 20, 2024
2194c9f
Formatting
phschaad Dec 20, 2024
bd30606
Copyright, more formatting
phschaad Dec 20, 2024
523c1d7
Adapt frontend to control flow regions, first step
phschaad Dec 20, 2024
36c6291
Fixes
phschaad Dec 23, 2024
fdc6312
Add branch generation
phschaad Dec 23, 2024
e8b94b9
WIP
phschaad Dec 23, 2024
e657f2c
Fixes
phschaad Dec 23, 2024
2cbfcd5
Fix symbol and scalar conflict
phschaad Dec 24, 2024
f6a9dc8
Import some of the offset changes
phschaad Dec 24, 2024
3ec0731
Fixes
phschaad Jan 6, 2025
67fade9
Fix to views on interstate edges
phschaad Jan 6, 2025
b16323b
Copy over frontend files and tests
phschaad Jan 10, 2025
3d52332
Merge branch 'f2dace/frontend_merge' into f2dace/frontend
phschaad Jan 10, 2025
fe58a8f
Fixes
phschaad Jan 10, 2025
e9df60d
Remove stale file
phschaad Jan 10, 2025
9ac2a62
Make test runnable
phschaad Jan 10, 2025
ea4f71d
Fixes and porting some hacks
phschaad Jan 10, 2025
39a881d
Revert formatting changes for transparency
phschaad Jan 10, 2025
0a3ac4b
Fix test
phschaad Jan 10, 2025
5c5cd96
Add intrinsics
phschaad Jan 10, 2025
ef8e8a7
Struct fixes
phschaad Jan 10, 2025
ee44a5c
Re-enable tests fixed from CFRs
phschaad Jan 10, 2025
d4f0be4
Fix typing issues în desugaring and re-enable more tests
phschaad Jan 10, 2025
73efee9
adapt ecrad pipeline
Jan 10, 2025
8181153
fixing ecrad pipeline
Jan 10, 2025
d401916
fix
mcopik Jan 10, 2025
5660763
wip
Jan 10, 2025
5404b9c
pow
mcopik Jan 10, 2025
9e9d7b2
pow fix
Jan 10, 2025
a585145
improved handling of type inference
mcopik Jan 10, 2025
b078d1a
test that fails
Jan 10, 2025
65f3e99
fix fix fixxxxxxx
mcopik Jan 10, 2025
a9f7846
intrinsics
Jan 10, 2025
619dea8
Fix invalid type use for 3.9
phschaad Jan 10, 2025
1457599
More missused type fixes
phschaad Jan 10, 2025
d8039cf
fixes for tests
Jan 12, 2025
3edc60d
fixes
Jan 12, 2025
12c5671
Skipping nested structs until merging flattening
Jan 12, 2025
4e244c9
[multi sdfg, fortran] Make global renaming apply only when there is a…
pratyai Jan 13, 2025
fef9f77
Missed the naming scheme changes for the test in the last PR.
pratyai Jan 13, 2025
ff11c91
Mixed up the `lt` vs. `le` and `gt` vs. `ge` earlier.
pratyai Jan 13, 2025
08bf378
Fix broken variable declaration inside CallExtractor
mcopik Jan 13, 2025
6319666
type inf fixes
mcopik Jan 13, 2025
f5355cf
fixy fixy
mcopik Jan 13, 2025
4ab6efa
[Multi SDFG, Fortran] 1) Add initializers for each derived type with …
pratyai Jan 14, 2025
8f0e2d9
[Multi SDFG, Fortran] Prune unused struct fields, i.e., if they are n…
pratyai Jan 14, 2025
6c60453
Update test after struct component pruning.
pratyai Jan 14, 2025
731ab48
Fixes for conditionals
phschaad Jan 15, 2025
132fbd7
[Multi SDFG, Fortran] 1) Convert "data statements" into regular assig…
pratyai Jan 15, 2025
e668e7d
Fix invalid f-string use
phschaad Jan 15, 2025
f490f72
Fix
phschaad Jan 15, 2025
bb8fa9c
Remove duplicate code
phschaad Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dace/codegen/targets/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,12 @@ def _Name(self, t: ast.Name):

# Replace values with their code-generated names (for example, persistent arrays)
desc = self.sdfg.arrays[t.id]
self.write(ptr(t.id, desc, self.sdfg, self.codegen))
base_ptr = ptr(t.id, desc, self.sdfg, self.codegen)
if isinstance(desc, data.View):
# In the case of a view we obtain a pointer that needs to be dereferenced first.
self.write(f'(*{base_ptr})')
else:
self.write(base_ptr)

def _Attribute(self, t: ast.Attribute):
from dace.frontend.python.astutils import rname
Expand Down
19 changes: 10 additions & 9 deletions dace/codegen/targets/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,8 @@ def allocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgraphV
arrsize_bytes = arrsize * nodedesc.dtype.bytes

if isinstance(nodedesc, data.Structure) and not isinstance(nodedesc, data.StructureView):
declaration_stream.write(f"{nodedesc.ctype} {name} = new {nodedesc.dtype.base_type};\n")
if not declared:
declaration_stream.write(f"{nodedesc.ctype} {name} = new {nodedesc.dtype.base_type};\n")
define_var(name, DefinedType.Pointer, nodedesc.ctype)
if allocate_nested_data:
for k, v in nodedesc.members.items():
Expand Down Expand Up @@ -476,21 +477,21 @@ def allocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgraphV
declaration_stream.write(definition, cfg, state_id, node)
define_var(name, DefinedType.Stream, ctypedef)

elif (nodedesc.storage == dtypes.StorageType.CPU_Heap
or (nodedesc.storage == dtypes.StorageType.Register and
elif (top_storage == dtypes.StorageType.CPU_Heap
or (top_storage == dtypes.StorageType.Register and
((symbolic.issymbolic(arrsize, sdfg.constants)) or
(arrsize_bytes and ((arrsize_bytes > Config.get("compiler", "max_stack_array_size")) == True))))):

if nodedesc.storage == dtypes.StorageType.Register:
if top_storage == dtypes.StorageType.Register:

if symbolic.issymbolic(arrsize, sdfg.constants):
warnings.warn('Variable-length array %s with size %s '
'detected and was allocated on heap instead of '
'%s' % (name, cpp.sym2cpp(arrsize), nodedesc.storage))
'%s' % (name, cpp.sym2cpp(arrsize), top_storage))
elif (arrsize_bytes > Config.get("compiler", "max_stack_array_size")) == True:
warnings.warn("Array {} with size {} detected and was allocated on heap instead of "
"{} since its size is greater than max_stack_array_size ({})".format(
name, cpp.sym2cpp(arrsize_bytes), nodedesc.storage,
name, cpp.sym2cpp(arrsize_bytes), top_storage,
Config.get("compiler", "max_stack_array_size")))

ctypedef = dtypes.pointer(nodedesc.dtype).ctype
Expand All @@ -510,7 +511,7 @@ def allocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgraphV
node)

return
elif (nodedesc.storage == dtypes.StorageType.Register):
elif (top_storage == dtypes.StorageType.Register):
ctypedef = dtypes.pointer(nodedesc.dtype).ctype
if nodedesc.start_offset != 0:
raise NotImplementedError('Start offset unsupported for registers')
Expand All @@ -531,7 +532,7 @@ def allocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgraphV
)
define_var(name, DefinedType.Pointer, ctypedef)
return
elif nodedesc.storage is dtypes.StorageType.CPU_ThreadLocal:
elif top_storage is dtypes.StorageType.CPU_ThreadLocal:
# Define pointer once
# NOTE: OpenMP threadprivate storage MUST be declared globally.
if not declared:
Expand Down Expand Up @@ -566,7 +567,7 @@ def allocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgraphV
allocation_stream.write('}')
self._dispatcher.defined_vars.add_global(name, DefinedType.Pointer, '%s *' % nodedesc.dtype.ctype)
else:
raise NotImplementedError("Unimplemented storage type " + str(nodedesc.storage))
raise NotImplementedError("Unimplemented storage type " + str(top_storage))

def deallocate_array(self, sdfg: SDFG, cfg: ControlFlowRegion, dfg: StateSubgraphView, state_id: int,
node: nodes.AccessNode, nodedesc: data.Data, function_stream: CodeIOStream,
Expand Down
12 changes: 10 additions & 2 deletions dace/codegen/targets/framecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def __init__(self, sdfg: SDFG):
self.fsyms: Dict[int, Set[str]] = {}
self._symbols_and_constants: Dict[int, Set[str]] = {}
fsyms = self.free_symbols(sdfg)
# TODO: Hack, remove!
fsyms = set(filter(lambda x: not (
str(x).startswith('__f2dace_SA') or str(x).startswith('__f2dace_SOA') or
str(x).startswith('tmp_struct_symbol')
), fsyms))
self.arglist = sdfg.arglist(scalars_only=False, free_symbols=fsyms)

# resolve all symbols and constants
Expand Down Expand Up @@ -239,8 +244,11 @@ def generate_footer(self, sdfg: SDFG, global_stream: CodeIOStream, callsite_stre
fname = sdfg.name
params = sdfg.signature(arglist=self.arglist)
paramnames = sdfg.signature(False, for_call=True, arglist=self.arglist)
initparams = sdfg.init_signature(free_symbols=self.free_symbols(sdfg))
initparamnames = sdfg.init_signature(for_call=True, free_symbols=self.free_symbols(sdfg))
# TODO: Hack, revert!
initparams = sdfg.signature(arglist=self.arglist)
initparamnames = sdfg.signature(False, for_call=True, arglist=self.arglist)
#initparams = sdfg.init_signature(free_symbols=self.free_symbols(sdfg))
#initparamnames = sdfg.init_signature(for_call=True, free_symbols=self.free_symbols(sdfg))

# Invoke all instrumentation providers
for instr in self._dispatcher.instrumentation.values():
Expand Down
2 changes: 1 addition & 1 deletion dace/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ def __init__(self,
# else:
# fields_and_types[str(s)] = dtypes.int32

dtype = dtypes.pointer(dtypes.struct(name, **fields_and_types))
dtype = dtypes.pointer(dtypes.struct(name, fields_and_types))
shape = (1, )
super(Structure, self).__init__(dtype, shape, transient, storage, location, lifetime, debuginfo)

Expand Down
3 changes: 2 additions & 1 deletion dace/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,8 @@ class struct(typeclass):
Example use: `dace.struct(a=dace.int32, b=dace.float64)`.
"""

def __init__(self, name, **fields_and_types):
def __init__(self, name, fields_and_types=None, **fields):
fields_and_types = fields_and_types or fields
# self._data = fields_and_types
self.type = ctypes.Structure
self.name = name
Expand Down
Loading
Loading