yum-mirror/VkFFT
git clone https://git.yummers.dev/yum-mirror/VkFFT
d6f7ded
v1.3.4
1//general parts 2#include <stdio.h> 3#include <vector> 4#include <memory> 5#include <string.h> 6#include <chrono> 7#include <thread> 8#include <iostream> 9#ifndef __STDC_FORMAT_MACROS 10#define __STDC_FORMAT_MACROS 11#endif 12#include <inttypes.h> 13 14//CUDA parts 15#include "cuda_runtime.h" 16#include "device_launch_parameters.h" 17#include <cufft.h> 18 19void launch_precision_cuFFT_r2c ( void * inputC , void * output_cuFFT , int device_id , uint64_t * dims ) 20{ 21cudaSetDevice ( device_id ) ; 22cufftHandle planR2C ; 23cufftReal * dataR ; 24cufftComplex * dataC ; 25cudaMalloc (( void ** ) & dataR , sizeof ( cufftComplex ) * ( dims [ 0 ] / 2 + 1 ) * dims [ 1 ] * dims [ 2 ]) ; 26cudaMalloc (( void ** ) & dataC , sizeof ( cufftComplex ) * ( dims [ 0 ] / 2 + 1 ) * dims [ 1 ] * dims [ 2 ]) ; 27cudaMemcpy ( dataR , inputC , sizeof ( cufftReal ) * dims [ 0 ] * dims [ 1 ] * dims [ 2 ] , cudaMemcpyHostToDevice ) ; 28if ( cudaGetLastError () != cudaSuccess ) { 29fprintf ( stderr , "Cuda error: Failed to allocate \n " ) ; 30return ; 31} 32switch ( dims [ 4 ]) { 33case 1 : 34cufftPlan1d ( & planR2C , dims [ 0 ] , CUFFT_R2C , 1 ) ; 35break ; 36case 2 : 37cufftPlan2d ( & planR2C , dims [ 1 ] , dims [ 0 ] , CUFFT_R2C ) ; 38break ; 39case 3 : 40cufftPlan3d ( & planR2C , dims [ 2 ] , dims [ 1 ] , dims [ 0 ] , CUFFT_R2C ) ; 41break ; 42} 43for ( int i = 0 ; i < 1 ; i ++ ) { 44cufftExecR2C ( planR2C , dataR , dataC ) ; 45} 46cudaDeviceSynchronize () ; 47cufftDestroy ( planR2C ) ; 48switch ( dims [ 4 ]) { 49case 1 : 50cufftPlan1d ( & planR2C , dims [ 0 ] , CUFFT_C2R , 1 ) ; 51break ; 52case 2 : 53cufftPlan2d ( & planR2C , dims [ 1 ] , dims [ 0 ] , CUFFT_C2R ) ; 54break ; 55case 3 : 56cufftPlan3d ( & planR2C , dims [ 2 ] , dims [ 1 ] , dims [ 0 ] , CUFFT_C2R ) ; 57break ; 58} 59for ( int i = 0 ; i < 1 ; i ++ ) { 60cufftExecC2R ( planR2C , dataC , dataR ) ; 61} 62cudaDeviceSynchronize () ; 63cudaMemcpy ( output_cuFFT , dataR , sizeof ( float ) * ( dims [ 0 ] ) * dims [ 1 ] * dims [ 2 ] , cudaMemcpyDeviceToHost ) ; 64cudaDeviceSynchronize () ; 65cufftDestroy ( planR2C ) ; 66cudaFree ( dataR ) ; 67cudaFree ( dataC ) ; 68}