Halide
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 
21 
22 /** These are forward declared here to allow clients to override the
23  * Halide Vulkan runtime. Do not call them. */
24 // @{
25 extern int halide_vulkan_initialize_kernels(void *user_context, void **state_ptr,
26  const char *src, int size);
27 
28 extern int halide_vulkan_run(void *user_context,
29  void *state_ptr,
30  const char *entry_name,
31  int blocksX, int blocksY, int blocksZ,
32  int threadsX, int threadsY, int threadsZ,
33  int shared_mem_bytes,
34  size_t arg_sizes[],
35  void *args[],
36  int8_t arg_is_buffer[]);
37 
38 extern void halide_vulkan_finalize_kernels(void *user_context, void *state_ptr);
39 
40 // @}
41 
42 // The default implementation of halide_acquire_vulkan_context uses
43 // the global pointers above, and serializes access with a spin lock.
44 // Overriding implementations of acquire/release must implement the
45 // following behavior:
46 
47 // - halide_acquire_vulkan_context should always store a valid
48 // instance/device/queue in the corresponding out parameters,
49 // or return an error code.
50 // - A call to halide_acquire_vulkan_context is followed by a matching
51 // call to halide_release_vulkan_context. halide_acquire_vulkan_context
52 // should block while a previous call (if any) has not yet been
53 // released via halide_release_vulkan_context.
54 // - Parameters:
55 // allocator: an internal halide type handle used for allocating resources
56 // instance: the vulkan instance handle
57 // device: the vulkan device handle
58 // physical_device: the vulkan physical device handle
59 // command_pool: the vulkan command pool handle (strangely doesn't have a VkCommandPool_T typedef)
60 // queue: the vulkan queue handle
61 // queue_family_index: the index corresponding to the device queue properties for the device (as described by vkGetPhysicalDeviceQueueFamilyProperties)
62 // create: if set to true, attempt to create a new vulkan context, otherwise acquire the current one
63 struct halide_vulkan_memory_allocator;
64 extern int halide_vulkan_acquire_context(void *user_context,
65  struct halide_vulkan_memory_allocator **allocator,
66  struct VkInstance_T **instance,
67  struct VkDevice_T **device,
68  struct VkPhysicalDevice_T **physical_device,
69  uint64_t *command_pool,
70  struct VkQueue_T **queue,
71  uint32_t *queue_family_index,
72  bool create = true);
73 
74 extern int halide_vulkan_release_context(void *user_context,
75  struct VkInstance_T *instance,
76  struct VkDevice_T *device,
77  struct VkQueue_T *queue);
78 
79 // --
80 
81 // Override the default allocation callbacks (default uses Vulkan runtime implementation)
82 extern void halide_vulkan_set_allocation_callbacks(const struct VkAllocationCallbacks *callbacks);
83 
84 // Access the current allocation callbacks
85 // -- may return nullptr ... which indicates the default Vulkan runtime implementation is being used)
86 extern const struct VkAllocationCallbacks *halide_vulkan_get_allocation_callbacks(void *user_context);
87 
88 // Access methods to assign/retrieve required layer names for the context
89 extern void halide_vulkan_set_layer_names(const char *n);
90 extern const char *halide_vulkan_get_layer_names(void *user_context);
91 
92 // Access methods to assign/retrieve required externsion names for the context
93 extern void halide_vulkan_set_extension_names(const char *n);
94 extern const char *halide_vulkan_get_extension_names(void *user_context);
95 
96 // Access methods to assign/retrieve required device type names for the context (either "cpu", "gpu" (any), "discrete-gpu" (only), "virtual-gpu" (sw))
97 extern void halide_vulkan_set_device_type(const char *n);
98 extern const char *halide_vulkan_get_device_type(void *user_context);
99 
100 // Access methods to assign/retrieve specific build options to the Vulkan runtime compiler
101 extern void halide_vulkan_set_build_options(const char *n);
102 extern const char *halide_vulkan_get_build_options(void *user_context);
103 
104 #ifdef __cplusplus
105 } // End extern "C"
106 #endif
107 
108 #endif // HALIDE_HALIDERUNTIMEVULKAN_H
halide_vulkan_set_layer_names
void halide_vulkan_set_layer_names(const char *n)
Definition: vulkan_extensions.h:277
int8_t
signed __INT8_TYPE__ int8_t
Definition: runtime_internal.h:28
halide_vulkan_get_build_options
const char * halide_vulkan_get_build_options(void *user_context)
Definition: vulkan_extensions.h:312
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:23
halide_vulkan_acquire_context
int halide_vulkan_acquire_context(void *user_context, struct halide_vulkan_memory_allocator **allocator, struct VkInstance_T **instance, struct VkDevice_T **device, struct VkPhysicalDevice_T **physical_device, uint64_t *command_pool, struct VkQueue_T **queue, uint32_t *queue_family_index, bool create=true)
halide_vulkan_device_interface
const struct halide_device_interface_t * halide_vulkan_device_interface()
halide_vulkan_get_layer_names
const char * halide_vulkan_get_layer_names(void *user_context)
Definition: vulkan_extensions.h:282
halide_vulkan_finalize_kernels
void halide_vulkan_finalize_kernels(void *user_context, void *state_ptr)
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_get_extension_names
const char * halide_vulkan_get_extension_names(void *user_context)
Definition: vulkan_extensions.h:292
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.
VkAllocationCallbacks
Definition: mini_vulkan.h:1449
halide_vulkan_set_build_options
void halide_vulkan_set_build_options(const char *n)
Definition: vulkan_extensions.h:307
HalideRuntime.h
halide_vulkan_set_device_type
void halide_vulkan_set_device_type(const char *n)
Definition: vulkan_extensions.h:297
halide_vulkan_set_allocation_callbacks
void halide_vulkan_set_allocation_callbacks(const struct VkAllocationCallbacks *callbacks)
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:770
halide_vulkan_get_allocation_callbacks
const struct VkAllocationCallbacks * halide_vulkan_get_allocation_callbacks(void *user_context)
Definition: vulkan_memory.h:1213
halide_vulkan_get_device_type
const char * halide_vulkan_get_device_type(void *user_context)
Definition: vulkan_extensions.h:302
uint32_t
unsigned __INT32_TYPE__ uint32_t
Definition: runtime_internal.h:25
halide_vulkan_set_extension_names
void halide_vulkan_set_extension_names(const char *n)
Definition: vulkan_extensions.h:287
halide_vulkan_release_context
int halide_vulkan_release_context(void *user_context, struct VkInstance_T *instance, struct VkDevice_T *device, struct VkQueue_T *queue)