Halide 19.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
15extern "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
42HALIDE_VULKAN_DEFINE_HANDLE(VkPhysicalDevice)
47
48#endif
49
51
52/** These are forward declared here to allow clients to override the
53 * Halide Vulkan runtime. Do not call them. */
54// @{
55extern int halide_vulkan_initialize_kernels(void *user_context, void **state_ptr,
56 const char *src, int size);
57
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
68extern 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
92struct halide_vulkan_memory_allocator;
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
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)
111extern 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)
115extern const struct VkAllocationCallbacks *halide_vulkan_get_allocation_callbacks(void *user_context);
116
117// Access methods to assign/retrieve required layer names for the context
118extern void halide_vulkan_set_layer_names(const char *n);
119extern const char *halide_vulkan_get_layer_names(void *user_context);
120
121// Access methods to assign/retrieve required externsion names for the context
122extern void halide_vulkan_set_extension_names(const char *n);
123extern 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))
126extern void halide_vulkan_set_device_type(const char *n);
127extern 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
130extern void halide_vulkan_set_build_options(const char *n);
131extern 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
This file declares the routines used by Halide internally in its runtime.
const char * halide_vulkan_get_layer_names(void *user_context)
#define HALIDE_VULKAN_DEFINE_NON_DISPATCHABLE_HANDLE(object)
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.
void halide_vulkan_set_extension_names(const char *n)
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)
const struct VkAllocationCallbacks * halide_vulkan_get_allocation_callbacks(void *user_context)
void halide_vulkan_set_build_options(const char *n)
void halide_vulkan_set_layer_names(const char *n)
int halide_vulkan_release_context(void *user_context, VkInstance instance, VkDevice device, VkQueue queue, VkDebugUtilsMessengerEXT messenger)
void halide_vulkan_set_device_type(const char *n)
const char * halide_vulkan_get_extension_names(void *user_context)
const char * halide_vulkan_get_device_type(void *user_context)
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[])
const struct halide_device_interface_t * halide_vulkan_device_interface()
void halide_vulkan_finalize_kernels(void *user_context, void *state_ptr)
#define HALIDE_VULKAN_DEFINE_HANDLE(object)
void halide_vulkan_set_allocation_callbacks(const struct VkAllocationCallbacks *callbacks)
const char * halide_vulkan_get_build_options(void *user_context)
unsigned __INT32_TYPE__ uint32_t
signed __INT8_TYPE__ int8_t
Each GPU API provides a halide_device_interface_t struct pointing to the code that manages device all...
void * user_context
VulkanMemoryAllocator * allocator