def runTest(self):
        nx, ny, nz, str_f, pt0, pt1 = self.args

        slidx = common.slice_index_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        fields = Fields(context, device, nx, ny, nz, '', 'single')
        getf = GetFields(fields, str_f, pt0, pt1)

        # host allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        eh_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs))
        fields.set_eh_bufs(*ehs)

        # verify
        getf.get_event().wait()

        for str_f in str_fs:
            original = eh_dict[str_f][slidx]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1 = self.args

        slidx = common.slice_index_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        fields = Fields(context, device, nx, ny, nz, '', 'single')
        getf = GetFields(fields, str_f, pt0, pt1) 
        
        # host allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) )
        fields.set_eh_bufs(*ehs)

        # verify
        getf.get_event().wait()

        for str_f in str_fs:
            original = eh_dict[str_f][slidx]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
Пример #3
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, use_cpu_core, split, tmax = self.args
        fields = Fields(nx, ny, nz, coeff_use, precision_float, use_cpu_core)
        core = Core(fields)

        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']
        slice_xyz = [slice(None, None), slice(None, None), fields.slice_z]

        # allocations
        ns = fields.ns
        dtype = fields.dtype

        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_ehs(*ehs)

        ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz, dtype)
        if 'e' in coeff_use:
            fields.set_ces(*ces)
        if 'h' in coeff_use:
            fields.set_chs(*chs)

        # update
        if ufunc == 'e':
            for tstep in xrange(0, tmax):
                fields.update_e()
                common_update.update_e(ehs, ces)
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[:3]:
                norm = np.linalg.norm(eh - fields.get(strf)[slice_xyz])
                max_diff = np.abs(eh - fields.get(strf)[slice_xyz]).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % (self.args, strf, norm, max_diff) )

                if fields.pad != 0:
                    if strf == 'ez':
                        norm2 = np.linalg.norm(fields.get(strf)[:,:,-fields.pad:])
                    else:
                        norm2 = np.linalg.norm(fields.get(strf)[:,:,-fields.pad-1:])
                    self.assertEqual(norm2, 0, '%s, %s, %g, padding' % (self.args, strf, norm2) )

        elif ufunc == 'h':
            for tstep in xrange(0, tmax):
                fields.update_h()
                common_update.update_h(ehs, chs)
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[3:]:
                norm = np.linalg.norm(eh - fields.get(strf)[slice_xyz])
                max_diff = np.abs(eh - fields.get(strf)[slice_xyz]).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )

                if fields.pad != 0:
                    if strf == 'hz':
                        norm2 = np.linalg.norm(fields.get(strf)[:,:,-fields.pad:])
                    else:
                        norm2 = np.linalg.norm(fields.get(strf)[:,:,-fields.pad:])
                    self.assertEqual(norm2, 0, '%s, %s, %g, padding' % (self.args, strf, norm2) )
Пример #4
0
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1 = self.args

        slices = common.slice_index_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)

        mainf_list = [gpu.Fields(context, device, nx, ny, nz) \
                for device in gpu_devices]
        mainf_list.append(cpu.Fields(nx, ny, nz))
        nodef = NodeFields(mainf_list)
        dtype = nodef.dtype
        anx = nodef.accum_nx_list

        getf = NodeGetFields(nodef, str_f, pt0, pt1)

        # generate random source
        global_ehs = [np.zeros(nodef.ns, dtype) for i in range(6)]
        eh_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], global_ehs))

        for i, f in enumerate(mainf_list[:-1]):
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_eh_bufs(*ehs)
            for eh, geh in zip(ehs, global_ehs):
                geh[anx[i]:anx[i + 1], :, :] = eh[:-1, :, :]

        f = mainf_list[-1]
        nx, ny, nz = f.ns
        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
        f.set_ehs(*ehs)
        for eh, geh in zip(ehs, global_ehs):
            geh[anx[-2]:anx[-1] + 1, :, :] = eh[:]

        # verify
        getf.wait()

        for str_f in str_fs:
            original = eh_dict[str_f][slices]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
Пример #5
0
    def runTest(self):
        nx, ny, nz, str_f, pt0, pt1 = self.args

        slices = common.slice_index_two_points(pt0, pt1)
        str_fs = common.convert_to_tuple(str_f)

        # instance
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)

        mainf_list = [gpu.Fields(context, device, nx, ny, nz) \
                for device in gpu_devices]
        mainf_list.append( cpu.Fields(nx, ny, nz) )
        nodef = NodeFields(mainf_list)
        dtype = nodef.dtype
        anx = nodef.accum_nx_list

        getf = NodeGetFields(nodef, str_f, pt0, pt1) 
        
        # generate random source
        global_ehs = [np.zeros(nodef.ns, dtype) for i in range(6)]
        eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], global_ehs) )

        for i, f in enumerate(mainf_list[:-1]):
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_eh_bufs(*ehs)
            for eh, geh in zip(ehs, global_ehs):
                geh[anx[i]:anx[i+1],:,:] = eh[:-1,:,:]

        f = mainf_list[-1]
        nx, ny, nz = f.ns
        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
        f.set_ehs(*ehs)
        for eh, geh in zip(ehs, global_ehs):
            geh[anx[-2]:anx[-1]+1,:,:] = eh[:]

        # verify
        getf.wait()

        for str_f in str_fs:
            original = eh_dict[str_f][slices]
            copy = getf.get_fields(str_f)
            norm = np.linalg.norm(original - copy)
            self.assertEqual(norm, 0, '%s, %g' % (self.args, norm))
Пример #6
0
    def runTest(self):
        axis, nx, ny, nz, precision_float = self.args

        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        fields = Fields(context, device, nx, ny, nz, '', precision_float)
        pbc = Pbc(fields, axis)

        # allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        fields.set_eh_bufs(*ehs)

        # update
        fields.update_e()
        fields.update_h()

        # verify
        getf0, getf1 = {}, {}
        strfs_e = {'x':['ey', 'ez'], 'y':['ex', 'ez'], 'z':['ex', 'ey']}[axis]
        strfs_h = {'x':['hy', 'hz'], 'y':['hx', 'hz'], 'z':['hx', 'hy']}[axis]

        pt0 = (0, 0, 0)
        pt1 = { 'x': (0, ny-2, nz-2), \
                'y': (nx-2, 0, nz-2), \
                'z': (nx-2, ny-2, 0) }[axis]
        getf0['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (nx-1, 0, 0), \
                'y': (0, ny-1, 0), \
                'z': (0, 0, nz-1) }[axis]
        pt1 = { 'x': (nx-1, ny-2, nz-2), \
                'y': (nx-2, ny-1, nz-2), \
                'z': (nx-2, ny-2, nz-1) }[axis]
        getf1['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (0, 1, 1), \
                'y': (1, 0, 1), \
                'z': (1, 1, 0) }[axis]
        pt1 = { 'x': (0, ny-1, nz-1), \
                'y': (nx-1, 0, nz-1), \
                'z': (nx-1, ny-1, 0) }[axis]
        getf0['h'] = GetFields(fields, strfs_h, pt0, pt1)

        pt0 = { 'x': (nx-1, 1, 1), \
                'y': (1, ny-1, 1), \
                'z': (1, 1, nz-1) }[axis]
        pt1 = (nx-1, ny-1, nz-1)
        getf1['h'] = GetFields(fields, strfs_h, pt0, pt1)

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            norm = np.linalg.norm( \
                    getf0[eh].get_fields() - getf1[eh].get_fields() )
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))
    def test(self):
        nx, ny, nz = 40, 50, 60
        tmax = 10

        # buffer instance
        if rank == 0:
            fields = Fields(10, ny, nz, mpi_type='x+')
            exmpi = ExchangeMpi(fields, 1, tmax)

        elif rank == 1:
            fields = Fields(3, ny, nz, mpi_type='x-')
            exmpi = ExchangeMpi(fields, 0, tmax)

        # generate random source
        nx, ny, nz = fields.ns
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        fields.set_ehs(*ehs)

        # verify
        for tstep in xrange(1, tmax + 1):
            fields.update_e()
            fields.update_h()

        getf_dict = {}
        if rank == 0:
            getf_dict['e'] = GetFields(fields, ['ey', 'ez'], \
                    (nx-1, 0, 0), (nx-1, ny-2, nz-2))

            getf_dict['h'] = GetFields(fields, ['hy', 'hz'], \
                    (1, 1, 1), (1, ny-1, nz-1))

            for eh in ['e', 'h']:
                getf = getf_dict[eh]
                getf.get_event().wait()
                g0 = getf.get_fields()
                g1 = np.zeros_like(g0)
                comm.Recv(g1, 1, tag=10)
                norm = np.linalg.norm(g0 - g1)
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'x', 'e'))

        elif rank == 1:
            getf_dict['e'] = GetFields(fields, ['ey', 'ez'], \
                    (nx-2, 0, 0), (nx-2, ny-2, nz-2))

            getf_dict['h'] = GetFields(fields, ['hy', 'hz'], \
                    (0, 1, 1), (0, ny-1, nz-1))

            for eh in ['e', 'h']:
                getf = getf_dict[eh]
                getf.get_event().wait()
                comm.Send(getf.get_fields(), 0, tag=10)
Пример #8
0
    def test(self):
        nx, ny, nz = 40, 50, 60
        tmax = 10

        # buffer instance
        if rank == 0:
            fields = Fields(10, ny, nz, mpi_type="x+")
            exmpi = ExchangeMpi(fields, 1, tmax)

        elif rank == 1:
            fields = Fields(3, ny, nz, mpi_type="x-")
            exmpi = ExchangeMpi(fields, 0, tmax)

        # generate random source
        nx, ny, nz = fields.ns
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        fields.set_ehs(*ehs)

        # verify
        for tstep in xrange(1, tmax + 1):
            fields.update_e()
            fields.update_h()

        getf_dict = {}
        if rank == 0:
            getf_dict["e"] = GetFields(fields, ["ey", "ez"], (nx - 1, 0, 0), (nx - 1, ny - 2, nz - 2))

            getf_dict["h"] = GetFields(fields, ["hy", "hz"], (1, 1, 1), (1, ny - 1, nz - 1))

            for eh in ["e", "h"]:
                getf = getf_dict[eh]
                getf.get_event().wait()
                g0 = getf.get_fields()
                g1 = np.zeros_like(g0)
                comm.Recv(g1, 1, tag=10)
                norm = np.linalg.norm(g0 - g1)
                self.assertEqual(norm, 0, "%g, %s, %s" % (norm, "x", "e"))

        elif rank == 1:
            getf_dict["e"] = GetFields(fields, ["ey", "ez"], (nx - 2, 0, 0), (nx - 2, ny - 2, nz - 2))

            getf_dict["h"] = GetFields(fields, ["hy", "hz"], (0, 1, 1), (0, ny - 1, nz - 1))

            for eh in ["e", "h"]:
                getf = getf_dict[eh]
                getf.get_event().wait()
                comm.Send(getf.get_fields(), 0, tag=10)
