Example #1
0
    def __init__(self, fields, axes):
        """
        """

        common.check_type('fields', fields, Fields)
        common.check_type('axes', axes, str)

        assert len(set(axes).intersection(
            set('xyz'))) > 0, 'axes option is wrong: %s is given' % repr(axes)

        # local variables
        nx, ny, nz = fields.ns
        dtype_str_list = fields.dtype_str_list

        # program
        macros = ['NMAX', 'IDX0', 'IDX1', 'DTYPE', 'PRAGMA_fp64']

        program_dict = {}
        gs_dict = {}
        for axis in list(axes):
            program_dict[axis] = {}

            for e_or_h in ['e', 'h']:
                pt0 = common_exchange.pt0_dict(nx, ny, nz)[axis][e_or_h]['get']
                pt1 = common_exchange.pt1_dict(nx, ny, nz)[axis][e_or_h]['get']
                nmaxi_str, xid_str, yid_str, zid_str = common_gpu.macro_replace_list(
                    pt0, pt1)
                idx0_str = '%s*ny*nz + %s*nz + %s' % (xid_str, yid_str,
                                                      zid_str)

                pt0 = common_exchange.pt0_dict(nx, ny, nz)[axis][e_or_h]['set']
                pt1 = common_exchange.pt1_dict(nx, ny, nz)[axis][e_or_h]['set']
                nmax_str, xid_str, yid_str, zid_str = common_gpu.macro_replace_list(
                    pt0, pt1)
                idx1_str = '%s*ny*nz + %s*nz + %s' % (xid_str, yid_str,
                                                      zid_str)

                values = [nmax_str, idx0_str, idx1_str] + dtype_str_list

                ksrc = common.replace_template_code( \
                        open(common_gpu.src_path + 'copy_self.cl').read(), \
                        macros, values)
                program = cl.Program(fields.context, ksrc).build()
                program_dict[axis][e_or_h] = program

            nmax = int(nmax_str)
            remainder = nmax % fields.ls
            gs_dict[
                axis] = nmax if remainder == 0 else nmax - remainder + fields.ls

        # global variables
        self.mainf = fields
        self.axes = axes
        self.program_dict = program_dict
        self.gs_dict = gs_dict

        # append to the update list
        self.priority_type = 'pbc'
        self.mainf.append_instance(self)
Example #2
0
    def __init__(self, fields, axes):
        """
        """

        common.check_type('fields', fields, Fields)
        common.check_type('axes', axes, str)

        assert len( set(axes).intersection(set('xyz')) ) > 0, 'axes option is wrong: %s is given' % repr(axes)

        # local variables
        nx, ny, nz = fields.ns
        dtype_str_list = fields.dtype_str_list

        # program
        macros = ['NMAX', 'IDX0', 'IDX1', 'DTYPE', 'PRAGMA_fp64']

        program_dict = {}
        gs_dict = {}
        for axis in list(axes):
            program_dict[axis] = {}

            for e_or_h in ['e', 'h']:
                pt0 = common_exchange.pt0_dict(nx, ny, nz)[axis][e_or_h]['get']
                pt1 = common_exchange.pt1_dict(nx, ny, nz)[axis][e_or_h]['get']
                nmaxi_str, xid_str, yid_str, zid_str = common_gpu.macro_replace_list(pt0, pt1)
                idx0_str = '%s*ny*nz + %s*nz + %s' % (xid_str, yid_str, zid_str)

                pt0 = common_exchange.pt0_dict(nx, ny, nz)[axis][e_or_h]['set']
                pt1 = common_exchange.pt1_dict(nx, ny, nz)[axis][e_or_h]['set']
                nmax_str, xid_str, yid_str, zid_str = common_gpu.macro_replace_list(pt0, pt1)
                idx1_str = '%s*ny*nz + %s*nz + %s' % (xid_str, yid_str, zid_str)

                values = [nmax_str, idx0_str, idx1_str] + dtype_str_list

                ksrc = common.replace_template_code( \
                        open(common_gpu.src_path + 'copy_self.cl').read(), \
                        macros, values)
                program = cl.Program(fields.context, ksrc).build()
                program_dict[axis][e_or_h] = program

            nmax = int(nmax_str)
            remainder = nmax % fields.ls
            gs_dict[axis] = nmax if remainder == 0 else nmax - remainder + fields.ls 

        # global variables
        self.mainf = fields
        self.axes = axes
        self.program_dict = program_dict
        self.gs_dict = gs_dict

        # append to the update list
        self.priority_type = 'pbc'
        self.mainf.append_instance(self)
