diff --git a/HySoP/hysop/gpu/config_default.py b/HySoP/hysop/gpu/config_default.py index dcf2a89a72252747ac79b2253eab241ca0dcaea3..2ddb6fa774b0e3dcb568bfec7bec116bf630b5fe 100644 --- a/HySoP/hysop/gpu/config_default.py +++ b/HySoP/hysop/gpu/config_default.py @@ -177,3 +177,45 @@ kernels_config[3][FLOAT_GPU]['diffusion'] = \ 16, 1, 1, lambda size, nb_part, tile: ((size[0], size[1] / nb_part), (tile, tile / nb_part))) + + +kernels_config[3][DOUBLE_GPU]['advec_comm'] = \ + (['common.cl', 'kernels/comm_advection_noVec.cl'], + False, 1, advection_index_space_3d) +kernels_config[3][DOUBLE_GPU]['advec_MS_comm'] = \ + (['common.cl', "remeshing/weights_noVec_builtin.cl", + 'kernels/comm_MS_advection_noVec.cl'], + False, 1, advection_index_space_3d) +kernels_config[3][DOUBLE_GPU]['remesh_comm'] = \ + (['common.cl', 'remeshing/weights_noVec.cl', + 'kernels/comm_remeshing_noVec.cl'], + False, 1, remeshing_index_space_3d) +kernels_config[3][DOUBLE_GPU]['advec_and_remesh_comm'] = \ + (['common.cl', 'remeshing/weights_noVec.cl', + 'kernels/comm_advection_and_remeshing_noVec.cl'], + False, 1, advection_and_remeshing_index_space) +kernels_config[3][DOUBLE_GPU]['advec_MS_and_remesh_comm'] = \ + (['common.cl', 'remeshing/weights_noVec.cl', + 'kernels/comm_advection_MS_and_remeshing_noVec.cl'], + False, 1, advection_and_remeshing_index_space) + + +kernels_config[3][FLOAT_GPU]['advec_comm'] = \ + (['common.cl', 'kernels/comm_advection_noVec.cl'], + False, 1, advection_index_space_3d) +kernels_config[3][FLOAT_GPU]['advec_MS_comm'] = \ + (['common.cl', "remeshing/weights_noVec_builtin.cl", + 'kernels/comm_MS_advection_noVec.cl'], + False, 1, advection_index_space_3d) +kernels_config[3][FLOAT_GPU]['remesh_comm'] = \ + (['common.cl', 'remeshing/weights_noVec.cl', + 'kernels/comm_remeshing_noVec.cl'], + False, 1, remeshing_index_space_3d) +kernels_config[3][FLOAT_GPU]['advec_and_remesh_comm'] = \ + (['common.cl', 'remeshing/weights_noVec.cl', + 'kernels/comm_advection_and_remeshing_noVec.cl'], + False, 1, advection_and_remeshing_index_space) +kernels_config[3][FLOAT_GPU]['advec_MS_and_remesh_comm'] = \ + (['common.cl', 'remeshing/weights_noVec.cl', + 'kernels/comm_advection_MS_and_remeshing_noVec.cl'], + False, 1, advection_and_remeshing_index_space) diff --git a/HySoP/hysop/gpu/gpu_diffusion.py b/HySoP/hysop/gpu/gpu_diffusion.py index aa6c3656cb12085e460765359cdf481f8d088393..0758a4581102465c0dc4c5a96ed53bbe1ed25064 100644 --- a/HySoP/hysop/gpu/gpu_diffusion.py +++ b/HySoP/hysop/gpu/gpu_diffusion.py @@ -7,6 +7,7 @@ from hysop.constants import debug, np, S_DIR, HYSOP_MPI_REAL, ORDERMPI, \ HYSOP_REAL, ORDER import hysop.tools.numpywrappers as npw from hysop.operator.discrete.discrete import DiscreteOperator +from hysop.operator.discrete.discrete import get_extra_args_from_method from hysop.gpu import cl from hysop.gpu.gpu_operator import GPUOperator from hysop.gpu.gpu_kernel import KernelLauncher @@ -18,8 +19,7 @@ from hysop.mpi.main_var import MPI class GPUDiffusion(DiscreteOperator, GPUOperator): @debug - def __init__(self, field, viscosity, field_tmp=None, - platform_id=None, device_id=None, device_type=None, **kwds): + def __init__(self, field, viscosity, **kwds): super(GPUDiffusion, self).__init__(variables=[field], **kwds) ## Discretisation of the solution field self.field = self.variables[0] @@ -30,10 +30,12 @@ class GPUDiffusion(DiscreteOperator, GPUOperator): self.direction = 0 self._cl_work_size = 0 - GPUOperator.__init__(self, platform_id=platform_id, - device_id=device_id, - device_type=device_type, - **kwds) + GPUOperator.__init__( + self, + platform_id=get_extra_args_from_method(self, 'platform_id', None), + device_id=get_extra_args_from_method(self, 'device_id', None), + device_type=get_extra_args_from_method(self, 'device_type', None), + **kwds) ## GPU allocation. alloc = not isinstance(self.field, GPUDiscreteField) @@ -44,7 +46,7 @@ class GPUDiffusion(DiscreteOperator, GPUOperator): if alloc: self.size_global_alloc += self.field.mem_size - self.field_tmp = field_tmp + self.field_tmp = get_extra_args_from_method(self, 'field_tmp', None), topo = self.field.topology self._cutdir_list = np.where(topo.cutdir)[0].tolist() diff --git a/HySoP/hysop/gpu/gpu_particle_advection.py b/HySoP/hysop/gpu/gpu_particle_advection.py index 110ca4d6cc7219398a894d8f6bb335c1493dc26c..9a2800c0cb1d710c037be12c261caab8e643fc69 100644 --- a/HySoP/hysop/gpu/gpu_particle_advection.py +++ b/HySoP/hysop/gpu/gpu_particle_advection.py @@ -10,6 +10,7 @@ from hysop.methods_keys import TimeIntegrator, Remesh, \ Support, Splitting, MultiScale from hysop.numerics.integrators.euler import Euler from hysop.operator.discrete.particle_advection import ParticleAdvection +from hysop.operator.discrete.discrete import get_extra_args_from_method from hysop.gpu import cl from hysop.gpu.gpu_kernel import KernelLauncher import hysop.default_methods as default @@ -27,9 +28,7 @@ class GPUParticleAdvection(ParticleAdvection, GPUOperator): __metaclass__ = ABCMeta @debug - def __init__(self, platform_id=None, device_id=None, device_type=None, - user_src=None, max_velocity=None, max_dt=None, - velocity_only_on_device=None, **kwds): + def __init__(self, **kwds): """ Create a Advection operator. Work on a given field (scalar or vector) at a given velocity to compute @@ -40,8 +39,6 @@ class GPUParticleAdvection(ParticleAdvection, GPUOperator): @param velocity : Velocity field @param fields_on_grid : Advected fields @param d : Direction to advect - @param platform_id : OpenCL platform id (default = 0). - @param device_id : OpenCL device id (default = 0). @param device_type : OpenCL device type (default = 'gpu'). @param method : the method to use. {'m4prime', 'm6prime', 'm8prime', 'l6star'} @@ -62,15 +59,20 @@ class GPUParticleAdvection(ParticleAdvection, GPUOperator): self._comm_size = self._comm.Get_size() self._comm_rank = self._comm.Get_rank() + user_src = get_extra_args_from_method(self, 'user_src', None) + # init the second base class (the previous super only call # the fist __init__ method found in the order of # [ParticleAdvection, GPUOperator], i.e. ParticleAdvection.__init__) # the GPUOperator.__init__ must be explicitely called. # see http://stackoverflow.com/questions/3277367/how-does-pythons-super-work-with-multiple-inheritance - GPUOperator.__init__(self, platform_id=platform_id, - device_id=device_id, - device_type=device_type, - user_src=user_src, **kwds) + GPUOperator.__init__( + self, + platform_id=get_extra_args_from_method(self, 'platform_id', None), + device_id=get_extra_args_from_method(self, 'device_id', None), + device_type=get_extra_args_from_method(self, 'device_type', None), + user_src=user_src, + **kwds) ## Work arrays for fields on particles (cpu) self.fields_on_part = None diff --git a/HySoP/hysop/gpu/multi_gpu_particle_advection.py b/HySoP/hysop/gpu/multi_gpu_particle_advection.py index e7e58fbe7430b37d3a4e2f71c990f93e51447123..623f577a2892837d87c107aa971d56bf7965cf1a 100644 --- a/HySoP/hysop/gpu/multi_gpu_particle_advection.py +++ b/HySoP/hysop/gpu/multi_gpu_particle_advection.py @@ -7,6 +7,7 @@ from abc import ABCMeta from hysop.constants import np, debug, HYSOP_INTEGER, HYSOP_REAL, ORDER,\ HYSOP_MPI_REAL, SIZEOF_HYSOP_REAL from hysop.gpu.gpu_particle_advection import GPUParticleAdvection +from hysop.operator.discrete.discrete import get_extra_args_from_method from hysop.methods_keys import Support, TimeIntegrator, MultiScale, Remesh from hysop.numerics.integrators.runge_kutta2 import RK2 from hysop.numerics.remeshing import Linear as Linear_rmsh @@ -25,8 +26,7 @@ class MultiGPUParticleAdvection(GPUParticleAdvection): __metaclass__ = ABCMeta @debug - def __init__(self, max_velocity=None, max_dt=None, - velocity_only_on_device=False, **kwds): + def __init__(self, **kwds): """ Create a Advection operator. Work on a given field (scalar or vector) at a given velocity to compute @@ -49,7 +49,10 @@ class MultiGPUParticleAdvection(GPUParticleAdvection): # self._is_cut_dir = self._cut_dir[direction] super(MultiGPUParticleAdvection, self).__init__(**kwds) - self._velocity_only_on_device = velocity_only_on_device + max_velocity = get_extra_args_from_method(self, 'max_velocity', None) + max_dt = get_extra_args_from_method(self, 'max_dt', None) + self._velocity_only_on_device = get_extra_args_from_method( + self, 'velocity_only_on_device', False), if self._velocity_only_on_device: self._get_velocity_buffers = self._get_velocity_buffers_from_device else: diff --git a/HySoP/hysop/methods_keys.py b/HySoP/hysop/methods_keys.py index 4344973ca795ccbeae766ff047c10eaba4f4f1f9..a4505dee4b5301303b6c6941c356bd9583a6cc11 100644 --- a/HySoP/hysop/methods_keys.py +++ b/HySoP/hysop/methods_keys.py @@ -41,3 +41,5 @@ dtCrit = 0 MultiScale = 12345 ## Float precision for advection Precision = 12346 +## Extra arguments for discrete operators +ExtraArgs = 9876 diff --git a/HySoP/hysop/operator/advection_dir.py b/HySoP/hysop/operator/advection_dir.py index a0be9e057b6dddc385b7fefea018161a31410ab5..bb44a50e7396e95932922c1e944c6cf84d5cce3d 100644 --- a/HySoP/hysop/operator/advection_dir.py +++ b/HySoP/hysop/operator/advection_dir.py @@ -5,13 +5,13 @@ Advection of a field in a single direction. """ from hysop.constants import debug, S_DIR from hysop.methods_keys import Support, MultiScale, \ - TimeIntegrator, Interpolation, Remesh + TimeIntegrator, Interpolation, Remesh, ExtraArgs from hysop.numerics.remeshing import L2_1, L4_2, L4_4, Remeshing, Linear from hysop.operator.computational import Computational # To get default method values for advection: import hysop.default_methods as default import numpy as np -from hysop.operator.continuous import opsetup, opapply +from hysop.operator.continuous import opsetup, opapply, Tools class AdvectionDir(Computational): diff --git a/HySoP/hysop/operator/discrete/discrete.py b/HySoP/hysop/operator/discrete/discrete.py index 0ba75204d522e190d45d2fd8fa675528198c6660..e24b24701eebb8d599532e1fdcc76e997053e807 100644 --- a/HySoP/hysop/operator/discrete/discrete.py +++ b/HySoP/hysop/operator/discrete/discrete.py @@ -45,14 +45,14 @@ class DiscreteOperator(object): domain : physical domain input : fields used as input (i.e. read-only) output : fields used as in/out (i.e. modified during apply call) - + Notes ----- Methods : to be done ... MPIParams : to be done ... - + """ if isinstance(variables, list): # variables @@ -185,3 +185,25 @@ class DiscreteOperator(object): def get_profiling_info(self): """Get the manual profiler informations into the default profiler""" pass + + +def get_extra_args_from_method(op, key, default_value): + """ + Returns the given extra arguments dictionary from method attribute. + + Parameters + ----------- + op : operator + extract method attribute from + key : string + key to extract + default_value : + default value when ExtraArgs is not in op.method or + key is not in op.method[ExtraArgs] + + """ + from hysop.methods_keys import ExtraArgs + try: + return op.method[ExtraArgs][key] + except KeyError: + return default_value