forked from oneapi-src/level-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzer.py
More file actions
102 lines (82 loc) · 4.29 KB
/
zer.py
File metadata and controls
102 lines (82 loc) · 4.29 KB
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
"""
Copyright (C) 2019-2025 Intel Corporation
SPDX-License-Identifier: MIT
@file zer.py
@version v1.15-r1.15.31
"""
import platform
from ctypes import *
from enum import *
###############################################################################
__version__ = "1.0"
###############################################################################
## @brief Immediate Command List default descriptor for GPU devices
###############################################################################
## @brief Device Unified Shared Memory Allocation default descriptor for GPU
## devices
###############################################################################
## @brief Host Unified Shared Memory Allocation default descriptor for GPU
## devices
###############################################################################
__use_win_types = "Windows" == platform.uname()[0]
###############################################################################
## @brief Function-pointer for zerGetLastErrorDescription
if __use_win_types:
_zerGetLastErrorDescription_t = WINFUNCTYPE( ze_result_t, POINTER(c_char_p) )
else:
_zerGetLastErrorDescription_t = CFUNCTYPE( ze_result_t, POINTER(c_char_p) )
###############################################################################
## @brief Function-pointer for zerTranslateDeviceHandleToIdentifier
if __use_win_types:
_zerTranslateDeviceHandleToIdentifier_t = WINFUNCTYPE( uint32_t, ze_device_handle_t )
else:
_zerTranslateDeviceHandleToIdentifier_t = CFUNCTYPE( uint32_t, ze_device_handle_t )
###############################################################################
## @brief Function-pointer for zerTranslateIdentifierToDeviceHandle
if __use_win_types:
_zerTranslateIdentifierToDeviceHandle_t = WINFUNCTYPE( ze_device_handle_t, c_ulong )
else:
_zerTranslateIdentifierToDeviceHandle_t = CFUNCTYPE( ze_device_handle_t, c_ulong )
###############################################################################
## @brief Function-pointer for zerGetDefaultContext
if __use_win_types:
_zerGetDefaultContext_t = WINFUNCTYPE( ze_context_handle_t, )
else:
_zerGetDefaultContext_t = CFUNCTYPE( ze_context_handle_t, )
###############################################################################
## @brief Table of Global functions pointers
class _zer_global_dditable_t(Structure):
_fields_ = [
("pfnGetLastErrorDescription", c_void_p), ## _zerGetLastErrorDescription_t
("pfnTranslateDeviceHandleToIdentifier", c_void_p), ## _zerTranslateDeviceHandleToIdentifier_t
("pfnTranslateIdentifierToDeviceHandle", c_void_p), ## _zerTranslateIdentifierToDeviceHandle_t
("pfnGetDefaultContext", c_void_p) ## _zerGetDefaultContext_t
]
###############################################################################
class _zer_dditable_t(Structure):
_fields_ = [
("Global", _zer_global_dditable_t)
]
###############################################################################
## @brief zer device-driver interfaces
class ZER_DDI:
def __init__(self, version : ze_api_version_t):
# load the ze_loader library
if "Windows" == platform.uname()[0]:
self.__dll = WinDLL("ze_loader.dll")
else:
self.__dll = CDLL("ze_loader.so")
# fill the ddi tables
self.__dditable = _zer_dditable_t()
# call driver to get function pointers
_Global = _zer_global_dditable_t()
r = ze_result_v(self.__dll.zerGetGlobalProcAddrTable(version, byref(_Global)))
if r != ze_result_v.SUCCESS:
raise Exception(r)
self.__dditable.Global = _Global
# attach function interface to function address
self.zerGetLastErrorDescription = _zerGetLastErrorDescription_t(self.__dditable.Global.pfnGetLastErrorDescription)
self.zerTranslateDeviceHandleToIdentifier = _zerTranslateDeviceHandleToIdentifier_t(self.__dditable.Global.pfnTranslateDeviceHandleToIdentifier)
self.zerTranslateIdentifierToDeviceHandle = _zerTranslateIdentifierToDeviceHandle_t(self.__dditable.Global.pfnTranslateIdentifierToDeviceHandle)
self.zerGetDefaultContext = _zerGetDefaultContext_t(self.__dditable.Global.pfnGetDefaultContext)
# success!