Пример #9
0
    def test_y_pbc_x_exchange(self):
        # instance
        nx, ny, nz = 40, 50, 60
        #nx, ny, nz = 3, 4, 5
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)

        gpuf = gpu.Fields(context, gpu_devices[0], nx, ny, nz)
        cpuf = cpu.Fields(nx, ny, nz)
        mainf_list = [gpuf, cpuf]
        nodef = NodeFields(mainf_list)
        core = NodeCore(nodef)
        pbc = NodePbc(nodef, 'y')
        exchange = NodeExchange(nodef)
        
        # generate random source
        ehs_gpu = common_update.generate_random_ehs(nx, ny, nz, nodef.dtype)
        gpuf.set_eh_bufs(*ehs_gpu)
        ehs_gpu_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs_gpu) )

        ehs_cpu = common_update.generate_random_ehs(nx, ny, nz, nodef.dtype)
        cpuf.set_ehs(*ehs_cpu)
        ehs_cpu_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs_cpu) )

        # verify
        for mainf in mainf_list:
            mainf.update_e()
        pbc.update_e()
        exchange.update_e()

        for mainf in mainf_list:
            mainf.update_h()
        pbc.update_h()
        exchange.update_h()

        mainf_list[-1].enqueue_barrier()
        getf0, getf1 = {}, {}

        # x-axis exchange
        getf0['e'] = gpu.GetFields(gpuf, ['ey', 'ez'], (nx-1, 0, 0), (nx-1, ny-2, nz-2))
        getf1['e'] = cpu.GetFields(cpuf, ['ey', 'ez'], (0, 0, 0), (0, ny-2, nz-2))

        getf0['h'] = gpu.GetFields(gpuf, ['hy', 'hz'], (nx-1, 1, 1), (nx-1, ny-1, nz-1))
        getf1['h'] = cpu.GetFields(cpuf, ['hy', 'hz'], (0, 1, 1), (0, ny-1, nz-1))

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            g0 = getf0[eh].get_fields()
            g1 = getf1[eh].get_fields()
            norm = np.linalg.norm(g0 - g1)
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'x-axis exchange', eh))

        # y-axis pbc gpu
        getf0['e'] = gpu.GetFields(gpuf, ['ex', 'ez'], (0, ny-1, 0), (nx-2, ny-1, nz-2))
        getf1['e'] = gpu.GetFields(gpuf, ['ex', 'ez'], (0, 0, 0), (nx-2, 0, nz-2))

        getf0['h'] = gpu.GetFields(gpuf, ['hx', 'hz'], (1, ny-1, 1), (nx-1, ny-1, nz-1))
        getf1['h'] = gpu.GetFields(gpuf, ['hx', 'hz'], (1, 0, 1), (nx-1, 0, nz-1))

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            g0 = getf0[eh].get_fields()
            g1 = getf1[eh].get_fields()
            norm = np.linalg.norm(g0 - g1)
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'y-axis pbc gpu', eh))

        # y-axis pbc cpu
        getf0['e'] = cpu.GetFields(cpuf, ['ex', 'ez'], (0, ny-1, 0), (nx-2, ny-1, nz-2))
        getf1['e'] = cpu.GetFields(cpuf, ['ex', 'ez'], (0, 0, 0), (nx-2, 0, nz-2))

        getf0['h'] = cpu.GetFields(cpuf, ['hx', 'hz'], (1, ny-1, 1), (nx-1, ny-1, nz-1))
        getf1['h'] = cpu.GetFields(cpuf, ['hx', 'hz'], (1, 0, 1), (nx-1, 0, nz-1))

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            g0 = getf0[eh].get_fields()
            g1 = getf1[eh].get_fields()
            norm = np.linalg.norm(g0 - g1)
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'y-axis pbc cpu', eh))
Пример #10
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, tmax = self.args

        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        fields = Fields(context, device, nx, ny, nz, coeff_use,
                        precision_float)
        core = Core(fields)

        # allocations
        ns = fields.ns
        dtype = fields.dtype
        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']

        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_eh_bufs(*ehs)

        ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz,
                                                    dtype)
        if 'e' in coeff_use:
            fields.set_ce_bufs(*ces)
        if 'h' in coeff_use:
            fields.set_ch_bufs(*chs)

        tmpf = np.zeros(fields.ns_pitch, dtype=dtype)

        # update
        if ufunc == 'e':
            for tstep in xrange(0, tmax):
                fields.update_e()
                common_update.update_e(ehs, ces)

            for strf, eh in zip(strf_list, ehs)[:3]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z])
                max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max()
                self.assertEqual(
                    norm, 0,
                    '%s, %s, %g, %g' % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == 'ez':
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad:])
                    else:
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad - 1:])
                    self.assertEqual(
                        norm2, 0,
                        '%s, %s, %g, padding' % (self.args, strf, norm2))

        elif ufunc == 'h':
            for tstep in xrange(0, tmax):
                fields.update_h()
                common_update.update_h(ehs, chs)

            for strf, eh in zip(strf_list, ehs)[3:]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z])
                max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max()
                self.assertEqual(
                    norm, 0,
                    '%s, %s, %g, %g' % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == 'hz':
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad:])
                    else:
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad:])
                    self.assertEqual(
                        norm2, 0,
                        '%s, %s, %g, padding' % (self.args, strf, norm2))
Пример #11
0
    def runTest(self):
        nx, ny, nz = self.args

        # instance
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)

        mainf_list = [gpu.Fields(context, device, nx, ny, nz) \
                for device in gpu_devices]
        mainf_list.append(cpu.Fields(nx, ny, nz))
        nodef = NodeFields(mainf_list)
        dtype = nodef.dtype

        # buffer instance
        nodef.append_buffer_fields(cpu.Fields(3, ny, nz, mpi_type='x-'))
        nodef.append_buffer_fields(cpu.Fields(3, nodef.nx, nz, mpi_type='y+'))
        nodef.append_buffer_fields(cpu.Fields(3, nodef.nx, nz, mpi_type='y-'))
        nodef.append_buffer_fields(cpu.Fields(3, nodef.nx, ny, mpi_type='z+'))
        nodef.append_buffer_fields(cpu.Fields(3, nodef.nx, ny, mpi_type='z-'))

        exchange = NodeExchange(nodef)

        # generate random source
        for f in mainf_list[:-1]:
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_eh_bufs(*ehs)

        for f in nodef.cpuf_dict.values():
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_ehs(*ehs)

        # verify
        exchange.update_e()
        exchange.update_h()
        getf0, getf1 = {}, {}

        # mainf list
        self.gpu, self.cpu = gpu, cpu
        for f0, f1 in zip(mainf_list[:-1], mainf_list[1:]):
            getf0['e'] = getattr(self, f0.device_type).GetFields(f0, ['ey', 'ez'], \
                    (f0.nx-1, 0, 0), (f0.nx-1, f0.ny-2, f0.nz-2))
            getf1['e'] = getattr(self, f1.device_type).GetFields(f1, ['ey', 'ez'], \
                    (0, 0, 0), (0, f1.ny-2, f1.nz-2))

            getf0['h'] = getattr(self, f0.device_type).GetFields(f0, ['hy', 'hz'], \
                    (f0.nx-1, 1, 1), (f0.nx-1, f0.ny-1, f0.nz-1))
            getf1['h'] = getattr(self, f1.device_type).GetFields(f1, ['hy', 'hz'], \
                    (0, 1, 1), (0, f1.ny-1, f1.nz-1))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm(getf0[eh].get_fields() -
                                      getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%s, %g, %s, %s, %s' % \
                        (self.args, norm, 'mainf', \
                        getf0[eh].mainf.device_type, getf1[eh].mainf.device_type) )

        # buffer 'x-'
        f0, f1 = nodef.cpuf_dict['x-'], mainf_list[0]
        getf0['e'] = cpu.GetFields(f0, ['ey', 'ez'], \
                (f0.nx-1, 0, 0), (f0.nx-1, f0.ny-2, f0.nz-2))
        getf1['e'] = gpu.GetFields(f1, ['ey', 'ez'], \
                (1, 0, 0), (1, f1.ny-2, f1.nz-2))

        getf0['h'] = cpu.GetFields(f0, ['hy', 'hz'], \
                (f0.nx-2, 1, 1), (f0.nx-2, f0.ny-1, f0.nz-1))
        getf1['h'] = gpu.GetFields(f1, ['hy', 'hz'], \
                (0, 1, 1), (0, f1.ny-1, f1.nz-1))

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            norm = np.linalg.norm( \
                    getf0[eh].get_fields() - getf1[eh].get_fields())
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'x-', eh))

        # buffer 'y+'
        anx_list = nodef.accum_nx_list

        f1 = nodef.cpuf_dict['y+']
        for f0, anx0, anx1 in zip(mainf_list, anx_list[:-1], anx_list[1:]):
            getf0['e'] = getattr(self, f0.device_type).GetFields(f0, ['ex', 'ez'], \
                    (0, f0.ny-1, 0), (f0.nx-2, f0.ny-1, f0.nz-2))
            getf1['e'] = cpu.GetFields(f1, ['ey', 'ez'], \
                    (1, anx0, 0), (1, anx1-1, f1.nz-2))

            getf0['h'] = getattr(self, f0.device_type).GetFields(f0, ['hx', 'hz'], \
                    (1, f0.ny-2, 1), (f0.nx-1, f0.ny-2, f0.nz-1))
            getf1['h'] = cpu.GetFields(f1, ['hy', 'hz'], \
                    (0, anx0+1, 1), (0, anx1, f1.nz-1))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm( \
                        getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'y+', eh))

        # buffer 'y-'
        f0 = nodef.cpuf_dict['y-']
        for f1, anx0, anx1 in zip(mainf_list, anx_list[:-1], anx_list[1:]):
            getf0['e'] = cpu.GetFields(f0, ['ey', 'ez'], \
                    (f0.nx-1, anx0, 0), (f0.nx-1, anx1-1, f0.nz-2))
            getf1['e'] = getattr(self, f1.device_type).GetFields(f1, ['ex', 'ez'], \
                    (0, 1, 0), (f1.nx-2, 1, f1.nz-2))

            getf0['h'] = cpu.GetFields(f0, ['hy', 'hz'], \
                    (f0.nx-2, anx0+1, 1), (f0.nx-2, anx1, f0.nz-1))
            getf1['h'] = getattr(self, f1.device_type).GetFields(f1, ['hx', 'hz'], \
                    (1, 0, 1), (f1.nx-1, 0, f1.nz-1))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm( \
                        getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'y-', eh))

        # buffer 'z+'
        f1 = nodef.cpuf_dict['z+']
        for f0, anx0, anx1 in zip(mainf_list, anx_list[:-1], anx_list[1:]):
            getf0['e'] = getattr(self, f0.device_type).GetFields(f0, ['ex', 'ey'], \
                    (0, 0, f0.nz-1), (f0.nx-2, f0.ny-2, f0.nz-1))
            getf1['e'] = cpu.GetFields(f1, ['ey', 'ez'], \
                    (1, anx0, 0), (1, anx1-1, f1.nz-2))

            getf0['h'] = getattr(self, f0.device_type).GetFields(f0, ['hx', 'hy'], \
                    (1, 1, f0.nz-2), (f0.nx-1, f0.ny-1, f0.nz-2))
            getf1['h'] = cpu.GetFields(f1, ['hy', 'hz'], \
                    (0, anx0+1, 1), (0, anx1, f1.nz-1))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm( \
                        getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'z+', eh))

        # buffer 'z-'
        f0 = nodef.cpuf_dict['z-']
        for f1, anx0, anx1 in zip(mainf_list, anx_list[:-1], anx_list[1:]):
            getf0['e'] = cpu.GetFields(f0, ['ey', 'ez'], \
                    (f0.nx-1, anx0, 0), (f0.nx-1, anx1-1, f0.nz-2))
            getf1['e'] = getattr(self, f1.device_type).GetFields(f1, ['ex', 'ey'], \
                    (0, 0, 1), (f1.nx-2, f1.ny-2, 1))

            getf0['h'] = cpu.GetFields(f0, ['hy', 'hz'], \
                    (f0.nx-2, anx0+1, 1), (f0.nx-2, anx1, f0.nz-1))
            getf1['h'] = getattr(self, f1.device_type).GetFields(f1, ['hx', 'hy'], \
                    (1, 1, 0), (f1.nx-1, f1.ny-1, 0))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm( \
                        getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'z-', eh))
Пример #12
0
    def runTest(self):
        axis, nx, ny, nz = self.args
        self.gpu, self.cpu = gpu, cpu

        # instance
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)

        mainf_list = [gpu.Fields(context, device, nx, ny, nz) \
                for device in gpu_devices]
        mainf_list.append(cpu.Fields(nx, ny, nz))
        nodef = NodeFields(mainf_list)
        dtype = nodef.dtype

        pbc = NodePbc(nodef, axis)
        exchange = NodeExchange(nodef)

        # generate random source
        for f in mainf_list[:-1]:
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_eh_bufs(*ehs)

        for f in nodef.cpuf_dict.values():
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_ehs(*ehs)

        # verify
        for mainf in mainf_list:
            mainf.update_e()
        pbc.update_e()
        exchange.update_e()

        for mainf in mainf_list:
            mainf.update_h()
        pbc.update_h()
        exchange.update_h()

        mainf_list[-1].enqueue_barrier()

        getf0, getf1 = {}, {}

        if axis == 'x':
            f0, f1 = mainf_list[0], mainf_list[-1]
            getf0['e'] = getattr(self, f0.device_type).GetFields(f0, ['ey', 'ez'], \
                    (0, 0, 0), (0, f0.ny-2, f0.nz-2))
            getf1['e'] = getattr(self, f1.device_type).GetFields(f1, ['ey', 'ez'], \
                    (f1.nx-1, 0, 0), (f1.nx-1, f1.ny-2, f1.nz-2))

            getf0['h'] = getattr(self, f0.device_type).GetFields(f0, ['hy', 'hz'], \
                    (0, 1, 1), (0, f0.ny-1, f0.nz-1))
            getf1['h'] = getattr(self, f1.device_type).GetFields(f1, ['hy', 'hz'], \
                    (f1.nx-1, 1, 1), (f1.nx-1, f1.ny-1, f1.nz-1))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm(getf0[eh].get_fields() -
                                      getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'x', eh))

        elif axis == 'y':
            for f in mainf_list:
                getf0['e'] = getattr(self, f.device_type).GetFields(f, ['ex', 'ez'], \
                        (0, 0, 0), (f.nx-2, 0, f.nz-2))
                getf1['e'] = getattr(self, f.device_type).GetFields(f, ['ex', 'ez'], \
                        (0, f.ny-1, 0), (f.nx-2, f.ny-1, f.nz-2))

                getf0['h'] = getattr(self, f.device_type).GetFields(f, ['hx', 'hz'], \
                        (1, 0, 1), (f.nx-1, 0, f.nz-1))
                getf1['h'] = getattr(self, f.device_type).GetFields(f, ['hx', 'hz'], \
                        (1, f.ny-1, 1), (f.nx-1, f.ny-1, f.nz-1))

                for getf in getf0.values() + getf1.values():
                    getf.get_event().wait()

                for eh in ['e', 'h']:
                    norm = np.linalg.norm( \
                            getf0[eh].get_fields() - getf1[eh].get_fields())
                    self.assertEqual(
                        norm, 0,
                        '%g, %s, %s, %s' % (norm, 'y', eh, f.device_type))

        elif axis == 'z':
            for f in mainf_list:
                getf0['e'] = getattr(self, f.device_type).GetFields(f, ['ex', 'ey'], \
                        (0, 0, f.nz-1), (f.nx-2, f.ny-2, f.nz-1))
                getf1['e'] = getattr(self, f.device_type).GetFields(f, ['ex', 'ey'], \
                        (0, 0, 0), (f.nx-2, f.ny-2, 0))

                getf0['h'] = getattr(self, f.device_type).GetFields(f, ['hx', 'hy'], \
                        (1, 1, f.nz-1), (f.nx-1, f.ny-1, f.nz-1))
                getf1['h'] = getattr(self, f.device_type).GetFields(f, ['hx', 'hy'], \
                        (1, 1, 0), (f.nx-1, f.ny-1, 0))

                for getf in getf0.values() + getf1.values():
                    getf.get_event().wait()

                for eh in ['e', 'h']:
                    norm = np.linalg.norm( \
                            getf0[eh].get_fields() - getf1[eh].get_fields())
                    self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'z', eh))
Пример #13
0
    def runTest(self):
        axis, nx, ny, nz, mpi_type = self.args

        fields = Fields(nx, ny, nz, mpi_type=mpi_type)
        core = Core(fields)
        pbc = Pbc(fields, axis)

        # allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        fields.set_ehs(*ehs)

        # update
        fields.update_e()
        fields.update_h()
        fields.enqueue_barrier()

        # verify
        getf0, getf1 = {}, {}
        strfs_e = {'x':['ey', 'ez'], 'y':['ex', 'ez'], 'z':['ex', 'ey']}[axis]
        strfs_h = {'x':['hy', 'hz'], 'y':['hx', 'hz'], 'z':['hx', 'hy']}[axis]

        pt0 = (0, 0, 0)
        pt1 = { 'x': (0, ny-2, nz-2), \
                'y': (nx-2, 0, nz-2), \
                'z': (nx-2, ny-2, 0) }[axis]
        getf0['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (nx-1, 0, 0), \
                'y': (0, ny-1, 0), \
                'z': (0, 0, nz-1) }[axis]
        pt1 = { 'x': (nx-1, ny-2, nz-2), \
                'y': (nx-2, ny-1, nz-2), \
                'z': (nx-2, ny-2, nz-1) }[axis]
        getf1['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (0, 1, 1), \
                'y': (1, 0, 1), \
                'z': (1, 1, 0) }[axis]
        pt1 = { 'x': (0, ny-1, nz-1), \
                'y': (nx-1, 0, nz-1), \
                'z': (nx-1, ny-1, 0) }[axis]
        getf0['h'] = GetFields(fields, strfs_h, pt0, pt1)

        pt0 = { 'x': (nx-1, 1, 1), \
                'y': (1, ny-1, 1), \
                'z': (1, 1, nz-1) }[axis]
        pt1 = (nx-1, ny-1, nz-1)
        getf1['h'] = GetFields(fields, strfs_h, pt0, pt1)

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            g0 = getf0[eh].get_fields()
            g1 = getf1[eh].get_fields()
            norm = np.linalg.norm(g0 - g1)
            '''
            print eh
            print g0
            print g1
            '''
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))
Пример #14
0
    def runTest(self):
        nx, ny, nz = self.args

        # instance
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)

        mainf_list = [gpu.Fields(context, device, nx, ny, nz) \
                for device in gpu_devices]
        mainf_list.append( cpu.Fields(nx, ny, nz) )
        nodef = NodeFields(mainf_list)
        dtype = nodef.dtype

        # buffer instance
        nodef.append_buffer_fields(cpu.Fields(3, ny, nz, mpi_type='x-'))
        nodef.append_buffer_fields(cpu.Fields(3, nodef.nx, nz, mpi_type='y+'))
        nodef.append_buffer_fields(cpu.Fields(3, nodef.nx, nz, mpi_type='y-'))
        nodef.append_buffer_fields(cpu.Fields(3, nodef.nx, ny, mpi_type='z+'))
        nodef.append_buffer_fields(cpu.Fields(3, nodef.nx, ny, mpi_type='z-'))

        exchange = NodeExchange(nodef)
        
        # generate random source
        for f in mainf_list[:-1]:
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_eh_bufs(*ehs)

        for f in nodef.cpuf_dict.values():
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_ehs(*ehs)

        # verify
        exchange.update_e()
        exchange.update_h()
        getf0, getf1 = {}, {}

        # mainf list
        self.gpu, self.cpu = gpu, cpu
        for f0, f1 in zip(mainf_list[:-1], mainf_list[1:]):
            getf0['e'] = getattr(self, f0.device_type).GetFields(f0, ['ey', 'ez'], \
                    (f0.nx-1, 0, 0), (f0.nx-1, f0.ny-2, f0.nz-2))
            getf1['e'] = getattr(self, f1.device_type).GetFields(f1, ['ey', 'ez'], \
                    (0, 0, 0), (0, f1.ny-2, f1.nz-2))

            getf0['h'] = getattr(self, f0.device_type).GetFields(f0, ['hy', 'hz'], \
                    (f0.nx-1, 1, 1), (f0.nx-1, f0.ny-1, f0.nz-1))
            getf1['h'] = getattr(self, f1.device_type).GetFields(f1, ['hy', 'hz'], \
                    (0, 1, 1), (0, f1.ny-1, f1.nz-1))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm(getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%s, %g, %s, %s, %s' % \
                        (self.args, norm, 'mainf', \
                        getf0[eh].mainf.device_type, getf1[eh].mainf.device_type) )

        # buffer 'x-'
        f0, f1 = nodef.cpuf_dict['x-'], mainf_list[0]
        getf0['e'] = cpu.GetFields(f0, ['ey', 'ez'], \
                (f0.nx-1, 0, 0), (f0.nx-1, f0.ny-2, f0.nz-2))
        getf1['e'] = gpu.GetFields(f1, ['ey', 'ez'], \
                (1, 0, 0), (1, f1.ny-2, f1.nz-2))

        getf0['h'] = cpu.GetFields(f0, ['hy', 'hz'], \
                (f0.nx-2, 1, 1), (f0.nx-2, f0.ny-1, f0.nz-1))
        getf1['h'] = gpu.GetFields(f1, ['hy', 'hz'], \
                (0, 1, 1), (0, f1.ny-1, f1.nz-1))

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            norm = np.linalg.norm( \
                    getf0[eh].get_fields() - getf1[eh].get_fields())
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'x-', eh) )

        # buffer 'y+'
        anx_list = nodef.accum_nx_list

        f1 = nodef.cpuf_dict['y+']
        for f0, anx0, anx1 in zip(mainf_list, anx_list[:-1], anx_list[1:]):
            getf0['e'] = getattr(self, f0.device_type).GetFields(f0, ['ex', 'ez'], \
                    (0, f0.ny-1, 0), (f0.nx-2, f0.ny-1, f0.nz-2))
            getf1['e'] = cpu.GetFields(f1, ['ey', 'ez'], \
                    (1, anx0, 0), (1, anx1-1, f1.nz-2))

            getf0['h'] = getattr(self, f0.device_type).GetFields(f0, ['hx', 'hz'], \
                    (1, f0.ny-2, 1), (f0.nx-1, f0.ny-2, f0.nz-1))
            getf1['h'] = cpu.GetFields(f1, ['hy', 'hz'], \
                    (0, anx0+1, 1), (0, anx1, f1.nz-1))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm( \
                        getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'y+', eh) )

        # buffer 'y-'
        f0 = nodef.cpuf_dict['y-']
        for f1, anx0, anx1 in zip(mainf_list, anx_list[:-1], anx_list[1:]):
            getf0['e'] = cpu.GetFields(f0, ['ey', 'ez'], \
                    (f0.nx-1, anx0, 0), (f0.nx-1, anx1-1, f0.nz-2))
            getf1['e'] = getattr(self, f1.device_type).GetFields(f1, ['ex', 'ez'], \
                    (0, 1, 0), (f1.nx-2, 1, f1.nz-2))

            getf0['h'] = cpu.GetFields(f0, ['hy', 'hz'], \
                    (f0.nx-2, anx0+1, 1), (f0.nx-2, anx1, f0.nz-1))
            getf1['h'] = getattr(self, f1.device_type).GetFields(f1, ['hx', 'hz'], \
                    (1, 0, 1), (f1.nx-1, 0, f1.nz-1))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm( \
                        getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'y-', eh) )

        # buffer 'z+'
        f1 = nodef.cpuf_dict['z+']
        for f0, anx0, anx1 in zip(mainf_list, anx_list[:-1], anx_list[1:]):
            getf0['e'] = getattr(self, f0.device_type).GetFields(f0, ['ex', 'ey'], \
                    (0, 0, f0.nz-1), (f0.nx-2, f0.ny-2, f0.nz-1))
            getf1['e'] = cpu.GetFields(f1, ['ey', 'ez'], \
                    (1, anx0, 0), (1, anx1-1, f1.nz-2))

            getf0['h'] = getattr(self, f0.device_type).GetFields(f0, ['hx', 'hy'], \
                    (1, 1, f0.nz-2), (f0.nx-1, f0.ny-1, f0.nz-2))
            getf1['h'] = cpu.GetFields(f1, ['hy', 'hz'], \
                    (0, anx0+1, 1), (0, anx1, f1.nz-1))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm( \
                        getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'z+', eh) )

        # buffer 'z-'
        f0 = nodef.cpuf_dict['z-']
        for f1, anx0, anx1 in zip(mainf_list, anx_list[:-1], anx_list[1:]):
            getf0['e'] = cpu.GetFields(f0, ['ey', 'ez'], \
                    (f0.nx-1, anx0, 0), (f0.nx-1, anx1-1, f0.nz-2))
            getf1['e'] = getattr(self, f1.device_type).GetFields(f1, ['ex', 'ey'], \
                    (0, 0, 1), (f1.nx-2, f1.ny-2, 1))

            getf0['h'] = cpu.GetFields(f0, ['hy', 'hz'], \
                    (f0.nx-2, anx0+1, 1), (f0.nx-2, anx1, f0.nz-1))
            getf1['h'] = getattr(self, f1.device_type).GetFields(f1, ['hx', 'hy'], \
                    (1, 1, 0), (f1.nx-1, f1.ny-1, 0))

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ['e', 'h']:
                norm = np.linalg.norm( \
                        getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, '%g, %s, %s' % (norm, 'z-', eh) )