Example #3
0
    def put_x(self, e_or_h, f0, f1):
        gf, sf = (f1, f0) if e_or_h == 'e' else (f0, f1)
        strfs = common_exchange.str_fs_dict['x'][e_or_h]

        if isinstance(f0, cpu.BufferFields) or isinstance(f1, cpu.BufferFields):
            gpt0 = common_exchange.pt0_buf_dict(*gf.ns)['x'][e_or_h]['get']
            gpt1 = common_exchange.pt1_buf_dict(*gf.ns)['x'][e_or_h]['get']
        else:
            gpt0 = common_exchange.pt0_dict(*gf.ns)['x'][e_or_h]['get']
            gpt1 = common_exchange.pt1_dict(*gf.ns)['x'][e_or_h]['get']

        spt0 = common_exchange.pt0_dict(*sf.ns)['x'][e_or_h]['set']
        spt1 = common_exchange.pt1_dict(*sf.ns)['x'][e_or_h]['set']

        self.put_getf_setf_list(e_or_h, gf, strfs, gpt0, gpt1, sf, strfs, spt0, spt1)
Example #4
0
    def put_yz(self, e_or_h, f0, f1, axis, anx0, anx1):
        is_buf0 = True if isinstance(f0, cpu.BufferFields) else False
        is_buf1 = True if isinstance(f1, cpu.BufferFields) else False
        gf, sf = (f1, f0) if e_or_h == 'e' else (f0, f1)

        if is_buf0:
            ax0, ax1 = 'x', axis
        elif is_buf1:
            ax0, ax1 = axis, 'x'
        gax, sax = (ax1, ax0) if e_or_h == 'e' else (ax0, ax1)

        gstr = common_exchange.str_fs_dict[gax][e_or_h]
        sstr = common_exchange.str_fs_dict[sax][e_or_h]

        gpt0 = common_exchange.pt0_buf_dict(*gf.ns)[gax][e_or_h]['get']
        gpt1 = common_exchange.pt1_buf_dict(*gf.ns)[gax][e_or_h]['get']
        spt0 = common_exchange.pt0_dict(*sf.ns)[sax][e_or_h]['set']
        spt1 = common_exchange.pt1_dict(*sf.ns)[sax][e_or_h]['set']

        if (is_buf0 and e_or_h == 'e') or (is_buf1 and e_or_h == 'h'):  # sf
            spt0 = (spt0[0], anx0, spt0[2])
            spt1 = (spt1[0], anx1, spt1[2])
        else:
            gpt0 = (gpt0[0], anx0, gpt0[2])
            gpt1 = (gpt1[0], anx1, gpt1[2])

        self.put_getf_setf_list(e_or_h, gf, gstr, gpt0, gpt1, sf, sstr, spt0,
                                spt1)
        '''
Example #5
0
    def put_yz(self, e_or_h, f0, f1, axis, anx0, anx1):
        is_buf0 = True if isinstance(f0, cpu.BufferFields) else False
        is_buf1 = True if isinstance(f1, cpu.BufferFields) else False
        gf, sf = (f1, f0) if e_or_h == 'e' else (f0, f1)

        if is_buf0:
            ax0, ax1 = 'x', axis
        elif is_buf1:
            ax0, ax1 = axis, 'x'
        gax, sax = (ax1, ax0) if e_or_h == 'e' else (ax0, ax1)

        gstr = common_exchange.str_fs_dict[gax][e_or_h]
        sstr = common_exchange.str_fs_dict[sax][e_or_h]

        gpt0 = common_exchange.pt0_buf_dict(*gf.ns)[gax][e_or_h]['get']
        gpt1 = common_exchange.pt1_buf_dict(*gf.ns)[gax][e_or_h]['get']
        spt0 = common_exchange.pt0_dict(*sf.ns)[sax][e_or_h]['set']
        spt1 = common_exchange.pt1_dict(*sf.ns)[sax][e_or_h]['set']

        if (is_buf0 and e_or_h=='e') or (is_buf1 and e_or_h=='h'):   # sf
            spt0 = (spt0[0], anx0, spt0[2])
            spt1 = (spt1[0], anx1, spt1[2])
        else:
            gpt0 = (gpt0[0], anx0, gpt0[2])
            gpt1 = (gpt1[0], anx1, gpt1[2])

        self.put_getf_setf_list(e_or_h, gf, gstr, gpt0, gpt1, sf, sstr, spt0, spt1)

        '''
