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
......@@ -68,6 +68,7 @@ import platform
import glob
import atexit
import shutil
import numpy as np
from appdirs import user_config_dir, user_cache_dir
from ctypes import cdll
from pystencils.backends.cbackend import generateC, getHeaders
......@@ -428,7 +429,8 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict, func):
cacheValues = []
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:
args = cache[key]
func(*args)
......
......@@ -33,7 +33,8 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}):
cacheValues = []
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:
args, dictWithBlockAndThreadNumbers = cache[key]
func(*args, **dictWithBlockAndThreadNumbers)
......
Markdown is supported
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