Commit 93b1d694 authored by Martin Bauer's avatar Martin Bauer
Browse files

Bugfix in JIT cacheing

- cache relied on uniqueness of  python id()
- id may be reused if object is freed
-> object must be held alive
-> kernel keeps all it arguments it was ever called with, alive (problematic in terms of memory consumption)
parent 12238a82
......@@ -430,6 +430,7 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict):
parameters = kernelFunctionNode.parameters
cache = {}
cacheValues = []
def wrapper(**kwargs):
key = hash(tuple((k, id(v)) for k, v in kwargs.items()))
......@@ -441,6 +442,7 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict):
fullArguments.update(kwargs)
args = buildCTypeArgumentList(parameters, fullArguments)
cache[key] = args
cacheValues.append(kwargs) # keep objects alive such that ids remain unique
func(*args)
return wrapper
......
......@@ -29,6 +29,7 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}):
parameters = kernelFunctionNode.parameters
cache = {}
cacheValues = []
def wrapper(**kwargs):
key = hash(tuple((k, id(v)) for k, v in kwargs.items()))
......@@ -45,6 +46,7 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}):
args = _buildNumpyArgumentList(parameters, fullArguments)
cache[key] = (args, dictWithBlockAndThreadNumbers)
cacheValues.append(kwargs) # keep objects alive such that ids remain unique
func(*args, **dictWithBlockAndThreadNumbers)
#cuda.Context.synchronize() # useful for debugging, to get errors right after kernel was called
return wrapper
......
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