Ejemplo n.º 1
0
    def __init__(self, halo, grid, dimension, in_grid_name="in_grid", out_grid_name="out_grid", device=None):
        """

        :param halo: the halo shape
        :param grid: the shape of the grid that stencil is to be applied to
        :param dimension: the dimension this kernel applies to
        :return:
        """
        self.halo = tuple(halo)
        self.grid = grid
        self.shape = grid.shape
        self.in_grid_name = in_grid_name
        self.out_grid_name = out_grid_name

        # check for some pathologies and raise exception if any are present
        if len(halo) != len(self.shape):
            raise StencilException("halo {} can't apply to grid shape {}".format(self.halo, self.shape))

        if dimension < 0 or dimension >= len(self.shape):
            raise StencilException("dimension {} too big for grid shape {}".format(dimension, self.shape))

        # halo or grid to small
        if any([x < 1 or y < 1 for x, y in zip(self.halo, self.shape)]):
            raise StencilException(
                "halo {} can't be bigger than grid {} in any dimension".format(self.halo, self.shape)
            )
        # no interior points in a dimension
        if any([s <= 2*h for h, s in zip(self.halo, self.shape)]):
            raise StencilException(
                "halo {} can't span grid shape {} in any dimension".format(self.halo, self.shape)
            )

        self.dimension = dimension
        self.dimensions = len(grid.shape)

        self.device = device

        self.global_size, self.global_offset = self.compute_global_size()
        lcs = LocalSizeComputer(self.global_size, device=device)
        self.local_size = lcs.compute_local_size_thin()
        self.virtual_global_size = lcs.compute_virtual_global_size(self.local_size)

        self.kernel_name = OclBoundaryCopier.kernel_name(self.dimension)