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