Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
HalideRuntimeVulkan.h
Go to the documentation of this file.
1#ifndef HALIDE_HALIDERUNTIMEVULKAN_H
2#define HALIDE_HALIDERUNTIMEVULKAN_H
3
4// Don't include HalideRuntime.h if the contents of it were already pasted into a generated header above this one
5#ifndef HALIDE_HALIDERUNTIME_H
6
7#include "HalideRuntime.h"
8
9#endif
10/** \file
11 * Routines specific to the Halide Vulkan runtime.
12 */
13
14#ifdef __cplusplus
15 extern "C" {
16#endif
17
18#define HALIDE_RUNTIME_VULKAN
19
20// Guard against redefining handles if vulkan.h was included elsewhere
21#ifndef VK_DEFINE_HANDLE
22
23#define HALIDE_VULKAN_DEFINE_HANDLE(object) typedef struct object##_T *(object);
24
25#ifndef HALIDE_VULKAN_USE_64_BIT_PTR_DEFINES
26#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__) || (defined(__riscv) && __riscv_xlen == 64)
27#define HALIDE_VULKAN_USE_64_BIT_PTR_DEFINES 1
28#else
29#define HALIDE_VULKAN_USE_64_BIT_PTR_DEFINES 0
30#endif
31#endif
32
33#ifndef HALIDE_VULKAN_DEFINE_NON_DISPATCHABLE_HANDLE
34#if (HALIDE_VULKAN_USE_64_BIT_PTR_DEFINES == 1)
35#define HALIDE_VULKAN_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef struct object##_T *(object);
36#else
37#define HALIDE_VULKAN_DEFINE_NON_DISPATCHABLE_HANDLE(object) typedef uint64_t(object);
38#endif
39#endif
40
41 HALIDE_VULKAN_DEFINE_HANDLE(VkInstance)
42 HALIDE_VULKAN_DEFINE_HANDLE(VkPhysicalDevice)
43 HALIDE_VULKAN_DEFINE_HANDLE(VkDevice)
44 HALIDE_VULKAN_DEFINE_HANDLE(VkQueue)
45 HALIDE_VULKAN_DEFINE_NON_DISPATCHABLE_HANDLE(VkCommandPool)
46 HALIDE_VULKAN_DEFINE_NON_DISPATCHABLE_HANDLE(VkDebugUtilsMessengerEXT)
47
48#endif
49
50 extern const struct halide_device_interface_t *halide_vulkan_device_interface();
51
52/** These are forward declared here to allow clients to override the
53 * Halide Vulkan runtime. Do not call them. */
54// @{
55 extern int halide_vulkan_initialize_kernels(void *user_context, void **state_ptr,
56 const char *src, int size);
57
58 extern int halide_vulkan_run(void *user_context,
59 void *state_ptr,
60 const char *entry_name,
61 int blocksX, int blocksY, int blocksZ,
62 int threadsX, int threadsY, int threadsZ,
63 int shared_mem_bytes,
64 size_t arg_sizes[],
65 void *args[],
66 int8_t arg_is_buffer[]);
67
68 extern void halide_vulkan_finalize_kernels(void *user_context, void *state_ptr);
69
70// @}
71
72// The default implementation of halide_acquire_vulkan_context uses
73// the global pointers above, and serializes access with a spin lock.
74// Overriding implementations of acquire/release must implement the
75// following behavior:
76
77// - halide_acquire_vulkan_context should always store a valid
78// instance/device/queue in the corresponding out parameters,
79// or return an error code.
80// - A call to halide_acquire_vulkan_context is followed by a matching
81// call to halide_release_vulkan_context. halide_acquire_vulkan_context
82// should block while a previous call (if any) has not yet been
83// released via halide_release_vulkan_context.
84// - Parameters:
85// allocator: an internal halide type handle used for allocating resources
86// instance: the vulkan instance handle
87// device: the vulkan device handle
88// physical_device: the vulkan physical device handle
89// queue: the vulkan queue handle
90// queue_family_index: the index corresponding to the device queue properties for the device (as described by vkGetPhysicalDeviceQueueFamilyProperties)
91// create: if set to true, attempt to create a new vulkan context, otherwise acquire the current one
92 struct halide_vulkan_memory_allocator;
93 extern int halide_vulkan_acquire_context(void *user_context,
94 struct halide_vulkan_memory_allocator **allocator,
95 VkInstance *instance,
96 VkDevice *device,
97 VkPhysicalDevice *physical_device,
98 VkQueue *queue,
99 uint32_t *queue_family_index,
100 VkDebugUtilsMessengerEXT *messenger,
101 bool create = true);
102
103 extern int halide_vulkan_release_context(void *user_context,
104 VkInstance instance,
105 VkDevice device,
106 VkQueue queue,
107 VkDebugUtilsMessengerEXT messenger);
108// --
109
110// Override the default allocation callbacks (default uses Vulkan runtime implementation)
111 extern void halide_vulkan_set_allocation_callbacks(const struct VkAllocationCallbacks *callbacks);
112
113// Access the current allocation callbacks
114// -- may return nullptr ... which indicates the default Vulkan runtime implementation is being used)
115 extern const struct VkAllocationCallbacks *halide_vulkan_get_allocation_callbacks(void *user_context);
116
117// Access methods to assign/retrieve required layer names for the context
118 extern void halide_vulkan_set_layer_names(const char *n);
119 extern const char *halide_vulkan_get_layer_names(void *user_context);
120
121// Access methods to assign/retrieve required externsion names for the context
122 extern void halide_vulkan_set_extension_names(const char *n);
123 extern const char *halide_vulkan_get_extension_names(void *user_context);
124
125// Access methods to assign/retrieve required device type names for the context (either "cpu", "gpu" (any), "discrete-gpu" (only), "virtual-gpu" (sw))
126 extern void halide_vulkan_set_device_type(const char *n);
127 extern const char *halide_vulkan_get_device_type(void *user_context);
128
129// Access methods to assign/retrieve specific build options to the Vulkan runtime compiler
130 extern void halide_vulkan_set_build_options(const char *n);
131 extern const char *halide_vulkan_get_build_options(void *user_context);
132
133#ifdef __cplusplus
134} // End extern "C"
135#endif
136
137#endif // HALIDE_HALIDERUNTIMEVULKAN_H
HalideRuntime.h
This file declares the routines used by Halide internally in its runtime.
halide_vulkan_get_layer_names
const char * halide_vulkan_get_layer_names(void *user_context)
Definition vulkan_extensions.h:330
HALIDE_VULKAN_DEFINE_NON_DISPATCHABLE_HANDLE
#define HALIDE_VULKAN_DEFINE_NON_DISPATCHABLE_HANDLE(object)
Definition HalideRuntimeVulkan.h:37
halide_vulkan_initialize_kernels
int halide_vulkan_initialize_kernels(void *user_context, void **state_ptr, const char *src, int size)
These are forward declared here to allow clients to override the Halide Vulkan runtime.
halide_vulkan_set_extension_names
void halide_vulkan_set_extension_names(const char *n)
Definition vulkan_extensions.h:335
halide_vulkan_acquire_context
int halide_vulkan_acquire_context(void *user_context, struct halide_vulkan_memory_allocator **allocator, VkInstance *instance, VkDevice *device, VkPhysicalDevice *physical_device, VkQueue *queue, uint32_t *queue_family_index, VkDebugUtilsMessengerEXT *messenger, bool create=true)
halide_vulkan_get_allocation_callbacks
const struct VkAllocationCallbacks * halide_vulkan_get_allocation_callbacks(void *user_context)
Definition vulkan_memory.h:1501
halide_vulkan_set_build_options
void halide_vulkan_set_build_options(const char *n)
Definition vulkan_extensions.h:355
halide_vulkan_set_layer_names
void halide_vulkan_set_layer_names(const char *n)
Definition vulkan_extensions.h:325
halide_vulkan_release_context
int halide_vulkan_release_context(void *user_context, VkInstance instance, VkDevice device, VkQueue queue, VkDebugUtilsMessengerEXT messenger)
halide_vulkan_set_device_type
void halide_vulkan_set_device_type(const char *n)
Definition vulkan_extensions.h:345
halide_vulkan_get_extension_names
const char * halide_vulkan_get_extension_names(void *user_context)
Definition vulkan_extensions.h:340
halide_vulkan_get_device_type
const char * halide_vulkan_get_device_type(void *user_context)
Definition vulkan_extensions.h:350
halide_vulkan_run
int halide_vulkan_run(void *user_context, void *state_ptr, const char *entry_name, int blocksX, int blocksY, int blocksZ, int threadsX, int threadsY, int threadsZ, int shared_mem_bytes, size_t arg_sizes[], void *args[], int8_t arg_is_buffer[])
halide_vulkan_device_interface
const struct halide_device_interface_t * halide_vulkan_device_interface()
halide_vulkan_finalize_kernels
void halide_vulkan_finalize_kernels(void *user_context, void *state_ptr)
HALIDE_VULKAN_DEFINE_HANDLE
#define HALIDE_VULKAN_DEFINE_HANDLE(object)
Definition HalideRuntimeVulkan.h:23
halide_vulkan_set_allocation_callbacks
void halide_vulkan_set_allocation_callbacks(const struct VkAllocationCallbacks *callbacks)
halide_vulkan_get_build_options
const char * halide_vulkan_get_build_options(void *user_context)
Definition vulkan_extensions.h:360
uint32_t
unsigned __INT32_TYPE__ uint32_t
Definition runtime_internal.h:25
int8_t
signed __INT8_TYPE__ int8_t
Definition runtime_internal.h:28
halide_device_interface_t
Each GPU API provides a halide_device_interface_t struct pointing to the code that manages device all...
Definition HalideRuntime.h:797
user_context
void * user_context
Definition vulkan_resources.h:178
allocator
VulkanMemoryAllocator * allocator
Definition vulkan_resources.h:179