Пример #15
0
    def test_y_pbc_x_exchange(self):
        # instance
        nx, ny, nz = 40, 50, 60
        #nx, ny, nz = 3, 4, 5
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)

        gpuf = gpu.Fields(context, gpu_devices[0], nx, ny, nz)
        cpuf = cpu.Fields(nx, ny, nz)
        mainf_list = [gpuf, cpuf]
        nodef = NodeFields(mainf_list)
        core = NodeCore(nodef)
        pbc = NodePbc(nodef, 'y')
        exchange = NodeExchange(nodef)

        # generate random source
        ehs_gpu = common_update.generate_random_ehs(nx, ny, nz, nodef.dtype)
        gpuf.set_eh_bufs(*ehs_gpu)
        ehs_gpu_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs_gpu))

        ehs_cpu = common_update.generate_random_ehs(nx, ny, nz, nodef.dtype)
        cpuf.set_ehs(*ehs_cpu)
        ehs_cpu_dict = dict(zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs_cpu))

        # verify
        for mainf in mainf_list:
            mainf.update_e()
        pbc.update_e()
        exchange.update_e()

        for mainf in mainf_list:
            mainf.update_h()
        pbc.update_h()
        exchange.update_h()

        mainf_list[-1].enqueue_barrier()
        getf0, getf1 = {}, {}

        # x-axis exchange
        getf0['e'] = gpu.GetFields(gpuf, ['ey', 'ez'], (nx - 1, 0, 0),
                                   (nx - 1, ny - 2, nz - 2))
        getf1['e'] = cpu.GetFields(cpuf, ['ey', 'ez'], (0, 0, 0),
                                   (0, ny - 2, nz - 2))

        getf0['h'] = gpu.GetFields(gpuf, ['hy', 'hz'], (nx - 1, 1, 1),
                                   (nx - 1, ny - 1, nz - 1))
        getf1['h'] = cpu.GetFields(cpuf, ['hy', 'hz'], (0, 1, 1),
                                   (0, ny - 1, nz - 1))

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            g0 = getf0[eh].get_fields()
            g1 = getf1[eh].get_fields()
            norm = np.linalg.norm(g0 - g1)
            self.assertEqual(norm, 0,
                             '%g, %s, %s' % (norm, 'x-axis exchange', eh))

        # y-axis pbc gpu
        getf0['e'] = gpu.GetFields(gpuf, ['ex', 'ez'], (0, ny - 1, 0),
                                   (nx - 2, ny - 1, nz - 2))
        getf1['e'] = gpu.GetFields(gpuf, ['ex', 'ez'], (0, 0, 0),
                                   (nx - 2, 0, nz - 2))

        getf0['h'] = gpu.GetFields(gpuf, ['hx', 'hz'], (1, ny - 1, 1),
                                   (nx - 1, ny - 1, nz - 1))
        getf1['h'] = gpu.GetFields(gpuf, ['hx', 'hz'], (1, 0, 1),
                                   (nx - 1, 0, nz - 1))

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            g0 = getf0[eh].get_fields()
            g1 = getf1[eh].get_fields()
            norm = np.linalg.norm(g0 - g1)
            self.assertEqual(norm, 0,
                             '%g, %s, %s' % (norm, 'y-axis pbc gpu', eh))

        # y-axis pbc cpu
        getf0['e'] = cpu.GetFields(cpuf, ['ex', 'ez'], (0, ny - 1, 0),
                                   (nx - 2, ny - 1, nz - 2))
        getf1['e'] = cpu.GetFields(cpuf, ['ex', 'ez'], (0, 0, 0),
                                   (nx - 2, 0, nz - 2))

        getf0['h'] = cpu.GetFields(cpuf, ['hx', 'hz'], (1, ny - 1, 1),
                                   (nx - 1, ny - 1, nz - 1))
        getf1['h'] = cpu.GetFields(cpuf, ['hx', 'hz'], (1, 0, 1),
                                   (nx - 1, 0, nz - 1))

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            g0 = getf0[eh].get_fields()
            g1 = getf1[eh].get_fields()
            norm = np.linalg.norm(g0 - g1)
            self.assertEqual(norm, 0,
                             '%g, %s, %s' % (norm, 'y-axis pbc cpu', eh))
