def test_make_plan_many(self): fft = cufft.CUFFT(self.ctx) fft.auto_allocation = False sz = fft.make_plan_many((256, 128), 8, cufft.CUFFT_C2C) logging.debug( "make_plan_many (default layout) for 256x128 x8 returned %d", sz) logging.debug("size is %d", fft.size) self.assertEqual(fft.execute, fft.exec_c2c) fft = cufft.CUFFT(self.ctx) fft.auto_allocation = False sz = fft.make_plan_many((256, 128), 8, cufft.CUFFT_C2C, (256, 128), 1, 256 * 128, (256, 128), 1, 256 * 128) logging.debug( "make_plan_many (tight layout) for 256x128 x8 returned is %d", sz) logging.debug("size is %d", fft.size)
def test_auto_allocation(self): fft = cufft.CUFFT(self.ctx) self.assertTrue(fft.auto_allocation) fft.auto_allocation = False self.assertFalse(fft.auto_allocation) fft.auto_allocation = True self.assertTrue(fft.auto_allocation)
def _test_exec_complex(self, dtype): x = numpy.zeros([32, 64], dtype=dtype) x.real = numpy.random.rand(x.size).reshape(x.shape) - 0.5 x.imag = numpy.random.rand(x.size).reshape(x.shape) - 0.5 y = numpy.ones_like(x) x_gold = x.copy() try: y_gold = numpy.fft.fft2(x) except TypeError: y_gold = None # for pypy xbuf = cu.MemAlloc(self.ctx, x) ybuf = cu.MemAlloc(self.ctx, y) # Forward transform fft = cufft.CUFFT(self.ctx) fft.auto_allocation = False sz = fft.make_plan_many(x.shape, 1, { numpy.complex64: cufft.CUFFT_C2C, numpy.complex128: cufft.CUFFT_Z2Z }[dtype]) tmp = cu.MemAlloc(self.ctx, sz) fft.workarea = tmp self.assertEqual(fft.workarea, tmp) self.assertEqual(fft.execute, { numpy.complex64: fft.exec_c2c, numpy.complex128: fft.exec_z2z }[dtype]) fft.execute(xbuf, ybuf, cufft.CUFFT_FORWARD) ybuf.to_host(y) if y_gold is not None: delta = y - y_gold max_diff = numpy.fabs( numpy.sqrt(delta.real * delta.real + delta.imag * delta.imag)).max() logging.debug("Forward max_diff is %.6e", max_diff) self.assertLess(max_diff, { numpy.complex64: 1.0e-3, numpy.complex128: 1.0e-6 }[dtype]) # Inverse transform y /= x.size # correct scale before inverting ybuf.to_device_async(y) xbuf.memset32_async(0) # reset the resulting vector fft.execute(ybuf, xbuf, cufft.CUFFT_INVERSE) xbuf.to_host(x) delta = x - x_gold max_diff = numpy.fabs( numpy.sqrt(delta.real * delta.real + delta.imag * delta.imag)).max() logging.debug("Inverse max_diff is %.6e", max_diff) self.assertLess(max_diff, { numpy.complex64: 1.0e-3, numpy.complex128: 1.0e-6 }[dtype])
def test_version(self): fft = cufft.CUFFT(self.ctx) ver = fft.version logging.debug("cuFFT version is %d", ver) self.assertTrue(ver == int(ver))