Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

WIP: Add a non-forking compiler option #614

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 113 additions & 28 deletions pyop2/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,16 @@ def __init__(self, data=None, map=None, access=None, lgmaps=None, unroll_map=Fal
"To set of %s doesn't match the set of %s." % (map, data))

@cached_property
def _kernel_args_(self):
return self.data._kernel_args_
def ctypes_args(self):
return self.data.ctypes_args

@property
def cffi_args(self):
return self.data.cffi_args

@property
def cppyy_args(self):
return self.data.cppyy_args

@cached_property
def _argtypes_(self):
Expand Down Expand Up @@ -403,7 +411,9 @@ class Set(object):

_extruded = False

_kernel_args_ = ()
ctypes_args = ()
cffi_args = ()
cppyy_args = ()
_argtypes_ = ()

@cached_property
Expand Down Expand Up @@ -531,7 +541,9 @@ class GlobalSet(Set):
"""A proxy set allowing a :class:`Global` to be used in place of a
:class:`Dat` where appropriate."""

_kernel_args_ = ()
ctypes_args = ()
cffi_args = ()
cppyy_args = ()
_argtypes_ = ()

def __init__(self, comm=None):
Expand Down Expand Up @@ -642,8 +654,16 @@ def __init__(self, parent, layers):
self._extruded = True

@cached_property
def _kernel_args_(self):
return (self.layers_array.ctypes.data, )
def ctypes_args(self):
return (self.layers_array.ctypes.data,)

@property
def cffi_args(self):
return NotImplemented

@property
def cppyy_args(self):
return (self._layers,)

@cached_property
def _argtypes_(self):
Expand Down Expand Up @@ -723,8 +743,16 @@ def __init__(self, superset, indices):
self._extruded = superset._extruded

@cached_property
def _kernel_args_(self):
return self._superset._kernel_args_ + (self._indices.ctypes.data, )
def ctypes_args(self):
return self._superset.ctypes_args + (self._indices.ctypes.data,)

@property
def cffi_args(self):
return NotImplemented

@property
def cppyy_args(self):
return self._superset.cppyy_args + (self._indices,)

@cached_property
def _argtypes_(self):
Expand Down Expand Up @@ -782,8 +810,8 @@ def layers_array(self):
class SetPartition(object):
def __init__(self, set, offset, size):
self.set = set
self.offset = offset
self.size = size
self.offset = int(offset)
self.size = int(size)


class MixedSet(Set, ObjectCached):
Expand All @@ -800,8 +828,16 @@ def __init__(self, sets):
self.comm = reduce(lambda a, b: a or b, map(lambda s: s if s is None else s.comm, sets))
self._initialized = True

@cached_property
def _kernel_args_(self):
@property
def ctypes_args(self):
raise NotImplementedError

@property
def cffi_args(self):
raise NotImplementedError

@property
def cppyy_args(self):
raise NotImplementedError

@cached_property
Expand Down Expand Up @@ -1370,9 +1406,17 @@ def __init__(self, dataset, data=None, dtype=None, name=None):
self.halo_valid = True
self._name = name or "dat_#x%x" % id(self)

@cached_property
def _kernel_args_(self):
return (self._data.ctypes.data, )
@property
def ctypes_args(self):
return (self._data.ctypes.data,)

@property
def cffi_args(self):
raise NotImplementedError

@property
def cppyy_args(self):
return (self._data,)

@cached_property
def _argtypes_(self):
Expand Down Expand Up @@ -1587,6 +1631,7 @@ def _copy_parloop(self, other, subset=None):
if not hasattr(self, '_copy_kernel'):
import islpy as isl
import pymbolic.primitives as p
name = f"copy_{id(self)}"
inames = isl.make_zero_and_vars(["i"])
domain = (inames[0].le_set(inames["i"])) & (inames["i"].lt_set(inames[0] + self.cdim))
_other = p.Variable("other")
Expand All @@ -1595,9 +1640,9 @@ def _copy_parloop(self, other, subset=None):
insn = loopy.Assignment(_other.index(i), _self.index(i), within_inames=frozenset(["i"]))
data = [loopy.GlobalArg("self", dtype=self.dtype, shape=(self.cdim,)),
loopy.GlobalArg("other", dtype=other.dtype, shape=(other.cdim,))]
knl = loopy.make_function([domain], [insn], data, name="copy")
knl = loopy.make_function([domain], [insn], data, name=name)

self._copy_kernel = _make_object('Kernel', knl, 'copy')
self._copy_kernel = _make_object('Kernel', knl, name)
return _make_object('ParLoop', self._copy_kernel,
subset or self.dataset.set,
self(READ), other(WRITE))
Expand Down Expand Up @@ -1923,9 +1968,17 @@ def __init__(self, dat, index):
name="view[%s](%s)" % (index, dat.name))
self._parent = dat

@cached_property
def _kernel_args_(self):
return self._parent._kernel_args_
@property
def ctypes_args(self):
return self._parent.ctypes_args

@property
def cffi_args(self):
raise NotImplementedError

@property
def cppyy_args(self):
return self._parent.cppyy_args

@cached_property
def _argtypes_(self):
Expand Down Expand Up @@ -2005,8 +2058,16 @@ def what(x):
self.comm = self._dats[0].comm

@cached_property
def _kernel_args_(self):
return tuple(itertools.chain(*(d._kernel_args_ for d in self)))
def ctypes_args(self):
return tuple(itertools.chain(*(d.ctypes_args for d in self)))

@cached_property
def cffi_args(self):
raise NotImplementedError

@cached_property
def cppyy_args(self):
return tuple(itertools.chain(*(d.cppyy_args for d in self)))

@cached_property
def _argtypes_(self):
Expand Down Expand Up @@ -2290,8 +2351,16 @@ def __init__(self, dim, data=None, dtype=None, name=None, comm=None):
self.comm = comm

@cached_property
def _kernel_args_(self):
return (self._data.ctypes.data, )
def ctypes_args(self):
return (self._data.ctypes.data,)

@cached_property
def cffi_args(self):
raise NotImplementedError

@cached_property
def cppyy_args(self):
return (self._data,)

@cached_property
def _argtypes_(self):
Expand Down Expand Up @@ -2528,8 +2597,16 @@ def __init__(self, iterset, toset, arity, values=None, name=None, offset=None):
self._cache = {}

@cached_property
def _kernel_args_(self):
return (self._values.ctypes.data, )
def ctypes_args(self):
return (self._values.ctypes.data,)

@cached_property
def cffi_args(self):
raise NotImplementedError

@cached_property
def cppyy_args(self):
return (self._values,)

@cached_property
def _argtypes_(self):
Expand Down Expand Up @@ -2654,8 +2731,16 @@ def _cache_key(cls, maps):
return maps

@cached_property
def _kernel_args_(self):
return tuple(itertools.chain(*(m._kernel_args_ for m in self if m is not None)))
def ctypes_args(self):
return tuple(itertools.chain(*(m.ctypes_args for m in self if m is not None)))

@cached_property
def cffi_args(self):
raise NotImplementedError

@cached_property
def cppyy_args(self):
return tuple(itertools.chain(*(m.cppyy_args for m in self if m is not None)))

@cached_property
def _argtypes_(self):
Expand Down
Loading