yum-mirror/VkFFT

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

Tolmachev DmitriiRadix 6, 8, 9, 10, 12, 14, 15, 16, 32 support + Bluestein tuning -Added support for more composite radix kenrels. Improves performance by reducing shared memory communications -Added Bluestein sequence advanced tuning: can now specify the sequence to pad to. Added default tuned values for FP32 and FP64 for Nvidia A100 and AMD MI250 for sequences up to 4096 -Improved LUT usage: do not upload the first radix, coalesced upload to shared memory for small stage requests. -Bugfixes: C2R check for big radix, matrix convolution coordinate assignment, specification of device_id in cuFFT/rocFFT scripts9640836

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