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