yum-mirror/VkFFT
git clone https://git.yummers.dev/yum-mirror/VkFFT
5f7df3f
develop
1#ifndef VKFFT_UTILS_H 2#define VKFFT_UTILS_H 3#include "vkFFT.h" 4#include <vector> 5typedef struct { 6#if (VKFFT_BACKEND == 0 ) 7VkInstance instance ;//a connection between the application and the Vulkan library 8VkPhysicalDevice physicalDevice ;//a handle for the graphics card used in the application 9VkPhysicalDeviceProperties physicalDeviceProperties ;//bastic device properties 10VkPhysicalDeviceMemoryProperties physicalDeviceMemoryProperties ;//bastic memory properties of the device 11VkDevice device ;//a logical device, interacting with physical device 12VkDebugUtilsMessengerEXT debugMessenger ;//extension for debugging 13uint64_t queueFamilyIndex ;//if multiple queues are available, specify the used one 14VkQueue queue ;//a place, where all operations are submitted 15VkCommandPool commandPool ;//an opaque objects that command buffer memory is allocated from 16VkFence fence ;//a vkGPU->fence used to synchronize dispatches 17std ::vector < const char *> enabledDeviceExtensions ; 18uint64_t enableValidationLayers ; 19 20VkBuffer * stagingBuffer ;//optional pointer to the user defined staging buffer 21VkDeviceMemory * stagingBufferMemory ;//optional pointer to the user defined staging buffer memory, associated with the stagingBuffer 22#elif (VKFFT_BACKEND == 1 ) 23CUdevice device ; 24CUcontext context ; 25#elif (VKFFT_BACKEND == 2 ) 26hipDevice_t device ; 27hipCtx_t context ; 28#elif (VKFFT_BACKEND == 3 ) 29cl_platform_id platform ; 30cl_device_id device ; 31cl_context context ; 32cl_command_queue commandQueue ; 33#elif (VKFFT_BACKEND == 4 ) 34ze_driver_handle_t driver ; 35ze_device_handle_t device ; 36ze_context_handle_t context ; 37ze_command_queue_handle_t commandQueue ; 38uint32_t commandQueueID ; 39#elif (VKFFT_BACKEND == 5 ) 40MTL ::Device * device ; 41MTL ::CommandQueue * queue ; 42#endif 43uint64_t device_id ;//an id of a device, reported by Vulkan device list 44}VkGPU ;//an example structure containing Vulkan primitives 45 46typedef struct { 47uint64_t X ; 48uint64_t Y ; 49uint64_t Z ; 50uint64_t P ; 51uint64_t B ; 52uint64_t N ; 53uint64_t R2C ; 54uint64_t DCT ; 55uint64_t saveApplicationToString ; 56uint64_t loadApplicationFromString ; 57}VkFFTUserSystemParameters ;//an example structure used to pass user-defined system for benchmarking 58 59#if (VKFFT_BACKEND == 0 ) 60VkResult CreateDebugUtilsMessengerEXT (VkGPU * vkGPU ,const VkDebugUtilsMessengerCreateInfoEXT * pCreateInfo ,const VkAllocationCallbacks * pAllocator ,VkDebugUtilsMessengerEXT * pDebugMessenger ); 61void DestroyDebugUtilsMessengerEXT (VkGPU * vkGPU ,const VkAllocationCallbacks * pAllocator ); 62static VKAPI_ATTR VkBool32 VKAPI_CALL debugCallback (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity ,VkDebugUtilsMessageTypeFlagsEXT messageType ,const VkDebugUtilsMessengerCallbackDataEXT * pCallbackData ,void * pUserData ); 63VkResult setupDebugMessenger (VkGPU * vkGPU ); 64VkResult checkValidationLayerSupport (); 65std ::vector < const char *> getRequiredExtensions (VkGPU * vkGPU ,uint64_t sample_id ); 66VkResult createInstance (VkGPU * vkGPU ,uint64_t sample_id ); 67VkResult findPhysicalDevice (VkGPU * vkGPU ); 68VkResult getComputeQueueFamilyIndex (VkGPU * vkGPU ); 69VkResult createDevice (VkGPU * vkGPU ,uint64_t sample_id ); 70VkResult createFence (VkGPU * vkGPU ); 71VkResult createCommandPool (VkGPU * vkGPU ); 72VkFFTResult findMemoryType (VkGPU * vkGPU ,uint64_t memoryTypeBits ,uint64_t memorySize ,VkMemoryPropertyFlags properties ,uint32_t * memoryTypeIndex ); 73VkFFTResult allocateBuffer (VkGPU * vkGPU ,VkBuffer * buffer ,VkDeviceMemory * deviceMemory ,VkBufferUsageFlags usageFlags ,VkMemoryPropertyFlags propertyFlags ,uint64_t size ); 74#endif 75VkFFTResult allocateMemoryGPU (VkGPU * vkGPU ,void ** buffer ,void ** deviceMemoryVulkan ,uint64_t bufferSize ); 76VkFFTResult transferDataToCPU (VkGPU * vkGPU ,void * cpu_arr ,void * output_buffer ,uint64_t bufferSize ); 77VkFFTResult transferDataFromCPU (VkGPU * vkGPU ,void * cpu_arr ,void * input_buffer ,uint64_t bufferSize ); 78VkFFTResult devices_list (); 79VkFFTResult performVulkanFFT (VkGPU * vkGPU ,VkFFTApplication * app ,VkFFTLaunchParams * launchParams ,int inverse ,uint64_t num_iter ); 80VkFFTResult performVulkanFFTiFFT (VkGPU * vkGPU ,VkFFTApplication * app ,VkFFTLaunchParams * launchParams ,uint64_t num_iter ,double * time_result ); 81#endif