Ejemplo n.º 1
0
    def arguments(self, **kwargs):
        mapper = {i.name: i for i in self.parameters}
        local_grids_mapper = {
            namespace['code-grid-name'](k): v
            for k, v in self.yk_soln.local_grids.items()
        }

        # The user has the illusion to provide plain data objects to the
        # generated kernels, but what we actually need and thus going to
        # provide are pointers to the wrapped YASK grids.
        toshare = {}
        more_args = {}
        for i in self.parameters:
            grid_arg = mapper.get(namespace['code-grid-name'](i.name))
            if grid_arg is not None:
                assert i.provider.from_YASK is True
                obj = kwargs.get(i.name, i.provider)
                # Get the associated Data wrapper (scalars are a special case)
                if np.isscalar(obj):
                    wrapper = DataScalar(obj)
                    toshare[i.provider] = wrapper
                else:
                    wrapper = obj.data
                    toshare[obj] = wrapper
                # Add C-level pointer to the YASK grids
                more_args[grid_arg.name] = wrapper.rawpointer
            elif i.name in local_grids_mapper:
                # Add C-level pointer to the temporary YASK grids
                more_args[i.name] = rawpointer(local_grids_mapper[i.name])
        kwargs.update(more_args)
        return super(Operator, self).arguments(**kwargs), toshare
Ejemplo n.º 2
0
    def apply(self, **kwargs):
        # Build the arguments list to invoke the kernel function
        args = self.arguments(**kwargs)

        # Map default Functions to runtime Functions; will be used for "var sharing"
        toshare = {}
        for i in self.input:
            v = kwargs.get(i.name, i)
            if np.isscalar(v):
                toshare[i] = DataScalar(v)
            elif i.from_YASK and (i.is_Constant or i.is_Function):
                toshare[v] = v.data

        for i in self.yk_solns.values():
            i.pre_apply(toshare)

        arg_values = [args[p.name] for p in self.parameters]
        cfunction = self.cfunction
        with self._profiler.timer_on('apply', comm=args.comm):
            cfunction(*arg_values)

        for i in self.yk_solns.values():
            i.post_apply()

        # Output summary of performance achieved
        return self._emit_apply_profiling(args)
Ejemplo n.º 3
0
    def apply(self, **kwargs):
        # Build the arguments list to invoke the kernel function
        arguments = self.arguments(**kwargs)

        # Map default Functions to runtime Functions; will be used for "grid sharing"
        toshare = {}
        for i in self.input:
            v = kwargs.get(i.name, i)
            if np.isscalar(v):
                toshare[i] = DataScalar(v)
            elif i.from_YASK and (i.is_Constant or i.is_Function):
                toshare[v] = v.data

        log("Running YASK Operator through Devito...")
        arg_values = [arguments[p.name] for p in self.parameters]
        self.yk_soln.run(self.cfunction, arg_values, toshare)
        log("YASK Operator successfully run!")

        # Output summary of performance achieved
        return self._profile_output(arguments)
Ejemplo n.º 4
0
 def data(self, val):
     self._value = DataScalar(val)
Ejemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     value = kwargs.pop('value', 0.)
     super(Constant, self).__init__(*args,
                                    value=DataScalar(value),
                                    **kwargs)