From 563d65cbd559fa7a437782613db3daf66df2fc64 Mon Sep 17 00:00:00 2001
From: markus holzer <markus.holzer@fau.de>
Date: Sat, 18 Mar 2023 08:57:23 +0100
Subject: [PATCH] Use common field for indexing

---
 pystencils/gpucuda/kernelcreation.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/pystencils/gpucuda/kernelcreation.py b/pystencils/gpucuda/kernelcreation.py
index 29211586a..7bc7fb9dd 100644
--- a/pystencils/gpucuda/kernelcreation.py
+++ b/pystencils/gpucuda/kernelcreation.py
@@ -44,7 +44,9 @@ def create_cuda_kernel(assignments: Union[AssignmentCollection, NodeCollection],
         field_accesses = {e for e in field_accesses if not e.is_absolute_access}
         num_buffer_accesses += sum(1 for access in eq.atoms(Field.Access) if FieldType.is_buffer(access.field))
 
+    # common shape and field to from the iteration space
     common_shape = get_common_shape(fields_without_buffers)
+    common_field = list(sorted(fields_without_buffers, key=lambda e: str(e)))[0]
 
     if iteration_slice is None:
         # determine iteration slice from ghost layers
@@ -62,7 +64,7 @@ def create_cuda_kernel(assignments: Union[AssignmentCollection, NodeCollection],
                 iteration_slice.append(slice(ghost_layers[i][0],
                                              -ghost_layers[i][1] if ghost_layers[i][1] > 0 else None))
 
-    indexing = indexing_creator(field=list(fields_without_buffers)[0], iteration_slice=iteration_slice)
+    indexing = indexing_creator(field=common_field, iteration_slice=iteration_slice)
     coord_mapping = indexing.coordinates
 
     cell_idx_assignments = [SympyAssignment(LoopOverCoordinate.get_loop_counter_symbol(i), value)
-- 
GitLab