yum-mirror/VkFFT
git clone https://git.yummers.dev/yum-mirror/VkFFT
41aa1a5
v1.3.1
1#LyX 2.3 created this file. For more info see http://www.lyx.org/ 2\lyxformat 544 3\begin_document 4\begin_header 5\save_transient_properties true 6\origin unavailable 7\textclass article 8\begin_preamble 9\usepackage{sourcecodepro} 10\usepackage[parfill]{parskip} 11\usepackage{enumitem} 12\setlist[itemize]{leftmargin=*} 13\usepackage{minted} 14\usepackage{mdframed} 15\definecolor{bg}{rgb}{0.95,0.95,0.95} 16\usepackage{hyperref} 17\hypersetup{ 18 colorlinks, 19 citecolor=black, 20 filecolor=black, 21 linkcolor=black, 22 urlcolor=black 23} 24\end_preamble 25\use_default_options true 26\maintain_unincluded_children false 27\language english 28\language_package default 29\inputencoding auto 30\fontencoding global 31\font_roman "default" "default" 32\font_sans "default" "default" 33\font_typewriter "default" "default" 34\font_math "auto" "auto" 35\font_default_family default 36\use_non_tex_fonts true 37\font_sc false 38\font_osf false 39\font_sf_scale 100 100 40\font_tt_scale 100 100 41\use_microtype false 42\use_dash_ligatures true 43\graphics default 44\default_output_format default 45\output_sync 0 46\bibtex_command default 47\index_command default 48\paperfontsize 12 49\spacing single 50\use_hyperref false 51\papersize default 52\use_geometry true 53\use_package amsmath 1 54\use_package amssymb 1 55\use_package cancel 1 56\use_package esint 1 57\use_package mathdots 1 58\use_package mathtools 1 59\use_package mhchem 1 60\use_package stackrel 1 61\use_package stmaryrd 1 62\use_package undertilde 1 63\cite_engine basic 64\cite_engine_type default 65\biblio_style plain 66\use_bibtopic false 67\use_indices false 68\paperorientation portrait 69\suppress_date false 70\justification true 71\use_refstyle 1 72\use_minted 0 73\index Index 74\shortcut idx 75\color #008000 76\end_index 77\leftmargin 2.5cm 78\topmargin 2.5cm 79\rightmargin 2.5cm 80\bottommargin 2.5cm 81\secnumdepth 3 82\tocdepth 3 83\paragraph_separation indent 84\paragraph_indentation default 85\is_math_indent 0 86\math_numbering_side default 87\quotes_style english 88\dynamic_quotes 0 89\papercolumns 1 90\papersides 1 91\paperpagestyle default 92\tracking_changes false 93\output_changes false 94\html_math_output 0 95\html_css_as_file 0 96\html_be_strict false 97\end_header 98 99\begin_body 100 101\begin_layout Standard 102\begin_inset ERT 103status open 104 105\begin_layout Plain Layout 106 107 108\backslash 109UseRawInputEncoding 110\end_layout 111 112\begin_layout Plain Layout 113 114 115\backslash 116begin{titlepage} 117\end_layout 118 119\begin_layout Plain Layout 120 121 122\backslash 123centering 124\end_layout 125 126\begin_layout Plain Layout 127 128 129\backslash 130vspace{1cm} 131\end_layout 132 133\begin_layout Plain Layout 134 135{ 136\backslash 137scshape 138\backslash 139LARGE VkFFT - Vulkan/CUDA/HIP/OpenCL/Level Zero/Metal Fast Fourier Transform 140 library 141\backslash 142par} 143\end_layout 144 145\begin_layout Plain Layout 146 147 148\backslash 149vspace{1.5cm} 150\end_layout 151 152\begin_layout Plain Layout 153 154{ 155\backslash 156huge 157\backslash 158bfseries API guide with examples 159\backslash 160par} 161\end_layout 162 163\begin_layout Plain Layout 164 165 166\backslash 167vspace{2cm} 168\end_layout 169 170\begin_layout Plain Layout 171 172{ 173\backslash 174Large Dmitrii Tolmachev 175\backslash 176par} 177\end_layout 178 179\begin_layout Plain Layout 180 181 182\end_layout 183 184\begin_layout Plain Layout 185 186 187\backslash 188vspace{1cm} 189\end_layout 190 191\begin_layout Plain Layout 192 193{ 194\backslash 195large July 2023, version 1.3.0 196\backslash 197par} 198\end_layout 199 200\begin_layout Plain Layout 201 202 203\backslash 204end{titlepage} 205\end_layout 206 207\end_inset 208 209 210\end_layout 211 212\begin_layout Standard 213\begin_inset Newpage newpage 214\end_inset 215 216 217\end_layout 218 219\begin_layout Standard 220\begin_inset CommandInset toc 221LatexCommand tableofcontents 222 223\end_inset 224 225 226\end_layout 227 228\begin_layout Standard 229\begin_inset Newpage newpage 230\end_inset 231 232 233\end_layout 234 235\begin_layout Section 236Introduction 237\end_layout 238 239\begin_layout Standard 240This document describes VkFFT - Vulkan/CUDA/HIP/OpenCL/Level Zero/Metal 241 Fast Fourier Transform library. 242 It describes the features and current limitations of VkFFT, explains the 243 API and compares it to other FFT libraries (like FFTW and cuFFT) on the 244 set of examples. 245 It is by no means the final version, so if there is something unclear - 246 feel free to contact me (dtolm96@gmail.com), so I can update it. 247 248\end_layout 249 250\begin_layout Standard 251\begin_inset Newpage newpage 252\end_inset 253 254 255\end_layout 256 257\begin_layout Section 258Using the VkFFT API 259\end_layout 260 261\begin_layout Standard 262This chapter will cover the basics of VkFFT. 263 Fourier transform of a sequence is called Discrete Fourier Transform (DFT). 264 It is defined by the following formula: 265\begin_inset Formula 266\begin{equation} 267X_{k}=\stackrel[n=0]{N-1}{\sum}x_{n}e^{-\frac{2\pi i}{N}nk}=\mathrm{DFT}{}_{N}(x_{n},k),\label{eq:dft} 268\end{equation} 269 270\end_inset 271 272 273\end_layout 274 275\begin_layout Standard 276where 277\begin_inset Formula $x_{n}$ 278\end_inset 279 280is the input sequence, 281\begin_inset Formula $N$ 282\end_inset 283 284 is the length of the input sequence and 285\begin_inset Formula $k\in[0,N-1],k\in\mathbb{Z}$ 286\end_inset 287 288is the output index, corresponding to frequency in Fourier space. 289 Corresponding to that, inverse DFT is defined as following: 290\begin_inset Formula 291\begin{equation} 292x_{n}=\stackrel[k=0]{\mathrm{N-1}}{\sum}X_{k}e^{\frac{2\pi i}{N}nk}=\mathrm{IDFT}{}_{N}(X_{k},n) 293\end{equation} 294 295\end_inset 296 297 298\end_layout 299 300\begin_layout Standard 301VkFFT follows the same definitions as FFTW and cuFFT - forward FFT has the 302 exponent sign 303\begin_inset Formula $-1$ 304\end_inset 305 306, while the inverse has the exponent sign 307\begin_inset Formula $1$ 308\end_inset 309 310. 311 Note, that inverse transform by default is unnormalized, so to get the 312 input sequence after FFT + iFFT, the user has to divide the result by 313\begin_inset Formula $N$ 314\end_inset 315 316. 317\end_layout 318 319\begin_layout Subsection 320Installing VkFFT 321\end_layout 322 323\begin_layout Standard 324VkFFT is distributed as a header-only library (strating from the version 325 1.3, it is no longer a single header). 326 The installation process consists of the following steps: 327\end_layout 328 329\begin_layout Enumerate 330\noindent 331\align left 332Copy vkFFT.h file and vkFFT directory into one of the directories included 333 in the user's project. 334\end_layout 335 336\begin_layout Enumerate 337\noindent 338Define VKFFT_BACKEND as a number corresponding to the API used in the user's 339 project: 0 - Vulkan, 1 - CUDA, 2 - HIP, 3 - OpenCL, 4 - Level Zero, 5 - 340 Metal. 341 Definition is done like: 342\begin_inset ERT 343status open 344 345\begin_layout Plain Layout 346 347 348\backslash 349begin{mdframed}[backgroundcolor=bg] 350\end_layout 351 352\begin_layout Plain Layout 353 354 355\backslash 356begin{minted}[tabsize=4,obeytabs,breaklines]{make} 357\end_layout 358 359\begin_layout Plain Layout 360 361-DVKFFT_BACKEND=X 362\end_layout 363 364\begin_layout Plain Layout 365 366 367\backslash 368end{minted} 369\end_layout 370 371\begin_layout Plain Layout 372 373 374\backslash 375end{mdframed} 376\end_layout 377 378\end_inset 379 380 in GCC or as 381\begin_inset ERT 382status open 383 384\begin_layout Plain Layout 385 386 387\backslash 388begin{mdframed}[backgroundcolor=bg] 389\end_layout 390 391\begin_layout Plain Layout 392 393 394\backslash 395begin{minted}[tabsize=4,obeytabs,breaklines]{cmake} 396\end_layout 397 398\begin_layout Plain Layout 399 400set(VKFFT_BACKEND 1 CACHE STRING "0 - Vulkan, 1 - CUDA, 2 - HIP, 3 - OpenCL, 401 4 - Level Zero, 5 - Metal") 402\end_layout 403 404\begin_layout Plain Layout 405 406 407\backslash 408end{minted} 409\end_layout 410 411\begin_layout Plain Layout 412 413 414\backslash 415end{mdframed} 416\end_layout 417 418\end_inset 419 420in CMake. 421\end_layout 422 423\begin_layout Enumerate 424Define VKFFT_MAX_FFT_DIMENSIONS as the number of max dimensions to be supported 425 by VkFFT. 426 Default is 4. 427\end_layout 428 429\begin_layout Enumerate 430Depending on the API backend, the project must use additional libraries 431 for run-time compilation: 432\end_layout 433 434\begin_deeper 435\begin_layout Enumerate 436Vulkan API: SPIRV, glslang and Vulkan. 437 Define VK_API_VERSION to the available Vulkan version. 438 Sample CMakeLists can look like this: 439\begin_inset ERT 440status open 441 442\begin_layout Plain Layout 443 444 445\backslash 446begin{mdframed}[backgroundcolor=bg] 447\end_layout 448 449\begin_layout Plain Layout 450 451 452\backslash 453begin{minted}[tabsize=4,obeytabs,breaklines]{cmake} 454\end_layout 455 456\begin_layout Plain Layout 457 458find_package(Vulkan REQUIRED) 459\end_layout 460 461\begin_layout Plain Layout 462 463target_compile_definitions(${PROJECT_NAME} PUBLIC -DVK_API_VERSION=11)#10 464 - Vulkan 1.0, 11 - Vulkan 1.1, 12 - Vulkan 1.2 465\end_layout 466 467\begin_layout Plain Layout 468 469target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/gl 470slang-master/glslang/Include/) 471\end_layout 472 473\begin_layout Plain Layout 474 475add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/glslang-master) 476\end_layout 477 478\begin_layout Plain Layout 479 480\end_layout 481 482\begin_layout Plain Layout 483 484target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vk 485FFT/) 486\end_layout 487 488\begin_layout Plain Layout 489 490add_library(VkFFT INTERFACE) 491\end_layout 492 493\begin_layout Plain Layout 494 495target_compile_definitions(VkFFT INTERFACE -DVKFFT_BACKEND=0) 496\end_layout 497 498\begin_layout Plain Layout 499 500\end_layout 501 502\begin_layout Plain Layout 503 504target_link_libraries(${PROJECT_NAME} PUBLIC SPIRV glslang Vulkan::Vulkan 505 VkFFT) 506\end_layout 507 508\begin_layout Plain Layout 509 510 511\backslash 512end{minted} 513\end_layout 514 515\begin_layout Plain Layout 516 517 518\backslash 519end{mdframed} 520\end_layout 521 522\end_inset 523 524 525\end_layout 526 527\begin_layout Enumerate 528CUDA API: CUDA and NVRTC. 529 Sample CMakeLists can look like this: 530\begin_inset ERT 531status open 532 533\begin_layout Plain Layout 534 535 536\backslash 537begin{mdframed}[backgroundcolor=bg] 538\end_layout 539 540\begin_layout Plain Layout 541 542 543\backslash 544begin{minted}[tabsize=4,obeytabs,breaklines]{cmake} 545\end_layout 546 547\begin_layout Plain Layout 548 549find_package(CUDA 9.0 REQUIRED) 550\end_layout 551 552\begin_layout Plain Layout 553 554enable_language(CUDA) 555\end_layout 556 557\begin_layout Plain Layout 558 559set_property(TARGET ${PROJECT_NAME} PROPERTY CUDA_ARCHITECTURES 35 60 70 560 75 80 86) 561\end_layout 562 563\begin_layout Plain Layout 564 565target_compile_options(${PROJECT_NAME} PUBLIC "$<$<COMPILE_LANGUAGE:CUDA>:SHELL: 566 567\end_layout 568 569\begin_layout Plain Layout 570 571 -DVKFFT_BACKEND=${VKFFT_BACKEND} 572\end_layout 573 574\begin_layout Plain Layout 575 576 -gencode arch=compute_60,code=compute_60 577\end_layout 578 579\begin_layout Plain Layout 580 581 -gencode arch=compute_70,code=compute_70 582\end_layout 583 584\begin_layout Plain Layout 585 586 -gencode arch=compute_75,code=compute_75 587\end_layout 588 589\begin_layout Plain Layout 590 591 -gencode arch=compute_80,code=compute_80 592\end_layout 593 594\begin_layout Plain Layout 595 596 -gencode arch=compute_86,code=compute_86>") 597\end_layout 598 599\begin_layout Plain Layout 600 601set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_SEPARABLE_COMPILATION 602 ON) 603\end_layout 604 605\begin_layout Plain Layout 606 607set_target_properties(${PROJECT_NAME} PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS 608 ON) 609\end_layout 610 611\begin_layout Plain Layout 612 613\end_layout 614 615\begin_layout Plain Layout 616 617find_library(CUDA_NVRTC_LIB libnvrtc nvrtc HINTS "${CUDA_TOOLKIT_ROOT_DIR}/lib64 618" "${LIBNVRTC_LIBRARY_DIR}" "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64" /usr/lib64 619 /usr/local/cuda/lib64) 620\end_layout 621 622\begin_layout Plain Layout 623 624add_definitions(-DCUDA_TOOLKIT_ROOT_DIR="${CUDA_TOOLKIT_ROOT_DIR}") 625\end_layout 626 627\begin_layout Plain Layout 628 629\end_layout 630 631\begin_layout Plain Layout 632 633target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vk 634FFT/) 635\end_layout 636 637\begin_layout Plain Layout 638 639add_library(VkFFT INTERFACE) 640\end_layout 641 642\begin_layout Plain Layout 643 644target_compile_definitions(VkFFT INTERFACE -DVKFFT_BACKEND=1) 645\end_layout 646 647\begin_layout Plain Layout 648 649\end_layout 650 651\begin_layout Plain Layout 652 653target_link_libraries(${PROJECT_NAME} PUBLIC ${CUDA_LIBRARIES} cuda ${CUDA_NVRTC 654_LIB} VkFFT) 655\end_layout 656 657\begin_layout Plain Layout 658 659 660\backslash 661end{minted} 662\end_layout 663 664\begin_layout Plain Layout 665 666 667\backslash 668end{mdframed} 669\end_layout 670 671\end_inset 672 673 674\end_layout 675 676\begin_layout Enumerate 677HIP API: HIP and HIPRTC. 678 Sample CMakeLists can look like this: 679\begin_inset ERT 680status open 681 682\begin_layout Plain Layout 683 684 685\backslash 686begin{mdframed}[backgroundcolor=bg] 687\end_layout 688 689\begin_layout Plain Layout 690 691 692\backslash 693begin{minted}[tabsize=4,obeytabs,breaklines]{cmake} 694\end_layout 695 696\begin_layout Plain Layout 697 698list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hip /opt/rocm) 699\end_layout 700 701\begin_layout Plain Layout 702 703find_package(hip) 704\end_layout 705 706\begin_layout Plain Layout 707 708\end_layout 709 710\begin_layout Plain Layout 711 712target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vk 713FFT/) 714\end_layout 715 716\begin_layout Plain Layout 717 718add_library(VkFFT INTERFACE) 719\end_layout 720 721\begin_layout Plain Layout 722 723target_compile_definitions(VkFFT INTERFACE -DVKFFT_BACKEND=2) 724\end_layout 725 726\begin_layout Plain Layout 727 728#target_compile_definitions(${PROJECT_NAME} PUBLIC -DVKFFT_OLD_ROCM) #ROCm 729 versions before 4.5 needed kernel include of hiprtc 730\end_layout 731 732\begin_layout Plain Layout 733 734\end_layout 735 736\begin_layout Plain Layout 737 738target_link_libraries(${PROJECT_NAME} PUBLIC hip::host VkFFT) 739\end_layout 740 741\begin_layout Plain Layout 742 743 744\backslash 745end{minted} 746\end_layout 747 748\begin_layout Plain Layout 749 750 751\backslash 752end{mdframed} 753\end_layout 754 755\end_inset 756 757 758\end_layout 759 760\begin_layout Enumerate 761OpenCL API: OpenCL. 762 Sample CMakeLists can look like this: 763\begin_inset ERT 764status open 765 766\begin_layout Plain Layout 767 768 769\backslash 770begin{mdframed}[backgroundcolor=bg] 771\end_layout 772 773\begin_layout Plain Layout 774 775 776\backslash 777begin{minted}[tabsize=4,obeytabs,breaklines]{cmake} 778\end_layout 779 780\begin_layout Plain Layout 781 782find_package(OpenCL REQUIRED) 783\end_layout 784 785\begin_layout Plain Layout 786 787\end_layout 788 789\begin_layout Plain Layout 790 791target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vk 792FFT/) 793\end_layout 794 795\begin_layout Plain Layout 796 797add_library(VkFFT INTERFACE) 798\end_layout 799 800\begin_layout Plain Layout 801 802target_compile_definitions(VkFFT INTERFACE -DVKFFT_BACKEND=3) 803\end_layout 804 805\begin_layout Plain Layout 806 807\end_layout 808 809\begin_layout Plain Layout 810 811target_link_libraries(${PROJECT_NAME} PUBLIC OpenCL::OpenCL VkFFT) 812\end_layout 813 814\begin_layout Plain Layout 815 816 817\backslash 818end{minted} 819\end_layout 820 821\begin_layout Plain Layout 822 823 824\backslash 825end{mdframed} 826\end_layout 827 828\end_inset 829 830 831\end_layout 832 833\begin_layout Enumerate 834Level Zero API: Level Zero; Clang and llvm-spirv must be in the system path 835 (for kernel compilation). 836 Sample CMakeLists can look like this: 837\begin_inset ERT 838status open 839 840\begin_layout Plain Layout 841 842 843\backslash 844begin{mdframed}[backgroundcolor=bg] 845\end_layout 846 847\begin_layout Plain Layout 848 849 850\backslash 851begin{minted}[tabsize=4,obeytabs,breaklines]{cmake} 852\end_layout 853 854\begin_layout Plain Layout 855 856set(LevelZero_LIBRARY "/usr/lib/x86_64-linux-gnu/") 857\end_layout 858 859\begin_layout Plain Layout 860 861set(LevelZero_INCLUDE_DIR "/usr/include/") 862\end_layout 863 864\begin_layout Plain Layout 865 866find_library( 867\end_layout 868 869\begin_layout Plain Layout 870 871 LevelZero_LIB 872\end_layout 873 874\begin_layout Plain Layout 875 876 NAMES "ze_loader" 877\end_layout 878 879\begin_layout Plain Layout 880 881 PATHS ${LevelZero_LIBRARY} 882\end_layout 883 884\begin_layout Plain Layout 885 886 PATH_SUFFIXES "lib" "lib64" 887\end_layout 888 889\begin_layout Plain Layout 890 891 NO_DEFAULT_PATH 892\end_layout 893 894\begin_layout Plain Layout 895 896 ) 897\end_layout 898 899\begin_layout Plain Layout 900 901find_path( 902\end_layout 903 904\begin_layout Plain Layout 905 906 LevelZero_INCLUDES 907\end_layout 908 909\begin_layout Plain Layout 910 911 NAMES "ze_api.h" 912\end_layout 913 914\begin_layout Plain Layout 915 916 PATHS ${LevelZero_INCLUDE_DIR} 917\end_layout 918 919\begin_layout Plain Layout 920 921 PATH_SUFFIXES "include" 922\end_layout 923 924\begin_layout Plain Layout 925 926 NO_DEFAULT_PATH 927\end_layout 928 929\begin_layout Plain Layout 930 931 ) 932\end_layout 933 934\begin_layout Plain Layout 935 936target_include_directories(${PROJECT_NAME} PUBLIC ${LevelZero_INCLUDES}) 937\end_layout 938 939\begin_layout Plain Layout 940 941add_library(VkFFT INTERFACE) 942\end_layout 943 944\begin_layout Plain Layout 945 946target_compile_definitions(VkFFT INTERFACE -DVKFFT_BACKEND=4) 947\end_layout 948 949\begin_layout Plain Layout 950 951\end_layout 952 953\begin_layout Plain Layout 954 955target_link_libraries(${PROJECT_NAME} PUBLIC LevelZero VkFFT) 956\end_layout 957 958\begin_layout Plain Layout 959 960 961\backslash 962end{minted} 963\end_layout 964 965\begin_layout Plain Layout 966 967 968\backslash 969end{mdframed} 970\end_layout 971 972\end_inset 973 974 975\end_layout 976 977\begin_layout Enumerate 978Metal API: Metal. 979 Sample CMakeLists can look like this: 980\begin_inset ERT 981status open 982 983\begin_layout Plain Layout 984 985 986\backslash 987begin{mdframed}[backgroundcolor=bg] 988\end_layout 989 990\begin_layout Plain Layout 991 992 993\backslash 994begin{minted}[tabsize=4,obeytabs,breaklines]{cmake} 995\end_layout 996 997\begin_layout Plain Layout 998 999add_compile_options(-WMTL_IGNORE_WARNINGS) 1000\end_layout 1001 1002\begin_layout Plain Layout 1003 1004find_library(FOUNDATION_LIB Foundation REQUIRED) 1005\end_layout 1006 1007\begin_layout Plain Layout 1008 1009find_library(QUARTZ_CORE_LIB QuartzCore REQUIRED) 1010\end_layout 1011 1012\begin_layout Plain Layout 1013 1014find_library(METAL_LIB Metal REQUIRED) 1015\end_layout 1016 1017\begin_layout Plain Layout 1018 1019target_include_directories(${PROJECT_NAME} PUBLIC "metal-cpp/") 1020\end_layout 1021 1022\begin_layout Plain Layout 1023 1024\end_layout 1025 1026\begin_layout Plain Layout 1027 1028target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/vk 1029FFT/) 1030\end_layout 1031 1032\begin_layout Plain Layout 1033 1034add_library(VkFFT INTERFACE) 1035\end_layout 1036 1037\begin_layout Plain Layout 1038 1039target_compile_definitions(VkFFT INTERFACE -DVKFFT_BACKEND=5) 1040\end_layout 1041 1042\begin_layout Plain Layout 1043 1044\end_layout 1045 1046\begin_layout Plain Layout 1047 1048target_link_libraries(${PROJECT_NAME} PUBLIC ${FOUNDATION_LIB} ${QUARTZ_CORE_LIB 1049} ${METAL_LIB} VkFFT) 1050\end_layout 1051 1052\begin_layout Plain Layout 1053 1054 1055\backslash 1056end{minted} 1057\end_layout 1058 1059\begin_layout Plain Layout 1060 1061 1062\backslash 1063end{mdframed} 1064\end_layout 1065 1066\end_inset 1067 1068 1069\end_layout 1070 1071\end_deeper 1072\begin_layout Subsection 1073Fourier Transform Setup 1074\end_layout 1075 1076\begin_layout Standard 1077VkFFT follows a plan structure like FFTW/cuFFT with a notable difference 1078 - there is a unified interface to all transforms. 1079 This means that there are no separate functions like fftPlan1D/fftPlan2D/fftPla 1080nMany/etc. 1081 The initialization is done through a single configuration struct - VkFFTConfigu 1082ration. 1083 Each parameter of it will be covered in detail in this document. 1084 Plans in VkFFT are called VkFFTApplication and they are created with a 1085 unified initializeVkFFT call. 1086 1087\end_layout 1088 1089\begin_layout Standard 1090As the code is written in C, don't forget to zero-initialize used structs! 1091\end_layout 1092 1093\begin_layout Standard 1094During the initializeVkFFT(VkFFTApplication* app, VkFFTConfiguration inputLaunch 1095Configuration) call VkFFT performs kernel generation and compilation from 1096 scratch (kernel reuse may be added later). 1097 The overall process of initialization looks like this: 1098\end_layout 1099 1100\begin_layout Enumerate 1101Get device parameters, perform default initialization of internal copy of 1102 configuration struct inside the VkFFTApplication, then fill in user-defined 1103 parameters from inputLaunchConfiguration. 1104\begin_inset space ~ 1105\end_inset 1106 1107VkFFTApplication is passed as a pointer, so initializeVkFFT modifies the 1108 user-provided application. 1109\end_layout 1110 1111\begin_layout Enumerate 1112By default, there are two internal FFT plans created - inverse and forward. 1113 Multidimensional FFT is done as a combination of 1D FFTs in each axis direction. 1114 For each axis, the VkFFTPlanAxis function is called. 1115\end_layout 1116 1117\begin_layout Enumerate 1118VkFFTPlanAxis configures parameters for each axis. 1119 It may perform additional memory allocations (see: memory allocated by 1120 VkFFT). 1121\end_layout 1122 1123\begin_layout Enumerate 1124shaderGenVkFFT generates corresponding to the axis code in a char buffer 1125 (each axis may require more than one kernel: see Four-step FFT, Bluestein's 1126 algorithm for FFT). 1127 1128\end_layout 1129 1130\begin_layout Enumerate 1131Code is then compiled with the run-time compiler of the specified backend. 1132\end_layout 1133 1134\begin_layout Standard 1135Once the plan is no longer need, a call to the deleteVkFFT function frees 1136 all the allocated resources. 1137 There are no processes launched that continue to work outside of the VkFFT 1138 related function calls. 1139\end_layout 1140 1141\begin_layout Subsection 1142Fourier Transform types and their definitions 1143\end_layout 1144 1145\begin_layout Standard 1146VkFFT supports commonly used Complex to complex (C2C), real to complex (R2C), 1147 complex to real (C2R) transformations and real to real (R2R) Discrete Cosine 1148 Transformations of types II, III and IV. 1149 VkFFT uses the same definitions as FFTW, except for the multidimensional 1150 FFT axis ordering: in FFTW dimensions are ordered with the decrease in 1151 consecutive elements stride, while VkFFT does the opposite - the first 1152 axis is the non-strided axis (the one that has elements located consecutively 1153 in memory with no gaps, usually named as the X-axis). 1154 So, in FFTW dimensions are specified as ZYX and in VkFFT as XYZ. 1155 This felt more logical to me - no matter if there are 1, 2, 3 or more dimension 1156s, the user can always find the axis with the same stride at the same position. 1157 This choice doesn't require any modification in the user's data management 1158 - just provide the FFT dimensions in the reverse order to VkFFT. 1159 1160\end_layout 1161 1162\begin_layout Standard 1163The 1.3 version of VkFFT supports arbitrary number of dimensions, defined 1164 as VKFFT_MAX_FFT_DIMENSIONS compile constant. 1165 VkFFT also supports two forms of batching: the number of coordinates and 1166 the number of systems. 1167 The choice of two distinct batching ways is made to support matrix-vector 1168 convolutions, where the kernel is presented as a matrix. 1169 Overall, the layout of VkFFT can be described as WHD+CN - width, height, 1170 depth, other dimensions, coordinate and number of systems (in order of 1171 increasing strides, starting with 1 for width). 1172 Often, the coordinate part of the layout is not used, so the main batching 1173 is done by specifying N. 1174\end_layout 1175 1176\begin_layout Standard 1177VkFFT assumes that complex numbers are stored consecutively in memory: RIRIRI... 1178 where R denotes the real part of the complex number and I denotes the imaginary 1179 part. 1180 There is no difference between using a float2/double2/half2 container or 1181 access memory as float/double/half as long as the byte order remains the 1182 same. 1183\end_layout 1184 1185\begin_layout Standard 1186This section and the next one will cover the basics of VkFFT data layouts 1187 and memory management. 1188 1189\end_layout 1190 1191\begin_layout Subsubsection 1192C2C transforms 1193\end_layout 1194 1195\begin_layout Standard 1196The base FFT algorithm - C2C in VkFFT has the same definition as FFTW. 1197 Forward FFT has the exponent sign 1198\begin_inset Formula $-1$ 1199\end_inset 1200 1201, while the inverse has the exponent sign 1202\begin_inset Formula $1$ 1203\end_inset 1204 1205. 1206 By default, the inverse transform is unnormalized. 1207 1208\begin_inset Formula $N_{x}N_{y}N_{z}$ 1209\end_inset 1210 1211 complex numbers map to 1212\begin_inset Formula $N_{x}N_{y}N_{z}$ 1213\end_inset 1214 1215 complex numbers and no additional padding is required. 1216 The resulting data order will be the same as in FFTW/cuFFT, unless special 1217 parameters are provided in configuration (see: advanced memory management) 1218\end_layout 1219 1220\begin_layout Subsubsection 1221R2C/C2R transforms 1222\end_layout 1223 1224\begin_layout Standard 1225R2C/C2R transforms can be explained as C2C transforms with imaginary part 1226 set to zero. 1227 They exploit Hermitian symmetry of the result: 1228\begin_inset Formula $X_{k}=X_{N-k}^{*}$ 1229\end_inset 1230 1231 on the non-strided axis (the one that has elements located consecutively 1232 in memory with no gaps). 1233 This results in s reduction of required memory to store the complex result 1234 - we may only store 1235\begin_inset Formula $floor(\frac{N_{x}}{2})+1$ 1236\end_inset 1237 1238 complex numbers instead of 1239\begin_inset Formula $N_{x}$ 1240\end_inset 1241 1242. 1243 However, this results in memory requirements mismatch between input and 1244 output in R2C: 1245\begin_inset Formula $floor(\frac{N_{x}}{2})+1$ 1246\end_inset 1247 1248 complex elements will require 1249\begin_inset Formula $N_{x}+2$ 1250\end_inset 1251 1252 real numbers worth of memory for even 1253\begin_inset Formula $N_{x}$ 1254\end_inset 1255 1256 and 1257\begin_inset Formula $N_{x}+1$ 1258\end_inset 1259 1260 real numbers worth of memory for odd 1261\begin_inset Formula $N_{x}$ 1262\end_inset 1263 1264. 1265 For C2R the situation is reversed. 1266 There are two approaches to this problem: pad each sequence of the non-strided 1267 axis with zeros to the required length or use out-of-place mode. 1268 More information on how to do this will be given in the next section. 1269\end_layout 1270 1271\begin_layout Subsubsection 1272R2R (DCT) transforms 1273\end_layout 1274 1275\begin_layout Standard 1276R2R transforms in VkFFT are implemented in the form of Discrete cosine transform 1277s of types I, II, III and IV. 1278 Their definitions and transforms results match FFTW: 1279\end_layout 1280 1281\begin_layout Enumerate 1282DCT-I: 1283\begin_inset Formula $X_{k}=x_{0}+(-1)^{k}x_{N-1}+2\stackrel[n=1]{N-2}{\sum}x_{n}cos(\frac{\pi}{N-1}nk)$ 1284\end_inset 1285 1286, inverse of DCT-I (itself) 1287\end_layout 1288 1289\begin_layout Enumerate 1290DCT-II: 1291\begin_inset Formula $X_{k}=2\stackrel[n=1]{N-1}{\sum}x_{n}cos(\frac{\pi}{N}(n+\frac{1}{2})k)$ 1292\end_inset 1293 1294, inverse of DCT-III 1295\end_layout 1296 1297\begin_layout Enumerate 1298DCT-III: 1299\begin_inset Formula $X_{k}=x_{0}+2\stackrel[n=1]{N-1}{\sum}x_{n}cos(\frac{\pi}{N}n(k+\frac{1}{2}))$ 1300\end_inset 1301 1302, inverse of DCT-II 1303\end_layout 1304 1305\begin_layout Enumerate 1306DCT-IV: 1307\begin_inset Formula $X_{k}=2\stackrel[n=0]{N-1}{\sum}x_{n}cos(\frac{\pi}{N}(n+\frac{1}{2})(k+\frac{1}{2}))$ 1308\end_inset 1309 1310, inverse of DCT-IV (itself) 1311\end_layout 1312 1313\begin_layout Standard 1314R2R transforms are performed by redefinition of them to the C2C transforms 1315 (internal C2C sequence length can be different from the input R2R sequence 1316 length). 1317 R2R transform performs a one-to-one mapping between real numbers, so they 1318 don't require stride management, unlike R2C/C2R. 1319\end_layout 1320 1321\begin_layout Subsection 1322Memory management, data layouts for different transforms 1323\end_layout 1324 1325\begin_layout Subsubsection 1326VkFFT buffers 1327\end_layout 1328 1329\begin_layout Standard 1330VkFFT allows for explicit control over the data flow, which makes both in-place 1331 and out-of-place transforms possible. 1332 Buffers are passed to VkFFT as VkBuffer pointer in Vulkan, as double void 1333 pointers in CUDA/HIP/Level Zero, as cl_mem pointer in OpenCL and as MTL::Buffer 1334 pointer in Metal. 1335 This is done to maintain a uniform data pattern because some of the buffers 1336 can be allocated automatically. 1337 1338\end_layout 1339 1340\begin_layout Standard 1341The main buffer is called buffer and it always has to be provided, either 1342 during the plan creation or when the plan is executed. 1343 All calculations are performed in this buffer and it is always overwritten. 1344 To do calculations out-of-place, VkFFT provides an option to specify inputBuffe 1345r/outputBuffer buffer. 1346 The logic behind their usage is fairly simple - the user specifies inputBuffer 1347 if the input data has to be read from a buffer, different from the main 1348 buffer. 1349 As the data is read only once and nothing is written back to the inputBuffer, 1350 this allows doing truly out-of-place transformations. 1351 The same logic applies to outputBuffer with the difference that it is responsib 1352le for the absolute last write of the VkFFT. 1353 It is possible to use all three buffers to create complex data management 1354 paths. 1355\end_layout 1356 1357\begin_layout Standard 1358It must be noted, that sometimes FFT can not be done inside one buffer (see: 1359 Four-Step FFT algorithm, Bluestein's algorithm). 1360 To compute FFT in these cases, there exists tempBuffer buffer and data 1361 is transferred between the main buffer and tempBuffer during the FFT execution. 1362 The ordering of transfers between the main buffer and tempBuffer is done 1363 in such a way, so the initial data read and final data write are obeying 1364 the configuration from the previous paragraph. 1365 Users can allocate tempBuffer themselves of some memory that does not have 1366 any useful information at the time of FFT execution (the tempBuffer size 1367 can depend on the configuration, so this is a rather advanced operation 1368 - read more in the advanced memory management section) or allow VkFFT to 1369 manage tempBuffer allocation itself (tempBuffer will be freed at the deleteVkFF 1370T call). 1371\end_layout 1372 1373\begin_layout Standard 1374To compute convolutions and cross-correlations, a kernel buffer has to be 1375 specified. 1376 It must have the same layout as the result of the FFT transform. 1377\end_layout 1378 1379\begin_layout Subsubsection 1380VkFFT buffers strides. 1381 A special case of R2C/C2R transforms 1382\end_layout 1383 1384\begin_layout Standard 1385To have better control of memory, the user can specify the strides between 1386 consecutive elements of different axes. 1387 The W (width) stride is fixed to be 1, so to achieve innermost batching, 1388 user needs to initialize an N+1 dimension FFT and omit the innermost dimension 1389 using omitDimension[0] = 1 parameter. 1390 N (number of systems) stride will be consecutive of C in memory if C is 1391 used, otherwise N will propagate the previous non-uniform stride multiplied 1392 by the corresponding axis length). 1393 Strides are specified not in bytes, but in the element type used - similar 1394 to the way how the user would access the corresponding element in the array. 1395 If all elements are consecutive in C2C, stride for H will be equal to the 1396 FFT length of W axis, stride for D will be multiplication of first two 1397 FFT axis lengths and so on, stride for C will be multiplication of all 1398 FFT axes lengths, etc. 1399 These are the default values of C2C and R2R strides if they are not explicitly 1400 specified. 1401\end_layout 1402 1403\begin_layout Standard 1404One of the main use-cases of strides comes to solve the R2C/C2R Hermitian 1405 symmetry H stride mismatch - for real space, it is equal to 1406\begin_inset Formula $N_{x}$ 1407\end_inset 1408 1409 real elements and for the frequency space it is equal to 1410\begin_inset Formula $floor(\frac{N_{x}}{2})+1$ 1411\end_inset 1412 1413 complex numbers. 1414 So, with strides it is possible to use a buffer, padded to 1415\begin_inset Formula $2\cdot(floor(\frac{N_{x}}{2})+1)$ 1416\end_inset 1417 1418 real elements in H stride (all elements between 1419\begin_inset Formula $N_{x}$ 1420\end_inset 1421 1422 and 1423\begin_inset Formula $2\cdot(floor(\frac{N_{x}}{2})+1)$ 1424\end_inset 1425 1426 will not be read so it does not matter what data is there before the write 1427 stage). 1428 All other strides are done as a multiplication between the previous stride 1429 and the number of elements in the previous axis. 1430 These are the default values of R2C/C2R strides if they are not explicitly 1431 specified. 1432\end_layout 1433 1434\begin_layout Standard 1435It is possible to specify separate sets of strides for all user-defined 1436 buffers: bufferStride for the main buffer, inputStride for input buffer, 1437 outputStride for output buffer (kernel stride is assumed to be the same 1438 as bufferStride, tempBuffer strides are configured automatically). 1439 1440\end_layout 1441 1442\begin_layout Standard 1443For an out-of-place R2C FFT, there is no need to pad buffer with real numbers, 1444 but user must specify H stride there (as it differs to default one) - 1445\begin_inset Formula $N_{x}$ 1446\end_inset 1447 1448 real elements for real space and 1449\begin_inset Formula $floor(\frac{N_{x}}{2})+1$ 1450\end_inset 1451 1452 complex numbers for the frequency space. 1453\end_layout 1454 1455\begin_layout Standard 1456An out-of-place C2R FFT is a more tricky transform. 1457 In the multidimensional case, the main buffer will be written to and read 1458 from multiple times. 1459 The intermediate stores have a complex layout, which requires more space 1460 than the output real layout, so in order not to modify the input data, 1461 there exist two options. 1462 First, pad the real data layout has to 1463\begin_inset Formula $2\cdot(floor(\frac{N_{x}}{2})+1)$ 1464\end_inset 1465 1466 real elements in H stride (complex buffer will be used as inputBuffer, 1467 real buffer as buffer). 1468 Second, use the third buffer, so both input and output buffers have their 1469 original layouts (complex buffer will be used as inputBuffer, the main 1470 buffer for calculations is buffer and output real buffer as outputBuffer). 1471 If you use inverseReturnToInputBuffer option, where R2C is configured to 1472 read from input buffer and C2R is configured to write to the input buffer; 1473 C2R will modify the buffer it reads from in some cases (see issue 1474\begin_inset CommandInset href 1475LatexCommand href 1476name "#58" 1477target "https://github.com/DTolm/VkFFT/issues/58#issuecomment-1007205682" 1478literal "false" 1479 1480\end_inset 1481 1482) 1483\end_layout 1484 1485\begin_layout Subsection 1486VkFFT algorithms 1487\end_layout 1488 1489\begin_layout Standard 1490VkFFT implements a wide range of algorithms to compute different types of 1491 FFTs but all of them can be reduced to a mixed-radix Cooley-Tukey FFT algorithm 1492 in the Stockham autosort form. 1493 The main idea behind it is to decompose the sequence as a set of primes, 1494 for each of which FFT can be written down exactly. 1495 As of now, VkFFT has radix implementations for primes up to 13, so all 1496 C2C sequences decomposable into a multiplication of such primes will be 1497 done purely with the Stockham algorithm. 1498 Below additional algorithms and their use-cases are described. 1499\end_layout 1500 1501\begin_layout Subsubsection 1502Bluestein's algorithm 1503\end_layout 1504 1505\begin_layout Standard 1506A complex algorithm that is used in cases where the sequence is not decomposable 1507 with implemented radix butterflies (currently - primes up to 13). 1508 It is derived by replacing 1509\begin_inset Formula $nk=\left(n^{2}+k^{2}-(n-k)^{2}\right)/2$ 1510\end_inset 1511 1512 in 1513\begin_inset CommandInset ref 1514LatexCommand ref 1515reference "eq:dft" 1516plural "false" 1517caps "false" 1518noprefix "false" 1519 1520\end_inset 1521 1522: 1523\end_layout 1524 1525\begin_layout Standard 1526\begin_inset Formula 1527\begin{align} 1528X_{k} & =\left(e^{-\pi i\frac{k^{2}}{N}}\right)\stackrel[n=0]{N-1}{\sum}\left(x_{n}e^{-\pi i\frac{n^{2}}{N}}\right)\left(e^{\pi i\frac{\left(k-n\right)^{2}}{N}}\right)=b_{k}^{\ast}\stackrel[n=0]{N-1}{\sum}a_{n}b_{k-n}\label{eq:dft-1}\\ 1529a_{n} & =x_{n}b_{n}^{\ast}\\ 1530b_{n} & =e^{\pi i\frac{n^{2}}{N}} 1531\end{align} 1532 1533\end_inset 1534 1535 1536\end_layout 1537 1538\begin_layout Standard 1539Here FFT is represented as a convolution between two sequences: 1540\begin_inset Formula $a_{n}$ 1541\end_inset 1542 1543 and 1544\begin_inset Formula $b_{n}$ 1545\end_inset 1546 1547, which can be performed by the means of convolution theorem: 1548\end_layout 1549 1550\begin_layout Standard 1551\begin_inset Formula 1552\begin{equation} 1553F\{a\ast b\}=F\{a\}\cdot F\{b\} 1554\end{equation} 1555 1556\end_inset 1557 1558 1559\end_layout 1560 1561\begin_layout Standard 1562By padding 1563\begin_inset Formula $a_{n}$ 1564\end_inset 1565 1566 and 1567\begin_inset Formula $b_{n}$ 1568\end_inset 1569 1570 to a sequence length decomposable with implemented radix butterflies with 1571 a size of at least 1572\begin_inset Formula $2N-1$ 1573\end_inset 1574 1575 (because the length of 1576\begin_inset Formula $b_{n}$ 1577\end_inset 1578 1579 is 1580\begin_inset Formula $2N-1$ 1581\end_inset 1582 1583), we can perform FFT of any length. 1584 FFT of 1585\begin_inset Formula $b_{n}$ 1586\end_inset 1587 1588 can be precomputed, so overall this algorithm requires at least 4x the 1589 computations and more memory transfers. 1590 This algorithm can be combined with all other algorithms implemented in 1591 VkFFT. 1592 If an FFT can not be done in a single upload, a tempBuffer has to be allocated 1593 (because the logical FFT buffer size is bigger than the original system). 1594\end_layout 1595 1596\begin_layout Subsubsection 1597The Four-Step FFT algorithm 1598\end_layout 1599 1600\begin_layout Standard 1601GPUs and CPUs have a hierarchical memory model - the closer memory to the 1602 unit that performs the computations, the faster its speed and the lower 1603 the size. 1604 So it is advantageous to split FFTs, not to the lowest primes, but to some 1605 bigger multiplication of those primes, then upload this subsequence to 1606 the closest cache level to the cores and do the final prime split there. 1607 The absolute lowest level is the register file, however, it does not allow 1608 for thread communications outside the warp. 1609 For this purpose, modern GPUs employ shared memory - a fast memory with 1610 a bank structure that is visible to all threads in a thread block. 1611 The usual sizes of it change on a scale from 16KB to 192KB and it is often 1612 beneficial to use it fully. 1613 However, if the full sequence can not fit inside the shared memory, FFT 1614 has to be done in multiple uploads - with the Four Step FFT algorithm. 1615 The main idea behind it is to represent a big 1D sequence as a 2D (or 3D 1616 for the three-upload scheme) FFT - we first do FFT along the columns, then 1617 the rows, then transpose the result and multiply by a special set of phase 1618 vectors. 1619 Similar decomposition idea as the main Cooley-Tukey algorithm. 1620 However, performing transpositions in-place is a complicated task - especially 1621 for a non-trivial ratio between dimensions. 1622 It will also require an additional read/write stage, as it can not be merged 1623 with the last write of the FFT algorithm. 1624 The easiest and the most performant solution is to use a tempBuffer (it 1625 is the main reason for having this functionality, actually) and store intermedi 1626ate FFT results out-of-place. 1627 This way the last transposition step can be merged with the write step, 1628 as we can overwrite the output buffer without losing data. 1629\end_layout 1630 1631\begin_layout Standard 1632To estimate if your sequence size is single upload or not, divide the amount 1633 of available shared memory (48KB - Nvidia GPUs with Vulkan/OpenCL API, 1634 64KB - AMD GPUs, 100KB - Nvidia GPUs in CUDA API) by the complex size used 1635 for calculations (8 byte - single precision, 16 byte - double precision). 1636 For 64KB of shared memory, we get 8192 as max single upload single-precision 1637 non-strided FFT, 4096 for double precision. 1638 For strided axes (H and D parts of the layout) these numbers have to be 1639 divided by 4 and 2 respectively to achieve coalescing, resulting in 2048 1640 length for single upload in both precisions. 1641 For more information on coalescing see: coalescing API reference. 1642\end_layout 1643 1644\begin_layout Standard 1645In the case of the Four-Step FFT algorithm, tempBuffer size has to be at 1646 least the same as the default main buffer size. 1647 It does not matter how many uploads are in the Four Step FFT algorithm 1648 - only a single tempBuffer is required. 1649 In this document, all systems that can fit in the shared memory entirely 1650 and be done without the Four Step FFT algorithm (and multiple uploads) 1651 are called single upload systems. 1652\end_layout 1653 1654\begin_layout Standard 1655If the last transposition is not required (the output data is allowed to 1656 be in not unshuffled form) it can be disabled during the configuration 1657 phase. 1658 This way tempBuffer will not be needed and all computations will be done 1659 in-place (unless Bluestein's algorithm is used). 1660 An example use-case of this is convolutions - if the kernel is computed 1661 with the same operation ordering, point-wise multiplication in the frequency 1662 domain is not dependent on the correct data ordering and the inverse FFT 1663 will restore the original layout. 1664\end_layout 1665 1666\begin_layout Subsubsection 1667R2C/C2R FFTs 1668\end_layout 1669 1670\begin_layout Standard 1671A typical approach to a single upload R2C/C2R system is to just set the 1672 imaginary part to zero inside the shared memory and do a simple C2C transform. 1673 This doesn't affect the amount of memory transferred from VRAM and is not 1674 a bad approach as FFT is a memory-bound algorithm, however, this can be 1675 improved in multidimensional (in HDCN part of the layout) case by the compositi 1676on of a single C2C sequence from two real sequences and some write for R2C/read 1677 for C2R post-processing. 1678 Both of these algorithms are implemented in VkFFT. 1679 Note, that R2C/C2R only affects the non-strided axis (W). 1680 All strided axes are still done as C2C. 1681\end_layout 1682 1683\begin_layout Subsubsection 1684R2C/C2R multi-upload FFT algorithm 1685\end_layout 1686 1687\begin_layout Standard 1688For even sequences there exists an easy mapping between R2C/C2R FFTs and 1689 the C2C of half the size. 1690 In this case, all even indices (starting from 0) are read as the real values 1691 of a complex number and all odd indices are read as the imaginary values. 1692 This C2C sequence can be done with the help of the Four-Step FFT algorithm. 1693 When FFT is done, separate post-processing for R2C/pre-processing for C2R 1694 is applied. 1695\end_layout 1696 1697\begin_layout Subsubsection 1698R2R Discrete Cosine Transforms 1699\end_layout 1700 1701\begin_layout Standard 1702There exist many different mappings between DCT and FFT. 1703 As of now, VkFFT has the following algorithms implemented (all single-upload 1704 for now): 1705\end_layout 1706 1707\begin_layout Itemize 1708DCT-I - mapping between R2R and C2C of the 1709\begin_inset Formula $2N-2$ 1710\end_inset 1711 1712 length. 1713 For non-strided axis can use an optimization similar to the R2C/C2R multidimens 1714ional case (setting the imaginary part to the next FFT sequence). 1715\end_layout 1716 1717\begin_layout Itemize 1718DCT-II/DCT-III - mapping between R2R and C2C of the same length. 1719 For non-strided axis can use an optimization similar to the R2C/C2R multidimens 1720ional case (setting the imaginary part to the next FFT sequence). 1721\end_layout 1722 1723\begin_layout Itemize 1724DCT-IV - for even sizes, mapping between R2R and C2C sequence of half-length. 1725 For odd sizes mapping to the FFT of the same length (for non-strided axis 1726 can use an optimization similar to the R2C/C2R multidimensional case (setting 1727 the imaginary part to the next FFT sequence)). 1728\end_layout 1729 1730\begin_layout Subsubsection 1731Register overutilization 1732\end_layout 1733 1734\begin_layout Standard 1735Not an FFT algorithm by itself, but an optimization to do bigger sequences 1736 in a single upload instead of switching to the Four Step FFT algorithm. 1737 The main idea behind it is to use a register file (which is often bigger 1738 than the amount of shared memory) to store the sequence and use shared 1739 memory only as a communication buffer. 1740 This is useful in Vulkan and OpenCL APIs on Nvidia GPU, as they are only 1741 allowed to allocate 48KB of shared memory with a register file having the 1742 size of 256KB. 1743\end_layout 1744 1745\begin_layout Subsubsection 1746Zero padding 1747\end_layout 1748 1749\begin_layout Standard 1750Not an FFT algorithm by itself, but a memory management optimization. 1751 If the user's system has parts that are known to be zero - for example, 1752 when an open system is modeled, to avoid a circular part of the FFT system 1753 has to be padded with zeros up to 2x in each direction. 1754 VkFFT can omit sequences full of zeros and don't perform the corresponding 1755 memory transfers and computations, as the output result will be zero. 1756 This way it is possible to get up to two times speed increase in the 2D 1757 case and up to 3x increase in the 3D case. 1758 1759\end_layout 1760 1761\begin_layout Subsubsection 1762Convolution and cross-correlation support 1763\end_layout 1764 1765\begin_layout Standard 1766With the help of the Convolution theorem, which states that the Fourier 1767 transform of a convolution is the pointwise product of signals Fourier 1768 transforms, it is possible to perform convolution with 1769\begin_inset Formula $NlogN$ 1770\end_inset 1771 1772 complexity, compared to 1773\begin_inset Formula $N^{2}$ 1774\end_inset 1775 1776 complexity of the simple multiplication approach. 1777 This is extremely useful for kernels spanning more than 50 elements in 1778 size. 1779 VkFFT can merge the last step FFT, kernel multiplication in the Fourier 1780 domain and the first step of inverse FFT to provide substantial memory 1781 transfer savings. 1782 Moreover, FFTs of big sequences can be performed without data reordering, 1783 which results in a better locality. 1784 1785\end_layout 1786 1787\begin_layout Subsection 1788VkFFT accuracy 1789\end_layout 1790 1791\begin_layout Standard 1792To measure how VkFFT (single/double/half precision) results compare to cuFFT/roc 1793FFT (single/double/half precision) and FFTW (double precision), multiple 1794 sets of systems covering full supported C2C/R2C+C2R/R2R FFT range are filled 1795 with random complex data on the scale of [-1,1] and one transform was performed 1796 on each system. 1797 Samples 11(single), 12(double), 13(half), 14(non-power of 2 C2C, single), 1798 15(R2C+C2R, single), 16(DCT-I/II/III/IV, single), 17(DCT-I/II/III/IV, double), 1799 18(non-power of 2 C2C, double) are available in VkFFT Benchmark Suite to 1800 perform VkFFT verification on any of the target platforms. 1801 Overall, the Cooley-Tukey algorithm (Stockham autosort) exhibits logarithmic 1802 relative error scaling, similar to those of other GPU FFT libraries. 1803 Typically, the more computationally expensive algorithm is - the worse 1804 its precision is. 1805 So, Bluestein's algorithm has lower accuracy than Stockham autosort algorithm. 1806\end_layout 1807 1808\begin_layout Standard 1809Single precision in VkFFT supports two modes of calculation - by using the 1810 on-chip Special Function Units that can compute sines and cosines on the 1811 go or by using the precomputed on CPU look-up tables. 1812 For Nvidia and AMD GPUs, SFU provide great precision, while Intel iGPUs 1813 and mobile GPUs must use LUT to perform FFTs correctly. 1814\end_layout 1815 1816\begin_layout Standard 1817Double precision in VkFFT also supports two modes of calculation - by using 1818 polynomial sincos approximation and computing them on-chip or by using 1819 precomputed LUT as well. 1820 The second option is the better one, as polynomial sincos approximation 1821 is too compute-heavy for modern GPUs. 1822 It is selected by default on all devices. 1823\end_layout 1824 1825\begin_layout Standard 1826Half precision is currently only supported in the Vulkan backend and is 1827 often experiencing precision problems with the first number of the resulting 1828 FFT sequence, which is the sum of all input numbers. 1829 Half precision is implemented only as a memory trick - all on-chip computations 1830 are done in single precision, but this doesn't help with the first number 1831 problem. 1832 Half precision can use SFU or LUT as well. 1833\end_layout 1834 1835\begin_layout Standard 1836VkFFT also supports mixed-precision operations, where memory storing is 1837 done at lower precision, compared to the on-chip calculations. 1838 For example, it is possible to read data in single precision, do calculations 1839 in double and store data back in single precision. 1840 1841\end_layout 1842 1843\begin_layout Subsection 1844VkFFT additional memory allocations 1845\end_layout 1846 1847\begin_layout Standard 1848In this section, all GPU memory allocations that are done by VkFFT are described. 1849 There are up to three situations when VkFFT allocates memory. 1850 All of the VkFFT allocated memory is freed at the deleteVkFFT call. 1851\end_layout 1852 1853\begin_layout Subsubsection 1854LUT allocations 1855\end_layout 1856 1857\begin_layout Standard 1858This memory is used to store precomputed twiddle factors and phase vectors 1859 used during the computation. 1860 This buffer can have: 1861\end_layout 1862 1863\begin_layout Itemize 1864twiddle factors for each radix stage of Stockham FFT calculation 1865\end_layout 1866 1867\begin_layout Itemize 1868phase vectors used in the Four Step FFT algorithm between stages 1869\end_layout 1870 1871\begin_layout Itemize 1872phase vectors used in DCT-II/III/IV to perform a mapping between R2R and 1873 C2C 1874\end_layout 1875 1876\begin_layout Itemize 1877phase vectors used in post-processing for R2C/pre-processing for C2R for 1878 even length sequences as C2C of half size 1879\end_layout 1880 1881\begin_layout Standard 1882VkFFT manages LUT allocations by itself and they are performed during the 1883 initializeVkFFT call. 1884 LUT are allocated per axis, though some of them can be reused if the axes 1885 have the same LUT. 1886 Inverse and forward FFT plans share the same LUT (conjugation is performed 1887 on-chip). 1888\end_layout 1889 1890\begin_layout Subsubsection 1891The Four-Step FFT algorithm - tempBuffer allocation 1892\end_layout 1893 1894\begin_layout Standard 1895To perform the merging of the transposition with the last upload of an axis, 1896 VkFFT requires additional memory to mimic an out-of-place execution. 1897 This memory is located in tempBuffer and has to be of at least the same 1898 size as the main buffer. 1899 It is possible for the users to allocate it themselves, though if this 1900 is not done, VkFFT can do the allocation automatically (the size of the 1901 tempBuffer will be the same as the main buffer, unless the logical dimensions 1902 of FFT are bigger than user-defined - then, it will allocate the system 1903 with the minimal size, that can cover maximal logical system size used 1904 in any of the axes - see next subsection). 1905\end_layout 1906 1907\begin_layout Subsubsection 1908Bluestein's buffers allocation 1909\end_layout 1910 1911\begin_layout Standard 1912To do Bluestein's FFT algorithm, precomputed sequences 1913\begin_inset Formula $b_{n}=e^{\pi i\frac{n^{2}}{N}}$ 1914\end_inset 1915 1916, 1917\begin_inset Formula $FFT(b_{n})$ 1918\end_inset 1919 1920 and 1921\begin_inset Formula $iFFT(b_{n})$ 1922\end_inset 1923 1924 are required. 1925 For each axis, they can be different and are computed separately (unless 1926 VkFFT can determine that they match, then the buffers are allocated only 1927 once). 1928 Notably, as Bluestein's algorithm pads the sequence length to at least 1929 1930\begin_inset Formula $2N-1$ 1931\end_inset 1932 1933, if it can not be done in a single upload and the Four Step algorithm has 1934 to be used, the intermediate storage required will be bigger than the main 1935 buffer size. 1936 In this case, tempBuffer must always be allocated. 1937 As the padded sequence can be different for each of the dimensions, the 1938 required size of the tempBuffer will also vary. 1939 VkFFT determines the biggest size needed among axes and allocated tempBuffer 1940 of this size. 1941\end_layout 1942 1943\begin_layout Standard 1944\begin_inset Newpage newpage 1945\end_inset 1946 1947 1948\end_layout 1949 1950\begin_layout Section 1951Runtime code optimization platform 1952\begin_inset CommandInset label 1953LatexCommand label 1954name "sec:Modern-GPU-architecture." 1955 1956\end_inset 1957 1958 1959\end_layout 1960 1961\begin_layout Subsection 1962Platform for GPU code generation 1963\end_layout 1964 1965\begin_layout Standard 1966While GPUs show extraordinary performance, they are harder to program for 1967 compared to regular CPUs. 1968 Firstly, the algorithms must be optimized for SIMT (single instruction, 1969 multiple threads) execution, which is the soul of the GPU model. 1970 Secondly, rapid GPU development makes all vendor architectures (Nvidia, 1971 AMD, Intel) largely different. 1972 Below we will list some examples: 1973\end_layout 1974 1975\begin_layout Itemize 1976Shared memory size. 1977 If your code uses the full 64KB of shared memory on AMD MI250X, it won't 1978 be optimal on Nvidia H100 which has 256KB of it. 1979 The same goes for L2/L3 cache size. 1980\end_layout 1981 1982\begin_layout Itemize 1983Warp size. 1984 If your code uses 32 core warps (usual on Nvidia), it will not work or 1985 work inefficiently for 64 core warps of AMD CDNA. 1986\end_layout 1987 1988\begin_layout Itemize 1989Coalesced memory. 1990 For Nvidia and AMD we have to coalesce 32-byte memory requests, for Intel, 1991 it is equal to 64 bytes. 1992 Multiple of these requests are then combined into 128-byte transactions 1993 to the chip. 1994 However, this is a big simplification. 1995 There exist undocumented issues for Nvidia and AMD, when bandwidth drops 1996 when code tries to do distant, but coalesced memory accesses, i.e. 1997 data are still grouped in 32-byte transactions but target addresses with 1998 > 2^18 bytes between them (and the bigger the distance - the bigger the 1999 drop). 2000 The load-store unit (LSU) can not group 32-byte transactions. 2001 It is possible to regain full bandwidth by switching to 128-byte memory 2002 coalescing on Nvidia, while on AMD memory management follows different 2003 rules and these requests just happen to hit the same physical memory pin 2004 and thus be serialized. 2005 All this information is usually never shared by vendors, so programmers 2006 have to find solutions by trial and error. 2007\end_layout 2008 2009\begin_layout Itemize 2010Compute unit composition. 2011 Some compute units have special function units that can evaluate single 2012 precision sines and cosines in one cycle (AMD and Nvidia). 2013 On Intel GPUs, they are often imprecise. 2014 The ratio between FP32 and FP64 units also imposes limitations on the algorithm 2015 - compute units with low FP64 core count will benefit from data precomputation 2016 in the lookup tables more. 2017 Some compute units have tensor cores for accelerated matrix products. 2018\end_layout 2019 2020\begin_layout Itemize 2021There are many other nuanced differences (like the number of supported by 2022 hardware queues/streams, support for CUDA MPS execution model, register 2023 spilling control) which result in some complicated kernels being unpredictable 2024 in performance before you try. 2025 So having an option to tweak some of its parameters loosely related to 2026 hardware is a huge benefit. 2027 2028\end_layout 2029 2030\begin_layout Standard 2031This brings us to a big obstacle: all vendors have their own computing platforms. 2032 CUDA for Nvidia, HIP for AMD, Level Zero for Intel, Metal for Apple. 2033 To facilitate the development of code for all these different in details 2034 but similar in SIMD nature GPUs, I used all the knowledge obtained via 2035 numerous experiments with VkFFT to generalize GPU programming as much as 2036 possible - and create a unified platform for GPU code generation. 2037 2038\end_layout 2039 2040\begin_layout Subsection 2041Platform structure 2042\end_layout 2043 2044\begin_layout Standard 2045The project structure is split into four main parts: 2046\end_layout 2047 2048\begin_layout Itemize 2049Application manager. 2050 We use a container-based model of management - the user fills out the configura 2051tion struct and then initializes the application with only one initializer 2052 function. 2053 So this part of the platform performs initial configuration management, 2054 pass of the parameters to the corresponding to the particular subprogram 2055 plan initializer, binary load/store for future reuse and resources deallocation. 2056 Here we have application dispatch handlers, which abstract the actual applicati 2057on-dependent code dispatch handlers in the same way as we have one function 2058 for initialization. 2059\end_layout 2060 2061\begin_layout Itemize 2062Plan manager. 2063 After configuration propagation, the plan manager performs extensive configurat 2064ion of parameters for a particular task code generation. 2065 It also performs general API-dependent parameter initialization for supported 2066 backends. 2067 The plan manager also performs code compilation using supported by the 2068 target API runtime compiler (NVRTC by Nvidia CUDA, HIPRTC by AMD HIP, glslang 2069 by Vulkan, native OpenCL, clang and llvm-spirv for Intel Level Zero). 2070 It manages additional memory allocations and backend-specific memory management. 2071 Finally, it has plan-specific dispatch routines and a plan resource deallocatio 2072n manager. 2073\end_layout 2074 2075\begin_layout Itemize 2076Code manager. 2077 This part of the platform is solely responsible for GPU code generation. 2078 It takes a special input configuration structure created from user configuratio 2079n and API-derived parameters and produces a char array containing code to 2080 be executed. 2081 The code manager has a block structure that developers can use. 2082 This allows reusing parts of code between kernels. 2083 The block structure has the following designations: 2084\end_layout 2085 2086\begin_deeper 2087\begin_layout Itemize 2088Level 2 kernels: problem-specific kernels and layout configuration. 2089 These functions are called by the plan manager and they are intended to 2090 have a clear description of what is going on in the function. 2091 There is no pure code here - only calls to append lower-level functions 2092 code to the kernel code and additional inlining constants configuration 2093 that can be performed by the propagated from the plan manager information. 2094 This kernel also performs calls to additional kernel configuration routines 2095 like shared memory and register inlining inside a kernel and overall kernel 2096 decoration (like calls to inlining structure definitions, calls to kernel 2097 name inlining) - these routines are defined in lower kernels levels. 2098\end_layout 2099 2100\begin_layout Itemize 2101Level 1 kernels: less abstract simple routine kernels, like matrix-vector 2102 products, copy kernels, radix components of FFT, read/write managers. 2103 All of them must have a specified structure so they can be reused, for 2104 example, considering all input data to be in shared memory with a specific 2105 layout - then level 2 kernels will have a simple job of providing data 2106 to level 1 kernels in a specified manner and get the output in an also 2107 specified manner. 2108\end_layout 2109 2110\begin_layout Itemize 2111Level 0 kernels: memory management kernels. 2112 Here we have the absolute simplest kernel blocks, like memory data transfer 2113 request calls, synchronization, inlining of register/shared memory initializati 2114on code, etc. 2115 Many APIs have their own definitions for particular math operations, so 2116 we can define functions for inlining additions multiplications and other 2117 basic arithmetics here as well. 2118 The target of this level is to provide level 1 and 2 kernels with an easy 2119 way to reuse things that can be generalized between the widest range of 2120 math algorithms. 2121 2122\end_layout 2123 2124\begin_layout Standard 2125All of the different level kernels have full access to the target GPU hardware 2126 parameters - hence (depending on the quality of implemented kernels) it 2127 is possible to autotune the algorithm at run-time and simplify the compiler 2128 job as much as possible. 2129 This involves loop unrolling, constants inlining, etc. 2130 Having an additional level (level 1) dedicated to the simple algorithms 2131 allows for kernel merging. 2132 2133\end_layout 2134 2135\end_deeper 2136\begin_layout Itemize 2137Structs definitions. 2138 Here we define all structs used by the platform. 2139 It also contains some helper structs that can be used to manage GPU with 2140 different APIs and collect generated applications in a library struct for 2141 easier access through a map key (if the user's code uses many applications, 2142 this turns out to be extremely helpful). 2143\end_layout 2144 2145\begin_layout Subsection 2146Container abstractions 2147\end_layout 2148 2149\begin_layout Standard 2150The main design improvement that enables the platform functionality and 2151 greatly expands its usability are container abstractions. 2152 The code generator now operates on special data containers (implemented 2153 as C-unions), that can hold integer/float/complex numbers either as known 2154 during the plan creation values or as strings of variable names - no more 2155 sprintf calls with big chunks of unreadable code. 2156 2157\end_layout 2158 2159\begin_layout Standard 2160An example operation that uses containers is a MUL operation that performs 2161 a multiplication A equals B multiplied by C. 2162 If all containers have known values, A can be precomputed during plan creation. 2163 If A , B and C are, for example, register names, we print to the kernel 2164 an operation of multiplication. 2165 Each operation like MUL has its own representation for all supported APIs 2166 in the vkFFT_MathUtils.h file. 2167 An important distinction is that it is not a full compiler, but a simple 2168 tool that unifies syntaxis of different APIs and supports JIT optimizations. 2169 However, as the code manager outputs code that resembles binary, one of 2170 the future exploration possibilities it may be interesting to try to make 2171 level 0 and 1 kernels output assembly without additional compilation by 2172 the plan manager. 2173 2174\end_layout 2175 2176\begin_layout Standard 2177Usage of container abstractions brings exciting opportunities to code creation. 2178 Behaving as multi-API templates it will be possible to implement double-double 2179 FP128 mathematics support on GPU without modifying any of the already written 2180 algorithm code. 2181 Another big benefit is automatic type casting between precisions and option 2182 to perform precomputation in higher precision than the GPU code executes 2183 in. 2184 2185\end_layout 2186 2187\begin_layout Standard 2188I have also explored other ways to implement these container abstractions 2189 - including switching to C++ from C99 and using templates and operator 2190 overloading, however this turned out to be just a syntactic sugar, as if 2191 it did not reduce number of lines of code and did not increase readibility. 2192 So the code is still C with almost instant compilations as a bonus. 2193 All this is subject to change in the future if people present convincing 2194 arguments. 2195 2196\end_layout 2197 2198\begin_layout Standard 2199\begin_inset Newpage newpage 2200\end_inset 2201 2202 2203\end_layout 2204 2205\begin_layout Section 2206VkFFT API Reference 2207\end_layout 2208 2209\begin_layout Standard 2210This section covers error codes, API functions that can be used by the user 2211 and configuration parameters. 2212\end_layout 2213 2214\begin_layout Subsection 2215Return value VkFFTResult 2216\end_layout 2217 2218\begin_layout Standard 2219All VkFFT Library return values except for VKFFT_SUCCESS are used in case 2220 of a failure and provide information on what has gone wrong. 2221 VkFFTResult is unified among different backends, though some of its values 2222 may not be used in specific backends. 2223 Possible return values of VkFFTResult are defined as following: 2224\end_layout 2225 2226\begin_layout Standard 2227\begin_inset ERT 2228status open 2229 2230\begin_layout Plain Layout 2231 2232 2233\backslash 2234begin{mdframed}[backgroundcolor=bg] 2235\end_layout 2236 2237\begin_layout Plain Layout 2238 2239 2240\backslash 2241begin{minted}[tabsize=4,obeytabs,breaklines]{C} 2242\end_layout 2243 2244\begin_layout Plain Layout 2245 2246typedef enum VkFFTResult { 2247\end_layout 2248 2249\begin_layout Plain Layout 2250 2251VKFFT_SUCCESS = 0, // The VkFFT operation was successful 2252\end_layout 2253 2254\begin_layout Plain Layout 2255 2256VKFFT_ERROR_MALLOC_FAILED = 1, // Some malloc call inside VkFFT has failed. 2257 Report this to the GitHub repo 2258\end_layout 2259 2260\begin_layout Plain Layout 2261 2262VKFFT_ERROR_INSUFFICIENT_CODE_BUFFER = 2, // Generated kernel is bigger 2263 than default kernel array. 2264 Increase it with maxCodeLength parameter of configuration. 2265\end_layout 2266 2267\begin_layout Plain Layout 2268 2269VKFFT_ERROR_INSUFFICIENT_TEMP_BUFFER = 3, // Temporary string used in kernel 2270 generation is bigger than default temporary string array. 2271 Increase it with maxTempLength parameter of configuration. 2272\end_layout 2273 2274\begin_layout Plain Layout 2275 2276VKFFT_ERROR_PLAN_NOT_INITIALIZED = 4, // Code attempts to use uninitialized 2277 plan (it is zero inside VkFFTApplication) 2278\end_layout 2279 2280\begin_layout Plain Layout 2281 2282VKFFT_ERROR_NULL_TEMP_PASSED = 5, // Internal kernel generation error 2283\end_layout 2284 2285\begin_layout Plain Layout 2286 2287VKFFT_ERROR_MATH_FAILED = 6, // Math instruction in code generator failed 2288 2289\end_layout 2290 2291\begin_layout Plain Layout 2292 2293VKFFT_ERROR_FFTdim_GT_MAX_FFT_DIMENSIONS = 7, // User specified a number 2294 of dimensions higher than the code is compiled to handle with VKFFT_MAX_FFT_DIM 2295ENSIONS 2296\end_layout 2297 2298\begin_layout Plain Layout 2299 2300VKFFT_ERROR_INVALID_PHYSICAL_DEVICE = 1001, // No physical device is provided 2301 (Vulkan API) 2302\end_layout 2303 2304\begin_layout Plain Layout 2305 2306VKFFT_ERROR_INVALID_DEVICE = 1002, // No device is provided (All APIs) 2307\end_layout 2308 2309\begin_layout Plain Layout 2310 2311VKFFT_ERROR_INVALID_QUEUE = 1003, // No queue is provided (Vulkan API) 2312\end_layout 2313 2314\begin_layout Plain Layout 2315 2316VKFFT_ERROR_INVALID_COMMAND_POOL = 1004, // No command pool is provided 2317 (Vulkan API) 2318\end_layout 2319 2320\begin_layout Plain Layout 2321 2322VKFFT_ERROR_INVALID_FENCE = 1005, // No fence is provided (Vulkan API) 2323\end_layout 2324 2325\begin_layout Plain Layout 2326 2327VKFFT_ERROR_ONLY_FORWARD_FFT_INITIALIZED = 1006, // VkFFT tries to access 2328 inverse FFT plan, when appliction is created with makeForwardPlanOnly flag 2329\end_layout 2330 2331\begin_layout Plain Layout 2332 2333VKFFT_ERROR_ONLY_INVERSE_FFT_INITIALIZED = 1007, // VkFFT tries to access 2334 forward FFT plan, when appliction is created with makeInversePlanOnly flag 2335\end_layout 2336 2337\begin_layout Plain Layout 2338 2339VKFFT_ERROR_INVALID_CONTEXT = 1008, // No context is provided (OpenCL API) 2340\end_layout 2341 2342\begin_layout Plain Layout 2343 2344VKFFT_ERROR_INVALID_PLATFORM = 1009, // No platform is provided (OpenCL 2345 API) 2346\end_layout 2347 2348\begin_layout Plain Layout 2349 2350VKFFT_ERROR_EMPTY_FILE = 1011, 2351\end_layout 2352 2353\begin_layout Plain Layout 2354 2355VKFFT_ERROR_EMPTY_FFTdim = 2001, // Number of dimensions is not provided 2356 in the configuration 2357\end_layout 2358 2359\begin_layout Plain Layout 2360 2361VKFFT_ERROR_EMPTY_size = 2002, // Array of dimensions is not provided in 2362 the configuration 2363\end_layout 2364 2365\begin_layout Plain Layout 2366 2367VKFFT_ERROR_EMPTY_bufferSize = 2003, // Buffer size has to be provided during 2368 the application creation 2369\end_layout 2370 2371\begin_layout Plain Layout 2372 2373VKFFT_ERROR_EMPTY_buffer = 2004, // Buffer has te be specified either at 2374 the application creation stage or during launch through VkFFTLaunchParams 2375 struct 2376\end_layout 2377 2378\begin_layout Plain Layout 2379 2380VKFFT_ERROR_EMPTY_tempBufferSize = 2005, // Same error as VKFFT_ERROR_EMPTY_buff 2381erSize if userTempBuffer is enabled 2382\end_layout 2383 2384\begin_layout Plain Layout 2385 2386VKFFT_ERROR_EMPTY_tempBuffer = 2006, // Same error as VKFFT_ERROR_EMPTY_buffer 2387 if userTempBuffer is enabled 2388\end_layout 2389 2390\begin_layout Plain Layout 2391 2392VKFFT_ERROR_EMPTY_inputBufferSize = 2007, // Same error as VKFFT_ERROR_EMPTY_buf 2393ferSize if isInputFormatted is enabled 2394\end_layout 2395 2396\begin_layout Plain Layout 2397 2398VKFFT_ERROR_EMPTY_inputBuffer = 2008, // Same error as VKFFT_ERROR_EMPTY_buffer 2399 if isInputFormatted is enabled 2400\end_layout 2401 2402\begin_layout Plain Layout 2403 2404VKFFT_ERROR_EMPTY_outputBufferSize = 2009, // Same error as VKFFT_ERROR_EMPTY_bu 2405fferSize if isOutputFormatted is enabled 2406\end_layout 2407 2408\begin_layout Plain Layout 2409 2410VKFFT_ERROR_EMPTY_outputBuffer = 2010, // Same error as VKFFT_ERROR_EMPTY_buffer 2411 if isOutputFormatted is enabled 2412\end_layout 2413 2414\begin_layout Plain Layout 2415 2416VKFFT_ERROR_EMPTY_kernelSize = 2011, // Same error as VKFFT_ERROR_EMPTY_bufferSi 2417ze if performConvolution is enabled 2418\end_layout 2419 2420\begin_layout Plain Layout 2421 2422VKFFT_ERROR_EMPTY_kernel = 2012, // Same error as VKFFT_ERROR_EMPTY_buffer 2423 if performConvolution is enabled 2424\end_layout 2425 2426\begin_layout Plain Layout 2427 2428VKFFT_ERROR_EMPTY_applicationString = 2013, // loadApplicationString is 2429 zero when loadApplicationFromString is enabled 2430\end_layout 2431 2432\begin_layout Plain Layout 2433 2434VKFFT_ERROR_EMPRY_useCustomBluesteinPaddingPattern_arrays = 2014, // pointers 2435 to primeSizes or paddedSizes arrays are zero when useCustomBluesteinPaddingPatt 2436ern is enabled 2437\end_layout 2438 2439\begin_layout Plain Layout 2440 2441VKFFT_ERROR_UNSUPPORTED_RADIX = 3001, // VkFFT has encountered unsupported 2442 radix (more than 13) during decomposition and Bluestein's FFT fallback 2443 did not work 2444\end_layout 2445 2446\begin_layout Plain Layout 2447 2448VKFFT_ERROR_UNSUPPORTED_FFT_LENGTH = 3002, // VkFFT can not do this sequence 2449 length currently - it requires mor than three-upload Four step FFT 2450\end_layout 2451 2452\begin_layout Plain Layout 2453 2454VKFFT_ERROR_UNSUPPORTED_FFT_LENGTH_R2C = 3003, // VkFFT can not do this 2455 sequence length currently - odd multi-upload R2C/C2R FFTs 2456\end_layout 2457 2458\begin_layout Plain Layout 2459 2460VKFFT_ERROR_UNSUPPORTED_FFT_LENGTH_DCT = 3004, // VkFFT can not do this 2461 sequence length currently - multi-upload R2R transforms, odd DCT-IV transforms 2462\end_layout 2463 2464\begin_layout Plain Layout 2465 2466VKFFT_ERROR_UNSUPPORTED_FFT_OMIT = 3005, // VkFFT can not omit sequences 2467 in convolution calculations and R2C/C2R case 2468\end_layout 2469 2470\begin_layout Plain Layout 2471 2472VKFFT_ERROR_FAILED_TO_ALLOCATE = 4001, // VkFFT failed to allocate GPU memory 2473\end_layout 2474 2475\begin_layout Plain Layout 2476 2477VKFFT_ERROR_FAILED_TO_MAP_MEMORY = 4002, // 4002-4052 are handlers for errors 2478 of used backend APIs. 2479 They may indicate a driver failure. 2480 If they are thrown - report to the GitHub repo 2481\end_layout 2482 2483\begin_layout Plain Layout 2484 2485VKFFT_ERROR_FAILED_TO_ALLOCATE_COMMAND_BUFFERS = 4003, 2486\end_layout 2487 2488\begin_layout Plain Layout 2489 2490VKFFT_ERROR_FAILED_TO_BEGIN_COMMAND_BUFFER = 4004, 2491\end_layout 2492 2493\begin_layout Plain Layout 2494 2495VKFFT_ERROR_FAILED_TO_END_COMMAND_BUFFER = 4005, 2496\end_layout 2497 2498\begin_layout Plain Layout 2499 2500VKFFT_ERROR_FAILED_TO_SUBMIT_QUEUE = 4006, 2501\end_layout 2502 2503\begin_layout Plain Layout 2504 2505VKFFT_ERROR_FAILED_TO_WAIT_FOR_FENCES = 4007, 2506\end_layout 2507 2508\begin_layout Plain Layout 2509 2510VKFFT_ERROR_FAILED_TO_RESET_FENCES = 4008, 2511\end_layout 2512 2513\begin_layout Plain Layout 2514 2515VKFFT_ERROR_FAILED_TO_CREATE_DESCRIPTOR_POOL = 4009, 2516\end_layout 2517 2518\begin_layout Plain Layout 2519 2520VKFFT_ERROR_FAILED_TO_CREATE_DESCRIPTOR_SET_LAYOUT = 4010, 2521\end_layout 2522 2523\begin_layout Plain Layout 2524 2525VKFFT_ERROR_FAILED_TO_ALLOCATE_DESCRIPTOR_SETS = 4011, 2526\end_layout 2527 2528\begin_layout Plain Layout 2529 2530VKFFT_ERROR_FAILED_TO_CREATE_PIPELINE_LAYOUT = 4012, 2531\end_layout 2532 2533\begin_layout Plain Layout 2534 2535VKFFT_ERROR_FAILED_SHADER_PREPROCESS = 4013, 2536\end_layout 2537 2538\begin_layout Plain Layout 2539 2540VKFFT_ERROR_FAILED_SHADER_PARSE = 4014, 2541\end_layout 2542 2543\begin_layout Plain Layout 2544 2545VKFFT_ERROR_FAILED_SHADER_LINK = 4015, 2546\end_layout 2547 2548\begin_layout Plain Layout 2549 2550VKFFT_ERROR_FAILED_SPIRV_GENERATE = 4016, 2551\end_layout 2552 2553\begin_layout Plain Layout 2554 2555VKFFT_ERROR_FAILED_TO_CREATE_SHADER_MODULE = 4017, 2556\end_layout 2557 2558\begin_layout Plain Layout 2559 2560VKFFT_ERROR_FAILED_TO_CREATE_INSTANCE = 4018, 2561\end_layout 2562 2563\begin_layout Plain Layout 2564 2565VKFFT_ERROR_FAILED_TO_SETUP_DEBUG_MESSENGER = 4019, 2566\end_layout 2567 2568\begin_layout Plain Layout 2569 2570VKFFT_ERROR_FAILED_TO_FIND_PHYSICAL_DEVICE = 4020, 2571\end_layout 2572 2573\begin_layout Plain Layout 2574 2575VKFFT_ERROR_FAILED_TO_CREATE_DEVICE = 4021, 2576\end_layout 2577 2578\begin_layout Plain Layout 2579 2580VKFFT_ERROR_FAILED_TO_CREATE_FENCE = 4022, 2581\end_layout 2582 2583\begin_layout Plain Layout 2584 2585VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_POOL = 4023, 2586\end_layout 2587 2588\begin_layout Plain Layout 2589 2590VKFFT_ERROR_FAILED_TO_CREATE_BUFFER = 4024, 2591\end_layout 2592 2593\begin_layout Plain Layout 2594 2595VKFFT_ERROR_FAILED_TO_ALLOCATE_MEMORY = 4025, 2596\end_layout 2597 2598\begin_layout Plain Layout 2599 2600VKFFT_ERROR_FAILED_TO_BIND_BUFFER_MEMORY = 4026, 2601\end_layout 2602 2603\begin_layout Plain Layout 2604 2605VKFFT_ERROR_FAILED_TO_FIND_MEMORY = 4027, 2606\end_layout 2607 2608\begin_layout Plain Layout 2609 2610VKFFT_ERROR_FAILED_TO_SYNCHRONIZE = 4028, 2611\end_layout 2612 2613\begin_layout Plain Layout 2614 2615VKFFT_ERROR_FAILED_TO_COPY = 4029, 2616\end_layout 2617 2618\begin_layout Plain Layout 2619 2620VKFFT_ERROR_FAILED_TO_CREATE_PROGRAM = 4030, 2621\end_layout 2622 2623\begin_layout Plain Layout 2624 2625VKFFT_ERROR_FAILED_TO_COMPILE_PROGRAM = 4031, 2626\end_layout 2627 2628\begin_layout Plain Layout 2629 2630VKFFT_ERROR_FAILED_TO_GET_CODE_SIZE = 4032, 2631\end_layout 2632 2633\begin_layout Plain Layout 2634 2635VKFFT_ERROR_FAILED_TO_GET_CODE = 4033, 2636\end_layout 2637 2638\begin_layout Plain Layout 2639 2640VKFFT_ERROR_FAILED_TO_DESTROY_PROGRAM = 4034, 2641\end_layout 2642 2643\begin_layout Plain Layout 2644 2645VKFFT_ERROR_FAILED_TO_LOAD_MODULE = 4035, 2646\end_layout 2647 2648\begin_layout Plain Layout 2649 2650VKFFT_ERROR_FAILED_TO_GET_FUNCTION = 4036, 2651\end_layout 2652 2653\begin_layout Plain Layout 2654 2655VKFFT_ERROR_FAILED_TO_SET_DYNAMIC_SHARED_MEMORY = 4037, 2656\end_layout 2657 2658\begin_layout Plain Layout 2659 2660VKFFT_ERROR_FAILED_TO_MODULE_GET_GLOBAL = 4038, 2661\end_layout 2662 2663\begin_layout Plain Layout 2664 2665VKFFT_ERROR_FAILED_TO_LAUNCH_KERNEL = 4039, 2666\end_layout 2667 2668\begin_layout Plain Layout 2669 2670VKFFT_ERROR_FAILED_TO_EVENT_RECORD = 4040, 2671\end_layout 2672 2673\begin_layout Plain Layout 2674 2675VKFFT_ERROR_FAILED_TO_ADD_NAME_EXPRESSION = 4041, 2676\end_layout 2677 2678\begin_layout Plain Layout 2679 2680VKFFT_ERROR_FAILED_TO_INITIALIZE = 4042, 2681\end_layout 2682 2683\begin_layout Plain Layout 2684 2685VKFFT_ERROR_FAILED_TO_SET_DEVICE_ID = 4043, 2686\end_layout 2687 2688\begin_layout Plain Layout 2689 2690VKFFT_ERROR_FAILED_TO_GET_DEVICE = 4044, 2691\end_layout 2692 2693\begin_layout Plain Layout 2694 2695VKFFT_ERROR_FAILED_TO_CREATE_CONTEXT = 4045, 2696\end_layout 2697 2698\begin_layout Plain Layout 2699 2700VKFFT_ERROR_FAILED_TO_CREATE_PIPELINE = 4046, 2701\end_layout 2702 2703\begin_layout Plain Layout 2704 2705VKFFT_ERROR_FAILED_TO_SET_KERNEL_ARG = 4047, 2706\end_layout 2707 2708\begin_layout Plain Layout 2709 2710VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QUEUE = 4048, 2711\end_layout 2712 2713\begin_layout Plain Layout 2714 2715VKFFT_ERROR_FAILED_TO_RELEASE_COMMAND_QUEUE = 4049, 2716\end_layout 2717 2718\begin_layout Plain Layout 2719 2720VKFFT_ERROR_FAILED_TO_ENUMERATE_DEVICES = 4050, 2721\end_layout 2722 2723\begin_layout Plain Layout 2724 2725VKFFT_ERROR_FAILED_TO_GET_ATTRIBUTE = 4051, 2726\end_layout 2727 2728\begin_layout Plain Layout 2729 2730VKFFT_ERROR_FAILED_TO_CREATE_EVENT = 4052, 2731\end_layout 2732 2733\begin_layout Plain Layout 2734 2735VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_LIST = 4053, 2736\end_layout 2737 2738\begin_layout Plain Layout 2739 2740VKFFT_ERROR_FAILED_TO_DESTROY_COMMAND_LIST = 4054, 2741\end_layout 2742 2743\begin_layout Plain Layout 2744 2745VKFFT_ERROR_FAILED_TO_SUBMIT_BARRIER = 4055 2746\end_layout 2747 2748\begin_layout Plain Layout 2749 2750} VkFFTResult; 2751\end_layout 2752 2753\begin_layout Plain Layout 2754 2755 2756\backslash 2757end{minted} 2758\end_layout 2759 2760\begin_layout Plain Layout 2761 2762 2763\backslash 2764end{mdframed} 2765\end_layout 2766 2767\end_inset 2768 2769 2770\end_layout 2771 2772\begin_layout Subsection 2773VkFFT application management functions 2774\end_layout 2775 2776\begin_layout Standard 2777VkFFT has a unified plan management model - all different transform types/ 2778 dimensionalities/ precision use the same calls with configuration done 2779 through VkFFTConfiguration struct. 2780 This section shows how to initialize/use/free VkFFT with this unified model, 2781 while the next one will go into how to configure VkFFTConfiguration correctly. 2782 All of the functions operate on VkFFTApplication and VkFFTConfiguration 2783 assuming they have been zero-initialized before usage, so do not forget 2784 to do this when initializing: 2785\end_layout 2786 2787\begin_layout Standard 2788\begin_inset ERT 2789status open 2790 2791\begin_layout Plain Layout 2792 2793 2794\backslash 2795begin{mdframed}[backgroundcolor=bg] 2796\end_layout 2797 2798\begin_layout Plain Layout 2799 2800 2801\backslash 2802begin{minted}[tabsize=4,obeytabs,breaklines]{C} 2803\end_layout 2804 2805\begin_layout Plain Layout 2806 2807VkFFTConfiguration configuration = {}; 2808\end_layout 2809 2810\begin_layout Plain Layout 2811 2812VkFFTApplication app = {}; 2813\end_layout 2814 2815\begin_layout Plain Layout 2816 2817 2818\backslash 2819end{minted} 2820\end_layout 2821 2822\begin_layout Plain Layout 2823 2824 2825\backslash 2826end{mdframed} 2827\end_layout 2828 2829\end_inset 2830 2831 2832\end_layout 2833 2834\begin_layout Subsubsection 2835Function initializeVkFFT() 2836\end_layout 2837 2838\begin_layout Standard 2839\begin_inset ERT 2840status open 2841 2842\begin_layout Plain Layout 2843 2844 2845\backslash 2846begin{mdframed}[backgroundcolor=bg] 2847\end_layout 2848 2849\begin_layout Plain Layout 2850 2851 2852\backslash 2853begin{minted}[tabsize=4,obeytabs,breaklines]{C} 2854\end_layout 2855 2856\begin_layout Plain Layout 2857 2858VkFFTResult initializeVkFFT(VkFFTApplication* app, VkFFTConfiguration inputLaunc 2859hConfiguration) 2860\end_layout 2861 2862\begin_layout Plain Layout 2863 2864 2865\backslash 2866end{minted} 2867\end_layout 2868 2869\begin_layout Plain Layout 2870 2871 2872\backslash 2873end{mdframed} 2874\end_layout 2875 2876\end_inset 2877 2878 2879\end_layout 2880 2881\begin_layout Standard 2882Creates an FFT application (collection of forward and inverse plans). 2883 As forward and inverse FFTs may have different memory layouts, can have 2884 different normalizations - they are done as separate internal plans inside 2885 VkFFTApplication. 2886 This call assumes the application to be zero-initialized, so can be only 2887 done once on a particular application, until it is deleted. 2888\end_layout 2889 2890\begin_layout Standard 2891If the initializeVkFFT call fails, it frees all allocated by VkFFT CPU/GPU 2892 resources and sets the application to zero. 2893 VkFFTResult is returned with an error code corresponding to what went wrong. 2894\end_layout 2895 2896\begin_layout Standard 2897In case of success, VkFFTApplication will contain initialized plans with 2898 compiled kernels ready for execution with VKFFT_SUCCESS returned. 2899\end_layout 2900 2901\begin_layout Subsubsection 2902Function VkFFTAppend() 2903\end_layout 2904 2905\begin_layout Standard 2906\begin_inset ERT 2907status open 2908 2909\begin_layout Plain Layout 2910 2911 2912\backslash 2913begin{mdframed}[backgroundcolor=bg] 2914\end_layout 2915 2916\begin_layout Plain Layout 2917 2918 2919\backslash 2920begin{minted}[tabsize=4,obeytabs,breaklines]{C} 2921\end_layout 2922 2923\begin_layout Plain Layout 2924 2925VkFFTResult VkFFTAppend(VkFFTApplication* app, int inverse, VkFFTLaunchParams* 2926 launchParams) 2927\end_layout 2928 2929\begin_layout Plain Layout 2930 2931 2932\backslash 2933end{minted} 2934\end_layout 2935 2936\begin_layout Plain Layout 2937 2938 2939\backslash 2940end{mdframed} 2941\end_layout 2942 2943\end_inset 2944 2945 2946\end_layout 2947 2948\begin_layout Standard 2949Performs FFT in the int inverse direction (-1 for forward FFT, 1 for inverse 2950 FFT). 2951 FFT plans are selected from the VkFFTApplication collection automatically. 2952 VkFFTApplication must be initialized with initializeVkFFT call before. 2953 VkFFTLaunchParams struct allows for pre-launch configuration of some parameters 2954, namely: 2955\end_layout 2956 2957\begin_layout Itemize 2958buffer - similar to how FFTW/cuFFT expects input/output data pointers in 2959 *execC2C (and other) function calls, VkFFT allows specifying memory used 2960 for computations at launch. 2961 It must have the same size/layout/strides as defined during the application 2962 creation. 2963\end_layout 2964 2965\begin_layout Itemize 2966inputBuffer/outputBuffer/tempBuffer/kernel - other buffers can also be specified 2967 at launch. 2968 In addition to them having the same size/layout/strides as defined during 2969 the application creation, the application must be created with flags enabling 2970 the corresponding buffer usage: isInputFormatted/isOutputFormatted/userTempBuff 2971er/performConvolution respectively. 2972\end_layout 2973 2974\begin_layout Itemize 2975bufferOffset/tempBufferOffset/inputBufferOffset/outputBufferOffset/kernelOffset 2976 - specify if VkFFT has to offset the first element position inside the 2977 corresponding buffer. 2978 In bytes. 2979 Default 0. 2980 specifyOffsetsAtLaunch parameter must be enabled during the initializeVkFFT 2981 call before. 2982 2983\end_layout 2984 2985\begin_layout Standard 2986Depending on the API, the execution model may vary and require additional 2987 information at launch: 2988\end_layout 2989 2990\begin_layout Itemize 2991Vulkan API: VkFFT appends a sequence of vkCmdDispatch calls to the user-defined 2992 VkCommandBuffer (with respective push constants/descriptor sets/pipelines/memor 2993y barriers bindings). 2994 VkCommandBuffer must be provided as a pointer in VkFFTLaunchParams. 2995 VkCommandBuffer must be in the writing stage, started with vkBeginCommandBuffer 2996 call. 2997 After VkFFTAppend has finished, provided VkCommandBuffer will contain a 2998 sequence of operations performing FFT. 2999 The first call of the sequence has no input memory barrier, the last call 3000 has one, ensuring FFT has finished execution. 3001\end_layout 3002 3003\begin_layout Itemize 3004CUDA/HIP API: if the user wants to use streams, they have to be provided 3005 during the application configuration stage. 3006 VkFFTAppend performs a series of cuLaunchKernel, which are sequential if 3007 appended to one stream and synchronized if appended to multiple streams. 3008\end_layout 3009 3010\begin_layout Itemize 3011OpenCL API: similar to Vulkan, VkFFT appends a sequence of clEnqueueNDRangeKerne 3012l calls to user-defined cl_command_queue. 3013 Currently, they are all assumed to be sequential. 3014 cl_command_queue must be provided as a pointer in VkFFTLaunchParams. 3015 3016\end_layout 3017 3018\begin_layout Itemize 3019Level Zero API: similar to Vulkan, VkFFT appends a sequence of zeCommandListAppe 3020ndLaunchKernel calls to user-defined command list ze_command_list_handle_t. 3021 They have execution barriers between. 3022 ze_command_list_handle_t must be provided as a pointer in VkFFTLaunchParams. 3023 3024\end_layout 3025 3026\begin_layout Itemize 3027Metal API: similar to Vulkan, VkFFT appends a sequence of dispatchThreads 3028 calls to user-defined command encoder MTL::ComputeCommandEncoder. 3029 MTL::ComputeCommandEncoder and its MTL::CommandBuffer must be provided 3030 as a pointer in VkFFTLaunchParams. 3031 3032\end_layout 3033 3034\begin_layout Standard 3035If VkFFT fails during the VkFFTAppend call, it will not free the application 3036 and allocated there resources - use a separate call for that. 3037\end_layout 3038 3039\begin_layout Subsubsection 3040Function deleteVkFFT() 3041\end_layout 3042 3043\begin_layout Standard 3044\begin_inset ERT 3045status open 3046 3047\begin_layout Plain Layout 3048 3049 3050\backslash 3051begin{mdframed}[backgroundcolor=bg] 3052\end_layout 3053 3054\begin_layout Plain Layout 3055 3056 3057\backslash 3058begin{minted}[tabsize=4,obeytabs,breaklines]{C} 3059\end_layout 3060 3061\begin_layout Plain Layout 3062 3063void deleteVkFFT(VkFFTApplication* app) 3064\end_layout 3065 3066\begin_layout Plain Layout 3067 3068 3069\backslash 3070end{minted} 3071\end_layout 3072 3073\begin_layout Plain Layout 3074 3075 3076\backslash 3077end{mdframed} 3078\end_layout 3079 3080\end_inset 3081 3082 3083\end_layout 3084 3085\begin_layout Standard 3086Performs deallocation of resources used in the provided application. 3087 Returns application to the zero-initialized state. 3088\end_layout 3089 3090\begin_layout Subsubsection 3091Function VkFFTGetVersion() 3092\end_layout 3093 3094\begin_layout Standard 3095\begin_inset ERT 3096status open 3097 3098\begin_layout Plain Layout 3099 3100 3101\backslash 3102begin{mdframed}[backgroundcolor=bg] 3103\end_layout 3104 3105\begin_layout Plain Layout 3106 3107 3108\backslash 3109begin{minted}[tabsize=4,obeytabs,breaklines]{C} 3110\end_layout 3111 3112\begin_layout Plain Layout 3113 3114int VkFFTGetVersion() 3115\end_layout 3116 3117\begin_layout Plain Layout 3118 3119 3120\backslash 3121end{minted} 3122\end_layout 3123 3124\begin_layout Plain Layout 3125 3126 3127\backslash 3128end{mdframed} 3129\end_layout 3130 3131\end_inset 3132 3133 3134\end_layout 3135 3136\begin_layout Standard 3137Returns the version of the VkFFT library in the X.XX.XX format (without dots). 3138\end_layout 3139 3140\begin_layout Subsection 3141VkFFT configuration 3142\end_layout 3143 3144\begin_layout Standard 3145This section will cover all the parameters that can be specified in the 3146 VkFFTConfiguration struct. 3147 It will start with a short description of the struct (intended to be used 3148 as a cheat sheet), then go for each field in detail. 3149\end_layout 3150 3151\begin_layout Standard 3152\begin_inset ERT 3153status open 3154 3155\begin_layout Plain Layout 3156 3157 3158\backslash 3159begin{mdframed}[backgroundcolor=bg] 3160\end_layout 3161 3162\begin_layout Plain Layout 3163 3164 3165\backslash 3166begin{minted}[tabsize=4,obeytabs,breaklines]{C} 3167\end_layout 3168 3169\begin_layout Plain Layout 3170 3171typedef struct { 3172\end_layout 3173 3174\begin_layout Plain Layout 3175 3176// Required parameters: 3177\end_layout 3178 3179\begin_layout Plain Layout 3180 3181uint64_t FFTdim; // FFT dimensionality (1, 2 or 3) 3182\end_layout 3183 3184\begin_layout Plain Layout 3185 3186uint64_t size[VKFFT_MAX_FFT_DIMENSIONS]; // WHD+ - system dimensions 3187\end_layout 3188 3189\begin_layout Plain Layout 3190 3191#if(VKFFT_BACKEND==0) //Vulkan API 3192\end_layout 3193 3194\begin_layout Plain Layout 3195 3196VkPhysicalDevice* physicalDevice; // Pointer to Vulkan physical device, 3197 obtained from vkEnumeratePhysicalDevices 3198\end_layout 3199 3200\begin_layout Plain Layout 3201 3202VkDevice* device; // Pointer to Vulkan device, created with vkCreateDevice 3203\end_layout 3204 3205\begin_layout Plain Layout 3206 3207VkQueue* queue; // Pointer to Vulkan queue, created with vkGetDeviceQueue 3208\end_layout 3209 3210\begin_layout Plain Layout 3211 3212VkCommandPool* commandPool; // Pointer to Vulkan command pool, created with 3213 vkCreateCommandPool 3214\end_layout 3215 3216\begin_layout Plain Layout 3217 3218VkFence* fence; // Pointer to Vulkan fence, created with vkCreateFence 3219\end_layout 3220 3221\begin_layout Plain Layout 3222 3223uint64_t isCompilerInitialized; // Specify if glslang compiler has been 3224 intialized before (0 - off, 1 - on). 3225 Default 0 3226\end_layout 3227 3228\begin_layout Plain Layout 3229 3230#elif(VKFFT_BACKEND==1) //CUDA API 3231\end_layout 3232 3233\begin_layout Plain Layout 3234 3235CUdevice* device; // Pointer to CUDA device, obtained from cuDeviceGet 3236\end_layout 3237 3238\begin_layout Plain Layout 3239 3240cudaStream_t* stream; // Pointer to streams (can be more than 1), where 3241 to execute the kernels. 3242 Deafult 0 3243\end_layout 3244 3245\begin_layout Plain Layout 3246 3247uint64_t num_streams; // Try to submit CUDA kernels in multiple streams 3248 for asynchronous execution. 3249 Default 1 3250\end_layout 3251 3252\begin_layout Plain Layout 3253 3254#elif(VKFFT_BACKEND==2) //HIP API 3255\end_layout 3256 3257\begin_layout Plain Layout 3258 3259hipDevice_t* device; // Pointer to HIP device, obtained from hipDeviceGet 3260\end_layout 3261 3262\begin_layout Plain Layout 3263 3264hipStream_t* stream; // Pointer to streams (can be more than 1), where to 3265 execute the kernels. 3266 Deafult 0 3267\end_layout 3268 3269\begin_layout Plain Layout 3270 3271uint64_t num_streams; // Try to submit HIP kernels in multiple streams for 3272 asynchronous execution. 3273 Default 1 3274\end_layout 3275 3276\begin_layout Plain Layout 3277 3278#elif(VKFFT_BACKEND==3) //OpenCL API 3279\end_layout 3280 3281\begin_layout Plain Layout 3282 3283cl_platform_id* platform; // NOT REQUIRED 3284\end_layout 3285 3286\begin_layout Plain Layout 3287 3288cl_device_id* device; // Pointer to OpenCL device, obtained from clGetDeviceIDs 3289\end_layout 3290 3291\begin_layout Plain Layout 3292 3293cl_context* context; // Pointer to OpenCL context, obtained from clCreateContext 3294\end_layout 3295 3296\begin_layout Plain Layout 3297 3298#elif(VKFFT_BACKEND==4) //Level Zero API 3299\end_layout 3300 3301\begin_layout Plain Layout 3302 3303ze_device_handle_t* device; // Pointer to Level Zero device, obtained from 3304 zeDeviceGet 3305\end_layout 3306 3307\begin_layout Plain Layout 3308 3309ze_context_handle_t* context; // Pointer to Level Zero context, obtained 3310 from zeContextCreate 3311\end_layout 3312 3313\begin_layout Plain Layout 3314 3315ze_command_queue_handle_t* commandQueue; // Pointer to Level Zero command 3316 queue with compute and copy capabilities, obtained from zeCommandQueueCreate 3317\end_layout 3318 3319\begin_layout Plain Layout 3320 3321uint32_t commandQueueID; // ID of the commandQueue with compute and copy 3322 capabilities 3323\end_layout 3324 3325\begin_layout Plain Layout 3326 3327#elif(VKFFT_BACKEND==5) 3328\end_layout 3329 3330\begin_layout Plain Layout 3331 3332MTL::Device* device; // Pointer to Metal device, obtained from MTL::CopyAllDevic 3333es 3334\end_layout 3335 3336\begin_layout Plain Layout 3337 3338MTL::CommandQueue* queue; // Pointer to Metal queue, obtained from device->newCo 3339mmandQueue() 3340\end_layout 3341 3342\begin_layout Plain Layout 3343 3344#endif 3345\end_layout 3346 3347\begin_layout Plain Layout 3348 3349\end_layout 3350 3351\begin_layout Plain Layout 3352 3353// Data parameters (buffers can be specified at launch): 3354\end_layout 3355 3356\begin_layout Plain Layout 3357 3358uint64_t userTempBuffer; // Buffer allocated by app automatically if needed 3359 to reorder Four step algorithm. 3360 Setting to non zero value enables manual user allocation (0 - off, 1 - 3361 on) 3362\end_layout 3363 3364\begin_layout Plain Layout 3365 3366uint64_t bufferNum; // Multiple buffer sequence storage is Vulkan only. 3367 Default 1 3368\end_layout 3369 3370\begin_layout Plain Layout 3371 3372uint64_t tempBufferNum; // Multiple buffer sequence storage is Vulkan only. 3373 Default 1, buffer allocated by app automatically if needed to reorder Four 3374 step algorithm. 3375 Setting to non zero value enables manual user allocation 3376\end_layout 3377 3378\begin_layout Plain Layout 3379 3380uint64_t inputBufferNum; // Multiple buffer sequence storage is Vulkan only. 3381 Default 1, if isInputFormatted is enabled 3382\end_layout 3383 3384\begin_layout Plain Layout 3385 3386uint64_t outputBufferNum; // Multiple buffer sequence storage is Vulkan 3387 only. 3388 Default 1, if isOutputFormatted is enabled 3389\end_layout 3390 3391\begin_layout Plain Layout 3392 3393uint64_t kernelNum; // Multiple buffer sequence storage is Vulkan only. 3394 Default 1, if performConvolution is enabled 3395\end_layout 3396 3397\begin_layout Plain Layout 3398 3399uint64_t* bufferSize; // Array of buffers sizes in bytes 3400\end_layout 3401 3402\begin_layout Plain Layout 3403 3404uint64_t* tempBufferSize; // Array of temp buffers sizes in bytes. 3405 Default set to bufferSize sum, buffer allocated by app automatically if 3406 needed to reorder Four step algorithm. 3407 Setting to non zero value enables manual user allocation 3408\end_layout 3409 3410\begin_layout Plain Layout 3411 3412uint64_t* inputBufferSize; // Array of input buffers sizes in bytes, if 3413 isInputFormatted is enabled 3414\end_layout 3415 3416\begin_layout Plain Layout 3417 3418uint64_t* outputBufferSize; // Array of output buffers sizes in bytes, if 3419 isOutputFormatted is enabled 3420\end_layout 3421 3422\begin_layout Plain Layout 3423 3424uint64_t* kernelSize; // Array of kernel buffers sizes in bytes, if performConvo 3425lution is enabled 3426\end_layout 3427 3428\begin_layout Plain Layout 3429 3430#if(VKFFT_BACKEND==0) //Vulkan API 3431\end_layout 3432 3433\begin_layout Plain Layout 3434 3435VkBuffer* buffer; // Pointer to array of buffers (or one buffer) used for 3436 computations 3437\end_layout 3438 3439\begin_layout Plain Layout 3440 3441VkBuffer* tempBuffer; // Needed if reorderFourStep is enabled to transpose 3442 the array. 3443 Same sum size or bigger as buffer (can be split in multiple). 3444 Default 0. 3445 Setting to non zero value enables manual user allocation 3446\end_layout 3447 3448\begin_layout Plain Layout 3449 3450VkBuffer* inputBuffer; // Pointer to array of input buffers (or one buffer) 3451 used to read data from if isInputFormatted is enabled 3452\end_layout 3453 3454\begin_layout Plain Layout 3455 3456VkBuffer* outputBuffer; // Pointer to array of output buffers (or one buffer) 3457 used to write data to if isOutputFormatted is enabled 3458\end_layout 3459 3460\begin_layout Plain Layout 3461 3462VkBuffer* kernel; // Pointer to array of kernel buffers (or one buffer) 3463 used to read kernel data from if performConvolution is enabled 3464\end_layout 3465 3466\begin_layout Plain Layout 3467 3468#elif(VKFFT_BACKEND==1) //CUDA API 3469\end_layout 3470 3471\begin_layout Plain Layout 3472 3473void** buffer; // Pointer to device buffer used for computations 3474\end_layout 3475 3476\begin_layout Plain Layout 3477 3478void** tempBuffer; // Needed if reorderFourStep is enabled to transpose 3479 the array. 3480 Same size as buffer. 3481 Default 0. 3482 Setting to non zero value enables manual user allocation 3483\end_layout 3484 3485\begin_layout Plain Layout 3486 3487void** inputBuffer; // Pointer to device buffer used to read data from if 3488 isInputFormatted is enabled 3489\end_layout 3490 3491\begin_layout Plain Layout 3492 3493void** outputBuffer; // Pointer to device buffer used to write data to if 3494 isOutputFormatted is enabled 3495\end_layout 3496 3497\begin_layout Plain Layout 3498 3499void** kernel; // Pointer to device buffer used to read kernel data from 3500 if performConvolution is enabled 3501\end_layout 3502 3503\begin_layout Plain Layout 3504 3505#elif(VKFFT_BACKEND==2) //HIP API 3506\end_layout 3507 3508\begin_layout Plain Layout 3509 3510void** buffer; // Pointer to device buffer used for computations 3511\end_layout 3512 3513\begin_layout Plain Layout 3514 3515void** tempBuffer; // Needed if reorderFourStep is enabled to transpose 3516 the array. 3517 Same size as buffer. 3518 Default 0. 3519 Setting to non zero value enables manual user allocation 3520\end_layout 3521 3522\begin_layout Plain Layout 3523 3524void** inputBuffer; // Pointer to device buffer used to read data from if 3525 isInputFormatted is enabled 3526\end_layout 3527 3528\begin_layout Plain Layout 3529 3530void** outputBuffer; // Pointer to device buffer used to write data to if 3531 isOutputFormatted is enabled 3532\end_layout 3533 3534\begin_layout Plain Layout 3535 3536void** kernel; // Pointer to device buffer used to read kernel data from 3537 if performConvolution is enabled 3538\end_layout 3539 3540\begin_layout Plain Layout 3541 3542#elif(VKFFT_BACKEND==3) //OpenCL API 3543\end_layout 3544 3545\begin_layout Plain Layout 3546 3547cl_mem* buffer; // Pointer to device buffer used for computations 3548\end_layout 3549 3550\begin_layout Plain Layout 3551 3552cl_mem* tempBuffer; // Needed if reorderFourStep is enabled to transpose 3553 the array. 3554 Same size as buffer. 3555 Default 0. 3556 Setting to non zero value enables manual user allocation 3557\end_layout 3558 3559\begin_layout Plain Layout 3560 3561cl_mem* inputBuffer; // Pointer to device buffer used to read data from 3562 if isInputFormatted is enabled 3563\end_layout 3564 3565\begin_layout Plain Layout 3566 3567cl_mem* outputBuffer; // Pointer to device buffer used to write data to 3568 if isOutputFormatted is enabled 3569\end_layout 3570 3571\begin_layout Plain Layout 3572 3573cl_mem* kernel; // Pointer to device buffer used to read kernel data from 3574 if performConvolution is enabled 3575\end_layout 3576 3577\begin_layout Plain Layout 3578 3579#elif(VKFFT_BACKEND==4) 3580\end_layout 3581 3582\begin_layout Plain Layout 3583 3584void** buffer; // Pointer to device buffer used for computations 3585\end_layout 3586 3587\begin_layout Plain Layout 3588 3589void** tempBuffer; // Needed if reorderFourStep is enabled to transpose 3590 the array. 3591 Same size as buffer. 3592 Default 0. 3593 Setting to non zero value enables manual user allocation 3594\end_layout 3595 3596\begin_layout Plain Layout 3597 3598void** inputBuffer; // Pointer to device buffer used to read data from if 3599 isInputFormatted is enabled 3600\end_layout 3601 3602\begin_layout Plain Layout 3603 3604void** outputBuffer; // Pointer to device buffer used to read data from 3605 if isOutputFormatted is enabled 3606\end_layout 3607 3608\begin_layout Plain Layout 3609 3610void** kernel; // Pointer to device buffer used to read kernel data from 3611 if performConvolution is enabled 3612\end_layout 3613 3614\begin_layout Plain Layout 3615 3616#elif(VKFFT_BACKEND==5) 3617\end_layout 3618 3619\begin_layout Plain Layout 3620 3621MTL::Buffer** buffer; // Pointer to device buffer used for computations 3622\end_layout 3623 3624\begin_layout Plain Layout 3625 3626MTL::Buffer** tempBuffer; // Needed if reorderFourStep is enabled to transpose 3627 the array. 3628 Same size as buffer. 3629 Default 0. 3630 Setting to non zero value enables manual user allocation 3631\end_layout 3632 3633\begin_layout Plain Layout 3634 3635MTL::Buffer** inputBuffer; // Pointer to device buffer used to read data 3636 from if isInputFormatted is enabled 3637\end_layout 3638 3639\begin_layout Plain Layout 3640 3641MTL::Buffer** outputBuffer; // Pointer to device buffer used to read data 3642 from if isOutputFormatted is enabled 3643\end_layout 3644 3645\begin_layout Plain Layout 3646 3647MTL::Buffer** kernel; // Pointer to device buffer used to read kernel data 3648 from if performConvolution is enabled 3649\end_layout 3650 3651\begin_layout Plain Layout 3652 3653#endif 3654\end_layout 3655 3656\begin_layout Plain Layout 3657 3658uint64_t bufferOffset; // Specify if VkFFT has to offset the first element 3659 position inside the buffer. 3660 In bytes. 3661 Default 0 3662\end_layout 3663 3664\begin_layout Plain Layout 3665 3666uint64_t tempBufferOffset; // Specify if VkFFT has to offset the first element 3667 position inside the temp buffer. 3668 In bytes. 3669 Default 0 3670\end_layout 3671 3672\begin_layout Plain Layout 3673 3674uint64_t inputBufferOffset; // Specify if VkFFT has to offset the first 3675 element position inside the input buffer. 3676 In bytes. 3677 Default 0 3678\end_layout 3679 3680\begin_layout Plain Layout 3681 3682uint64_t outputBufferOffset; // Specify if VkFFT has to offset the first 3683 element position inside the output buffer. 3684 In bytes. 3685 Default 0 3686\end_layout 3687 3688\begin_layout Plain Layout 3689 3690uint64_t kernelOffset; // Specify if VkFFT has to offset the first element 3691 position inside the kernel. 3692 In bytes. 3693 Default 0 3694\end_layout 3695 3696\begin_layout Plain Layout 3697 3698uint64_t specifyOffsetsAtLaunch; // Specify if offsets will be selected 3699 with launch parameters VkFFTLaunchParams (0 - off, 1 - on). 3700 Default 0 3701\end_layout 3702 3703\begin_layout Plain Layout 3704 3705\end_layout 3706 3707\begin_layout Plain Layout 3708 3709// Optional: (default 0 if not stated otherwise) 3710\end_layout 3711 3712\begin_layout Plain Layout 3713 3714uint64_t coalescedMemory; // In bytes, for Nvidia and AMD is equal to 32, 3715 Intel is equal 64, scaled for half precision. 3716 Going to work regardless, but if specified by user correctly, the performance 3717 will be higher. 3718\end_layout 3719 3720\begin_layout Plain Layout 3721 3722uint64_t aimThreads; // Aim at this many threads per block. 3723 Default 128 3724\end_layout 3725 3726\begin_layout Plain Layout 3727 3728uint64_t numSharedBanks; // How many banks shared memory has. 3729 Default 32 3730\end_layout 3731 3732\begin_layout Plain Layout 3733 3734uint64_t inverseReturnToInputBuffer; // return data to the input buffer 3735 in inverse transform (0 - off, 1 - on). 3736 isInputFormatted must be enabled 3737\end_layout 3738 3739\begin_layout Plain Layout 3740 3741uint64_t numberBatches; // N - used to perform multiple batches of initial 3742 data. 3743 Default 1 3744\end_layout 3745 3746\begin_layout Plain Layout 3747 3748uint64_t useUint64; // Use 64-bit addressing mode in generated kernels 3749\end_layout 3750 3751\begin_layout Plain Layout 3752 3753uint64_t omitDimension[VKFFT_MAX_FFT_DIMENSIONS]; // Disable FFT for this 3754 dimension (0 - FFT enabled, 1 - FFT disabled). 3755 Default 0. 3756 Doesn't work for R2C first axis for now. 3757 Doesn't work with convolutions. 3758\end_layout 3759 3760\begin_layout Plain Layout 3761 3762uint64_t performBandwidthBoost; // Try to reduce coalsesced number by a 3763 factor of X to get bigger sequence in one upload for strided axes. 3764 Default: -1 for DCT, 2 for Bluestein's algorithm (or -1 if DCT), 0 otherwise 3765 3766\end_layout 3767 3768\begin_layout Plain Layout 3769 3770\end_layout 3771 3772\begin_layout Plain Layout 3773 3774uint64_t doublePrecision; // Perform calculations in double precision (0 3775 - off, 1 - on). 3776\end_layout 3777 3778\begin_layout Plain Layout 3779 3780uint64_t halfPrecision; // Perform calculations in half precision (0 - off, 3781 1 - on) 3782\end_layout 3783 3784\begin_layout Plain Layout 3785 3786uint64_t halfPrecisionMemoryOnly; // Use half precision only as input/output 3787 buffer. 3788 Input/Output have to be allocated as half, buffer/tempBuffer have to be 3789 allocated as float (out-of-place mode only). 3790 Specify isInputFormatted and isOutputFormatted to use (0 - off, 1 - on) 3791\end_layout 3792 3793\begin_layout Plain Layout 3794 3795uint64_t doublePrecisionFloatMemory; // Use FP64 precision for all calculations, 3796 while all memory storage is done in FP32. 3797\end_layout 3798 3799\begin_layout Plain Layout 3800 3801uint64_t performR2C; // Perform R2C/C2R decomposition (0 - off, 1 - on) 3802\end_layout 3803 3804\begin_layout Plain Layout 3805 3806uint64_t performDCT; // Perform DCT transformation (X - DCT type, 1-4) 3807\end_layout 3808 3809\begin_layout Plain Layout 3810 3811uint64_t disableMergeSequencesR2C; // Disable merging of two real sequences 3812 to reduce calculations (0 - off, 1 - on) 3813\end_layout 3814 3815\begin_layout Plain Layout 3816 3817uint64_t normalize; // Normalize inverse transform (0 - off, 1 - on) 3818\end_layout 3819 3820\begin_layout Plain Layout 3821 3822uint64_t disableReorderFourStep; // Disables unshuffling of Four step algorithm. 3823 Requires tempbuffer allocation (0 - off, 1 - on) 3824\end_layout 3825 3826\begin_layout Plain Layout 3827 3828uint64_t useLUT; // Switches from calculating sincos to using precomputed 3829 LUT tables (0 - off, 1 - on). 3830 Configured by initialization routine 3831\end_layout 3832 3833\begin_layout Plain Layout 3834 3835uint64_t makeForwardPlanOnly; // Generate code only for forward FFT (0 - 3836 off, 1 - on) 3837\end_layout 3838 3839\begin_layout Plain Layout 3840 3841uint64_t makeInversePlanOnly; // Generate code only for inverse FFT (0 - 3842 off, 1 - on) 3843\end_layout 3844 3845\begin_layout Plain Layout 3846 3847uint64_t bufferStride[VKFFT_MAX_FFT_DIMENSIONS]; // Buffer strides - default 3848 set to x - x*y - x*y*z values 3849\end_layout 3850 3851\begin_layout Plain Layout 3852 3853uint64_t isInputFormatted; // Specify if input buffer is padded - 0 - padded, 3854 1 - not padded. 3855 For example if it is not padded for R2C if out-of-place mode is selected 3856 (only if numberBatches==1 and numberKernels==1) 3857\end_layout 3858 3859\begin_layout Plain Layout 3860 3861uint64_t isOutputFormatted; // Specify if output buffer is padded - 0 - 3862 padded, 1 - not padded. 3863 For example if it is not padded for R2C if out-of-place mode is selected 3864 (only if numberBatches==1 and numberKernels==1) 3865\end_layout 3866 3867\begin_layout Plain Layout 3868 3869uint64_t inputBufferStride[VKFFT_MAX_FFT_DIMENSIONS]; // Input buffer strides. 3870 Used if isInputFormatted is enabled. 3871 Default set to bufferStride values 3872\end_layout 3873 3874\begin_layout Plain Layout 3875 3876uint64_t outputBufferStride[VKFFT_MAX_FFT_DIMENSIONS]; // Output buffer 3877 strides. 3878 Used if isInputFormatted is enabled. 3879 Default set to bufferStride values 3880\end_layout 3881 3882\begin_layout Plain Layout 3883 3884uint64_t considerAllAxesStrided; // Will create plan for non-strided axis 3885 similar as a strided axis - used with disableReorderFourStep to get the 3886 same layout for Bluestein kernel (0 - off, 1 - on) 3887\end_layout 3888 3889\begin_layout Plain Layout 3890 3891uint64_t keepShaderCode; // Will keep shader code and print all executed 3892 shaders during the plan execution in order (0 - off, 1 - on) 3893\end_layout 3894 3895\begin_layout Plain Layout 3896 3897uint64_t printMemoryLayout; // Will print order of buffers used in shaders 3898 (0 - off, 1 - on) 3899\end_layout 3900 3901\begin_layout Plain Layout 3902 3903\end_layout 3904 3905\begin_layout Plain Layout 3906 3907uint64_t saveApplicationToString; // Will save all compiled binaries to 3908 VkFFTApplication.saveApplicationString (will be allocated by VkFFT, deallocated 3909 with deleteVkFFT call). 3910 VkFFTApplication.applicationStringSize will contain size of binary in bytes. 3911 Currently disabled in Metal backend. 3912 (0 - off, 1 - on) 3913\end_layout 3914 3915\begin_layout Plain Layout 3916 3917uint64_t loadApplicationFromString; // Will load all binaries from loadApplicati 3918onString instead of recompiling them (must be allocated by user, must contain 3919 what saveApplicationToString call generated previously in VkFFTApplication.saveA 3920pplicationString). 3921 Currently disabled in Metal backend. 3922 (0 - off, 1 - on). 3923 Mutually exclusive with saveApplicationToString 3924\end_layout 3925 3926\begin_layout Plain Layout 3927 3928void* loadApplicationString; // Memory binary array through which user can 3929 load VkFFT binaries, must be provided by user if loadApplicationFromString 3930 = 1. 3931 Use rb/wb flags to load/save. 3932\end_layout 3933 3934\begin_layout Plain Layout 3935 3936\end_layout 3937 3938\begin_layout Plain Layout 3939 3940uint64_t disableSetLocale; // disables all VkFFT attempts to set locale 3941 to C - user must ensure that VkFFT has C locale during the plan initialization. 3942 This option is needed for multithreading. 3943 Default 0. 3944 3945\end_layout 3946 3947\begin_layout Plain Layout 3948 3949\end_layout 3950 3951\begin_layout Plain Layout 3952 3953//optional Bluestein optimizations: (default 0 if not stated otherwise) 3954\end_layout 3955 3956\begin_layout Plain Layout 3957 3958uint64_t fixMaxRadixBluestein; // controls the padding of sequences in Bluestein 3959 convolution. 3960 If specified, padded sequence will be made of up to fixMaxRadixBluestein 3961 primes. 3962 Default: 2 for CUDA and Vulkan/OpenCL/HIP up to 1048576 combined dimension 3963 FFT system, 7 for Vulkan/OpenCL/HIP past after. 3964 Min = 2, Max = 13. 3965\end_layout 3966 3967\begin_layout Plain Layout 3968 3969uint64_t forceBluesteinSequenceSize; // force the sequence size to pad to 3970 in Bluestein's algorithm. 3971 Must be at least 2*N-1 and decomposable with primes 2-13. 3972\end_layout 3973 3974\begin_layout Plain Layout 3975 3976uint64_t useCustomBluesteinPaddingPattern; // force the sequence sizes to 3977 pad to in Bluestein's algorithm, but on a range. 3978 This number specifies the number of elements in primeSizes and in paddedSizes 3979 arrays. 3980 primeSizes - array of non-decomposable as radix scheme sizes - 17, 23, 3981 31 etc. 3982 paddedSizes - array of lengths to pad to. 3983 paddedSizes[i] will be the padding size for all non-decomposable sequences 3984 from primeSizes[i] to primeSizes[i+1] (will use default scheme after last 3985 one) - 42, 60, 64 for primeSizes before and 37+ will use default scheme 3986 (for example). 3987 Default is vendor and API-based specified in autoCustomBluesteinPaddingPattern. 3988\end_layout 3989 3990\begin_layout Plain Layout 3991 3992uint64_t* primeSizes; // described in useCustomBluesteinPaddingPattern 3993\end_layout 3994 3995\begin_layout Plain Layout 3996 3997uint64_t* paddedSizes; // described in useCustomBluesteinPaddingPattern 3998\end_layout 3999 4000\begin_layout Plain Layout 4001 4002\end_layout 4003 4004\begin_layout Plain Layout 4005 4006uint64_t fixMinRaderPrimeMult; // start direct multiplication Rader's algorithm 4007 for radix primes from this number. 4008 This means that VkFFT will inline custom Rader kernels if sequence is divisible 4009 by these primes. 4010 Default is 17, as VkFFT has kernels for 2-13. 4011 If you make it less than 13, VkFFT will switch from these kernels to Rader. 4012\end_layout 4013 4014\begin_layout Plain Layout 4015 4016uint64_t fixMaxRaderPrimeMult; // switch from Mult Rader's algorithm for 4017 radix primes from this number. 4018 Current limitation for Rader is maxThreadNum/2+1, realistically you would 4019 want to switch somewhere on 30-100 range. 4020 Default is vendor-specific (currently ~40) 4021\end_layout 4022 4023\begin_layout Plain Layout 4024 4025\end_layout 4026 4027\begin_layout Plain Layout 4028 4029uint64_t fixMinRaderPrimeFFT; // start FFT convolution version of Rader 4030 for radix primes from this number. 4031 Better than direct multiplication version for almost all primes (except 4032 small ones, like 17-23 on some GPUs). 4033 Must be bigger or equal to fixMinRaderPrimeMult. 4034 Deafult 29 on AMD and 17 on other GPUs. 4035 4036\end_layout 4037 4038\begin_layout Plain Layout 4039 4040uint64_t fixMaxRaderPrimeFFT; // switch to Bluestein's algorithm for radix 4041 primes from this number. 4042 Switch may happen earlier if prime can't fit in shared memory. 4043 Default is 16384, which is bigger than most current GPU's shared memory. 4044\end_layout 4045 4046\begin_layout Plain Layout 4047 4048\end_layout 4049 4050\begin_layout Plain Layout 4051 4052// Optional zero padding control parameters: (default 0 if not stated otherwise) 4053\end_layout 4054 4055\begin_layout Plain Layout 4056 4057uint64_t performZeropadding[VKFFT_MAX_FFT_DIMENSIONS]; // Don't read some 4058 data/perform computations if some input sequences are zeropadded for each 4059 axis (0 - off, 1 - on) 4060\end_layout 4061 4062\begin_layout Plain Layout 4063 4064uint64_t fft_zeropad_left[VKFFT_MAX_FFT_DIMENSIONS]; // Specify start boundary 4065 of zero block in the system for each axis 4066\end_layout 4067 4068\begin_layout Plain Layout 4069 4070uint64_t fft_zeropad_right[VKFFT_MAX_FFT_DIMENSIONS]; // Specify end boundary 4071 of zero block in the system for each axis 4072\end_layout 4073 4074\begin_layout Plain Layout 4075 4076uint64_t frequencyZeroPadding; // Set to 1 if zeropadding of frequency domain, 4077 default 0 - spatial zeropadding 4078\end_layout 4079 4080\begin_layout Plain Layout 4081 4082\end_layout 4083 4084\begin_layout Plain Layout 4085 4086// Optional convolution control parameters: (default 0 if not stated otherwise) 4087\end_layout 4088 4089\begin_layout Plain Layout 4090 4091uint64_t performConvolution; // Perform convolution in this application 4092 (0 - off, 1 - on). 4093 Disables reorderFourStep parameter 4094\end_layout 4095 4096\begin_layout Plain Layout 4097 4098uint64_t coordinateFeatures; // C - coordinate, or dimension of features 4099 vector. 4100 In matrix convolution - size of a vector 4101\end_layout 4102 4103\begin_layout Plain Layout 4104 4105uint64_t matrixConvolution; // If equal to 2 perform 2x2, if equal to 3 4106 perform 3x3 matrix-vector convolution. 4107 Overrides coordinateFeatures 4108\end_layout 4109 4110\begin_layout Plain Layout 4111 4112uint64_t symmetricKernel; // Specify if kernel in 2x2 or 3x3 matrix convolution 4113 is symmetric 4114\end_layout 4115 4116\begin_layout Plain Layout 4117 4118uint64_t numberKernels; // N - only used in convolution step - specify how 4119 many kernels were initialized before. 4120 Expands one input to multiple (batched) output 4121\end_layout 4122 4123\begin_layout Plain Layout 4124 4125uint64_t kernelConvolution; // Specify if this application is used to create 4126 kernel for convolution, so it has the same properties. 4127 performConvolution has to be set to 0 for kernel creation 4128\end_layout 4129 4130\begin_layout Plain Layout 4131 4132\end_layout 4133 4134\begin_layout Plain Layout 4135 4136// Register overutilization (experimental): (default 0 if not stated otherwise) 4137\end_layout 4138 4139\begin_layout Plain Layout 4140 4141uint64_t registerBoost; // Specify if register file size is bigger than 4142 shared memory and can be used to extend it X times (on Nvidia 256KB register 4143 file can be used instead of 32KB of shared memory, set this constant to 4144 4 to emulate 128KB of shared memory). 4145 Defaults: Nvidia - 4 in Vulkan/OpenCL, 1 in CUDA backend; AMD - 2 if shared 4146 memory >= 64KB, else 4 in Vulkan/OpenCL backend, 1 in HIP backend; Intel 4147 - 1 if shared memory >= 64KB, else 2 in Vulkan/OpenCL/Level Zero backends, 4148 1 in Metal; Default 1 4149\end_layout 4150 4151\begin_layout Plain Layout 4152 4153uint64_t registerBoostNonPow2; // Specify if register overutilization should 4154 be used on non power of 2 sequences (0 - off, 1 - on) 4155\end_layout 4156 4157\begin_layout Plain Layout 4158 4159uint64_t registerBoost4Step; // Specify if register file overutilization 4160 should be used in big sequences (>2^14), same definition as registerBoost. 4161 Default 1 4162\end_layout 4163 4164\begin_layout Plain Layout 4165 4166//not used techniques: 4167\end_layout 4168 4169\begin_layout Plain Layout 4170 4171uint64_t swapTo3Stage4Step; // Specify at which power of 2 to switch from 4172 2 upload to 3 upload 4-step FFT, in case if making max sequence size lower 4173 than coalesced sequence helps to combat TLB misses. 4174 Default 0 - disabled. 4175 Must be at least 17 4176\end_layout 4177 4178\begin_layout Plain Layout 4179 4180uint64_t devicePageSize; // In KB, the size of a page on the GPU. 4181 Setting to 0 disables local buffer split in pages 4182\end_layout 4183 4184\begin_layout Plain Layout 4185 4186uint64_t localPageSize; // In KB, the size to split page into if sequence 4187 spans multiple devicePageSize pages 4188\end_layout 4189 4190\begin_layout Plain Layout 4191 4192\end_layout 4193 4194\begin_layout Plain Layout 4195 4196// Automatically filled based on device info (still can be reconfigured 4197 by user): 4198\end_layout 4199 4200\begin_layout Plain Layout 4201 4202uint64_t computeCapabilityMajor; // CUDA/HIP compute capability of the device 4203\end_layout 4204 4205\begin_layout Plain Layout 4206 4207uint64_t computeCapabilityMinor; // CUDA/HIP compute capability of the device 4208 4209\end_layout 4210 4211\begin_layout Plain Layout 4212 4213uint64_t maxComputeWorkGroupCount[VKFFT_MAX_FFT_DIMENSIONS]; // maxComputeWorkGr 4214oupCount from VkPhysicalDeviceLimits 4215\end_layout 4216 4217\begin_layout Plain Layout 4218 4219uint64_t maxComputeWorkGroupSize[VKFFT_MAX_FFT_DIMENSIONS]; // maxComputeWorkGro 4220upCount from VkPhysicalDeviceLimits 4221\end_layout 4222 4223\begin_layout Plain Layout 4224 4225uint64_t maxThreadsNum; // Max number of threads from VkPhysicalDeviceLimits 4226\end_layout 4227 4228\begin_layout Plain Layout 4229 4230uint64_t sharedMemorySizeStatic; // Available for static allocation shared 4231 memory size, in bytes 4232\end_layout 4233 4234\begin_layout Plain Layout 4235 4236uint64_t sharedMemorySize; // Available for allocation shared memory size, 4237 in bytes 4238\end_layout 4239 4240\begin_layout Plain Layout 4241 4242uint64_t sharedMemorySizePow2; // Power of 2 which is less or equal to sharedMem 4243orySize, in bytes 4244\end_layout 4245 4246\begin_layout Plain Layout 4247 4248uint64_t warpSize; // Number of threads per warp/wavefront. 4249\end_layout 4250 4251\begin_layout Plain Layout 4252 4253uint64_t halfThreads; // Intel fix 4254\end_layout 4255 4256\begin_layout Plain Layout 4257 4258uint64_t allocateTempBuffer; // Buffer allocated by app automatically if 4259 needed to reorder Four step algorithm. 4260 Parameter to check if it has been allocated 4261\end_layout 4262 4263\begin_layout Plain Layout 4264 4265uint64_t reorderFourStep; // Unshuffle Four step algorithm. 4266 Requires tempbuffer allocation (0 - off, 1 - on). 4267 Default 1. 4268\end_layout 4269 4270\begin_layout Plain Layout 4271 4272int64_t maxCodeLength; // Specify how big can be buffer used for code generation 4273 (in char). 4274 Default 1000000 chars. 4275 4276\end_layout 4277 4278\begin_layout Plain Layout 4279 4280int64_t maxTempLength; // Specify how big can be buffer used for intermediate 4281 string sprintfs be (in char). 4282 Default 5000 chars. 4283 If code segfaults for some reason - try increasing this number. 4284\end_layout 4285 4286\begin_layout Plain Layout 4287 4288uint64_t autoCustomBluesteinPaddingPattern; // default value for useCustomBluest 4289einPaddingPattern 4290\end_layout 4291 4292\begin_layout Plain Layout 4293 4294uint64_t useRaderUintLUT; // allocate additional LUT to store g_pow 4295\end_layout 4296 4297\begin_layout Plain Layout 4298 4299uint64_t vendorID; // vendorID 0x10DE - NVIDIA, 0x8086 - Intel, 0x1002 - 4300 AMD, etc 4301\end_layout 4302 4303\begin_layout Plain Layout 4304 4305#if(VKFFT_BACKEND==0) //Vulkan API 4306\end_layout 4307 4308\begin_layout Plain Layout 4309 4310VkDeviceMemory tempBufferDeviceMemory; // Filled at app creation 4311\end_layout 4312 4313\begin_layout Plain Layout 4314 4315VkCommandBuffer* commandBuffer; // Filled at app execution 4316\end_layout 4317 4318\begin_layout Plain Layout 4319 4320VkMemoryBarrier* memory_barrier; // Filled at app creation 4321\end_layout 4322 4323\begin_layout Plain Layout 4324 4325#elif(VKFFT_BACKEND==1) //CUDA API 4326\end_layout 4327 4328\begin_layout Plain Layout 4329 4330cudaEvent_t* stream_event; // Filled at app creation 4331\end_layout 4332 4333\begin_layout Plain Layout 4334 4335uint64_t streamCounter; // Filled at app creation 4336\end_layout 4337 4338\begin_layout Plain Layout 4339 4340uint64_t streamID; // Filled at app creation 4341\end_layout 4342 4343\begin_layout Plain Layout 4344 4345#elif(VKFFT_BACKEND==2) //HIP API 4346\end_layout 4347 4348\begin_layout Plain Layout 4349 4350hipEvent_t* stream_event; // Filled at app creation 4351\end_layout 4352 4353\begin_layout Plain Layout 4354 4355uint64_t streamCounter; // Filled at app creation 4356\end_layout 4357 4358\begin_layout Plain Layout 4359 4360uint64_t streamID; // Filled at app creation 4361\end_layout 4362 4363\begin_layout Plain Layout 4364 4365#elif(VKFFT_BACKEND==3) //OpenCL API 4366\end_layout 4367 4368\begin_layout Plain Layout 4369 4370cl_command_queue* commandQueue; // Filled at app creation 4371\end_layout 4372 4373\begin_layout Plain Layout 4374 4375#elif(VKFFT_BACKEND==4) 4376\end_layout 4377 4378\begin_layout Plain Layout 4379 4380ze_command_list_handle_t* commandList; // Filled at app creation 4381\end_layout 4382 4383\begin_layout Plain Layout 4384 4385#elif(VKFFT_BACKEND==5) 4386\end_layout 4387 4388\begin_layout Plain Layout 4389 4390MTL::CommandBuffer* commandBuffer; // Filled at app execution 4391\end_layout 4392 4393\begin_layout Plain Layout 4394 4395MTL::ComputeCommandEncoder* commandEncoder; // Filled at app execution 4396\end_layout 4397 4398\begin_layout Plain Layout 4399 4400#endif 4401\end_layout 4402 4403\begin_layout Plain Layout 4404 4405} VkFFTConfiguration; 4406\end_layout 4407 4408\begin_layout Plain Layout 4409 4410 4411\backslash 4412end{minted} 4413\end_layout 4414 4415\begin_layout Plain Layout 4416 4417 4418\backslash 4419end{mdframed} 4420\end_layout 4421 4422\end_inset 4423 4424 4425\end_layout 4426 4427\begin_layout Subsubsection 4428Driver API parameters 4429\end_layout 4430 4431\begin_layout Standard 4432In order to work, VkFFT needs some structures that are provided by the driver. 4433 They are backend API-dependent. 4434 VkFFT will return corresponding VkFFTResult if one of these structures 4435 are not provided (value equal to zero) unless it is stated that there is 4436 a default value assigned. 4437 VkFFT will not modify provided values directly. 4438\end_layout 4439 4440\begin_layout Standard 4441Vulkan API will need the following information: 4442\end_layout 4443 4444\begin_layout Itemize 4445VkPhysicalDevice* physicalDevice - Pointer to Vulkan physical device, obtained 4446 from vkEnumeratePhysicalDevices() 4447\end_layout 4448 4449\begin_layout Itemize 4450VkDevice* device - Pointer to Vulkan device, created with vkCreateDevice() 4451\end_layout 4452 4453\begin_layout Itemize 4454VkQueue* queue - Pointer to Vulkan queue, created with vkGetDeviceQueue() 4455\end_layout 4456 4457\begin_layout Itemize 4458VkCommandPool* commandPool - Pointer to Vulkan command pool, created with 4459 vkCreateCommandPool() 4460\end_layout 4461 4462\begin_layout Itemize 4463VkFence* fence - Pointer to Vulkan fence, created with vkCreateFence() 4464\end_layout 4465 4466\begin_layout Itemize 4467uint64_t isCompilerInitialized - Specify if glslang compiler has been intialized 4468 before (0 - off, 1 - on). 4469 Default 0 - VkFFT will call glslang_initialize_process() at initializeVkFFT() 4470 and glslang_finialize_process() at deleteVkFFT() calls. 4471\end_layout 4472 4473\begin_layout Standard 4474CUDA API will need the following information: 4475\end_layout 4476 4477\begin_layout Itemize 4478CUdevice* device - Pointer to CUDA device, obtained from cuDeviceGet() 4479\end_layout 4480 4481\begin_layout Itemize 4482cudaStream_t* stream - Pointer to streams (can be more than 1), where to 4483 execute the kernels. 4484 Default 0. 4485 Streams must be associated with the provided device. 4486 There is no real benefit in having more than one, however. 4487 4488\end_layout 4489 4490\begin_layout Itemize 4491uint64_t num_streams - Try to submit CUDA kernels in multiple streams for 4492 asynchronous execution. 4493 Default 1 4494\end_layout 4495 4496\begin_layout Standard 4497HIP API will need the following information: 4498\end_layout 4499 4500\begin_layout Itemize 4501hipDevice_t* device - Pointer to HIP device, obtained from hipDeviceGet() 4502\end_layout 4503 4504\begin_layout Itemize 4505hipStream_t* stream - Pointer to streams (can be more than 1), where to 4506 execute the kernels. 4507 Default 0. 4508 Streams must be associated with the provided device. 4509 There is no real benefit in having more than one, however. 4510 4511\end_layout 4512 4513\begin_layout Itemize 4514uint64_t num_streams - Try to submit HIP kernels in multiple streams for 4515 asynchronous execution. 4516 Default 1 4517\end_layout 4518 4519\begin_layout Standard 4520OpenCL API will need the following information: 4521\end_layout 4522 4523\begin_layout Itemize 4524cl_device_id* device - Pointer to OpenCL device, obtained from clGetDeviceIDs() 4525\end_layout 4526 4527\begin_layout Itemize 4528cl_context* context - Pointer to OpenCL context, obtained from clCreateContext() 4529\end_layout 4530 4531\begin_layout Standard 4532Level Zero API will need the following information: 4533\end_layout 4534 4535\begin_layout Itemize 4536ze_device_handle_t* device - Pointer to Level Zero device, obtained from 4537 zeDeviceGet() 4538\end_layout 4539 4540\begin_layout Itemize 4541ze_context_handle_t* context - Pointer to Level Zero context, obtained from 4542 zeContextGet() 4543\end_layout 4544 4545\begin_layout Itemize 4546ze_command_queue_handle_t* commandQueue - Pointer to Level Zero command 4547 queuewith compute and copy capabilities, obtained from zeCommandQueueCreate() 4548\end_layout 4549 4550\begin_layout Itemize 4551uint32_t commandQueueID - ID of the commandQueue with compute and copy capabilit 4552ies 4553\end_layout 4554 4555\begin_layout Standard 4556Metal API will need the following information: 4557\end_layout 4558 4559\begin_layout Itemize 4560MTL::Device* device - Pointer to Metal device, obtained from MTL::CopyAllDevices 4561\end_layout 4562 4563\begin_layout Itemize 4564MTL::CommandQueue* queue - Pointer to Metal queue, obtained from device->newComm 4565andQueue() 4566\end_layout 4567 4568\begin_layout Subsubsection 4569Memory management parameters 4570\end_layout 4571 4572\begin_layout Standard 4573There are five buffer types user can provide to VkFFT: 4574\end_layout 4575 4576\begin_layout Itemize 4577the main buffer (buffer) 4578\end_layout 4579 4580\begin_layout Itemize 4581temporary buffer used for calculations requiring out-of-place writes (tempBuffer 4582) 4583\end_layout 4584 4585\begin_layout Itemize 4586separate input buffer, from which initial read is performed (inputBuffer) 4587\end_layout 4588 4589\begin_layout Itemize 4590separate output buffer, to which final write is performed (outputBuffer) 4591\end_layout 4592 4593\begin_layout Itemize 4594kernel buffer, used for calculation of convolutions and cross-correlations 4595 (kernel) 4596\end_layout 4597 4598\begin_layout Standard 4599These buffers must be passed by a pointer: in Vulkan API they are provided 4600 as VkBuffer*, in CUDA, HIP and Level Zero they are provided as void**, 4601 in OpenCL they are provided as cl_mem*, in Metal they are provided as MTL::Buff 4602er*. 4603 Even though the underlying structure (VkBuffer, void*, cl_mem, MTL::Buffer*) 4604 is not a memory but just a number that the driver can use to access correspondi 4605ng allocated memory on the GPU, passing them by a pointer allows for the 4606 user to query multiple GPU allocated buffers for VkFFT to use. 4607 Currently, it is only supported in Vulkan API - each of five buffer types 4608 can be made out of multiple separate memory allocations. 4609 For example, it is possible to combine multiple small unused at the point 4610 of FFT calculation buffers to form a tempBuffer. 4611 This option also allows Vulkan API to overcome the limit of 4GB for a single 4612 memory allocation - due to the fact that Vulkan can only use 32-bit numbers 4613 for addressing (other APIs support 64-bit addressing). 4614 4615\end_layout 4616 4617\begin_layout Standard 4618To use the buffers other than the main buffer, the user has to specify this 4619 in configuration at the application creation stage (set to zero by default, 4620 optional parameters): 4621\end_layout 4622 4623\begin_layout Itemize 4624uint64_t userTempBuffer - enables manual temporary buffer allocation (otherwise 4625 it is managed by VkFFT) 4626\end_layout 4627 4628\begin_layout Itemize 4629uint64_t isInputFormatted - specifies that initial read is performed from 4630 a separate buffer (inputBuffer) 4631\end_layout 4632 4633\begin_layout Itemize 4634uint64_t isOutputFormatted - specifies that final write is performed to 4635 a separate buffer (outputBuffer) 4636\end_layout 4637 4638\begin_layout Itemize 4639uint64_t performConvolution - enables convolution calculations, which requires 4640 precomputed kernel (kernel) 4641\end_layout 4642 4643\begin_layout Standard 4644Buffer sizes (bufferSize/tempBufferSize/inputBufferSize/outputBufferSize/kernelS 4645ize) are provided as a uint64_t pointer to an array, where each element 4646 corresponds to the buffer size of the buffer with the same placement in 4647 the buffer array. 4648 Buffer sizes have to be provided in Vulkan API (due to the stricter memory 4649 management model and multiple buffer support) and are optional in other 4650 backends (they can be useful to determine when to switch for 64-bit addressing). 4651\end_layout 4652 4653\begin_layout Standard 4654Buffer number (bufferNum/tempBufferNum/inputBufferNum/outputBufferNum/kernelNum) 4655 corresponds to how many elements are in the buffer and buffer size array. 4656 By default it is set to 1 and is not required to be provided by the user. 4657 Non-Vulkan backends currently don't support values other than default. 4658 Optional parameter. 4659\end_layout 4660 4661\begin_layout Standard 4662Buffer offset (bufferOffset/ tempBufferOffset/ inputBufferOffset/ outputBufferOf 4663fset/ kernelOffset) specifies offset from the start of the buffer sequence. 4664 It must be specified in bytes and must be divisible by the number type 4665 size used in the corresponding array (otherwise, the offset will be truncated). 4666 It is provided as a single uint64_t value. 4667 Can be provided at launch time, if specifyOffsetsAtLaunch parameter is 4668 enabled during initialization call. 4669 Optional parameters. 4670\end_layout 4671 4672\begin_layout Standard 4673User can provide custom dimension strides for buffer/inputBuffer/outputBuffer 4674 buffers - uint64_t[VKFFT_MAX_FFT_DIMENSIONS] array. 4675 Strides are specified in elements used in the array (not bytes). 4676 The first element corresponds to the stride between elements in the H direction 4677, the second corresponds to the D direction and the third to C (or N, if 4678 the number of elements in C is 1). 4679 The first axis is assumed to be non-strided. 4680 Must be at least of the same size as default strides, otherwise the behavior 4681 is undefined. 4682 Optional parameters. 4683\end_layout 4684 4685\begin_layout Standard 4686uint64_t inverseReturnToInputBuffer - an option that allows setting the 4687 final output buffer of the inverse transform to the same buffer, initial 4688 read of forward transform is performed from (inputBuffer, if isInputFormatted 4689 enabled). 4690 Optional parameter. 4691\end_layout 4692 4693\begin_layout Subsubsection 4694General FFT parameters 4695\end_layout 4696 4697\begin_layout Standard 4698This section describes part of the configuration structure responsible for 4699 FFT specification. 4700 4701\end_layout 4702 4703\begin_layout Standard 4704uint64_t FFTdim - dimensionality of the transform (up to VKFFT_MAX_FFT_DIMENSION 4705S). 4706 Required parameter. 4707\end_layout 4708 4709\begin_layout Standard 4710uint64_t size[VKFFT_MAX_FFT_DIMENSIONS] - WHD+ dimensions of the transform. 4711 Required parameter. 4712\end_layout 4713 4714\begin_layout Standard 4715uint64_t numberBatches - N parameter of the transform. 4716 By default, it is set to 1. 4717 Optional parameter. 4718\end_layout 4719 4720\begin_layout Standard 4721uint64_t performR2C - perform R2C/C2R decomposition. 4722 performDCT must be set to 0. 4723 Default 0, set to 1 to enable. 4724 Optional parameter. 4725\end_layout 4726 4727\begin_layout Standard 4728uint64_t performDCT - perform DCT transformation. 4729 performR2C must be set to 0. 4730 Default 0, set to X for DCT-X (currently supported X: 1, 2, 3 and 4). 4731 Optional parameter. 4732\end_layout 4733 4734\begin_layout Standard 4735uint64_t normalize - enabling this parameter will make the inverse transform 4736 divide the result by the FFT length. 4737 Default 0, set to 1 to enable. 4738 Optional parameter. 4739\end_layout 4740 4741\begin_layout Subsubsection 4742Precision parameters (and some things that can affect it): 4743\end_layout 4744 4745\begin_layout Standard 4746uint64_t doublePrecision - perform calculations in double precision. 4747 Default 0, set to 1 to enable. 4748 In Vulkan/OpenCL/Level Zero your device must support double precision functiona 4749lity. 4750 Metal API does not support double precision. 4751 Optional parameter. 4752\end_layout 4753 4754\begin_layout Standard 4755uint64_t doublePrecisionFloatMemory - perform calculations in double precision, 4756 but all intermediate and final storage in float. 4757 Input/Output/main buffers must have single-precision layout. 4758 doublePrecision must be set to 0. 4759 This option increases precision, but not that much to be recommended for 4760 actual use. 4761 Default 0, set to 1 to enable. 4762 In Vulkan/OpenCL/Level Zero your device must support double precision functiona 4763lity. 4764 Metal API does not support double precision. 4765 Experimental feature. 4766 Optional parameter. 4767\end_layout 4768 4769\begin_layout Standard 4770uint64_t halfPrecision - half-precision in VkFFT is implemented only as 4771 memory optimization. 4772 All calculations are done in single precision (similar way as doublePrecisionFl 4773oatMemory works for double and single precision). 4774 Default 0, set to 1 to enable. 4775 Works only in Vulkan API now, experimental feature (half precision seems 4776 to have bad precision for the first FFT element). 4777 Optional parameter. 4778\end_layout 4779 4780\begin_layout Standard 4781uint64_t halfPrecisionMemoryOnly - another way of performing half-precision 4782 in VkFFT, it will use half-precision only for initial and final memory 4783 storage in input/output buffer. 4784 Input/Output have to be allocated as half, buffer/tempBuffer have to be 4785 allocated as float (out-of-place mode only). 4786 Specify isInputFormatted and isOutputFormatted to use. 4787 So, for example, intermediate storage between axes FFTs in the multidimensional 4788 case will be done in single precision, as opposed to half-precision in 4789 the base halfPrecision case. 4790 halfPrecision must be set to 1. 4791 Default 0, set to 1 to enable. 4792 Works only in Vulkan API now, experimental feature. 4793 Optional parameter. 4794\end_layout 4795 4796\begin_layout Standard 4797int64_t useLUT - switches from calculating sines and cosines (via special 4798 function units in single precision or as a polynomial approximation in 4799 double precision) to using precomputed Look-Up Tables. 4800 -1 - off, 0 - auto, 1 - on. 4801 Default 0 in single precision, 1 in double precision. 4802 Set to 1 by default for Intel GPUs. 4803 If you have issues with single-precision accuracy on your GPU, try enabling 4804 this parameter (mobile GPUs may be affected). 4805 Optional parameter. 4806\end_layout 4807 4808\begin_layout Standard 4809int64_t useLUT_4step - switches from calculating sincos to using precomputed 4810 LUT tables for intermediate roots of 1 in the Four-step FFT algorithm. 4811 (-1 - off, 0 - auto, 1 - on). 4812 Configured by initialization routine. 4813 Optional parameter. 4814 4815\end_layout 4816 4817\begin_layout Subsubsection 4818Advanced parameters (code will work fine without using them) 4819\end_layout 4820 4821\begin_layout Standard 4822uint64_t omitDimension[VKFFT_MAX_FFT_DIMENSIONS] - parameter, that disables 4823 the FFT calculation for a particular axis (WHD). 4824 Note, that omitted dimensions still need to be included in FFTdim and size. 4825 This parameter simply works as a switch during execution - by not executing 4826 the particular dimension code. 4827 It doesn't work with the non-strided axis (W) of R2C/C2R mode. 4828 It doesn't work with convolution calculations. 4829 Default 0, set to 1 to enable. 4830 Optional parameter. 4831\end_layout 4832 4833\begin_layout Standard 4834uint64_t useUint64 - forces VkFFT to use 64-bit addressing in generated 4835 kernels. 4836 It is automatically enabled if the estimated buffer size is more than 4GB. 4837 Doesn't work with the Vulkan backend. 4838 By default, it is set to 0. 4839 Optional parameter. 4840\end_layout 4841 4842\begin_layout Standard 4843uint64_t coalescedMemory - number of bytes to coalesce per one transaction. 4844 For Nvidia and AMD is equal to 32, Intel is equal to 64. 4845 Going to work regardless, but if specified by the user correctly, the performan 4846ce will be higher. 4847 Default 64 for other GPUs. 4848 For half-precision should be multiplied by two. 4849 Should be a power of two. 4850 Optional parameter. 4851\end_layout 4852 4853\begin_layout Standard 4854uint64_t numSharedBanks - configure the number of shared banks on the target 4855 GPU. 4856 Default 32. 4857 Minor performance boost as it solves shared memory conflicts for the power 4858 of two systems. 4859 Optional parameter. 4860\end_layout 4861 4862\begin_layout Standard 4863uint64_t aimThreads - try to aim all kernels at this amount of threads. 4864 Gains/losses are not predictable, just a parameter to play with (it is 4865 not guaranteed that the target kernel will use that many threads). 4866 Default 128. 4867 Optional parameter. 4868\end_layout 4869 4870\begin_layout Standard 4871uint64_t useUint64 - forces 64-bit addressing in generated kernels. 4872 Should be enabled automatically for systems spanning more than 4GB, but 4873 it is better to have an option to force it as a failsafe. 4874 Doesn't work in Vulkan API (use multiple buffer binding). 4875 Default 0, set to 1 to enable. 4876 Optional parameter. 4877\end_layout 4878 4879\begin_layout Standard 4880uint64_t performBandwidthBoost - try to reduce coalsesced number by a factor 4881 of X to get bigger sequence in one upload for strided axes. 4882 Default: -1(inf) for DCT, 2 for Bluestein's algorithm (or -1 if DCT), 0 4883 otherwise 4884\end_layout 4885 4886\begin_layout Standard 4887uint64_t disableMergeSequencesR2C - disable the optimization that performs 4888 merging of two real sequences to reduce calculations (in R2C/C2R and R2R). 4889 If enabled, calculations will be performed by simply setting the imaginary 4890 component to zero. 4891 Default 0, set to 1 to enable. 4892 Optional parameter. 4893\end_layout 4894 4895\begin_layout Standard 4896uint64_t disableReorderFourStep - disables unshuffling of the Four Step 4897 FFT algorithm (last transposition of data). 4898 With this option enabled, tempBuffer will not be needed (unless it is required 4899 by Bluestein's multi-upload FFT algorithm). 4900 Default 0, set to 1 to enable. 4901 Automatically enabled for convolution calculations and Bluestein's algorithm. 4902 Optional parameter. 4903\end_layout 4904 4905\begin_layout Standard 4906uint64_t makeForwardPlanOnly - generate code only for forward FFT. 4907 Default 0, set to 1 to enable. 4908 Mutually exclusive with makeInversePlanOnly. 4909 Optional parameter. 4910\end_layout 4911 4912\begin_layout Standard 4913uint64_t makeInversePlanOnly - generate code only for inverse FFT. 4914 Default 0, set to 1 to enable. 4915 Mutually exclusive with makeForwardPlan. 4916 Optional parameter. 4917\end_layout 4918 4919\begin_layout Standard 4920uint64_t considerAllAxesStrided - will create a plan for a non-strided axis 4921 similar to a strided axis (used with disableReorderFourStep to get the 4922 same layout for Bluestein kernel). 4923 Default 0, set to 1 to enable. 4924 Optional parameter. 4925\end_layout 4926 4927\begin_layout Standard 4928uint64_t keepShaderCode - debugging option, will keep shader code and print 4929 all executed shaders during the plan execution in order. 4930 Default 0, set to 1 to enable. 4931 Optional parameter. 4932\end_layout 4933 4934\begin_layout Standard 4935uint64_t printMemoryLayout - debugging option, will print order of buffers 4936 used in kernels. 4937 Default 0, set to 1 to enable. 4938 Optional parameter. 4939 4940\end_layout 4941 4942\begin_layout Standard 4943uint64_t saveApplicationToString - will save all compiled binaries to VkFFTAppli 4944cation.saveApplicationString (will be allocated by VkFFT, deallocated with 4945 deleteVkFFT call). 4946 VkFFTApplication.applicationStringSize will contain size of binary in bytes. 4947 Currently disabled in Metal backend. 4948 Default 0, set to 1 to enable. 4949 Optional parameter. 4950\end_layout 4951 4952\begin_layout Standard 4953uint64_t loadApplicationFromString - will load all binaries from loadApplication 4954String instead of recompiling them (loadApplicationString must be allocated 4955 by user, must contain what saveApplicationToString call generated previously 4956 in VkFFTApplication.saveApplicationString). 4957 Currently disabled in Metal backend. 4958 Default 0, set to 1 to enable. 4959 Optional parameter. 4960 Mutually exclusive with saveApplicationToString 4961\end_layout 4962 4963\begin_layout Standard 4964void* loadApplicationString - memory binary array through which user can 4965 load VkFFT binaries, must be provided by user if loadApplicationFromString 4966 = 1. 4967 Use rb/wb flags to load/save. 4968\end_layout 4969 4970\begin_layout Standard 4971uint64_t disableSetLocale - disables all VkFFT attempts to set locale to 4972 C - user must ensure that VkFFT has C locale during the plan initialization. 4973 This option is needed for multithreading. 4974 Default 0. 4975\end_layout 4976 4977\begin_layout Standard 4978uint64_t groupedBatch[VKFFT_MAX_FFT_DIMENSIONS] - try to force this many 4979 FFTs to be perfromed by one threadblock for each dimension. 4980 Optional parameter. 4981 4982\end_layout 4983 4984\begin_layout Subsubsection 4985Rader control parameters 4986\end_layout 4987 4988\begin_layout Standard 4989uint64_t fixMinRaderPrimeMult - start direct multiplication Rader's algorithm 4990 for radix primes from this number. 4991 This means that VkFFT will inline custom Rader kernels if sequence is divisible 4992 by these primes. 4993 Default is 17, as VkFFT has kernels for 2-13. 4994 If you make it less than 13, VkFFT will switch from these kernels to Rader. 4995\end_layout 4996 4997\begin_layout Standard 4998uint64_t fixMaxRaderPrimeMult - switch from Mult Rader's algorithm for radix 4999 primes from this number. 5000 Current limitation for Rader is maxThreadNum/2+1, realistically you would 5001 want to switch somewhere on 30-100 range. 5002 Default is vendor-specific (currently ~40) 5003\end_layout 5004 5005\begin_layout Standard 5006uint64_t fixMinRaderPrimeFFT - start FFT convolution version of Rader for 5007 radix primes from this number. 5008 Better than direct multiplication version for almost all primes (except 5009 small ones, like 17-23 on some GPUs). 5010 Must be bigger or equal to fixMinRaderPrimeMult. 5011 Deafult 29 on AMD and 17 on other GPUs. 5012 5013\end_layout 5014 5015\begin_layout Standard 5016uint64_t fixMaxRaderPrimeFFT - switch to Bluestein's algorithm for radix 5017 primes from this number. 5018 Switch may happen earlier if prime can't fit in shared memory. 5019 Default is 16384, which is bigger than most current GPU's shared memory. 5020\end_layout 5021 5022\begin_layout Subsubsection 5023Bluestein control parameters 5024\end_layout 5025 5026\begin_layout Standard 5027If the sequence can not be decomposed as a multiplication of primes up to 5028 13, FFT is performed as a convolution. 5029 The sequence to pad to with the best performance is usually device-dependent. 5030 VkFFT uses parameters manually tuned for all sequences between 2 and 4096 5031 for both double and single precision on Nvidia A100 (Nvidia profile) and 5032 AMD MI250 (default profile). 5033 To control this process, VkFFT allows for the following parameters specificatio 5034n: 5035\end_layout 5036 5037\begin_layout Standard 5038uint64_t fixMaxRadixBluestein - controls the padding of sequences in Bluestein 5039 convolution. 5040 If specified, padded sequence will be made of up to fixMaxRadixBluestein 5041 primes. 5042 Default: 2 for CUDA and Vulkan/OpenCL/HIP up to 1048576 combined dimension 5043 FFT system, 7 for Vulkan/OpenCL/HIP past after. 5044 Min = 2, Max = 13. 5045\end_layout 5046 5047\begin_layout Standard 5048uint64_t forceBluesteinSequenceSize - force the sequence size to pad to 5049 in Bluestein's algorithm. 5050 Must be at least 2*N-1 and decomposable with primes 2-13. 5051\end_layout 5052 5053\begin_layout Standard 5054uint64_t useCustomBluesteinPaddingPattern - force the sequence sizes to 5055 pad to in Bluestein's algorithm, but on a range. 5056 This number specifies the number of elements in primeSizes and in paddedSizes 5057 arrays. 5058 primeSizes - array of non-decomposable as radix scheme sizes - 17, 23, 5059 31 etc. 5060 paddedSizes - array of lengths to pad to. 5061 paddedSizes[i] will be the padding size for all non-decomposable sequences 5062 from primeSizes[i] to primeSizes[i+1] (will use default scheme after last 5063 one) - 42, 60, 64 for primeSizes before and 37+ will use default scheme 5064 (for example). 5065 Default is vendor and API-based specified in autoCustomBluesteinPaddingPattern. 5066\end_layout 5067 5068\begin_layout Standard 5069uint64_t* primeSizes - described in useCustomBluesteinPaddingPattern 5070\end_layout 5071 5072\begin_layout Standard 5073uint64_t* paddedSizes - described in useCustomBluesteinPaddingPattern 5074\end_layout 5075 5076\begin_layout Subsubsection 5077Zero padding parameters 5078\end_layout 5079 5080\begin_layout Standard 5081uint64_t performZeropadding[VKFFT_MAX_FFT_DIMENSIONS] - do not read/write 5082 some data/perform computations if some part of the sequence is known to 5083 have zeros. 5084 Set separately for each axis (WHD). 5085 If enabled, all 1D sequences in this direction will be considered padded 5086 (independent of other zero-padded axes). 5087 Default 0, set to 1 to enable. 5088 Optional parameter. 5089 5090\end_layout 5091 5092\begin_layout Standard 5093uint64_t fft_zeropad_left[VKFFT_MAX_FFT_DIMENSIONS] - specify start boundary 5094 of zero block in the system for each axis. 5095 Default 0, set to the value between 0 and size[X]-1. 5096 Optional parameter. 5097\end_layout 5098 5099\begin_layout Standard 5100uint64_t fft_zeropad_right[VKFFT_MAX_FFT_DIMENSIONS] - specify end boundary 5101 of zero block in the system for each axis. 5102 Default 0, set to the value between fft_zeropad_left[X] and size[X]-1. 5103 Optional parameter. 5104\end_layout 5105 5106\begin_layout Standard 5107uint64_t frequencyZeroPadding - enables zero padding of the frequency domain, 5108 so the first read of inverse FFT will consider the parts of the system 5109 from fft_zeropad_left to fft_zeropad_right as zero. 5110 Default 0 - spatial zero padding, set to 1 to enable. 5111 Optional parameter. 5112 5113\end_layout 5114 5115\begin_layout Subsubsection 5116Convolution parameters 5117\end_layout 5118 5119\begin_layout Standard 5120uint64_t performConvolution - main parameter that enables convolutions in 5121 the application. 5122 If enabled, you must specify kernel buffer, number of kernel buffers and 5123 kernel sizes (in Vulkan API). 5124 Disables reordering of the Four Step FFT algorithm. 5125 Default 0, set to 1 to enable. 5126 Optional parameter. 5127 5128\end_layout 5129 5130\begin_layout Standard 5131uint64_t conjugateConvolution - default 0, set to 1 to enable enables conjugatio 5132n of the sequence FFT is currently done on, 2 to enable conjugation of the 5133 convolution kernel. 5134 Optional parameter. 5135 5136\end_layout 5137 5138\begin_layout Standard 5139uint64_t crossPowerSpectrumNormalization - normalize the FFT * kernel multiplica 5140tion in frequency domain. 5141 Default 0, set to 1 to enable. 5142 Optional parameter. 5143 5144\end_layout 5145 5146\begin_layout Standard 5147uint64_t coordinateFeatures - max coordinate (C), or dimension of the features 5148 vector. 5149 In matrix convolution - the size of the vector. 5150 The main purpose is to support Matrix-Vector convolutions. 5151 Use numberBatches parameter in tasks, not requiring two separate coordinate-lik 5152e enumerations of data. 5153 Default 1. 5154 Optional parameter. 5155\end_layout 5156 5157\begin_layout Standard 5158uint64_t matrixConvolution - set to 2 to perform 2x2, set to 3 to perform 5159 3x3 matrix-vector convolution. 5160 Matrix-vector convolution is a form of point-wise multiplication in the 5161 Fourier space, used by the convolution theorem, where multiplication takes 5162 the form of Matrix-vector multiplication. 5163 Overrides coordinateFeatures during execution. 5164 Default 0. 5165 Optional parameter. 5166 5167\end_layout 5168 5169\begin_layout Standard 5170uint64_t symmetricKernel - specify if kernel in 2x2 or 3x3 matrix convolution 5171 is symmetric. 5172 You need to store data as xx, xy, yy (upper-triangular) if enabled and 5173 as xx, xy, yx, yy (along rows then along columns, from left to right) if 5174 disabled. 5175 Default 0, set to 1 to enable. 5176 Optional parameter. 5177 5178\end_layout 5179 5180\begin_layout Standard 5181uint64_t numberKernels - specify how many kernels were initialized before 5182 performing one input/multiple output convolutions. 5183 Overwrites numberBatches (N). 5184 Only used in convolution step and the following inverse transforms. 5185 Default 1. 5186 Optional parameter. 5187 5188\end_layout 5189 5190\begin_layout Standard 5191uint64_t kernelConvolution - specify if this application is used to create 5192 kernel for convolution, so it has the same properties/memory layout. 5193 performConvolution has to be set to 0 for the kernel creation. 5194 Default 0, set to 1 to enable. 5195 Optional parameter, but it is a required parameter for kernel generation. 5196\end_layout 5197 5198\begin_layout Subsubsection 5199Register overutilization 5200\end_layout 5201 5202\begin_layout Standard 5203Only works in C2C mode, without convolution support. 5204 Enabled in Vulkan, OpenCL and Level Zero APIs only (it works in other APIs, 5205 but worse, does not work in Metal). 5206 Experimental feature. 5207\end_layout 5208 5209\begin_layout Standard 5210uint64_t registerBoost - specify if the register file size is bigger than 5211 shared memory and can be used to extend it X times (on Nvidia 256KB register 5212 file can be used instead of 32KB of shared memory, set this constant to 5213 4 to emulate 128KB of shared memory). 5214 Default 1 - no overutilization. 5215 In Vulkan, OpenCL and Level Zero it is set to 4 on Nvidia GPUs, to 2 if 5216 the driver shows 64KB or more of shared memory on AMD, to 2 if the driver 5217 shows less than 64KB of shared memory on AMD, to 1 if the driver shows 5218 64KB or more of shared memory on Intel, to 2 if the driver shows less than 5219 64KB of shared memory on Intel. 5220 Optional parameter. 5221\end_layout 5222 5223\begin_layout Standard 5224uint64_t registerBoostNonPow2 - specify if register overutilization should 5225 be used on non-power of 2 sequences. 5226 Default 0, set to 1 to enable. 5227 Optional parameter. 5228\end_layout 5229 5230\begin_layout Standard 5231uint64_t registerBoost4Step - specify if register file overutilization should 5232 be used in big sequences (>2^14), same definition as registerBoost. 5233 Default 1. 5234 Optional parameter. 5235\end_layout 5236 5237\begin_layout Subsubsection 5238Extra advanced parameters (filled automatically) 5239\end_layout 5240 5241\begin_layout Standard 5242uint64_t computeCapabilityMajor - CUDA/HIP compute capability of the device 5243\end_layout 5244 5245\begin_layout Standard 5246uint64_t computeCapabilityMinor - CUDA/HIP compute capability of the device 5247 5248\end_layout 5249 5250\begin_layout Standard 5251uint64_t maxComputeWorkGroupCount[3] - how many workgroups can be launched 5252 at one dispatch. 5253 Automatically derived from the driver, can be artificially lowered. 5254 Then VkFFT will perform a logical split and extension of the number of 5255 workgroups to cover the required range. 5256\end_layout 5257 5258\begin_layout Standard 5259uint64_t maxComputeWorkGroupSize[3] - max dimensions of the workgroup. 5260 Automatically derived from the driver. 5261 Can be modified if there are some issues with the driver (as there were 5262 with ROCm 4.0, when it returned 1024 for maxComputeWorkGroupSize and actually 5263 supported only up to 256 threads). 5264\end_layout 5265 5266\begin_layout Standard 5267uint64_t maxThreadsNum - max number of threads per block. 5268 Similar to maxComputeWorkGroupSize, but aggregated. 5269 Automatically derived from the driver. 5270\end_layout 5271 5272\begin_layout Standard 5273uint64_t sharedMemorySizeStatic - available for static allocation shared 5274 memory size, in bytes. 5275 Automatically derived from the driver. 5276 Can be controlled by the user, if desired. 5277\end_layout 5278 5279\begin_layout Standard 5280uint64_t sharedMemorySize - available for allocation shared memory size, 5281 in bytes. 5282 VkFFT uses dynamic shared memory in CUDA/HIP as it allows for bigger allocation 5283s. 5284 Automatically derived from the driver. 5285 Can be controlled by the user, if desired. 5286\end_layout 5287 5288\begin_layout Standard 5289uint64_t sharedMemorySizePow2 - the power of 2 which is less or equal to 5290 sharedMemorySize, in bytes. 5291 Automatically computed. 5292\end_layout 5293 5294\begin_layout Standard 5295uint64_t warpSize - number of threads per warp/wavefront. 5296 Automatically derived from the driver, but can be modified (can increase 5297 performance, though unpredictable as defaults have good values). 5298 Must be a power of two. 5299\end_layout 5300 5301\begin_layout Standard 5302uint64_t halfThreads - Intel GPU fix, tries to reduce the amount of dispatched 5303 threads in half to solve performance degradation in the Four Step FFT algorithm. 5304 Default 0 for other GPUs, try enabling it if performance degrades in the 5305 Four Step FFT algorithm for your GPU as well. 5306 5307\end_layout 5308 5309\begin_layout Standard 5310int64_t maxCodeLength - specify how big can the buffer used for code generation 5311 be (in char). 5312 Default 1000000 chars. 5313 5314\end_layout 5315 5316\begin_layout Standard 5317int64_t maxTempLength - specify how big can the buffer used for intermediate 5318 string sprintf's be (in char). 5319 Default 5000 chars. 5320 If code segfaults for some reason - try increasing this number. 5321\end_layout 5322 5323\begin_layout Standard 5324uint64_t autoCustomBluesteinPaddingPattern - default value for useCustomBluestei 5325nPaddingPattern 5326\end_layout 5327 5328\begin_layout Standard 5329uint64_t useRaderUintLUT - allocate additional LUT to store g_pow 5330\end_layout 5331 5332\begin_layout Standard 5333uint64_t vendorID - vendorID 0x10DE - NVIDIA, 0x8086 - Intel, 0x1002 - AMD, 5334 etc. 5335\end_layout 5336 5337\begin_layout Standard 5338\begin_inset Newpage newpage 5339\end_inset 5340 5341 5342\end_layout 5343 5344\begin_layout Section 5345VkFFT Benchmark/Precision Suite and utils_VkFFT helper routines 5346\end_layout 5347 5348\begin_layout Standard 5349The only licensed (MIT) part of the VkFFT repository is the VkFFT header 5350 file - core library. 5351 Other files are either external helper libraries (half, glslang, with their 5352 respective licenses) or unlicensed code that is intended for simple copy-pastin 5353g (benchmark_scripts, utils_VkFFT.h). 5354 It is the easiest way to understand how to use VkFFT by taking the provided 5355 scripts and tinker them to the particular task. 5356 The current version of the benchmark and precision verification suite has 5357 the following codes available: 5358\end_layout 5359 5360\begin_layout Itemize 5361user_benchmark_VkFFT - generalization of the main configuration parameters 5362 that can be used to launch simplest in-place transforms for the most important 5363 supported functionality 5364\end_layout 5365 5366\begin_layout Itemize 5367Sample 0 - FFT + iFFT C2C benchmark 1D batched in single precision 5368\end_layout 5369 5370\begin_layout Itemize 5371Sample 1 - FFT + iFFT C2C benchmark 1D batched in double precision 5372\end_layout 5373 5374\begin_layout Itemize 5375Sample 2 - FFT + iFFT C2C benchmark 1D batched in half precision 5376\end_layout 5377 5378\begin_layout Itemize 5379Sample 3 - FFT + iFFT C2C multidimensional benchmark in single precision 5380\end_layout 5381 5382\begin_layout Itemize 5383Sample 4 - FFT + iFFT C2C multidimensional benchmark in single precision, 5384 native zeropadding 5385\end_layout 5386 5387\begin_layout Itemize 5388Sample 5 - FFT + iFFT C2C benchmark 1D batched in single precision, no reshuffli 5389ng 5390\end_layout 5391 5392\begin_layout Itemize 5393Sample 6 - FFT + iFFT R2C / C2R benchmark, in-place. 5394\end_layout 5395 5396\begin_layout Itemize 5397Sample 7 - FFT + iFFT C2C Bluestein benchmark in single precision 5398\end_layout 5399 5400\begin_layout Itemize 5401Sample 8 - FFT + iFFT C2C Bluestein benchmark in double precision 5402\end_layout 5403 5404\begin_layout Itemize 5405Sample 10 - multiple buffers (4 by default) split version of benchmark 0 5406\end_layout 5407 5408\begin_layout Itemize 5409Sample 11 - VkFFT / xFFT / FFTW C2C precision test in single precision (xFFT 5410 can be cuFFT or rocFFT) 5411\end_layout 5412 5413\begin_layout Itemize 5414Sample 12 - VkFFT / xFFT / FFTW C2C precision test in double precision (xFFT 5415 can be cuFFT or rocFFT) 5416\end_layout 5417 5418\begin_layout Itemize 5419Sample 13 - VkFFT / cuFFT / FFTW C2C precision test in half precision 5420\end_layout 5421 5422\begin_layout Itemize 5423Sample 14 - VkFFT / FFTW C2C radix 3 / 5 / 7 / 11 / 13 / Bluestein precision 5424 test in single precision 5425\end_layout 5426 5427\begin_layout Itemize 5428Sample 15 - VkFFT / xFFT / FFTW R2C+C2R precision test in single precision, 5429 out-of-place. 5430 (xFFT can be cuFFT or rocFFT) 5431\end_layout 5432 5433\begin_layout Itemize 5434Sample 16 - VkFFT / FFTW R2R DCT-I, II, III and IV precision test in single 5435 precision 5436\end_layout 5437 5438\begin_layout Itemize 5439Sample 17 - VkFFT / FFTW R2R DCT-I, II, III and IV precision test in double 5440 precision 5441\end_layout 5442 5443\begin_layout Itemize 5444Sample 18 - VkFFT / FFTW C2C radix 3 / 5 / 7 / 11 / 13 / Bluestein precision 5445 test in double precision 5446\end_layout 5447 5448\begin_layout Itemize 5449Sample 50 - convolution example with identity kernel 5450\end_layout 5451 5452\begin_layout Itemize 5453Sample 51 - zero padding convolution example with identity kernel 5454\end_layout 5455 5456\begin_layout Itemize 5457Sample 52 - batched convolution example with identity kernel 5458\end_layout 5459 5460\begin_layout Itemize 5461Sample 100 - VkFFT FFT + iFFT R2R DCT multidimensional benchmark in single 5462 precision 5463\end_layout 5464 5465\begin_layout Itemize 5466Sample 101 - VkFFT FFT + iFFT R2R DCT multidimensional benchmark in double 5467 precision 5468\end_layout 5469 5470\begin_layout Itemize 5471Sample 1000 - FFT + iFFT C2C benchmark 1D batched in single precision: all 5472 supported systems from 2 to 4096 5473\end_layout 5474 5475\begin_layout Itemize 5476Sample 1001 - FFT + iFFT C2C benchmark 1D batched in single precision: all 5477 supported systems from 2 to 4096 5478\end_layout 5479 5480\begin_layout Itemize 5481Sample 1003 - FFT + iFFT C2C benchmark 1D batched in single precision: all 5482 supported systems from 2 to 4096 5483\end_layout 5484 5485\begin_layout Subsection 5486utils_VkFFT helper routines 5487\end_layout 5488 5489\begin_layout Standard 5490Launching even the simplest Vulkan application can be a non-trivial task. 5491 To help with this, utils_VkFFT contains the routines that can help to create 5492 the simplest Vulkan application, allocate memory, record command buffers 5493 and launch them. 5494 Code has some comments explaining what is going on at each step. 5495 It also has some useful struct defines (like vkGPU) that keep the most 5496 important handles used in Vulkan Compute. 5497 This section may be expanded in the future to the proper step-by-step guide 5498 on Vulkan Compute simple application creation. 5499 I also encourage to check https://github.com/DTolm/VulkanComputeSamples-Transpos 5500ition repository for another example of a compute algorithm (matrix transpositio 5501n) implemented with Vulkan API. 5502\end_layout 5503 5504\begin_layout Standard 5505utils_VkFFT also has a routine that prints the list of available devices. 5506\end_layout 5507 5508\begin_layout Standard 5509vkGPU struct has the following definition: 5510\end_layout 5511 5512\begin_layout Standard 5513\begin_inset ERT 5514status open 5515 5516\begin_layout Plain Layout 5517 5518 5519\backslash 5520begin{mdframed}[backgroundcolor=bg] 5521\end_layout 5522 5523\begin_layout Plain Layout 5524 5525 5526\backslash 5527begin{minted}[tabsize=4,obeytabs,breaklines]{C} 5528\end_layout 5529 5530\begin_layout Plain Layout 5531 5532typedef struct { 5533\end_layout 5534 5535\begin_layout Plain Layout 5536 5537#if(VKFFT_BACKEND==0) //Vulkan API 5538\end_layout 5539 5540\begin_layout Plain Layout 5541 5542VkInstance instance; //a connection between the application and the Vulkan 5543 library 5544\end_layout 5545 5546\begin_layout Plain Layout 5547 5548VkPhysicalDevice physicalDevice; //a handle for the graphics card used in 5549 the application 5550\end_layout 5551 5552\begin_layout Plain Layout 5553 5554VkPhysicalDeviceProperties physicalDeviceProperties; //bastic device properties 5555\end_layout 5556 5557\begin_layout Plain Layout 5558 5559VkPhysicalDeviceMemoryProperties physicalDeviceMemoryProperties; //basic 5560 memory properties of the device 5561\end_layout 5562 5563\begin_layout Plain Layout 5564 5565VkDevice device; //a logical device, interacting with physical device 5566\end_layout 5567 5568\begin_layout Plain Layout 5569 5570VkDebugUtilsMessengerEXT debugMessenger; //extension for debugging 5571\end_layout 5572 5573\begin_layout Plain Layout 5574 5575uint64_t queueFamilyIndex; //if multiple queues are available, specify the 5576 used one 5577\end_layout 5578 5579\begin_layout Plain Layout 5580 5581VkQueue queue; //a place, where all operations are submitted 5582\end_layout 5583 5584\begin_layout Plain Layout 5585 5586VkCommandPool commandPool; //an opaque objects that command buffer memory 5587 is allocated from 5588\end_layout 5589 5590\begin_layout Plain Layout 5591 5592VkFence fence; //a vkGPU->fence used to synchronize dispatches 5593\end_layout 5594 5595\begin_layout Plain Layout 5596 5597std::vector<const char*> enabledDeviceExtensions; 5598\end_layout 5599 5600\begin_layout Plain Layout 5601 5602uint64_t enableValidationLayers; 5603\end_layout 5604 5605\begin_layout Plain Layout 5606 5607#elif(VKFFT_BACKEND==1) //CUDA API 5608\end_layout 5609 5610\begin_layout Plain Layout 5611 5612CUdevice device; 5613\end_layout 5614 5615\begin_layout Plain Layout 5616 5617CUcontext context; 5618\end_layout 5619 5620\begin_layout Plain Layout 5621 5622#elif(VKFFT_BACKEND==2) //HIP API 5623\end_layout 5624 5625\begin_layout Plain Layout 5626 5627hipDevice_t device; 5628\end_layout 5629 5630\begin_layout Plain Layout 5631 5632hipCtx_t context; 5633\end_layout 5634 5635\begin_layout Plain Layout 5636 5637#elif(VKFFT_BACKEND==3) //OpenCL API 5638\end_layout 5639 5640\begin_layout Plain Layout 5641 5642cl_platform_id platform; 5643\end_layout 5644 5645\begin_layout Plain Layout 5646 5647cl_device_id device; 5648\end_layout 5649 5650\begin_layout Plain Layout 5651 5652cl_context context; 5653\end_layout 5654 5655\begin_layout Plain Layout 5656 5657cl_command_queue commandQueue; 5658\end_layout 5659 5660\begin_layout Plain Layout 5661 5662#elif(VKFFT_BACKEND==4) //Level Zero API 5663\end_layout 5664 5665\begin_layout Plain Layout 5666 5667ze_driver_handle_t driver; 5668\end_layout 5669 5670\begin_layout Plain Layout 5671 5672ze_device_handle_t device; 5673\end_layout 5674 5675\begin_layout Plain Layout 5676 5677ze_context_handle_t context; 5678\end_layout 5679 5680\begin_layout Plain Layout 5681 5682ze_command_queue_handle_t commandQueue; 5683\end_layout 5684 5685\begin_layout Plain Layout 5686 5687uint32_t commandQueueID; 5688\end_layout 5689 5690\begin_layout Plain Layout 5691 5692#elif(VKFFT_BACKEND==5) //Metal API 5693\end_layout 5694 5695\begin_layout Plain Layout 5696 5697MTL::Device* device; 5698\end_layout 5699 5700\begin_layout Plain Layout 5701 5702MTL::CommandQueue* queue; 5703\end_layout 5704 5705\begin_layout Plain Layout 5706 5707#endif 5708\end_layout 5709 5710\begin_layout Plain Layout 5711 5712uint64_t device_id; //an id of a device, reported by devices_list call 5713\end_layout 5714 5715\begin_layout Plain Layout 5716 5717} VkGPU; 5718\end_layout 5719 5720\begin_layout Plain Layout 5721 5722 5723\backslash 5724end{minted} 5725\end_layout 5726 5727\begin_layout Plain Layout 5728 5729 5730\backslash 5731end{mdframed} 5732\end_layout 5733 5734\end_inset 5735 5736 5737\begin_inset Newpage newpage 5738\end_inset 5739 5740 5741\end_layout 5742 5743\begin_layout Section 5744VkFFT Code Examples 5745\end_layout 5746 5747\begin_layout Standard 5748This section will provide some simple pseudocode for VkFFT usage, which 5749 will once again outline important steps required to launch FFT with VkFFT. 5750 More information (and fully working code) can be found in this folder of 5751 the VkFFT repository: 5752\end_layout 5753 5754\begin_layout Standard 5755/benchmark_samples/vkFFT_scripts/src/ 5756\end_layout 5757 5758\begin_layout Subsection 5759Driver initializations 5760\end_layout 5761 5762\begin_layout Standard 5763Before launching VkFFT, do not forget to do all necessary driver initializations. 5764 The following code specifies them for all the supported backends, though 5765 the final implementation may be different depending on the particular user's 5766 configuration. 5767\end_layout 5768 5769\begin_layout Standard 5770\begin_inset ERT 5771status open 5772 5773\begin_layout Plain Layout 5774 5775 5776\backslash 5777begin{mdframed}[backgroundcolor=bg] 5778\end_layout 5779 5780\begin_layout Plain Layout 5781 5782 5783\backslash 5784begin{minted}[tabsize=4,obeytabs,breaklines]{C} 5785\end_layout 5786 5787\begin_layout Plain Layout 5788 5789#if(VKFFT_BACKEND==0) //Vulkan API 5790\end_layout 5791 5792\begin_layout Plain Layout 5793 5794VkResult res = VK_SUCCESS; 5795\end_layout 5796 5797\begin_layout Plain Layout 5798 5799//create instance - a connection between the application and the Vulkan 5800 library 5801\end_layout 5802 5803\begin_layout Plain Layout 5804 5805res = createInstance(vkGPU, sample_id); 5806\end_layout 5807 5808\begin_layout Plain Layout 5809 5810if (res != 0) { 5811\end_layout 5812 5813\begin_layout Plain Layout 5814 5815 //printf("Instance creation failed, error code: %" PRIu64 " 5816\backslash 5817n", res); 5818\end_layout 5819 5820\begin_layout Plain Layout 5821 5822 return VKFFT_ERROR_FAILED_TO_CREATE_INSTANCE; 5823\end_layout 5824 5825\begin_layout Plain Layout 5826 5827} 5828\end_layout 5829 5830\begin_layout Plain Layout 5831 5832//set up the debugging messenger 5833\end_layout 5834 5835\begin_layout Plain Layout 5836 5837res = setupDebugMessenger(vkGPU); 5838\end_layout 5839 5840\begin_layout Plain Layout 5841 5842if (res != 0) { 5843\end_layout 5844 5845\begin_layout Plain Layout 5846 5847//printf("Debug messenger creation failed, error code: %" PRIu64 " 5848\backslash 5849n", res); 5850\end_layout 5851 5852\begin_layout Plain Layout 5853 5854 return VKFFT_ERROR_FAILED_TO_SETUP_DEBUG_MESSENGER; 5855\end_layout 5856 5857\begin_layout Plain Layout 5858 5859} 5860\end_layout 5861 5862\begin_layout Plain Layout 5863 5864//check if there are GPUs that support Vulkan and select one 5865\end_layout 5866 5867\begin_layout Plain Layout 5868 5869res = findPhysicalDevice(vkGPU); 5870\end_layout 5871 5872\begin_layout Plain Layout 5873 5874if (res != 0) { 5875\end_layout 5876 5877\begin_layout Plain Layout 5878 5879//printf("Physical device not found, error code: %" PRIu64 " 5880\backslash 5881n", res); 5882\end_layout 5883 5884\begin_layout Plain Layout 5885 5886 return VKFFT_ERROR_FAILED_TO_FIND_PHYSICAL_DEVICE; 5887\end_layout 5888 5889\begin_layout Plain Layout 5890 5891} 5892\end_layout 5893 5894\begin_layout Plain Layout 5895 5896//create logical device representation 5897\end_layout 5898 5899\begin_layout Plain Layout 5900 5901res = createDevice(vkGPU, sample_id); 5902\end_layout 5903 5904\begin_layout Plain Layout 5905 5906if (res != 0) { 5907\end_layout 5908 5909\begin_layout Plain Layout 5910 5911//printf("Device creation failed, error code: %" PRIu64 " 5912\backslash 5913n", res); 5914\end_layout 5915 5916\begin_layout Plain Layout 5917 5918 return VKFFT_ERROR_FAILED_TO_CREATE_DEVICE; 5919\end_layout 5920 5921\begin_layout Plain Layout 5922 5923} 5924\end_layout 5925 5926\begin_layout Plain Layout 5927 5928//create fence for synchronization 5929\end_layout 5930 5931\begin_layout Plain Layout 5932 5933res = createFence(vkGPU); 5934\end_layout 5935 5936\begin_layout Plain Layout 5937 5938if (res != 0) { 5939\end_layout 5940 5941\begin_layout Plain Layout 5942 5943//printf("Fence creation failed, error code: %" PRIu64 " 5944\backslash 5945n", res); 5946\end_layout 5947 5948\begin_layout Plain Layout 5949 5950 return VKFFT_ERROR_FAILED_TO_CREATE_FENCE; 5951\end_layout 5952 5953\begin_layout Plain Layout 5954 5955} 5956\end_layout 5957 5958\begin_layout Plain Layout 5959 5960//create a place, command buffer memory is allocated from 5961\end_layout 5962 5963\begin_layout Plain Layout 5964 5965res = createCommandPool(vkGPU); 5966\end_layout 5967 5968\begin_layout Plain Layout 5969 5970if (res != 0) { 5971\end_layout 5972 5973\begin_layout Plain Layout 5974 5975 //printf("Fence creation failed, error code: %" PRIu64 " 5976\backslash 5977n", res); 5978\end_layout 5979 5980\begin_layout Plain Layout 5981 5982 return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_POOL; 5983\end_layout 5984 5985\begin_layout Plain Layout 5986 5987} 5988\end_layout 5989 5990\begin_layout Plain Layout 5991 5992vkGetPhysicalDeviceProperties(vkGPU->physicalDevice, &vkGPU->physicalDevicePrope 5993rties); 5994\end_layout 5995 5996\begin_layout Plain Layout 5997 5998vkGetPhysicalDeviceMemoryProperties(vkGPU->physicalDevice, &vkGPU->physicalDevic 5999eMemoryProperties); 6000\end_layout 6001 6002\begin_layout Plain Layout 6003 6004glslang_initialize_process(); 6005\end_layout 6006 6007\begin_layout Plain Layout 6008 6009//compiler can be initialized before VkFFT 6010\end_layout 6011 6012\begin_layout Plain Layout 6013 6014\end_layout 6015 6016\begin_layout Plain Layout 6017 6018#elif(VKFFT_BACKEND==1) //CUDA API 6019\end_layout 6020 6021\begin_layout Plain Layout 6022 6023CUresult res = CUDA_SUCCESS; 6024\end_layout 6025 6026\begin_layout Plain Layout 6027 6028cudaError_t res2 = cudaSuccess; 6029\end_layout 6030 6031\begin_layout Plain Layout 6032 6033res = cuInit(0); 6034\end_layout 6035 6036\begin_layout Plain Layout 6037 6038if (res != CUDA_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE; 6039\end_layout 6040 6041\begin_layout Plain Layout 6042 6043res2 = cudaSetDevice((int)vkGPU->device_id); 6044\end_layout 6045 6046\begin_layout Plain Layout 6047 6048if (res2 != cudaSuccess) return VKFFT_ERROR_FAILED_TO_SET_DEVICE_ID; 6049\end_layout 6050 6051\begin_layout Plain Layout 6052 6053res = cuDeviceGet(&vkGPU->device, (int)vkGPU->device_id); 6054\end_layout 6055 6056\begin_layout Plain Layout 6057 6058if (res != CUDA_SUCCESS) return VKFFT_ERROR_FAILED_TO_GET_DEVICE; 6059\end_layout 6060 6061\begin_layout Plain Layout 6062 6063res = cuCtxCreate(&vkGPU->context, 0, (int)vkGPU->device); 6064\end_layout 6065 6066\begin_layout Plain Layout 6067 6068if (res != CUDA_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_CONTEXT; 6069\end_layout 6070 6071\begin_layout Plain Layout 6072 6073#elif(VKFFT_BACKEND==2) //HIP API 6074\end_layout 6075 6076\begin_layout Plain Layout 6077 6078hipError_t res = hipSuccess; 6079\end_layout 6080 6081\begin_layout Plain Layout 6082 6083res = hipInit(0); 6084\end_layout 6085 6086\begin_layout Plain Layout 6087 6088if (res != hipSuccess) return VKFFT_ERROR_FAILED_TO_INITIALIZE; 6089\end_layout 6090 6091\begin_layout Plain Layout 6092 6093res = hipSetDevice((int)vkGPU->device_id); 6094\end_layout 6095 6096\begin_layout Plain Layout 6097 6098if (res != hipSuccess) return VKFFT_ERROR_FAILED_TO_SET_DEVICE_ID; 6099\end_layout 6100 6101\begin_layout Plain Layout 6102 6103res = hipDeviceGet(&vkGPU->device, (int)vkGPU->device_id); 6104\end_layout 6105 6106\begin_layout Plain Layout 6107 6108if (res != hipSuccess) return VKFFT_ERROR_FAILED_TO_GET_DEVICE; 6109\end_layout 6110 6111\begin_layout Plain Layout 6112 6113res = hipCtxCreate(&vkGPU->context, 0, (int)vkGPU->device); 6114\end_layout 6115 6116\begin_layout Plain Layout 6117 6118if (res != hipSuccess) return VKFFT_ERROR_FAILED_TO_CREATE_CONTEXT; 6119\end_layout 6120 6121\begin_layout Plain Layout 6122 6123#elif(VKFFT_BACKEND==3) //OpenCL API 6124\end_layout 6125 6126\begin_layout Plain Layout 6127 6128cl_int res = CL_SUCCESS; 6129\end_layout 6130 6131\begin_layout Plain Layout 6132 6133cl_uint numPlatforms; 6134\end_layout 6135 6136\begin_layout Plain Layout 6137 6138res = clGetPlatformIDs(0, 0, &numPlatforms); 6139\end_layout 6140 6141\begin_layout Plain Layout 6142 6143if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE; 6144\end_layout 6145 6146\begin_layout Plain Layout 6147 6148cl_platform_id* platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id) 6149 * numPlatforms); 6150\end_layout 6151 6152\begin_layout Plain Layout 6153 6154if (!platforms) return VKFFT_ERROR_MALLOC_FAILED; 6155\end_layout 6156 6157\begin_layout Plain Layout 6158 6159res = clGetPlatformIDs(numPlatforms, platforms, 0); 6160\end_layout 6161 6162\begin_layout Plain Layout 6163 6164if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE; 6165\end_layout 6166 6167\begin_layout Plain Layout 6168 6169uint64_t k = 0; 6170\end_layout 6171 6172\begin_layout Plain Layout 6173 6174for (uint64_t j = 0; j < numPlatforms; j++) { 6175\end_layout 6176 6177\begin_layout Plain Layout 6178 6179 cl_uint numDevices; 6180\end_layout 6181 6182\begin_layout Plain Layout 6183 6184 res = clGetDeviceIDs(platforms[j], CL_DEVICE_TYPE_ALL, 0, 0, &numDevices); 6185\end_layout 6186 6187\begin_layout Plain Layout 6188 6189 cl_device_id* deviceList = (cl_device_id*)malloc(sizeof(cl_device_id) * 6190 numDevices); 6191\end_layout 6192 6193\begin_layout Plain Layout 6194 6195 if (!deviceList) return VKFFT_ERROR_MALLOC_FAILED; 6196\end_layout 6197 6198\begin_layout Plain Layout 6199 6200 res = clGetDeviceIDs(platforms[j], CL_DEVICE_TYPE_ALL, numDevices, deviceList, 6201 0); 6202\end_layout 6203 6204\begin_layout Plain Layout 6205 6206 if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_GET_DEVICE; 6207\end_layout 6208 6209\begin_layout Plain Layout 6210 6211 for (uint64_t i = 0; i < numDevices; i++) { 6212\end_layout 6213 6214\begin_layout Plain Layout 6215 6216 if (k == vkGPU->device_id) { 6217\end_layout 6218 6219\begin_layout Plain Layout 6220 6221 vkGPU->platform = platforms[j]; 6222\end_layout 6223 6224\begin_layout Plain Layout 6225 6226 vkGPU->device = deviceList[i]; 6227\end_layout 6228 6229\begin_layout Plain Layout 6230 6231 vkGPU->context = clCreateContext(NULL, 1, &vkGPU->device, NULL, NULL, 6232 &res); 6233\end_layout 6234 6235\begin_layout Plain Layout 6236 6237 if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_CONTEXT; 6238\end_layout 6239 6240\begin_layout Plain Layout 6241 6242 cl_command_queue commandQueue = clCreateCommandQueue(vkGPU->context, 6243 vkGPU->device, 0, &res); 6244\end_layout 6245 6246\begin_layout Plain Layout 6247 6248 if (res != CL_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QUEUE; 6249\end_layout 6250 6251\begin_layout Plain Layout 6252 6253 vkGPU->commandQueue = commandQueue; 6254\end_layout 6255 6256\begin_layout Plain Layout 6257 6258 i=numDevices; 6259\end_layout 6260 6261\begin_layout Plain Layout 6262 6263 j=numPlatforms; 6264\end_layout 6265 6266\begin_layout Plain Layout 6267 6268 } 6269\end_layout 6270 6271\begin_layout Plain Layout 6272 6273 else { 6274\end_layout 6275 6276\begin_layout Plain Layout 6277 6278 k++; 6279\end_layout 6280 6281\begin_layout Plain Layout 6282 6283 } 6284\end_layout 6285 6286\begin_layout Plain Layout 6287 6288 } 6289\end_layout 6290 6291\begin_layout Plain Layout 6292 6293 free(deviceList); 6294\end_layout 6295 6296\begin_layout Plain Layout 6297 6298} 6299\end_layout 6300 6301\begin_layout Plain Layout 6302 6303free(platforms); 6304\end_layout 6305 6306\begin_layout Plain Layout 6307 6308#elif(VKFFT_BACKEND==4) 6309\end_layout 6310 6311\begin_layout Plain Layout 6312 6313 ze_result_t res = ZE_RESULT_SUCCESS; 6314\end_layout 6315 6316\begin_layout Plain Layout 6317 6318 res = zeInit(0); 6319\end_layout 6320 6321\begin_layout Plain Layout 6322 6323 if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE; 6324\end_layout 6325 6326\begin_layout Plain Layout 6327 6328 uint32_t numDrivers = 0; 6329\end_layout 6330 6331\begin_layout Plain Layout 6332 6333 res = zeDriverGet(&numDrivers, 0); 6334\end_layout 6335 6336\begin_layout Plain Layout 6337 6338 if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE; 6339\end_layout 6340 6341\begin_layout Plain Layout 6342 6343 ze_driver_handle_t* drivers = (ze_driver_handle_t*)malloc(numDrivers * 6344 sizeof(ze_driver_handle_t)); 6345\end_layout 6346 6347\begin_layout Plain Layout 6348 6349 if (!drivers) return VKFFT_ERROR_MALLOC_FAILED; 6350\end_layout 6351 6352\begin_layout Plain Layout 6353 6354 res = zeDriverGet(&numDrivers, drivers); 6355\end_layout 6356 6357\begin_layout Plain Layout 6358 6359 if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_INITIALIZE; 6360\end_layout 6361 6362\begin_layout Plain Layout 6363 6364 uint64_t k = 0; 6365\end_layout 6366 6367\begin_layout Plain Layout 6368 6369 for (uint64_t j = 0; j < numDrivers; j++) { 6370\end_layout 6371 6372\begin_layout Plain Layout 6373 6374 uint32_t numDevices = 0; 6375\end_layout 6376 6377\begin_layout Plain Layout 6378 6379 res = zeDeviceGet(drivers[j], &numDevices, nullptr); 6380\end_layout 6381 6382\begin_layout Plain Layout 6383 6384 if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_GET_DEVICE; 6385\end_layout 6386 6387\begin_layout Plain Layout 6388 6389 ze_device_handle_t* deviceList = (ze_device_handle_t*)malloc(numDevices 6390 * sizeof(ze_device_handle_t)); 6391\end_layout 6392 6393\begin_layout Plain Layout 6394 6395 if (!deviceList) return VKFFT_ERROR_MALLOC_FAILED; 6396\end_layout 6397 6398\begin_layout Plain Layout 6399 6400 res = zeDeviceGet(drivers[j], &numDevices, deviceList); 6401\end_layout 6402 6403\begin_layout Plain Layout 6404 6405 if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_GET_DEVICE; 6406\end_layout 6407 6408\begin_layout Plain Layout 6409 6410 for (uint64_t i = 0; i < numDevices; i++) { 6411\end_layout 6412 6413\begin_layout Plain Layout 6414 6415 if (k == vkGPU->device_id) { 6416\end_layout 6417 6418\begin_layout Plain Layout 6419 6420 vkGPU->driver = drivers[j]; 6421\end_layout 6422 6423\begin_layout Plain Layout 6424 6425 vkGPU->device = deviceList[i]; 6426\end_layout 6427 6428\begin_layout Plain Layout 6429 6430 ze_context_desc_t contextDescription = {}; 6431\end_layout 6432 6433\begin_layout Plain Layout 6434 6435 contextDescription.stype = ZE_STRUCTURE_TYPE_CONTEXT_DESC; 6436\end_layout 6437 6438\begin_layout Plain Layout 6439 6440 res = zeContextCreate(vkGPU->driver, &contextDescription, &vkGPU->context); 6441\end_layout 6442 6443\begin_layout Plain Layout 6444 6445 if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_CONTEXT; 6446\end_layout 6447 6448\begin_layout Plain Layout 6449 6450\end_layout 6451 6452\begin_layout Plain Layout 6453 6454 uint32_t queueGroupCount = 0; 6455\end_layout 6456 6457\begin_layout Plain Layout 6458 6459 res = zeDeviceGetCommandQueueGroupProperties(vkGPU->device, &queueGroupCount 6460, 0); 6461\end_layout 6462 6463\begin_layout Plain Layout 6464 6465 if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QU 6466EUE; 6467\end_layout 6468 6469\begin_layout Plain Layout 6470 6471\end_layout 6472 6473\begin_layout Plain Layout 6474 6475 ze_command_queue_group_properties_t* cmdqueueGroupProperties = (ze_command_q 6476ueue_group_properties_t*) malloc(queueGroupCount * sizeof(ze_command_queue_group 6477_properties_t)); 6478\end_layout 6479 6480\begin_layout Plain Layout 6481 6482 if (!cmdqueueGroupProperties) return VKFFT_ERROR_MALLOC_FAILED; 6483\end_layout 6484 6485\begin_layout Plain Layout 6486 6487 res = zeDeviceGetCommandQueueGroupProperties(vkGPU->device, &queueGroupCount 6488, cmdqueueGroupProperties); 6489\end_layout 6490 6491\begin_layout Plain Layout 6492 6493 if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QU 6494EUE; 6495\end_layout 6496 6497\begin_layout Plain Layout 6498 6499\end_layout 6500 6501\begin_layout Plain Layout 6502 6503 uint32_t commandQueueID = -1; 6504\end_layout 6505 6506\begin_layout Plain Layout 6507 6508 for (uint32_t i = 0; i < queueGroupCount; ++i) { 6509\end_layout 6510 6511\begin_layout Plain Layout 6512 6513 if ((cmdqueueGroupProperties[i].flags && ZE_COMMAND_QUEUE_GROUP_PROPERTY_FLA 6514G_COMPUTE) && (cmdqueueGroupProperties[i].flags && ZE_COMMAND_QUEUE_GROUP_PROPERT 6515Y_FLAG_COPY)) { 6516\end_layout 6517 6518\begin_layout Plain Layout 6519 6520 commandQueueID = i; 6521\end_layout 6522 6523\begin_layout Plain Layout 6524 6525 break; 6526\end_layout 6527 6528\begin_layout Plain Layout 6529 6530 } 6531\end_layout 6532 6533\begin_layout Plain Layout 6534 6535 } 6536\end_layout 6537 6538\begin_layout Plain Layout 6539 6540 if (commandQueueID == -1) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QUEUE; 6541\end_layout 6542 6543\begin_layout Plain Layout 6544 6545 vkGPU->commandQueueID = commandQueueID; 6546\end_layout 6547 6548\begin_layout Plain Layout 6549 6550 ze_command_queue_desc_t commandQueueDescription = {}; 6551\end_layout 6552 6553\begin_layout Plain Layout 6554 6555 commandQueueDescription.stype = ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC; 6556\end_layout 6557 6558\begin_layout Plain Layout 6559 6560 commandQueueDescription.ordinal = commandQueueID; 6561\end_layout 6562 6563\begin_layout Plain Layout 6564 6565 commandQueueDescription.priority = ZE_COMMAND_QUEUE_PRIORITY_NORMAL; 6566\end_layout 6567 6568\begin_layout Plain Layout 6569 6570 commandQueueDescription.mode = ZE_COMMAND_QUEUE_MODE_DEFAULT; 6571\end_layout 6572 6573\begin_layout Plain Layout 6574 6575 res = zeCommandQueueCreate(vkGPU->context, vkGPU->device, &commandQueueDescr 6576iption, &vkGPU->commandQueue); 6577\end_layout 6578 6579\begin_layout Plain Layout 6580 6581 if (res != ZE_RESULT_SUCCESS) return VKFFT_ERROR_FAILED_TO_CREATE_COMMAND_QU 6582EUE; 6583\end_layout 6584 6585\begin_layout Plain Layout 6586 6587 free(cmdqueueGroupProperties); 6588\end_layout 6589 6590\begin_layout Plain Layout 6591 6592 i=numDevices; 6593\end_layout 6594 6595\begin_layout Plain Layout 6596 6597 j=numPlatforms; 6598\end_layout 6599 6600\begin_layout Plain Layout 6601 6602 } 6603\end_layout 6604 6605\begin_layout Plain Layout 6606 6607 else { 6608\end_layout 6609 6610\begin_layout Plain Layout 6611 6612 k++; 6613\end_layout 6614 6615\begin_layout Plain Layout 6616 6617 } 6618\end_layout 6619 6620\begin_layout Plain Layout 6621 6622 } 6623\end_layout 6624 6625\begin_layout Plain Layout 6626 6627\end_layout 6628 6629\begin_layout Plain Layout 6630 6631 free(deviceList); 6632\end_layout 6633 6634\begin_layout Plain Layout 6635 6636 } 6637\end_layout 6638 6639\begin_layout Plain Layout 6640 6641 free(drivers); 6642\end_layout 6643 6644\begin_layout Plain Layout 6645 6646#elif(VKFFT_BACKEND==5) 6647\end_layout 6648 6649\begin_layout Plain Layout 6650 6651 NS::Array* devices = MTL::CopyAllDevices(); 6652\end_layout 6653 6654\begin_layout Plain Layout 6655 6656 MTL::Device* device = (MTL::Device*)devices->object(vkGPU->device_id); 6657\end_layout 6658 6659\begin_layout Plain Layout 6660 6661 vkGPU->device = device; 6662\end_layout 6663 6664\begin_layout Plain Layout 6665 6666 MTL::CommandQueue* queue = device->newCommandQueue(); 6667\end_layout 6668 6669\begin_layout Plain Layout 6670 6671 vkGPU->queue = queue; 6672\end_layout 6673 6674\begin_layout Plain Layout 6675 6676#endif 6677\end_layout 6678 6679\begin_layout Plain Layout 6680 6681 6682\backslash 6683end{minted} 6684\end_layout 6685 6686\begin_layout Plain Layout 6687 6688 6689\backslash 6690end{mdframed} 6691\end_layout 6692 6693\end_inset 6694 6695 6696\end_layout 6697 6698\begin_layout Subsection 6699Simple FFT application example: 1D (one dimensional) C2C (complex to complex) 6700 FP32 (single precision) FFT 6701\end_layout 6702 6703\begin_layout Standard 6704This example performs the simplest case of FFT. 6705 It shows all the necessary fields that the user must fill during the configurat 6706ion and the submission process. 6707 Other samples will build on this one, as driver parameters initialization 6708 and code execution commands are the same for all configurations (except 6709 for the launch parameters that can be configured after application creation). 6710\end_layout 6711 6712\begin_layout Standard 6713\begin_inset ERT 6714status open 6715 6716\begin_layout Plain Layout 6717 6718 6719\backslash 6720begin{mdframed}[backgroundcolor=bg] 6721\end_layout 6722 6723\begin_layout Plain Layout 6724 6725 6726\backslash 6727begin{minted}[tabsize=4,obeytabs,breaklines]{C} 6728\end_layout 6729 6730\begin_layout Plain Layout 6731 6732//zero-initialize configuration + FFT application 6733\end_layout 6734 6735\begin_layout Plain Layout 6736 6737VkFFTConfiguration configuration = {}; 6738\end_layout 6739 6740\begin_layout Plain Layout 6741 6742VkFFTApplication app = {}; 6743\end_layout 6744 6745\begin_layout Plain Layout 6746 6747\end_layout 6748 6749\begin_layout Plain Layout 6750 6751configuration.FFTdim = 1; //FFT dimension 6752\end_layout 6753 6754\begin_layout Plain Layout 6755 6756configuration.size[0] = Nx; //FFT size 6757\end_layout 6758 6759\begin_layout Plain Layout 6760 6761uint64_t bufferSize = (uint64_t)sizeof(float) * 2 * configuration.size[0]; 6762\end_layout 6763 6764\begin_layout Plain Layout 6765 6766\end_layout 6767 6768\begin_layout Plain Layout 6769 6770//Device management + code submission 6771\end_layout 6772 6773\begin_layout Plain Layout 6774 6775#if(VKFFT_BACKEND==5) 6776\end_layout 6777 6778\begin_layout Plain Layout 6779 6780configuration.device = vkGPU->device; 6781\end_layout 6782 6783\begin_layout Plain Layout 6784 6785#else 6786\end_layout 6787 6788\begin_layout Plain Layout 6789 6790configuration.device = &vkGPU->device; 6791\end_layout 6792 6793\begin_layout Plain Layout 6794 6795#endif 6796\end_layout 6797 6798\begin_layout Plain Layout 6799 6800\end_layout 6801 6802\begin_layout Plain Layout 6803 6804#if(VKFFT_BACKEND==0) //Vulkan API 6805\end_layout 6806 6807\begin_layout Plain Layout 6808 6809configuration.queue = &vkGPU->queue; 6810\end_layout 6811 6812\begin_layout Plain Layout 6813 6814configuration.fence = &vkGPU->fence; 6815\end_layout 6816 6817\begin_layout Plain Layout 6818 6819configuration.commandPool = &vkGPU->commandPool; 6820\end_layout 6821 6822\begin_layout Plain Layout 6823 6824configuration.physicalDevice = &vkGPU->physicalDevice; 6825\end_layout 6826 6827\begin_layout Plain Layout 6828 6829configuration.isCompilerInitialized = isCompilerInitialized; //glslang compiler 6830 can be initialized before VkFFT plan creation. 6831 if not, VkFFT will create and destroy one after initialization 6832\end_layout 6833 6834\begin_layout Plain Layout 6835 6836#elif(VKFFT_BACKEND==3) //OpenCL API 6837\end_layout 6838 6839\begin_layout Plain Layout 6840 6841configuration.context = &vkGPU->context; 6842\end_layout 6843 6844\begin_layout Plain Layout 6845 6846#elif(VKFFT_BACKEND==4) 6847\end_layout 6848 6849\begin_layout Plain Layout 6850 6851configuration.context = &vkGPU->context; 6852\end_layout 6853 6854\begin_layout Plain Layout 6855 6856configuration.commandQueue = &vkGPU->commandQueue; 6857\end_layout 6858 6859\begin_layout Plain Layout 6860 6861configuration.commandQueueID = vkGPU->commandQueueID; 6862\end_layout 6863 6864\begin_layout Plain Layout 6865 6866#elif(VKFFT_BACKEND==5) 6867\end_layout 6868 6869\begin_layout Plain Layout 6870 6871configuration.queue = vkGPU->queue; 6872\end_layout 6873 6874\begin_layout Plain Layout 6875 6876#endif 6877\end_layout 6878 6879\begin_layout Plain Layout 6880 6881\end_layout 6882 6883\begin_layout Plain Layout 6884 6885allocateBuffer(buffer, bufferSize); //Pseudocode for buffer allocation, 6886 differs between APIs 6887\end_layout 6888 6889\begin_layout Plain Layout 6890 6891transferDataFromCPU(buffer, cpu_buffer); //Pseudocode for data transfer 6892 from CPU to GPU, differs between APIs 6893\end_layout 6894 6895\begin_layout Plain Layout 6896 6897\end_layout 6898 6899\begin_layout Plain Layout 6900 6901#if(VKFFT_BACKEND==0) //Vulkan API needs bufferSize at initialization 6902\end_layout 6903 6904\begin_layout Plain Layout 6905 6906configuration.bufferSize = &bufferSize; 6907\end_layout 6908 6909\begin_layout Plain Layout 6910 6911#endif 6912\end_layout 6913 6914\begin_layout Plain Layout 6915 6916\end_layout 6917 6918\begin_layout Plain Layout 6919 6920VkFFTResult resFFT = initializeVkFFT(&app, configuration); 6921\end_layout 6922 6923\begin_layout Plain Layout 6924 6925\end_layout 6926 6927\begin_layout Plain Layout 6928 6929VkFFTLaunchParams launchParams = {}; 6930\end_layout 6931 6932\begin_layout Plain Layout 6933 6934launchParams.buffer = &buffer; 6935\end_layout 6936 6937\begin_layout Plain Layout 6938 6939#if(VKFFT_BACKEND==0) //Vulkan API 6940\end_layout 6941 6942\begin_layout Plain Layout 6943 6944launchParams.commandBuffer = &commandBuffer; 6945\end_layout 6946 6947\begin_layout Plain Layout 6948 6949#elif(VKFFT_BACKEND==3) //OpenCL API 6950\end_layout 6951 6952\begin_layout Plain Layout 6953 6954launchParams.commandQueue = &commandQueue; 6955\end_layout 6956 6957\begin_layout Plain Layout 6958 6959#elif(VKFFT_BACKEND==4) //Level Zero API 6960\end_layout 6961 6962\begin_layout Plain Layout 6963 6964launchParams->commandList = &commandList; 6965\end_layout 6966 6967\begin_layout Plain Layout 6968 6969#elif(VKFFT_BACKEND==5) //Metal API 6970\end_layout 6971 6972\begin_layout Plain Layout 6973 6974launchParams->commandBuffer = commandBuffer; 6975\end_layout 6976 6977\begin_layout Plain Layout 6978 6979launchParams->commandEncoder = commandEncoder; 6980\end_layout 6981 6982\begin_layout Plain Layout 6983 6984#endif 6985\end_layout 6986 6987\begin_layout Plain Layout 6988 6989resFFT = VkFFTAppend(app, -1, &launchParams); 6990\end_layout 6991 6992\begin_layout Plain Layout 6993 6994\end_layout 6995 6996\begin_layout Plain Layout 6997 6998//add synchronization relevant to your API - vkWaitForFences/cudaDeviceSynchroni 6999ze/hipDeviceSynchronize/clFinish 7000\end_layout 7001 7002\begin_layout Plain Layout 7003 7004transferDataToCPU(cpu_buffer, buffer); //Pseudocode for data transfer from 7005 GPU to CPU, differs between APIs 7006\end_layout 7007 7008\begin_layout Plain Layout 7009 7010\end_layout 7011 7012\begin_layout Plain Layout 7013 7014freeBuffer(buffer, bufferSize); //Pseudocode for buffer deallocation, differs 7015 between APIs 7016\end_layout 7017 7018\begin_layout Plain Layout 7019 7020\end_layout 7021 7022\begin_layout Plain Layout 7023 7024deleteVkFFT(&app); 7025\end_layout 7026 7027\begin_layout Plain Layout 7028 7029 7030\backslash 7031end{minted} 7032\end_layout 7033 7034\begin_layout Plain Layout 7035 7036 7037\backslash 7038end{mdframed} 7039\end_layout 7040 7041\end_inset 7042 7043 7044\end_layout 7045 7046\begin_layout Subsection 7047Advanced FFT application example: ND, C2C/R2C/R2R, different precisions, 7048 batched FFT 7049\end_layout 7050 7051\begin_layout Standard 7052This example shows how to configure the main parameters of interest in the 7053 VkFFT library: multidimensional case, different types of transforms, different 7054 precision, perform batched transforms. 7055\end_layout 7056 7057\begin_layout Standard 7058In the code below X, Y and Z are the dimensions of FFT, B - number of batches, 7059 R2C - real to complex mode 0 or 1 (on/off), DCT - 0, 1, 2, 3 or 4 (off/DCT 7060 type), P - precision (0 - single, 1 - double, 2 - half). 7061\end_layout 7062 7063\begin_layout Standard 7064\begin_inset ERT 7065status open 7066 7067\begin_layout Plain Layout 7068 7069 7070\backslash 7071begin{mdframed}[backgroundcolor=bg] 7072\end_layout 7073 7074\begin_layout Plain Layout 7075 7076 7077\backslash 7078begin{minted}[tabsize=4,obeytabs,breaklines]{C} 7079\end_layout 7080 7081\begin_layout Plain Layout 7082 7083//zero-initialize configuration + FFT application 7084\end_layout 7085 7086\begin_layout Plain Layout 7087 7088VkFFTConfiguration configuration = {}; 7089\end_layout 7090 7091\begin_layout Plain Layout 7092 7093VkFFTApplication app = {}; 7094\end_layout 7095 7096\begin_layout Plain Layout 7097 7098\end_layout 7099 7100\begin_layout Plain Layout 7101 7102configuration.FFTdim = 1; //FFT dimension 7103\end_layout 7104 7105\begin_layout Plain Layout 7106 7107configuration.size[0] = X; 7108\end_layout 7109 7110\begin_layout Plain Layout 7111 7112configuration.size[1] = Y; 7113\end_layout 7114 7115\begin_layout Plain Layout 7116 7117configuration.size[2] = Z; 7118\end_layout 7119 7120\begin_layout Plain Layout 7121 7122if (Y > 1) configuration.FFTdim++; 7123\end_layout 7124 7125\begin_layout Plain Layout 7126 7127if (Z > 1) configuration.FFTdim++; 7128\end_layout 7129 7130\begin_layout Plain Layout 7131 7132configuration.numberBatches = B; 7133\end_layout 7134 7135\begin_layout Plain Layout 7136 7137configuration.performR2C = R2C; 7138\end_layout 7139 7140\begin_layout Plain Layout 7141 7142configuration.performDCT = DCT; 7143\end_layout 7144 7145\begin_layout Plain Layout 7146 7147if (P == 1) configuration.doublePrecision = 1; 7148\end_layout 7149 7150\begin_layout Plain Layout 7151 7152if (P == 2) configuration.halfPrecision = 1; 7153\end_layout 7154 7155\begin_layout Plain Layout 7156 7157\end_layout 7158 7159\begin_layout Plain Layout 7160 7161uint64_t bufferSize = 0; 7162\end_layout 7163 7164\begin_layout Plain Layout 7165 7166\end_layout 7167 7168\begin_layout Plain Layout 7169 7170if (R2C) { 7171\end_layout 7172 7173\begin_layout Plain Layout 7174 7175 bufferSize = (uint64_t)(storageComplexSize / 2) * (configuration.size[0] 7176 + 2) * configuration.size[1] * configuration.size[2] * configuration.numberBatches 7177; 7178\end_layout 7179 7180\begin_layout Plain Layout 7181 7182} 7183\end_layout 7184 7185\begin_layout Plain Layout 7186 7187else { 7188\end_layout 7189 7190\begin_layout Plain Layout 7191 7192 if (DCT) { 7193\end_layout 7194 7195\begin_layout Plain Layout 7196 7197 bufferSize = (uint64_t)(storageComplexSize / 2) * configuration.size[0] 7198 * configuration.size[1] * configuration.size[2] * configuration.numberBatches; 7199\end_layout 7200 7201\begin_layout Plain Layout 7202 7203 } 7204\end_layout 7205 7206\begin_layout Plain Layout 7207 7208 else { 7209\end_layout 7210 7211\begin_layout Plain Layout 7212 7213 bufferSize = (uint64_t)storageComplexSize * configuration.size[0] * configurati 7214on.size[1] * configuration.size[2] * configuration.numberBatches; 7215\end_layout 7216 7217\begin_layout Plain Layout 7218 7219 } 7220\end_layout 7221 7222\begin_layout Plain Layout 7223 7224} // storageComplexSize - 4/8/16 for FP16/FP32/FP64 respectively. 7225\end_layout 7226 7227\begin_layout Plain Layout 7228 7229\end_layout 7230 7231\begin_layout Plain Layout 7232 7233//Device management + code submission - code is identical to the previous 7234 example 7235\end_layout 7236 7237\begin_layout Plain Layout 7238 7239 7240\backslash 7241end{minted} 7242\end_layout 7243 7244\begin_layout Plain Layout 7245 7246 7247\backslash 7248end{mdframed} 7249\end_layout 7250 7251\end_inset 7252 7253 7254\end_layout 7255 7256\begin_layout Subsection 7257Advanced FFT application example: out-of-place R2C FFT with custom strides 7258\end_layout 7259 7260\begin_layout Standard 7261In this example, VkFFT is configured to calculate a 3D out-of-place R2C 7262 FFT of a system with custom strides. 7263 VkFFT reads data from the inputBuffer and produces the result in the buffer. 7264 7265\end_layout 7266 7267\begin_layout Standard 7268\begin_inset ERT 7269status open 7270 7271\begin_layout Plain Layout 7272 7273 7274\backslash 7275begin{mdframed}[backgroundcolor=bg] 7276\end_layout 7277 7278\begin_layout Plain Layout 7279 7280 7281\backslash 7282begin{minted}[tabsize=4,obeytabs,breaklines]{C} 7283\end_layout 7284 7285\begin_layout Plain Layout 7286 7287//zero-initialize configuration + FFT application 7288\end_layout 7289 7290\begin_layout Plain Layout 7291 7292VkFFTConfiguration configuration = {}; 7293\end_layout 7294 7295\begin_layout Plain Layout 7296 7297VkFFTApplication app = {}; 7298\end_layout 7299 7300\begin_layout Plain Layout 7301 7302\end_layout 7303 7304\begin_layout Plain Layout 7305 7306configuration.FFTdim = 3; //FFT dimension 7307\end_layout 7308 7309\begin_layout Plain Layout 7310 7311configuration.size[0] = Nx; 7312\end_layout 7313 7314\begin_layout Plain Layout 7315 7316configuration.size[1] = Ny; 7317\end_layout 7318 7319\begin_layout Plain Layout 7320 7321configuration.size[2] = Nz; 7322\end_layout 7323 7324\begin_layout Plain Layout 7325 7326\end_layout 7327 7328\begin_layout Plain Layout 7329 7330configuration.performR2C = 1; 7331\end_layout 7332 7333\begin_layout Plain Layout 7334 7335\end_layout 7336 7337\begin_layout Plain Layout 7338 7339//out-of-place - we need to specify that input buffer is separate from the 7340 main buffer 7341\end_layout 7342 7343\begin_layout Plain Layout 7344 7345configuration.isInputFormatted = 1; 7346\end_layout 7347 7348\begin_layout Plain Layout 7349 7350configuration.inputBufferStride[0] = configuration.size[0]; 7351\end_layout 7352 7353\begin_layout Plain Layout 7354 7355configuration.inputBufferStride[1] = configuration.inputBufferStride[0] * 7356 configuration.size[1]; 7357\end_layout 7358 7359\begin_layout Plain Layout 7360 7361configuration.inputBufferStride[2] = configuration.inputBufferStride[1] * 7362 configuration.size[2]; 7363\end_layout 7364 7365\begin_layout Plain Layout 7366 7367 7368\end_layout 7369 7370\begin_layout Plain Layout 7371 7372configuration.bufferStride[0] = (uint64_t) (configuration.size[0] / 2) + 1; 7373\end_layout 7374 7375\begin_layout Plain Layout 7376 7377configuration.bufferStride[1] = configuration.bufferStride[0] * configuration.size[ 73781]; 7379\end_layout 7380 7381\begin_layout Plain Layout 7382 7383configuration.bufferStride[2] = configuration.bufferStride[1]* configuration.size[2 7384]; 7385\end_layout 7386 7387\begin_layout Plain Layout 7388 7389\end_layout 7390 7391\begin_layout Plain Layout 7392 7393uint64_t inputBufferSize = (uint64_t)sizeof(float) * configuration.size[0] 7394 * configuration.size[1] * configuration.size[2]; 7395\end_layout 7396 7397\begin_layout Plain Layout 7398 7399\end_layout 7400 7401\begin_layout Plain Layout 7402 7403uint64_t bufferSize = (uint64_t)sizeof(float) * 2 * (configuration.size[0]/2+1) 7404 * configuration.size[1] * configuration.size[2]; 7405\end_layout 7406 7407\begin_layout Plain Layout 7408 7409\end_layout 7410 7411\begin_layout Plain Layout 7412 7413//Device management + code submission - code is identical to the first example, 7414 except that you need to allocate two buffers (and provide them in the launch 7415 configuration). 7416\end_layout 7417 7418\begin_layout Plain Layout 7419 7420\end_layout 7421 7422\begin_layout Plain Layout 7423 7424 7425\backslash 7426end{minted} 7427\end_layout 7428 7429\begin_layout Plain Layout 7430 7431 7432\backslash 7433end{mdframed} 7434\end_layout 7435 7436\end_inset 7437 7438 7439\end_layout 7440 7441\begin_layout Subsection 7442Advanced FFT application example: 3D FFT with innermost batching 7443\end_layout 7444 7445\begin_layout Standard 7446In this example, VkFFT is configured to calculate a 3D in-place C2C FFT 7447 of a system with innermost (fast axis) batching. 7448 7449\end_layout 7450 7451\begin_layout Standard 7452\begin_inset ERT 7453status open 7454 7455\begin_layout Plain Layout 7456 7457 7458\backslash 7459begin{mdframed}[backgroundcolor=bg] 7460\end_layout 7461 7462\begin_layout Plain Layout 7463 7464 7465\backslash 7466begin{minted}[tabsize=4,obeytabs,breaklines]{C} 7467\end_layout 7468 7469\begin_layout Plain Layout 7470 7471//zero-initialize configuration + FFT application 7472\end_layout 7473 7474\begin_layout Plain Layout 7475 7476VkFFTConfiguration configuration = {}; 7477\end_layout 7478 7479\begin_layout Plain Layout 7480 7481VkFFTApplication app = {}; 7482\end_layout 7483 7484\begin_layout Plain Layout 7485 7486\end_layout 7487 7488\begin_layout Plain Layout 7489 7490configuration.FFTdim = 4; //FFT dimension, 3+1 7491\end_layout 7492 7493\begin_layout Plain Layout 7494 7495configuration.size[0] = Nbatch; 7496\end_layout 7497 7498\begin_layout Plain Layout 7499 7500configuration.size[1] = Nx; 7501\end_layout 7502 7503\begin_layout Plain Layout 7504 7505configuration.size[2] = Ny; 7506\end_layout 7507 7508\begin_layout Plain Layout 7509 7510configuration.size[3] = Nz; 7511\end_layout 7512 7513\begin_layout Plain Layout 7514 7515\end_layout 7516 7517\begin_layout Plain Layout 7518 7519configuration.omitDimension[0] = 1; // disable FFT over the batching dimension 7520\end_layout 7521 7522\begin_layout Plain Layout 7523 7524\end_layout 7525 7526\begin_layout Plain Layout 7527 7528uint64_t bufferSize = (uint64_t)sizeof(float) * configuration.size[0] * configura 7529tion.size[1] * configuration.size[2] * configuration.size[3]; 7530\end_layout 7531 7532\begin_layout Plain Layout 7533 7534\end_layout 7535 7536\begin_layout Plain Layout 7537 7538//Device management + code submission - code is identical to the first example, 7539 except that you need to allocate two buffers (and provide them in the launch 7540 configuration). 7541\end_layout 7542 7543\begin_layout Plain Layout 7544 7545\end_layout 7546 7547\begin_layout Plain Layout 7548 7549 7550\backslash 7551end{minted} 7552\end_layout 7553 7554\begin_layout Plain Layout 7555 7556 7557\backslash 7558end{mdframed} 7559\end_layout 7560 7561\end_inset 7562 7563 7564\end_layout 7565 7566\begin_layout Subsection 7567Advanced FFT application example: 3D zero-padded FFT 7568\end_layout 7569 7570\begin_layout Standard 7571In this example, VkFFT is configured to calculate a 3D FFT of a system. 7572 The meaningful data is located in the first octant of the buffer, the rest 7573 is padded with zeros. 7574 This configuration removes the circular part of the convolution and allows 7575 modelling of open systems. 7576\end_layout 7577 7578\begin_layout Standard 7579\begin_inset ERT 7580status open 7581 7582\begin_layout Plain Layout 7583 7584 7585\backslash 7586begin{mdframed}[backgroundcolor=bg] 7587\end_layout 7588 7589\begin_layout Plain Layout 7590 7591 7592\backslash 7593begin{minted}[tabsize=4,obeytabs,breaklines]{C} 7594\end_layout 7595 7596\begin_layout Plain Layout 7597 7598//zero-initialize configuration + FFT application 7599\end_layout 7600 7601\begin_layout Plain Layout 7602 7603VkFFTConfiguration configuration = {}; 7604\end_layout 7605 7606\begin_layout Plain Layout 7607 7608VkFFTApplication app = {}; 7609\end_layout 7610 7611\begin_layout Plain Layout 7612 7613\end_layout 7614 7615\begin_layout Plain Layout 7616 7617configuration.FFTdim = 3; //FFT dimension 7618\end_layout 7619 7620\begin_layout Plain Layout 7621 7622configuration.size[0] = Nx; 7623\end_layout 7624 7625\begin_layout Plain Layout 7626 7627configuration.size[1] = Ny; 7628\end_layout 7629 7630\begin_layout Plain Layout 7631 7632configuration.size[2] = Nz; 7633\end_layout 7634 7635\begin_layout Plain Layout 7636 7637\end_layout 7638 7639\begin_layout Plain Layout 7640 7641configuration.performZeropadding[0] = 1; //Perform padding with zeros on 7642 GPU. 7643 Still need to properly align input data (no need to fill padding area with 7644 meaningful data) but this will increase performance due to the lower amount 7645 of the memory reads/writes and omitting sequences only consisting of zeros. 7646\end_layout 7647 7648\begin_layout Plain Layout 7649 7650configuration.performZeropadding[1] = 1; 7651\end_layout 7652 7653\begin_layout Plain Layout 7654 7655configuration.performZeropadding[2] = 1; 7656\end_layout 7657 7658\begin_layout Plain Layout 7659 7660configuration.fft_zeropad_left[0] = (uint64_t)ceil(configuration.size[0] / 7661 2.0); 7662\end_layout 7663 7664\begin_layout Plain Layout 7665 7666configuration.fft_zeropad_right[0] = configuration.size[0]; 7667\end_layout 7668 7669\begin_layout Plain Layout 7670 7671configuration.fft_zeropad_left[1] = (uint64_t)ceil(configuration.size[1] / 7672 2.0); 7673\end_layout 7674 7675\begin_layout Plain Layout 7676 7677configuration.fft_zeropad_right[1] = configuration.size[1]; 7678\end_layout 7679 7680\begin_layout Plain Layout 7681 7682configuration.fft_zeropad_left[2] = (uint64_t)ceil(configuration.size[2] / 7683 2.0); 7684\end_layout 7685 7686\begin_layout Plain Layout 7687 7688configuration.fft_zeropad_right[2] = configuration.size[2]; 7689\end_layout 7690 7691\begin_layout Plain Layout 7692 7693\end_layout 7694 7695\begin_layout Plain Layout 7696 7697uint64_t bufferSize = (uint64_t)storageComplexSize * configuration.size[0] 7698 * configuration.size[1] * configuration.size[2]; 7699\end_layout 7700 7701\begin_layout Plain Layout 7702 7703\end_layout 7704 7705\begin_layout Plain Layout 7706 7707\end_layout 7708 7709\begin_layout Plain Layout 7710 7711//Device management + code submission - code is identical to the first example 7712\end_layout 7713 7714\begin_layout Plain Layout 7715 7716\end_layout 7717 7718\begin_layout Plain Layout 7719 7720 7721\backslash 7722end{minted} 7723\end_layout 7724 7725\begin_layout Plain Layout 7726 7727 7728\backslash 7729end{mdframed} 7730\end_layout 7731 7732\end_inset 7733 7734 7735\end_layout 7736 7737\begin_layout Subsection 7738Convolution application example: 3x3 matrix-vector convolution in 1D 7739\end_layout 7740 7741\begin_layout Standard 7742In this example, VkFFT is configured to calculate a kernel, represented 7743 by a 3x3 matrix and a system, represented by a 3D vector. 7744 Their convolution is a matrix-vector multiplication in the frequency domain. 7745\end_layout 7746 7747\begin_layout Standard 7748\begin_inset ERT 7749status open 7750 7751\begin_layout Plain Layout 7752 7753 7754\backslash 7755begin{mdframed}[backgroundcolor=bg] 7756\end_layout 7757 7758\begin_layout Plain Layout 7759 7760 7761\backslash 7762begin{minted}[tabsize=4,obeytabs,breaklines]{C} 7763\end_layout 7764 7765\begin_layout Plain Layout 7766 7767//zero-initialize configuration + FFT application, we need two - one for 7768 kernel calculation 7769\end_layout 7770 7771\begin_layout Plain Layout 7772 7773VkFFTConfiguration kernel_configuration = {}; 7774\end_layout 7775 7776\begin_layout Plain Layout 7777 7778VkFFTConfiguration convolution_configuration = {}; 7779\end_layout 7780 7781\begin_layout Plain Layout 7782 7783VkFFTApplication app_kernel = {}; 7784\end_layout 7785 7786\begin_layout Plain Layout 7787 7788VkFFTApplication app_convolution = {}; 7789\end_layout 7790 7791\begin_layout Plain Layout 7792 7793\end_layout 7794 7795\begin_layout Plain Layout 7796 7797\end_layout 7798 7799\begin_layout Plain Layout 7800 7801kernel_configuration.FFTdim = 1; //FFT dimension 7802\end_layout 7803 7804\begin_layout Plain Layout 7805 7806kernel_configuration.size[0] = Nx; //FFT size 7807\end_layout 7808 7809\begin_layout Plain Layout 7810 7811\end_layout 7812 7813\begin_layout Plain Layout 7814 7815uint64_t bufferSize = (uint64_t)sizeof(float) * 2 * kernel_configuration.size[0]; 7816\end_layout 7817 7818\begin_layout Plain Layout 7819 7820\end_layout 7821 7822\begin_layout Plain Layout 7823 7824//configure kernel 7825\end_layout 7826 7827\begin_layout Plain Layout 7828 7829kernel_configuration.kernelConvolution = 1; //specify if this plan is used 7830 to create kernel for convolution 7831\end_layout 7832 7833\begin_layout Plain Layout 7834 7835kernel_configuration.coordinateFeatures = 9; //Specify dimensionality of 7836 the input feature vector (default 1). 7837 Each component is stored not as a vector, but as a separate system and 7838 padded on it's own according to other options (i.e. 7839 for x*y system of 3-vector, first x*y elements correspond to the first 7840 dimension, then goes x*y for the second, etc). 7841\end_layout 7842 7843\begin_layout Plain Layout 7844 7845//coordinateFeatures number is an important constant for convolution. 7846 If we perform 1x1 convolution, it is equal to number of features, but matrixCon 7847volution should be equal to 1. 7848 For matrix convolution, it must be equal to matrixConvolution parameter. 7849 If we perform 2x2 convolution, it is equal to 3 for symmetric kernel (stored 7850 as xx, xy, yy) and 4 for nonsymmetric (stored as xx, xy, yx, yy). 7851 Similarly, 6 (stored as xx, xy, xz, yy, yz, zz) and 9 (stored as xx, xy, 7852 xz, yx, yy, yz, zx, zy, zz) for 3x3 convolutions. 7853 7854\end_layout 7855 7856\begin_layout Plain Layout 7857 7858kernel_configuration.normalize = 1; 7859\end_layout 7860 7861\begin_layout Plain Layout 7862 7863\end_layout 7864 7865\begin_layout Plain Layout 7866 7867//Initialize app_kernel and perform a single forward FFT like in examples 7868 before. 7869 You pass kernel as a buffer for the preparation stage. 7870\end_layout 7871 7872\begin_layout Plain Layout 7873 7874\end_layout 7875 7876\begin_layout Plain Layout 7877 7878convolution_configuration = kernel_configuration; 7879\end_layout 7880 7881\begin_layout Plain Layout 7882 7883convolution_configuration.kernelConvolution = 0; 7884\end_layout 7885 7886\begin_layout Plain Layout 7887 7888convolution_configuration.performConvolution = 1; 7889\end_layout 7890 7891\begin_layout Plain Layout 7892 7893convolution_configuration.symmetricKernel = 0;//Specify if convolution kernel 7894 is symmetric. 7895 In this case we only pass upper triangle part of it in the form of: (xx, 7896 xy, yy) for 2d and (xx, xy, xz, yy, yz, zz) for 3d. 7897\end_layout 7898 7899\begin_layout Plain Layout 7900 7901convolution_configuration.matrixConvolution = 3;//we do matrix convolution, 7902 so kernel is 9 numbers (3x3), but vector dimension is 3 7903\end_layout 7904 7905\begin_layout Plain Layout 7906 7907convolution_configuration.coordinateFeatures = 3;//equal to matrixConvolution 7908 size 7909\end_layout 7910 7911\begin_layout Plain Layout 7912 7913\end_layout 7914 7915\begin_layout Plain Layout 7916 7917//Initialize app_convolution and perform a single forward FFT like in examples 7918 before. 7919 You pass kernel as kernel and system to be convolved with it as buffer 7920\end_layout 7921 7922\begin_layout Plain Layout 7923 7924\end_layout 7925 7926\begin_layout Plain Layout 7927 7928 7929\backslash 7930end{minted} 7931\end_layout 7932 7933\begin_layout Plain Layout 7934 7935 7936\backslash 7937end{mdframed} 7938\end_layout 7939 7940\end_inset 7941 7942 7943\end_layout 7944 7945\begin_layout Subsection 7946Convolution application example: R2C cross-correlation between two sets 7947 of N images 7948\end_layout 7949 7950\begin_layout Standard 7951In this example, VkFFT is configured to calculate a kernel, represented 7952 by three 2D vectors (RGB values of a pixel) and a system, also represented 7953 by three 2D vectors. 7954 There are N kernels and N systems. 7955 Their cross-correlation is a conjugate convolution in the frequency domain. 7956 Images are usually stored as real, not complex numbers, so code uses R2C 7957 optimization as well. 7958\end_layout 7959 7960\begin_layout Standard 7961\begin_inset ERT 7962status open 7963 7964\begin_layout Plain Layout 7965 7966 7967\backslash 7968begin{mdframed}[backgroundcolor=bg] 7969\end_layout 7970 7971\begin_layout Plain Layout 7972 7973 7974\backslash 7975begin{minted}[tabsize=4,obeytabs,breaklines]{C} 7976\end_layout 7977 7978\begin_layout Plain Layout 7979 7980//zero-initialize configuration + FFT application, we need two - one for 7981 kernel calculation 7982\end_layout 7983 7984\begin_layout Plain Layout 7985 7986VkFFTConfiguration kernel_configuration = {}; 7987\end_layout 7988 7989\begin_layout Plain Layout 7990 7991VkFFTConfiguration convolution_configuration = {}; 7992\end_layout 7993 7994\begin_layout Plain Layout 7995 7996VkFFTApplication app_kernel = {}; 7997\end_layout 7998 7999\begin_layout Plain Layout 8000 8001VkFFTApplication app_convolution = {}; 8002\end_layout 8003 8004\begin_layout Plain Layout 8005 8006\end_layout 8007 8008\begin_layout Plain Layout 8009 8010\end_layout 8011 8012\begin_layout Plain Layout 8013 8014kernel_configuration.FFTdim = 2; //FFT dimension 8015\end_layout 8016 8017\begin_layout Plain Layout 8018 8019kernel_configuration.size[0] = Nx; 8020\end_layout 8021 8022\begin_layout Plain Layout 8023 8024kernel_configuration.size[1] = Ny; 8025\end_layout 8026 8027\begin_layout Plain Layout 8028 8029kernel_configuration.coordinateFeatures = 3; 8030\end_layout 8031 8032\begin_layout Plain Layout 8033 8034kernel_configuration.numberBatches = N; 8035\end_layout 8036 8037\begin_layout Plain Layout 8038 8039kernel_configuration.performR2C = 1; 8040\end_layout 8041 8042\begin_layout Plain Layout 8043 8044kernel_configuration.normalize = 1; 8045\end_layout 8046 8047\begin_layout Plain Layout 8048 8049\end_layout 8050 8051\begin_layout Plain Layout 8052 8053uint64_t bufferSize = (uint64_t)sizeof(float) * 2 * (kernel_configuration.size[0] 8054/2+1) * kernel_configuration.size[1] * kernel_configuration.coordinateFeatures 8055 * kernel_configuration.numberBatches; 8056\end_layout 8057 8058\begin_layout Plain Layout 8059 8060 8061\end_layout 8062 8063\begin_layout Plain Layout 8064 8065kernel_configuration.kernelConvolution = 1; //specify if this plan is used 8066 to create kernel for convolution 8067\end_layout 8068 8069\begin_layout Plain Layout 8070 8071\end_layout 8072 8073\begin_layout Plain Layout 8074 8075//Initialize app_kernel and perform a single forward FFT like in examples 8076 before. 8077 Pad in-place R2C system like this: 8078\end_layout 8079 8080\begin_layout Plain Layout 8081 8082\end_layout 8083 8084\begin_layout Plain Layout 8085 8086for (uint64_t n = 0; n < kernel_configuration.numberBatches; n++) { 8087\end_layout 8088 8089\begin_layout Plain Layout 8090 8091 for (uint64_t c = 0; c < kernel_configuration.coordinateFeatures; c++) { 8092\end_layout 8093 8094\begin_layout Plain Layout 8095 8096 for (uint64_t j = 0; j < kernel_configuration.size[1]; j++) { 8097\end_layout 8098 8099\begin_layout Plain Layout 8100 8101 for (uint64_t i = 0; i < kernel_configuration.size[0]; i++) { 8102\end_layout 8103 8104\begin_layout Plain Layout 8105 8106 kernel_padded_GPU[i + j * 2 * (kernel_configuration.size[0]/2 + 1) + 8107 c * 2 * (kernel_configuration.size[0]/2 + 1) * kernel_configuration.size[1] 8108 + n * 2 * (kernel_configuration.size[0]/2 + 1) * kernel_configuration.size[1] 8109 * kernel_configuration.coordinateFeatures] = kernel_input[i + j * kernel_configu 8110ration.size[0] + c * kernel_configuration.size[0] * kernel_configuration.size[1] 8111 + n * kernel_configuration.size[0] * kernel_configuration.size[1] * kernel_config 8112uration.coordinateFeatures]; 8113\end_layout 8114 8115\begin_layout Plain Layout 8116 8117 } 8118\end_layout 8119 8120\begin_layout Plain Layout 8121 8122 } 8123\end_layout 8124 8125\begin_layout Plain Layout 8126 8127 } 8128\end_layout 8129 8130\begin_layout Plain Layout 8131 8132} 8133\end_layout 8134 8135\begin_layout Plain Layout 8136 8137convolution_configuration = kernel_configuration; 8138\end_layout 8139 8140\begin_layout Plain Layout 8141 8142convolution_configuration.kernelConvolution = 0; 8143\end_layout 8144 8145\begin_layout Plain Layout 8146 8147convolution_configuration.performConvolution = 1; 8148\end_layout 8149 8150\begin_layout Plain Layout 8151 8152convolution_configuration.conjugateConvolution = 1; 8153\end_layout 8154 8155\begin_layout Plain Layout 8156 8157\end_layout 8158 8159\begin_layout Plain Layout 8160 8161//Initialize app_convolution and perform a single forward FFT like in examples 8162 before. 8163 Pad the system in the same way as the kernel 8164\end_layout 8165 8166\begin_layout Plain Layout 8167 8168\end_layout 8169 8170\begin_layout Plain Layout 8171 8172 8173\backslash 8174end{minted} 8175\end_layout 8176 8177\begin_layout Plain Layout 8178 8179 8180\backslash 8181end{mdframed} 8182\end_layout 8183 8184\end_inset 8185 8186 8187\end_layout 8188 8189\begin_layout Subsection 8190Simple FFT application binary reuse application 8191\end_layout 8192 8193\begin_layout Standard 8194This example shows how to save/load binaries generated by VkFFT. 8195 This can reduce time taken by initializeVkFFT call by removing RTC components 8196 from it. 8197 Be sure that rest of the configuration stays the same to reuse the binary. 8198 Use rb/wb flags to load/save. 8199 This does not currently work in Metal backend. 8200\end_layout 8201 8202\begin_layout Standard 8203\begin_inset ERT 8204status open 8205 8206\begin_layout Plain Layout 8207 8208 8209\backslash 8210begin{mdframed}[backgroundcolor=bg] 8211\end_layout 8212 8213\begin_layout Plain Layout 8214 8215 8216\backslash 8217begin{minted}[tabsize=4,obeytabs,breaklines]{C} 8218\end_layout 8219 8220\begin_layout Plain Layout 8221 8222VkFFTConfiguration configuration = {}; 8223\end_layout 8224 8225\begin_layout Plain Layout 8226 8227VkFFTApplication app = {}; 8228\end_layout 8229 8230\begin_layout Plain Layout 8231 8232\end_layout 8233 8234\begin_layout Plain Layout 8235 8236//configuration is initialized like in other examples 8237\end_layout 8238 8239\begin_layout Plain Layout 8240 8241configuration.saveApplicationToString = 1; 8242\end_layout 8243 8244\begin_layout Plain Layout 8245 8246//configuration.loadApplicationFromString = 1; //choose one to save/load 8247 binary file 8248\end_layout 8249 8250\begin_layout Plain Layout 8251 8252\end_layout 8253 8254\begin_layout Plain Layout 8255 8256if (configuration.loadApplicationFromString) { 8257\end_layout 8258 8259\begin_layout Plain Layout 8260 8261 FILE* kernelCache; 8262\end_layout 8263 8264\begin_layout Plain Layout 8265 8266 uint64_t str_len; 8267\end_layout 8268 8269\begin_layout Plain Layout 8270 8271 kernelCache = fopen("VkFFT_binary", "rb"); 8272\end_layout 8273 8274\begin_layout Plain Layout 8275 8276 fseek(kernelCache, 0, SEEK_END); 8277\end_layout 8278 8279\begin_layout Plain Layout 8280 8281 str_len = ftell(kernelCache); 8282\end_layout 8283 8284\begin_layout Plain Layout 8285 8286 fseek(kernelCache, 0, SEEK_SET); 8287\end_layout 8288 8289\begin_layout Plain Layout 8290 8291 configuration.loadApplicationString = malloc(str_len); 8292\end_layout 8293 8294\begin_layout Plain Layout 8295 8296 fread(configuration.loadApplicationString, str_len, 1, kernelCache); 8297\end_layout 8298 8299\begin_layout Plain Layout 8300 8301 fclose(kernelCache); 8302\end_layout 8303 8304\begin_layout Plain Layout 8305 8306} 8307\end_layout 8308 8309\begin_layout Plain Layout 8310 8311\end_layout 8312 8313\begin_layout Plain Layout 8314 8315resFFT = initializeVkFFT(&app, configuration); 8316\end_layout 8317 8318\begin_layout Plain Layout 8319 8320if (resFFT != VKFFT_SUCCESS) return resFFT; 8321\end_layout 8322 8323\begin_layout Plain Layout 8324 8325\end_layout 8326 8327\begin_layout Plain Layout 8328 8329if (configuration.loadApplicationFromString) 8330\end_layout 8331 8332\begin_layout Plain Layout 8333 8334 free(configuration.loadApplicationString); 8335\end_layout 8336 8337\begin_layout Plain Layout 8338 8339\end_layout 8340 8341\begin_layout Plain Layout 8342 8343if (configuration.saveApplicationToString) { 8344\end_layout 8345 8346\begin_layout Plain Layout 8347 8348 FILE* kernelCache; 8349\end_layout 8350 8351\begin_layout Plain Layout 8352 8353 kernelCache = fopen("VkFFT_binary", "wb"); 8354\end_layout 8355 8356\begin_layout Plain Layout 8357 8358 fwrite(app.saveApplicationString, app.applicationStringSize, 1, kernelCache); 8359\end_layout 8360 8361\begin_layout Plain Layout 8362 8363 fclose(kernelCache); 8364\end_layout 8365 8366\begin_layout Plain Layout 8367 8368} 8369\end_layout 8370 8371\begin_layout Plain Layout 8372 8373\end_layout 8374 8375\begin_layout Plain Layout 8376 8377//application is launched like in other examples 8378\end_layout 8379 8380\begin_layout Plain Layout 8381 8382 8383\backslash 8384end{minted} 8385\end_layout 8386 8387\begin_layout Plain Layout 8388 8389 8390\backslash 8391end{mdframed} 8392\end_layout 8393 8394\end_inset 8395 8396 8397\end_layout 8398 8399\end_body 8400\end_document