diff --git a/examples/laplace2d.py b/examples/laplace2d.py index 383951f7341681a4a88de9332602bb7c54d435cd..0d879b82439e641a4078ac07b63783042a5cb9de 100644 --- a/examples/laplace2d.py +++ b/examples/laplace2d.py @@ -38,6 +38,7 @@ else: import numpy as np import pyopencl as cl +import pyopencl.array from volumential.tools import ScalarFieldExpressionEvaluation as Eval import pymbolic as pmbl diff --git a/examples/laplace3d.py b/examples/laplace3d.py index 31e96153e26258578217512b0c79d21d6a304678..eed3063209564e1eb172e94908e51e24adfb29da 100644 --- a/examples/laplace3d.py +++ b/examples/laplace3d.py @@ -29,6 +29,7 @@ import logging import numpy as np import pyopencl as cl +import pyopencl.array import pymbolic as pmbl import pymbolic.functions diff --git a/volumential/droste.py b/volumential/droste.py index e594bf9fe5ecdda4a412a4e6decb7e03f820b5ad..48362251bd84af232ea2d80a4ee238ec76bfaccc 100644 --- a/volumential/droste.py +++ b/volumential/droste.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, division, print_function - __copyright__ = "Copyright (C) 2018 Xiaoyu Wei" __license__ = """ @@ -268,14 +266,14 @@ class DrosteBase(KernelCacheWrapper): ] from sumpy.symbolic import SympyToPymbolicMapper - + from sumpy.tools import ScalingAssignmentTag sympy_conv = SympyToPymbolicMapper() scaling_assignment = lp.Assignment( id=None, assignee="knl_scaling", expression=sympy_conv(self.integral_knl.get_global_scaling_const()), - temp_var_type=lp.Optional(), - ) + temp_var_type=lp.Optional(lp.auto), + tags=frozenset([ScalingAssignmentTag()])) return quad_kernel_insns + [scaling_assignment] @@ -524,10 +522,10 @@ class DrosteBase(KernelCacheWrapper): for iaxis template_target[iaxis] = if( template_target[iaxis] > 1, - 1, + 1.0, if( template_target[iaxis] < 0, - 0, + 0.0, template_target[iaxis]) ) {id=tplt_tgt4,dup=iaxis,dep=tplt_tgt3} end diff --git a/volumential/expansion_wrangler_fpnd.py b/volumential/expansion_wrangler_fpnd.py index b691f63f4d7edd57cb36c2dd68f229d47f2d88a6..95b47d7d281dfd87433d371a4c859d6b38c9cb8b 100644 --- a/volumential/expansion_wrangler_fpnd.py +++ b/volumential/expansion_wrangler_fpnd.py @@ -121,6 +121,7 @@ class FPNDSumpyExpansionWrangler( kernel_extra_kwargs=None, self_extra_kwargs=None, list1_extra_kwargs=None, + translation_classes_data=None, ): """ near_field_table can either one of three things: @@ -128,10 +129,12 @@ class FPNDSumpyExpansionWrangler( 2. a list of tables, when len(target_kernels) = 1 (multiple levels) 3. otherwise, a dictionary from kernel.__repr__() to a list of its tables """ + if source_extra_kwargs is None: + source_extra_kwargs = {} - self.code = code_container - self.queue = queue - self.tree = tree + super().__init__( + code_container, queue, tree, dtype, fmm_level_to_order, + source_extra_kwargs, kernel_extra_kwargs, translation_classes_data) self.near_field_table = {} # list of tables for a single out kernel @@ -236,39 +239,11 @@ class FPNDSumpyExpansionWrangler( # deferred until trav.target_boxes is passed when invoking # eval_direct - self.dtype = dtype - - if source_extra_kwargs is None: - source_extra_kwargs = {} - - if kernel_extra_kwargs is None: - kernel_extra_kwargs = {} - - if self_extra_kwargs is None: - self_extra_kwargs = {} - if list1_extra_kwargs is None: list1_extra_kwargs = {} - - if not callable(fmm_level_to_order): - raise TypeError("fmm_level_to_order not passed") - - base_kernel = code_container.get_base_kernel() - kernel_arg_set = frozenset(kernel_extra_kwargs.items()) - self.level_orders = [ - fmm_level_to_order(base_kernel, kernel_arg_set, tree, lev) - for lev in range(tree.nlevels) - ] - - # print("Multipole order = ",self.level_orders) - - self.source_extra_kwargs = source_extra_kwargs - self.kernel_extra_kwargs = kernel_extra_kwargs - self.self_extra_kwargs = self_extra_kwargs self.list1_extra_kwargs = list1_extra_kwargs - self.extra_kwargs = source_extra_kwargs.copy() - self.extra_kwargs.update(self.kernel_extra_kwargs) + # print("Multipole order = ",self.level_orders) # }}} End constructor diff --git a/volumential/list1.py b/volumential/list1.py index e845589c9bc7973dfb82dae2555e884de6070ca4..10bb1bf3d671c121a0e4b14257feb22360fa860b 100644 --- a/volumential/list1.py +++ b/volumential/list1.py @@ -465,6 +465,8 @@ class NearFieldFromCSR(NearFieldEvalBase): def __call__(self, queue, **kwargs): knl = self.get_cached_optimized_kernel() + from loopy.target.opencl import OpenCLCallable + knl = loopy.register_callable(knl, "round", OpenCLCallable("round")) result = kwargs.pop("result") box_centers = kwargs.pop("box_centers") @@ -501,9 +503,11 @@ class NearFieldFromCSR(NearFieldEvalBase): integral_kernel_init_kargs[key] = np.float64(val) extra_knl_args_from_init = {} - for key, val in integral_kernel_init_kargs.items(): - if key in knl.arg_dict: - extra_knl_args_from_init[key] = val + if 0: + # loopy kernel no longer has arg_dict + for key, val in integral_kernel_init_kargs.items(): + if key in knl.arg_dict: + extra_knl_args_from_init[key] = val evt, res = knl( queue, diff --git a/volumential/symbolic.py b/volumential/symbolic.py index 1c5f9ec80390705a5b3183b2eaf5ae99627dfb78..a16e98e6bb08bed7ee4f369a960aafb291f1788e 100644 --- a/volumential/symbolic.py +++ b/volumential/symbolic.py @@ -126,9 +126,7 @@ def get_evaluator(dim, expression, variables=None): assert len(variables) == dim return ScalarFieldExpressionEvaluation( - dim=dim, - expression=expression, - variables=variables, - function_manglers=[math_func_mangler]) + dim=dim, expression=expression, + variables=variables) # }}} End evaluation helper diff --git a/volumential/tools.py b/volumential/tools.py index d5bc2139f70fb07b0a207def7b087b515956d54d..66dfc14a80ac2d069c177182c3709d1bcaebf378 100644 --- a/volumential/tools.py +++ b/volumential/tools.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import, division, print_function import six __copyright__ = "Copyright (C) 2018 Xiaoyu Wei" @@ -133,7 +132,7 @@ class ScalarFieldExpressionEvaluation(KernelCacheWrapper): """ def __init__(self, dim, expression, variables=None, dtype=np.float64, - function_manglers=None, preamble_generators=None): + preamble_generators=None): """ :arg dim :arg expression A pymbolic expression for the function @@ -142,19 +141,22 @@ class ScalarFieldExpressionEvaluation(KernelCacheWrapper): assert dim > 0 self.dim = dim - assert isinstance(expression, (ExpressionType, int, float, complex)) - self.expr = expression + if isinstance(expression, (ExpressionType, int, float, complex)): + self.expr = expression + else: + from pymbolic.interop.sympy import SympyToPymbolicMapper + stpm = SympyToPymbolicMapper() + self.expr = stpm(expression) if variables is None: self.vars = [pmbl.var("x%d" % d) for d in range(self.dim)] else: assert isinstance(variables, list) - for var in variables: - assert isinstance(var, VariableType) + variables = [var if isinstance(var, VariableType) + else stpm(var) for var in variables] self.vars = variables self.dtype = dtype - self.function_manglers = function_manglers self.preamble_generators = preamble_generators self.name = "ScalarFieldExpressionEvaluation" @@ -239,11 +241,6 @@ class ScalarFieldExpressionEvaluation(KernelCacheWrapper): loopy_knl = lp.set_options(loopy_knl, write_cl=False) loopy_knl = lp.set_options(loopy_knl, return_dict=True) - if self.function_manglers is not None: - loopy_knl = lp.register_function_manglers( - loopy_knl, - self.function_manglers) - if self.preamble_generators is not None: loopy_knl = lp.register_preamble_generators( loopy_knl, @@ -289,10 +286,6 @@ class ScalarFieldExpressionEvaluation(KernelCacheWrapper): knl = self.get_cached_optimized_kernel() - # FIXME: caching loses function mangler information - if self.function_manglers is not None: - knl = lp.register_function_manglers(knl, self.function_manglers) - if self.preamble_generators is not None: knl = lp.register_preamble_generators(knl, self.preamble_generators)