Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raise NotImplementedError
def make_rotated_uniform_particle_array(queue, nparticles, dims, dtype, seed=15):
raise NotImplementedError
# }}}
def particle_array_to_host(parray):
return np.array([x.get() for x in parray], order="F").T
# {{{ host/device data storage
class DeviceDataRecord(Record):
"""A record of array-type data. Some of this data may live in
:class:`pyopencl.array.Array` objects. :meth:`get` can then be
called to convert all these device arrays into :mod:`numpy.ndarray`
instances on the host.
"""
def _transform_arrays(self, f, exclude_fields=frozenset()):
result = {}
def transform_val(val):
from pyopencl.algorithm import BuiltList
if isinstance(val, np.ndarray) and val.dtype == object:
from pytools.obj_array import obj_array_vectorize
return obj_array_vectorize(f, val)
elif isinstance(val, list):
return [transform_val(i) for i in val]
"""
:arg insn: An instruction name or instance of
:class:`loopy.instruction.InstructionBase`
:returns: A :class:`LivenessResult` associated with `insn`
"""
return self.liveness()[sched_idx]
# }}}
# {{{ save and reload implementation
class TemporarySaver(object):
class PromotedTemporary(Record):
"""
.. attribute:: name
The name of the new temporary.
.. attribute:: orig_temporary_name
The name of original temporary variable object.
.. attribute:: hw_dims
A list of expressions, to be added in front of the shape
of the promoted temporary value, corresponding to
hardware dimensions
.. attribute:: hw_tags
def __init__(self, source, kernel_name, scalar_arg_dtypes, update_wg_size):
Record.__init__(self,
source=source,
kernel_name=kernel_name,
scalar_arg_dtypes=scalar_arg_dtypes,
update_wg_size=update_wg_size)
self.term_set_to_inside_inames_list,
inside_inames)
count_mapper(expr.expr)
return expr
elif isinstance(expr, str) or is_constant(expr):
return expr
else:
raise LoopyError(
"Unexpected expression type: %s" % type(expr).__name__)
# }}}
# {{{ replacing
class SubexpressionReplacementState(Record):
"""
.. attribute:: codegen_state
.. attribute:: name_generator
A callable that can generate new identifiers.
.. attribute:: term_set_to_inside_inames_list
A mapping from (summed) sets of subexpressions to a list of tuples of inames
within which the use is nested, one per use.
.. attribute:: term_subset_to_inside_inames_list
A mapping from (summed) subsets of subexpressions to their use counts.
for part_data, part_decl in single_item:
data += part_data[superblock_num]
for part_blocks, part_size in zip(multi_blocks, block_sizes):
assert block_count == len(part_blocks)
data += pad(part_blocks[superblock_num], part_size)
superblocks.append(data)
superblock_size = devdata.align(
single_valued(len(sb) for sb in superblocks))
data = pad_and_join(superblocks, superblock_size)
assert len(data) == superblock_size*block_count
class SuperblockedDataStructure(Record):
pass
return SuperblockedDataStructure(
struct=Struct(struct_name, struct_members),
device_memory=cuda.to_device(data),
block_bytes=superblock_size,
data=data,
**extra_fields
)
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
from pytools import Record, memoize_method
from hedge.optemplate import IdentityMapper
# {{{ instructions
class Instruction(Record):
__slots__ = ["dep_mapper_factory"]
priority = 0
def get_assignees(self):
raise NotImplementedError("no get_assignees in %s" % self.__class__)
def get_dependencies(self):
raise NotImplementedError("no get_dependencies in %s" % self.__class__)
def __str__(self):
raise NotImplementedError
def get_executor_method(self, executor):
raise NotImplementedError
return "" % (
self.name, self.dtype, ",".join(str(i) for i in self.shape))
class ArrayArg(GlobalArg):
def __init__(self, *args, **kwargs):
from warnings import warn
warn("ArrayArg is a deprecated name of GlobalArg", DeprecationWarning,
stacklevel=2)
GlobalArg.__init__(self, *args, **kwargs)
class ConstantArg(_ShapedArg):
def __repr__(self):
return "" % (
self.name, self.dtype, ",".join(str(i) for i in self.shape))
class ImageArg(Record):
def __init__(self, name, dtype=None, dimensions=None, shape=None):
dtype = np.dtype(dtype)
if shape is not None:
if dimensions is not None and dimensions != len(shape):
raise RuntimeError("cannot specify both shape and "
"disagreeing dimensions in ImageArg")
dimensions = len(shape)
else:
if not isinstance(dimensions, int):
raise RuntimeError("ImageArg: dimensions must be an integer")
Record.__init__(self,
dimensions=dimensions,
shape=shape,
dtype=dtype,
name=name)
import pytools
import numpy
import numpy.linalg as la
import hedge.discretization
import hedge.mesh
from hedge.optemplate import \
IdentityMapper, \
FluxOpReducerMixin
from hedge.tools.futures import Future
from hedge.backends import RunContext
import pytools.mpiwrap as mpi
from pymbolic.mapper import CSECachingMapperMixin
class RankData(pytools.Record):
def __init__(
self,
mesh,
global2local_elements,
global2local_vertex_indices,
neighbor_ranks,
global_periodic_opposite_faces,
old_el_numbers=None,
tag_to_elements=None
):
pytools.Record.__init__(self, locals())
def reordered_by(self, *args, **kwargs):
old_el_numbers = self.mesh.get_reorder_oldnumbers(*args, **kwargs)
mesh = self.mesh.reordered(old_el_numbers)
return self.copy(
if iname in used_inames:
raise RuntimeError("domain '%s' redefines iname '%s' "
"that is part of a previous domain" % (dom, iname))
used_inames.add(iname)
available_parameters.add(iname)
result.append(dom)
return result
class LoopKernel(Record):
"""
:ivar device: :class:`pyopencl.Device`
:ivar domains: :class:`islpy.BasicSet`
:ivar instructions:
:ivar args:
:ivar schedule:
:ivar name:
:ivar preambles: a list of (tag, code) tuples that identify preamble snippets.
Each tag's snippet is only included once, at its first occurrence.
The preambles will be inserted in order of their tags.
:ivar preamble_generators: a list of functions of signature
(seen_dtypes, seen_functions) where seen_functions is a set of
(name, c_name, arg_dtypes), generating extra entries for `preambles`.
:ivar assumptions: the initial implemented_domain, captures assumptions
on the parameters. (an isl.Set)
:ivar local_sizes: A dictionary from integers to integers, mapping
"%s[i]" % ax for ax in axis_names),
arguments=", ".join(
"__global %s *%s" % (coord_ctype, ax) for ax in axis_names),
preamble=preamble)
def __call__(self, particles):
dimensions = len(particles)
from pytools import single_valued
coord_dtype = single_valued(coord.dtype for coord in particles)
return self.get_kernel(dimensions, coord_dtype)(*particles)
# }}}
class _KernelInfo(Record):
pass
def padded_bin(i, l):
s = bin(i)[2:]
while len(s) < l:
s = '0' + s
return s
# {{{ data types
@memoize
def make_morton_bin_count_type(device, dimensions, particle_id_dtype):
fields = []
for mnr in range(2**dimensions):
fields.append(('c%s' % padded_bin(mnr, dimensions), particle_id_dtype))