From c8ce17446fac763676b9ac9738f2988448b29f26 Mon Sep 17 00:00:00 2001
From: Markus Holzer <markus.holzer@fau.de>
Date: Tue, 8 Jun 2021 06:33:33 +0000
Subject: [PATCH] Use int64 for indexing

---
 pystencils/backends/opencl_backend.py     | 2 +-
 pystencils/boundaries/boundaryhandling.py | 7 +++----
 pystencils/cpu/kernelcreation.py          | 5 +++--
 pystencils/gpucuda/kernelcreation.py      | 6 ++++--
 4 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/pystencils/backends/opencl_backend.py b/pystencils/backends/opencl_backend.py
index 9fe7b9788..be9d6adb3 100644
--- a/pystencils/backends/opencl_backend.py
+++ b/pystencils/backends/opencl_backend.py
@@ -83,7 +83,7 @@ class OpenClSympyPrinter(CudaSympyPrinter):
         function_name, dimension = tuple(symbol_name.split("."))
         dimension = self.DIMENSION_MAPPING[dimension]
         function_name = self.INDEXING_FUNCTION_MAPPING[function_name]
-        return f"(int) {function_name}({dimension})"
+        return f"(int64_t) {function_name}({dimension})"
 
     def _print_TextureAccess(self, node):
         raise NotImplementedError()
diff --git a/pystencils/boundaries/boundaryhandling.py b/pystencils/boundaries/boundaryhandling.py
index a1d23a372..077b1cd50 100644
--- a/pystencils/boundaries/boundaryhandling.py
+++ b/pystencils/boundaries/boundaryhandling.py
@@ -430,7 +430,7 @@ class BoundaryOffsetInfo(CustomCodeNode):
             inverse_dir = tuple([-i for i in direction])
             inv_dirs.append(str(stencil.index(inverse_dir)))
 
-        code += "const int %s [] = { %s };\n" % (self.INV_DIR_SYMBOL.name, ", ".join(inv_dirs))
+        code += "const int64_t %s [] = { %s };\n" % (self.INV_DIR_SYMBOL.name, ", ".join(inv_dirs))
         offset_symbols = BoundaryOffsetInfo._offset_symbols(dim)
         super(BoundaryOffsetInfo, self).__init__(code, symbols_read=set(),
                                                  symbols_defined=set(offset_symbols + [self.INV_DIR_SYMBOL]))
@@ -439,13 +439,12 @@ class BoundaryOffsetInfo(CustomCodeNode):
     def _offset_symbols(dim):
         return [TypedSymbol(f"c{d}", create_type(np.int64)) for d in ['x', 'y', 'z'][:dim]]
 
-    INV_DIR_SYMBOL = TypedSymbol("invdir", "int")
+    INV_DIR_SYMBOL = TypedSymbol("invdir", np.int64)
 
 
 def create_boundary_kernel(field, index_field, stencil, boundary_functor, target='cpu', **kernel_creation_args):
     elements = [BoundaryOffsetInfo(stencil)]
-    index_arr_dtype = index_field.dtype.numpy_dtype
-    dir_symbol = TypedSymbol("dir", index_arr_dtype.fields['dir'][0])
+    dir_symbol = TypedSymbol("dir", np.int64)
     elements += [Assignment(dir_symbol, index_field[0]('dir'))]
     elements += boundary_functor(field, direction_symbol=dir_symbol, index_field=index_field)
     return create_indexed_kernel(elements, [index_field], target=target, **kernel_creation_args)
diff --git a/pystencils/cpu/kernelcreation.py b/pystencils/cpu/kernelcreation.py
index 81daf49fc..4de8065e6 100644
--- a/pystencils/cpu/kernelcreation.py
+++ b/pystencils/cpu/kernelcreation.py
@@ -1,12 +1,13 @@
 from typing import List, Union
 
 import sympy as sp
+import numpy as np
 
 import pystencils.astnodes as ast
 from pystencils.assignment import Assignment
 from pystencils.astnodes import Block, KernelFunction, LoopOverCoordinate, SympyAssignment
 from pystencils.cpu.cpujit import make_python_function
-from pystencils.data_types import BasicType, StructType, TypedSymbol, create_type
+from pystencils.data_types import StructType, TypedSymbol, create_type
 from pystencils.field import Field, FieldType
 from pystencils.transformations import (
     add_types, filtered_tree_iteration, get_base_buffer_index, get_optimal_loop_ordering,
@@ -127,7 +128,7 @@ def create_indexed_kernel(assignments: AssignmentOrAstNodeList, index_fields, fu
             data_type = idx_field.dtype
             if data_type.has_element(name):
                 rhs = idx_field[0](name)
-                lhs = TypedSymbol(name, BasicType(data_type.get_element_type(name)))
+                lhs = TypedSymbol(name, np.int64)
                 return SympyAssignment(lhs, rhs)
         raise ValueError(f"Index {name} not found in any of the passed index fields")
 
diff --git a/pystencils/gpucuda/kernelcreation.py b/pystencils/gpucuda/kernelcreation.py
index 52a4dc8bd..08226e260 100644
--- a/pystencils/gpucuda/kernelcreation.py
+++ b/pystencils/gpucuda/kernelcreation.py
@@ -1,5 +1,7 @@
+import numpy as np
+
 from pystencils.astnodes import Block, KernelFunction, LoopOverCoordinate, SympyAssignment
-from pystencils.data_types import BasicType, StructType, TypedSymbol
+from pystencils.data_types import StructType, TypedSymbol
 from pystencils.field import Field, FieldType
 from pystencils.gpucuda.cudajit import make_python_function
 from pystencils.gpucuda.indexing import BlockIndexing
@@ -129,7 +131,7 @@ def created_indexed_cuda_kernel(assignments,
             data_type = ind_f.dtype
             if data_type.has_element(name):
                 rhs = ind_f[0](name)
-                lhs = TypedSymbol(name, BasicType(data_type.get_element_type(name)))
+                lhs = TypedSymbol(name, np.int64)
                 return SympyAssignment(lhs, rhs)
         raise ValueError(f"Index {name} not found in any of the passed index fields")
 
-- 
GitLab