Commit 04784686 authored by Martin Bauer's avatar Martin Bauer
Browse files

KernelFunction node stores now backend string - compiled functions have ast attribute

parent 979ee93b
......@@ -155,7 +155,7 @@ class KernelFunction(Node):
def __repr__(self):
return '<{0} {1}>'.format(self.dtype, self.name)
def __init__(self, body, ghostLayers=None, functionName="kernel"):
def __init__(self, body, ghostLayers=None, functionName="kernel", backend=""):
super(KernelFunction, self).__init__()
self._body = body
body.parent = self
......@@ -166,6 +166,7 @@ class KernelFunction(Node):
self.ghostLayers = ghostLayers
# these variables are assumed to be global, so no automatic parameter is generated for them
self.globalVariables = set()
self.backend = ""
@property
def symbolsDefined(self):
......
......@@ -439,4 +439,5 @@ def makePythonFunctionIncompleteParams(kernelFunctionNode, argumentDict, func):
cache[key] = args
cacheValues.append(kwargs) # keep objects alive such that ids remain unique
func(*args)
wrapper.ast = kernelFunctionNode
return wrapper
......@@ -139,7 +139,7 @@ def createIndexedKernel(listOfEquations, indexFields, functionName="kernel", typ
loopBody.append(assignment)
functionBody = Block([loopNode])
ast = KernelFunction(functionBody, functionName=functionName)
ast = KernelFunction(functionBody, "cpu", functionName=functionName)
fixedCoordinateMapping = {f.name: coordinateTypedSymbols for f in nonIndexFields}
resolveFieldAccesses(ast, set(['indexField']), fieldToFixedCoordinates=fixedCoordinateMapping)
......
......@@ -52,6 +52,7 @@ def makePythonFunction(kernelFunctionNode, argumentDict={}):
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
wrapper.ast = kernelFunctionNode
return wrapper
......
......@@ -45,7 +45,7 @@ def createCUDAKernel(listOfEquations, functionName="kernel", typeForSymbol=None,
block = Block(assignments)
block = indexing.guard(block, commonShape)
ast = KernelFunction(block, functionName=functionName, ghostLayers=ghostLayers)
ast = KernelFunction(block, functionName=functionName, ghostLayers=ghostLayers, backend='gpucuda')
ast.globalVariables.update(indexing.indexVariables)
coordMapping = indexing.coordinates
......@@ -118,7 +118,7 @@ def createdIndexedCUDAKernel(listOfEquations, indexFields, functionName="kernel"
functionBody = Block(coordinateSymbolAssignments + assignments)
functionBody = indexing.guard(functionBody, getCommonShape(indexFields))
ast = KernelFunction(functionBody, functionName=functionName)
ast = KernelFunction(functionBody, functionName=functionName, backend='gpucuda')
ast.globalVariables.update(indexing.indexVariables)
coordMapping = indexing.coordinates
......
......@@ -89,7 +89,7 @@ def createIndexedKernel(listOfEquations, indexFields, functionName="kernel", typ
loopBody.append(assignment)
functionBody = Block([loopNode])
ast = KernelFunction(functionBody, allFields, functionName)
ast = KernelFunction(functionBody, None, functionName, backend='llvm')
fixedCoordinateMapping = {f.name: coordinateTypedSymbols for f in nonIndexFields}
resolveFieldAccesses(ast, set(['indexField']), fieldToFixedCoordinates=fixedCoordinateMapping)
......
......@@ -141,6 +141,14 @@ class ParallelDataHandling(DataHandling):
array = array[:, :, 0]
yield array
def runKernel(self, kernelFunc, *args, **kwargs):
fieldArguments = [p.fieldName for p in kernelFunc.ast.parameters if p.isFieldPtrArgument]
for block in self.blocks:
fieldArgs = {fieldName: wlb.field.toArray(block[fieldName], withGhostLayers=True)
for fieldName in fieldArguments}
fieldArgs.update(kwargs)
kernelFunc(*args, **kwargs)
def toCpu(self, name):
if name in self._customDataTransferFunctions:
transferFunc = self._customDataTransferFunctions[name][1]
......
......@@ -121,7 +121,7 @@ def makeLoopOverDomain(body, functionName, iterationSlice=None, ghostLayers=None
currentBody.insertFront(assignment)
loopVars = [numBufferAccesses * var for var in loopVars]
astNode = ast.KernelFunction(currentBody, ghostLayers=ghostLayers, functionName=functionName)
astNode = ast.KernelFunction(currentBody, ghostLayers=ghostLayers, functionName=functionName, backend='cpu')
return (astNode, loopStrides, loopVars)
......
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