yum-mirror/VkFFT

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

Tolmachev DmitriiMulti-upload performance improvements + bugfixes -Improved multi-upload FFT algorithm performance in double precision on HPC GPUs -Fixed double precision sincos computation. Now it is possible to disable LUT - useLUT switched to int64_t, -1 disables LUT, 0 - auto decision, 1 forces it. It is possible to disable LUT for 4-step algorithm rotation only - useLUT_4step -Optimized swapTo3Stage4Step and switched it to direct number value from the power of 2 -Bugfixes: fixed FP64 usage in FP32 when number ending was not printed in kernels (important), fixed registerBoost incorrect writing, fixed #93e1c5886

v1.2.31
37.4 KiB1028 linesraw
1#include <vector>
2#include <memory>
3#include <string.h>
4#include <chrono>
5#include <thread>
6#include <iostream>
7#include <algorithm>
8#define __STDC_FORMAT_MACROS
9#include <inttypes.h>
10#if(VKFFT_BACKEND==0)
11#include "vulkan/vulkan.h"
12#include "glslang_c_interface.h"
13#elif(VKFFT_BACKEND==1)
14#include <cuda.h>
15#include <cuda_runtime.h>
16#include <nvrtc.h>
17#include <cuda_runtime_api.h>
18#include <cuComplex.h>
19#elif(VKFFT_BACKEND==2)
20#ifndef __HIP_PLATFORM_HCC__
21#define __HIP_PLATFORM_HCC__
22#endif
23#include <hip/hip_runtime.h>
24#include <hip/hiprtc.h>
25#include <hip/hip_runtime_api.h>
26#include <hip/hip_complex.h>
27#elif(VKFFT_BACKEND==3)
28#ifndef CL_USE_DEPRECATED_OPENCL_1_2_APIS
29#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
30#endif
31#ifdef __APPLE__
32#include <OpenCL/opencl.h>
33#else
34#include <CL/cl.h>
35#endif 
36#elif(VKFFT_BACKEND==4)
37#include <ze_api.h>
38#elif(VKFFT_BACKEND==5)
39#ifndef NS_PRIVATE_IMPLEMENTATION
40#define NS_PRIVATE_IMPLEMENTATION
41#endif
42#ifndef CA_PRIVATE_IMPLEMENTATION
43#define CA_PRIVATE_IMPLEMENTATION
44#endif
45#ifndef MTL_PRIVATE_IMPLEMENTATION
46#define MTL_PRIVATE_IMPLEMENTATION
47#endif
48#include "Foundation/Foundation.hpp"
49#include "QuartzCore/QuartzCore.hpp"
50#include "Metal/Metal.hpp"
51#endif
52#include "vkFFT.h"
53#include "utils_VkFFT.h"
54#include "half.hpp"
55#include "user_benchmark_VkFFT.h"
56#include "sample_0_benchmark_VkFFT_single.h"
57#include "sample_1_benchmark_VkFFT_double.h"
58#if(VKFFT_BACKEND==0)
59#include "sample_2_benchmark_VkFFT_half.h"
60#endif
61#include "sample_3_benchmark_VkFFT_single_3d.h"
62#include "sample_4_benchmark_VkFFT_single_3d_zeropadding.h"
63#include "sample_5_benchmark_VkFFT_single_disableReorderFourStep.h"
64#include "sample_6_benchmark_VkFFT_single_r2c.h"
65#include "sample_7_benchmark_VkFFT_single_Bluestein.h"
66#include "sample_8_benchmark_VkFFT_double_Bluestein.h"
67#include "sample_10_benchmark_VkFFT_single_multipleBuffers.h"
68#ifdef USE_FFTW
69#include "sample_11_precision_VkFFT_single.h"
70#include "sample_12_precision_VkFFT_double.h"
71#if(VKFFT_BACKEND==0)
72#include "sample_13_precision_VkFFT_half.h"
73#endif
74#include "sample_14_precision_VkFFT_single_nonPow2.h"
75#include "sample_15_precision_VkFFT_single_r2c.h"
76#include "sample_16_precision_VkFFT_single_dct.h"
77#include "sample_17_precision_VkFFT_double_dct.h"
78#include "sample_18_precision_VkFFT_double_nonPow2.h"
79#endif
80#include "sample_50_convolution_VkFFT_single_1d_matrix.h"
81#include "sample_51_convolution_VkFFT_single_3d_matrix_zeropadding_r2c.h"
82#include "sample_52_convolution_VkFFT_single_2d_batched_r2c.h"
83
84#include "sample_100_benchmark_VkFFT_single_nd_dct.h"
85#include "sample_101_benchmark_VkFFT_double_nd_dct.h"
86#include "sample_1000_VkFFT_single_2_4096.h"
87#include "sample_1001_benchmark_VkFFT_double_2_4096.h"
88#include "sample_1003_benchmark_VkFFT_single_3d_2_512.h"
89
90#ifdef USE_cuFFT
91#include "user_benchmark_cuFFT.h"
92#include "sample_0_benchmark_cuFFT_single.h"
93#include "sample_1_benchmark_cuFFT_double.h"
94#include "sample_2_benchmark_cuFFT_half.h"
95#include "sample_3_benchmark_cuFFT_single_3d.h"
96#include "sample_6_benchmark_cuFFT_single_r2c.h"
97#include "sample_7_benchmark_cuFFT_single_Bluestein.h"
98#include "sample_8_benchmark_cuFFT_double_Bluestein.h"
99#include "sample_1000_benchmark_cuFFT_single_2_4096.h"
100#include "sample_1001_benchmark_cuFFT_double_2_4096.h"
101#include "sample_1003_benchmark_cuFFT_single_3d_2_512.h"
102#endif  
103#ifdef USE_rocFFT
104#include "user_benchmark_rocFFT.h"
105#include "sample_0_benchmark_rocFFT_single.h"
106#include "sample_1_benchmark_rocFFT_double.h"
107#include "sample_3_benchmark_rocFFT_single_3d.h"
108#include "sample_6_benchmark_rocFFT_single_r2c.h"
109#include "sample_7_benchmark_rocFFT_single_Bluestein.h"
110#include "sample_8_benchmark_rocFFT_double_Bluestein.h"
111#include "sample_1000_benchmark_rocFFT_single_2_4096.h"
112#include "sample_1001_benchmark_rocFFT_double_2_4096.h"
113#include "sample_1003_benchmark_rocFFT_single_3d_2_512.h"
114#endif 
115#ifdef USE_FFTW
116#include "fftw3.h"
117#endif
118
119VkFFTResult launchVkFFT(VkGPU* vkGPU, uint64_t sample_id, bool file_output, FILE* output, VkFFTUserSystemParameters* userParams) {
120	//Sample Vulkan project GPU initialization.
121	VkFFTResult resFFT = VKFFT_SUCCESS;
122
123#if(VKFFT_BACKEND==0)
124	VkResult res = VK_SUCCESS;
125	//create instance - a connection between the application and the Vulkan library 
126	res = createInstance(vkGPU, sample_id);
127	if (res != 0) {
128		//printf("Instance creation failed, error code: %" PRIu64 "\n", res);
129		return VKFFT_ERROR_FAILED_TO_CREATE_INSTANCE;
130	}
131	//set up the debugging messenger 
132	res = setupDebugMessenger(vkGPU);
133	if (res != 0) {
134		//printf("Debug messenger creation failed, error code: %" PRIu64 "\n", res);
135		return VKFFT_ERROR_FAILED_TO_SETUP_DEBUG_MESSENGER;
136	}
137	//check if there are GPUs that support Vulkan and select one
138	res = findPhysicalDevice(vkGPU);
139	if (res != 0) {
140		//printf("Physical device not found, error code: %" PRIu64 "\n", res);
141		return VKFFT_ERROR_FAILED_TO_FIND_PHYSICAL_DEVICE;
142	}
143	//create logical device representation
144	res = createDevice(vkGPU, sample_id);
145	if (res != 0) {
146		//printf("Device creation failed, error code: %" PRIu64 "\n", res);
147		return VKFFT_ERROR_FAILED_TO_CREATE_DEVICE;
148	}
149	//create fence for synchronization 
150	res = createFence(vkGPU);
151	if (res != 0) {
152		//printf("Fence creation failed, error code: %" PRIu64 "\n", res);
153		return VKFFT_ERROR_FAILED_TO_CREATE_FENCE;
154	}
155	//create a place, command buffer memory is allocated from
156	res = createCommandPool(vkGPU);
157	if (res != 0) {
158		//printf("Fence creation failed, error code: %" PRIu64 "\n", res);
159		return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_POOL;
160	}
161	vkGetPhysicalDeviceProperties(vkGPU->physicalDevice, &vkGPU->physicalDeviceProperties);
162	vkGetPhysicalDeviceMemoryProperties(vkGPU->physicalDevice, &vkGPU->physicalDeviceMemoryProperties);
163
164	glslang_initialize_process();//compiler can be initialized before VkFFT
165#elif(VKFFT_BACKEND==1)
166	CUresult res = CUDA_SUCCESS;
167	cudaError_t res2 = cudaSuccess;
168	res = cuInit(0);
169	if (res != CUDA_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE;
170	res2 = cudaSetDevice((int)vkGPU->device_id);
171	if (res2 != cudaSuccess) return VKFFT_ERROR_FAILED_TO_SET_DEVICE_ID;
172	res = cuDeviceGet(&vkGPU->device, (int)vkGPU->device_id);
173	if (res != CUDA_SUCCESS) return VKFFT_ERROR_FAILED_TO_GET_DEVICE;
174	res = cuCtxCreate(&vkGPU->context, 0, (int)vkGPU->device);
175	if (res != CUDA_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_CONTEXT;
176#elif(VKFFT_BACKEND==2)
177	hipError_t res = hipSuccess;
178	res = hipInit(0);
179	if (res != hipSuccess) return VKFFT_ERROR_FAILED_TO_INITIALIZE;
180	res = hipSetDevice((int)vkGPU->device_id);
181	if (res != hipSuccess) return VKFFT_ERROR_FAILED_TO_SET_DEVICE_ID;
182	res = hipDeviceGet(&vkGPU->device, (int)vkGPU->device_id);
183	if (res != hipSuccess) return VKFFT_ERROR_FAILED_TO_GET_DEVICE;
184	res = hipCtxCreate(&vkGPU->context, 0, (int)vkGPU->device);
185	if (res != hipSuccess) return VKFFT_ERROR_FAILED_TO_CREATE_CONTEXT;
186#elif(VKFFT_BACKEND==3)
187	cl_int res = CL_SUCCESS;
188	cl_uint numPlatforms;
189	res = clGetPlatformIDs(0, 0, &numPlatforms);
190	if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE;
191	cl_platform_id* platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) * numPlatforms);
192	if (!platforms) return VKFFT_ERROR_MALLOC_FAILED;
193	res = clGetPlatformIDs(numPlatforms, platforms, 0);
194	if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE;
195	uint64_t k = 0;
196	for (uint64_t j = 0; j < numPlatforms; j++) {
197		cl_uint numDevices;
198		res = clGetDeviceIDs(platforms[j], CL_DEVICE_TYPE_ALL, 0, 0, &numDevices);
199		cl_device_id* deviceList = (cl_device_id*)malloc(sizeof(cl_device_id) * numDevices);
200		if (!deviceList) return VKFFT_ERROR_MALLOC_FAILED;
201		res = clGetDeviceIDs(platforms[j], CL_DEVICE_TYPE_ALL, numDevices, deviceList, 0);
202		if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_GET_DEVICE;
203		for (uint64_t i = 0; i < numDevices; i++) {
204			if (k == vkGPU->device_id) {
205				vkGPU->platform = platforms[j];
206				vkGPU->device = deviceList[i];
207				vkGPU->context = clCreateContext(NULL, 1, &vkGPU->device, NULL, NULL, &res);
208				if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_CONTEXT;
209				cl_command_queue commandQueue = clCreateCommandQueue(vkGPU->context, vkGPU->device, 0, &res);
210				if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QUEUE;
211				vkGPU->commandQueue = commandQueue;
212				k++;
213			}
214			else {
215				k++;
216			}
217		}
218		free(deviceList);
219	}
220	free(platforms);
221#elif(VKFFT_BACKEND==4)
222	ze_result_t res = ZE_RESULT_SUCCESS;
223	res = zeInit(0);
224	if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE;
225	uint32_t numDrivers = 0;
226	res = zeDriverGet(&numDrivers, 0);
227	if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE;
228	ze_driver_handle_t* drivers = (ze_driver_handle_t*)malloc(numDrivers * sizeof(ze_driver_handle_t));
229	if (!drivers) return VKFFT_ERROR_MALLOC_FAILED;
230	res = zeDriverGet(&numDrivers, drivers);
231	if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE;
232	uint64_t k = 0;
233	for (uint64_t j = 0; j < numDrivers; j++) {
234		uint32_t numDevices = 0;
235		res = zeDeviceGet(drivers[j], &numDevices, nullptr);
236		if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_GET_DEVICE;
237		ze_device_handle_t* deviceList = (ze_device_handle_t*)malloc(numDevices * sizeof(ze_device_handle_t));
238		if (!deviceList) return VKFFT_ERROR_MALLOC_FAILED;
239		res = zeDeviceGet(drivers[j], &numDevices, deviceList);
240		if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_GET_DEVICE;
241		for (uint64_t i = 0; i < numDevices; i++) {
242			if (k == vkGPU->device_id) {
243				vkGPU->driver = drivers[j];
244				vkGPU->device = deviceList[i];
245				ze_context_desc_t contextDescription = {};
246				contextDescription.stype = ZE_STRUCTURE_TYPE_CONTEXT_DESC;
247				res = zeContextCreate(vkGPU->driver, &contextDescription, &vkGPU->context);
248				if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_CONTEXT;
249
250				uint32_t queueGroupCount = 0;
251				res = zeDeviceGetCommandQueueGroupProperties(vkGPU->device, &queueGroupCount, 0);
252				if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QUEUE;
253
254				ze_command_queue_group_properties_t* cmdqueueGroupProperties = (ze_command_queue_group_properties_t*)malloc(queueGroupCount * sizeof(ze_command_queue_group_properties_t));
255				if (!cmdqueueGroupProperties) return VKFFT_ERROR_MALLOC_FAILED;
256				res = zeDeviceGetCommandQueueGroupProperties(vkGPU->device, &queueGroupCount, cmdqueueGroupProperties);
257				if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QUEUE;
258
259				uint32_t commandQueueID = -1;
260				for (uint32_t i = 0; i < queueGroupCount; ++i) {
261					if ((cmdqueueGroupProperties[i].flags && ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COMPUTE) && (cmdqueueGroupProperties[i].flags && ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLAG_COPY)) {
262						commandQueueID = i;
263						break;
264					}
265				}
266				if (commandQueueID == -1) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QUEUE;
267				vkGPU->commandQueueID = commandQueueID;
268				ze_command_queue_desc_t commandQueueDescription = {};
269				commandQueueDescription.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC;
270				commandQueueDescription.ordinal = commandQueueID;
271				commandQueueDescription.priority = ZE_COMMAND_QUEUE_PRIORITY_NORMAL;
272				commandQueueDescription.mode = ZE_COMMAND_QUEUE_MODE_DEFAULT;
273				res = zeCommandQueueCreate(vkGPU->context, vkGPU->device, &commandQueueDescription, &vkGPU->commandQueue);
274				if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QUEUE;
275				free(cmdqueueGroupProperties);
276				k++;
277			}
278			else {
279				k++;
280			}
281		}
282
283		free(deviceList);
284	}
285	free(drivers);
286#elif(VKFFT_BACKEND==5)
287    NS::Array* devices = MTL::CopyAllDevices();
288    MTL::Device* device = (MTL::Device*)devices->object(vkGPU->device_id);
289    vkGPU->device = device;
290    MTL::CommandQueue* queue = device->newCommandQueue();
291    vkGPU->queue = queue;
292#endif
293
294	uint64_t isCompilerInitialized = 1;
295
296    switch (sample_id) {
297    case 0:
298    {
299        resFFT = sample_0_benchmark_VkFFT_single(vkGPU, file_output, output, isCompilerInitialized);
300        break;
301    }
302    case 1:
303    {
304        resFFT = sample_1_benchmark_VkFFT_double(vkGPU, file_output, output, isCompilerInitialized);
305        break;
306    }
307#if ((VKFFT_BACKEND==0)&&(VK_API_VERSION>10))
308    case 2:
309    {
310        resFFT = sample_2_benchmark_VkFFT_half(vkGPU, file_output, output, isCompilerInitialized);
311        break;
312    }
313#endif
314    case 3:
315    {
316        resFFT = sample_3_benchmark_VkFFT_single_3d(vkGPU, file_output, output, isCompilerInitialized);
317        break;
318    }
319    case 4:
320    {
321        resFFT = sample_4_benchmark_VkFFT_single_3d_zeropadding(vkGPU, file_output, output, isCompilerInitialized);
322        break;
323    }
324    case 5:
325    {
326        resFFT = sample_5_benchmark_VkFFT_single_disableReorderFourStep(vkGPU, file_output, output, isCompilerInitialized);
327        break;
328    }
329    case 6:
330    {
331        resFFT = sample_6_benchmark_VkFFT_single_r2c(vkGPU, file_output, output, isCompilerInitialized);
332        break;
333    }
334    case 7:
335    {
336        resFFT = sample_7_benchmark_VkFFT_single_Bluestein(vkGPU, file_output, output, isCompilerInitialized);
337        break;
338    }
339    case 8:
340    {
341        resFFT = sample_8_benchmark_VkFFT_double_Bluestein(vkGPU, file_output, output, isCompilerInitialized);
342        break;
343    }
344#if(VKFFT_BACKEND==0)
345    case 10:
346    {
347        resFFT = sample_10_benchmark_VkFFT_single_multipleBuffers(vkGPU, file_output, output, isCompilerInitialized);
348        break;
349    }
350#endif
351#ifdef USE_FFTW
352    case 11:
353    {
354        resFFT = sample_11_precision_VkFFT_single(vkGPU, file_output, output, isCompilerInitialized);
355        break;
356    }
357    case 12:
358    {
359        resFFT = sample_12_precision_VkFFT_double(vkGPU, file_output, output, isCompilerInitialized);
360        break;
361    }
362#if ((VKFFT_BACKEND==0)&&(VK_API_VERSION>10))
363    case 13:
364    {
365        resFFT = sample_13_precision_VkFFT_half(vkGPU, file_output, output, isCompilerInitialized);
366        break;
367    }
368#endif
369    case 14:
370    {
371        resFFT = sample_14_precision_VkFFT_single_nonPow2(vkGPU, file_output, output, isCompilerInitialized);
372        break;
373    }
374    case 15:
375    {
376        resFFT = sample_15_precision_VkFFT_single_r2c(vkGPU, file_output, output, isCompilerInitialized);
377        break;
378    }
379    case 16:
380    {
381        resFFT = sample_16_precision_VkFFT_single_dct(vkGPU, file_output, output, isCompilerInitialized);
382        break;
383    }
384    case 17:
385    {
386        resFFT = sample_17_precision_VkFFT_double_dct(vkGPU, file_output, output, isCompilerInitialized);
387        break;
388    }
389    case 18:
390    {
391        resFFT = sample_18_precision_VkFFT_double_nonPow2(vkGPU, file_output, output, isCompilerInitialized);
392        break;
393    }
394#endif
395    case 50:
396    {
397        resFFT = sample_50_convolution_VkFFT_single_1d_matrix(vkGPU, file_output, output, isCompilerInitialized);
398        break;
399    }
400    case 51:
401    {
402        resFFT = sample_51_convolution_VkFFT_single_3d_matrix_zeropadding_r2c(vkGPU, file_output, output, isCompilerInitialized);
403        break;
404    }
405    case 52:
406    {
407        resFFT = sample_52_convolution_VkFFT_single_2d_batched_r2c(vkGPU, file_output, output, isCompilerInitialized);
408        break;
409    }
410    case 110:
411    {
412        resFFT = sample_100_benchmark_VkFFT_single_nd_dct(vkGPU, file_output, output, isCompilerInitialized, 1);
413        break;
414    }
415    case 120:
416    {
417        resFFT = sample_100_benchmark_VkFFT_single_nd_dct(vkGPU, file_output, output, isCompilerInitialized, 2);
418        break;
419    }
420    case 130:
421    {
422        resFFT = sample_100_benchmark_VkFFT_single_nd_dct(vkGPU, file_output, output, isCompilerInitialized, 3);
423        break;
424    }
425    case 140:
426    {
427        resFFT = sample_100_benchmark_VkFFT_single_nd_dct(vkGPU, file_output, output, isCompilerInitialized, 4);
428        break;
429    }
430    case 111:
431    {
432        resFFT = sample_101_benchmark_VkFFT_double_nd_dct(vkGPU, file_output, output, isCompilerInitialized, 1);
433        break;
434    }
435    case 121:
436    {
437        resFFT = sample_101_benchmark_VkFFT_double_nd_dct(vkGPU, file_output, output, isCompilerInitialized, 2);
438        break;
439    }
440    case 131:
441    {
442        resFFT = sample_101_benchmark_VkFFT_double_nd_dct(vkGPU, file_output, output, isCompilerInitialized, 3);
443        break;
444    }
445    case 141:
446    {
447        resFFT = sample_101_benchmark_VkFFT_double_nd_dct(vkGPU, file_output, output, isCompilerInitialized, 4);
448        break;
449    }
450    case 200: case 201:
451    {
452        resFFT = user_benchmark_VkFFT(vkGPU, file_output, output, isCompilerInitialized, userParams);
453        break;
454    }
455#if ((VKFFT_BACKEND==0)&&(VK_API_VERSION>10))
456    case 202:
457    {
458        resFFT = user_benchmark_VkFFT(vkGPU, file_output, output, isCompilerInitialized, userParams);
459        break;
460    }
461#endif
462    case 1000:
463    {
464        resFFT = sample_1000_VkFFT_single_2_4096(vkGPU, file_output, output, isCompilerInitialized);
465        break;
466    }
467    case 1001:
468    {
469        resFFT = sample_1001_benchmark_VkFFT_double_2_4096(vkGPU, file_output, output, isCompilerInitialized);
470        break;
471    }
472    case 1003:
473    {
474        resFFT = sample_1003_benchmark_VkFFT_single_3d_2_512(vkGPU, file_output, output, isCompilerInitialized);
475        break;
476    }
477    }
478#if(VKFFT_BACKEND==0)
479	vkDestroyFence(vkGPU->device, vkGPU->fence, NULL);
480	vkDestroyCommandPool(vkGPU->device, vkGPU->commandPool, NULL);
481	vkDestroyDevice(vkGPU->device, NULL);
482	DestroyDebugUtilsMessengerEXT(vkGPU, NULL);
483	vkDestroyInstance(vkGPU->instance, NULL);
484	glslang_finalize_process();//destroy compiler after use
485#elif(VKFFT_BACKEND==1)
486	res = cuCtxDestroy(vkGPU->context);
487#elif(VKFFT_BACKEND==2)
488	res = hipCtxDestroy(vkGPU->context);
489#elif(VKFFT_BACKEND==3)
490	res = clReleaseCommandQueue(vkGPU->commandQueue);
491	if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_RELEASE_COMMAND_QUEUE;
492	clReleaseContext(vkGPU->context);
493#elif(VKFFT_BACKEND==4)
494	res = zeCommandQueueDestroy(vkGPU->commandQueue);
495	if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_RELEASE_COMMAND_QUEUE;
496	res = zeContextDestroy(vkGPU->context);
497#elif(VKFFT_BACKEND==5)
498    vkGPU->queue->release();
499    vkGPU->device->release();
500    devices->release();
501#endif
502
503	return resFFT;
504}
505
506bool findFlag(char** start, char** end, const std::string& flag) {
507	return (std::find(start, end, flag) != end);
508}
509char* getFlagValue(char** start, char** end, const std::string& flag)
510{
511	char** value = std::find(start, end, flag);
512	value++;
513	if (value != end)
514	{
515		return *value;
516	}
517	return 0;
518}
519int main(int argc, char* argv[])
520{
521	VkGPU vkGPU = {};
522#if(VKFFT_BACKEND==0)
523	vkGPU.enableValidationLayers = 0;
524#endif
525	bool file_output = false;
526	FILE* output = NULL;
527	int sscanf_res = 0;
528	if (findFlag(argv, argv + argc, "-h"))
529	{
530		//print help
531		int version = VkFFTGetVersion();
532		int version_decomposed[3];
533		version_decomposed[0] = version / 10000;
534		version_decomposed[1] = (version - version_decomposed[0] * 10000) / 100;
535		version_decomposed[2] = (version - version_decomposed[0] * 10000 - version_decomposed[1] * 100);
536		printf("VkFFT v%d.%d.%d (25-10-2022). Author: Tolmachev Dmitrii\n", version_decomposed[0], version_decomposed[1], version_decomposed[2]);
537#if (VKFFT_BACKEND==0)
538		printf("Vulkan backend\n");
539#elif (VKFFT_BACKEND==1)
540		printf("CUDA backend\n");
541#elif (VKFFT_BACKEND==2)
542		printf("HIP backend\n");
543#elif (VKFFT_BACKEND==3)
544		printf("OpenCL backend\n");
545#elif (VKFFT_BACKEND==4)
546		printf("Level Zero backend\n");
547#elif (VKFFT_BACKEND==5)
548        printf("Metal backend\n");
549#endif
550		printf("	-h: print help\n");
551		printf("	-devices: print the list of available device ids, used as -d argument\n");
552		printf("	-d X: select device (default 0)\n");
553		printf("	-o NAME: specify output file path\n");
554		printf("	-vkfft X: launch VkFFT sample X:\n");
555		printf("		0 - FFT + iFFT C2C benchmark 1D batched in single precision\n");
556		printf("		1 - FFT + iFFT C2C benchmark 1D batched in double precision LUT\n");
557#if ((VKFFT_BACKEND==0)&&(VK_API_VERSION>10))
558		printf("		2 - FFT + iFFT C2C benchmark 1D batched in half precision\n");
559#endif
560		printf("		3 - FFT + iFFT C2C multidimensional benchmark in single precision\n");
561		printf("		4 - FFT + iFFT C2C multidimensional benchmark in single precision, native zeropadding\n");
562		printf("		5 - FFT + iFFT C2C benchmark 1D batched in single precision, no reshuffling\n");
563		printf("		6 - FFT + iFFT R2C / C2R benchmark\n");
564		printf("		7 - FFT + iFFT C2C Bluestein benchmark in single precision\n");
565		printf("		8 - FFT + iFFT C2C Bluestein benchmark in double precision\n");
566#if (VKFFT_BACKEND==0)
567		printf("		10 - multiple buffer(4 by default) split version of benchmark 0\n");
568#endif
569#ifdef USE_FFTW
570#ifdef USE_cuFFT
571		printf("		11 - VkFFT / cuFFT / FFTW C2C precision test in single precision\n");
572		printf("		12 - VkFFT / cuFFT / FFTW C2C precision test in double precision\n");
573#if ((VKFFT_BACKEND==0)&&(VK_API_VERSION>10))
574		printf("		13 - VkFFT / cuFFT / FFTW C2C precision test in half precision\n");
575#endif
576		printf("		14 - VkFFT / FFTW C2C radix 3 / 5 / 7 / 11 / 13 / Bluestein precision test in single precision\n");
577		printf("		15 - VkFFT / cuFFT / FFTW R2C+C2R precision test in single precision\n");
578		printf("		16 - VkFFT / FFTW R2R DCT-I, II, III and IV precision test in single precision\n");
579		printf("		17 - VkFFT / FFTW R2R DCT-I, II, III and IV precision test in double precision\n");
580		printf("		18 - VkFFT / FFTW C2C radix 3 / 5 / 7 / 11 / 13 / Bluestein precision test in double precision\n");
581#elif USE_rocFFT
582		printf("		11 - VkFFT / rocFFT / FFTW C2C precision test in single precision\n");
583		printf("		12 - VkFFT / rocFFT / FFTW C2C precision test in double precision\n");
584#if ((VKFFT_BACKEND==0)&&(VK_API_VERSION>10))
585		printf("		13 - VkFFT / FFTW C2C precision test in half precision\n");
586#endif
587		printf("		14 - VkFFT / FFTW C2C radix 3 / 5 / 7 / 11 / 13 / Bluestein precision test in single precision\n");
588		printf("		15 - VkFFT / rocFFT / FFTW R2C+C2R precision test in single precision\n");
589		printf("		16 - VkFFT / FFTW R2R DCT-I, II, III and IV precision test in single precision\n");
590		printf("		17 - VkFFT / FFTW R2R DCT-I, II, III and IV precision test in double precision\n");
591		printf("		18 - VkFFT / FFTW C2C radix 3 / 5 / 7 / 11 / 13 / Bluestein precision test in double precision\n");
592#else
593		printf("		11 - VkFFT / FFTW C2C precision test in single precision\n");
594		printf("		12 - VkFFT / FFTW C2C precision test in double precision\n");
595#if ((VKFFT_BACKEND==0)&&(VK_API_VERSION>10))
596		printf("		13 - VkFFT / FFTW C2C precision test in half precision\n");
597#endif
598		printf("		14 - VkFFT / FFTW C2C radix 3 / 5 / 7 / 11 / 13 / Bluestein precision test in single precision\n");
599		printf("		15 - VkFFT / FFTW R2C+C2R precision test in single precision\n");
600		printf("		16 - VkFFT / FFTW R2R DCT-I, II, III and IV precision test in single precision\n");
601		printf("		17 - VkFFT / FFTW R2R DCT-I, II, III and IV precision test in double precision\n");
602		printf("		18 - VkFFT / FFTW C2C radix 3 / 5 / 7 / 11 / 13 / Bluestein precision test in double precision\n");
603#endif
604#endif
605		printf("		50 - convolution example with identity kernel\n");
606		printf("		51 - zeropadding convolution example with identity kernel\n");
607		printf("		52 - batched convolution example with identity kernel\n");
608		printf("		110 - VkFFT FFT + iFFT R2R DCT-1 multidimensional benchmark in single precision\n");
609		printf("		111 - VkFFT FFT + iFFT R2R DCT-1 multidimensional benchmark in double precision\n");
610		printf("		120 - VkFFT FFT + iFFT R2R DCT-2 multidimensional benchmark in single precision\n");
611		printf("		121 - VkFFT FFT + iFFT R2R DCT-2 multidimensional benchmark in double precision\n");
612		printf("		130 - VkFFT FFT + iFFT R2R DCT-3 multidimensional benchmark in single precision\n");
613		printf("		131 - VkFFT FFT + iFFT R2R DCT-3 multidimensional benchmark in double precision\n");
614		printf("		140 - VkFFT FFT + iFFT R2R DCT-4 multidimensional benchmark in single precision\n");
615		printf("		141 - VkFFT FFT + iFFT R2R DCT-4 multidimensional benchmark in double precision\n");
616
617		printf("		1000 - FFT + iFFT C2C benchmark 1D batched in single precision: all supported systems from 2 to 4096\n");
618		printf("		1001 - FFT + iFFT C2C benchmark 1D batched in double precision: all supported systems from 2 to 4096\n");
619		printf("		1003 - FFT + iFFT C2C multidimensional benchmark in single precision: all supported cubes from 2 to 512\n");
620		printf("	-benchmark_vkfft: run VkFFT benchmark on a user-defined system:\n\
621		-X uint, -Y uint, -Z uint - FFT dimensions (default Y and Z are 1)\n");
622#if ((VKFFT_BACKEND==0)&&(VK_API_VERSION>10))
623		printf("\
624		-P uint - precision (0 - single, 1 - double, 2 - half) (default 0)\n");
625#else
626		printf("\
627		-P uint - precision (0 - single, 1 - double) (default 0)\n");
628#endif
629		printf("\
630		-B uint - number of batched systems (default 1)\n\
631		-N uint - number of consecutive FFT+iFFT iterations (default 1)\n\
632		-R2C uint - use R2C (0 - off, 1 - on) (default 0)\n\
633		-DCT uint - perform DCT (0 - off, else type: 1, 2, 3 or 4) (default 0)\n\
634		-save - save generated binaries\n\
635		-load - load previously generated binaries\n");
636#ifdef USE_cuFFT
637		printf("	-cufft X: launch cuFFT sample X:\n");
638		printf("		0 - FFT + iFFT C2C benchmark 1D batched in single precision\n");
639		printf("		1 - FFT + iFFT C2C benchmark 1D batched in double precision LUT\n");
640		printf("		2 - FFT + iFFT C2C benchmark 1D batched in half precision\n");
641		printf("		3 - FFT + iFFT C2C multidimensional benchmark in single precision\n");
642		printf("		6 - FFT + iFFT R2C / C2R benchmark\n");
643		printf("		7 - FFT + iFFT C2C big prime benchmark in single precision (similar to VkFFT Bluestein)\n");
644		printf("		8 - FFT + iFFT C2C big prime benchmark in double precision (similar to VkFFT Bluestein)\n");
645		printf("		1000 - FFT + iFFT C2C benchmark 1D batched in single precision: all supported systems from 2 to 4096\n");
646		printf("		1001 - FFT + iFFT C2C benchmark 1D batched in double precision: all supported systems from 2 to 4096\n");
647		printf("		1003 - FFT + iFFT C2C multidimensional benchmark in single precision: all supported cubes from 2 to 512\n");
648		printf("	-test: (or no -vkfft and -cufft keys) run vkfft benchmarks 0-6 and cufft benchmarks 0-6\n");
649		printf("	-benchmark_cufft: run cuFFT benchmark on a user-defined system:\n\
650		-X uint, -Y uint, -Z uint - FFT dimensions (default Y and Z are 1)\n\
651		-P uint - precision (0 - single, 1 - double) (default 0)\n\
652		-B uint - number of batched systems (default 1)\n\
653		-N uint - number of consecutive FFT+iFFT iterations (default 1)\n\
654		-R2C uint - use R2C (0 - off, 1 - on) (default 0)\n");
655#elif USE_rocFFT
656		printf("	-rocfft X: launch rocFFT sample X:\n");
657		printf("		0 - FFT + iFFT C2C benchmark 1D batched in single precision\n");
658		printf("		1 - FFT + iFFT C2C benchmark 1D batched in double precision LUT\n");
659		printf("		3 - FFT + iFFT C2C multidimensional benchmark in single precision\n");
660		printf("		6 - FFT + iFFT R2C / C2R benchmark\n");
661		printf("		7 - FFT + iFFT C2C big prime benchmark in single precision (similar to VkFFT Bluestein)\n");
662		printf("		8 - FFT + iFFT C2C big prime benchmark in double precision (similar to VkFFT Bluestein)\n");
663		printf("		1000 - FFT + iFFT C2C benchmark 1D batched in single precision: all supported systems from 2 to 4096\n");
664		printf("		1001 - FFT + iFFT C2C benchmark 1D batched in double precision: all supported systems from 2 to 4096\n");
665		printf("		1003 - FFT + iFFT C2C multidimensional benchmark in single precision: all supported cubes from 2 to 512\n");
666		printf("	-test: (or no -vkfft and -rocfft keys) run vkfft benchmarks 0-6 and rocfft benchmarks 0-6\n");
667		printf("	-benchmark_rocfft: run rocFFT benchmark on a user-defined system:\n\
668		-X uint, -Y uint, -Z uint - FFT dimensions (default Y and Z are 1)\n\
669		-P uint - precision (0 - single, 1 - double) (default 0)\n\
670		-B uint - number of batched systems (default 1)\n\
671		-N uint - number of consecutive FFT+iFFT iterations (default 1)\n\
672		-R2C uint - use R2C (0 - off, 1 - on) (default 0)\n");
673#else
674		printf("	-test: run vkfft benchmarks 0-6\n");
675		printf("	-cufft command is disabled\n");
676		printf("	-rocfft command is disabled\n");
677#endif
678		return 0;
679	}
680	if (findFlag(argv, argv + argc, "-devices"))
681	{
682		//print device list
683		VkFFTResult resFFT = devices_list();
684		return resFFT;
685	}
686	if (findFlag(argv, argv + argc, "-d"))
687	{
688		//select device_id
689		char* value = getFlagValue(argv, argv + argc, "-d");
690		if (value != 0) {
691			sscanf_res = sscanf(value, "%" PRIu64 "", &vkGPU.device_id);
692			if (sscanf_res <= 0) {
693				printf("sscanf failed\n");
694				return 1;
695			}
696		}
697		else {
698			printf("No device is selected with -d flag\n");
699			return 1;
700		}
701	}
702	if (findFlag(argv, argv + argc, "-o"))
703	{
704		//specify output file
705		char* value = getFlagValue(argv, argv + argc, "-o");
706		if (value != 0) {
707			file_output = true;
708			output = fopen(value, "a");
709		}
710		else {
711			printf("No output file is selected with -o flag\n");
712			return 1;
713		}
714	}
715	if (findFlag(argv, argv + argc, "-benchmark_vkfft") || findFlag(argv, argv + argc, "-benchmark_cufft") || findFlag(argv, argv + argc, "-benchmark_rocfft"))
716	{
717		//select sample_id
718		VkFFTUserSystemParameters userParams = {};
719		userParams.X = 1;
720		userParams.Y = 1;
721		userParams.Z = 1;
722		userParams.P = 0;
723		userParams.B = 1;
724		userParams.N = 1;
725		userParams.R2C = 0;
726		userParams.DCT = 0;
727		if (findFlag(argv, argv + argc, "-X"))
728		{
729			char* value = getFlagValue(argv, argv + argc, "-X");
730			if (value != 0) {
731				sscanf_res = sscanf(value, "%" PRIu64 "", &userParams.X);
732				if (sscanf_res <= 0) {
733					printf("sscanf failed\n");
734					return 1;
735				}
736			}
737			else {
738				printf("No dimension is selected with -X flag\n");
739				return 1;
740			}
741		}
742		else {
743			printf("No -X flag is selected\n");
744			return 1;
745		}
746		if (findFlag(argv, argv + argc, "-Y"))
747		{
748			char* value = getFlagValue(argv, argv + argc, "-Y");
749			if (value != 0) {
750				sscanf_res = sscanf(value, "%" PRIu64 "", &userParams.Y);
751				if (sscanf_res <= 0) {
752					printf("sscanf failed\n");
753					return 1;
754				}
755			}
756			else {
757				printf("No dimension is selected with -Y flag\n");
758				return 1;
759			}
760		}
761		if (findFlag(argv, argv + argc, "-Z"))
762		{
763			char* value = getFlagValue(argv, argv + argc, "-Z");
764			if (value != 0) {
765				sscanf_res = sscanf(value, "%" PRIu64 "", &userParams.Z);
766				if (sscanf_res <= 0) {
767					printf("sscanf failed\n");
768					return 1;
769				}
770			}
771			else {
772				printf("No dimension is selected with -Z flag\n");
773				return 1;
774			}
775		}
776		if (findFlag(argv, argv + argc, "-P"))
777		{
778			char* value = getFlagValue(argv, argv + argc, "-P");
779			if (value != 0) {
780				sscanf_res = sscanf(value, "%" PRIu64 "", &userParams.P);
781				if (sscanf_res <= 0) {
782					printf("sscanf failed\n");
783					return 1;
784				}
785			}
786			else {
787				printf("No precision is selected with -P flag\n");
788				return 1;
789			}
790		}
791		if (findFlag(argv, argv + argc, "-B"))
792		{
793			char* value = getFlagValue(argv, argv + argc, "-B");
794			if (value != 0) {
795				sscanf_res = sscanf(value, "%" PRIu64 "", &userParams.B);
796				if (sscanf_res <= 0) {
797					printf("sscanf failed\n");
798					return 1;
799				}
800			}
801			else {
802				printf("No batch is selected with -B flag\n");
803				return 1;
804			}
805		}
806		if (findFlag(argv, argv + argc, "-N"))
807		{
808			char* value = getFlagValue(argv, argv + argc, "-N");
809			if (value != 0) {
810				sscanf_res = sscanf(value, "%" PRIu64 "", &userParams.N);
811				if (sscanf_res <= 0) {
812					printf("sscanf failed\n");
813					return 1;
814				}
815			}
816			else {
817				printf("No number of iterations is selected with -N flag\n");
818				return 1;
819			}
820		}
821		if (findFlag(argv, argv + argc, "-R2C"))
822		{
823			char* value = getFlagValue(argv, argv + argc, "-R2C");
824			if (value != 0) {
825				sscanf_res = sscanf(value, "%" PRIu64 "", &userParams.R2C);
826				if (sscanf_res <= 0) {
827					printf("sscanf failed\n");
828					return 1;
829				}
830			}
831			else {
832				printf("No R2C parameter is selected with -R2C flag\n");
833				return 1;
834			}
835		}
836		if (findFlag(argv, argv + argc, "-DCT"))
837		{
838			char* value = getFlagValue(argv, argv + argc, "-DCT");
839			if (value != 0) {
840				sscanf_res = sscanf(value, "%" PRIu64 "", &userParams.DCT);
841				if (sscanf_res <= 0) {
842					printf("sscanf failed\n");
843					return 1;
844				}
845			}
846			else {
847				printf("No DCT parameter is selected with -DCT flag\n");
848				return 1;
849			}
850		}
851		if (findFlag(argv, argv + argc, "-save"))
852		{
853			userParams.saveApplicationToString = 1;
854		}
855		if (findFlag(argv, argv + argc, "-load"))
856		{
857			userParams.loadApplicationFromString = 1;
858		}
859		if (findFlag(argv, argv + argc, "-benchmark_vkfft")) {
860			VkFFTResult resFFT = launchVkFFT(&vkGPU, 200 + userParams.P, file_output, output, &userParams);
861			if (resFFT != VKFFT_SUCCESS) return resFFT;
862		}
863		else {
864#ifdef USE_cuFFT
865			if (findFlag(argv, argv + argc, "-benchmark_cufft")) {
866				user_benchmark_cuFFT(file_output, output, (cuFFTUserSystemParameters*)(&userParams), (int)vkGPU.device_id);
867			}
868			return 0;
869#elif USE_rocFFT
870			if (findFlag(argv, argv + argc, "-benchmark_rocfft")) {
871				user_benchmark_rocFFT(file_output, output, (rocFFTUserSystemParameters*)(&userParams), (int)vkGPU.device_id);
872			}
873			return 0;
874#endif
875			return 1;
876		}
877		return 0;
878	}
879
880	if (findFlag(argv, argv + argc, "-vkfft"))
881	{
882		//select sample_id
883		char* value = getFlagValue(argv, argv + argc, "-vkfft");
884		if (value != 0) {
885			uint64_t sample_id = 0;
886			sscanf_res = sscanf(value, "%" PRIu64 "", &sample_id);
887			if (sscanf_res <= 0) {
888				printf("sscanf failed\n");
889				return 1;
890			}
891			VkFFTResult resFFT = launchVkFFT(&vkGPU, sample_id, file_output, output, 0);
892			if (resFFT != VKFFT_SUCCESS) return resFFT;
893		}
894		else {
895			printf("No sample is selected with -vkfft flag\n");
896			return 1;
897		}
898	}
899#ifdef USE_cuFFT
900	if (findFlag(argv, argv + argc, "-cufft"))
901	{
902		//select sample_id
903		char* value = getFlagValue(argv, argv + argc, "-cufft");
904		if (value != 0) {
905			uint64_t sample_id = 0;
906			sscanf_res = sscanf(value, "%" PRIu64 "", &sample_id);
907			if (sscanf_res <= 0) {
908				printf("sscanf failed\n");
909				return 1;
910			}
911			switch (sample_id) {
912			case 0:
913				sample_0_benchmark_cuFFT_single(file_output, output, (int)vkGPU.device_id);
914				break;
915			case 1:
916				sample_1_benchmark_cuFFT_double(file_output, output, (int)vkGPU.device_id);
917				break;
918			case 2:
919				sample_2_benchmark_cuFFT_half(file_output, output, (int)vkGPU.device_id);
920				break;
921			case 3:
922				sample_3_benchmark_cuFFT_single_3d(file_output, output, (int)vkGPU.device_id);
923				break;
924			case 6:
925				sample_6_benchmark_cuFFT_single_r2c(file_output, output, (int)vkGPU.device_id);
926				break;
927			case 7:
928				sample_7_benchmark_cuFFT_single_Bluestein(file_output, output, (int)vkGPU.device_id);
929				break;
930			case 8:
931				sample_8_benchmark_cuFFT_double_Bluestein(file_output, output, (int)vkGPU.device_id);
932				break;
933			case 1000:
934				sample_1000_benchmark_cuFFT_single_2_4096(file_output, output, (int)vkGPU.device_id);
935				break;
936			case 1001:
937				sample_1001_benchmark_cuFFT_double_2_4096(file_output, output, (int)vkGPU.device_id);
938				break;
939			case 1003:
940				sample_1003_benchmark_cuFFT_single_3d_2_512(file_output, output, (int)vkGPU.device_id);
941				break;
942			}
943		}
944		else {
945			printf("No cuFFT script is selected with -cufft flag\n");
946			return 1;
947		}
948	}
949#elif USE_rocFFT
950	if (findFlag(argv, argv + argc, "-rocfft"))
951	{
952		//select sample_id
953		char* value = getFlagValue(argv, argv + argc, "-rocfft");
954		if (value != 0) {
955			uint64_t sample_id = 0;
956			sscanf_res = sscanf(value, "%" PRIu64 "", &sample_id);
957			if (sscanf_res <= 0) {
958				printf("sscanf failed\n");
959				return 1;
960			}
961			switch (sample_id) {
962			case 0:
963				sample_0_benchmark_rocFFT_single(file_output, output, (int)vkGPU.device_id);
964				break;
965			case 1:
966				sample_1_benchmark_rocFFT_double(file_output, output, (int)vkGPU.device_id);
967				break;
968			case 3:
969				sample_3_benchmark_rocFFT_single_3d(file_output, output, (int)vkGPU.device_id);
970				break;
971			case 6:
972				sample_6_benchmark_rocFFT_single_r2c(file_output, output, (int)vkGPU.device_id);
973				break;
974			case 7:
975				sample_7_benchmark_rocFFT_single_Bluestein(file_output, output, (int)vkGPU.device_id);
976				break;
977			case 8:
978				sample_8_benchmark_rocFFT_double_Bluestein(file_output, output, (int)vkGPU.device_id);
979				break;
980			case 1000:
981				sample_1000_benchmark_rocFFT_single_2_4096(file_output, output, (int)vkGPU.device_id);
982				break;
983			case 1001:
984				sample_1001_benchmark_rocFFT_double_2_4096(file_output, output, (int)vkGPU.device_id);
985				break;
986			case 1003:
987				sample_1003_benchmark_rocFFT_single_3d_2_512(file_output, output, (int)vkGPU.device_id);
988				break;
989			}
990		}
991		else {
992			printf("No rocFFT script is selected with -rocfft flag\n");
993			return 1;
994		}
995	}
996#endif
997	if ((findFlag(argv, argv + argc, "-test")) || ((!findFlag(argv, argv + argc, "-cufft")) && (!findFlag(argv, argv + argc, "-rocfft")) && (!findFlag(argv, argv + argc, "-vkfft"))))
998	{
999		if (output == NULL) {
1000			file_output = true;
1001			output = fopen("result.txt", "a");
1002		}
1003		for (uint64_t i = 0; i < 9; i++) {
1004#if((VKFFT_BACKEND>0) || (VK_API_VERSION == 10))
1005			if (i == 2) i++;
1006#endif
1007			VkFFTResult resFFT = launchVkFFT(&vkGPU, i, file_output, output, 0);
1008			if (resFFT != VKFFT_SUCCESS) return resFFT;
1009		}
1010#ifdef USE_cuFFT
1011		sample_0_benchmark_cuFFT_single(file_output, output, (int)vkGPU.device_id);
1012		sample_1_benchmark_cuFFT_double(file_output, output, (int)vkGPU.device_id);
1013		sample_2_benchmark_cuFFT_half(file_output, output, (int)vkGPU.device_id);
1014		sample_3_benchmark_cuFFT_single_3d(file_output, output, (int)vkGPU.device_id);
1015		sample_6_benchmark_cuFFT_single_r2c(file_output, output, (int)vkGPU.device_id);
1016		sample_7_benchmark_cuFFT_single_Bluestein(file_output, output, (int)vkGPU.device_id);
1017		sample_8_benchmark_cuFFT_double_Bluestein(file_output, output, (int)vkGPU.device_id);
1018#elif USE_rocFFT
1019		sample_0_benchmark_rocFFT_single(file_output, output, (int)vkGPU.device_id);
1020		sample_1_benchmark_rocFFT_double(file_output, output, (int)vkGPU.device_id);
1021		sample_3_benchmark_rocFFT_single_3d(file_output, output, (int)vkGPU.device_id);
1022		sample_6_benchmark_rocFFT_single_r2c(file_output, output, (int)vkGPU.device_id);
1023		sample_7_benchmark_rocFFT_single_Bluestein(file_output, output, (int)vkGPU.device_id);
1024		sample_8_benchmark_rocFFT_double_Bluestein(file_output, output, (int)vkGPU.device_id);
1025#endif
1026	}
1027	return 0;
1028}