ae2f_docs
vk.h
Go to the documentation of this file.
1#include <vulkan/vulkan_core.h>
2
3#include <assert.h>
4#include <stdio.h>
5#include <string.h>
6#include <stdlib.h>
7
8VkResult vkres = VK_SUCCESS;
9
10static VkInstanceCreateInfo vulkancreat;
11static VkInstance vulkan;
12
13static VkPhysicalDevice vkphydev;
14static uint32_t vkphydevcount = 0;
15static VkPhysicalDeviceMemoryProperties vkphydevmemprops;
16
17static VkDevice vkdev;
18static VkDeviceCreateInfo vkdevcreat;
19static VkQueue vkqueue;
20
21static uint32_t find_queue_family(VkPhysicalDevice phydev) {
22 uint32_t queueFamilyCount = 0;
23 vkGetPhysicalDeviceQueueFamilyProperties(
24 phydev
25 , &queueFamilyCount
26 , NULL
27 );
28
29 union upVkQueueFamilyProperties {
30 void* v;
31 VkQueueFamilyProperties* p;
32 } queueFamilies;
33
34 queueFamilies.v = malloc(queueFamilyCount * sizeof(VkQueueFamilyProperties));
35
36 vkGetPhysicalDeviceQueueFamilyProperties(
37 phydev
38 , &queueFamilyCount
39 , queueFamilies.p
40 );
41
42 uint32_t queueFamilyIndex = UINT32_MAX;
43 for (uint32_t i = 0; i < queueFamilyCount; i++) {
44 if (queueFamilies.p[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
45 queueFamilyIndex = i;
46 break;
47 }
48 }
49 free(queueFamilies.v);
50 return queueFamilyIndex;
51}
52
53static void Test_VkInit() {
54 vkdev = 0;
55 vulkan = 0;
56 vkphydevcount = 0;
57 vkphydev = 0;
58 memset(&vkphydevmemprops, 0, sizeof(vkphydevmemprops));
59 memset(&vkdevcreat, 0, sizeof(vkdevcreat));
60 memset(&vulkancreat, 0, sizeof(vulkancreat));
61
62
63 vulkancreat.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
64 vulkancreat.enabledExtensionCount = 0;
65 vulkancreat.enabledLayerCount = 0;
66 vulkancreat.ppEnabledExtensionNames = 0;
67 vulkancreat.ppEnabledLayerNames = 0;
68 vulkancreat.flags = 0;
69 vulkancreat.pApplicationInfo = NULL;
70
71 vkres = vkCreateInstance(&vulkancreat, 0, &vulkan);
72 printf("vkCreateInstance result: %d\n", vkres);
73 assert(vkres == VK_SUCCESS && "vkCreateInstance has failed");
74
75 vkphydevcount = 0;
76
77 vkres = vkEnumeratePhysicalDevices(
78 vulkan
79 , &vkphydevcount
80 , 0
81 );
82
83 assert(vkres == VK_SUCCESS);
84 assert(vkphydevcount && "vkphydevcount must be greater than 0.");
85 printf("Number of Physical Device available: %u\n", vkphydevcount);
86
87 vkphydevcount = 1;
88
89 vkres = vkEnumeratePhysicalDevices(
90 vulkan
91 , &vkphydevcount
92 , &vkphydev
93 );
94
95 assert(vkres == VK_SUCCESS && "vkEnumeratePhysicalDevices has failed.");
96 assert(vkphydevcount != 0 && "vkphydevcount has changed, which is not expected.");
97 assert(vkphydev && "vkphydev is no initialised");
98
99 vkphydevcount = 1;
100
101 vkdevcreat.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
102
103 // Find a queue family
104 uint32_t queueFamilyIndex = find_queue_family(vkphydev);
105 assert(queueFamilyIndex != UINT32_MAX && "No suitable queue family found");
106
107 // Initialize VkDeviceQueueCreateInfo
108 float queuePriority = 1.0f;
109 VkDeviceQueueCreateInfo queueCreateInfo;
110 memset(&queueCreateInfo, 0, sizeof(queueCreateInfo));
111
112 queueCreateInfo.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
113 queueCreateInfo.queueFamilyIndex = queueFamilyIndex;
114 queueCreateInfo.queueCount = 1;
115 queueCreateInfo.pQueuePriorities = &queuePriority;
116
117 // Initialize VkDeviceCreateInfo
118 vkdevcreat.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
119 vkdevcreat.queueCreateInfoCount = 1;
120 vkdevcreat.pQueueCreateInfos = &queueCreateInfo;
121 vkdevcreat.enabledExtensionCount = 0;
122 vkdevcreat.ppEnabledExtensionNames = NULL;
123 vkdevcreat.enabledLayerCount = 0;
124 vkdevcreat.ppEnabledLayerNames = NULL;
125 vkdevcreat.flags = 0;
126
127 vkres = vkCreateDevice(
128 vkphydev
129 , &vkdevcreat
130 , 0
131 , &vkdev
132 );
133
134 vkGetDeviceQueue(
135 vkdev
136 , queueFamilyIndex
137 , 0
138 , &vkqueue
139 );
140
141 assert(vkres == VK_SUCCESS && "vkCreateDevice has failed.");
142 assert(vkdev && "vkdev is not initialised");
143
144 vkGetPhysicalDeviceMemoryProperties(
145 vkphydev
146 , &vkphydevmemprops
147 );
148
149 puts("Test_VkInit has done.");
150}
151
152static void Test_VkEnd() {
153 if(vkdev) vkDestroyDevice(vkdev, 0);
154 if(vulkan) vkDestroyInstance(vulkan, 0);
155}
void ae2f_AnnAct_t(ae2f_float_t *ret, ae2f_float_t x)
Customisable activasion function type.
Definition Act.h:19
#define ae2f_float
Predefined floating point type.
Definition Float.auto.h:17
#define NULL_GENERIC(T)
Definition MlpInit.c:14
#define __ae2fVK_AnnMlpClean_imp(v_mlp)
Definition Mlp.auto.h:524
#define __ae2fVK_AnnMlpMk_imp(v_mk, iv_weight_opt, iv_bias_opt, iv_outstream_opt, iv_deltastream_opt, i_len_count, i_len, i_len_swap, i_prm_offset, i_extra, i_act, i_actderiv, i_lossderiv, i_learningrate, i_learningrate_bias, i_vkdev, i_vkmemprops, iv_vkalloccalls, i_vkcldeclaration, i_vkcldefinition)
Make MLP with OpenCL compute shader.
Definition Mlp.auto.h:65
VkResult vkres
Definition vk.h:8