Skip to content
Snippets Groups Projects
Commit d30c5f73 authored by Martin Bauer's avatar Martin Bauer
Browse files

Changed parameter bind caching for CPU and GPU kernels

- previously all objects where cached by id()
- for waLBerla simulations in each time step a new np.array view
  is created from the waLBerla field. Each of these views has a
  different id -> caching did not work for waLBerla setups
- changed hash for numpy arrays: instead of id, a tuple of
  (dataPtr, strides, shapes) is used as hash input
parent 5bcf24bf
No related merge requests found
...@@ -68,6 +68,7 @@ import platform ...@@ -68,6 +68,7 @@ import platform
import glob import glob
import atexit import atexit
import shutil import shutil
import numpy as np
from appdirs import user_config_dir, user_cache_dir from appdirs import user_config_dir, user_cache_dir
from ctypes import cdll from ctypes import cdll
from pystencils.backends.cbackend import generateC, getHeaders from pystencils.backends.cbackend import generateC, getHeaders
...@@ -428,7 +429,8 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict, func): ...@@ -428,7 +429,8 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict, func):
cacheValues = [] cacheValues = []
def wrapper(**kwargs): def wrapper(**kwargs):
key = hash(tuple((k, id(v)) for k, v in kwargs.items())) key = hash(tuple((k, v.ctypes.data, v.strides, v.shape) if isinstance(v, np.ndarray) else (k, id(v))
for k, v in kwargs.items()))
try: try:
args = cache[key] args = cache[key]
func(*args) func(*args)
......
...@@ -33,7 +33,8 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}): ...@@ -33,7 +33,8 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}):
cacheValues = [] cacheValues = []
def wrapper(**kwargs): def wrapper(**kwargs):
key = hash(tuple((k, id(v)) for k, v in kwargs.items())) key = hash(tuple((k, v.ctypes.data, v.strides, v.shape) if isinstance(v, np.ndarray) else (k, id(v))
for k, v in kwargs.items()))
try: try:
args, dictWithBlockAndThreadNumbers = cache[key] args, dictWithBlockAndThreadNumbers = cache[key]
func(*args, **dictWithBlockAndThreadNumbers) func(*args, **dictWithBlockAndThreadNumbers)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment