1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
|
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "vulkan/vulkan.h"
#include "ze_ddi.h"
#include "u_math.h"
#include "os_memory.h"
#include "os_time.h"
#include "zev_private.h"
static struct zev_driver glob_state;
static void zev_cmd_list_sync(struct zev_command_list *cmd_list);
static ze_result_t ze_vk_err(VkResult result)
{
switch (result) {
case VK_SUCCESS:
return ZE_RESULT_SUCCESS;
case VK_ERROR_OUT_OF_HOST_MEMORY:
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
return ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY;
case VK_ERROR_DEVICE_LOST:
return ZE_RESULT_ERROR_DEVICE_LOST;
case VK_ERROR_INITIALIZATION_FAILED:
return ZE_RESULT_ERROR_UNINITIALIZED;
case VK_TIMEOUT:
default:
return ZE_RESULT_NOT_READY;
}
}
static ze_result_t zev_Init(ze_init_flag_t flags)
{
uint32_t instance_prop_count = 0;
bool have_ext_memory_cap = false;
bool have_phys_dev_props2 = false;
vkEnumerateInstanceExtensionProperties(NULL, &instance_prop_count, NULL);
if (instance_prop_count > 0) {
VkExtensionProperties *inst_props = malloc(instance_prop_count * sizeof(VkExtensionProperties));
if (!inst_props)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
vkEnumerateInstanceExtensionProperties(NULL, &instance_prop_count, inst_props);
for (unsigned i = 0; i < instance_prop_count; i++) {
if (!strcmp(inst_props[i].extensionName, VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME))
have_ext_memory_cap = true;
if (!strcmp(inst_props[i].extensionName, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME))
have_phys_dev_props2 = true;
}
free(inst_props);
}
if (!have_ext_memory_cap || !have_phys_dev_props2)
return VK_ERROR_INITIALIZATION_FAILED;
const VkApplicationInfo app = {
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pNext = NULL,
.pApplicationName = "L0",
.applicationVersion = 0,
.pEngineName = "L0",
.engineVersion = 0,
.apiVersion = VK_API_VERSION_1_0,
};
const char *ext_list[] = { VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME,
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME };
VkInstanceCreateInfo inst_create = {
.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = NULL,
.pApplicationInfo = &app,
.enabledLayerCount = 0,
.ppEnabledLayerNames = NULL,
.enabledExtensionCount = 2,
.ppEnabledExtensionNames = ext_list,
};
VkResult res = vkCreateInstance(&inst_create, NULL, &glob_state.vk_inst);
if (res != VK_SUCCESS)
return ze_vk_err(res);
res = vkEnumeratePhysicalDevices(glob_state.vk_inst, &glob_state.dev_count, NULL);
if (glob_state.dev_count == 0)
return ZE_RESULT_ERROR_UNINITIALIZED;
VkPhysicalDevice *phys_devs = malloc(glob_state.dev_count * sizeof(VkPhysicalDevice));
if (!phys_devs) {
vkDestroyInstance(glob_state.vk_inst, NULL);
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
res = vkEnumeratePhysicalDevices(glob_state.vk_inst, &glob_state.dev_count, phys_devs);
glob_state.devs = calloc(glob_state.dev_count, sizeof(struct zev_device));
for (unsigned pd = 0; pd < glob_state.dev_count; pd++) {
struct zev_device *dev = &glob_state.devs[pd];
dev->phys_dev = phys_devs[pd];
bool dev_has_ext_host_memory = false, dev_has_mesa_lvl0 = false;
uint32_t dev_prop_count;
vkEnumerateDeviceExtensionProperties(dev->phys_dev, NULL, &dev_prop_count, NULL);
if (dev_prop_count >= 0) {
VkExtensionProperties *dev_props = malloc(dev_prop_count * sizeof(VkExtensionProperties));
vkEnumerateDeviceExtensionProperties(dev->phys_dev, NULL, &dev_prop_count, dev_props);
for (unsigned i = 0; i < dev_prop_count; i++) {
if (!strcmp(dev_props[i].extensionName, VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME))
dev_has_ext_host_memory = true;
if (!strcmp(dev_props[i].extensionName, VK_MESA_LVL0_EXTENSION_NAME))
dev_has_mesa_lvl0 = true;
}
}
if (!dev_has_ext_host_memory || !dev_has_mesa_lvl0) {
continue;
}
VkPhysicalDeviceExternalMemoryHostPropertiesEXT host_mem_props = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT,
.pNext = NULL,
};
VkPhysicalDeviceProperties2 props = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
.pNext = &host_mem_props,
};
vkGetPhysicalDeviceProperties2(phys_devs[pd], &props);
dev->props = props.properties;
dev->host_ptr_align = host_mem_props.minImportedHostPointerAlignment;
vkGetPhysicalDeviceFeatures(phys_devs[pd], &dev->feats);
vkGetPhysicalDeviceMemoryProperties(phys_devs[pd], &dev->mem_props);
vkGetPhysicalDeviceQueueFamilyProperties(phys_devs[pd], &dev->qf_count, NULL);
dev->qf = malloc(dev->qf_count * sizeof(VkQueueFamilyProperties));
if (!dev->qf)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
vkGetPhysicalDeviceQueueFamilyProperties(phys_devs[pd], &dev->qf_count, dev->qf);
const VkDeviceQueueCreateInfo q_create = {
.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.pNext = NULL,
.queueCount = 1,
};
const char *dev_ext_list[] = { VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME, VK_MESA_LVL0_EXTENSION_NAME };
VkDeviceCreateInfo dev_create_info = {
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
.pNext = NULL,
.queueCreateInfoCount = 1,
.pQueueCreateInfos = &q_create,
.enabledLayerCount = 0,
.enabledExtensionCount = 2,
.ppEnabledExtensionNames = dev_ext_list,
.pEnabledFeatures = NULL,
};
res = vkCreateDevice(phys_devs[pd], &dev_create_info, NULL, &dev->vk_dev);
if (res != VK_SUCCESS)
return ze_vk_err(res);
dev->get_kernel_input_map = (PFN_vkGetKernelInputMapMESA)vkGetDeviceProcAddr(dev->vk_dev, "vkGetKernelInputMapMESA");
dev->driver = &glob_state;
dev->queues = malloc(sizeof(struct zev_queue) * 1);
vkGetDeviceQueue(dev->vk_dev, 0, 0, &dev->queues[0].queue);
// TODO multiq
VkCommandPoolCreateInfo pool_create = {
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.pNext = NULL,
.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
.queueFamilyIndex = 0
};
res = vkCreateCommandPool(dev->vk_dev, &pool_create, NULL, &dev->queues[0].cmd_pool);
if (res)
return ze_vk_err(res);
VkDescriptorSetLayoutBinding input_binding = {
.binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_COMPUTE_BIT,
};
VkDescriptorSetLayoutCreateInfo desc_set_layout_create = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pNext = NULL,
.bindingCount = 1,
.pBindings = &input_binding,
};
res = vkCreateDescriptorSetLayout(dev->vk_dev,
&desc_set_layout_create, NULL,
&dev->input_layout);
VkDescriptorPoolCreateInfo desc_pool_create = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
.pNext = NULL,
.maxSets = 1,
.poolSizeCount = 1,
.pPoolSizes = &(VkDescriptorPoolSize){ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1024 },
};
vkCreateDescriptorPool(dev->vk_dev, &desc_pool_create, NULL, &dev->desc_pool);
}
glob_state.mem_allocs = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
_mesa_key_pointer_equal);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DriverGet(uint32_t *count, ze_driver_handle_t *drivers)
{
if (!count)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
*count = 1;
if (drivers)
drivers[0] = zev_driver_to_handle(&glob_state);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DriverGetDriverVersion(ze_driver_handle_t driver, uint32_t *version)
{
*version = ZE_MAKE_VERSION(0, 1);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DriverGetApiVersion(ze_driver_handle_t driver, ze_api_version_t *version)
{
if (!driver)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (!version)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
*version = ZE_API_VERSION_1_0;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DriverGetIPCProperties(ze_driver_handle_t driver, ze_driver_ipc_properties_t *ipc_properties)
{
memset(ipc_properties, 0, sizeof(*ipc_properties));
ipc_properties->version = ZE_DRIVER_IPC_PROPERTIES_VERSION_CURRENT;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DriverGetProperties(ze_driver_handle_t driver,
ze_driver_properties_t *p_driver_properties)
{
memset(p_driver_properties, 0, sizeof(*p_driver_properties));
p_driver_properties->version = ZE_DRIVER_PROPERTIES_VERSION_CURRENT;
p_driver_properties->driverVersion = 1;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DriverGetExtensionFunctionAddress(ze_driver_handle_t driver, const char *func_name, void **func)
{
if (strcmp(func_name, "zeInit") == 0)
*func = &zev_Init;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceGet(ze_driver_handle_t driver, uint32_t *count, ze_device_handle_t *devices)
{
struct zev_driver *drv = zev_driver_from_handle(driver);
if (!drv)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (!count)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
*count = drv->dev_count;
if (devices) {
for (unsigned i = 0; i < drv->dev_count; i++) {
devices[i] = (ze_device_handle_t)&drv->devs[i];
}
}
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceGetSubDevices(ze_device_handle_t device, uint32_t *count, ze_device_handle_t *sub_devices)
{
*count = 0;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceGetProperties(ze_device_handle_t _device, ze_device_properties_t *props)
{
if (!_device)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (!props)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
ZEV_FROM_HANDLE(zev_device, device, _device);
memset(props, 0, sizeof(*props));
props->type = ZE_DEVICE_TYPE_GPU;
props->version = ZE_DEVICE_PROPERTIES_VERSION_CURRENT;
props->vendorId = device->props.vendorID;
props->deviceId = device->props.deviceID;
memcpy(props->name, device->props.deviceName, ZE_MAX_DEVICE_NAME);
memcpy(&props->uuid, device->props.pipelineCacheUUID, VK_UUID_SIZE);
props->isSubdevice = 0;
props->unifiedMemorySupported = 0;
props->maxCommandQueues = 0;
props->numAsyncComputeEngines = 0;
props->numAsyncCopyEngines = 0;
for (unsigned q = 0; q < device->qf_count; q++) {
if (device->qf[q].queueFlags & VK_QUEUE_GRAPHICS_BIT)
props->maxCommandQueues = device->qf[q].queueCount;
else if (device->qf[q].queueFlags & VK_QUEUE_COMPUTE_BIT)
props->numAsyncComputeEngines = device->qf[q].queueCount;
else if (device->qf[q].queueFlags & VK_QUEUE_TRANSFER_BIT)
props->numAsyncCopyEngines = device->qf[q].queueCount;
}
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceGetComputeProperties(ze_device_handle_t _device,
ze_device_compute_properties_t *compute_props)
{
ZEV_FROM_HANDLE(zev_device, device, _device);
compute_props->maxTotalGroupSize = device->props.limits.maxComputeWorkGroupInvocations;
compute_props->maxGroupSizeX = device->props.limits.maxComputeWorkGroupSize[0];
compute_props->maxGroupSizeY = device->props.limits.maxComputeWorkGroupSize[1];
compute_props->maxGroupSizeZ = device->props.limits.maxComputeWorkGroupSize[2];
compute_props->maxGroupCountX = device->props.limits.maxComputeWorkGroupCount[0];
compute_props->maxGroupCountY = device->props.limits.maxComputeWorkGroupCount[1];
compute_props->maxGroupCountZ = device->props.limits.maxComputeWorkGroupCount[2];
compute_props->maxSharedLocalMemory = device->props.limits.maxComputeSharedMemorySize;
compute_props->numSubGroupSizes = 1;
compute_props->subGroupSizes[0] = 32;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceGetCacheProperties(ze_device_handle_t _device,
ze_device_cache_properties_t *p_cache_properties)
{
memset(p_cache_properties, 0, sizeof(*p_cache_properties));
p_cache_properties->version = ZE_DEVICE_CACHE_PROPERTIES_VERSION_CURRENT;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceGetImageProperties(ze_device_handle_t _device,
ze_device_image_properties_t *p_image_properties)
{
memset(p_image_properties, 0, sizeof(*p_image_properties));
p_image_properties->version = ZE_DEVICE_IMAGE_PROPERTIES_VERSION_CURRENT;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceGetKernelProperties(ze_device_handle_t _device,
ze_device_kernel_properties_t *p_kernel_properties)
{
memset(p_kernel_properties, 0, sizeof(*p_kernel_properties));
p_kernel_properties->version = ZE_DEVICE_KERNEL_PROPERTIES_VERSION_CURRENT;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceGetMemoryProperties(ze_device_handle_t _device,
uint32_t *p_count,
ze_device_memory_properties_t *p_mem_properties)
{
if (*p_count == 0) {
*p_count = 1;
return ZE_RESULT_SUCCESS;
}
ze_device_memory_properties_t props = {
.version = ZE_DEVICE_MEMORY_PROPERTIES_VERSION_CURRENT,
.maxClockRate = 0,
.maxBusWidth = 128,
.totalSize = 1024*1024*1024*1,
};
*p_mem_properties = props;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceGetMemoryAccessProperties(ze_device_handle_t _device,
ze_device_memory_access_properties_t *p_mem_access_properties)
{
memset(p_mem_access_properties, 0, sizeof(*p_mem_access_properties));
p_mem_access_properties->version = ZE_DEVICE_MEMORY_ACCESS_PROPERTIES_VERSION_CURRENT;
p_mem_access_properties->hostAllocCapabilities = ZE_MEMORY_ACCESS;
p_mem_access_properties->deviceAllocCapabilities = ZE_MEMORY_ACCESS;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DeviceCanAccessPeer(ze_device_handle_t _device,
ze_device_handle_t _peer,
ze_bool_t *value)
{
*value = 0;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DriverAllocSharedMem(ze_driver_handle_t _driver,
const ze_device_mem_alloc_desc_t* device_desc,
const ze_host_mem_alloc_desc_t* host_desc,
size_t size, size_t alignment, ze_device_handle_t _device,
void **pptr)
{
if (!_driver)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
ZEV_FROM_HANDLE(zev_driver, driver, _driver);
ZEV_FROM_HANDLE(zev_device, device, _device);
int mtc = -1;
for (unsigned i = 0; i < device->mem_props.memoryTypeCount; i++) {
if (!(device->mem_props.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
continue;
mtc = i;
}
if (mtc == -1)
mtc = 0;
/* find device memory type from flags. */
/* need to put a hash table in here */
struct zev_memory_allocation *alloc_info = malloc(sizeof(struct zev_memory_allocation));
if (!alloc_info)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
alloc_info->size = size;
alloc_info->alignment = alignment;
alloc_info->type = ZEV_MEMORY_SHARED;
alloc_info->device = device;
VkMemoryAllocateInfo vk_alloc_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = NULL,
.allocationSize = size,
.memoryTypeIndex = 0,
};
VkResult result = vkAllocateMemory(device->vk_dev, &vk_alloc_info, NULL, &alloc_info->vk_dev_mem);
if (result != VK_SUCCESS)
return ze_vk_err(result);
alloc_info->base = alloc_info;
/* if we have to copy device memory - need to create a buffer around it. */
VkBufferCreateInfo buffer_create_info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.size = size,
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT|VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
};
result = vkCreateBuffer(device->vk_dev, &buffer_create_info, NULL, &alloc_info->vk_buf_mem);
vkBindBufferMemory(device->vk_dev, alloc_info->vk_buf_mem, alloc_info->vk_dev_mem, 0);
vkMapMemory(device->vk_dev, alloc_info->vk_dev_mem, 0, alloc_info->size, 0, pptr);
struct hash_entry *entry = _mesa_hash_table_insert(driver->mem_allocs,
*pptr, alloc_info);
if (!entry)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
return ze_vk_err(result);
}
static ze_result_t zev_DriverAllocDeviceMem(ze_driver_handle_t _driver,
const ze_device_mem_alloc_desc_t *device_desc,
size_t size,
size_t alignment,
ze_device_handle_t _device,
void **pptr)
{
if (!_driver)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
ZEV_FROM_HANDLE(zev_driver, driver, _driver);
ZEV_FROM_HANDLE(zev_device, device, _device);
int mtc = -1;
for (unsigned i = 0; i < device->mem_props.memoryTypeCount; i++) {
if (!(device->mem_props.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT))
continue;
mtc = i;
}
if (mtc == -1)
mtc = 0;
/* find device memory type from flags. */
/* need to put a hash table in here */
struct zev_memory_allocation *alloc_info = malloc(sizeof(struct zev_memory_allocation));
if (!alloc_info)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
alloc_info->size = size;
alloc_info->alignment = alignment;
alloc_info->type = ZEV_MEMORY_DEVICE;
alloc_info->device = device;
VkMemoryAllocateInfo vk_alloc_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = NULL,
.allocationSize = size,
.memoryTypeIndex = 0,
};
VkResult result = vkAllocateMemory(device->vk_dev, &vk_alloc_info, NULL, &alloc_info->vk_dev_mem);
if (result != VK_SUCCESS)
return ze_vk_err(result);
alloc_info->base = alloc_info;
*pptr = alloc_info->base;
/* if we have to copy device memory - need to create a buffer around it. */
VkBufferCreateInfo buffer_create_info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.size = size,
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT|VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
};
result = vkCreateBuffer(device->vk_dev, &buffer_create_info, NULL, &alloc_info->vk_buf_mem);
vkBindBufferMemory(device->vk_dev, alloc_info->vk_buf_mem, alloc_info->vk_dev_mem, 0);
struct hash_entry *entry = _mesa_hash_table_insert(driver->mem_allocs,
alloc_info->base, alloc_info);
if (!entry)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
return ze_vk_err(result);
}
static ze_result_t zev_DriverAllocHostMem(ze_driver_handle_t _driver,
const ze_host_mem_alloc_desc_t *host_desc,
size_t size,
size_t alignment,
void **pptr)
{
ZEV_FROM_HANDLE(zev_driver, driver, _driver);
struct zev_memory_allocation *alloc_info = malloc(sizeof(struct zev_memory_allocation));
void *ptr;
assert(driver->dev_count == 1);
if (!alloc_info)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
alloc_info->size = size;
alloc_info->alignment = alignment;
alloc_info->type = ZEV_MEMORY_HOST;
size = align(size, driver->devs[0].host_ptr_align);
alignment = align(alignment, driver->devs[0].host_ptr_align);
ptr = os_malloc_aligned(size, alignment);
alloc_info->base = ptr;
VkImportMemoryHostPointerInfoEXT host_info = {
.sType = VK_STRUCTURE_TYPE_IMPORT_MEMORY_HOST_POINTER_INFO_EXT,
.pNext = NULL,
.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT,
.pHostPointer = ptr,
};
VkMemoryAllocateInfo vk_alloc_info = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.pNext = &host_info,
.allocationSize = size,
.memoryTypeIndex = 0,
};
struct zev_device *device = &driver->devs[0];
//TODO import into each device?
VkResult result = vkAllocateMemory(device->vk_dev, &vk_alloc_info, NULL, &alloc_info->vk_dev_mem);
if (result != VK_SUCCESS)
return ze_vk_err(result);
/* if we have to copy device memory - need to create a buffer around it. */
VkBufferCreateInfo buffer_create_info = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.size = size,
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT|VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
};
result = vkCreateBuffer(device->vk_dev, &buffer_create_info, NULL, &alloc_info->vk_buf_mem);
vkBindBufferMemory(device->vk_dev, alloc_info->vk_buf_mem, alloc_info->vk_dev_mem, 0);
struct hash_entry *entry = _mesa_hash_table_insert(driver->mem_allocs,
ptr, alloc_info);
if (!entry)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
*pptr = ptr;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DriverFreeMem(ze_driver_handle_t _driver,
void *ptr)
{
if (!_driver)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (!ptr)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
ZEV_FROM_HANDLE(zev_driver, driver, _driver);
struct hash_entry *entry = _mesa_hash_table_search(driver->mem_allocs, ptr);
if (!entry)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
struct zev_memory_allocation *alloc_info = entry->data;
if (alloc_info->type == ZEV_MEMORY_HOST)
os_free_aligned(alloc_info->base);
else if (alloc_info->type == ZEV_MEMORY_DEVICE || alloc_info->type == ZEV_MEMORY_SHARED) {
if (alloc_info->type == ZEV_MEMORY_SHARED)
vkUnmapMemory(alloc_info->device->vk_dev, alloc_info->vk_dev_mem);
vkDestroyBuffer(alloc_info->device->vk_dev, alloc_info->vk_buf_mem, NULL);
vkFreeMemory(alloc_info->device->vk_dev, alloc_info->vk_dev_mem, NULL);
}
_mesa_hash_table_remove(driver->mem_allocs, entry);
free(alloc_info);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_DriverGetMemAddressRange(ze_driver_handle_t _driver,
const void *ptr,
void **p_base,
size_t *p_size)
{
if (_driver == NULL)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
if (ptr == NULL)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
ZEV_FROM_HANDLE(zev_driver, driver, _driver);
struct hash_entry *entry = _mesa_hash_table_search(driver->mem_allocs, ptr);
if (!entry)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
struct zev_memory_allocation *alloc_info = entry->data;
if (p_base)
*p_base = alloc_info->base;
if (p_size)
*p_size = alloc_info->size;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandQueueCreate(ze_device_handle_t _device,
const ze_command_queue_desc_t *desc,
ze_command_queue_handle_t *command_queue)
{
ZEV_FROM_HANDLE(zev_device, device, _device);
struct zev_command_queue *cmdq;
cmdq = calloc(1, sizeof(struct zev_command_queue));
if (!cmdq)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
cmdq->desc = *desc;
cmdq->dev = device;
*command_queue = zev_command_queue_to_handle(cmdq);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandQueueDestroy(ze_command_queue_handle_t command_queue)
{
ZEV_FROM_HANDLE(zev_command_queue, cmdq, command_queue);
free(cmdq);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandQueueExecuteCommandLists(ze_command_queue_handle_t command_queue,
uint32_t num_command_lists,
ze_command_list_handle_t *command_lists,
ze_fence_handle_t _fence)
{
ZEV_FROM_HANDLE(zev_command_queue, cmdq, command_queue);
ZEV_FROM_HANDLE(zev_fence, fence, _fence);
struct zev_device *dev = cmdq->dev;
VkCommandBuffer *cmd_bufs = malloc(num_command_lists * sizeof(VkCommandBuffer));
if (!cmd_bufs)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
for (unsigned i = 0; i < num_command_lists; i++) {
struct zev_command_list *cmdl = zev_command_list_from_handle(command_lists[i]);
cmd_bufs[i] = cmdl->cmd_buffer;
}
VkSubmitInfo submit_info = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.pNext = NULL,
.commandBufferCount = num_command_lists,
.pCommandBuffers = cmd_bufs,
};
vkQueueSubmit(dev->queues[0].queue, 1, &submit_info, fence ? fence->fence : NULL);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandQueueSynchronize(ze_command_queue_handle_t command_queue,
uint32_t timeout)
{
ZEV_FROM_HANDLE(zev_command_queue, cmdq, command_queue);
struct zev_device *dev = cmdq->dev;
/* store last fence on this queue and wait for it? */
vkQueueWaitIdle(dev->queues[0].queue);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListCreate(ze_device_handle_t _device,
const ze_command_list_desc_t *desc,
ze_command_list_handle_t *cmd_list)
{
ZEV_FROM_HANDLE(zev_device, device, _device);
struct zev_command_list *cmdl;
cmdl = calloc(1, sizeof(struct zev_command_list));
if (!cmdl)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
VkResult res;
VkCommandBufferAllocateInfo alloc_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.pNext = NULL,
.commandPool = device->queues[0].cmd_pool,
.level = 0,
.commandBufferCount = 1,
};
res = vkAllocateCommandBuffers(device->vk_dev, &alloc_info, &cmdl->cmd_buffer);
if (res != VK_SUCCESS)
return ze_vk_err(res);
cmdl->dev = device;
VkCommandBufferBeginInfo begin_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = NULL,
.flags = 0,
.pInheritanceInfo = NULL
};
vkBeginCommandBuffer(cmdl->cmd_buffer, &begin_info);
*cmd_list = zev_command_list_to_handle(cmdl);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_submit_immediate(struct zev_command_list *cmdlist)
{
vkEndCommandBuffer(cmdlist->cmd_buffer);
VkSubmitInfo submit_info = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.pNext = NULL,
.commandBufferCount = 1,
.pCommandBuffers = &cmdlist->cmd_buffer,
};
vkQueueSubmit(cmdlist->dev->queues[0].queue, 1, &submit_info, NULL);
vkQueueWaitIdle(cmdlist->dev->queues[0].queue);
vkResetCommandBuffer(cmdlist->cmd_buffer, 0);
VkCommandBufferBeginInfo begin_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = NULL,
.flags = 0,
.pInheritanceInfo = NULL
};
vkBeginCommandBuffer(cmdlist->cmd_buffer, &begin_info);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListCreateImmediate(ze_device_handle_t _device,
const ze_command_queue_desc_t *desc,
ze_command_list_handle_t *cmd_list)
{
ZEV_FROM_HANDLE(zev_device, device, _device);
struct zev_command_list *cmdl;
cmdl = calloc(1, sizeof(struct zev_command_list));
if (!cmdl)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
VkResult res;
VkCommandBufferAllocateInfo alloc_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.pNext = NULL,
.commandPool = device->queues[0].cmd_pool,
.level = 0,
.commandBufferCount = 1,
};
res = vkAllocateCommandBuffers(device->vk_dev, &alloc_info, &cmdl->cmd_buffer);
if (res != VK_SUCCESS)
return ze_vk_err(res);
cmdl->dev = device;
cmdl->immediate = true;
VkCommandBufferBeginInfo begin_info = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = NULL,
.flags = 0,
.pInheritanceInfo = NULL
};
vkBeginCommandBuffer(cmdl->cmd_buffer, &begin_info);
*cmd_list = zev_command_list_to_handle(cmdl);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListDestroy(ze_command_list_handle_t _cmd_list)
{
if (!_cmd_list)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
ZEV_FROM_HANDLE(zev_command_list, cmdl, _cmd_list);
vkFreeCommandBuffers(cmdl->dev->vk_dev, cmdl->dev->queues[0].cmd_pool, 1, &cmdl->cmd_buffer);
free(cmdl);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListClose(ze_command_list_handle_t _cmd_list)
{
ZEV_FROM_HANDLE(zev_command_list, cmdl, _cmd_list);
vkEndCommandBuffer(cmdl->cmd_buffer);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListReset(ze_command_list_handle_t _cmd_list)
{
ZEV_FROM_HANDLE(zev_command_list, cmdl, _cmd_list);
vkResetCommandBuffer(cmdl->cmd_buffer, 0);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_FenceCreate(ze_command_queue_handle_t cmd_queue,
const ze_fence_desc_t *desc,
ze_fence_handle_t *p_fence)
{
ZEV_FROM_HANDLE(zev_command_queue, cmdq, cmd_queue);
struct zev_device *dev = cmdq->dev;
struct zev_fence *fence;
fence = malloc(sizeof(struct zev_fence));
if (!fence)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
fence->cmdq = cmdq;
VkFenceCreateInfo create_info = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.pNext = NULL,
.flags = 0,
};
VkResult res;
res = vkCreateFence(dev->vk_dev, &create_info, NULL, &fence->fence);
if (res != VK_SUCCESS)
return ze_vk_err(res);
*p_fence = zev_fence_to_handle(fence);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_FenceDestroy(ze_fence_handle_t _fence)
{
if (!_fence)
return ZE_RESULT_ERROR_INVALID_NULL_POINTER;
ZEV_FROM_HANDLE(zev_fence, fence, _fence);
vkDestroyFence(fence->cmdq->dev->vk_dev, fence->fence, NULL);
free(fence);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_FenceQueryStatus(ze_fence_handle_t _fence)
{
ZEV_FROM_HANDLE(zev_fence, fence, _fence);
VkResult res;
res = vkGetFenceStatus(fence->cmdq->dev->vk_dev, fence->fence);
return ze_vk_err(res);
}
static ze_result_t zev_FenceReset(ze_fence_handle_t _fence)
{
ZEV_FROM_HANDLE(zev_fence, fence, _fence);
vkResetFences(fence->cmdq->dev->vk_dev, 1, &fence->fence);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_FenceHostSynchronize(ze_fence_handle_t _fence,
uint32_t timeout)
{
ZEV_FROM_HANDLE(zev_fence, fence, _fence);
VkResult res;
res = vkWaitForFences(fence->cmdq->dev->vk_dev, 1, &fence->fence, VK_FALSE, timeout);
return ze_vk_err(res);
}
static ze_result_t zev_CommandListAppendLaunchKernel(ze_command_list_handle_t command_list,
ze_kernel_handle_t _kernel,
const ze_group_count_t *launch_args,
ze_event_handle_t signal_event,
uint32_t num_wait_events,
ze_event_handle_t *wait_events)
{
ZEV_FROM_HANDLE(zev_command_list, cmd_list, command_list);
ZEV_FROM_HANDLE(zev_kernel, kernel, _kernel);
if (num_wait_events) {
VkEvent *events = malloc(num_wait_events * sizeof(VkEvent));
for (unsigned i = 0; i < num_wait_events; i++) {
events[i] = zev_event_from_handle(wait_events[i])->event;
}
vkCmdWaitEvents(cmd_list->cmd_buffer, num_wait_events, events, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, NULL, 0, NULL, 0, NULL);
free(events);
}
vkCmdBindPipeline(cmd_list->cmd_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, kernel->pipeline);
vkCmdDispatch(cmd_list->cmd_buffer, launch_args->groupCountX, launch_args->groupCountY, launch_args->groupCountZ);
if (signal_event) {
ZEV_FROM_HANDLE(zev_event, sig_event, signal_event);
vkCmdSetEvent(cmd_list->cmd_buffer, sig_event->event, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
if (cmd_list->immediate)
zev_submit_immediate(cmd_list);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListAppendLaunchKernelIndirect(ze_command_list_handle_t command_list,
ze_kernel_handle_t _kernel,
const ze_group_count_t *launch_args,
ze_event_handle_t signal_event,
uint32_t num_wait_events,
ze_event_handle_t *wait_events)
{
ZEV_FROM_HANDLE(zev_command_list, cmd_list, command_list);
if (num_wait_events) {
VkEvent *events = malloc(num_wait_events * sizeof(VkEvent));
for (unsigned i = 0; i < num_wait_events; i++) {
events[i] = zev_event_from_handle(wait_events[i])->event;
}
vkCmdWaitEvents(cmd_list->cmd_buffer, num_wait_events, events, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, NULL, 0, NULL, 0, NULL);
free(events);
}
if (signal_event) {
ZEV_FROM_HANDLE(zev_event, sig_event, signal_event);
vkCmdSetEvent(cmd_list->cmd_buffer, sig_event->event, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
if (cmd_list->immediate)
zev_submit_immediate(cmd_list);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListAppendMemoryFill(ze_command_list_handle_t command_list,
void *ptr,
const void *pattern,
size_t pattern_size,
size_t size,
ze_event_handle_t _event)
{
ZEV_FROM_HANDLE(zev_command_list, cmd_list, command_list);
struct zev_device *device = cmd_list->dev;
struct hash_entry *entry = _mesa_hash_table_search(device->driver->mem_allocs, ptr);
/* todo find a better range manager */
if (!entry)
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
struct zev_memory_allocation *alloc_info = entry->data;
if (alloc_info->type != ZEV_MEMORY_DEVICE)
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
uint32_t fill_val;
if (pattern_size == 1) {
uint32_t val = *(uint8_t *)pattern;
fill_val = (val | val << 8 | val << 16 | val << 24);
} else if (pattern_size == 2) {
uint32_t val = *(uint16_t *)pattern;
fill_val = val | val << 16;
} else if (pattern_size == 4)
fill_val = *(uint32_t *)pattern;
else
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
vkCmdFillBuffer(cmd_list->cmd_buffer, alloc_info->vk_buf_mem, 0, size, fill_val);
if (_event) {
ZEV_FROM_HANDLE(zev_event, event, _event);
vkCmdSetEvent(cmd_list->cmd_buffer, event->event, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
if (cmd_list->immediate)
zev_submit_immediate(cmd_list);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListAppendMemoryCopy(ze_command_list_handle_t command_list,
void *dstptr,
const void *srcptr,
size_t size,
ze_event_handle_t _event)
{
ZEV_FROM_HANDLE(zev_command_list, cmd_list, command_list);
struct zev_device *device = cmd_list->dev;
struct hash_entry *dst_entry = _mesa_hash_table_search(device->driver->mem_allocs, dstptr);
/* todo find a better range manager */
if (!dst_entry)
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
struct hash_entry *src_entry = _mesa_hash_table_search(device->driver->mem_allocs, srcptr);
/* todo find a better range manager */
if (!src_entry)
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
struct zev_memory_allocation *src_info = src_entry->data;
struct zev_memory_allocation *dst_info = dst_entry->data;
VkBufferCopy region;
region.srcOffset = 0;
region.dstOffset = 0;
region.size = size;
vkCmdCopyBuffer(cmd_list->cmd_buffer, src_info->vk_buf_mem, dst_info->vk_buf_mem, 1, ®ion);
if (_event) {
ZEV_FROM_HANDLE(zev_event, event, _event);
vkCmdSetEvent(cmd_list->cmd_buffer, event->event, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
if (cmd_list->immediate)
zev_submit_immediate(cmd_list);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListAppendBarrier(ze_command_list_handle_t command_list,
ze_event_handle_t _signal_event,
uint32_t num_wait_events,
ze_event_handle_t *wait_events)
{
ZEV_FROM_HANDLE(zev_command_list, cmd_list, command_list);
if (num_wait_events) {
VkEvent *events = malloc(num_wait_events * sizeof(VkEvent));
for (unsigned i = 0; i < num_wait_events; i++) {
events[i] = zev_event_from_handle(wait_events[i])->event;
}
vkCmdWaitEvents(cmd_list->cmd_buffer, num_wait_events, events, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0, NULL, 0, NULL, 0, NULL);
free(events);
}
vkCmdPipelineBarrier(cmd_list->cmd_buffer, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
0, 0, NULL, 0, NULL, 0, NULL);
if (_signal_event) {
ZEV_FROM_HANDLE(zev_event, signal_event, _signal_event);
vkCmdSetEvent(cmd_list->cmd_buffer, signal_event->event, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
}
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_ModuleCreate(ze_device_handle_t device,
const ze_module_desc_t *desc,
ze_module_handle_t *handle,
ze_module_build_log_handle_t *build_log)
{
ZEV_FROM_HANDLE(zev_device, dev, device);
struct zev_module *module;
module = malloc(sizeof(struct zev_module));
if (!module)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
module->dev = dev;
VkShaderModuleCreateInfo create_info = {
.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO,
.pNext = NULL,
.codeSize = desc->inputSize,
.pCode = (uint32_t *)desc->pInputModule,
.flags = VK_SHADER_MODULE_CREATE_KERNEL_BIT_EXT,
};
module->spec_info = NULL;
if (desc->pConstants && desc->pConstants->numConstants > 0) {
uint32_t num_const = desc->pConstants->numConstants;
uint32_t data_size = num_const * sizeof(uint64_t);
uint32_t map_size = num_const * sizeof(VkSpecializationMapEntry);
VkSpecializationMapEntry *map_entries;
void *data;
module->spec_info = calloc(1, sizeof(VkSpecializationInfo) + map_size + data_size);
map_entries = (VkSpecializationMapEntry *)(module->spec_info + 1);
module->spec_info->pMapEntries = map_entries;
data = (uint8_t *)module->spec_info->pMapEntries + map_size;
module->spec_info->pData = data;
module->spec_info->mapEntryCount = num_const;
module->spec_info->dataSize = data_size;
for (unsigned i = 0; i < num_const; i++) {
map_entries[i].constantID = desc->pConstants->pConstantIds[i];
map_entries[i].offset = i * sizeof(uint64_t);
map_entries[i].size = sizeof(uint64_t);
*((uint64_t *)module->spec_info->pData + i) = desc->pConstants->pConstantValues[i];
}
}
VkResult res = vkCreateShaderModule(dev->vk_dev, &create_info, NULL, &module->module);
if (res != VK_SUCCESS)
return ze_vk_err(res);
*handle = zev_module_to_handle(module);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_ModuleDestroy(ze_module_handle_t _module)
{
ZEV_FROM_HANDLE(zev_module, module, _module);
if (_module == NULL)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
vkDestroyShaderModule(module->dev->vk_dev, module->module, NULL);
free(module->spec_info);
free(module);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_ModuleGetNativeBinary(ze_module_handle_t _module,
size_t *p_size,
uint8_t *module_native_binary)
{
*p_size = 0;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_KernelCreate(ze_module_handle_t _module,
const ze_kernel_desc_t *desc,
ze_kernel_handle_t *handle)
{
ZEV_FROM_HANDLE(zev_module, module, _module);
struct zev_kernel *kernel;
kernel = malloc(sizeof(struct zev_kernel));
if (!kernel)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
kernel->module = module;
VkDescriptorSetAllocateInfo desc_set_allocate_info = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
.pNext = NULL,
.descriptorPool = module->dev->desc_pool,
.descriptorSetCount = 1,
.pSetLayouts = &module->dev->input_layout,
};
vkAllocateDescriptorSets(module->dev->vk_dev, &desc_set_allocate_info, &kernel->set);
VkPipelineLayoutCreateInfo pipeline_layout_create = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.pNext = NULL,
.setLayoutCount = 1,
.pSetLayouts = &module->dev->input_layout,
};
VkResult res = vkCreatePipelineLayout(module->dev->vk_dev, &pipeline_layout_create,
NULL, &kernel->pipeline_layout);
VkPipelineShaderStageCreateInfo stage_create = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.pNext = NULL,
.stage = VK_SHADER_STAGE_COMPUTE_BIT,
.module = module->module,
.pName = desc->pKernelName,
.pSpecializationInfo = module->spec_info,
};
VkComputePipelineCreateInfo create_info = {
.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
.pNext = NULL,
.stage = stage_create,
.layout = kernel->pipeline_layout,
};
res = vkCreateComputePipelines(module->dev->vk_dev,
NULL, 1,
&create_info,
NULL,
&kernel->pipeline);
if (res != VK_SUCCESS)
return ze_vk_err(res);
(*module->dev->get_kernel_input_map)(module->dev->vk_dev, kernel->pipeline, &kernel->num_inputs, NULL);
kernel->input_map = malloc(kernel->num_inputs * 4);
(*module->dev->get_kernel_input_map)(module->dev->vk_dev, kernel->pipeline, &kernel->num_inputs, kernel->input_map);
*handle = zev_kernel_to_handle(kernel);
VkBufferCreateInfo input_buffer = {
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
.pNext = NULL,
.size = 1024,
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
};
res = vkCreateBuffer(module->dev->vk_dev, &input_buffer, NULL, &kernel->input_buffer);
VkMemoryRequirements mem_reqs;
vkGetBufferMemoryRequirements(module->dev->vk_dev, kernel->input_buffer, &mem_reqs);
VkMemoryAllocateInfo mem_alloc = {
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
.allocationSize = mem_reqs.size,
.memoryTypeIndex = 0,
};
res = vkAllocateMemory(module->dev->vk_dev, &mem_alloc, NULL, &kernel->input_buffer_mem);
res = vkBindBufferMemory(module->dev->vk_dev, kernel->input_buffer, kernel->input_buffer_mem, 0);
vkMapMemory(module->dev->vk_dev, kernel->input_buffer_mem, 0, 1024, 0, &kernel->input_ptr);
VkWriteDescriptorSet desc_write = {
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
.dstSet = kernel->set,
.descriptorCount = 1,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.pBufferInfo = &(VkDescriptorBufferInfo){ .buffer = kernel->input_buffer, 0, 1024 },
};
vkUpdateDescriptorSets(module->dev->vk_dev, 1, &desc_write, 0, NULL);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_KernelDestroy(ze_kernel_handle_t _kernel)
{
ZEV_FROM_HANDLE(zev_kernel, kernel, _kernel);
if (_kernel == NULL)
return ZE_RESULT_ERROR_INVALID_NULL_HANDLE;
vkUnmapMemory(kernel->module->dev->vk_dev, kernel->input_buffer_mem);
vkFreeMemory(kernel->module->dev->vk_dev, kernel->input_buffer_mem, NULL);
vkDestroyBuffer(kernel->module->dev->vk_dev, kernel->input_buffer, NULL);
vkDestroyPipeline(kernel->module->dev->vk_dev, kernel->pipeline, NULL);
vkDestroyPipelineLayout(kernel->module->dev->vk_dev, kernel->pipeline_layout, NULL);
free(kernel);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_KernelSetGroupSize(ze_kernel_handle_t _kernel,
uint32_t group_size_x,
uint32_t group_size_y,
uint32_t group_size_z)
{
ZEV_FROM_HANDLE(zev_kernel, kernel, _kernel);
kernel->group_size_x = group_size_x;
kernel->group_size_y = group_size_y;
kernel->group_size_z = group_size_z;
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_KernelSetArgumentValue(ze_kernel_handle_t _kernel,
uint32_t arg_index,
size_t arg_size,
const void *arg_value)
{
ZEV_FROM_HANDLE(zev_kernel, kernel, _kernel);
uint32_t offset = kernel->input_map[arg_index];
if (arg_value)
memcpy(kernel->input_ptr + offset, arg_value, arg_size);
else
memset(kernel->input_ptr + offset, 0, arg_size);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_EventPoolCreate(ze_driver_handle_t driver,
const ze_event_pool_desc_t *desc,
uint32_t num_devices,
ze_device_handle_t *p_devices,
ze_event_pool_handle_t *handle)
{
struct zev_event_pool *pool;
pool = malloc(sizeof(struct zev_event_pool) + (num_devices * sizeof(struct zev_device *)));
if (!pool)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
pool->drv = zev_driver_from_handle(driver);
pool->num_devices = num_devices;
pool->devs = (struct zev_device **)(pool + 1);
pool->timestamp = !!(desc->flags & ZE_EVENT_POOL_FLAG_TIMESTAMP);
for (unsigned i = 0; i < num_devices; i++)
pool->devs[i] = zev_device_from_handle(p_devices[i]);
*handle = zev_event_pool_to_handle(pool);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_EventPoolDestroy(ze_event_pool_handle_t _pool)
{
ZEV_FROM_HANDLE(zev_event_pool, pool, _pool);
free(pool);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_EventCreate(ze_event_pool_handle_t event_pool,
const ze_event_desc_t *desc,
ze_event_handle_t *handle)
{
ZEV_FROM_HANDLE(zev_event_pool, pool, event_pool);
struct zev_event *event;
if (pool->num_devices > 1)
return ZE_RESULT_NOT_READY;
event = malloc(sizeof(struct zev_event));
if (!event)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
event->pool = pool;
VkEventCreateInfo create_info = {
.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO,
.pNext = NULL,
};
VkResult res = vkCreateEvent(pool->devs[0]->vk_dev, &create_info, NULL, &event->event);
if (res != VK_SUCCESS)
return ze_vk_err(res);
*handle = zev_event_to_handle(event);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_EventDestroy(ze_event_handle_t _event)
{
ZEV_FROM_HANDLE(zev_event, event, _event);
free(event);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_EventHostReset(ze_event_handle_t _event)
{
ZEV_FROM_HANDLE(zev_event, event, _event);
VkResult res = vkResetEvent(event->pool->devs[0]->vk_dev, event->event);
return ze_vk_err(res);
}
static ze_result_t zev_EventGetTimestamp(ze_event_handle_t _event,
ze_event_timestamp_type_t timestamp_type,
void *dstptr)
{
// TODO
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListAppendSignalEvent(ze_command_list_handle_t command_list,
ze_event_handle_t _event)
{
ZEV_FROM_HANDLE(zev_command_list, cmd_list, command_list);
ZEV_FROM_HANDLE(zev_event, event, _event);
vkCmdSetEvent(cmd_list->cmd_buffer, event->event, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListAppendWaitOnEvents(ze_command_list_handle_t command_list,
uint32_t num_events,
ze_event_handle_t *events)
{
ZEV_FROM_HANDLE(zev_command_list, cmd_list, command_list);
VkEvent *vk_events = malloc(num_events * sizeof(VkEvent));
if (!vk_events)
return ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
for (unsigned i = 0; i < num_events; i++) {
struct zev_event *event = zev_event_from_handle(events[i]);
vk_events[i] = event->event;
}
vkCmdWaitEvents(cmd_list->cmd_buffer, num_events, vk_events,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
0, NULL, 0, NULL, 0, NULL);
free(vk_events);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_CommandListAppendEventReset(ze_command_list_handle_t command_list,
ze_event_handle_t _event)
{
ZEV_FROM_HANDLE(zev_command_list, cmd_list, command_list);
ZEV_FROM_HANDLE(zev_event, event, _event);
vkCmdResetEvent(cmd_list->cmd_buffer, event->event, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
return ZE_RESULT_SUCCESS;
}
static ze_result_t zev_EventHostSignal(ze_event_handle_t _event)
{
ZEV_FROM_HANDLE(zev_event, event, _event);
VkResult res = vkSetEvent(event->pool->devs[0]->vk_dev, event->event);
return ze_vk_err(res);
}
static ze_result_t zev_EventHostSynchronize(ze_event_handle_t _event, uint32_t timeout)
{
ZEV_FROM_HANDLE(zev_event, event, _event);
VkResult res;
time_t start;
if (timeout != UINT32_MAX && timeout != 0) {
start = os_time_get_nano();
}
while (1) {
res = vkGetEventStatus(event->pool->devs[0]->vk_dev, event->event);
if (res == VK_EVENT_SET)
return ZE_RESULT_SUCCESS;
if (timeout == 0)
return ZE_RESULT_NOT_READY;
if (timeout != UINT32_MAX) {
time_t current = os_time_get_nano();
if (current-start > timeout)
break;
}
};
// TODO polling required.
return ZE_RESULT_NOT_READY;
}
static ze_result_t zev_EventQueryStatus(ze_event_handle_t _event)
{
ZEV_FROM_HANDLE(zev_event, event, _event);
VkResult res = vkGetEventStatus(event->pool->devs[0]->vk_dev, event->event);
return (res == VK_EVENT_SET) ? ZE_RESULT_SUCCESS : ZE_RESULT_NOT_READY;
}
static const ze_global_dditable_t zev_global_dditable = {
.pfnInit = zev_Init,
};
ze_result_t zeGetGlobalProcAddrTable(ze_api_version_t version,
ze_global_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_global_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_DRIVER(x) .pfn##x = zev_Driver##x
static const ze_driver_dditable_t zev_driver_dditable = {
PFN_DRIVER(Get),
PFN_DRIVER(GetApiVersion),
PFN_DRIVER(GetProperties),
PFN_DRIVER(GetIPCProperties),
PFN_DRIVER(GetExtensionFunctionAddress),
PFN_DRIVER(AllocSharedMem),
PFN_DRIVER(AllocDeviceMem),
PFN_DRIVER(AllocHostMem),
PFN_DRIVER(FreeMem),
// GetMemAllocProperties
PFN_DRIVER(GetMemAddressRange),
// GetMemIpcHandle
// OpenMemIpcHandle
// CloseMemIpcHandle
};
ze_result_t zeGetDriverProcAddrTable(ze_api_version_t version,
ze_driver_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_driver_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_DEVICE(x) .pfn##x = zev_Device##x
static const ze_device_dditable_t zev_device_dditable = {
PFN_DEVICE(Get),
PFN_DEVICE(GetSubDevices),
PFN_DEVICE(GetProperties),
PFN_DEVICE(GetComputeProperties),
PFN_DEVICE(GetKernelProperties),
PFN_DEVICE(GetMemoryProperties),
PFN_DEVICE(GetMemoryAccessProperties),
PFN_DEVICE(GetCacheProperties),
PFN_DEVICE(GetImageProperties),
// GetP2PProperties
PFN_DEVICE(CanAccessPeer),
// SetLastLevelCacheConfig
// SystemBarrier
// MakeMemoryResident
// EvictMemory
// MakeImageResident
// EvictImage
// RegisterCLMemory
// RegisterCLProgram
// RegisterCLCommandQueue
};
ze_result_t zeGetDeviceProcAddrTable(ze_api_version_t version,
ze_device_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_device_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_COMMAND_QUEUE(x) .pfn##x = zev_CommandQueue##x
static const ze_command_queue_dditable_t zev_command_queue_dditable = {
PFN_COMMAND_QUEUE(Create),
PFN_COMMAND_QUEUE(Destroy),
PFN_COMMAND_QUEUE(ExecuteCommandLists),
PFN_COMMAND_QUEUE(Synchronize),
};
ze_result_t zeGetCommandQueueProcAddrTable(ze_api_version_t version,
ze_command_queue_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_command_queue_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_COMMAND_LIST(x) .pfn##x = zev_CommandList##x
static const ze_command_list_dditable_t zev_command_list_dditable = {
PFN_COMMAND_LIST(Create),
PFN_COMMAND_LIST(CreateImmediate),
PFN_COMMAND_LIST(Destroy),
PFN_COMMAND_LIST(Close),
PFN_COMMAND_LIST(Reset),
PFN_COMMAND_LIST(AppendBarrier),
// AppendMemoryRangesBarrier
PFN_COMMAND_LIST(AppendLaunchKernel),
// AppendLaunchCooperativeKernel
PFN_COMMAND_LIST(AppendLaunchKernelIndirect),
// AppendLunachMultipleKernelsIndirect
PFN_COMMAND_LIST(AppendSignalEvent),
PFN_COMMAND_LIST(AppendWaitOnEvents),
PFN_COMMAND_LIST(AppendEventReset),
PFN_COMMAND_LIST(AppendMemoryCopy),
PFN_COMMAND_LIST(AppendMemoryFill),
// AppendMemoryCopyRegion
// AppendImageCopy
// AppendImageCopyRegion
// AppendImageCopyToMemory
// AppendImageCopyFromMemory
// AppendMemoryPrefetch
// AppendMemAdvise
};
ze_result_t zeGetCommandListProcAddrTable(ze_api_version_t version,
ze_command_list_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_command_list_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_FENCE(x) .pfn##x = zev_Fence##x
static const ze_fence_dditable_t zev_fence_dditable = {
PFN_FENCE(Create),
PFN_FENCE(Destroy),
PFN_FENCE(HostSynchronize),
PFN_FENCE(QueryStatus),
PFN_FENCE(Reset),
};
ze_result_t zeGetFenceProcAddrTable(ze_api_version_t version,
ze_fence_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_fence_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_EVENT_POOL(x) .pfn##x = zev_EventPool##x
static const ze_event_pool_dditable_t zev_event_pool_dditable = {
PFN_EVENT_POOL(Create),
PFN_EVENT_POOL(Destroy),
// GetIpcHandle
// OpenIpcHnadle
// CloseIpcHandle
};
ze_result_t zeGetEventPoolProcAddrTable(ze_api_version_t version,
ze_event_pool_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_event_pool_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_EVENT(x) .pfn##x = zev_Event##x
static const ze_event_dditable_t zev_event_dditable = {
PFN_EVENT(Create),
PFN_EVENT(Destroy),
PFN_EVENT(HostSignal),
PFN_EVENT(HostSynchronize),
PFN_EVENT(QueryStatus),
PFN_EVENT(HostReset),
PFN_EVENT(GetTimestamp),
};
ze_result_t zeGetEventProcAddrTable(ze_api_version_t version,
ze_event_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_event_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_IMAGE(x) .pfn##x = zev_Image##x
static const ze_image_dditable_t zev_image_dditable = {
//GetProperties
//Create
//Destroy
};
ze_result_t zeGetImageProcAddrTable(ze_api_version_t version,
ze_image_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_image_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_MODULE(x) .pfn##x = zev_Module##x
static const ze_module_dditable_t zev_module_dditable = {
PFN_MODULE(Create),
PFN_MODULE(Destroy),
PFN_MODULE(GetNativeBinary),
// GetGlobalPointer
// GetKernelNames
// GetFunctionPointer
};
ze_result_t zeGetModuleProcAddrTable(ze_api_version_t version,
ze_module_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_module_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_MODULE_BUILD_LOG(x) .pfn##x = zev_ModuleBuildLog##x
static const ze_module_build_log_dditable_t zev_module_build_log_dditable = {
//Destroy
//GetString
};
ze_result_t zeGetModuleBuildLogProcAddrTable(ze_api_version_t version,
ze_module_build_log_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_module_build_log_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_KERNEL(x) .pfn##x = zev_Kernel##x
static const ze_kernel_dditable_t zev_kernel_dditable = {
PFN_KERNEL(Create),
PFN_KERNEL(Destroy),
// SetIntermediateCacheConfig
PFN_KERNEL(SetGroupSize),
// SugggestGroupSize
// SuggestMaxCooperativeGroupCount
PFN_KERNEL(SetArgumentValue),
// SetAttribute
// GetAttribute
// GetProperties
};
ze_result_t zeGetKernelProcAddrTable(ze_api_version_t version,
ze_kernel_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_kernel_dditable;
return ZE_RESULT_SUCCESS;
}
#define PFN_SAMPLER(x) .pfn##x = zev_Sampler##x
static const ze_sampler_dditable_t zev_sampler_dditable = {
// PFN_SAMPLER(Create);
// PFN_SAMPLER(Destroy);
};
ze_result_t zeGetSamplerProcAddrTable(ze_api_version_t version,
ze_sampler_dditable_t *p_ddi_table)
{
*p_ddi_table = zev_sampler_dditable;
return ZE_RESULT_SUCCESS;
}
|