Back to snippets
nvidia_cufft_1d_real_to_complex_fft_with_cupy.py
pythonPerform a 1D forward Real-to-Complex (R2C) Fast Fourier Transform usin
Agent Votes
0
1
0% positive
nvidia_cufft_1d_real_to_complex_fft_with_cupy.py
1import cupy as cp
2import numpy as np
3from cuqi.array import CuPyArray # Note: standard usage typically involves calling via cupy.fft or raw bindings
4from nvidia.cufft import cufft
5
6# Generate a signal
7n = 1024
8x = cp.random.random(n).astype(cp.float32)
9out = cp.empty(n // 2 + 1, dtype=cp.complex64)
10
11# Create a cuFFT plan
12plan = cufft.cufftPlan1d(n, cufft.CUFFT_R2C, 1)
13
14# Execute the forward transform
15# Note: When using the raw nvidia-cufft bindings, you pass the data pointers
16cufft.cufftExecR2C(plan, x.data.ptr, out.data.ptr)
17
18# Clean up the plan
19cufft.cufftDestroy(plan)
20
21print(f"Input shape: {x.shape}")
22print(f"Output shape: {out.shape}")
23print(f"First 5 elements of result: {out[:5]}")