Skip to content
Snippets Groups Projects
Commit 0f7b69a5 authored by Jean-Baptiste Keck's avatar Jean-Baptiste Keck
Browse files

advection tweaks

parent 75469370
No related branches found
No related tags found
No related merge requests found
...@@ -51,7 +51,7 @@ def init_vorticity(data, coords, dim): ...@@ -51,7 +51,7 @@ def init_vorticity(data, coords, dim):
else: else:
raise NotImplementedError('dimension {}'.format(dim)) raise NotImplementedError('dimension {}'.format(dim))
def run(npts=256+1, viscosity=1./1600., lcfl=0.125, cfl=0.5): def run(npts=128+1, viscosity=1./1600., lcfl=0.125, cfl=0.5):
autotuner_config = AutotunerConfig(autotuner_flag=AutotunerFlags.ESTIMATE, autotuner_config = AutotunerConfig(autotuner_flag=AutotunerFlags.ESTIMATE,
prune_threshold=1.2, override_cache=True, verbose=0) prune_threshold=1.2, override_cache=True, verbose=0)
kernel_config = KernelConfig(autotuner_config=autotuner_config) kernel_config = KernelConfig(autotuner_config=autotuner_config)
...@@ -116,6 +116,5 @@ def run(npts=256+1, viscosity=1./1600., lcfl=0.125, cfl=0.5): ...@@ -116,6 +116,5 @@ def run(npts=256+1, viscosity=1./1600., lcfl=0.125, cfl=0.5):
problem.finalize() problem.finalize()
if __name__=='__main__': if __name__=='__main__':
N = 128 + 1 run()
run(N)
...@@ -147,6 +147,8 @@ class CartesianDiscreteFieldView(DiscreteFieldView): ...@@ -147,6 +147,8 @@ class CartesianDiscreteFieldView(DiscreteFieldView):
new_data arrays have to match dimension, size, shape and dtype of original data. new_data arrays have to match dimension, size, shape and dtype of original data.
""" """
raise NotImplementedError()
# TODO fix all data views update
msg='Discrete field {}::{}::swap_data(), swapping components {}.' msg='Discrete field {}::{}::swap_data(), swapping components {}.'
msg=msg.format(self.backend.kind, self.name, components) msg=msg.format(self.backend.kind, self.name, components)
dprint(msg) dprint(msg)
...@@ -168,12 +170,7 @@ class CartesianDiscreteFieldView(DiscreteFieldView): ...@@ -168,12 +170,7 @@ class CartesianDiscreteFieldView(DiscreteFieldView):
By default return all components. By default return all components.
""" """
data = self.__get_data_views(*components) data = self.__get_data_views(*components)
return tuple(d.handle for d in data)
if self.backend.kind != Backend.OPENCL:
return data
# cl.Buffer are wrapped so we extract them
return tuple(d.data for d in data)
def __getitem__(self, key): def __getitem__(self, key):
""" """
...@@ -330,7 +327,7 @@ CartesianDiscreteFieldView (id={}, tag={}) ...@@ -330,7 +327,7 @@ CartesianDiscreteFieldView (id={}, tag={})
formula(**formula_kwds) formula(**formula_kwds)
# update ghosts # update ghosts
self.exchange_ghosts(data=data) self.exchange_ghosts(data=(d.handle for d in data))
assert all((d.size == self.size) for d in data), 'Array size was altered.' assert all((d.size == self.size) for d in data), 'Array size was altered.'
assert all((d.dtype == self.dtype) for d in data), 'Array dtype was altered.' assert all((d.dtype == self.dtype) for d in data), 'Array dtype was altered.'
...@@ -401,8 +398,7 @@ CartesianDiscreteFieldView (id={}, tag={}) ...@@ -401,8 +398,7 @@ CartesianDiscreteFieldView (id={}, tag={})
components = to_tuple(components or range(self.nb_components)) components = to_tuple(components or range(self.nb_components))
directions = to_tuple(directions or range(self.dim)) directions = to_tuple(directions or range(self.dim))
data = data or self.data data = to_tuple(data or self.buffers)
data = tuple(d.handle if isinstance(d,Array) else d for d in data)
# exchange_ghosts currently only supports hosts buffers # exchange_ghosts currently only supports hosts buffers
check_instance(data, tuple, values=np.ndarray) check_instance(data, tuple, values=np.ndarray)
......
...@@ -59,6 +59,17 @@ class TestTransposeOperator(object): ...@@ -59,6 +59,17 @@ class TestTransposeOperator(object):
dim=dim, dtype=dtype, is_inplace=is_inplace, dim=dim, dtype=dtype, is_inplace=is_inplace,
domain=domain, Fin=Fin, Fout=Fout) domain=domain, Fin=Fin, Fout=Fout)
@classmethod
def __field_init(data, coords, dtype):
shape = data[0].shape
if is_integer(dtype):
data[0][...] = np.random.random_integer(low=0, high=255, shape=shape)
elif is_fp(dtype)
data[0][...] = np.random.random(shape=shape)
else:
msg='Unknown dtype {}.'.format(dtype)
raise NotImplementedError(msg)
def _test_one(self, cl_env, shape, axes, def _test_one(self, cl_env, shape, axes,
dim, dtype, is_inplace, dim, dtype, is_inplace,
domain, Fin, Fout): domain, Fin, Fout):
...@@ -72,17 +83,15 @@ class TestTransposeOperator(object): ...@@ -72,17 +83,15 @@ class TestTransposeOperator(object):
fin, fout = Fin, Fout fin, fout = Fin, Fout
variables = { fin: shape, fout: shape } variables = { fin: shape, fout: shape }
transpose_cpu = Transpose(fields=fin, output_fields=fout, for impl in Transpose.available_implementations():
tranpose = Transpose(fields=fin, output_fields=fout,
variables=variables, axes=axes, variables=variables, axes=axes,
implementation=Implementation.PYTHON, implementation=impl,
name='test_transpose_cpu').build() name='test_transpose_{}'.format(str(impl))).build()
dfin, dfout = transpose.input_vars[fin], transpose.output_vars[fout]
transpose_gpu = Transpose(fields=fin, output_fields=fout, dfin.initialize(self.__field_init)
variables=variables, axes=axes, import sys
implementation=Implementation.OPENCL_CODEGEN, sys.exit(1)
name='test_transpose_gpu', cl_env=cl_env).build()
@opencl_failed @opencl_failed
......
from hysop.deps import np from hysop.deps import np
from collections import Iterable
class InstanceOf(object): class InstanceOf(object):
def __init__(self, cls): def __init__(self, cls):
...@@ -215,7 +216,7 @@ def to_tuple(arg, cast=None): ...@@ -215,7 +216,7 @@ def to_tuple(arg, cast=None):
as a tuple. as a tuple.
""" """
cast = cast or (lambda x: x) cast = cast or (lambda x: x)
if isinstance(arg, (tuple,list,frozenset,set,np.ndarray)): if isinstance(arg, (tuple,list,frozenset,set,np.ndarray,Iterable)):
return tuple(cast(x) for x in arg) return tuple(cast(x) for x in arg)
else: else:
return (cast(arg),) return (cast(arg),)
...@@ -227,7 +228,7 @@ def to_list(arg, cast=None): ...@@ -227,7 +228,7 @@ def to_list(arg, cast=None):
as a list. as a list.
""" """
cast = cast or (lambda x: x) cast = cast or (lambda x: x)
if isinstance(arg, (tuple,list,frozenset,set,np.ndarray)): if isinstance(arg, (tuple,list,frozenset,set,np.ndarray,Iterable)):
return list(cast(x) for x in arg) return list(cast(x) for x in arg)
else: else:
return [cast(arg),] return [cast(arg),]
...@@ -239,7 +240,7 @@ def to_set(arg, cast=None): ...@@ -239,7 +240,7 @@ def to_set(arg, cast=None):
as a set. as a set.
""" """
cast = cast or (lambda x: x) cast = cast or (lambda x: x)
if isinstance(arg, (tuple,list,frozenset,set,np.ndarray)): if isinstance(arg, (tuple,list,frozenset,set,np.ndarray,Iterable)):
return set(cast(x) for x in arg) return set(cast(x) for x in arg)
else: else:
return set((cast(arg),)) return set((cast(arg),))
...@@ -251,7 +252,7 @@ def to_frozenset(arg, cast=None): ...@@ -251,7 +252,7 @@ def to_frozenset(arg, cast=None):
as a frozenset. as a frozenset.
""" """
cast = cast or (lambda x: x) cast = cast or (lambda x: x)
if isinstance(arg, (tuple,list,frozenset,set,np.ndarray)): if isinstance(arg, (tuple,list,frozenset,set,np.ndarray,Iterable)):
return frozenset(cast(x) for x in arg) return frozenset(cast(x) for x in arg)
else: else:
return frozenset((cast(arg),)) return frozenset((cast(arg),))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment