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 and External SDFGs #1723

Closed
wants to merge 546 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
546 commits
Select commit Hold shift + click to select a range
fd4bb7f
Support proper replacement of interfaces on dependency graph
mcopik Feb 16, 2024
896c191
maybe next bug fixed?
Feb 16, 2024
7f6d443
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Feb 17, 2024
a8f6a03
Merge branch 'multi_sdfg2' into multi_sdfg
mcopik Feb 17, 2024
d021202
yet another fix
Feb 18, 2024
c534363
yet another fix
Feb 18, 2024
fda4642
tiny fix
Feb 18, 2024
c068539
Add test reproducing symbol error
mcopik Feb 19, 2024
1f49f3a
maybe next bug fixed?
Feb 19, 2024
dc39c33
Fix handling of assumed array shapes for multiple declarations
mcopik Feb 19, 2024
b630ffc
Adapt shape parsing to the new size definition
mcopik Feb 19, 2024
631b690
Fix one more bug in array shape parsing
mcopik Feb 19, 2024
22889c3
adding stuff
Feb 19, 2024
c831401
Fix for array creation in Fortran
mcopik Feb 19, 2024
f2e7678
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Feb 19, 2024
4ba9da7
Add new failing test
mcopik Feb 19, 2024
79096a4
Fix bug in normalization
mcopik Feb 19, 2024
b37b3dc
Fix for already declared (nested) Structures.
alexnick83 Feb 19, 2024
b80531a
maybe next bug fixed?
Feb 19, 2024
e231027
maybe next bug fixed?
Feb 19, 2024
062db4d
maybe next bug fixed?
Feb 19, 2024
db222d4
Fix one more bug for visiting array indices
mcopik Feb 20, 2024
4b159e7
Add test
mcopik Feb 20, 2024
471957c
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Feb 20, 2024
a0958da
next bug fixed!
Feb 21, 2024
323a22d
Fix bug in placeholder propagation and normalized offset generation
mcopik Feb 22, 2024
b779afe
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Feb 22, 2024
56c2ff2
small bug fixed
Feb 22, 2024
4c51f99
small bug fixed
Feb 22, 2024
8e0ba38
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Feb 22, 2024
87139d6
small bug fixed
Feb 22, 2024
7c88b17
small bug fixed
Feb 22, 2024
1488628
small bug fixed
Feb 22, 2024
597d393
small bug fixed
Feb 22, 2024
d277490
small bug fixed
Feb 22, 2024
2cf4589
small bug fixed
Feb 22, 2024
35d8989
maybe next bug fixed?
Feb 23, 2024
dc79e8f
big bug found
Feb 24, 2024
1f29662
maybe next bug fixed?
Feb 25, 2024
65f125c
`dtypes.validate_name` now supports nested data names.
alexnick83 Feb 26, 2024
67d81f1
Added method for validating that memlet data and access node data are…
alexnick83 Feb 26, 2024
0c1e585
Fix duplicate structure definition emission.
alexnick83 Feb 26, 2024
8b1ab75
`CPUCodeGen._emit_copy` now uses the new memlet data validation method.
alexnick83 Feb 26, 2024
72583f7
Added test for structutre nested in struct array nested in another st…
alexnick83 Feb 26, 2024
2eb4908
`validate_memlet_data` returns False if any of the datanames are None.
alexnick83 Feb 26, 2024
e8c6847
Do not try to replace nested data names.
alexnick83 Feb 26, 2024
07068b7
maybe next bug fixed?
Feb 26, 2024
381444c
maybe next bug fixed?
Feb 26, 2024
056769f
maybe next bug fixed?
Feb 26, 2024
7a73eac
struct handling improved
Feb 26, 2024
34a21cd
bugfix
Feb 27, 2024
9e2de27
memlet bounds fixed
Feb 27, 2024
2327868
Improved error message.
alexnick83 Feb 27, 2024
20fd345
Add slice lifting to lift struct views
phschaad Feb 27, 2024
3d0a801
memlet bounds fixed
Feb 27, 2024
524332c
yet another bug
Feb 27, 2024
6f72bb9
Count optional args in a function
mcopik Feb 27, 2024
27bc5c5
first version of interface block replacement
mcopik Feb 27, 2024
caead94
work on interface blocks
mcopik Feb 27, 2024
c086b19
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Feb 27, 2024
9b0e070
fix incorrect code change
mcopik Feb 28, 2024
f6bdca3
test broken
Feb 28, 2024
8e92a22
Validation uses `validate_memlet_data` for subset validity.
alexnick83 Feb 28, 2024
4ce2ad5
RemoveSliceView does not apply to StructureViews.
alexnick83 Feb 28, 2024
ec19d4d
InlineSDFG adds necessary structure-related views and modified memlet…
alexnick83 Feb 28, 2024
5611a7d
test broken
Feb 28, 2024
45b3dd1
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Feb 28, 2024
33b1868
struct sizes assign bug
Feb 28, 2024
755fb64
struct sizes assign bug
Feb 28, 2024
5889a91
Adapt interface to new passes
mcopik Feb 28, 2024
8fa0330
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Feb 28, 2024
3b5ad6e
Major work on replacing interface blocks
mcopik Feb 29, 2024
95cff10
struct sizes assign bug
Feb 29, 2024
5892c43
struct sizes assign bug fixed
Feb 29, 2024
38fd43e
Extend function definition with count of mandatory args
mcopik Feb 29, 2024
ad374c5
Fix for double pointer allocation.
alexnick83 Feb 29, 2024
172e43d
a new fix
Mar 1, 2024
472d0fa
a new fix
Mar 1, 2024
61d9ac0
Multiple fixes in call arg extractor, function2subroutine, and new tr…
mcopik Mar 1, 2024
b8a8182
Change the order of type inference transformations
mcopik Mar 1, 2024
de587e8
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Mar 1, 2024
1622ff4
Lift struct view fix
phschaad Mar 1, 2024
f9cd5da
Optimize intrinsic parsing by removing duplicates
mcopik Mar 2, 2024
432837e
Extend interface block resolution with dimensionality
mcopik Mar 2, 2024
5aae106
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Mar 2, 2024
6e8f4e8
many fixes
Mar 3, 2024
a2580e6
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 3, 2024
1eb807a
struct sizes assign bug fixed
Mar 3, 2024
05801b8
fix for intrinsic test
Mar 3, 2024
6fdc5da
Fix missing intrinsic transformations
mcopik Mar 3, 2024
d4db1f1
fix for intrinsic test
Mar 3, 2024
955536f
fix for velocity tendencies
Mar 3, 2024
c261778
fix for velocity tendencies
Mar 3, 2024
57095b0
float/double fix
Mar 3, 2024
5cbe5eb
Read and write sets adatped to views
lukastruemper Mar 3, 2024
4e3b748
LoopToMap extended to structs
lukastruemper Mar 4, 2024
31c73de
Stop memlet propagation for struct member accesses in nested SDFGs
lukastruemper Mar 4, 2024
387c96b
float/double fix
Mar 4, 2024
4fc03ff
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 4, 2024
1ffd32e
float/double fix
Mar 4, 2024
6de92b1
Take into account the case where the second child is None.
alexnick83 Mar 5, 2024
db626b2
Temporary: Never consider Views to be const.
alexnick83 Mar 5, 2024
03c13ba
LoopToMap: Always create nested SDFG
lukastruemper Mar 4, 2024
22e26a8
ScalarToSymbolPromotion: Extended to views
lukastruemper Mar 5, 2024
36426e0
ConstantPropagation: Don't replace memlets by complex expressions
lukastruemper Mar 5, 2024
3508645
InlineMultistateSDFG extensions
lukastruemper Nov 30, 2023
3176f4a
Disabling InlineMultistateSDFG for now
lukastruemper Mar 5, 2024
8e2ced0
Remove STRUCTOFFSETARRAY symbols from arglist
lukastruemper Mar 5, 2024
cb6aba8
offsets are in
Mar 5, 2024
4baf629
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 5, 2024
685d156
Refined arglist
lukastruemper Mar 5, 2024
1a85c2b
offsets are in
Mar 5, 2024
4638f6f
tmp_struct_symbol removed from arglist
lukastruemper Mar 5, 2024
ee9a118
Use lexicographical order for struct members' cpp definitions
BenWeber42 Mar 6, 2024
ed2aee4
float/double fix
Mar 6, 2024
858f047
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 6, 2024
722bd93
Fixup for InlineMultistateSDFG
lukastruemper Mar 6, 2024
a3a527e
Scalar2Symbol Promotion: Don't promote viewes
lukastruemper Mar 6, 2024
fa18ced
index extractor fix
Mar 6, 2024
2f25c14
InlineMultistateSDFG: Rename input arguments after use
lukastruemper Mar 6, 2024
b959f65
index extractor fix
Mar 6, 2024
fc1a35c
InlineMultistateSDFG fixup
lukastruemper Mar 6, 2024
5ff2c5f
Scalar2SymbolPromotion fixup
lukastruemper Mar 6, 2024
cf62bfd
index extractor fix
Mar 7, 2024
6f99d4e
Added InlineMap transformation
lukastruemper Mar 7, 2024
052d6b4
InlineMap: Prepare for multiple cases
lukastruemper Mar 7, 2024
3f3cb5f
Fix issue in optional args processing and normalizing offsets of arra…
mcopik Mar 8, 2024
d4d362f
Fix non error
mcopik Mar 8, 2024
54ab1db
Fix handling of potential nones
mcopik Mar 8, 2024
20f6c05
fix test
mcopik Mar 8, 2024
38cde51
Recursively declare/define StructureView members.
alexnick83 Mar 8, 2024
d1ea268
optional arg fix
Mar 8, 2024
da39f65
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 8, 2024
947e3d7
Confirm that node still exists in SDFGState.
alexnick83 Mar 9, 2024
7b6a0cc
Added entering and exiting scope code for `declared_arrays` in framec…
alexnick83 Mar 9, 2024
bf9f1b4
2 fixes
Mar 10, 2024
accd0e9
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 10, 2024
1e25089
new issue
Mar 10, 2024
547e597
last issue
Mar 11, 2024
de2ba60
reproducer
Mar 11, 2024
c11641b
InlinMap extended
lukastruemper Mar 11, 2024
f3ebbb1
InlineMap: Enable single-state inlining
lukastruemper Mar 11, 2024
3adc62e
testing optipipeline
Mar 11, 2024
17c22f8
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 11, 2024
cd30c85
Cache SDFG starting block before potentially removing it.
alexnick83 Mar 12, 2024
a64ea7f
Improved InlineMapByAssignment's symbol handling, including treating …
alexnick83 Mar 12, 2024
8c4ee43
container array fixes
Mar 13, 2024
e716ff5
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 13, 2024
9cfdd11
References must be declared and defined in the same line.
alexnick83 Mar 13, 2024
629d11c
Dereference extra StructureView pointer.
alexnick83 Mar 13, 2024
f621f39
Infer Structure out connectors as Scalars.
alexnick83 Mar 13, 2024
a999b17
Consider Structures Scalars.
alexnick83 Mar 13, 2024
9eaaf2a
More elaborate is_scalar inference.
alexnick83 Mar 13, 2024
8238c99
Instead of dereferencing extra pointers, cancel out pointer and refer…
alexnick83 Mar 13, 2024
8b58533
container array fixes
Mar 13, 2024
cf31ea8
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 13, 2024
7bda614
Minor fix in InlineMultistateSDFG
lukastruemper Mar 13, 2024
f92f692
container array fixes
Mar 14, 2024
5fb26f9
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 14, 2024
7298e4e
container array fixes
Mar 15, 2024
ac4c012
Create pointer removal pass
mcopik Mar 15, 2024
dced3b3
symbol fix
Mar 15, 2024
28c7b3c
container array fixes
Mar 15, 2024
8d60c85
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Mar 15, 2024
f464682
Rewrite pointerremoval pass to not use deepcopy
mcopik Mar 15, 2024
de714af
helpful annotations
mcopik Mar 15, 2024
02fefd8
InlineMultistateSDFG: Rename indirections with iconns
lukastruemper Mar 15, 2024
a1b144a
Minor fixes
lukastruemper Mar 16, 2024
a490c2f
InlineMap: Fixed symbol assignments
lukastruemper Mar 16, 2024
ccb664f
fixes for interfaces, container arrays, and optionals
Mar 17, 2024
d4baaaa
fixes for interfaces, container arrays, and optionals
Mar 17, 2024
9f21396
Fix pointer removal pass - make sure that ptr itself is removed
mcopik Mar 17, 2024
e15db7b
Change order of AST passes
mcopik Mar 17, 2024
7e8cb71
update test
mcopik Mar 17, 2024
fc97b75
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Mar 17, 2024
cea544d
still buggy
Mar 17, 2024
06cb554
still buggy
Mar 17, 2024
68217b4
Fix bad typo in LiftStructView
phschaad Mar 17, 2024
ecdcd92
still buggy
Mar 17, 2024
bc6543e
still buggy
Mar 17, 2024
c1a3068
Handle correctly unexpected Nones in AST structures
mcopik Mar 17, 2024
833649d
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Mar 17, 2024
ec1c61f
Connectors fix
phschaad Mar 17, 2024
98b5bd0
InlineMultistateSDFG: Updated symbol mapping
lukastruemper Mar 17, 2024
eeb5326
State fission after fixed
lukastruemper Mar 17, 2024
97e8d10
first dycore SDFG validate
Mar 17, 2024
6246a2e
still buggy
Mar 17, 2024
7b66647
first dycore validation
Mar 17, 2024
9ba1b46
Velocity Tendencies: auto-opt working
lukastruemper Mar 17, 2024
1030893
first dycore validation
Mar 18, 2024
694d9f5
nh_solve fix
Mar 18, 2024
491add7
nh_solve fix
Mar 18, 2024
94c46b8
nh_solve fix
Mar 18, 2024
99fb1e6
nh_solve fix
Mar 18, 2024
409c83c
try to fix bug in processing optional args
mcopik Mar 18, 2024
c9c1f07
nh_solve fix
Mar 19, 2024
571e7a6
Ensure `diag` is not interpeted as a function in `pystr_to_symbolic`.
alexnick83 Mar 19, 2024
aed1a1b
InlineMapByAssignment: Check for constants
lukastruemper Mar 20, 2024
d509143
InlineMultistateSDFG: Rename symbols to avoid clashes with map scopes
lukastruemper Mar 20, 2024
854e824
Bugfixes for lift_struct_views
phschaad Mar 21, 2024
e87d3a7
RemoveSliceView: don't apply to container arrays and container views
lukastruemper Mar 21, 2024
18cc774
nh_solve fix
Mar 22, 2024
0e942fb
Don't overwrite "prefix" since we need it later.
alexnick83 Mar 22, 2024
ec64861
Experimental Inlining Extension: To be tested
lukastruemper Mar 22, 2024
a858c42
Typo fix
lukastruemper Mar 22, 2024
e490e00
nh_solve fix
Mar 22, 2024
f4224b3
InlineMultistateSDFG: Minor fix
lukastruemper Mar 22, 2024
aa8e513
InlineMultistateSDFG: Removed workaround
lukastruemper Mar 23, 2024
ca3e610
Fixed tuple comprehension.
alexnick83 Mar 23, 2024
f5accde
LiftStructView fix
phschaad Mar 23, 2024
081b57c
Enable viewing individual states
phschaad Mar 24, 2024
dfc3051
fix for redundant array removing struct.field views
Mar 24, 2024
aeae7da
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 24, 2024
cb8b504
Minor fixes
lukastruemper Mar 24, 2024
fe95e89
fix frontend wrong argument added
Mar 24, 2024
ad3fed6
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 24, 2024
1613468
Liftstructview fix
phschaad Mar 25, 2024
64a747d
codegen issue
Mar 25, 2024
253aee3
nh_solve fix structureView instead of arrayView
Mar 26, 2024
d799a8a
wip
mcopik Mar 27, 2024
c59ee77
Fixing struct codegen (#1554)
alexnick83 Mar 27, 2024
f7614bc
fix memlet generation
mcopik Mar 27, 2024
116d246
nh_solve fix
Mar 27, 2024
747c591
cloudsc fix
Mar 27, 2024
4b288e3
cloudsc fix
Mar 27, 2024
e49f2d9
remove printouts
mcopik Mar 27, 2024
9cf41a0
remove debugs
mcopik Mar 27, 2024
3057e2b
LoopToMap for views
lukastruemper Mar 27, 2024
590ee24
cloudsc fix
Mar 27, 2024
c09adca
Merge branch 'multi_sdfg' of github.com:spcl/dace into multi_sdfg
mcopik Mar 27, 2024
3ebb9b7
cloudsc fix
Mar 27, 2024
f7df33b
InlineMap fixes
lukastruemper Mar 27, 2024
238ec2f
InlineMap fixes
lukastruemper Mar 29, 2024
e527b0a
InlineMap final fix
lukastruemper Mar 30, 2024
cdc552c
Argument flattening for nested SDFGs
lukastruemper Mar 31, 2024
4e140a6
deserialize issue
Mar 31, 2024
6854f7f
Codegen fixes
lukastruemper Mar 31, 2024
6ede21a
deserialize issue
Mar 31, 2024
aa96497
Merge branch 'multi_sdfg' of https://github.com/spcl/dace into multi_…
Mar 31, 2024
134f3d8
Added transformations
lukastruemper Apr 1, 2024
c7e03dd
Introduced temporary workaround to load old SDFG where the TensorTran…
alexnick83 Apr 1, 2024
bff104c
Fix for scalar nested sdfg arguments connected to a view.
alexnick83 Jul 12, 2024
33fd505
Views should not be const or ref.
alexnick83 Jul 13, 2024
ae6b0db
Use ptrname instead of name.
alexnick83 Jul 13, 2024
5f70a19
Added new SDFG utiity methods for removing Views to Scalars and renam…
alexnick83 Jul 22, 2024
82477fc
Do not make reference to Structure when setting a simple pointer to s…
alexnick83 Aug 12, 2024
98a17ab
Enhanced `remove_scalar_views` utility method to also remove views to…
alexnick83 Aug 12, 2024
db94eb0
Fix pruning of imported symbols when it appears in type definition
mcopik Sep 10, 2024
6fc4df6
Merge branch 'main' into multi_sdfg
phschaad Nov 1, 2024
bce6f0c
Merge branch 'main' into users/phschaad/multi_sdfg_merge
phschaad Nov 8, 2024
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
4 changes: 4 additions & 0 deletions dace/codegen/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,11 @@ def dispatch_state(self, state: SDFGState, function_stream: CodeIOStream, callsi
""" Dispatches a code generator for an SDFG state. """

self.defined_vars.enter_scope(state)
self.declared_arrays.enter_scope(state)
disp = self.get_state_dispatcher(state.sdfg, state)
disp.generate_state(state.sdfg, state.parent_graph, state, function_stream, callsite_stream)
self.defined_vars.exit_scope(state)
self.declared_arrays.exit_scope(state)

def dispatch_subgraph(self,
sdfg: SDFG,
Expand Down Expand Up @@ -462,10 +464,12 @@ def dispatch_scope(self,

entry_node = sub_dfg.source_nodes()[0]
self.defined_vars.enter_scope(entry_node)
self.declared_arrays.enter_scope(entry_node)
self._used_targets.add(self._map_dispatchers[map_schedule])
self._map_dispatchers[map_schedule].generate_scope(sdfg, cfg, sub_dfg, state_id, function_stream,
callsite_stream)
self.defined_vars.exit_scope(entry_node)
self.declared_arrays.exit_scope(entry_node)

def get_array_dispatcher(self, storage: dtypes.StorageType) -> target.TargetCodeGenerator:
return self._array_dispatchers[storage]
Expand Down
92 changes: 82 additions & 10 deletions dace/codegen/targets/cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,18 @@ def emit_memlet_reference(dispatcher: 'TargetDispatcher',
typedef = conntype.ctype
offset = cpp_offset_expr(desc, memlet.subset)
offset_expr = '[' + offset + ']'
is_scalar = not isinstance(conntype, dtypes.pointer)
is_scalar = not isinstance(conntype, dtypes.pointer) # or (isinstance(conntype, dtypes.pointer) and isinstance(desc, data.ContainerArray))
# is_scalar = not isinstance(conntype, dtypes.pointer)
# is_scalar = is_scalar or isinstance(desc, data.Structure)
# is_dtype_struct = isinstance(desc, data.ContainerArray) and isinstance(desc.dtype, dtypes.pointer) and isinstance(desc.dtype.base_type, dtypes.struct)
# is_scalar = is_scalar or (is_dtype_struct and memlet.subset and memlet.subset.num_elements() == 1)
ptrname = ptr(memlet.data, desc, sdfg, dispatcher.frame)
ref = ''

if isinstance(desc, data.Structure):
offset = ''
offset_expr = ''

# Get defined type (pointer, stream etc.) and change the type definition
# accordingly.
defined_types = None
Expand Down Expand Up @@ -324,6 +332,28 @@ def emit_memlet_reference(dispatcher: 'TargetDispatcher',
else:
datadef = ptr(memlet.data, desc, sdfg, dispatcher.frame)

if '.' in memlet.data:
tokens = memlet.data.split('.')
datadef = ''
for token in tokens[:-1]:
assert token in sdfg.arrays
desc = sdfg.arrays[token]
assert isinstance(desc, data.Structure)
if not datadef:
datadef = token
if isinstance(desc, data.StructureView) and isinstance(desc.dtype, dtypes.pointer):
datadef = f"(*{token})"
continue
if isinstance(desc.dtype, dtypes.struct):
datadef = f"{datadef}.{token}"
elif isinstance(desc.dtype, dtypes.pointer) and isinstance(desc.dtype.base_type, dtypes.struct):
datadef = f"{datadef}->{token}"
else:
raise TypeError(f"Unsupported structure type: {desc.dtype}")
datadef = f"({datadef}.{tokens[-1]})"
elif isinstance(desc, data.StructureView) and isinstance(desc.dtype, dtypes.pointer):
datadef = f"(*{datadef})"

def make_const(expr: str) -> str:
# check whether const has already been added before
if not expr.startswith("const "):
Expand All @@ -334,14 +364,18 @@ def make_const(expr: str) -> str:
if (defined_type == DefinedType.Pointer
or (defined_type == DefinedType.ArrayInterface and isinstance(desc, data.View))):
if not is_scalar and desc.dtype == conntype.base_type:
# Cast potential consts
typedef = defined_ctype
if isinstance(desc, data.Structure):
# typdef = defined_ctype
pass
else:
# Cast potential consts
typedef = defined_ctype

if is_scalar:
defined_type = DefinedType.Scalar
if is_write is False:
if is_write is False and not isinstance(desc, (data.View, data.ContainerArray)):
typedef = make_const(typedef)
ref = '&'
ref = '&'
else:
# constexpr arrays
if memlet.data in dispatcher.frame.symbols_and_constants(sdfg):
Expand Down Expand Up @@ -397,14 +431,22 @@ def make_const(expr: str) -> str:
ref = '&'
else:
# Cast as necessary
expr = make_ptr_vector_cast(datadef + offset_expr, desc.dtype, conntype, is_scalar, defined_type)
if ref == '&' and offset_expr:
ref = ''
offset_expr = ''
# NOTE: Structures are misunderstood as pointers to scalar in `make_ptr_vecor_cast`.
if isinstance(desc, data.Structure) and isinstance(conntype.base_type, dtypes.struct):
expr = datadef
else:
expr = make_ptr_vector_cast(datadef + offset_expr, desc.dtype, conntype, is_scalar, defined_type)
expr = expr.replace('.', '->')

# Register defined variable
dispatcher.defined_vars.add(pointer_name, defined_type, typedef, allow_shadowing=True)

# NOTE: `expr` may only be a name or a sequence of names and dots. The latter indicates nested data and structures.
# NOTE: Since structures are implemented as pointers, we replace dots with arrows.
expr = expr.replace('.', '->')
# expr = expr.replace('.', '->')

return (typedef + ref, pointer_name, expr)

Expand Down Expand Up @@ -1036,10 +1078,19 @@ 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))
to_write = ptr(t.id, desc, self.sdfg, self.codegen)
if isinstance(desc, data.StructureView):
to_write = f"(*{to_write})"
self.write(to_write)

def _Attribute(self, t: ast.Attribute):
from dace.frontend.python.astutils import rname
from dace.frontend.python.astutils import rname, unparse

if '.' in unparse(t):
super().dispatch(t.value)
self.write(f'->{t.attr}')
return

name = rname(t)
if name not in self.sdfg.arrays:
return super()._Attribute(t)
Expand All @@ -1049,13 +1100,34 @@ def _Attribute(self, t: ast.Attribute):
self.write(ptr(name, desc, self.sdfg, self.codegen))

def _Subscript(self, t: ast.Subscript):
from dace.frontend.python.astutils import subscript_to_slice
from dace.frontend.python.astutils import subscript_to_slice, unparse

if isinstance(t.value, ast.Name):
name = t.value.id
desc = self.sdfg.arrays[name]
if isinstance(desc, data.Structure):
to_write = name
if isinstance(desc, data.StructureView):
to_write = f"(*{to_write})"
self.write(to_write)
return

target, rng = subscript_to_slice(t, self.sdfg.arrays)
rng = subsets.Range(rng)
if rng.num_elements() != 1:
raise SyntaxError('Range subscripts disallowed in interstate edges')

memlet = mmlt.Memlet(data=target, subset=rng)
to_write = cpp_array_expr(self.sdfg, memlet, codegen=self.codegen)

if '.' in unparse(t):
super().dispatch(t.value)
desc = self.sdfg.arrays[target]
if not isinstance(desc, data.Structure):
i0 = to_write.find('[')
i1 = to_write.rfind(']')
self.write(to_write[i0:i1 + 1])
return

if target not in self.sdfg.arrays:
# This could be an FPGA array whose name has been mangled
Expand Down
Loading