Example #6
0
    def put_x(self, e_or_h, f0, f1):
        gf, sf = (f1, f0) if e_or_h == 'e' else (f0, f1)
        strfs = common_exchange.str_fs_dict['x'][e_or_h]

        if isinstance(f0, cpu.BufferFields) or isinstance(
                f1, cpu.BufferFields):
            gpt0 = common_exchange.pt0_buf_dict(*gf.ns)['x'][e_or_h]['get']
            gpt1 = common_exchange.pt1_buf_dict(*gf.ns)['x'][e_or_h]['get']
        else:
            gpt0 = common_exchange.pt0_dict(*gf.ns)['x'][e_or_h]['get']
            gpt1 = common_exchange.pt1_dict(*gf.ns)['x'][e_or_h]['get']

        spt0 = common_exchange.pt0_dict(*sf.ns)['x'][e_or_h]['set']
        spt1 = common_exchange.pt1_dict(*sf.ns)['x'][e_or_h]['set']

        self.put_getf_setf_list(e_or_h, gf, strfs, gpt0, gpt1, sf, strfs, spt0,
                                spt1)
Example #7
0
    def __init__(self, fields, axes):
        """
        """

        common.check_type("fields", fields, Fields)
        common.check_type("axes", axes, str)

        assert len(set(axes).intersection(set("xyz"))) > 0, "axes option is wrong: %s is given" % repr(axes)

        # local variables
        nx, ny, nz = fields.ns
        dtype_str_list = fields.dtype_str_list

        # program
        macros = ["NMAX", "IDX0", "IDX1", "DTYPE", "PRAGMA_fp64"]

        program_dict = {}
        for axis in list(axes):
            program_dict[axis] = {}

            for e_or_h in ["e", "h"]:
                pt0 = common_exchange.pt0_dict(nx, ny, nz)[axis][e_or_h]["get"]
                pt1 = common_exchange.pt1_dict(nx, ny, nz)[axis][e_or_h]["get"]
                nmax, xid, yid, zid = common_gpu.macro_replace_list(pt0, pt1)
                idx0_str = "%s*ny*nz + %s*nz + %s" % (xid, yid, zid)

                pt0 = common_exchange.pt0_dict(nx, ny, nz)[axis][e_or_h]["set"]
                pt1 = common_exchange.pt1_dict(nx, ny, nz)[axis][e_or_h]["set"]
                nmax, xid, yid, zid = common_gpu.macro_replace_list(pt0, pt1)
                idx1_str = "%s*ny*nz + %s*nz + %s" % (xid, yid, zid)

                values = [nmax, idx0_str, idx1_str] + dtype_str_list

                ksrc = common.replace_template_code(open(common_gpu.src_path + "copy_self.cl").read(), macros, values)
                program = cl.Program(fields.context, ksrc).build()
                program_dict[axis][e_or_h] = program

        # global variables
        self.mainf = fields
        self.axes = axes
        self.program_dict = program_dict

        # append to the update list
        self.priority_type = "pbc"
        self.mainf.append_instance(self)
Example #8
0
    def put_getf_setf_list(self, eh, f0, f1):
        gf, sf = (f1, f0) if eh == 'e' else (f0, f1)
        strfs = common_exchange.str_fs_dict['x'][eh]

        gpt0 = common_exchange.pt0_dict(*gf.ns)['x'][eh]['get']
        gpt1 = common_exchange.pt1_dict(*gf.ns)['x'][eh]['get']
        spt0 = common_exchange.pt0_dict(*sf.ns)['x'][eh]['set']
        spt1 = common_exchange.pt1_dict(*sf.ns)['x'][eh]['set']

        gtype = getattr(self, gf.device_type)
        stype = getattr(self, sf.device_type)
        getf = gtype.GetFields(gf, strfs, gpt0, gpt1)
        setf = stype.SetFields(sf, strfs, spt0, spt1, True)

        if gtype == 'cpu' and stype == 'gpu':
            self.getf_block_dict[eh].append(getf)
            self.setf_block_dict[eh].append(setf)
        else:
            self.getf_dict[eh].append(getf)
            self.setf_dict[eh].append(setf)