yum-mirror/VkFFT

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

Tolmachev DmitriiVkFFT v1.3.3 released6f7ded

master
1.7 KiB67 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//ROCM parts
15#include "hip/hip_runtime.h"
16#include <hipfft.h>
17
18void launch_precision_rocFFT_r2c(void* inputC, void* output_rocFFT, int device_id, uint64_t* dims)
19{
20	hipSetDevice(device_id);
21	hipfftHandle planR2C;
22	hipfftReal* dataR;
23	hipfftComplex* dataC;
24	hipMalloc((void**)&dataR, sizeof(hipfftComplex) * (dims[0]/2+1) * dims[1] * dims[2]);
25	hipMalloc((void**)&dataC, sizeof(hipfftComplex) * (dims[0] / 2 + 1) * dims[1] * dims[2]);
26	hipMemcpy(dataR, inputC, sizeof(hipfftReal) * dims[0] * dims[1] * dims[2], hipMemcpyHostToDevice);
27	if (hipGetLastError() != hipSuccess) {
28		fprintf(stderr, "ROCM error: Failed to allocate\n");
29		return;
30	}
31	switch (dims[4]) {
32	case 1:
33		hipfftPlan1d(&planR2C, dims[0], HIPFFT_R2C, 1);
34		break;
35	case 2:
36		hipfftPlan2d(&planR2C, dims[1], dims[0], HIPFFT_R2C);
37		break;
38	case 3:
39		hipfftPlan3d(&planR2C, dims[2], dims[1], dims[0], HIPFFT_R2C);
40		break;
41	}
42	for (int i = 0; i < 1; i++) {
43		hipfftExecR2C(planR2C, dataR, dataC);
44	}
45	hipDeviceSynchronize();
46	hipfftDestroy(planR2C);
47	switch (dims[4]) {
48	case 1:
49		hipfftPlan1d(&planR2C, dims[0], HIPFFT_C2R, 1);
50		break;
51	case 2:
52		hipfftPlan2d(&planR2C, dims[1], dims[0], HIPFFT_C2R);
53		break;
54	case 3:
55		hipfftPlan3d(&planR2C, dims[2], dims[1], dims[0], HIPFFT_C2R);
56		break;
57	}
58	for (int i = 0; i < 1; i++) {
59		hipfftExecC2R(planR2C, dataC, dataR);
60	}
61	hipDeviceSynchronize();
62	hipMemcpy(output_rocFFT, dataR, sizeof(float) * (dims[0] ) * dims[1] * dims[2], hipMemcpyDeviceToHost);
63	hipDeviceSynchronize();
64	hipfftDestroy(planR2C);
65	hipFree(dataR);
66	hipFree(dataC);
67}