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