Пример #1
0
        /// <summary>
        /// Creates a 2D plan.
        /// </summary>
        /// <param name="fftType">Type of FFT.</param>
        /// <param name="dataType">Data type.</param>
        /// <param name="nx">The number of samples in x dimension.</param>
        /// <param name="ny">The number of samples in y dimension.</param>
        /// <param name="batchSize">Size of batch.</param>
        /// <returns>Plan.</returns>
        public override FFTPlan2D Plan2D(eFFTType fftType, eDataType dataType, int nx, int ny, int batchSize)
        {
            int         insize, outsize;
            CUFFTType   cuFFTType = VerifyTypes(fftType, dataType, out insize, out outsize);
            cufftHandle handle    = new cufftHandle();
            CUFFTResult res;

            if (batchSize <= 1)
            {
                res = _driver.cufftPlan2d(ref handle, nx, ny, cuFFTType);
            }
            else
            {
                res = _driver.cufftPlanMany(ref handle, 2, new int[] { nx, ny }, null, 1, 0, null, 1, 0, cuFFTType, batchSize);
            }
            if (res != CUFFTResult.Success)
            {
                throw new CudafyHostException(res.ToString());
            }
            FFTPlan2D   plan   = new FFTPlan2D(nx, ny, batchSize, this);
            FFTPlan2DEx planEx = new FFTPlan2DEx(plan)
            {
                CudaFFTHandle = handle, CudaFFTType = cuFFTType, DataType = dataType
            };

            Plans.Add(plan, planEx);
            return(plan);
        }
Пример #2
0
        /// <summary>
        /// Creates a 2D plan.
        /// </summary>
        /// <param name="fftType">Type of FFT.</param>
        /// <param name="dataType">The data type.</param>
        /// <param name="nx">The x length in samples.</param>
        /// <param name="ny">The y length in samples.</param>
        /// <param name="batch">The number of FFTs in batch.</param>
        /// <returns>
        /// Plan.
        /// </returns>
        public override FFTPlan2D Plan2D(eFFTType fftType, eDataType dataType, int nx, int ny, int batch)
        {
            int       insize, outsize;
            int       totalSize = nx * ny;
            CUFFTType cuFFTType = VerifyTypes(fftType, dataType, out insize, out outsize);
            IntPtr    pin       = fftwf.malloc(totalSize * insize * batch);
            IntPtr    pout      = fftwf.malloc(totalSize * outsize * batch);

            Ifftw_plan fwdPlan;
            Ifftw_plan invPlan;

            if (dataType == eDataType.Single)
            {
                if (batch == 1)
                {
                    fwdPlan = fftwf_plan.dft_2d(fftType, nx, ny, pin, pout, fftw_direction.Forward, fftw_flags.Estimate);
                    invPlan = fftwf_plan.dft_2d(fftType, nx, ny, pin, pout, fftw_direction.Backward, fftw_flags.Estimate);
                }
                else
                {
                    fwdPlan = fftwf_plan.dft_many(fftType, 2, new int[] { nx, ny }, batch,
                                                  pin, null, 1, nx * ny,
                                                  pout, null, 1, nx * ny, fftw_direction.Forward, fftw_flags.Estimate);
                    invPlan = fftwf_plan.dft_many(fftType, 2, new int[] { nx, ny }, batch,
                                                  pin, null, 1, nx * ny,
                                                  pout, null, 1, nx * ny, fftw_direction.Backward, fftw_flags.Estimate);
                }
            }
            else
            {
                if (batch == 1)
                {
                    fwdPlan = fftw_plan.dft_2d(fftType, nx, ny, pin, pout, fftw_direction.Forward, fftw_flags.Estimate);
                    invPlan = fftw_plan.dft_2d(fftType, nx, ny, pin, pout, fftw_direction.Backward, fftw_flags.Estimate);
                }
                else
                {
                    fwdPlan = fftw_plan.dft_many(fftType, 2, new int[] { nx, ny }, batch,
                                                 pin, null, 1, nx * ny,
                                                 pout, null, 1, nx * ny, fftw_direction.Forward, fftw_flags.Estimate);
                    invPlan = fftw_plan.dft_many(fftType, 2, new int[] { nx, ny }, batch,
                                                 pin, null, 1, nx * ny,
                                                 pout, null, 1, nx * ny, fftw_direction.Backward, fftw_flags.Estimate);
                }
            }

            FFTPlan2D   plan   = new FFTPlan2D(nx, ny, batch, this);
            FFTPlan2DEx planEx = new FFTPlan2DEx(plan)
            {
                FFTWFwdPlan = fwdPlan, FFTWInvPlan = invPlan, N = totalSize, DataType = dataType
            };

            Plans.Add(plan, planEx);
            return(plan);
        }
Пример #3
0
 public FFTPlan2DEx(FFTPlan2D plan)
 {
     Plan = plan;
 }