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

pystencils cleanup

- single function to create kernel for specified target
- data type creation from string - reuse numpy functionality
- bugfixes in dot display
parent 25bf6c7b
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ from pystencils.astnodes import SympyAssignment ...@@ -5,7 +5,7 @@ from pystencils.astnodes import SympyAssignment
from pystencils.sympyextensions import getSymmetricPart from pystencils.sympyextensions import getSymmetricPart
from pystencils import Field from pystencils import Field
from lbmpy.boundaries.boundary_kernel import offsetFromDir, weightOfDirection, invDir from lbmpy.boundaries.boundary_kernel import offsetFromDir, weightOfDirection, invDir
from pystencils.data_types import createTypeFromString from pystencils.data_types import createType
class Boundary(object): class Boundary(object):
...@@ -87,7 +87,7 @@ class NoSlipFullWay(Boundary): ...@@ -87,7 +87,7 @@ class NoSlipFullWay(Boundary):
@property @property
def additionalData(self): def additionalData(self):
return [('lastValue', createTypeFromString("double"))] return [('lastValue', createType("double"))]
@property @property
def additionalDataInitKernelEquations(self): def additionalDataInitKernelEquations(self):
...@@ -133,7 +133,7 @@ class UBB(Boundary): ...@@ -133,7 +133,7 @@ class UBB(Boundary):
@property @property
def additionalData(self): def additionalData(self):
if callable(self._velocity): if callable(self._velocity):
return [('vel_%d' % (i,), createTypeFromString("double")) for i in range(self.dim)] return [('vel_%d' % (i,), createType("double")) for i in range(self.dim)]
else: else:
return [] return []
......
...@@ -146,9 +146,7 @@ For example, to modify the AST one can run:: ...@@ -146,9 +146,7 @@ For example, to modify the AST one can run::
""" """
import sympy as sp import sympy as sp
from copy import copy from copy import copy
from functools import partial from pystencils.cache import diskcache
import json
from pystencils.cache import diskcache, SympyJSONDecoder, SympyJSONEncoder
from lbmpy.methods import createSRT, createTRT, createOrthogonalMRT, createKBCTypeTRT, \ from lbmpy.methods import createSRT, createTRT, createOrthogonalMRT, createKBCTypeTRT, \
createRawMRT, createThreeRelaxationRateMRT createRawMRT, createThreeRelaxationRateMRT
from lbmpy.methods.entropic import addIterativeEntropyCondition, addEntropyCondition from lbmpy.methods.entropic import addIterativeEntropyCondition, addEntropyCondition
...@@ -161,6 +159,7 @@ from lbmpy.updatekernels import StreamPullTwoFieldsAccessor, PeriodicTwoFieldsAc ...@@ -161,6 +159,7 @@ from lbmpy.updatekernels import StreamPullTwoFieldsAccessor, PeriodicTwoFieldsAc
createLBMKernel createLBMKernel
from pystencils.equationcollection.equationcollection import EquationCollection from pystencils.equationcollection.equationcollection import EquationCollection
from pystencils.field import getLayoutOfArray, Field from pystencils.field import getLayoutOfArray, Field
from pystencils import createKernel
def updateWithDefaultParameters(params, optParams, failOnUnknownParameter=True): def updateWithDefaultParameters(params, optParams, failOnUnknownParameter=True):
...@@ -276,22 +275,7 @@ def createLatticeBoltzmannFunction(ast=None, optimizationParams={}, **kwargs): ...@@ -276,22 +275,7 @@ def createLatticeBoltzmannFunction(ast=None, optimizationParams={}, **kwargs):
params['optimizationParams'] = optParams params['optimizationParams'] = optParams
ast = createLatticeBoltzmannAst(**params) ast = createLatticeBoltzmannAst(**params)
if optParams['target'] == 'cpu': res = ast.compile()
if optParams['vectorization']:
import pystencils.backends.simd_instruction_sets as vec
from pystencils.vectorization import vectorize
vecParams = optParams['vectorization']
vec.selectedInstructionSet = vec.x86VectorInstructionSet(instructionSet=vecParams[0], dataType=vecParams[1])
vectorize(ast)
from pystencils.cpu import makePythonFunction as makePythonCpuFunction, addOpenMP
addOpenMP(ast, numThreads=optParams['openMP'])
res = makePythonCpuFunction(ast)
elif optParams['target'] == 'gpu':
from pystencils.gpucuda import makePythonFunction as makePythonGpuFunction
res = makePythonGpuFunction(ast)
else:
return ValueError("'target' has to be either 'cpu' or 'gpu'")
res.method = ast.method res.method = ast.method
res.updateRule = ast.updateRule res.updateRule = ast.updateRule
...@@ -306,36 +290,10 @@ def createLatticeBoltzmannAst(updateRule=None, optimizationParams={}, **kwargs): ...@@ -306,36 +290,10 @@ def createLatticeBoltzmannAst(updateRule=None, optimizationParams={}, **kwargs):
params['optimizationParams'] = optimizationParams params['optimizationParams'] = optimizationParams
updateRule = createLatticeBoltzmannUpdateRule(**params) updateRule = createLatticeBoltzmannUpdateRule(**params)
if optParams['target'] == 'cpu': dtype = 'double' if optParams['doublePrecision'] else 'float32'
from pystencils.cpu import createKernel res = createKernel(updateRule, target=optParams['target'], dataType=dtype,
if 'splitGroups' in updateRule.simplificationHints: cpuOpenMP=optParams['openMP'], cpuVectorizeInfo=optParams['vectorization'],
splitGroups = updateRule.simplificationHints['splitGroups'] gpuIndexing=optParams['gpuIndexing'], gpuIndexingParams=optParams['gpuIndexingParams'])
else:
splitGroups = ()
res = createKernel(updateRule.allEquations, splitGroups=splitGroups,
typeForSymbol='double' if optParams['doublePrecision'] else 'float32',
ghostLayers=1)
elif optParams['target'] == 'gpu':
from pystencils.gpucuda import createCUDAKernel
from pystencils.gpucuda.indexing import LineIndexing, BlockIndexing
assert optParams['gpuIndexing'] in ('line', 'block')
indexingCreator = LineIndexing if optParams['gpuIndexing'] == 'line' else BlockIndexing
if optParams['gpuIndexingParams']:
indexingCreator = partial(indexingCreator, **optParams['gpuIndexingParams'])
res = createCUDAKernel(updateRule.allEquations,
typeForSymbol='double' if optParams['doublePrecision'] else 'float',
indexingCreator=indexingCreator, ghostLayers=1)
elif optParams['target'] == 'llvm':
from pystencils.llvm import createKernel
if 'splitGroups' in updateRule.simplificationHints:
splitGroups = updateRule.simplificationHints['splitGroups']
else:
splitGroups = ()
res = createKernel(updateRule.allEquations, splitGroups=splitGroups,
typeForSymbol='double' if optParams['doublePrecision'] else 'float',
ghostLayers=1)
else:
return ValueError("'target' has to be either 'cpu' or 'gpu'")
res.method = updateRule.method res.method = updateRule.method
res.updateRule = updateRule res.updateRule = updateRule
......
...@@ -89,6 +89,14 @@ import sympy as sp ...@@ -89,6 +89,14 @@ import sympy as sp
from lbmpy.methods.relaxationrates import getShearRelaxationRate from lbmpy.methods.relaxationrates import getShearRelaxationRate
class ScalarSource(object):
def __init__(self, source):
self._source = source
def __call__(self, lbMethod, **kwargs):
return [w_i * self._source for w_i in lbMethod.weights]
class Simple(object): class Simple(object):
r""" r"""
A simple force model which introduces the following additional force term in the A simple force model which introduces the following additional force term in the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment