Example #1
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, tmax = self.args

        fields = gpu.Fields(0, nx, ny, nz, coeff_use, precision_float)
        gpu.Core(fields)

        fields_ref = naive.Fields(nx,
                                  ny,
                                  nz,
                                  precision_float,
                                  segment_nbytes=64)
        naive.Core(fields_ref)

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

        ehs = common_random.generate_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_eh_bufs(*ehs)
        fields_ref.set_ehs(*ehs)

        ces, chs = common_random.generate_cs(nx, ny, nz, dtype, coeff_use)
        if 'e' in coeff_use:
            fields.set_ce_bufs(*ces)
            fields_ref.set_ces(*ces)
        if 'h' in coeff_use:
            fields.set_ch_bufs(*chs)
            fields_ref.set_chs(*chs)

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

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

            for strf, eh in zip(strf_list, ehs)[:3]:
                cuda.memcpy_dtoh(tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(fields_ref.get(strf) - tmpf)
                max_diff = np.abs(fields_ref.get(strf) - tmpf).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()
                fields_ref.update_h()

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

        fields.context.pop()
Example #2
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, use_cpu_core, tmax = self.args
        qtask = cpu.QueueTask()
        fields = cpu.Fields(qtask, nx, ny, nz, coeff_use, precision_float,
                            use_cpu_core)
        cpu.Core(fields)

        fields_ref = naive.Fields(nx,
                                  ny,
                                  nz,
                                  precision_float,
                                  segment_nbytes=16)
        naive.Core(fields_ref)

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

        ehs = common_random.generate_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_ehs(*ehs)
        fields_ref.set_ehs(*ehs)

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

        # verify
        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']

        if ufunc == 'e':
            for tstep in xrange(0, tmax):
                fields.update_e()
                fields_ref.update_e()
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[:3]:
                norm = np.linalg.norm(fields.get(strf) - fields_ref.get(strf))
                max_diff = np.abs(fields.get(strf) -
                                  fields_ref.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()
                fields_ref.update_h()
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[3:]:
                norm = np.linalg.norm(fields.get(strf) - fields_ref.get(strf))
                max_diff = np.abs(fields.get(strf) -
                                  fields_ref.get(strf)).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )
Example #3
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 = gpu.Fields(context, device, nx, ny, nz, coeff_use,
                            precision_float)
        gpu.Core(fields)

        fields_ref = naive.Fields(nx, ny, nz, precision_float)
        naive.Core(fields_ref)

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

        ehs = common_random.generate_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_eh_bufs(*ehs)
        fields_ref.set_ehs(*ehs)

        ces, chs = common_random.generate_cs(nx, ny, nz, dtype, coeff_use)
        if 'e' in coeff_use:
            fields.set_ce_bufs(*ces)
            fields_ref.set_ces(*ces)
        if 'h' in coeff_use:
            fields.set_ch_bufs(*chs)
            fields_ref.set_chs(*chs)

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

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

            for strf, eh in zip(strf_list, ehs)[:3]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(fields_ref.get(strf) - tmpf)
                max_diff = np.abs(fields_ref.get(strf) - tmpf).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()
                fields_ref.update_h()

            for strf, eh in zip(strf_list, ehs)[3:]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(fields_ref.get(strf) - tmpf)
                max_diff = np.abs(fields_ref.get(strf) - tmpf).max()
                self.assertEqual(
                    norm, 0,
                    '%s, %s, %g, %g' % (self.args, strf, norm, max_diff))
Example #4
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]
        qtask = cpu.QueueTask()
        fields = gpu.Fields(context, device, qtask, nx, ny, nz, coeff_use, precision_float)
        gpu.Core(fields)

        fields_ref = naive.Fields(nx, ny, nz, precision_float, segment_nbytes=64)
        naive.Core(fields_ref)

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

        ehs = common_random.generate_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_eh_bufs(*ehs)
        fields_ref.set_ehs(*ehs)

        ces, chs = common_random.generate_cs(nx, ny, nz, dtype, coeff_use)
        if 'e' in coeff_use:
            fields.set_ce_bufs(*ces)
            fields_ref.set_ces(*ces)
        if 'h' in coeff_use:
            fields.set_ch_bufs(*chs)
            fields_ref.set_chs(*chs)

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

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

            for strf, eh in zip(strf_list, ehs)[:3]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(fields_ref.get(strf) - tmpf)
                max_diff = np.abs(fields_ref.get(strf) - tmpf).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()
                fields_ref.update_h()

            for strf, eh in zip(strf_list, ehs)[3:]:
                cl.enqueue_copy(fields.queue, tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(fields_ref.get(strf) - tmpf)
                max_diff = np.abs(fields_ref.get(strf) - tmpf).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % (self.args, strf, norm, max_diff) )
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, use_cpu_core, tmax = self.args
        qtask = cpu.QueueTask()
        fields = cpu.Fields(qtask, nx, ny, nz, coeff_use, precision_float, use_cpu_core)
        cpu.Core(fields)

        fields_ref = naive.Fields(nx, ny, nz, precision_float, segment_nbytes=16)
        naive.Core(fields_ref)

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

        ehs = common_random.generate_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_ehs(*ehs)
        fields_ref.set_ehs(*ehs)

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

        # verify
        strf_list = ['ex', 'ey', 'ez', 'hx', 'hy', 'hz']

        if ufunc == 'e':
            for tstep in xrange(0, tmax):
                for instance in fields.instance_list:
                    instance.update_e('pre')
                    instance.update_e('post')
                fields_ref.update_e()
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[:3]:
                norm = np.linalg.norm(fields.get(strf) - fields_ref.get(strf))
                max_diff = np.abs(fields.get(strf) - fields_ref.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):
                for instance in fields.instance_list:
                    instance.update_h('pre')
                    instance.update_h('post')
                fields_ref.update_h()
            fields.enqueue_barrier()

            for strf, eh in zip(strf_list, ehs)[3:]:
                norm = np.linalg.norm(fields.get(strf) - fields_ref.get(strf))
                max_diff = np.abs(fields.get(strf) - fields_ref.get(strf)).max()
                self.assertEqual(norm, 0, '%s, %s, %g, %g' % \
                        (self.args, strf, norm, max_diff) )
Example #6
0
    def runTest(self):
        ufunc, nx, ny, nz, coeff_use, precision_float, tmax = self.args

        fields = gpu.Fields(0, nx, ny, nz, coeff_use, precision_float)
        gpu.Core(fields)

        fields_ref = naive.Fields(nx, ny, nz, precision_float, segment_nbytes=64)
        naive.Core(fields_ref)

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

        ehs = common_random.generate_ehs(nx, ny, nz, dtype, ufunc)
        fields.set_eh_bufs(*ehs)
        fields_ref.set_ehs(*ehs)

        ces, chs = common_random.generate_cs(nx, ny, nz, dtype, coeff_use)
        if 'e' in coeff_use:
            fields.set_ce_bufs(*ces)
            fields_ref.set_ces(*ces)
        if 'h' in coeff_use:
            fields.set_ch_bufs(*chs)
            fields_ref.set_chs(*chs)

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

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

            for strf, eh in zip(strf_list, ehs)[:3]:
                cuda.memcpy_dtoh(tmpf, fields.get_buf(strf))
                norm = np.linalg.norm(fields_ref.get(strf) - tmpf)
                max_diff = np.abs(fields_ref.get(strf) - tmpf).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()
                fields_ref.update_h()

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

        fields.context.pop()