-
Notifications
You must be signed in to change notification settings - Fork 97
/
ze_ldrddi.cpp
8983 lines (7545 loc) · 403 KB
/
ze_ldrddi.cpp
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
/*
*
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
* @file ze_ldrddi.cpp
*
*/
#include "ze_loader_internal.h"
namespace loader
{
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeInit
__zedlllocal ze_result_t ZE_APICALL
zeInit(
ze_init_flags_t flags ///< [in] initialization flags.
///< must be 0 (default) or a combination of ::ze_init_flag_t.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
bool atLeastOneDriverValid = false;
for( auto& drv : loader::context->zeDrivers )
{
if(drv.initStatus != ZE_RESULT_SUCCESS)
continue;
drv.initStatus = drv.dditable.ze.Global.pfnInit( flags );
if(drv.initStatus == ZE_RESULT_SUCCESS)
atLeastOneDriverValid = true;
}
if(!atLeastOneDriverValid)
result=ZE_RESULT_ERROR_UNINITIALIZED;
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDriverGet
__zedlllocal ze_result_t ZE_APICALL
zeDriverGet(
uint32_t* pCount, ///< [in,out] pointer to the number of driver instances.
///< if count is zero, then the loader shall update the value with the
///< total number of drivers available.
///< if count is greater than the number of drivers available, then the
///< loader shall update the value with the correct number of drivers available.
ze_driver_handle_t* phDrivers ///< [in,out][optional][range(0, *pCount)] array of driver instance handles.
///< if count is less than the number of drivers available, then the loader
///< shall only retrieve that number of drivers.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
uint32_t total_driver_handle_count = 0;
for( auto& drv : loader::context->zeDrivers )
{
if(drv.initStatus != ZE_RESULT_SUCCESS)
continue;
if( ( 0 < *pCount ) && ( *pCount == total_driver_handle_count))
break;
uint32_t library_driver_handle_count = 0;
result = drv.dditable.ze.Driver.pfnGet( &library_driver_handle_count, nullptr );
if( ZE_RESULT_SUCCESS != result ) {
// If Get Drivers fails with Uninitialized, then update the driver init status to prevent reporting this driver in the next get call.
if (ZE_RESULT_ERROR_UNINITIALIZED == result) {
drv.initStatus = result;
}
continue;
}
if( nullptr != phDrivers && *pCount !=0)
{
if( total_driver_handle_count + library_driver_handle_count > *pCount) {
library_driver_handle_count = *pCount - total_driver_handle_count;
}
result = drv.dditable.ze.Driver.pfnGet( &library_driver_handle_count, &phDrivers[ total_driver_handle_count ] );
if( ZE_RESULT_SUCCESS != result ) break;
drv.driverInuse = true;
try
{
for( uint32_t i = 0; i < library_driver_handle_count; ++i ) {
uint32_t driver_index = total_driver_handle_count + i;
phDrivers[ driver_index ] = reinterpret_cast<ze_driver_handle_t>(
context->ze_driver_factory.getInstance( phDrivers[ driver_index ], &drv.dditable ) );
}
}
catch( std::bad_alloc& )
{
result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
}
total_driver_handle_count += library_driver_handle_count;
}
// If the last driver get failed, but at least one driver succeeded, then return success with total count.
if( ZE_RESULT_SUCCESS == result || total_driver_handle_count > 0)
*pCount = total_driver_handle_count;
if (total_driver_handle_count > 0) {
result = ZE_RESULT_SUCCESS;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeInitDrivers
__zedlllocal ze_result_t ZE_APICALL
zeInitDrivers(
uint32_t* pCount, ///< [in,out] pointer to the number of driver instances.
///< if count is zero, then the loader shall update the value with the
///< total number of drivers available.
///< if count is greater than the number of drivers available, then the
///< loader shall update the value with the correct number of drivers available.
ze_driver_handle_t* phDrivers, ///< [in,out][optional][range(0, *pCount)] array of driver instance handles.
///< if count is less than the number of drivers available, then the loader
///< shall only retrieve that number of drivers.
ze_init_driver_type_desc_t* desc ///< [in] descriptor containing the driver type initialization details
///< including ::ze_init_driver_type_flag_t combinations.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
uint32_t total_driver_handle_count = 0;
for( auto& drv : loader::context->zeDrivers )
{
if (!drv.dditable.ze.Global.pfnInitDrivers) {
drv.initDriversStatus = ZE_RESULT_ERROR_UNINITIALIZED;
continue;
}
if( ( 0 < *pCount ) && ( *pCount == total_driver_handle_count))
break;
uint32_t library_driver_handle_count = 0;
result = drv.dditable.ze.Global.pfnInitDrivers( &library_driver_handle_count, nullptr, desc );
if( ZE_RESULT_SUCCESS != result ) {
// If Get Drivers fails with Uninitialized, then update the driver init status to prevent reporting this driver in the next get call.
if (ZE_RESULT_ERROR_UNINITIALIZED == result) {
drv.initDriversStatus = result;
}
continue;
}
if( nullptr != phDrivers && *pCount !=0)
{
if( total_driver_handle_count + library_driver_handle_count > *pCount) {
library_driver_handle_count = *pCount - total_driver_handle_count;
}
result = drv.dditable.ze.Global.pfnInitDrivers( &library_driver_handle_count, &phDrivers[ total_driver_handle_count ], desc );
if( ZE_RESULT_SUCCESS != result ) break;
drv.driverInuse = true;
try
{
for( uint32_t i = 0; i < library_driver_handle_count; ++i ) {
uint32_t driver_index = total_driver_handle_count + i;
phDrivers[ driver_index ] = reinterpret_cast<ze_driver_handle_t>(
context->ze_driver_factory.getInstance( phDrivers[ driver_index ], &drv.dditable ) );
}
}
catch( std::bad_alloc& )
{
result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
}
total_driver_handle_count += library_driver_handle_count;
}
// If the last driver get failed, but at least one driver succeeded, then return success with total count.
if( ZE_RESULT_SUCCESS == result || total_driver_handle_count > 0)
*pCount = total_driver_handle_count;
if (total_driver_handle_count > 0) {
result = ZE_RESULT_SUCCESS;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDriverGetApiVersion
__zedlllocal ze_result_t ZE_APICALL
zeDriverGetApiVersion(
ze_driver_handle_t hDriver, ///< [in] handle of the driver instance
ze_api_version_t* version ///< [out] api version
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_driver_object_t*>( hDriver )->dditable;
auto pfnGetApiVersion = dditable->ze.Driver.pfnGetApiVersion;
if( nullptr == pfnGetApiVersion )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDriver = reinterpret_cast<ze_driver_object_t*>( hDriver )->handle;
// forward to device-driver
result = pfnGetApiVersion( hDriver, version );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDriverGetProperties
__zedlllocal ze_result_t ZE_APICALL
zeDriverGetProperties(
ze_driver_handle_t hDriver, ///< [in] handle of the driver instance
ze_driver_properties_t* pDriverProperties ///< [in,out] query result for driver properties
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_driver_object_t*>( hDriver )->dditable;
auto pfnGetProperties = dditable->ze.Driver.pfnGetProperties;
if( nullptr == pfnGetProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDriver = reinterpret_cast<ze_driver_object_t*>( hDriver )->handle;
// forward to device-driver
result = pfnGetProperties( hDriver, pDriverProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDriverGetIpcProperties
__zedlllocal ze_result_t ZE_APICALL
zeDriverGetIpcProperties(
ze_driver_handle_t hDriver, ///< [in] handle of the driver instance
ze_driver_ipc_properties_t* pIpcProperties ///< [in,out] query result for IPC properties
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_driver_object_t*>( hDriver )->dditable;
auto pfnGetIpcProperties = dditable->ze.Driver.pfnGetIpcProperties;
if( nullptr == pfnGetIpcProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDriver = reinterpret_cast<ze_driver_object_t*>( hDriver )->handle;
// forward to device-driver
result = pfnGetIpcProperties( hDriver, pIpcProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDriverGetExtensionProperties
__zedlllocal ze_result_t ZE_APICALL
zeDriverGetExtensionProperties(
ze_driver_handle_t hDriver, ///< [in] handle of the driver instance
uint32_t* pCount, ///< [in,out] pointer to the number of extension properties.
///< if count is zero, then the driver shall update the value with the
///< total number of extension properties available.
///< if count is greater than the number of extension properties available,
///< then the driver shall update the value with the correct number of
///< extension properties available.
ze_driver_extension_properties_t* pExtensionProperties ///< [in,out][optional][range(0, *pCount)] array of query results for
///< extension properties.
///< if count is less than the number of extension properties available,
///< then driver shall only retrieve that number of extension properties.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_driver_object_t*>( hDriver )->dditable;
auto pfnGetExtensionProperties = dditable->ze.Driver.pfnGetExtensionProperties;
if( nullptr == pfnGetExtensionProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDriver = reinterpret_cast<ze_driver_object_t*>( hDriver )->handle;
// forward to device-driver
result = pfnGetExtensionProperties( hDriver, pCount, pExtensionProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDriverGetExtensionFunctionAddress
__zedlllocal ze_result_t ZE_APICALL
zeDriverGetExtensionFunctionAddress(
ze_driver_handle_t hDriver, ///< [in] handle of the driver instance
const char* name, ///< [in] extension function name
void** ppFunctionAddress ///< [out] pointer to function pointer
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_driver_object_t*>( hDriver )->dditable;
auto pfnGetExtensionFunctionAddress = dditable->ze.Driver.pfnGetExtensionFunctionAddress;
if( nullptr == pfnGetExtensionFunctionAddress )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDriver = reinterpret_cast<ze_driver_object_t*>( hDriver )->handle;
// forward to device-driver
result = pfnGetExtensionFunctionAddress( hDriver, name, ppFunctionAddress );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDriverGetLastErrorDescription
__zedlllocal ze_result_t ZE_APICALL
zeDriverGetLastErrorDescription(
ze_driver_handle_t hDriver, ///< [in] handle of the driver instance
const char** ppString ///< [in,out] pointer to a null-terminated array of characters describing
///< cause of error.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_driver_object_t*>( hDriver )->dditable;
auto pfnGetLastErrorDescription = dditable->ze.Driver.pfnGetLastErrorDescription;
if( nullptr == pfnGetLastErrorDescription )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDriver = reinterpret_cast<ze_driver_object_t*>( hDriver )->handle;
// forward to device-driver
result = pfnGetLastErrorDescription( hDriver, ppString );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGet
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGet(
ze_driver_handle_t hDriver, ///< [in] handle of the driver instance
uint32_t* pCount, ///< [in,out] pointer to the number of devices.
///< if count is zero, then the driver shall update the value with the
///< total number of devices available.
///< if count is greater than the number of devices available, then the
///< driver shall update the value with the correct number of devices available.
ze_device_handle_t* phDevices ///< [in,out][optional][range(0, *pCount)] array of handle of devices.
///< if count is less than the number of devices available, then driver
///< shall only retrieve that number of devices.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_driver_object_t*>( hDriver )->dditable;
auto pfnGet = dditable->ze.Device.pfnGet;
if( nullptr == pfnGet )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDriver = reinterpret_cast<ze_driver_object_t*>( hDriver )->handle;
// forward to device-driver
result = pfnGet( hDriver, pCount, phDevices );
if( ZE_RESULT_SUCCESS != result )
return result;
try
{
// convert driver handles to loader handles
for( size_t i = 0; ( nullptr != phDevices ) && ( i < *pCount ); ++i )
phDevices[ i ] = reinterpret_cast<ze_device_handle_t>(
context->ze_device_factory.getInstance( phDevices[ i ], dditable ) );
}
catch( std::bad_alloc& )
{
result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetRootDevice
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetRootDevice(
ze_device_handle_t hDevice, ///< [in] handle of the device object
ze_device_handle_t* phRootDevice ///< [in,out] parent root device.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetRootDevice = dditable->ze.Device.pfnGetRootDevice;
if( nullptr == pfnGetRootDevice )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetRootDevice( hDevice, phRootDevice );
if( ZE_RESULT_SUCCESS != result )
return result;
try
{
// convert driver handle to loader handle
*phRootDevice = reinterpret_cast<ze_device_handle_t>(
context->ze_device_factory.getInstance( *phRootDevice, dditable ) );
}
catch( std::bad_alloc& )
{
result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetSubDevices
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetSubDevices(
ze_device_handle_t hDevice, ///< [in] handle of the device object
uint32_t* pCount, ///< [in,out] pointer to the number of sub-devices.
///< if count is zero, then the driver shall update the value with the
///< total number of sub-devices available.
///< if count is greater than the number of sub-devices available, then the
///< driver shall update the value with the correct number of sub-devices available.
ze_device_handle_t* phSubdevices ///< [in,out][optional][range(0, *pCount)] array of handle of sub-devices.
///< if count is less than the number of sub-devices available, then driver
///< shall only retrieve that number of sub-devices.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetSubDevices = dditable->ze.Device.pfnGetSubDevices;
if( nullptr == pfnGetSubDevices )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetSubDevices( hDevice, pCount, phSubdevices );
if( ZE_RESULT_SUCCESS != result )
return result;
try
{
// convert driver handles to loader handles
for( size_t i = 0; ( nullptr != phSubdevices ) && ( i < *pCount ); ++i )
phSubdevices[ i ] = reinterpret_cast<ze_device_handle_t>(
context->ze_device_factory.getInstance( phSubdevices[ i ], dditable ) );
}
catch( std::bad_alloc& )
{
result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device
ze_device_properties_t* pDeviceProperties ///< [in,out] query result for device properties
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetProperties = dditable->ze.Device.pfnGetProperties;
if( nullptr == pfnGetProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetProperties( hDevice, pDeviceProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetComputeProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetComputeProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device
ze_device_compute_properties_t* pComputeProperties ///< [in,out] query result for compute properties
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetComputeProperties = dditable->ze.Device.pfnGetComputeProperties;
if( nullptr == pfnGetComputeProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetComputeProperties( hDevice, pComputeProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetModuleProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetModuleProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device
ze_device_module_properties_t* pModuleProperties///< [in,out] query result for module properties
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetModuleProperties = dditable->ze.Device.pfnGetModuleProperties;
if( nullptr == pfnGetModuleProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetModuleProperties( hDevice, pModuleProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetCommandQueueGroupProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetCommandQueueGroupProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device
uint32_t* pCount, ///< [in,out] pointer to the number of command queue group properties.
///< if count is zero, then the driver shall update the value with the
///< total number of command queue group properties available.
///< if count is greater than the number of command queue group properties
///< available, then the driver shall update the value with the correct
///< number of command queue group properties available.
ze_command_queue_group_properties_t* pCommandQueueGroupProperties ///< [in,out][optional][range(0, *pCount)] array of query results for
///< command queue group properties.
///< if count is less than the number of command queue group properties
///< available, then driver shall only retrieve that number of command
///< queue group properties.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetCommandQueueGroupProperties = dditable->ze.Device.pfnGetCommandQueueGroupProperties;
if( nullptr == pfnGetCommandQueueGroupProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetCommandQueueGroupProperties( hDevice, pCount, pCommandQueueGroupProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetMemoryProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetMemoryProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device
uint32_t* pCount, ///< [in,out] pointer to the number of memory properties.
///< if count is zero, then the driver shall update the value with the
///< total number of memory properties available.
///< if count is greater than the number of memory properties available,
///< then the driver shall update the value with the correct number of
///< memory properties available.
ze_device_memory_properties_t* pMemProperties ///< [in,out][optional][range(0, *pCount)] array of query results for
///< memory properties.
///< if count is less than the number of memory properties available, then
///< driver shall only retrieve that number of memory properties.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetMemoryProperties = dditable->ze.Device.pfnGetMemoryProperties;
if( nullptr == pfnGetMemoryProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetMemoryProperties( hDevice, pCount, pMemProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetMemoryAccessProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetMemoryAccessProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device
ze_device_memory_access_properties_t* pMemAccessProperties ///< [in,out] query result for memory access properties
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetMemoryAccessProperties = dditable->ze.Device.pfnGetMemoryAccessProperties;
if( nullptr == pfnGetMemoryAccessProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetMemoryAccessProperties( hDevice, pMemAccessProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetCacheProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetCacheProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device
uint32_t* pCount, ///< [in,out] pointer to the number of cache properties.
///< if count is zero, then the driver shall update the value with the
///< total number of cache properties available.
///< if count is greater than the number of cache properties available,
///< then the driver shall update the value with the correct number of
///< cache properties available.
ze_device_cache_properties_t* pCacheProperties ///< [in,out][optional][range(0, *pCount)] array of query results for cache properties.
///< if count is less than the number of cache properties available, then
///< driver shall only retrieve that number of cache properties.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetCacheProperties = dditable->ze.Device.pfnGetCacheProperties;
if( nullptr == pfnGetCacheProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetCacheProperties( hDevice, pCount, pCacheProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetImageProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetImageProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device
ze_device_image_properties_t* pImageProperties ///< [in,out] query result for image properties
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetImageProperties = dditable->ze.Device.pfnGetImageProperties;
if( nullptr == pfnGetImageProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetImageProperties( hDevice, pImageProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetExternalMemoryProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetExternalMemoryProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device
ze_device_external_memory_properties_t* pExternalMemoryProperties ///< [in,out] query result for external memory properties
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetExternalMemoryProperties = dditable->ze.Device.pfnGetExternalMemoryProperties;
if( nullptr == pfnGetExternalMemoryProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetExternalMemoryProperties( hDevice, pExternalMemoryProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetP2PProperties
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetP2PProperties(
ze_device_handle_t hDevice, ///< [in] handle of the device performing the access
ze_device_handle_t hPeerDevice, ///< [in] handle of the peer device with the allocation
ze_device_p2p_properties_t* pP2PProperties ///< [in,out] Peer-to-Peer properties between source and peer device
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetP2PProperties = dditable->ze.Device.pfnGetP2PProperties;
if( nullptr == pfnGetP2PProperties )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// convert loader handle to driver handle
hPeerDevice = reinterpret_cast<ze_device_object_t*>( hPeerDevice )->handle;
// forward to device-driver
result = pfnGetP2PProperties( hDevice, hPeerDevice, pP2PProperties );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceCanAccessPeer
__zedlllocal ze_result_t ZE_APICALL
zeDeviceCanAccessPeer(
ze_device_handle_t hDevice, ///< [in] handle of the device performing the access
ze_device_handle_t hPeerDevice, ///< [in] handle of the peer device with the allocation
ze_bool_t* value ///< [out] returned access capability
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnCanAccessPeer = dditable->ze.Device.pfnCanAccessPeer;
if( nullptr == pfnCanAccessPeer )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// convert loader handle to driver handle
hPeerDevice = reinterpret_cast<ze_device_object_t*>( hPeerDevice )->handle;
// forward to device-driver
result = pfnCanAccessPeer( hDevice, hPeerDevice, value );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetStatus
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetStatus(
ze_device_handle_t hDevice ///< [in] handle of the device
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetStatus = dditable->ze.Device.pfnGetStatus;
if( nullptr == pfnGetStatus )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetStatus( hDevice );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeDeviceGetGlobalTimestamps
__zedlllocal ze_result_t ZE_APICALL
zeDeviceGetGlobalTimestamps(
ze_device_handle_t hDevice, ///< [in] handle of the device
uint64_t* hostTimestamp, ///< [out] value of the Host's global timestamp that correlates with the
///< Device's global timestamp value.
uint64_t* deviceTimestamp ///< [out] value of the Device's global timestamp that correlates with the
///< Host's global timestamp value.
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_device_object_t*>( hDevice )->dditable;
auto pfnGetGlobalTimestamps = dditable->ze.Device.pfnGetGlobalTimestamps;
if( nullptr == pfnGetGlobalTimestamps )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDevice = reinterpret_cast<ze_device_object_t*>( hDevice )->handle;
// forward to device-driver
result = pfnGetGlobalTimestamps( hDevice, hostTimestamp, deviceTimestamp );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeContextCreate
__zedlllocal ze_result_t ZE_APICALL
zeContextCreate(
ze_driver_handle_t hDriver, ///< [in] handle of the driver object
const ze_context_desc_t* desc, ///< [in] pointer to context descriptor
ze_context_handle_t* phContext ///< [out] pointer to handle of context object created
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_driver_object_t*>( hDriver )->dditable;
auto pfnCreate = dditable->ze.Context.pfnCreate;
if( nullptr == pfnCreate )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDriver = reinterpret_cast<ze_driver_object_t*>( hDriver )->handle;
// forward to device-driver
result = pfnCreate( hDriver, desc, phContext );
if( ZE_RESULT_SUCCESS != result )
return result;
try
{
// convert driver handle to loader handle
*phContext = reinterpret_cast<ze_context_handle_t>(
context->ze_context_factory.getInstance( *phContext, dditable ) );
}
catch( std::bad_alloc& )
{
result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeContextCreateEx
__zedlllocal ze_result_t ZE_APICALL
zeContextCreateEx(
ze_driver_handle_t hDriver, ///< [in] handle of the driver object
const ze_context_desc_t* desc, ///< [in] pointer to context descriptor
uint32_t numDevices, ///< [in][optional] number of device handles; must be 0 if `nullptr ==
///< phDevices`
ze_device_handle_t* phDevices, ///< [in][optional][range(0, numDevices)] array of device handles which
///< context has visibility.
///< if nullptr, then all devices and any sub-devices supported by the
///< driver instance are
///< visible to the context.
///< otherwise, the context only has visibility to the devices and any
///< sub-devices of the
///< devices in this array.
ze_context_handle_t* phContext ///< [out] pointer to handle of context object created
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_driver_object_t*>( hDriver )->dditable;
auto pfnCreateEx = dditable->ze.Context.pfnCreateEx;
if( nullptr == pfnCreateEx )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hDriver = reinterpret_cast<ze_driver_object_t*>( hDriver )->handle;
// convert loader handles to driver handles
auto phDevicesLocal = new ze_device_handle_t [numDevices];
for( size_t i = 0; ( nullptr != phDevices ) && ( i < numDevices ); ++i )
phDevicesLocal[ i ] = reinterpret_cast<ze_device_object_t*>( phDevices[ i ] )->handle;
// forward to device-driver
result = pfnCreateEx( hDriver, desc, numDevices, phDevicesLocal, phContext );
delete []phDevicesLocal;
if( ZE_RESULT_SUCCESS != result )
return result;
try
{
// convert driver handle to loader handle
*phContext = reinterpret_cast<ze_context_handle_t>(
context->ze_context_factory.getInstance( *phContext, dditable ) );
}
catch( std::bad_alloc& )
{
result = ZE_RESULT_ERROR_OUT_OF_HOST_MEMORY;
}
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeContextDestroy
__zedlllocal ze_result_t ZE_APICALL
zeContextDestroy(
ze_context_handle_t hContext ///< [in][release] handle of context object to destroy
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_context_object_t*>( hContext )->dditable;
auto pfnDestroy = dditable->ze.Context.pfnDestroy;
if( nullptr == pfnDestroy )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hContext = reinterpret_cast<ze_context_object_t*>( hContext )->handle;
// forward to device-driver
result = pfnDestroy( hContext );
if( ZE_RESULT_SUCCESS != result )
return result;
// release loader handle
context->ze_context_factory.release( hContext );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeContextGetStatus
__zedlllocal ze_result_t ZE_APICALL
zeContextGetStatus(
ze_context_handle_t hContext ///< [in] handle of context object
)
{
ze_result_t result = ZE_RESULT_SUCCESS;
// extract driver's function pointer table
auto dditable = reinterpret_cast<ze_context_object_t*>( hContext )->dditable;
auto pfnGetStatus = dditable->ze.Context.pfnGetStatus;
if( nullptr == pfnGetStatus )
return ZE_RESULT_ERROR_UNINITIALIZED;
// convert loader handle to driver handle
hContext = reinterpret_cast<ze_context_object_t*>( hContext )->handle;
// forward to device-driver
result = pfnGetStatus( hContext );
return result;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Intercept function for zeCommandQueueCreate
__zedlllocal ze_result_t ZE_APICALL