Пример #16
0
    def runTest(self):
        axis, nx, ny, nz = self.args
        self.gpu, self.cpu = gpu, cpu

        # instance
        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)

        mainf_list = [gpu.Fields(context, device, nx, ny, nz) for device in gpu_devices]
        mainf_list.append(cpu.Fields(nx, ny, nz))
        nodef = NodeFields(mainf_list)
        dtype = nodef.dtype

        pbc = NodePbc(nodef, axis)
        exchange = NodeExchange(nodef)

        # generate random source
        for f in mainf_list[:-1]:
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_eh_bufs(*ehs)

        for f in nodef.cpuf_dict.values():
            nx, ny, nz = f.ns
            ehs = common_update.generate_random_ehs(nx, ny, nz, dtype)
            f.set_ehs(*ehs)

        # verify
        for mainf in mainf_list:
            mainf.update_e()
        pbc.update_e()
        exchange.update_e()

        for mainf in mainf_list:
            mainf.update_h()
        pbc.update_h()
        exchange.update_h()

        mainf_list[-1].enqueue_barrier()

        getf0, getf1 = {}, {}

        if axis == "x":
            f0, f1 = mainf_list[0], mainf_list[-1]
            getf0["e"] = getattr(self, f0.device_type).GetFields(f0, ["ey", "ez"], (0, 0, 0), (0, f0.ny - 2, f0.nz - 2))
            getf1["e"] = getattr(self, f1.device_type).GetFields(
                f1, ["ey", "ez"], (f1.nx - 1, 0, 0), (f1.nx - 1, f1.ny - 2, f1.nz - 2)
            )

            getf0["h"] = getattr(self, f0.device_type).GetFields(f0, ["hy", "hz"], (0, 1, 1), (0, f0.ny - 1, f0.nz - 1))
            getf1["h"] = getattr(self, f1.device_type).GetFields(
                f1, ["hy", "hz"], (f1.nx - 1, 1, 1), (f1.nx - 1, f1.ny - 1, f1.nz - 1)
            )

            for getf in getf0.values() + getf1.values():
                getf.get_event().wait()

            for eh in ["e", "h"]:
                norm = np.linalg.norm(getf0[eh].get_fields() - getf1[eh].get_fields())
                self.assertEqual(norm, 0, "%g, %s, %s" % (norm, "x", eh))

        elif axis == "y":
            for f in mainf_list:
                getf0["e"] = getattr(self, f.device_type).GetFields(f, ["ex", "ez"], (0, 0, 0), (f.nx - 2, 0, f.nz - 2))
                getf1["e"] = getattr(self, f.device_type).GetFields(
                    f, ["ex", "ez"], (0, f.ny - 1, 0), (f.nx - 2, f.ny - 1, f.nz - 2)
                )

                getf0["h"] = getattr(self, f.device_type).GetFields(f, ["hx", "hz"], (1, 0, 1), (f.nx - 1, 0, f.nz - 1))
                getf1["h"] = getattr(self, f.device_type).GetFields(
                    f, ["hx", "hz"], (1, f.ny - 1, 1), (f.nx - 1, f.ny - 1, f.nz - 1)
                )

                for getf in getf0.values() + getf1.values():
                    getf.get_event().wait()

                for eh in ["e", "h"]:
                    norm = np.linalg.norm(getf0[eh].get_fields() - getf1[eh].get_fields())
                    self.assertEqual(norm, 0, "%g, %s, %s, %s" % (norm, "y", eh, f.device_type))

        elif axis == "z":
            for f in mainf_list:
                getf0["e"] = getattr(self, f.device_type).GetFields(
                    f, ["ex", "ey"], (0, 0, f.nz - 1), (f.nx - 2, f.ny - 2, f.nz - 1)
                )
                getf1["e"] = getattr(self, f.device_type).GetFields(f, ["ex", "ey"], (0, 0, 0), (f.nx - 2, f.ny - 2, 0))

                getf0["h"] = getattr(self, f.device_type).GetFields(
                    f, ["hx", "hy"], (1, 1, f.nz - 1), (f.nx - 1, f.ny - 1, f.nz - 1)
                )
                getf1["h"] = getattr(self, f.device_type).GetFields(f, ["hx", "hy"], (1, 1, 0), (f.nx - 1, f.ny - 1, 0))

                for getf in getf0.values() + getf1.values():
                    getf.get_event().wait()

                for eh in ["e", "h"]:
                    norm = np.linalg.norm(getf0[eh].get_fields() - getf1[eh].get_fields())
                    self.assertEqual(norm, 0, "%g, %s, %s" % (norm, "z", eh))
