Skip to content
Snippets Groups Projects
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
Branches
Tags
No related merge requests found
...@@ -430,6 +430,7 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict): ...@@ -430,6 +430,7 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict):
parameters = kernelFunctionNode.parameters parameters = kernelFunctionNode.parameters
cache = {} cache = {}
cacheValues = []
def wrapper(**kwargs): def wrapper(**kwargs):
key = hash(tuple((k, id(v)) for k, v in kwargs.items())) key = hash(tuple((k, id(v)) for k, v in kwargs.items()))
...@@ -441,6 +442,7 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict): ...@@ -441,6 +442,7 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict):
fullArguments.update(kwargs) fullArguments.update(kwargs)
args = buildCTypeArgumentList(parameters, fullArguments) args = buildCTypeArgumentList(parameters, fullArguments)
cache[key] = args cache[key] = args
cacheValues.append(kwargs) # keep objects alive such that ids remain unique
func(*args) func(*args)
return wrapper return wrapper
......
...@@ -29,6 +29,7 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}): ...@@ -29,6 +29,7 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}):
parameters = kernelFunctionNode.parameters parameters = kernelFunctionNode.parameters
cache = {} cache = {}
cacheValues = []
def wrapper(**kwargs): def wrapper(**kwargs):
key = hash(tuple((k, id(v)) for k, v in kwargs.items())) key = hash(tuple((k, id(v)) for k, v in kwargs.items()))
...@@ -45,6 +46,7 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}): ...@@ -45,6 +46,7 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}):
args = _buildNumpyArgumentList(parameters, fullArguments) args = _buildNumpyArgumentList(parameters, fullArguments)
cache[key] = (args, dictWithBlockAndThreadNumbers) cache[key] = (args, dictWithBlockAndThreadNumbers)
cacheValues.append(kwargs) # keep objects alive such that ids remain unique
func(*args, **dictWithBlockAndThreadNumbers) func(*args, **dictWithBlockAndThreadNumbers)
#cuda.Context.synchronize() # useful for debugging, to get errors right after kernel was called #cuda.Context.synchronize() # useful for debugging, to get errors right after kernel was called
return wrapper return wrapper
......
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