예제 #1
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)

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

        ehs = common_update.generate_random_ehs(ufunc, nx, ny, nz, dtype)
        pad_arr = np.zeros(fields.ns_pad, dtype=dtype)
        for strf, eh in zip(strf_list, ehs):
            eh_pitch = np.append(eh, pad_arr, 2).copy('C')
            cl.enqueue_copy(fields.queue, fields.get_buf(strf), eh_pitch)

        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):
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slz])
                max_diff = np.abs(eh - tmpf[:, :, fields.slz]).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )

        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):
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slz])
                max_diff = np.abs(eh - tmpf[:, :, fields.slz]).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )
예제 #2
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)

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

        ehs = common_update.generate_random_ehs(ufunc, nx, ny, nz, dtype)
        pad_arr = np.zeros(fields.ns_pad, dtype=dtype)
        for strf, eh in zip(strf_list, ehs):
            eh_pitch = np.append(eh, pad_arr, 2).copy("C")
            cl.enqueue_copy(fields.queue, fields.get_buf(strf), eh_pitch)

        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):
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slz])
                max_diff = np.abs(eh - tmpf[:, :, fields.slz]).max()
                self.assertEqual(norm, 0, "%s, %s, %g, %g" % (self.args, strf, norm, max_diff))

        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):
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(eh - tmpf[:, :, fields.slz])
                max_diff = np.abs(eh - tmpf[:, :, fields.slz]).max()
                self.assertEqual(norm, 0, "%s, %s, %g, %g" % (self.args, strf, norm, max_diff))
예제 #3
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, use_cpu_core, tmax = self.args
        fields = Fields(nx, ny, nz, coeff_use, precision_float, use_cpu_core)
        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']

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

        ehs = common_update.generate_random_ehs(ufunc, nx, ny, nz, dtype)
        for strf, eh in zip(strf_list, ehs):
            fields.get(strf)[:] = eh

        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):
                norm = np.linalg.norm(eh - fields.get(strf))
                max_diff = np.abs(eh - fields.get(strf)).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )

        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):
                norm = np.linalg.norm(eh - fields.get(strf))
                max_diff = np.abs(eh - fields.get(strf)).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )
예제 #4
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, use_cpu_core, tmax = self.args
        fields = Fields(nx, ny, nz, coeff_use, precision_float, use_cpu_core)
        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']

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

        ehs = common_update.generate_random_ehs(ufunc, nx, ny, nz, dtype)
        for strf, eh in zip(strf_list, ehs):
            fields.get(strf)[:] = eh

        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):
                norm = np.linalg.norm(eh - fields.get(strf))
                max_diff = np.abs(eh - fields.get(strf)).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )

        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):
                norm = np.linalg.norm(eh - fields.get(strf))
                max_diff = np.abs(eh - fields.get(strf)).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )