yum-mirror/VkFFT

git clone https://git.yummers.dev/yum-mirror/VkFFT

Tolmachev DmitriiVkFFT v1.3.3 released6f7ded

develop
1.8 KiB68 linesraw
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{
21	cudaSetDevice(device_id);
22	cufftHandle planR2C;
23	cufftReal* dataR;
24	cufftComplex* dataC;
25	cudaMalloc((void**)&dataR, sizeof(cufftComplex) * (dims[0]/2+1) * dims[1] * dims[2]);
26	cudaMalloc((void**)&dataC, sizeof(cufftComplex) * (dims[0] / 2 + 1) * dims[1] * dims[2]);
27	cudaMemcpy(dataR, inputC, sizeof(cufftReal) * dims[0] * dims[1] * dims[2], cudaMemcpyHostToDevice);
28	if (cudaGetLastError() != cudaSuccess) {
29		fprintf(stderr, "Cuda error: Failed to allocate\n");
30		return;
31	}
32	switch (dims[4]) {
33	case 1:
34		cufftPlan1d(&planR2C, dims[0], CUFFT_R2C, 1);
35		break;
36	case 2:
37		cufftPlan2d(&planR2C, dims[1], dims[0], CUFFT_R2C);
38		break;
39	case 3:
40		cufftPlan3d(&planR2C, dims[2], dims[1], dims[0], CUFFT_R2C);
41		break;
42	}
43	for (int i = 0; i < 1; i++) {
44		cufftExecR2C(planR2C, dataR, dataC);
45	}
46	cudaDeviceSynchronize();
47	cufftDestroy(planR2C);
48	switch (dims[4]) {
49	case 1:
50		cufftPlan1d(&planR2C, dims[0], CUFFT_C2R, 1);
51		break;
52	case 2:
53		cufftPlan2d(&planR2C, dims[1], dims[0], CUFFT_C2R);
54		break;
55	case 3:
56		cufftPlan3d(&planR2C, dims[2], dims[1], dims[0], CUFFT_C2R);
57		break;
58	}
59	for (int i = 0; i < 1; i++) {
60		cufftExecC2R(planR2C, dataC, dataR);
61	}
62	cudaDeviceSynchronize();
63	cudaMemcpy(output_cuFFT, dataR, sizeof(float) * (dims[0] ) * dims[1] * dims[2], cudaMemcpyDeviceToHost);
64	cudaDeviceSynchronize();
65	cufftDestroy(planR2C);
66	cudaFree(dataR);
67	cudaFree(dataC);
68}