Пример #17
0
    def runTest(self):
        axis, nx, ny, nz, mpi_type = self.args

        fields = Fields(nx, ny, nz, mpi_type=mpi_type)
        core = Core(fields)
        pbc = Pbc(fields, axis)

        # allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        fields.set_ehs(*ehs)

        # update
        fields.update_e()
        fields.update_h()
        fields.enqueue_barrier()

        # verify
        getf0, getf1 = {}, {}
        strfs_e = {
            'x': ['ey', 'ez'],
            'y': ['ex', 'ez'],
            'z': ['ex', 'ey']
        }[axis]
        strfs_h = {
            'x': ['hy', 'hz'],
            'y': ['hx', 'hz'],
            'z': ['hx', 'hy']
        }[axis]

        pt0 = (0, 0, 0)
        pt1 = { 'x': (0, ny-2, nz-2), \
                'y': (nx-2, 0, nz-2), \
                'z': (nx-2, ny-2, 0) }[axis]
        getf0['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (nx-1, 0, 0), \
                'y': (0, ny-1, 0), \
                'z': (0, 0, nz-1) }[axis]
        pt1 = { 'x': (nx-1, ny-2, nz-2), \
                'y': (nx-2, ny-1, nz-2), \
                'z': (nx-2, ny-2, nz-1) }[axis]
        getf1['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (0, 1, 1), \
                'y': (1, 0, 1), \
                'z': (1, 1, 0) }[axis]
        pt1 = { 'x': (0, ny-1, nz-1), \
                'y': (nx-1, 0, nz-1), \
                'z': (nx-1, ny-1, 0) }[axis]
        getf0['h'] = GetFields(fields, strfs_h, pt0, pt1)

        pt0 = { 'x': (nx-1, 1, 1), \
                'y': (1, ny-1, 1), \
                'z': (1, 1, nz-1) }[axis]
        pt1 = (nx - 1, ny - 1, nz - 1)
        getf1['h'] = GetFields(fields, strfs_h, pt0, pt1)

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            g0 = getf0[eh].get_fields()
            g1 = getf1[eh].get_fields()
            norm = np.linalg.norm(g0 - g1)
            '''
            print eh
            print g0
            print g1
            '''
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))
Пример #18
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, tmax = self.args

        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        fields = Fields(context, device, nx, ny, nz, coeff_use, precision_float)
        core = Core(fields)

        # allocations
        ns = fields.ns
        dtype = fields.dtype
        strf_list = ["ex", "ey", "ez", "hx", "hy", "hz"]

        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_eh_bufs(*ehs)

        ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz, dtype)
        if "e" in coeff_use:
            fields.set_ce_bufs(*ces)
        if "h" in coeff_use:
            fields.set_ch_bufs(*chs)

        tmpf = np.zeros(fields.ns_pitch, dtype=dtype)

        # update
        if ufunc == "e":
            for tstep in xrange(0, tmax):
                fields.update_e()
                common_update.update_e(ehs, ces)

            for strf, eh in zip(strf_list, ehs)[:3]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z])
                max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max()
                self.assertEqual(norm, 0, "%s, %s, %g, %g" % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == "ez":
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad :])
                    else:
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad - 1 :])
                    self.assertEqual(norm2, 0, "%s, %s, %g, padding" % (self.args, strf, norm2))

        elif ufunc == "h":
            for tstep in xrange(0, tmax):
                fields.update_h()
                common_update.update_h(ehs, chs)

            for strf, eh in zip(strf_list, ehs)[3:]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slice_z])
                max_diff = np.abs(eh - tmpf[:, :, fields.slice_z]).max()
                self.assertEqual(norm, 0, "%s, %s, %g, %g" % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == "hz":
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad :])
                    else:
                        norm2 = np.linalg.norm(tmpf[:, :, -fields.pad :])
                    self.assertEqual(norm2, 0, "%s, %s, %g, padding" % (self.args, strf, norm2))
Пример #19
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, use_cpu_core, split, tmax = self.args
        fields = Fields(nx, ny, nz, coeff_use, precision_float, use_cpu_core)
        core = Core(fields)

        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']
        slice_xyz = [slice(None, None), slice(None, None), fields.slice_z]

        # allocations
        ns = fields.ns
        dtype = fields.dtype

        ehs = common_update.generate_random_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_ehs(*ehs)

        ces, chs = common_update.generate_random_cs(coeff_use, nx, ny, nz,
                                                    dtype)
        if 'e' in coeff_use:
            fields.set_ces(*ces)
        if 'h' in coeff_use:
            fields.set_chs(*chs)

        # update
        if ufunc == 'e':
            for tstep in xrange(0, tmax):
                fields.update_e()
                common_update.update_e(ehs, ces)
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[:3]:
                norm = np.linalg.norm(eh - fields.get(strf)[slice_xyz])
                max_diff = np.abs(eh - fields.get(strf)[slice_xyz]).max()
                self.assertEqual(
                    norm, 0,
                    '%s, %s, %g, %g' % (self.args, strf, norm, max_diff))

                if fields.pad != 0:
                    if strf == 'ez':
                        norm2 = np.linalg.norm(
                            fields.get(strf)[:, :, -fields.pad:])
                    else:
                        norm2 = np.linalg.norm(
                            fields.get(strf)[:, :, -fields.pad - 1:])
                    self.assertEqual(
                        norm2, 0,
                        '%s, %s, %g, padding' % (self.args, strf, norm2))

        elif ufunc == 'h':
            for tstep in xrange(0, tmax):
                fields.update_h()
                common_update.update_h(ehs, chs)
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[3:]:
                norm = np.linalg.norm(eh - fields.get(strf)[slice_xyz])
                max_diff = np.abs(eh - fields.get(strf)[slice_xyz]).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )

                if fields.pad != 0:
                    if strf == 'hz':
                        norm2 = np.linalg.norm(
                            fields.get(strf)[:, :, -fields.pad:])
                    else:
                        norm2 = np.linalg.norm(
                            fields.get(strf)[:, :, -fields.pad:])
                    self.assertEqual(
                        norm2, 0,
                        '%s, %s, %g, padding' % (self.args, strf, norm2))
Пример #20
0
    def runTest(self):
        axis, nx, ny, nz, precision_float = self.args

        gpu_devices = common_gpu.gpu_device_list(print_info=False)
        context = cl.Context(gpu_devices)
        device = gpu_devices[0]
        fields = Fields(context, device, nx, ny, nz, '', precision_float)
        pbc = Pbc(fields, axis)

        # allocations
        ehs = common_update.generate_random_ehs(nx, ny, nz, fields.dtype)
        fields.set_eh_bufs(*ehs)

        # update
        fields.update_e()
        fields.update_h()

        # verify
        getf0, getf1 = {}, {}
        strfs_e = {
            'x': ['ey', 'ez'],
            'y': ['ex', 'ez'],
            'z': ['ex', 'ey']
        }[axis]
        strfs_h = {
            'x': ['hy', 'hz'],
            'y': ['hx', 'hz'],
            'z': ['hx', 'hy']
        }[axis]

        pt0 = (0, 0, 0)
        pt1 = { 'x': (0, ny-2, nz-2), \
                'y': (nx-2, 0, nz-2), \
                'z': (nx-2, ny-2, 0) }[axis]
        getf0['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (nx-1, 0, 0), \
                'y': (0, ny-1, 0), \
                'z': (0, 0, nz-1) }[axis]
        pt1 = { 'x': (nx-1, ny-2, nz-2), \
                'y': (nx-2, ny-1, nz-2), \
                'z': (nx-2, ny-2, nz-1) }[axis]
        getf1['e'] = GetFields(fields, strfs_e, pt0, pt1)

        pt0 = { 'x': (0, 1, 1), \
                'y': (1, 0, 1), \
                'z': (1, 1, 0) }[axis]
        pt1 = { 'x': (0, ny-1, nz-1), \
                'y': (nx-1, 0, nz-1), \
                'z': (nx-1, ny-1, 0) }[axis]
        getf0['h'] = GetFields(fields, strfs_h, pt0, pt1)

        pt0 = { 'x': (nx-1, 1, 1), \
                'y': (1, ny-1, 1), \
                'z': (1, 1, nz-1) }[axis]
        pt1 = (nx - 1, ny - 1, nz - 1)
        getf1['h'] = GetFields(fields, strfs_h, pt0, pt1)

        for getf in getf0.values() + getf1.values():
            getf.get_event().wait()

        for eh in ['e', 'h']:
            norm = np.linalg.norm( \
                    getf0[eh].get_fields() - getf1[eh].get_fields() )
            self.assertEqual(norm, 0, '%g, %s, %s' % (norm, self.args, eh))